Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2010-04-07 08:59:32 -0400
committeratikhomirov2010-04-07 08:59:32 -0400
commit2e960c358ce4f702fc4a1ed48bc1f8cb1c469501 (patch)
tree1df2c429ea10269dec4bece490a6f3ccc72456d9
parent661c6e5b808da18d3961f884b70d238cc2e94cee (diff)
downloadorg.eclipse.gmf-tooling-2e960c358ce4f702fc4a1ed48bc1f8cb1c469501.tar.gz
org.eclipse.gmf-tooling-2e960c358ce4f702fc4a1ed48bc1f8cb1c469501.tar.xz
org.eclipse.gmf-tooling-2e960c358ce4f702fc4a1ed48bc1f8cb1c469501.zip
viewer configuration moved out from GeneratorConfiguration and
not exposed in the session setup (needed in few tests only, not for the setup itself); Abstraction of generated diagram editor used throughout code separated from SessionSetup
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/AbstractDiagramEditorTest.java156
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/CompartmentPropertiesTest.java5
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramEditorTest.java147
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramNodeTest.java10
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractCanvasTest.java13
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractMultiSetupTest.java9
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AuditRulesTest.java6
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/BundleActivationTest.java7
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/EditHelpersTest.java15
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/ElementInitializerTest.java10
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/GeneratedCanvasTest.java25
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkChildMetaFeatureNotFromContainerTest.java11
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationConstraintsTest.java12
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationTest.java15
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkEcoreConstraintsTest.java4
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/MetricRulesTest.java5
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/PaletteTest.java5
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/AbstractGeneratorConfiguration.java48
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratedDiagramPlugin.java31
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratorConfiguration.java37
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/LinksSessionSetup.java6
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeBasedGeneratorConfiguration.java36
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java29
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ViewerConfiguration.java46
24 files changed, 388 insertions, 300 deletions
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/AbstractDiagramEditorTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/AbstractDiagramEditorTest.java
index bf1676fba..7eaa2999b 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/AbstractDiagramEditorTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/AbstractDiagramEditorTest.java
@@ -11,7 +11,6 @@
*/
package org.eclipse.gmf.tests.gef;
-import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collections;
@@ -30,12 +29,14 @@ import org.eclipse.emf.ecore.resource.ContentHandler;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gmf.codegen.gmfgen.GenDiagram;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.tests.Utils;
import org.eclipse.gmf.tests.rt.AbstractCanvasTest;
-import org.eclipse.gmf.tests.setup.GeneratorConfiguration;
+import org.eclipse.gmf.tests.setup.GeneratedDiagramPlugin;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
@@ -45,24 +46,28 @@ import org.eclipse.ui.part.FileEditorInput;
/**
* Abstract test that operates with open diagram editors instead of fake no-update viewers.
+ * Note, distinct subclasses for Full and Lite runtimes are required since
+ * {@link #createViewerConfiguration(EditPartViewer, GeneratedDiagramPlugin)} and
+ * {@link #createDiagramView(EObject, GeneratedDiagramPlugin)} need different implementation.
*/
-public class AbstractDiagramEditorTest extends AbstractCanvasTest {
+public abstract class AbstractDiagramEditorTest extends AbstractCanvasTest {
private IProject myProject;
private IEditorPart myEditor;
private IFile myDiagramFile;
+ private Boolean mySameModelAndDiagramFile = null;
+ private final ViewerConfiguration.Factory myViewerConfigFactory;
- public AbstractDiagramEditorTest(String name) {
+ public AbstractDiagramEditorTest(String name, ViewerConfiguration.Factory viewerConfigFactory) {
super(name);
+ assert viewerConfigFactory != null;
+ myViewerConfigFactory = viewerConfigFactory;
}
@Override
protected void setUp() throws Exception {
super.setUp();
myProject = createProject();
- myDiagramFile = createDiagram();
- myEditor = openEditor(myDiagramFile);
- assertNotNull(myEditor);
- assertFalse("Fail fast if not diagram editor is associated with diagram file", "org.eclipse.ui.DefaultTextEditor".equals(myEditor.getEditorSite().getId()));
+ mySameModelAndDiagramFile = null; // use default value (i.e. from gmfgen)
}
protected IProject getProject() {
@@ -70,22 +75,36 @@ public class AbstractDiagramEditorTest extends AbstractCanvasTest {
}
protected IEditorPart getEditor() {
+ if (myEditor == null) {
+ myEditor = openEditor(getDiagramFile());
+ assertNotNull(myEditor);
+ assertFalse("Fail fast if not diagram editor is associated with diagram file", "org.eclipse.ui.DefaultTextEditor".equals(myEditor.getEditorSite().getId()));
+ }
return myEditor;
}
+ private IFile getDiagramFile() {
+ if (myDiagramFile == null) {
+ myDiagramFile = createDiagramFile();
+ }
+ return myDiagramFile;
+ }
@Override
- protected GeneratorConfiguration.ViewerConfiguration createViewerConfiguration() throws Exception {
- return createViewerConfiguration(myEditor);
+ protected ViewerConfiguration createViewerConfiguration() {
+ IEditorPart editorPart = getEditor();
+ GraphicalViewer viewer = (GraphicalViewer) editorPart.getAdapter(GraphicalViewer.class);
+ return getViewerConfigurationFactory().createViewerConfiguration(viewer, getSetup());
}
- protected GeneratorConfiguration.ViewerConfiguration createViewerConfiguration(IEditorPart editorPart) throws Exception {
- GraphicalViewer viewer = (GraphicalViewer) editorPart.getAdapter(GraphicalViewer.class);
- return getSetup().getGeneratorConfiguration().createViewerConfiguration(viewer, getSetup().getGenModel().getGenDiagram(), getSetup().getGeneratedPlugin());
+ protected final ViewerConfiguration.Factory getViewerConfigurationFactory() {
+ return myViewerConfigFactory;
}
-
+
@Override
protected void tearDown() throws Exception {
- closeEditor(myEditor);
+ if (myEditor != null) {
+ closeEditor(myEditor);
+ }
// keep project alive for potential workspace investigations
// deleteProject();
myProject = null;
@@ -95,15 +114,10 @@ public class AbstractDiagramEditorTest extends AbstractCanvasTest {
protected static void closeEditor(IEditorPart editor) {
editor.doSave(new NullProgressMonitor());
- redispatchEvents();
+ Utils.assertDispatchDisplayMessages(3);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, true);
}
- protected static final void redispatchEvents() {
- final boolean t = Utils.dispatchDisplayMessages(3);
- assertTrue("Display message redispatch was not expected to end by timeout", t);
- }
-
protected IProject createProject() {
String projectName = getUniqueString();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
@@ -119,7 +133,7 @@ public class AbstractDiagramEditorTest extends AbstractCanvasTest {
}
protected void deleteProject() throws CoreException {
- if (getProject() != null) {
+ if (myProject != null) {
if (getProject().isOpen()) {
getProject().close(new NullProgressMonitor());
}
@@ -129,22 +143,44 @@ public class AbstractDiagramEditorTest extends AbstractCanvasTest {
}
}
- protected IFile createDiagram() throws Exception {
- return createDiagram(getSetup().getGenModel().getGenDiagram().getEditorGen().isSameFileForDiagramAndModel());
+ /**
+ * Unless invoked, default value from gmfgen model will be used.
+ * Note, should be called prior to any #getEditor() or #getDiagram() call
+ */
+ protected final void useSameFileForDiagramAndModel(boolean sameFile) {
+ assertNull("Can't use this method after diagram file has been created", myDiagramFile);
+ mySameModelAndDiagramFile = Boolean.valueOf(sameFile);
}
- protected IFile createDiagram(boolean storeModelInDiagramFile) throws Exception {
- GenDiagram genDiagram = getSetup().getGenModel().getGenDiagram();
- String uniqueName = getUniqueString();
- final String diagramFileName = uniqueName + "." + genDiagram.getEditorGen().getDiagramFileExtension();
- IFile diagramFile = getProject().getFile(diagramFileName);
+ private IFile createDiagramFile() {
+ boolean sameFileForDiagramAndModel;
+ if (mySameModelAndDiagramFile != null) {
+ sameFileForDiagramAndModel = mySameModelAndDiagramFile.booleanValue();
+ } else {
+ sameFileForDiagramAndModel = getSetup().getGenModel().getGenDiagram().getEditorGen().isSameFileForDiagramAndModel();
+ }
+ // use test name for diagram file name since there should be no more than one diagram file per test
+ // and it's easier to analyze test contents with meaningful names
+ EObject domainElement = createDiagramDomainObject(getSetup());
+ Diagram diagramView = createDiagramView(domainElement, getSetup());
+ assertNotNull("Diagram was not created", diagramView);
+ assertSame(domainElement, diagramView.getElement());
+ return createDiagramFile(getProject(), getName(), getSetup().getGenDiagram(), domainElement, diagramView, sameFileForDiagramAndModel);
+ }
+
+ // XXX full and lite runtimes now need different initialization steps (unless we have common createDiagram code in e.g. DiagramEditorUtil
+ protected abstract Diagram createDiagramView(EObject domainElement, GeneratedDiagramPlugin genPlugin);
+
+ private static IFile createDiagramFile(IProject where, String fileNameStem, GenDiagram genDiagram, EObject domainElement, Diagram diagramView, boolean storeModelInDiagramFile) {
+ final String diagramFileName = fileNameStem + "." + genDiagram.getEditorGen().getDiagramFileExtension();
+ IFile diagramFile = where.getFile(diagramFileName);
assertFalse("Diagram file was already created", diagramFile.exists());
IFile modelFile = null;
if (!storeModelInDiagramFile) {
IPath diagramFilePath = diagramFile.getProjectRelativePath();
IPath modelFilePath = diagramFilePath.removeFileExtension().addFileExtension(genDiagram.getEditorGen().getDomainFileExtension());
- modelFile = getProject().getFile(modelFilePath);
+ modelFile = where.getFile(modelFilePath);
assertFalse("Model file was already created", modelFile.exists());
}
@@ -152,49 +188,49 @@ public class AbstractDiagramEditorTest extends AbstractCanvasTest {
Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toOSString(), true), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
Resource modelResource = modelFile != null ? resourceSet.createResource(URI.createPlatformResourceURI(modelFile.getFullPath().toOSString(), true), ContentHandler.UNSPECIFIED_CONTENT_TYPE) : null;
- EObject domainDiagramElement = createDiagramDomainObject();
if (modelResource != null) {
- modelResource.getContents().add(domainDiagramElement);
+ modelResource.getContents().add(domainElement);
} else {
- diagramResource.getContents().add(domainDiagramElement);
- }
- Diagram diagram = getSetup().getGeneratorConfiguration().createDiagram(domainDiagramElement, getSetup());
- assertNotNull("Diagram was not created", diagram);
- if (diagram != null) {
- diagramResource.getContents().add(diagram);
- diagram.setName(uniqueName);
- diagram.setElement(domainDiagramElement);
+ diagramResource.getContents().add(domainElement);
}
+ assertSame("[sanity]", domainElement, diagramView.getElement());
+ diagramResource.getContents().add(diagramView);
+ diagramView.setName(fileNameStem);
try {
if (modelResource != null) {
modelResource.save(Collections.EMPTY_MAP);
}
diagramResource.save(Collections.EMPTY_MAP);
- } catch (IOException e) {
- fail(e.getMessage());
+ } catch (Exception e) {
+ fail(e.toString());
}
return diagramFile;
}
- protected EObject createDiagramDomainObject() throws Exception {
- GenClass diagramElementGenClass = getSetup().getGenModel().getGenDiagram().getDomainDiagramElement();
- GenPackage domainGenPackage = diagramElementGenClass.getGenPackage();
- Class<?> factoryInterface = getSetup().loadGeneratedClass(domainGenPackage.getQualifiedFactoryInterfaceName());
- assertNotNull("Factory interface not found", factoryInterface);
- Field accessor = null;
- accessor = factoryInterface.getField(domainGenPackage.getFactoryInstanceName());
- assertNotNull("Accessor field not found", accessor);
- Object factory = null;
- factory = accessor.get(null);
- assertNotNull("Factory unavailable", factory);
- Method createMethod = null;
- createMethod = factory.getClass().getMethod("create" + diagramElementGenClass.getName(), new Class[0]);
- assertNotNull("Create method unavailable", createMethod);
- EObject domainDiagramElement = null;
- domainDiagramElement = (EObject) createMethod.invoke(factory, new Object[0]);
- assertNotNull("Domain diagram element was not created", domainDiagramElement);
- return domainDiagramElement;
+ protected static EObject createDiagramDomainObject(GeneratedDiagramPlugin genPlugin) {
+ try {
+ GenClass diagramElementGenClass = genPlugin.getGenDiagram().getDomainDiagramElement();
+ GenPackage domainGenPackage = diagramElementGenClass.getGenPackage();
+ Class<?> factoryInterface = genPlugin.loadGeneratedClass(domainGenPackage.getQualifiedFactoryInterfaceName());
+ assertNotNull("Factory interface not found", factoryInterface);
+ Field accessor = null;
+ accessor = factoryInterface.getField(domainGenPackage.getFactoryInstanceName());
+ assertNotNull("Accessor field not found", accessor);
+ Object factory = null;
+ factory = accessor.get(null);
+ assertNotNull("Factory unavailable", factory);
+ Method createMethod = null;
+ createMethod = factory.getClass().getMethod("create" + diagramElementGenClass.getName(), new Class[0]);
+ assertNotNull("Create method unavailable", createMethod);
+ EObject domainDiagramElement = null;
+ domainDiagramElement = (EObject) createMethod.invoke(factory, new Object[0]);
+ assertNotNull("Domain diagram element was not created", domainDiagramElement);
+ return domainDiagramElement;
+ } catch (Exception ex) {
+ fail(ex.toString());
+ }
+ return null;
}
protected IEditorPart openEditor(IFile diagramFile) {
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/CompartmentPropertiesTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/CompartmentPropertiesTest.java
index 80854873e..0c532a910 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/CompartmentPropertiesTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/CompartmentPropertiesTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2009 Borland Software Corporation
+ * Copyright (c) 2006, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -27,6 +27,7 @@ import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.TitleStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tests.rt.GeneratedCanvasTest;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
import org.eclipse.gmf.tests.setup.SessionSetup;
/**
@@ -45,7 +46,7 @@ public final class CompartmentPropertiesTest extends GeneratedCanvasTest {
private static final NotationPackage NOTATION = NotationPackage.eINSTANCE;
public CompartmentPropertiesTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
myDefaultSetup = SessionSetup.newInstance();
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramEditorTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramEditorTest.java
index 2f4d333bd..b7533a279 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramEditorTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramEditorTest.java
@@ -16,7 +16,6 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -50,8 +49,11 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.tests.Utils;
+import org.eclipse.gmf.tests.setup.GeneratedDiagramPlugin;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
import org.eclipse.gmf.tests.setup.SessionSetup;
-import org.eclipse.gmf.tests.setup.GeneratorConfiguration.ViewerConfiguration;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
@@ -59,7 +61,7 @@ import org.eclipse.ui.IEditorPart;
public class DiagramEditorTest extends AbstractDiagramEditorTest {
public DiagramEditorTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
myDefaultSetup = SessionSetup.newInstance();
}
@@ -78,7 +80,7 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
assertFalse("Editor was not saved", editorPart.isDirty());
}
- public void testSaveNotaitonElementChanges() {
+ public void testSaveNotationElementChanges() {
IEditorPart editorPart = getEditor();
ViewerConfiguration viewerConfiguration = getViewerConfiguration();
Diagram diagram = getDiagram();
@@ -99,48 +101,31 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
}
public void testSaveDomainElementChangesSeparateFiles() {
- checkSaveDomainElementChanges(false);
+ useSameFileForDiagramAndModel(false);
+ checkSaveDomainElementChanges();
}
public void testSaveDomainElementChangesSameFile() {
- checkSaveDomainElementChanges(true);
+ useSameFileForDiagramAndModel(true);
+ checkSaveDomainElementChanges();
}
- private void checkSaveDomainElementChanges(boolean sameFile) {
- IEditorPart editorPart = setupCustomEditorPart(sameFile);
- try {
- ViewerConfiguration viewerConfiguration = getViewerConfiguration();
- EditPartViewer viewer = viewerConfiguration.getViewer();
- Diagram diagram = getDiagram();
-
- Node nodeA = createNodeA(diagram, editorPart);
- Command setLabelCommand = viewerConfiguration.getSetBusinessElementStructuralFeatureCommand(nodeA, "label", getUniqueString());
- checkEditorDirtyState(setLabelCommand, editorPart, viewer);
- } finally {
- editorPart.doSave(new NullProgressMonitor());
- closeEditor(editorPart);
- }
- }
+ private void checkSaveDomainElementChanges() {
+ IEditorPart editorPart = getEditor();
+ ViewerConfiguration viewerConfiguration = getViewerConfiguration();
+ EditPartViewer viewer = viewerConfiguration.getViewer();
+ Diagram diagram = getDiagram();
- private IEditorPart setupCustomEditorPart(boolean sameFileForModel) {
- try {
- IFile diagramFile = createDiagram(sameFileForModel);
- IEditorPart editorPart = openEditor(diagramFile);
- ViewerConfiguration viewerConfiguration = createViewerConfiguration(editorPart);
- // Substituting viewer configuraration with the custom one
- setViewerConfiguration(viewerConfiguration);
- return editorPart;
- } catch (Exception e) {
- fail(e.getMessage());
- return null;
- }
+ Node nodeA = createNodeA(diagram, editorPart);
+ Command setLabelCommand = viewerConfiguration.getSetBusinessElementStructuralFeatureCommand(nodeA, "label", getUniqueString());
+ checkEditorDirtyState(setLabelCommand, editorPart, viewer);
}
/**
* Testing fix of request:
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=153893
*/
- public void testSaveWithUnloadedResource() {
+ public void testSaveWithUnloadedResource() throws IOException {
IEditorPart editorPart = getEditor();
ViewerConfiguration viewerConfiguration = getViewerConfiguration();
EditPartViewer viewer = viewerConfiguration.getViewer();
@@ -236,28 +221,22 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
assertTrue("Unloaded resource was changed while saving editor", resource.getContents().size() == 1);
}
- private void createAdditionalModelResource(URI anotherResourceURI) {
+ private void createAdditionalModelResource(URI anotherResourceURI) throws IOException {
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(anotherResourceURI, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
- try {
- EObject domainDiagramElement = createDiagramDomainObject();
- resource.getContents().add(domainDiagramElement);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- try {
- resource.save(Collections.EMPTY_MAP);
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ EObject domainDiagramElement = createDiagramDomainObject(getSetup());
+ resource.getContents().add(domainDiagramElement);
+ resource.save(Collections.EMPTY_MAP);
}
public void testDiagramAndModelExternalModificationSameResource() {
- checkDiagramAndModelExternalModification(true);
+ useSameFileForDiagramAndModel(true);
+ checkDiagramAndModelExternalModification();
}
public void testDiagramAndModelExternalModificationSeparateResources() {
- checkDiagramAndModelExternalModification(false);
+ useSameFileForDiagramAndModel(false);
+ checkDiagramAndModelExternalModification();
}
/*
@@ -287,45 +266,41 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
[300887] content replaced fired
[300887] Test is about to re-get top EP's model:testDiagramAndModelExternalModificationSeparateResources
*/
- private void checkDiagramAndModelExternalModification(boolean sameFile) {
- IEditorPart editorPart = setupCustomEditorPart(sameFile);
+ private void checkDiagramAndModelExternalModification() {
+ IEditorPart editorPart = getEditor();
+ Diagram diagram = getDiagram();
+ assertTrue("Not empty diagram created", diagram.getChildren().size() == 0);
+ assertTrue("Not empty domain model element created", diagram.getElement().eContents().size() == 0);
+
+ Diagram diagramCopy = reloadInSeparateResourceSet(diagram);
+ assertTrue("Passed diagram is not empty", diagramCopy.getChildren().size() == 0);
try {
- Diagram diagram = getDiagram();
- assertTrue("Not empty diagram created", diagram.getChildren().size() == 0);
- assertTrue("Not empty domain model element created", diagram.getElement().eContents().size() == 0);
-
- Diagram diagramCopy = reloadInSeparateResoruceSet(diagram);
- assertTrue("Passed diagram is not empty", diagramCopy.getChildren().size() == 0);
- try {
- ViewerConfiguration viewerConfiguration = getSetup().getGeneratorConfiguration().createViewerConfiguration(new Shell(SWT.NONE), getSetup(), diagramCopy);
- Command command = viewerConfiguration.getCreateNodeCommand(diagramCopy, getSetup().getGenModel().getNodeA());
- viewerConfiguration.getViewer().getEditDomain().getCommandStack().execute(command);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- assertFalse("Diagram node was not created", diagramCopy.getChildren().size() == 0);
-
- saveResources(diagramCopy.eResource().getResourceSet().getResources());
- System.err.println("[300887] Done saveResources, all resource notifications should be already dispatched");
- redispatchEvents();
- System.err.println("[300887] Test is about to re-get top EP's model:" + getName());
-
- diagram = getDiagram();
- assertFalse("Editor is dirty", editorPart.isDirty());
- assertTrue("Diagram content was not refreshed", diagram.getChildren().size() > 0);
- assertTrue("Domain model content was not refreshed", diagram.getElement().eContents().size() > 0);
- } finally {
- closeEditor(editorPart);
+ ViewerConfiguration viewerConfiguration = getViewerConfigurationFactory().createViewerConfiguration(new Shell(SWT.NONE), diagramCopy, getSetup());
+ Command command = viewerConfiguration.getCreateNodeCommand(diagramCopy, getSetup().getGenModel().getNodeA());
+ viewerConfiguration.getViewer().getEditDomain().getCommandStack().execute(command);
+ } catch (Exception e) {
+ fail(e.getMessage());
}
+ assertFalse("Diagram node was not created", diagramCopy.getChildren().size() == 0);
+
+ saveResources(diagramCopy.eResource().getResourceSet().getResources());
+ System.err.println("[300887] Done saveResources, all resource notifications should be already dispatched");
+ Utils.assertDispatchDisplayMessages(3);
+ System.err.println("[300887] Test is about to re-get top EP's model:" + getName());
+
+ diagram = getDiagram();
+ assertFalse("Editor is dirty", editorPart.isDirty());
+ assertTrue("Diagram content was not refreshed", diagram.getChildren().size() > 0);
+ assertTrue("Domain model content was not refreshed", diagram.getElement().eContents().size() > 0);
}
- public void testDiagramResorceExternalModification() {
+ public void testDiagramResourceExternalModification() {
Diagram diagram = getDiagram();
String newDiagramName = getUniqueString();
- Diagram diagramCopy = reloadInSeparateResoruceSet(diagram);
+ Diagram diagramCopy = reloadInSeparateResourceSet(diagram);
try {
- ViewerConfiguration viewerConfiguration = getSetup().getGeneratorConfiguration().createViewerConfiguration(new Shell(SWT.NONE), getSetup(), diagramCopy);
+ ViewerConfiguration viewerConfiguration = getViewerConfigurationFactory().createViewerConfiguration(new Shell(SWT.NONE), diagramCopy, getSetup());
Command command = viewerConfiguration.getSetNotationalElementStructuralFeature(diagramCopy, NotationPackage.eINSTANCE.getDiagram_Name(), newDiagramName);
viewerConfiguration.getViewer().getEditDomain().getCommandStack().execute(command);
} catch (Exception e) {
@@ -334,7 +309,7 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
assertEquals("Diagram name was not set", newDiagramName, diagramCopy.getName());
saveResources(Collections.singletonList(diagramCopy.eResource()));
- redispatchEvents();
+ Utils.assertDispatchDisplayMessages(3);
diagram = getDiagram();
assertFalse("Editor is dirty", getEditor().isDirty());
@@ -344,17 +319,17 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
public void testModelResorceExternalModification() {
Diagram diagram = getDiagram();
- Diagram diagramCopy = reloadInSeparateResoruceSet(diagram);
+ Diagram diagramCopy = reloadInSeparateResourceSet(diagram);
String newName = getUniqueString();
try {
- ViewerConfiguration viewerConfiguration = getSetup().getGeneratorConfiguration().createViewerConfiguration(new Shell(SWT.NONE), getSetup(), diagramCopy);
+ ViewerConfiguration viewerConfiguration = getViewerConfigurationFactory().createViewerConfiguration(new Shell(SWT.NONE), diagramCopy, getSetup());
Command command = viewerConfiguration.getSetBusinessElementStructuralFeatureCommand(diagramCopy, "diagramAttribute", newName);
viewerConfiguration.getViewer().getEditDomain().getCommandStack().execute(command);
} catch (Exception e) {
fail(e.getMessage());
}
saveResources(Collections.singletonList(diagramCopy.getElement().eResource()));
- redispatchEvents();
+ Utils.assertDispatchDisplayMessages(3);
diagram = getDiagram();
assertFalse("Editor is dirty", getEditor().isDirty());
@@ -391,7 +366,7 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
}
}
- private Diagram reloadInSeparateResoruceSet(Diagram diagram) {
+ private Diagram reloadInSeparateResourceSet(Diagram diagram) {
TransactionalEditingDomain editingDoman = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
editingDoman.setID(getSetup().getGenModel().getGenDiagram().getEditingDomainID());
AdapterFactoryEditingDomain oldEditingDomain = (AdapterFactoryEditingDomain) TransactionUtil.getEditingDomain(diagram);
@@ -403,4 +378,8 @@ public class DiagramEditorTest extends AbstractDiagramEditorTest {
return (Diagram) newDiagram;
}
+ @Override
+ protected Diagram createDiagramView(EObject domainElement, GeneratedDiagramPlugin genPlugin) {
+ return RuntimeBasedGeneratorConfiguration.createDiagram(domainElement, genPlugin);
+ }
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramNodeTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramNodeTest.java
index fd76c7013..6c614eb47 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramNodeTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gef/DiagramNodeTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 Borland Software Corporation
+ * Copyright (c) 2005, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -44,6 +44,8 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tests.rt.GeneratedCanvasTest;
import org.eclipse.gmf.tests.setup.DiaDefSetup;
import org.eclipse.gmf.tests.setup.DiaGenSource;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
import org.eclipse.gmf.tests.setup.figures.GenericFigureCheck;
import org.eclipse.swt.graphics.RGB;
@@ -72,7 +74,11 @@ public class DiagramNodeTest extends GeneratedCanvasTest {
private final Dimension mySizeDelta = new Dimension(100, 50);
public DiagramNodeTest(String name) {
- super(name);
+ this(name, new RuntimeBasedGeneratorConfiguration());
+ }
+
+ protected DiagramNodeTest(String name, ViewerConfiguration.Factory viewerConfigFactory) {
+ super(name, viewerConfigFactory);
}
public void testCanCreateLink(){
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractCanvasTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractCanvasTest.java
index 613630be0..124f6a4f6 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractCanvasTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractCanvasTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2008 Borland Software Corporation
+ * Copyright (c) 2006, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -30,8 +30,7 @@ import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tests.ConfiguredTestCase;
-import org.eclipse.gmf.tests.setup.GeneratorConfiguration;
-import org.eclipse.gmf.tests.setup.GeneratorConfiguration.ViewerConfiguration;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
/**
* Provides default operations like creating nodes and links.
@@ -41,7 +40,7 @@ import org.eclipse.gmf.tests.setup.GeneratorConfiguration.ViewerConfiguration;
* instead, its subclasses do ({@link GeneratedCanvasTest}).
*/
public abstract class AbstractCanvasTest extends ConfiguredTestCase {
- private GeneratorConfiguration.ViewerConfiguration myViewerConfiguration;
+ private ViewerConfiguration myViewerConfiguration;
public AbstractCanvasTest(String name) {
super(name);
@@ -64,10 +63,6 @@ public abstract class AbstractCanvasTest extends ConfiguredTestCase {
return (Diagram) getDiagramEditPart().getModel();
}
- protected void setViewerConfiguration(ViewerConfiguration configuration) {
- myViewerConfiguration = configuration;
- }
-
public ViewerConfiguration getViewerConfiguration() {
if (myViewerConfiguration == null) {
try {
@@ -147,7 +142,7 @@ public abstract class AbstractCanvasTest extends ConfiguredTestCase {
return getViewerConfiguration().getViewer().getEditDomain().getCommandStack();
}
- protected abstract GeneratorConfiguration.ViewerConfiguration createViewerConfiguration() throws Exception;
+ protected abstract ViewerConfiguration createViewerConfiguration() throws Exception;
protected static class CreateListener extends AdapterImpl {
private EObject myCreatedChild;
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractMultiSetupTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractMultiSetupTest.java
index 2432b839c..2ac322bac 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractMultiSetupTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AbstractMultiSetupTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2008 Borland Software Corporation
+ * Copyright (c) 2007, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -14,12 +14,13 @@ package org.eclipse.gmf.tests.rt;
import org.eclipse.gmf.tests.setup.MultiSetup;
import org.eclipse.gmf.tests.setup.RTSource;
import org.eclipse.gmf.tests.setup.SessionSetup;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
-public class AbstractMultiSetupTest extends GeneratedCanvasTest {
+public abstract class AbstractMultiSetupTest extends GeneratedCanvasTest {
private MultiSetup myMultiSetup;
- public AbstractMultiSetupTest(String name) {
- super(name);
+ public AbstractMultiSetupTest(String name, ViewerConfiguration.Factory viewerConfigFactory) {
+ super(name, viewerConfigFactory);
}
public final void configure(MultiSetup setup) {
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AuditRulesTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AuditRulesTest.java
index faee151a3..6b4b5f478 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AuditRulesTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/AuditRulesTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008 Borland Software Corporation
+ * Copyright (c) 2005, 2010 Borland Software Corporation 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
@@ -58,6 +58,7 @@ import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tests.setup.LinksSessionSetup;
import org.eclipse.gmf.tests.setup.MapDefSource;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
/**
* Tests valid registration of audit rule definitions in emft validation framework
@@ -79,7 +80,7 @@ public class AuditRulesTest extends GeneratedCanvasTest {
private List<GenPackage> targetedPackages;
public AuditRulesTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
myDefaultSetup = LinksSessionSetup.newInstance();
}
@@ -193,6 +194,7 @@ public class AuditRulesTest extends GeneratedCanvasTest {
/*
* Checks if the constraint is correctly targeted to validated instances.
*/
+ @SuppressWarnings("unchecked")
void assertEvaluation(final AuditRule audit, final EObject target) {
final EObject[] validatedInstance = new EObject[1];
// Note: use notation::View host for the validated element in case of domain EObject to adapt the
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/BundleActivationTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/BundleActivationTest.java
index 2ba08fcf9..af1027601 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/BundleActivationTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/BundleActivationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009 Borland Software Corporation and others
+ * Copyright (c) 2008, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -36,6 +36,7 @@ import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tests.ConfiguredTestCase;
import org.eclipse.gmf.tests.setup.GenProjectSetup;
+import org.eclipse.gmf.tests.setup.GeneratorConfiguration;
import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
import org.eclipse.gmf.tests.setup.SessionSetup;
import org.osgi.framework.Bundle;
@@ -49,8 +50,8 @@ public class BundleActivationTest extends ConfiguredTestCase {
private final PreferencesHint prefHint = new PreferencesHint("a.b.c");
public final static SessionSetup setup = new SessionSetup(new RuntimeBasedGeneratorConfiguration()) {
@Override
- protected GenProjectSetup createGenProject() throws BundleException {
- return new GenProjectSetup(getGeneratorConfiguration()) {
+ protected GenProjectSetup createGenProject(GeneratorConfiguration generatorConfiguration) throws BundleException {
+ return new GenProjectSetup(generatorConfiguration) {
@Override
public GenProjectSetup init(GenEditorGenerator genEditor) throws BundleException {
try {
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/EditHelpersTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/EditHelpersTest.java
index 727626a0f..a39bcd733 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/EditHelpersTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/EditHelpersTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009 Borland Software Corp.
+ * Copyright (c) 2008, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -65,6 +65,7 @@ import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.tests.Plugin;
import org.eclipse.gmf.tests.Utils;
@@ -72,6 +73,7 @@ import org.eclipse.gmf.tests.gef.AbstractDiagramEditorTest;
import org.eclipse.gmf.tests.setup.DiaDefSource;
import org.eclipse.gmf.tests.setup.DomainModelSource;
import org.eclipse.gmf.tests.setup.GenProjectSetup;
+import org.eclipse.gmf.tests.setup.GeneratedDiagramPlugin;
import org.eclipse.gmf.tests.setup.GeneratorConfiguration;
import org.eclipse.gmf.tests.setup.MapDefSource;
import org.eclipse.gmf.tests.setup.MapSetup;
@@ -91,7 +93,7 @@ public class EditHelpersTest extends AbstractDiagramEditorTest {
public static final SessionSetup setup = new EditHelpersSessionSetup();
public EditHelpersTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
configure(setup);
}
@@ -126,6 +128,11 @@ public class EditHelpersTest extends AbstractDiagramEditorTest {
assertTrue(hasCommand(afterCommands, getSetup().getGenModel().getNodeB().getVisualID()));
}
+ @Override
+ protected Diagram createDiagramView(EObject domainElement, GeneratedDiagramPlugin genPlugin) {
+ return RuntimeBasedGeneratorConfiguration.createDiagram(domainElement, genPlugin);
+ }
+
private boolean hasCommand(Collection<IUndoableOperation> beforeCommands, int visualID) {
for (IUndoableOperation operation : beforeCommands) {
if (getEditHelperVisualID(operation) == visualID) {
@@ -233,8 +240,8 @@ public class EditHelpersTest extends AbstractDiagramEditorTest {
}
@Override
- protected GenProjectSetup createGenProject() throws BundleException {
- return new EditHelpersProjectSetup(getGeneratorConfiguration()).init(getGenModel());
+ protected GenProjectSetup createGenProject(GeneratorConfiguration generatorConfiguration) throws BundleException {
+ return new EditHelpersProjectSetup(generatorConfiguration).init(getGenModel());
}
@Override
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/ElementInitializerTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/ElementInitializerTest.java
index 0b74f7509..42ef6f370 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/ElementInitializerTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/ElementInitializerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009 Borland Software Corporation
+ * Copyright (c) 2005, 2010 Borland Software Corporation 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
@@ -40,6 +40,8 @@ import org.eclipse.gmf.codegen.gmfgen.GenJavaExpressionProvider;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.tests.setup.LinksSessionSetup;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
/**
* Tests domain meta-model element initialization
@@ -52,9 +54,13 @@ public class ElementInitializerTest extends GeneratedCanvasTest {
private Node myNodeA;
public ElementInitializerTest(String name) {
- super(name);
+ this(name, new RuntimeBasedGeneratorConfiguration());
myDefaultSetup = LinksSessionSetup.newInstance();
}
+
+ protected ElementInitializerTest(String name, ViewerConfiguration.Factory viewerConfigFactory) {
+ super(name, viewerConfigFactory);
+ }
protected void setUp() throws Exception {
super.setUp();
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/GeneratedCanvasTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/GeneratedCanvasTest.java
index 4f15086fb..8157172e4 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/GeneratedCanvasTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/GeneratedCanvasTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2008 Borland Software Corporation
+ * Copyright (c) 2006, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -13,13 +13,12 @@ package org.eclipse.gmf.tests.rt;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
-import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.tests.setup.DiaGenSource;
-import org.eclipse.gmf.tests.setup.GeneratorConfiguration;
import org.eclipse.gmf.tests.setup.RTSetup;
import org.eclipse.gmf.tests.setup.RTSource;
-import org.eclipse.gmf.tests.setup.GeneratorConfiguration.ViewerConfiguration;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration.Factory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
@@ -35,13 +34,20 @@ public abstract class GeneratedCanvasTest extends AbstractCanvasTest {
private EditPart myNodeEditPartB;
private CompartmentEditPart myCompartmentA;
private CompartmentEditPart myCompartmentB;
+ private final Factory myViewerConfigFactory;
- public GeneratedCanvasTest(String name) {
+ public GeneratedCanvasTest(String name, ViewerConfiguration.Factory viewerConfigFactory) {
super(name);
+ myViewerConfigFactory = viewerConfigFactory;
}
- protected GeneratorConfiguration.ViewerConfiguration createViewerConfiguration() throws Exception {
- return createViewerConfiguration(getCanvasInstance().getCanvas());
+ protected ViewerConfiguration createViewerConfiguration() throws Exception {
+ myParentShell = new Shell(SWT.NONE);
+ return getViewerConfigurationFactory().createViewerConfiguration(myParentShell, getCanvasInstance().getCanvas(), getSetup());
+ }
+
+ protected final ViewerConfiguration.Factory getViewerConfigurationFactory() {
+ return myViewerConfigFactory;
}
protected final RTSource getCanvasInstance() {
@@ -102,9 +108,4 @@ public abstract class GeneratedCanvasTest extends AbstractCanvasTest {
protected final DiaGenSource getGenModel() {
return getSetup().getGenModel();
}
-
- protected ViewerConfiguration createViewerConfiguration(Diagram canvas) throws Exception {
- myParentShell = new Shell(SWT.NONE);
- return getSetup().getGeneratorConfiguration().createViewerConfiguration(myParentShell, getSetup(), canvas);
- }
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkChildMetaFeatureNotFromContainerTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkChildMetaFeatureNotFromContainerTest.java
index f4e1b2033..d915b1547 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkChildMetaFeatureNotFromContainerTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkChildMetaFeatureNotFromContainerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008 Borland Software Corporation
+ * Copyright (c) 2008, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -32,12 +32,14 @@ import org.eclipse.gmf.codegen.gmfgen.TypeLinkModelFacet;
import org.eclipse.gmf.codegen.gmfgen.TypeModelFacet;
import org.eclipse.gmf.internal.bridge.genmodel.GenModelMatcher;
import org.eclipse.gmf.internal.bridge.genmodel.RuntimeGenModelAccess;
+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.NotationPackage;
import org.eclipse.gmf.tests.Utils;
import org.eclipse.gmf.tests.gef.AbstractDiagramEditorTest;
import org.eclipse.gmf.tests.setup.DiaGenSource;
+import org.eclipse.gmf.tests.setup.GeneratedDiagramPlugin;
import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
import org.eclipse.gmf.tests.setup.SessionSetup;
@@ -201,7 +203,7 @@ public class LinkChildMetaFeatureNotFromContainerTest extends AbstractDiagramEdi
};
public LinkChildMetaFeatureNotFromContainerTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
configure(setup);
}
@@ -233,4 +235,9 @@ public class LinkChildMetaFeatureNotFromContainerTest extends AbstractDiagramEdi
assertEquals("Link target should be B, accessible from L.lt", l.eGet(lt), b);
assertEquals("Link should originate at A element, from non-containment featyre A.lt", a.eGet(ls), l);
}
+
+ @Override
+ protected Diagram createDiagramView(EObject domainElement, GeneratedDiagramPlugin genPlugin) {
+ return RuntimeBasedGeneratorConfiguration.createDiagram(domainElement, genPlugin);
+ }
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationConstraintsTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationConstraintsTest.java
index 79a0055ee..f4e3fd260 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationConstraintsTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationConstraintsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008 Borland Software Corporation
+ * Copyright (c) 2005, 2010 Borland Software Corporation 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
@@ -25,20 +25,26 @@ import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tests.setup.LinksSessionSetup;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
+import org.eclipse.gmf.tests.setup.ViewerConfiguration;
public class LinkCreationConstraintsTest extends GeneratedCanvasTest {
public LinkCreationConstraintsTest(String name) {
- super(name);
+ this(name, new RuntimeBasedGeneratorConfiguration());
myDefaultSetup = LinksSessionSetup.newInstance();
}
+ protected LinkCreationConstraintsTest(String name, ViewerConfiguration.Factory viewerConfigFactory) {
+ super(name, viewerConfigFactory);
+ }
+
/*
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=148818
*/
public void testEndContexts() {
GenLink genLinkOrigin = getGenModel().getLinkC();
- GenLink genLink = (GenLink)EcoreUtil.copy(genLinkOrigin);
+ GenLink genLink = EcoreUtil.copy(genLinkOrigin);
assertTrue(genLink.getModelFacet() instanceof TypeLinkModelFacet);
TypeLinkModelFacet tlModelFacet = (TypeLinkModelFacet)genLink.getModelFacet();
assertTrue(tlModelFacet.getContainmentMetaFeature() != null && tlModelFacet.getTargetMetaFeature() != null);
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationTest.java
index 8380fe1fe..1e6b2f23f 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkCreationTest.java
@@ -1,5 +1,5 @@
-/**
- * Copyright (c) 2006 Borland Software Corp.
+/*
+ * Copyright (c) 2006, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -24,6 +24,7 @@ import org.eclipse.gmf.codegen.gmfgen.TypeLinkModelFacet;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
public class LinkCreationTest extends GeneratedCanvasTest {
@@ -32,7 +33,7 @@ public class LinkCreationTest extends GeneratedCanvasTest {
private Node myNodeB;
public LinkCreationTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
}
protected void setUp() throws Exception {
@@ -354,7 +355,7 @@ public class LinkCreationTest extends GeneratedCanvasTest {
EStructuralFeature linkFeature = linkSource.eClass().getEStructuralFeature(facet.getMetaFeature().getName());
assertNotNull(linkFeature);
Object linked = linkSource.eGet(linkFeature);
- if (linked instanceof Collection) {
+ if (linked instanceof Collection<?>) {
assertTrue("Link element was not added to the container", ((Collection<?>) linked).contains(linkTarget));
} else {
assertEquals("Link element was not added to the container", linkTarget, linked);
@@ -371,7 +372,7 @@ public class LinkCreationTest extends GeneratedCanvasTest {
EStructuralFeature containmentFeature = linkSource.eClass().getEStructuralFeature(facet.getContainmentMetaFeature().getName());
assertNotNull(containmentFeature);
Object contained = linkSource.eGet(containmentFeature);
- if (contained instanceof Collection) {
+ if (contained instanceof Collection<?>) {
assertTrue("Link element was not added to the container", ((Collection<?>) contained).contains(linkElement));
} else {
assertEquals("Link element was not added to the container", linkElement, contained);
@@ -380,7 +381,7 @@ public class LinkCreationTest extends GeneratedCanvasTest {
EStructuralFeature sourceFeature = linkElement.eClass().getEStructuralFeature(facet.getSourceMetaFeature().getName());
assertNotNull(sourceFeature);
Object sources = linkElement.eGet(sourceFeature);
- if (sources instanceof Collection) {
+ if (sources instanceof Collection<?>) {
assertTrue("Link source was not set correctly", ((Collection<?>) sources).contains(linkSource));
} else {
assertEquals("Link source was not set correctly", linkSource, sources);
@@ -390,7 +391,7 @@ public class LinkCreationTest extends GeneratedCanvasTest {
EStructuralFeature targetFeature = linkElement.eClass().getEStructuralFeature(facet.getTargetMetaFeature().getName());
assertNotNull(targetFeature);
Object targets = linkElement.eGet(targetFeature);
- if (targets instanceof Collection) {
+ if (targets instanceof Collection<?>) {
assertTrue("Link target was not set correctly", ((Collection<?>) targets).contains(linkTarget));
} else {
assertEquals("Link target was not set correctly", linkTarget, targets);
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkEcoreConstraintsTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkEcoreConstraintsTest.java
index 797f7bb13..8b3b57e18 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkEcoreConstraintsTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/LinkEcoreConstraintsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008 Borland Software Corporation
+ * Copyright (c) 2008, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -91,7 +91,7 @@ public class LinkEcoreConstraintsTest extends GeneratedCanvasTest {
};
public LinkEcoreConstraintsTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
}
@Override
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/MetricRulesTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/MetricRulesTest.java
index 2084f4203..60674f586 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/MetricRulesTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/MetricRulesTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008 Borland Software Corporation
+ * Copyright (c) 2005, 2010 Borland Software Corporation 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
@@ -21,6 +21,7 @@ import org.eclipse.gmf.codegen.gmfgen.GenMetricContainer;
import org.eclipse.gmf.codegen.gmfgen.GenMetricRule;
import org.eclipse.gmf.mappings.MetricContainer;
import org.eclipse.gmf.tests.setup.LinksSessionSetup;
+import org.eclipse.gmf.tests.setup.RuntimeBasedGeneratorConfiguration;
/**
* TODO: need to validate that not only calcXXX methods are present and work,
@@ -31,7 +32,7 @@ public class MetricRulesTest extends GeneratedCanvasTest {
private GenMetricContainer genMetricContainer;
public MetricRulesTest(String name) {
- super(name);
+ super(name, new RuntimeBasedGeneratorConfiguration());
myDefaultSetup = LinksSessionSetup.newInstance();
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/PaletteTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/PaletteTest.java
index e7c9145cf..028185f44 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/PaletteTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/rt/PaletteTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009 Borland Software Corporation
+ * Copyright (c) 2009, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -15,7 +15,6 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-import org.eclipse.gef.palette.CreationToolEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gef.palette.PaletteRoot;
@@ -30,7 +29,7 @@ public class PaletteTest extends GeneratedCanvasTest {
public PaletteTest(String name) {
- super(name);
+ super(name, null /* as long as we don't use ViewerConfiguration below to instantiate palette */);
myDefaultSetup = SessionSetup.newInstance();
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/AbstractGeneratorConfiguration.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/AbstractGeneratorConfiguration.java
index 4e3633964..4ac298762 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/AbstractGeneratorConfiguration.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/AbstractGeneratorConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2009 Borland Software Corporation
+ * Copyright (c) 2006, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -13,6 +13,8 @@ package org.eclipse.gmf.tests.setup;
import java.lang.reflect.Field;
+import junit.framework.Assert;
+
import org.eclipse.draw2d.DelegatingLayout;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.LayeredPane;
@@ -41,17 +43,21 @@ import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.osgi.framework.Bundle;
-public abstract class AbstractGeneratorConfiguration implements GeneratorConfiguration {
+public abstract class AbstractGeneratorConfiguration implements GeneratorConfiguration, ViewerConfiguration.Factory {
- public ViewerConfiguration createViewerConfiguration(Composite parent, SessionSetup sessionSetup, Diagram canvas) throws Exception {
- EditPartViewer viewer = createViewer(parent, sessionSetup, canvas);
- return createViewerConfiguration(viewer, sessionSetup.getGenModel().getGenDiagram(), sessionSetup.getGenProject().getBundle());
+ public ViewerConfiguration createViewerConfiguration(Composite parent, Diagram canvas, GeneratedDiagramPlugin genPlugin) {
+ try {
+ EditPartViewer viewer = createViewer(parent, canvas, genPlugin);
+ return createViewerConfiguration(viewer, genPlugin);
+ } catch (Exception ex) {
+ Assert.fail(ex.toString());
+ }
+ return null;
}
- public EditPartViewer createViewer(Composite parent, SessionSetup sessionSetup, Diagram canvas) throws Exception {
+ public EditPartViewer createViewer(Composite parent, Diagram canvas, GeneratedDiagramPlugin genPlugin) throws Exception {
// make sure there's display for current thread
Display.getDefault();
@@ -61,8 +67,8 @@ public abstract class AbstractGeneratorConfiguration implements GeneratorConfigu
gv.setEditDomain(ded);
gv.getEditDomain().setCommandStack(new DiagramCommandStack(ded));
- String epFactoryClassName = sessionSetup.getGenModel().getGenDiagram().getEditPartFactoryQualifiedClassName();
- Class<?> epFactory = sessionSetup.loadGeneratedClass(epFactoryClassName);
+ String epFactoryClassName = genPlugin.getGenDiagram().getEditPartFactoryQualifiedClassName();
+ Class<?> epFactory = genPlugin.loadGeneratedClass(epFactoryClassName);
assert EditPartFactory.class.isAssignableFrom(epFactory);
gv.setEditPartFactory((EditPartFactory) epFactory.newInstance());
gv.setContents(canvas);
@@ -75,14 +81,12 @@ public abstract class AbstractGeneratorConfiguration implements GeneratorConfigu
protected static abstract class AbstractViewerConfiguration implements ViewerConfiguration {
private final EditPartViewer myViewer;
- private final GenDiagram myDiagramModel;
- private final Bundle myGenProject;
+ private final GeneratedDiagramPlugin myGeneratedPlugin;
private PreferencesHint myDefaultPreferences;
- public AbstractViewerConfiguration(EditPartViewer viewer, GenDiagram model, Bundle genPlugin) {
+ public AbstractViewerConfiguration(EditPartViewer viewer, GeneratedDiagramPlugin genPlugin) {
myViewer = viewer;
- myDiagramModel = model;
- myGenProject = genPlugin;
+ myGeneratedPlugin = genPlugin;
}
public EditPartViewer getViewer() {
@@ -102,12 +106,12 @@ public abstract class AbstractGeneratorConfiguration implements GeneratorConfigu
return result;
}
- protected final Class<?> loadGeneratedClass(String qualifiedClassName) throws ClassNotFoundException {
- return myGenProject.loadClass(qualifiedClassName);
+ protected final Class<?> loadGeneratedClass(String qualifiedClassName) throws Exception {
+ return myGeneratedPlugin.loadGeneratedClass(qualifiedClassName);
}
protected GenDiagram getGenModel() {
- return myDiagramModel;
+ return myGeneratedPlugin.getGenDiagram();
}
protected IPreferenceStore getDefaultPreferences() {
@@ -117,16 +121,10 @@ public abstract class AbstractGeneratorConfiguration implements GeneratorConfigu
protected PreferencesHint getDefaultPreferencesHint() {
if (myDefaultPreferences == null){
try {
- Class<?> activatorClazz = loadGeneratedClass(myDiagramModel.getEditorGen().getPlugin().getActivatorQualifiedClassName());
+ Class<?> activatorClazz = loadGeneratedClass(myGeneratedPlugin.getGenDiagram().getEditorGen().getPlugin().getActivatorQualifiedClassName());
Field field = activatorClazz.getField("DIAGRAM_PREFERENCES_HINT");
myDefaultPreferences = (PreferencesHint)field.get(null);
- } catch (ClassNotFoundException e) {
- myDefaultPreferences = PreferencesHint.USE_DEFAULTS;
- } catch (SecurityException e) {
- myDefaultPreferences = PreferencesHint.USE_DEFAULTS;
- } catch (NoSuchFieldException e) {
- myDefaultPreferences = PreferencesHint.USE_DEFAULTS;
- } catch (IllegalAccessException e) {
+ } catch (Exception e) {
myDefaultPreferences = PreferencesHint.USE_DEFAULTS;
}
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratedDiagramPlugin.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratedDiagramPlugin.java
new file mode 100644
index 000000000..1ca11bed5
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratedDiagramPlugin.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2010 Artem Tikhomirov
+ *
+ * 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:
+ * Artem Tikhomirov (independent) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.setup;
+
+import org.eclipse.gmf.codegen.gmfgen.GenDiagram;
+
+/**
+ * Front-end for generated GMF diagram editor.
+ * @author artem
+ */
+public interface GeneratedDiagramPlugin {
+
+ /**
+ * This is the generator input for the generated editor
+ */
+ GenDiagram getGenDiagram();
+
+ /**
+ * Access to generated diagram classes (names should be obtained from {@link #getGenDiagram()}
+ */
+ Class<?> loadGeneratedClass(String qualifiedClassName) throws Exception;
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratorConfiguration.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratorConfiguration.java
index 10045c4de..beccc64b8 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratorConfiguration.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/GeneratorConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2008 Borland Software Corporation
+ * Copyright (c) 2006, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,44 +11,9 @@
*/
package org.eclipse.gmf.tests.setup;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.codegen.gmfgen.GenCommonBase;
import org.eclipse.gmf.codegen.gmfgen.GenDiagram;
-import org.eclipse.gmf.gmfgraph.Font;
import org.eclipse.gmf.internal.common.codegen.GeneratorBase;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Composite;
-import org.osgi.framework.Bundle;
public interface GeneratorConfiguration {
public GeneratorBase createGenerator(GenDiagram diagram);
-
- /**
- * Encapsulates differences in the way viewer is created and operated in different configurations.
- */
- public static interface ViewerConfiguration {
- // XXX is it really different?
- public EditPart findEditPart(View notationElement);
- public EditPartViewer getViewer();
- public Command getCreateNodeCommand(View parentView, GenCommonBase nodeType);
- public Command getStartLinkCommand(View source, GenCommonBase linkType);
- public Command getCreateLinkCommand(View source, View target, GenCommonBase linkType);
- public Command getSetBusinessElementStructuralFeatureCommand(View view, String featureName, Object value);
- public Command getSetNotationalElementStructuralFeature(View view, EStructuralFeature feature, Object value);
-
- public RGB getDefaultLinkColor();
- public Font getDefaultFont();
- }
-
- public ViewerConfiguration createViewerConfiguration(Composite parent, SessionSetup setup, Diagram canvas) throws Exception;
-
- public ViewerConfiguration createViewerConfiguration(EditPartViewer viewer, GenDiagram model, Bundle genProject) throws Exception;
-
- public Diagram createDiagram(EObject domainElement, SessionSetup setup) throws Exception;
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/LinksSessionSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/LinksSessionSetup.java
index 075f2d6d9..8a49e1a3d 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/LinksSessionSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/LinksSessionSetup.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2009 Borland Software Corporation
+ * Copyright (c) 2005, 2010 Borland Software Corporation 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
@@ -80,8 +80,8 @@ public class LinksSessionSetup extends SessionSetup {
}
@Override
- protected GenProjectSetup createGenProject() throws BundleException {
- GenProjectSetup genProjectSetup = super.createGenProject();
+ protected GenProjectSetup createGenProject(GeneratorConfiguration generatorConfiguration) throws BundleException {
+ GenProjectSetup genProjectSetup = super.createGenProject(generatorConfiguration);
assertValid("Test gmfmap model must be valid", EcoreUtil.getRootContainer(getMapModel().getMapping())); //$NON-NLS-1$
// assertValid("Test gmfgen model must be valid", EcoreUtil.getRootContainer(getGenModel().getGenDiagram())); //$NON-NLS-1$
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeBasedGeneratorConfiguration.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeBasedGeneratorConfiguration.java
index 2d2962a21..c708d9e2e 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeBasedGeneratorConfiguration.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeBasedGeneratorConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2008 Borland Software Corporation
+ * Copyright (c) 2006, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -61,7 +61,6 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.swt.graphics.RGB;
-import org.osgi.framework.Bundle;
public class RuntimeBasedGeneratorConfiguration extends AbstractGeneratorConfiguration {
@@ -73,29 +72,31 @@ public class RuntimeBasedGeneratorConfiguration extends AbstractGeneratorConfigu
return new Generator(editorGen, new CodegenEmitters(!editorGen.isDynamicTemplates(), editorGen.getTemplateDirectory(), editorGen.getModelAccess() != null));
}
- public ViewerConfiguration createViewerConfiguration(EditPartViewer viewer, GenDiagram model, Bundle genPlugin) throws Exception {
- return new DefaultViewerConfiguration(viewer, model, genPlugin);
+ public ViewerConfiguration createViewerConfiguration(EditPartViewer viewer, GeneratedDiagramPlugin genPlugin) {
+ return new DefaultViewerConfiguration(viewer, genPlugin);
}
protected EditPartViewer createViewerInstance() {
return new FakeViewer();
}
- /* (non-Javadoc)
- * @see org.eclipse.gmf.tests.setup.GeneratorConfiguration#createDiagram(org.eclipse.emf.ecore.EObject)
- */
- public Diagram createDiagram(EObject domainElement, SessionSetup sessionSetup) throws Exception {
- String pluginClassName = sessionSetup.getGenModel().getGenDiagram().getEditorGen().getPlugin().getActivatorQualifiedClassName();
- Class<?> pluginClass = sessionSetup.getGenProject().getBundle().loadClass(pluginClassName);
- Field field = pluginClass.getField("DIAGRAM_PREFERENCES_HINT");
- final PreferencesHint hint = (PreferencesHint) field.get(null);
- return ViewService.createDiagram(domainElement, sessionSetup.getGenModel().getGenDiagram().getEditorGen().getModelID(), hint);
+ public static Diagram createDiagram(EObject domainElement, GeneratedDiagramPlugin genPlugin) {
+ try {
+ String pluginClassName = genPlugin.getGenDiagram().getEditorGen().getPlugin().getActivatorQualifiedClassName();
+ Class<?> pluginClass = genPlugin.loadGeneratedClass(pluginClassName);
+ Field field = pluginClass.getField("DIAGRAM_PREFERENCES_HINT");
+ final PreferencesHint hint = (PreferencesHint) field.get(null);
+ return ViewService.createDiagram(domainElement, genPlugin.getGenDiagram().getEditorGen().getModelID(), hint);
+ } catch (Exception ex) {
+ Assert.fail(ex.toString());
+ }
+ return null;
}
protected static class DefaultViewerConfiguration extends AbstractViewerConfiguration {
- public DefaultViewerConfiguration(EditPartViewer viewer, GenDiagram model, Bundle genPlugin) throws Exception {
- super(viewer, model, genPlugin);
+ public DefaultViewerConfiguration(EditPartViewer viewer, GeneratedDiagramPlugin genPlugin) {
+ super(viewer, genPlugin);
}
public Command getSetBusinessElementStructuralFeatureCommand(View view, String featureName, Object value) {
@@ -147,9 +148,6 @@ public class RuntimeBasedGeneratorConfiguration extends AbstractGeneratorConfigu
return findEditPart(source).getCommand(wrapper);
}
- /* (non-Javadoc)
- * @see org.eclipse.gmf.tests.setup.GeneratorConfiguration.ViewerConfiguration#getCreateLinkCommand(org.eclipse.gmf.runtime.notation.View, org.eclipse.gmf.runtime.notation.View, org.eclipse.gmf.codegen.gmfgen.GenCommonBase)
- */
public Command getCreateLinkCommand(View source, View target, GenCommonBase linkType) {
IElementType metamodelType = getElementType(linkType);
CreateRelationshipRequest relationShipReq = new CreateRelationshipRequest(metamodelType);
@@ -226,7 +224,7 @@ public class RuntimeBasedGeneratorConfiguration extends AbstractGeneratorConfigu
return (IDiagramEditDomain) super.getEditDomain();
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public List findEditPartsForElement(String elementIdStr, Class editPartClass) {
return Collections.EMPTY_LIST;
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java
index 52301563c..eba572d53 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2008 Borland Software Corporation
+ * Copyright (c) 2005, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,6 +11,7 @@
*/
package org.eclipse.gmf.tests.setup;
+import org.eclipse.gmf.codegen.gmfgen.GenDiagram;
import org.eclipse.gmf.tests.TestConfiguration;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
@@ -18,7 +19,7 @@ import org.osgi.framework.BundleException;
/**
* @author artem
*/
-public class SessionSetup implements TestConfiguration {
+public class SessionSetup implements TestConfiguration, GeneratedDiagramPlugin {
private DomainModelSource myDomainModel;
private DiaGenSource myGenModel;
@@ -80,17 +81,13 @@ public class SessionSetup implements TestConfiguration {
protected GenProjectSetup getGenProject() throws Exception {
if (myProject == null) {
- myProject = createGenProject();
+ myProject = createGenProject(myGeneratorConfig);
}
return myProject;
}
- protected GenProjectSetup createGenProject() throws BundleException {
- return new GenProjectSetup(getGeneratorConfiguration()).init(getGenModel());
- }
-
- public GeneratorConfiguration getGeneratorConfiguration() {
- return myGeneratorConfig;
+ protected GenProjectSetup createGenProject(GeneratorConfiguration generatorConfiguration) throws BundleException {
+ return new GenProjectSetup(generatorConfiguration).init(getGenModel());
}
public MapDefSource getMapModel() {
@@ -133,15 +130,19 @@ public class SessionSetup implements TestConfiguration {
}
}
+ public final Bundle getGeneratedPlugin() throws Exception {
+ return getGenProject().getBundle();
+ }
+
+ public GenDiagram getGenDiagram() {
+ return getGenModel().getGenDiagram();
+ }
+
public final Class<?> loadGeneratedClass(String qualifiedClassName) throws Exception {
// move to GenProjectSetup?
return getGeneratedPlugin().loadClass(qualifiedClassName);
}
- public final Bundle getGeneratedPlugin() throws Exception {
- return getGenProject().getBundle();
- }
-
// FUTURE: automatically unload/cleanup when myUses goes to zero.
public void oneUp() {
myUses++;
@@ -149,5 +150,5 @@ public class SessionSetup implements TestConfiguration {
public void oneDown() {
myUses--;
- }
+ }
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ViewerConfiguration.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ViewerConfiguration.java
new file mode 100644
index 000000000..0ca6d35e0
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ViewerConfiguration.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006, 2010 Borland Software Corporation 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:
+ * Boris Blajer (Borland) - initial API and implementation
+ * Artem Tikhomirov (independent) - extracted out from GeneratorConfiguration
+ */
+package org.eclipse.gmf.tests.setup;
+
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.codegen.gmfgen.GenCommonBase;
+import org.eclipse.gmf.gmfgraph.Font;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Encapsulates differences in the way viewer is created and operated in different configurations.
+ */
+public interface ViewerConfiguration {
+ // XXX is it really different?
+ public EditPart findEditPart(View notationElement);
+ public EditPartViewer getViewer();
+ public Command getCreateNodeCommand(View parentView, GenCommonBase nodeType);
+ public Command getStartLinkCommand(View source, GenCommonBase linkType);
+ public Command getCreateLinkCommand(View source, View target, GenCommonBase linkType);
+ public Command getSetBusinessElementStructuralFeatureCommand(View view, String featureName, Object value);
+ public Command getSetNotationalElementStructuralFeature(View view, EStructuralFeature feature, Object value);
+
+ public RGB getDefaultLinkColor();
+ public Font getDefaultFont();
+
+ interface Factory {
+ ViewerConfiguration createViewerConfiguration(Composite parent, Diagram canvas, GeneratedDiagramPlugin genPlugin);
+ ViewerConfiguration createViewerConfiguration(EditPartViewer viewer, GeneratedDiagramPlugin genPlugin);
+ }
+} \ No newline at end of file

Back to the top