### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.graphdef Index: src/org/eclipse/gmf/gmfgraph/util/RuntimeFQNSwitch.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef/src/org/eclipse/gmf/gmfgraph/util/RuntimeFQNSwitch.java,v retrieving revision 1.2 diff -u -r1.2 RuntimeFQNSwitch.java --- src/org/eclipse/gmf/gmfgraph/util/RuntimeFQNSwitch.java 13 Mar 2006 17:53:14 -0000 1.2 +++ src/org/eclipse/gmf/gmfgraph/util/RuntimeFQNSwitch.java 23 Mar 2006 15:31:10 -0000 @@ -64,6 +64,9 @@ if (usesPolylineConnections(gallery)) { rv.add(pluginRuntimeDraw2d); } + if (gallery.getImplementationBundle() != null){ + rv.add(gallery.getImplementationBundle()); + } return rv.toArray(new String[rv.size()]); } #P org.eclipse.gmf.graphdef.codegen Index: templates/plugin/manifest.mfjet =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/templates/plugin/manifest.mfjet,v retrieving revision 1.1 diff -u -r1.1 manifest.mfjet --- templates/plugin/manifest.mfjet 2 Mar 2006 13:16:15 -0000 1.1 +++ templates/plugin/manifest.mfjet 23 Mar 2006 15:31:11 -0000 @@ -28,6 +28,7 @@ Bundle-SymbolicName: <%=config.getPluginID()%>; singleton:=true Bundle-Version: 1.0.0 Bundle-Vendor: %providerName +Bundle-Activator: <%=config.getPluginActivatorPackageName()%>.<%=config.getPluginActivatorClassName()%> Bundle-Localization: plugin <% HashSet exportedPackages = new HashSet(); Index: src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java,v retrieving revision 1.1 diff -u -r1.1 ManifestMFGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java 2 Mar 2006 13:16:15 -0000 1.1 +++ src/org/eclipse/gmf/graphdef/codegen/standalone/templates/ManifestMFGenerator.java 23 Mar 2006 15:31:11 -0000 @@ -16,11 +16,13 @@ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = "Manifest-Version: 1.0" + NL + "Bundle-ManifestVersion: 2" + NL + "Bundle-Name: %pluginName" + NL + "Bundle-SymbolicName: "; - protected final String TEXT_2 = "; singleton:=true" + NL + "Bundle-Version: 1.0.0" + NL + "Bundle-Vendor: %providerName" + NL + "Bundle-Localization: plugin"; - protected final String TEXT_3 = NL + "Export-Package: "; - protected final String TEXT_4 = NL + "Require-Bundle: "; - protected final String TEXT_5 = NL + "Eclipse-LazyStart: true"; - protected final String TEXT_6 = NL; + protected final String TEXT_2 = "; singleton:=true" + NL + "Bundle-Version: 1.0.0" + NL + "Bundle-Vendor: %providerName" + NL + "Bundle-Activator: "; + protected final String TEXT_3 = "."; + protected final String TEXT_4 = NL + "Bundle-Localization: plugin"; + protected final String TEXT_5 = NL + "Export-Package: "; + protected final String TEXT_6 = NL + "Require-Bundle: "; + protected final String TEXT_7 = NL + "Eclipse-LazyStart: true"; + protected final String TEXT_8 = NL; public String generate(Object argument) { @@ -50,12 +52,16 @@ stringBuffer.append(TEXT_1); stringBuffer.append(config.getPluginID()); stringBuffer.append(TEXT_2); + stringBuffer.append(config.getPluginActivatorPackageName()); + stringBuffer.append(TEXT_3); + stringBuffer.append(config.getPluginActivatorClassName()); + stringBuffer.append(TEXT_4); HashSet exportedPackages = new HashSet(); exportedPackages.add(config.getMainPackageName()); exportedPackages.add(config.getPluginActivatorPackageName()); - stringBuffer.append(TEXT_3); + stringBuffer.append(TEXT_5); stringBuffer.append(listComposer.composeList(exportedPackages)); final Set allRequiredBundles = new LinkedHashSet(); @@ -68,10 +74,10 @@ allRequiredBundles.add("org.eclipse.gmf.runtime.draw2d.ui"); } - stringBuffer.append(TEXT_4); - stringBuffer.append(listComposer.composeList(allRequiredBundles)); - stringBuffer.append(TEXT_5); stringBuffer.append(TEXT_6); + stringBuffer.append(listComposer.composeList(allRequiredBundles)); + stringBuffer.append(TEXT_7); + stringBuffer.append(TEXT_8); return stringBuffer.toString(); } } Index: src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java,v retrieving revision 1.14 diff -u -r1.14 FigureGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java 1 Mar 2006 20:24:39 -0000 1.14 +++ src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java 23 Mar 2006 15:31:11 -0000 @@ -16,6 +16,8 @@ import org.eclipse.gmf.common.codegen.ImportAssistant; import org.eclipse.gmf.gmfgraph.BorderLayout; import org.eclipse.gmf.gmfgraph.BorderLayoutData; +import org.eclipse.gmf.gmfgraph.CustomClass; +import org.eclipse.gmf.gmfgraph.CustomFigure; import org.eclipse.gmf.gmfgraph.CustomLayout; import org.eclipse.gmf.gmfgraph.CustomLayoutData; import org.eclipse.gmf.gmfgraph.Figure; @@ -32,6 +34,7 @@ import org.eclipse.gmf.gmfgraph.XYLayoutData; import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch; import org.eclipse.gmf.graphdef.codegen.templates.CustomClassAttributesGenerator; +import org.eclipse.gmf.graphdef.codegen.templates.CustomFigureAttrGenerator; import org.eclipse.gmf.graphdef.codegen.templates.FigureAttrGenerator; import org.eclipse.gmf.graphdef.codegen.templates.FigureChildrenGenerator; import org.eclipse.gmf.graphdef.codegen.templates.InitBorderLayoutDataGenerator; @@ -134,6 +137,7 @@ tr.put(RoundedRectangle.class, "/attr/RoundedRectangle.javajet", RoundedRectAttrGenerator.class); tr.put(PolygonDecoration.class, "/attr/PolygonDecoration.javajet", PolygonDecorationAttrGenerator.class); tr.put(PolylineDecoration.class, "/attr/PolylineDecoration.javajet", PolylineDecorationAttrGenerator.class); + tr.put(CustomFigure.class, "/attr/CustomFigure.javajet", CustomFigureAttrGenerator.class); // instantiation templates - only single one now. FIXME - make it overridable tr.put("instantiate", "/new/Figure.javajet", NewFigureGenerator.class); // children templates - only single one now. FIXME - make it overridable Index: src/org/eclipse/gmf/graphdef/codegen/templates/CustomFigureAttrGenerator.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/templates/CustomFigureAttrGenerator.java diff -N src/org/eclipse/gmf/graphdef/codegen/templates/CustomFigureAttrGenerator.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/templates/CustomFigureAttrGenerator.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,38 @@ +package org.eclipse.gmf.graphdef.codegen.templates; + +import org.eclipse.gmf.gmfgraph.*; +import org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher; + +public class CustomFigureAttrGenerator +{ + protected static String nl; + public static synchronized CustomFigureAttrGenerator create(String lineSeparator) + { + nl = lineSeparator; + CustomFigureAttrGenerator result = new CustomFigureAttrGenerator(); + nl = null; + return result; + } + + protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = ""; + protected final String TEXT_2 = NL; + protected final String TEXT_3 = NL; + + public String generate(Object argument) + { + StringBuffer stringBuffer = new StringBuffer(); + +GraphDefDispatcher.Args args = (GraphDefDispatcher.Args) argument; +final CustomFigure figureInstance = (CustomFigure) args.getFigure(); +final String figureVarName = args.getVariableName(); +final GraphDefDispatcher dispatcher = args.getDispatcher(); + + stringBuffer.append(TEXT_1); + stringBuffer.append(dispatcher.dispatch("customAttributes", new Object[] {figureInstance, dispatcher, figureVarName})); + stringBuffer.append(TEXT_2); + stringBuffer.append(dispatcher.dispatch("Figure", args)); + stringBuffer.append(TEXT_3); + return stringBuffer.toString(); + } +} Index: templates/attr/CustomFigure.javajet =================================================================== RCS file: templates/attr/CustomFigure.javajet diff -N templates/attr/CustomFigure.javajet --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ templates/attr/CustomFigure.javajet 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,10 @@ +<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="CustomFigureAttrGenerator" + imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher"%> +<% +GraphDefDispatcher.Args args = (GraphDefDispatcher.Args) argument; +final CustomFigure figureInstance = (CustomFigure) args.getFigure(); +final String figureVarName = args.getVariableName(); +final GraphDefDispatcher dispatcher = args.getDispatcher(); +%> +<%=dispatcher.dispatch("customAttributes", new Object[] {figureInstance, dispatcher, figureVarName})%> +<%=dispatcher.dispatch("Figure", args)%> #P org.eclipse.gmf.tests Index: src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java,v retrieving revision 1.21 diff -u -r1.21 RuntimeWorkspaceSetup.java --- src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java 14 Feb 2006 11:05:25 -0000 1.21 +++ src/org/eclipse/gmf/tests/setup/RuntimeWorkspaceSetup.java 23 Mar 2006 15:31:13 -0000 @@ -129,6 +129,7 @@ "org.eclipse.emf.ocl", //$NON-NLS-1$ "org.eclipse.emf.query", //$NON-NLS-1$ "org.eclipse.emf.query.ocl", //$NON-NLS-1$ + "org.eclipse.gmf.tests", //$NON-NLS-1$ // "org.eclipse.emf.edit", //$NON-NLS-1$ "org.eclipse.emf.transaction", //$NON-NLS-1$ Index: src/org/eclipse/gmf/tests/gen/RTFigureTest.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/RTFigureTest.java,v retrieving revision 1.4 diff -u -r1.4 RTFigureTest.java --- src/org/eclipse/gmf/tests/gen/RTFigureTest.java 7 Mar 2006 19:04:35 -0000 1.4 +++ src/org/eclipse/gmf/tests/gen/RTFigureTest.java 23 Mar 2006 15:31:13 -0000 @@ -32,6 +32,8 @@ import org.eclipse.gmf.gmfgraph.RGBColor; import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch; import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator; +import org.eclipse.gmf.tests.Plugin; +import org.eclipse.gmf.tests.draw2d.CustomFigureNoProperties; public class RTFigureTest extends TestCase { @@ -69,8 +71,8 @@ CustomFigure bottomCustom = GMFGraphFactory.eINSTANCE.createCustomFigure(); bottomCustom.setName("BottomCustom"); - bottomCustom.setBundleName("org.eclipse.gmf.runtime.diagram.ui.geoshapes"); - bottomCustom.setQualifiedClassName("org.eclipse.gmf.runtime.diagram.ui.geoshapes.internal.draw2d.figures.GeoShapeCylinderFigure"); + bottomCustom.setBundleName(Plugin.getPluginID()); + bottomCustom.setQualifiedClassName(CustomFigureNoProperties.class.getName()); RGBColor blue = GMFGraphFactory.eINSTANCE.createRGBColor(); red.setBlue(255); bottomCustom.setForegroundColor(blue); Index: src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java,v retrieving revision 1.5 diff -u -r1.5 FigureCodegenTest.java --- src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java 1 Mar 2006 20:24:38 -0000 1.5 +++ src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java 23 Mar 2006 15:31:12 -0000 @@ -29,20 +29,24 @@ } public void testGenCustomFigure() { - performTests(figure1()); + performTests(figure1(), getFigure1Check()); } public void testGenSimpleShape() { - performTests(figure2()); + performTests(figure2(), getFigure2Check()); } public void testGenComplexShape() { - performTests(figure3()); + performTests(figure3(), getFigure3Check()); } public void testGenFigureWithoutPackageStmt() { setCustomFigureGenerator(new FigureGenerator(null, new NullImportAssistant(), new RuntimeFQNSwitch())); testGenComplexShape(); } + + public void testGenCustomFigureWithAttributes(){ + performTests(figure4(), getFigure4Check()); + } } Index: src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java,v retrieving revision 1.7 diff -u -r1.7 FigureCodegenTestBase.java --- src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 9 Mar 2006 13:35:59 -0000 1.7 +++ src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 23 Mar 2006 15:31:13 -0000 @@ -12,19 +12,28 @@ package org.eclipse.gmf.tests.gen; import java.net.MalformedURLException; +import java.util.List; +import junit.framework.Assert; import junit.framework.TestCase; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.PointList; import org.eclipse.emf.codegen.jet.JETException; import org.eclipse.gmf.common.codegen.ImportUtil; import org.eclipse.gmf.gmfgraph.BasicFont; import org.eclipse.gmf.gmfgraph.ColorConstants; import org.eclipse.gmf.gmfgraph.ConnectionFigure; import org.eclipse.gmf.gmfgraph.ConstantColor; +import org.eclipse.gmf.gmfgraph.CustomAttribute; import org.eclipse.gmf.gmfgraph.CustomFigure; +import org.eclipse.gmf.gmfgraph.Dimension; import org.eclipse.gmf.gmfgraph.Ellipse; import org.eclipse.gmf.gmfgraph.Figure; import org.eclipse.gmf.gmfgraph.FigureGallery; @@ -41,13 +50,21 @@ import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch; import org.eclipse.gmf.graphdef.codegen.FigureGenerator; import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator; +import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx; import org.eclipse.gmf.tests.CompileUtil; import org.eclipse.gmf.tests.Plugin; +import org.eclipse.gmf.tests.draw2d.CustomFigureNoProperties; +import org.eclipse.gmf.tests.draw2d.CustomFigureWithProperties; +import org.eclipse.gmf.tests.setup.SessionSetup; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; @@ -57,18 +74,32 @@ */ public class FigureCodegenTestBase extends TestCase { private FigureGenerator figureGenerator; - + public FigureCodegenTestBase(String name) { super(name); } + protected void setUp() throws Exception { + super.setUp(); + SessionSetup.getRuntimeWorkspaceSetup(); + } + protected final void setCustomFigureGenerator(FigureGenerator generator){ figureGenerator = generator; } - + protected final void performTests(Figure f) { + performTests(f, null); + } + + protected final void performTests(Figure f, FigureCheck check) { generateAndParse(f); - //generateAndCompile(getGMFGraphGeneratorConfig(), f); + Class figureClass = generateAndCompile(getGMFGraphGeneratorConfig(), f); + if (check != null){ + IFigure figure = check.instantiateFigure(figureClass); + assertNotNull(figure); + check.checkFigure(figure); + } } protected final void generateAndParse(Figure f){ @@ -98,22 +129,22 @@ } } - /* private StandaloneGenerator.Config getGMFGraphGeneratorConfig(){ return new StandaloneGenerator.ConfigImpl(getTestPluginName(), getFigurePackageName()); } - */ protected final Class generateAndCompile(StandaloneGenerator.Config config, Figure figure) { try { FigureGallery fg = GMFGraphFactory.eINSTANCE.createFigureGallery(); fg.setName("bb"); fg.getFigures().add(figure); + fg.setImplementationBundle(Plugin.getPluginID()); StandaloneGenerator generator = new StandaloneGenerator(fg, config, new RuntimeFQNSwitch()); generator.run(); assertTrue(generator.getRunStatus().getSeverity() < IStatus.ERROR); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(config.getPluginID()); + SessionSetup.getRuntimeWorkspaceSetup().updateClassPath(project); IStatus compileStatus = new CompileUtil().build(project); assertTrue(compileStatus.getMessage(), compileStatus.getSeverity() < IStatus.ERROR); @@ -127,16 +158,20 @@ fail(e.getMessage()); } catch (ClassNotFoundException e) { fail(e.getMessage()); + } catch (CoreException e){ + fail(e.getMessage()); + } catch (Exception e){ + fail(e.getMessage()); } throw new InternalError("Impossible"); } - // custom top-level, hierarchical children. + // custom top-level, hierarchical children, no custom properties protected final Figure figure1() { CustomFigure cf = GMFGraphFactory.eINSTANCE.createCustomFigure(); - cf.setName("MyCylinder"); - cf.setBundleName("org.eclipse.gmf.runtime.diagram.ui.geoshapes"); - cf.setQualifiedClassName("org.eclipse.gmf.runtime.diagram.ui.geoshapes.internal.draw2d.figures.GeoShapeCylinderFigure"); + cf.setName("MyXRectangle"); + cf.setBundleName(Plugin.getPluginID()); + cf.setQualifiedClassName(CustomFigureNoProperties.class.getName()); Point p = GMFGraphFactory.eINSTANCE.createPoint(); p.setX(1023); p.setY(33); @@ -149,6 +184,23 @@ return cf; } + protected final FigureCheck getFigure1Check(){ + return new FigureCheck(){ + public void checkFigure(IFigure figure) { + assertTrue(figure instanceof CustomFigureNoProperties); + assertEquals(new org.eclipse.draw2d.geometry.Dimension(1023, 33), figure.getSize()); + + List children = figure.getChildren(); + assertEquals(2, children.size()); + assertTrue(children.get(0) instanceof IFigure); + assertTrue(children.get(1) instanceof org.eclipse.draw2d.Ellipse); + + IFigure childFigure2 = (IFigure)children.get(0); + getFigure2Check().checkFigure(childFigure2); + } + }; + } + // basic toplevel with plain list of children protected final Figure figure2() { Rectangle r = GMFGraphFactory.eINSTANCE.createRectangle(); @@ -179,6 +231,56 @@ r.getChildren().add(l2); return r; } + + protected final FigureCheck getFigure2Check(){ + return new FigureCheck(){ + public void checkFigure(IFigure figure) { + assertTrue(figure instanceof RectangleFigure); + RectangleFigure rectangle = (RectangleFigure)figure; + assertEquals(3, rectangle.getLineWidth()); + assertEquals(Graphics.LINE_DASHDOT, rectangle.getLineStyle()); + + List children = rectangle.getChildren(); + assertEquals(2, children.size()); + + IFigure labelA = (IFigure) children.get(0); + IFigure labelB = (IFigure) children.get(1); + + checkLabel(labelA, "aaaaa"); + checkLabel(labelB, "bbbbb"); + + checkFont(labelA, "Arial", 9, SWT.ITALIC); + checkFont(labelB, "Helvetica", 12, SWT.BOLD); + + checkForeground(labelA, org.eclipse.draw2d.ColorConstants.cyan); + } + + private void checkFont(IFigure figure, String faceName, int height, int style){ + assertNotNull(figure); + Font actual = figure.getFont(); + assertNotNull(actual); + if (actual.getFontData().length == 1){ + FontData theOnly = actual.getFontData()[0]; + assertEquals(faceName, theOnly.getName()); + assertEquals(height, theOnly.getHeight()); + assertEquals(style, theOnly.getStyle()); + } + } + + private void checkForeground(IFigure figure, Color expected){ + Color actual = figure.getForegroundColor(); + //intentionally not checking via equals + assertEquals(expected.getRed(), actual.getRed()); + assertEquals(expected.getGreen(), actual.getGreen()); + assertEquals(expected.getBlue(), actual.getBlue()); + } + + private void checkLabel(IFigure label, String expectedText){ + assertTrue(label instanceof org.eclipse.draw2d.Label); + assertEquals(expectedText, ((org.eclipse.draw2d.Label)label).getText()); + } + }; + } // basic toplebel with hierarhical list of children (one of them is custom, another is polygon) protected final Figure figure3() { @@ -202,6 +304,72 @@ r.getChildren().add(figure1()); return r; } + + protected final FigureCheck getFigure3Check(){ + return new FigureCheck(){ + public void checkFigure(IFigure figure) { + assertTrue(figure instanceof org.eclipse.draw2d.RoundedRectangle); + org.eclipse.draw2d.RoundedRectangle roundedRectangle = (org.eclipse.draw2d.RoundedRectangle)figure; + List children = roundedRectangle.getChildren(); + assertEquals(2, children.size()); + assertTrue(children.get(0) instanceof org.eclipse.draw2d.Polygon); + org.eclipse.draw2d.Polygon first = (org.eclipse.draw2d.Polygon)children.get(0); + + PointList actual = first.getPoints(); + org.eclipse.draw2d.geometry.Point[] expected = new org.eclipse.draw2d.geometry.Point[] { + new org.eclipse.draw2d.geometry.Point(1, 2), + new org.eclipse.draw2d.geometry.Point(0, 3), + new org.eclipse.draw2d.geometry.Point(-2, -1), + }; + assertEquals(expected.length, actual.size()); + for (int i = 0; i < expected.length; i++){ + assertEquals(expected[i], actual.getPoint(i)); + } + + assertTrue(children.get(1) instanceof IFigure); + getFigure1Check().checkFigure((IFigure)children.get(1)); + } + + }; + } + + // custom top-level figure with custom properties + protected final Figure figure4() { + CustomFigure result = GMFGraphFactory.eINSTANCE.createCustomFigure(); + result.setName("MyRectangleWithInner40x40"); + result.setBundleName(Plugin.getPluginID()); + result.setQualifiedClassName(CustomFigureWithProperties.class.getName()); + + CustomAttribute innerWidthAttr = GMFGraphFactory.eINSTANCE.createCustomAttribute(); + innerWidthAttr.setName("innerWidth"); + innerWidthAttr.setValue("40"); + result.getAttributes().add(innerWidthAttr); + + CustomAttribute innerHeightAttr = GMFGraphFactory.eINSTANCE.createCustomAttribute(); + innerHeightAttr.setName("innerHeight"); + innerHeightAttr.setValue("40"); + innerHeightAttr.setDirectAccess(true); + result.getAttributes().add(innerHeightAttr); + + Dimension outerPrefSize = GMFGraphFactory.eINSTANCE.createDimension(); + outerPrefSize.setDx(100); + outerPrefSize.setDy(100); + result.setPreferredSize(outerPrefSize); + + return result; + } + + protected final FigureCheck getFigure4Check(){ + return new FigureCheck(){ + public void checkFigure(IFigure figure) { + assertTrue(figure instanceof CustomFigureWithProperties); + CustomFigureWithProperties custom = (CustomFigureWithProperties)figure; + assertEquals(new org.eclipse.draw2d.geometry.Dimension(100, 100), custom.getPreferredSize()); + assertEquals(40, custom.getInnerWidth()); + assertEquals(40, custom.innerHeight); + } + }; + } protected final ConnectionFigure ecoreContainmentRef() { PolylineConnection cf = GMFGraphFactory.eINSTANCE.createPolylineConnection(); @@ -211,6 +379,14 @@ cf.setSourceDecoration(df); return cf; } + + protected final FigureCheck ecoreContainmentRefCheck(){ + return new FigureCheck(){ + public void checkFigure(IFigure figure) { + assertTrue(figure instanceof PolylineConnectionEx); + } + }; + } protected final PolygonDecoration createRhomb() { PolygonDecoration df = GMFGraphFactory.eINSTANCE.createPolygonDecoration(); @@ -253,4 +429,31 @@ return figureGenerator; } + public static abstract class FigureCheck extends Assert { + /** + * Overridable to allow not default construction + */ + protected IFigure instantiateFigure(Class figureClass){ + Object result = null; + try { + result = figureClass.newInstance(); + } catch (InstantiationException e) { + fail(e.getMessage()); + } catch (IllegalAccessException e) { + fail(e.getMessage()); + } + assertNotNull(result); + assertTrue(figureClass.getName(), result instanceof IFigure); + return (IFigure)result; + } + + public abstract void checkFigure(IFigure figure); + } + + protected static final FigureCheck CHECK_CAN_CREATE_INSTANCE = new FigureCheck(){ + public void checkFigure(IFigure figure) { + // + } + }; + } Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/META-INF/MANIFEST.MF,v retrieving revision 1.14 diff -u -r1.14 MANIFEST.MF --- META-INF/MANIFEST.MF 15 Mar 2006 15:17:01 -0000 1.14 +++ META-INF/MANIFEST.MF 23 Mar 2006 15:31:12 -0000 @@ -19,3 +19,4 @@ org.eclipse.gmf.codegen.ui Bundle-Activator: org.eclipse.gmf.tests.Plugin Eclipse-LazyStart: true +Export-Package: org.eclipse.gmf.tests.draw2d Index: src/org/eclipse/gmf/tests/draw2d/CustomFigureNoProperties.java =================================================================== RCS file: src/org/eclipse/gmf/tests/draw2d/CustomFigureNoProperties.java diff -N src/org/eclipse/gmf/tests/draw2d/CustomFigureNoProperties.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/tests/draw2d/CustomFigureNoProperties.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2006 Borland Software Corporation + * + * 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: + * Michael Golubev (Borland) - initial API and implementation + */ + +package org.eclipse.gmf.tests.draw2d; + +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Rectangle; + +public class CustomFigureNoProperties extends RectangleFigure { + protected void outlineShape(Graphics graphics) { + super.outlineShape(graphics); + + Rectangle r = getBounds(); + graphics.drawLine(r.getBottomLeft(), r.getTopRight()); + graphics.drawLine(r.getBottomRight(), r.getTopLeft()); + } +} Index: src/org/eclipse/gmf/tests/draw2d/CustomFigureWithProperties.java =================================================================== RCS file: src/org/eclipse/gmf/tests/draw2d/CustomFigureWithProperties.java diff -N src/org/eclipse/gmf/tests/draw2d/CustomFigureWithProperties.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/tests/draw2d/CustomFigureWithProperties.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2006 Borland Software Corporation + * + * 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: + * Michael Golubev (Borland) - initial API and implementation + */ + +package org.eclipse.gmf.tests.draw2d; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.RectangleFigure; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Color; + +public class CustomFigureWithProperties extends RectangleFigure { + private int myInnerWidth = 20; + + /** + * Intentionally public to test CustomAttribute#isDirectAccess + */ + public int innerHeight = 20; + + public void setInnerWidth(int innerWidth){ + myInnerWidth = innerWidth; + } + + public int getInnerWidth() { + return myInnerWidth; + } + + public Color getInnerColor(){ + return isRed(getBackgroundColor()) ? ColorConstants.green : ColorConstants.red; + } + + protected void outlineShape(Graphics graphics) { + super.outlineShape(graphics); + Rectangle r = getBounds(); + if (myInnerWidth > 0 && innerHeight > 0 && myInnerWidth < r.width && innerHeight < r.height){ + int innerX = r.x + (myInnerWidth - r.width) / 2; + int innerY = r.y + (innerHeight - r.height) / 2; + graphics.drawRectangle(innerX, innerY, myInnerWidth, innerHeight); + } + } + + protected void fillShape(Graphics graphics) { + super.fillShape(graphics); + Rectangle r = getBounds(); + if (myInnerWidth > 0 && innerHeight > 0 && myInnerWidth < r.width - 2 && innerHeight < r.height - 2){ + graphics.pushState(); + graphics.setBackgroundColor(getInnerColor()); + int innerX = r.x + (myInnerWidth - r.width) / 2 + 1; + int innerY = r.y + (innerHeight - r.height) / 2 + 1; + graphics.fillRectangle(innerX + 1, innerY + 1, myInnerWidth - 1, innerHeight + 1); + graphics.popState(); + } + } + + private static boolean isRed(Color color){ + //do not use RGB to avoid object creation + return color != null && color.getRed() == 255 && color.getBlue() == 0 && color.getGreen() == 0; + } +}