Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: abe79d046d0ab8bc42c490ee76095a8578f6f5e6 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
 * Copyright (c) 2010-2012, 2015 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:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.dawn.tests.ui.util;

import org.eclipse.emf.cdo.dawn.examples.acore.AClass;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AClassAggregationsEditPart;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AClassAssociationsEditPart;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AClassCompositionsEditPart;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AClassEditPart;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AClassImplementedInterfacesEditPart;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AClassSubClassesEditPart;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AInterfaceEditPart;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.part.AcoreVisualIDRegistry;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.providers.AcoreElementTypes;
import org.eclipse.emf.cdo.dawn.examples.acore.diagram.providers.AcoreViewProvider;
import org.eclipse.emf.cdo.dawn.ui.DawnColorConstants;
import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
import org.eclipse.emf.cdo.dawn.ui.helper.EditorDescriptionHelper;

import org.eclipse.emf.common.util.URI;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.matchers.AbstractMatcher;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import org.hamcrest.Description;

import java.util.List;

/**
 * @author Martin Fluegge
 */
public class DawnAcoreTestUtil
{
  public static final String A_CLASS = "AClass";

  public static final String A_INTERFACE = "AInterface";

  public static final String A_ATTRIBUTE = "AAttribute";

  public static final String A_OPERATION = "AOperation";

  public static final String CONNECTION_IHERITS = "inherits";

  public static final String CONNECTION_IMPLEMENTS = "implements";

  public static final String CONNECTION_ASSOCIATION = "association";

  public static final String CONNECTION_AGGREGATION = "aggregation";

  public static final String CONNECTION_COMPOSITION = "composition";

  public static final String CREATION_WIZARD_NAME_GMF = "Dawn Acore Diagram";

  public static final String CREATION_WIZARD_NAME_EMF = "Dawn Acore Model";

  private static IViewProvider viewProvider = new AcoreViewProvider();

  private static String resourceFieldLabel = org.eclipse.emf.cdo.dawn.ui.messages.Messages.DawnCreateNewResourceWizardPage_6;

  public static SWTBotGefEditor openNewAcoreGMFEditor(String diagramResourceName, SWTGefBot bot)
  {
    return openNewAcoreGMFEditor(diagramResourceName, diagramResourceName.replace("_diagram", ""), bot);
  }

  public static SWTBotGefEditor openNewAcoreGMFEditor(String diagramResourceName, String semanticResource,
      SWTGefBot bot)
  {
    bot.menu("File").menu("New").menu("Other...").click();

    SWTBotShell shell = bot.shell("New");
    shell.activate();
    bot.tree().expandNode("Dawn Examples").select("Dawn Acore Diagram");
    bot.button("Next >").click();

    shell.activate();

    SWTBotText fileNameLabel = bot.textWithLabel(resourceFieldLabel);
    fileNameLabel.setText(diagramResourceName);

    bot.button("Next >").click();

    SWTBotText fileSemanticNameLabel = bot.textWithLabel(resourceFieldLabel);

    fileSemanticNameLabel = bot.textWithLabel(resourceFieldLabel);
    fileSemanticNameLabel.setText(semanticResource);

    fileSemanticNameLabel = bot.textWithLabel(resourceFieldLabel);

    bot.button("Finish").click();

    SWTBotGefEditor editor = bot.gefEditor(diagramResourceName);
    return editor;
  }

  public static DawnSWTBotEMFEditor openAcoreEMFEditor(URI resourceURI, DawnEMFEditorBot bot)
  {
    String resourceName = resourceURI.lastSegment();
    final String editorID = EditorDescriptionHelper.getEditorIdForDawnEditor(resourceName);

    final DawnEditorInput editorInput = new DawnEditorInput(resourceURI);

    UIThreadRunnable.asyncExec(new VoidResult()
    {
      public void run()
      {
        try
        {
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getPage()
              .openEditor(editorInput, editorID);
        }
        catch (PartInitException ex)
        {
          throw new RuntimeException(ex);
        }
      }
    });

    return bot.emfEditor(resourceName);
  }

  public static DawnSWTBotEMFEditor openNewAcoreEMFEditor(String resourceName, DawnEMFEditorBot bot)
  {
    bot.menu("File").menu("New").menu("Other...").click();

    SWTBotShell shell = bot.shell("New");
    shell.activate();
    bot.tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF);
    bot.button("Next >").click();

    shell = bot.shell("New");
    shell.activate();

    SWTBotText fileSemanticNameLabel = bot.textWithLabel(resourceFieldLabel);
    fileSemanticNameLabel.setText(resourceName);

    bot.button("Next >").click();

    SWTBotCombo comboBox = bot.comboBox(0);// bot.ccomboBox(0);
    comboBox.setFocus();
    comboBox.setSelection("ACore Root");

    bot.button("Finish").click();

    return bot.emfEditor(resourceName);
  }

  public static List<SWTBotGefEditPart> getAClassEditParts(SWTBotGefEditor editor)
  {
    List<SWTBotGefEditPart> editParts = editor.editParts(new AbstractMatcher<AClassEditPart>()
    {
      @Override
      protected boolean doMatch(Object item)
      {
        return item instanceof AClassEditPart;
      }

      public void describeTo(Description description)
      {
      }
    });
    return editParts;
  }

  public static List<SWTBotGefEditPart> getAInterfaceEditParts(SWTBotGefEditor editor)
  {
    List<SWTBotGefEditPart> editParts = editor.editParts(new AbstractMatcher<AInterfaceEditPart>()
    {
      @Override
      protected boolean doMatch(Object item)
      {
        return item instanceof AInterfaceEditPart;
      }

      public void describeTo(Description description)
      {
      }
    });
    return editParts;
  }

  public static List<SWTBotGefEditPart> getAClassAssociationsEditParts(SWTBotGefEditor editor)
  {
    List<SWTBotGefEditPart> editParts = getAClassEditParts(editor);
    return DawnSWTBotUtil.getConnectionEditParts(editor, AClassAssociationsEditPart.class, editParts);
  }

  public static Node createNewAClassRemote(Diagram diagram, AClass newAClass)
  {
    String type = AcoreVisualIDRegistry.getType(AClassEditPart.VISUAL_ID);
    return DawnSWTBotUtil.createNewNodeRemote(diagram, newAClass, type);
  }

  // public static Edge createNewAssociationRemote(Node source, Node target)
  // {
  // String type = AcoreVisualIDRegistry.getType(AClassAssociationsEditPart.VISUAL_ID);
  // Edge newEdge = DawnSWTBotUtil.createEdgeRemote(source, target, type);
  // return newEdge;
  // }

  public static Edge createNewAssociationRemote(Node source, Node target, List<RelativeBendpoint> bendpoints)
  {
    String type = AcoreVisualIDRegistry.getType(AClassAssociationsEditPart.VISUAL_ID);
    return DawnSWTBotUtil.createEdgeRemote(source, target, type, AcoreElementTypes.AClassAssociations_4003, bendpoints,
        viewProvider);
  }

  public static Edge createNewImplementsRelationRemote(Node source, Node target, List<RelativeBendpoint> bendpoints)
  {
    String type = AcoreVisualIDRegistry.getType(AClassImplementedInterfacesEditPart.VISUAL_ID);
    return DawnSWTBotUtil.createEdgeRemote(source, target, type, AcoreElementTypes.AClassImplementedInterfaces_4002,
        bendpoints, viewProvider);
  }

  public static Edge createNewInheritanceRelationRemote(Node source, Node target, List<RelativeBendpoint> bendpoints)
  {
    String type = AcoreVisualIDRegistry.getType(AClassSubClassesEditPart.VISUAL_ID);
    return DawnSWTBotUtil.createEdgeRemote(source, target, type, AcoreElementTypes.AClassSubClasses_4001, bendpoints,
        viewProvider);
  }

  public static Edge createNewCompositionRemote(Node source, Node target, List<RelativeBendpoint> bendpoints)
  {
    String type = AcoreVisualIDRegistry.getType(AClassCompositionsEditPart.VISUAL_ID);
    return DawnSWTBotUtil.createEdgeRemote(source, target, type, AcoreElementTypes.AClassCompositions_4005, bendpoints,
        viewProvider);
  }

  public static Edge createNewAggregationRemote(Node source, Node target, List<RelativeBendpoint> bendpoints)
  {
    String type = AcoreVisualIDRegistry.getType(AClassAggregationsEditPart.VISUAL_ID);
    return DawnSWTBotUtil.createEdgeRemote(source, target, type, AcoreElementTypes.AClassAggregations_4004, bendpoints,
        viewProvider);
  }

  public static void sleep(int seconds)
  {
    try
    {
      Thread.sleep(seconds);
    }
    catch (InterruptedException ex)
    {
      throw new RuntimeException(ex);
    }
  }

  public static boolean showsConflict(EditPart editPart)
  {
    if (editPart instanceof AClassEditPart || editPart instanceof AInterfaceEditPart)
    {
      GraphicalEditPart e = (GraphicalEditPart)editPart;

      IFigure figure = e.getFigure();
      return ((LineBorder)figure.getBorder()).getColor().equals(DawnColorConstants.COLOR_DELETE_CONFLICT);
    }
    return false;
  }

  public static Object showsLock(EditPart editPart, Color lockColor)
  {
    if (editPart instanceof AClassEditPart || editPart instanceof AInterfaceEditPart)
    {
      GraphicalEditPart e = (GraphicalEditPart)editPart;

      IFigure figure = e.getFigure();
      return ((LineBorder)figure.getBorder()).getColor().equals(lockColor);
    }
    return false;
  }

  public static Object showsNoLock(EditPart editPart)
  {
    if (editPart instanceof AClassEditPart || editPart instanceof AInterfaceEditPart)
    {
      GraphicalEditPart e = (GraphicalEditPart)editPart;

      IFigure figure = e.getFigure();
      Color color = ((LineBorder)figure.getBorder()).getColor();
      return !(color.equals(DawnColorConstants.COLOR_LOCKED_REMOTELY)
          && color.equals(DawnColorConstants.COLOR_LOCKED_LOCALLY));
    }
    return false;
  }
}

Back to the top