### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.tests Index: src/org/eclipse/gmf/tests/setup/RTSetup.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RTSetup.java,v retrieving revision 1.27 diff -u -r1.27 RTSetup.java --- src/org/eclipse/gmf/tests/setup/RTSetup.java 19 Jun 2006 12:42:00 -0000 1.27 +++ src/org/eclipse/gmf/tests/setup/RTSetup.java 19 Jun 2006 16:47:28 -0000 @@ -105,7 +105,13 @@ FeatureLinkModelFacet byRefFacet = (FeatureLinkModelFacet) genSource.getLinkD().getModelFacet(); Assert.assertNotNull(byRefFacet); - instanceProducer.setFeatureValue(myNodeA.getElement(), myNodeB.getElement(), byRefFacet.getMetaFeature()); + EStructuralFeature metaFeature = byRefFacet.getMetaFeature().getEcoreFeature(); + //The direction of the link is unspecified, could be from A to B or vice versa + if (myNodeA.eClass().getEAllStructuralFeatures().contains(metaFeature)) { + instanceProducer.setFeatureValue(myNodeA.getElement(), myNodeB.getElement(), byRefFacet.getMetaFeature()); + } else if (myNodeB.eClass().getEAllStructuralFeatures().contains(metaFeature)) { + instanceProducer.setFeatureValue(myNodeB.getElement(), myNodeA.getElement(), byRefFacet.getMetaFeature()); + } myLinkByRef = NotationFactory.eINSTANCE.createEdge(); myCanvas.getPersistedEdges().add(myLinkByRef); myLinkByRef.setType(String.valueOf(genSource.getLinkD().getVisualID())); #P org.eclipse.gmf.tests.lite Index: src/org/eclipse/gmf/tests/lite/Activator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/Activator.java,v retrieving revision 1.1 diff -u -r1.1 Activator.java --- src/org/eclipse/gmf/tests/lite/Activator.java 22 May 2006 18:14:09 -0000 1.1 +++ src/org/eclipse/gmf/tests/lite/Activator.java 19 Jun 2006 16:47:35 -0000 @@ -11,7 +11,10 @@ */ package org.eclipse.gmf.tests.lite; +import java.io.IOException; + import org.eclipse.core.runtime.Plugin; +import org.eclipse.emf.common.util.URI; import org.osgi.framework.BundleContext; /** @@ -49,6 +52,11 @@ super.stop(context); } + public static URI createURI(String bundledFileName) throws IOException { + assert bundledFileName.charAt(0) == '/'; + return URI.createURI("platform:/plugin/" + getDefault().getBundle().getSymbolicName() + bundledFileName); + } + /** * Returns the shared instance * Index: src/org/eclipse/gmf/tests/lite/AllTests.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests.lite/src/org/eclipse/gmf/tests/lite/AllTests.java,v retrieving revision 1.4 diff -u -r1.4 AllTests.java --- src/org/eclipse/gmf/tests/lite/AllTests.java 5 Jun 2006 13:36:00 -0000 1.4 +++ src/org/eclipse/gmf/tests/lite/AllTests.java 19 Jun 2006 16:47:35 -0000 @@ -15,9 +15,11 @@ import org.eclipse.gmf.tests.gef.DiagramNodeTest; import org.eclipse.gmf.tests.lite.gef.DiagramElementTest; import org.eclipse.gmf.tests.lite.gef.DiagramLinksTest; +import org.eclipse.gmf.tests.lite.gef.NotationRefreshTest; import org.eclipse.gmf.tests.lite.gen.LiteCompilationTest; import org.eclipse.gmf.tests.lite.gen.RCPLiteCompilationTest; import org.eclipse.gmf.tests.lite.rt.ElementInitializerTest; +import org.eclipse.gmf.tests.lite.setup.LibraryConstrainedSetup; import org.eclipse.gmf.tests.lite.setup.LiteLinksSessionSetup; import org.eclipse.gmf.tests.lite.setup.LiteSessionSetup; import org.eclipse.gmf.tests.rt.LinkCreationConstraintsTest; @@ -36,6 +38,7 @@ final SessionSetup sessionSetup = LiteSessionSetup.getInstance(); final LinksSessionSetup sessionSetup2 = LiteLinksSessionSetup.getInstance(); + final LibraryConstrainedSetup sessionSetup3 = LibraryConstrainedSetup.getInstance(); SessionSetup.disallowSingleTestCaseUse(); suite.addTest(feed(DiagramNodeTest.class, sessionSetup)); @@ -43,12 +46,14 @@ suite.addTest(feed(DiagramLinksTest.class, sessionSetup2)); suite.addTest(feed(ElementInitializerTest.class, sessionSetup2)); suite.addTest(feed(LinkCreationConstraintsTest.class, sessionSetup2)); + suite.addTest(feed(NotationRefreshTest.class, sessionSetup3)); suite.addTest(new TestCase("testCleanup") { protected void runTest() throws Throwable { try { sessionSetup.cleanup(); sessionSetup2.cleanup(); + sessionSetup3.cleanup(); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { Index: models/library/library.ecore =================================================================== RCS file: models/library/library.ecore diff -N models/library/library.ecore --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/library/library.ecore 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,68 @@ + + + + +
+ + + + + + + +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + Index: models/library/library_constrained.gmfgen =================================================================== RCS file: models/library/library_constrained.gmfgen diff -N models/library/library_constrained.gmfgen --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/library/library_constrained.gmfgen 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,354 @@ + + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + + + org.eclipse.draw2d + + + + + + + + + org.eclipse.draw2d + + + + + + org.eclipse.draw2d + + + + + + + + + org.eclipse.emf.ocl + org.eclipse.emf.query.ocl + + + Index: src/org/eclipse/gmf/tests/lite/setup/LibraryConstrainedSetup.java =================================================================== RCS file: src/org/eclipse/gmf/tests/lite/setup/LibraryConstrainedSetup.java diff -N src/org/eclipse/gmf/tests/lite/setup/LibraryConstrainedSetup.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/tests/lite/setup/LibraryConstrainedSetup.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2006 Eclipse.org + * + * 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: + * bblajer - initial API and implementation + */ +package org.eclipse.gmf.tests.lite.setup; + +import java.io.IOException; + +import junit.framework.Assert; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.gmf.tests.EPath; +import org.eclipse.gmf.tests.lite.Activator; +import org.eclipse.gmf.tests.lite.gen.LiteGeneratorConfiguration; +import org.eclipse.gmf.tests.setup.DiaGenFileSetup; +import org.eclipse.gmf.tests.setup.DiaGenSource; +import org.eclipse.gmf.tests.setup.DomainModelFileSetup; +import org.eclipse.gmf.tests.setup.DomainModelSource; +import org.eclipse.gmf.tests.setup.GeneratorConfiguration; +import org.eclipse.gmf.tests.setup.MapDefFileSetup; +import org.eclipse.gmf.tests.setup.MapDefSource; +import org.eclipse.gmf.tests.setup.SessionSetup; + +public class LibraryConstrainedSetup extends SessionSetup { + private static String modelURI = "/models/library/library.ecore"; //$NON-NLS-1$ + private static String mapURI = "/models/library/library_constrained.gmfmap"; //$NON-NLS-1$ + private static String genURI = "/models/library/library_constrained.gmfgen"; //$NON-NLS-1$ + + protected LibraryConstrainedSetup() { + } + + public static LibraryConstrainedSetup getInstance() { + if (factoryClosed) { + return null; + } + return new LibraryConstrainedSetup(); + } + + protected DomainModelSource createDomainModel() { + DomainModelFileSetup modelSetup = new DomainModelFileSetup() { + public EClass getDiagramElement() { + return (EClass) EPath.ECORE.lookup(getModel(), "Library"); //$NON-NLS-1$ + } + public NodeData getNodeA() { + EClass n = (EClass) EPath.ECORE.lookup(getModel(), "Writer"); //$NON-NLS-1$ + EReference c = (EReference) EPath.ECORE.lookup(getModel(), "Library::writers"); //$NON-NLS-1$ + return new NodeData(n, null, c); + } + public NodeData getNodeB() { + EClass n = (EClass) EPath.ECORE.lookup(getModel(), "Book"); //$NON-NLS-1$ + EReference c = (EReference) EPath.ECORE.lookup(getModel(), "Library::books"); //$NON-NLS-1$ + return new NodeData(n, null, c); + } + public EReference getLinkAsRef() { + return (EReference) EPath.ECORE.lookup(getModel(), "Book::author"); //$NON-NLS-1$ + } + public LinkData getLinkAsClass() { + EClass l = (EClass) EPath.ECORE.lookup(getModel(), "Opinion"); //$NON-NLS-1$ + EReference t = (EReference) EPath.ECORE.lookup(getModel(), "Opinion::book"); //$NON-NLS-1$ + EReference c = (EReference) EPath.ECORE.lookup(getModel(), "Writer::opinions"); //$NON-NLS-1$ + return new LinkData(l, t, c); + } + }; + try { + modelSetup.init(Activator.createURI(modelURI)); + } catch (IOException e) { + e.printStackTrace(); + Assert.fail("Failed to setup the domain model. " + e.getLocalizedMessage()); //$NON-NLS-1$ + } + return modelSetup; + } + + protected MapDefSource createMapModel() { + MapDefFileSetup mapSetup = new MapDefFileSetup() { + }; + try { + mapSetup.init(Activator.createURI(mapURI)); + } catch (IOException e) { + e.printStackTrace(); + Assert.fail("Failed to setup the gmfmap. " + e.getLocalizedMessage()); //$NON-NLS-1$ + } + return mapSetup; + } + + protected DiaGenSource createGenModel() { + DiaGenFileSetup genSetup = new DiaGenFileSetup() { + }; + try { + genSetup.init(Activator.createURI(genURI)); + } catch (IOException e) { + e.printStackTrace(); + Assert.fail("Failed to setup the gmfmap. " + e.getLocalizedMessage()); //$NON-NLS-1$ + } + return genSetup; + } + + protected GeneratorConfiguration createGeneratorConfiguration() { + return new LiteGeneratorConfiguration(); + } +} Index: models/library/library_constrained.gmfmap =================================================================== RCS file: models/library/library_constrained.gmfmap diff -N models/library/library_constrained.gmfmap --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/library/library_constrained.gmfmap 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/org/eclipse/gmf/tests/lite/gef/NotationRefreshTest.java =================================================================== RCS file: src/org/eclipse/gmf/tests/lite/gef/NotationRefreshTest.java diff -N src/org/eclipse/gmf/tests/lite/gef/NotationRefreshTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/tests/lite/gef/NotationRefreshTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2006 Eclipse.org + * + * 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: + * bblajer - initial API and implementation + */ +package org.eclipse.gmf.tests.lite.gef; + +import java.util.Iterator; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.util.TransactionUtil; +import org.eclipse.emf.workspace.EMFCommandOperation; +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.notation.Bounds; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.tests.rt.RuntimeDiagramTestBase; + +public class NotationRefreshTest extends RuntimeDiagramTestBase { + public NotationRefreshTest(String name) { + super(name); + } + + public void testNotationRefreshOnDeleteNode() throws Exception { + EditPart diagramEP = getDiagramEditPart(); + Diagram diagram = (Diagram) diagramEP.getModel(); + EObject diagramElement = diagram.getElement(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(diagramElement); + View nodeA = getCanvasInstance().getNodeA(); + EObject elementA = nodeA.getElement(); + EditPart editPartA = findEditPart(nodeA); + Command command = RemoveCommand.create(editingDomain, elementA.eContainer(), elementA.eContainingFeature(), elementA); + assertTrue("Failed to obtain command to remove an instance of the domain model element", command != null && command.canExecute()); + new EMFCommandOperation(editingDomain, command).execute(new NullProgressMonitor(), null); + assertNull("RemoveCommand not executed properly", elementA.eContainer()); + assertNull("Notational refresh failed on domain element removal", findView(diagram, elementA)); + assertNull("EditPart not removed automatically", findEditPart(nodeA)); + assertFalse(editPartA.isActive()); + } + + public void testNotationRefreshOnCreateNode() throws Exception { + EditPart diagramEP = getDiagramEditPart(); + Diagram diagram = (Diagram) diagramEP.getModel(); + EObject diagramElement = diagram.getElement(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(diagramElement); + EStructuralFeature feature = getCanvasInstance().getNodeA().getElement().eContainmentFeature(); + EClass newChildClass = getCanvasInstance().getNodeA().getElement().eClass(); + EObject newChild = newChildClass.getEPackage().getEFactoryInstance().create(newChildClass); + + Command command = AddCommand.create(editingDomain, diagramElement, feature, newChild); + assertTrue("Failed to obtain command to create a new instance of the domain model element", command != null && command.canExecute()); + new EMFCommandOperation(editingDomain, command).execute(new NullProgressMonitor(), null); + assertSame("AddCommand not executed properly", diagramElement, newChild.eContainer()); + View newChildView = findView(diagram, newChild); + assertNotNull("Notational refresh failed on domain element creation", newChildView); + int visualId = getType(newChildView); + assertEquals(getGenModel().getNodeA().getVisualID(), visualId); + EditPart newChildEP = findEditPart(newChildView); + assertNotNull("EditPart not created automatically", newChildEP); + } + + public void testNotationRefreshOnAttributeChangeThatAffectsSelector() throws Exception { + EditPart diagramEP = getDiagramEditPart(); + Diagram diagram = (Diagram) diagramEP.getModel(); + EObject diagramElement = diagram.getElement(); + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(diagramElement); + Node nodeB = getCanvasInstance().getNodeB(); + Bounds bounds = (Bounds) nodeB.getLayoutConstraint(); + Rectangle rectangle = new Rectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()); + assertEquals("Unexpected visual ID of the element", getGenModel().getNodeB().getVisualID(), getType(nodeB)); + EObject elementB = nodeB.getElement(); + EditPart editPartB = findEditPart(nodeB); + EClass elementBClass = elementB.eClass(); + EStructuralFeature feature = elementBClass.getEStructuralFeature("pages"); //$NON-NLS-1$ + assertNotNull("Failed to find the feature that affects selector", feature); + Integer newValue = new Integer(200); + Command command = SetCommand.create(editingDomain, elementB, feature, newValue); + assertTrue("Failed to obtain command to make a change that affects selector", command != null && command.canExecute()); + new EMFCommandOperation(editingDomain, command).execute(new NullProgressMonitor(), null); + assertEquals("SetCommand not executed properly", newValue, elementB.eGet(feature)); + Node newNodeB = (Node) findView(diagram, elementB); + assertNotNull("Notational refresh failed to recreate a new node upon a change that affects selector", newNodeB); + assertNotSame("Notational refresh failed to replace a new node upon a change that affects selector", nodeB, newNodeB); + assertTrue("Notational refresh failed to change visual ID of the element upon a change that affects selector", getGenModel().getNodeB().getVisualID() != getType(newNodeB)); + EditPart newEditPartB = findEditPart(newNodeB); + assertNotNull("EditPart not recreated automatically", newEditPartB); + assertNotSame("EditPart not replaced automatically", editPartB, newEditPartB); + assertFalse(editPartB.isActive()); + assertTrue(newEditPartB.isActive()); + Bounds newBounds = (Bounds) newNodeB.getLayoutConstraint(); + Rectangle newRectangle = new Rectangle(newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight()); + assertEquals("Notational refresh failed to position the new node where the old one was", rectangle, newRectangle); + } + + private int getType(View view) { + return Integer.parseInt(view.getType()); + } + + private View findView(View container, EObject child) { + for(Iterator it = container.getChildren().iterator(); it.hasNext(); ) { + View next = (View) it.next(); + if (child.equals(next.getElement())) { + return next; + } + } + return null; + } +} Index: models/library/library.genmodel =================================================================== RCS file: models/library/library.genmodel diff -N models/library/library.genmodel --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ models/library/library.genmodel 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,44 @@ + + + C:\library.mdl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +