Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5f6a61f7a29fa4c245a4b6feb94e01b6725ce907 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
 * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Martin Fluegge - initial API and implementation
 */
package org.eclipse.emf.cdo.dawn.tests;

import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnSWTBotUtil;
import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
import org.eclipse.emf.cdo.dawn.ui.helper.EditorDescriptionHelper;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.ui.AbstractCDOUITest;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.gmf.runtime.notation.Bounds;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import org.junit.Before;

/**
 * @author Martin Fluegge
 */
public abstract class AbstractDawnUITest<T extends SWTWorkbenchBot> extends AbstractCDOUITest<T>
{
  @Override
  @Before
  public void setUp() throws Exception
  {
    super.setUp();
    SWTBotPreferences.SCREENSHOTS_DIR = DawnTestPlatform.instance.getTestFolder();
    resetWorkbench();
    DawnSWTBotUtil.initTest(getBot());

    // TODO Remove this line if bug 323788 is solved.
    getBot().viewByTitle("CDO Sessions").close();
  }

  /**
   * This method opens a DawnDiagramEditor specified by the given URI. It automatically finds the right editor by
   * matching the "file extension".
   */
  protected void openEditor(final String resourcePath)
  {
    UIThreadRunnable.syncExec(new VoidResult()
    {
      public void run()
      {
        CDOSession session = openSession();
        CDOView view = session.openView();

        CDOResource resource = view.getResource(resourcePath);

        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null)
        {
          IWorkbenchPage page = window.getActivePage();
          String editorID = EditorDescriptionHelper.getEditorIdForDawnEditor(resource.getName());

          try
          {
            DawnEditorInput editorInput = new DawnEditorInput(resource.getURI());

            page.openEditor(editorInput, editorID);
          }
          catch (PartInitException e)
          {
            e.printStackTrace();
          }
        }
      }
    });
  }

  protected boolean resourceExists(String resourcePath)
  {
    try
    {
      CDOSession session = openSession();
      CDOView view = session.openView();

      CDOResource resource = view.getResource(resourcePath);

      return resource != null ? true : false;
    }
    catch (Exception ex)
    {
      return false;
    }
  }

  protected void createNode(String type, int xPosition, int yPosition, SWTGefBot bot, SWTBotGefEditor editor)
  {
    editor.activateTool(type);
    editor.click(xPosition, yPosition);
  }

  protected void createNodeWithLabel(String type, int xPosition, int yPosition, String labelText, SWTGefBot bot,
      SWTBotGefEditor editor)
  {
    createNode(type, xPosition, yPosition, bot, editor);
    typeTextToFocusedWidget(labelText, bot, true);
  }

  protected void createEdge(String type, int fromXPosition, int fromYPosition, int toXPosition, int toYPosition,
      SWTBotGefEditor editor)
  {
    editor.activateTool(type);
    editor.drag(fromXPosition, fromYPosition, toXPosition, toYPosition);
  }

  protected void createEdge(String type, Node nodeFrom, Node nodeTo, SWTBotGefEditor editor)
  {
    Bounds boundsA = (Bounds)nodeFrom.getLayoutConstraint();
    Bounds boundsB = (Bounds)nodeTo.getLayoutConstraint();
    createEdge(type, boundsA.getX(), boundsA.getY(), boundsB.getX(), boundsB.getY(), editor);
  }
}

Back to the top