### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.graphdef.codegen Index: templates/attr/Figure.javajet =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet,v retrieving revision 1.6 diff -u -r1.6 Figure.javajet --- templates/attr/Figure.javajet 17 May 2006 11:30:53 -0000 1.6 +++ templates/attr/Figure.javajet 26 Jun 2006 15:40:24 -0000 @@ -7,12 +7,16 @@ final GraphDefDispatcher dispatcher = args.getDispatcher(); final ImportAssistant importManager = dispatcher.getImportManager(); %> -<%Color colorVal; +<% +Color colorVal; +String colorName; if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())) { - colorVal = figureInstance.getForegroundColor();%> + colorVal = figureInstance.getForegroundColor(); + colorName = figureInstance.getName().toUpperCase() + "_FORE";%> <%=figureVarName%>.setForegroundColor(<%@ include file="../Color.jetinc"%>); <%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())) { - colorVal = figureInstance.getBackgroundColor();%> + colorVal = figureInstance.getBackgroundColor(); + colorName = figureInstance.getName().toUpperCase() + "_BACK";%> <%=figureVarName%>.setBackgroundColor(<%@ include file="../Color.jetinc"%>); <%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())) { Dimension d = figureInstance.getPreferredSize();%> @@ -37,7 +41,12 @@ } } %> - <%=figureVarName%>.setFont(new <%=importManager.getImportedName("org.eclipse.swt.graphics.Font")%>(<%=importManager.getImportedName("org.eclipse.swt.widgets.Display")%>.getCurrent(), "<%=fontName%>", <%=font.getHeight()%>, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.<%=font.getStyle().getLiteral()%>)); + <%=figureVarName%>.setFont( + <%=dispatcher.getStaticFieldsManager().addStaticField( + importManager.getImportedName("org.eclipse.swt.graphics.Font"), + figureInstance.getName().toUpperCase() + "_FONT", + "new " + importManager.getImportedName("org.eclipse.swt.graphics.Font") + "(" + importManager.getImportedName("org.eclipse.swt.widgets.Display") + ".getCurrent(), \"" + fontName + "\", " + font.getHeight() + ", " + importManager.getImportedName("org.eclipse.swt.SWT") + "." + font.getStyle().getLiteral() + ")" + )%>); <%} if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) { Insets insets = figureInstance.getInsets();%> <%=figureVarName%>.setBorder(new <%=importManager.getImportedName("org.eclipse.draw2d.MarginBorder")%>(<%=dispatcher.DPtoLP(insets.getTop())%>, <%=dispatcher.DPtoLP(insets.getLeft())%>, <%=dispatcher.DPtoLP(insets.getBottom())%>, <%=dispatcher.DPtoLP(insets.getRight())%>)); Index: templates/top/PolylineConnection.javajet =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet,v retrieving revision 1.5 diff -u -r1.5 PolylineConnection.javajet --- templates/top/PolylineConnection.javajet 18 May 2006 19:12:40 -0000 1.5 +++ templates/top/PolylineConnection.javajet 26 Jun 2006 15:40:24 -0000 @@ -1,11 +1,12 @@ <%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopConnectionGenerator" - imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher"%> + imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* java.util.Iterator"%> <% Object[] args = (Object[]) argument; PolylineConnection figure = (PolylineConnection) args[0]; final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean placeStaticFieldsOutsideClassBody = ((Boolean) args[4]).booleanValue(); %> <%importManager.emitPackageStatement(stringBuffer);%> @@ -50,4 +51,5 @@ return df; } <%}%> -}<%importManager.emitSortedImports();%> \ No newline at end of file +<%@ include file="classFooter.jetinc"%> +<%importManager.emitSortedImports();%> \ No newline at end of file Index: templates/top/Figure.javajet =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet,v retrieving revision 1.10 diff -u -r1.10 Figure.javajet --- templates/top/Figure.javajet 18 May 2006 19:12:40 -0000 1.10 +++ templates/top/Figure.javajet 26 Jun 2006 15:40:24 -0000 @@ -1,11 +1,12 @@ <%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopFigureGenerator" - imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.*"%> + imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* java.util.Iterator;"%> <% Object[] args = (Object[]) argument; Figure figure = (Figure) args[0]; final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean placeStaticFieldsOutsideClassBody = ((Boolean) args[4]).booleanValue(); %> <%importManager.emitPackageStatement(stringBuffer);%> @@ -33,4 +34,5 @@ <%if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/%> <%@ include file="localCoordinates.jetinc"%> <%}%> -}<%importManager.emitSortedImports();%> +<%@ include file="classFooter.jetinc"%> +<%importManager.emitSortedImports();%> Index: src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java,v retrieving revision 1.6 diff -u -r1.6 TopConnectionGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java 18 May 2006 19:12:40 -0000 1.6 +++ src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java 26 Jun 2006 15:40:24 -0000 @@ -3,7 +3,8 @@ import org.eclipse.gmf.gmfgraph.*; import org.eclipse.gmf.gmfgraph.util.*; import org.eclipse.gmf.common.codegen.*; -import org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher; +import org.eclipse.gmf.graphdef.codegen.*; +import java.util.Iterator; public class TopConnectionGenerator { @@ -35,7 +36,18 @@ protected final String TEXT_16 = " createTargetDecoration() {"; protected final String TEXT_17 = NL; protected final String TEXT_18 = NL + "\t\treturn df;" + NL + "\t}"; - protected final String TEXT_19 = NL + "}"; + protected final String TEXT_19 = NL; + protected final String TEXT_20 = NL + "}" + NL + "\t"; + protected final String TEXT_21 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_22 = " "; + protected final String TEXT_23 = " = "; + protected final String TEXT_24 = ";"; + protected final String TEXT_25 = NL + "\t"; + protected final String TEXT_26 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_27 = " "; + protected final String TEXT_28 = " = "; + protected final String TEXT_29 = ";"; + protected final String TEXT_30 = NL + "}"; public String generate(Object argument) { @@ -46,6 +58,7 @@ final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean placeStaticFieldsOutsideClassBody = ((Boolean) args[4]).booleanValue(); importManager.emitPackageStatement(stringBuffer); stringBuffer.append(TEXT_1); @@ -86,6 +99,43 @@ stringBuffer.append(TEXT_18); } stringBuffer.append(TEXT_19); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean placeStaticFieldsOutsideClassBody +if (placeStaticFieldsOutsideClassBody){ + stringBuffer.append(TEXT_20); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_21); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_22); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_23); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_24); + +} + + } else { + stringBuffer.append(TEXT_25); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_26); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_27); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_28); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_29); + +} + + stringBuffer.append(TEXT_30); + } importManager.emitSortedImports(); return stringBuffer.toString(); } Index: src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java,v retrieving revision 1.7 diff -u -r1.7 FigureAttrGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java 17 May 2006 11:30:53 -0000 1.7 +++ src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java 26 Jun 2006 15:40:23 -0000 @@ -18,58 +18,43 @@ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = "\t\t"; protected final String TEXT_2 = ".setForegroundColor("; - protected final String TEXT_3 = "new "; - protected final String TEXT_4 = "(null, "; - protected final String TEXT_5 = ", "; - protected final String TEXT_6 = ", "; - protected final String TEXT_7 = ")"; - protected final String TEXT_8 = "."; - protected final String TEXT_9 = ");"; - protected final String TEXT_10 = NL + "\t\t"; - protected final String TEXT_11 = ".setBackgroundColor("; - protected final String TEXT_12 = "new "; - protected final String TEXT_13 = "(null, "; - protected final String TEXT_14 = ", "; + protected final String TEXT_3 = NL; + protected final String TEXT_4 = ");"; + protected final String TEXT_5 = NL + "\t\t"; + protected final String TEXT_6 = ".setBackgroundColor("; + protected final String TEXT_7 = NL; + protected final String TEXT_8 = ");"; + protected final String TEXT_9 = NL + "\t\t"; + protected final String TEXT_10 = ".setPreferredSize("; + protected final String TEXT_11 = ", "; + protected final String TEXT_12 = ");"; + protected final String TEXT_13 = NL + "\t\t"; + protected final String TEXT_14 = ".setSize("; protected final String TEXT_15 = ", "; - protected final String TEXT_16 = ")"; - protected final String TEXT_17 = "."; - protected final String TEXT_18 = ");"; - protected final String TEXT_19 = NL + "\t\t"; - protected final String TEXT_20 = ".setPreferredSize("; - protected final String TEXT_21 = ", "; - protected final String TEXT_22 = ");"; - protected final String TEXT_23 = NL + "\t\t"; - protected final String TEXT_24 = ".setSize("; + protected final String TEXT_16 = ");"; + protected final String TEXT_17 = NL + "\t\t"; + protected final String TEXT_18 = ".setMaximumSize(new "; + protected final String TEXT_19 = "("; + protected final String TEXT_20 = ", "; + protected final String TEXT_21 = "));"; + protected final String TEXT_22 = NL + "\t\t"; + protected final String TEXT_23 = ".setMinimumSize(new "; + protected final String TEXT_24 = "("; protected final String TEXT_25 = ", "; - protected final String TEXT_26 = ");"; + protected final String TEXT_26 = "));"; protected final String TEXT_27 = NL + "\t\t"; - protected final String TEXT_28 = ".setMaximumSize(new "; - protected final String TEXT_29 = "("; - protected final String TEXT_30 = ", "; - protected final String TEXT_31 = "));"; - protected final String TEXT_32 = NL + "\t\t"; - protected final String TEXT_33 = ".setMinimumSize(new "; - protected final String TEXT_34 = "("; + protected final String TEXT_28 = ".setFont(" + NL + "\t\t\t"; + protected final String TEXT_29 = ");"; + protected final String TEXT_30 = NL + "\t\t"; + protected final String TEXT_31 = ".setBorder(new "; + protected final String TEXT_32 = "("; + protected final String TEXT_33 = ", "; + protected final String TEXT_34 = ", "; protected final String TEXT_35 = ", "; protected final String TEXT_36 = "));"; protected final String TEXT_37 = NL + "\t\t"; - protected final String TEXT_38 = ".setFont(new "; - protected final String TEXT_39 = "("; - protected final String TEXT_40 = ".getCurrent(), \""; - protected final String TEXT_41 = "\", "; - protected final String TEXT_42 = ", "; - protected final String TEXT_43 = "."; - protected final String TEXT_44 = "));"; - protected final String TEXT_45 = NL + "\t\t"; - protected final String TEXT_46 = ".setBorder(new "; - protected final String TEXT_47 = "("; - protected final String TEXT_48 = ", "; - protected final String TEXT_49 = ", "; - protected final String TEXT_50 = ", "; - protected final String TEXT_51 = "));"; - protected final String TEXT_52 = NL + "\t\t"; - protected final String TEXT_53 = ".setBorder("; - protected final String TEXT_54 = ");"; + protected final String TEXT_38 = ".setBorder("; + protected final String TEXT_39 = ");"; public String generate(Object argument) { @@ -81,89 +66,109 @@ final GraphDefDispatcher dispatcher = args.getDispatcher(); final ImportAssistant importManager = dispatcher.getImportManager(); - Color colorVal; + +Color colorVal; +String colorName; if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor())) { colorVal = figureInstance.getForegroundColor(); + colorName = figureInstance.getName().toUpperCase() + "_FORE"; stringBuffer.append(TEXT_1); stringBuffer.append(figureVarName); stringBuffer.append(TEXT_2); - if (colorVal instanceof RGBColor) { + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + +{ //namespace + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue; + if (colorVal instanceof RGBColor){ + staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + } else if (colorVal instanceof ConstantColor){ + staticFieldValue = importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral(); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + stringBuffer.append(TEXT_3); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + +} //namespace + stringBuffer.append(TEXT_4); - stringBuffer.append(((RGBColor) colorVal).getRed()); + } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())) { + colorVal = figureInstance.getBackgroundColor(); + colorName = figureInstance.getName().toUpperCase() + "_BACK"; stringBuffer.append(TEXT_5); - stringBuffer.append(((RGBColor) colorVal).getGreen()); + stringBuffer.append(figureVarName); stringBuffer.append(TEXT_6); - stringBuffer.append(((RGBColor) colorVal).getBlue()); + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + +{ //namespace + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue; + if (colorVal instanceof RGBColor){ + staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + } else if (colorVal instanceof ConstantColor){ + staticFieldValue = importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral(); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + stringBuffer.append(TEXT_7); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + +} //namespace + stringBuffer.append(TEXT_8); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_9); - } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_BackgroundColor())) { - colorVal = figureInstance.getBackgroundColor(); - stringBuffer.append(TEXT_10); - stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_11); - if (colorVal instanceof RGBColor) { - stringBuffer.append(TEXT_12); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); - stringBuffer.append(TEXT_13); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_14); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_15); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_16); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - stringBuffer.append(TEXT_17); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_18); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())) { Dimension d = figureInstance.getPreferredSize(); - stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_9); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_10); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_11); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_12); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())) { Point p = figureInstance.getSize(); - stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_13); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_14); stringBuffer.append(dispatcher.DPtoLP(p.getX())); - stringBuffer.append(TEXT_25); + stringBuffer.append(TEXT_15); stringBuffer.append(dispatcher.DPtoLP(p.getY())); - stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_16); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())) { Dimension d = figureInstance.getMaximumSize(); - stringBuffer.append(TEXT_27); + stringBuffer.append(TEXT_17); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_28); + stringBuffer.append(TEXT_18); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")); - stringBuffer.append(TEXT_29); + stringBuffer.append(TEXT_19); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_30); + stringBuffer.append(TEXT_20); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_31); + stringBuffer.append(TEXT_21); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())) { Dimension d = figureInstance.getMinimumSize(); - stringBuffer.append(TEXT_32); + stringBuffer.append(TEXT_22); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_23); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")); - stringBuffer.append(TEXT_34); + stringBuffer.append(TEXT_24); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_35); + stringBuffer.append(TEXT_25); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_36); + stringBuffer.append(TEXT_26); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Font())) { // XXX possible CCE when fonts other than Basic added to model BasicFont font = (BasicFont) figureInstance.getFont(); @@ -175,43 +180,37 @@ } } - stringBuffer.append(TEXT_37); + stringBuffer.append(TEXT_27); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_38); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Font")); - stringBuffer.append(TEXT_39); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.widgets.Display")); - stringBuffer.append(TEXT_40); - stringBuffer.append(fontName); - stringBuffer.append(TEXT_41); - stringBuffer.append(font.getHeight()); - stringBuffer.append(TEXT_42); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.SWT")); - stringBuffer.append(TEXT_43); - stringBuffer.append(font.getStyle().getLiteral()); - stringBuffer.append(TEXT_44); + stringBuffer.append(TEXT_28); + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField( + importManager.getImportedName("org.eclipse.swt.graphics.Font"), + figureInstance.getName().toUpperCase() + "_FONT", + "new " + importManager.getImportedName("org.eclipse.swt.graphics.Font") + "(" + importManager.getImportedName("org.eclipse.swt.widgets.Display") + ".getCurrent(), \"" + fontName + "\", " + font.getHeight() + ", " + importManager.getImportedName("org.eclipse.swt.SWT") + "." + font.getStyle().getLiteral() + ")" + )); + stringBuffer.append(TEXT_29); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) { Insets insets = figureInstance.getInsets(); - stringBuffer.append(TEXT_45); + stringBuffer.append(TEXT_30); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_46); + stringBuffer.append(TEXT_31); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.MarginBorder")); - stringBuffer.append(TEXT_47); + stringBuffer.append(TEXT_32); stringBuffer.append(dispatcher.DPtoLP(insets.getTop())); - stringBuffer.append(TEXT_48); + stringBuffer.append(TEXT_33); stringBuffer.append(dispatcher.DPtoLP(insets.getLeft())); - stringBuffer.append(TEXT_49); + stringBuffer.append(TEXT_34); stringBuffer.append(dispatcher.DPtoLP(insets.getBottom())); - stringBuffer.append(TEXT_50); + stringBuffer.append(TEXT_35); stringBuffer.append(dispatcher.DPtoLP(insets.getRight())); - stringBuffer.append(TEXT_51); + stringBuffer.append(TEXT_36); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())) { Border border = figureInstance.getBorder(); - stringBuffer.append(TEXT_52); + stringBuffer.append(TEXT_37); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_53); + stringBuffer.append(TEXT_38); stringBuffer.append(dispatcher.dispatch(border, new Object[] {border, dispatcher})); - stringBuffer.append(TEXT_54); + stringBuffer.append(TEXT_39); } return stringBuffer.toString(); } Index: src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java,v retrieving revision 1.2 diff -u -r1.2 NewLineBorderExpressionGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java 7 Apr 2006 14:49:17 -0000 1.2 +++ src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java 26 Jun 2006 15:40:24 -0000 @@ -18,29 +18,19 @@ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = "new "; protected final String TEXT_2 = "("; - protected final String TEXT_3 = "new "; - protected final String TEXT_4 = "(null, "; - protected final String TEXT_5 = ", "; - protected final String TEXT_6 = ", "; - protected final String TEXT_7 = ")"; - protected final String TEXT_8 = "."; - protected final String TEXT_9 = ", "; - protected final String TEXT_10 = ")"; - protected final String TEXT_11 = NL + "new "; - protected final String TEXT_12 = "("; - protected final String TEXT_13 = "new "; - protected final String TEXT_14 = "(null, "; - protected final String TEXT_15 = ", "; - protected final String TEXT_16 = ", "; - protected final String TEXT_17 = ")"; - protected final String TEXT_18 = "."; - protected final String TEXT_19 = ")"; - protected final String TEXT_20 = NL + "new "; - protected final String TEXT_21 = "("; - protected final String TEXT_22 = ")"; - protected final String TEXT_23 = NL + "new "; - protected final String TEXT_24 = "()"; - protected final String TEXT_25 = NL; + protected final String TEXT_3 = NL; + protected final String TEXT_4 = ", "; + protected final String TEXT_5 = ")"; + protected final String TEXT_6 = NL + "new "; + protected final String TEXT_7 = "("; + protected final String TEXT_8 = NL; + protected final String TEXT_9 = ")"; + protected final String TEXT_10 = NL + "new "; + protected final String TEXT_11 = "("; + protected final String TEXT_12 = ")"; + protected final String TEXT_13 = NL + "new "; + protected final String TEXT_14 = "()"; + protected final String TEXT_15 = NL; public String generate(Object argument) { @@ -59,69 +49,86 @@ boolean hasColor = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color()); boolean hasWidth = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Width()); Color colorVal = (hasColor) ? border.getColor() : null; + String colorName = (hasColor) ? "BORDER" : null; if (hasColor && hasWidth){ stringBuffer.append(TEXT_1); stringBuffer.append(borderClazz); stringBuffer.append(TEXT_2); - if (colorVal instanceof RGBColor) { + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + +{ //namespace + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue; + if (colorVal instanceof RGBColor){ + staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + } else if (colorVal instanceof ConstantColor){ + staticFieldValue = importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral(); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + stringBuffer.append(TEXT_3); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + +} //namespace + stringBuffer.append(TEXT_4); - stringBuffer.append(((RGBColor) colorVal).getRed()); + stringBuffer.append(dispatcher.DPtoLP(border.getWidth())); stringBuffer.append(TEXT_5); - stringBuffer.append(((RGBColor) colorVal).getGreen()); + + } else if (hasColor && !hasWidth) { + stringBuffer.append(TEXT_6); - stringBuffer.append(((RGBColor) colorVal).getBlue()); + stringBuffer.append(borderClazz); stringBuffer.append(TEXT_7); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + +{ //namespace + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue; + if (colorVal instanceof RGBColor){ + staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + } else if (colorVal instanceof ConstantColor){ + staticFieldValue = importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral(); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + stringBuffer.append(TEXT_8); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_9); - stringBuffer.append(dispatcher.DPtoLP(border.getWidth())); - stringBuffer.append(TEXT_10); + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); - } else if (hasColor && !hasWidth) { +} //namespace - stringBuffer.append(TEXT_11); - stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_12); - if (colorVal instanceof RGBColor) { - stringBuffer.append(TEXT_13); - stringBuffer.append(importManager.getImportedName("org.eclipse.swt.graphics.Color")); - stringBuffer.append(TEXT_14); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_15); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_16); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_17); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - stringBuffer.append(TEXT_18); - stringBuffer.append(((ConstantColor) colorVal).getValue().getLiteral()); - } - stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_9); } else if (!hasColor && hasWidth){ - stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_10); stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_11); stringBuffer.append(dispatcher.DPtoLP(border.getWidth())); - stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_12); } else { - stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_13); stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_14); } - stringBuffer.append(TEXT_25); + stringBuffer.append(TEXT_15); return stringBuffer.toString(); } } Index: src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java,v retrieving revision 1.11 diff -u -r1.11 TopFigureGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java 18 May 2006 19:12:40 -0000 1.11 +++ src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java 26 Jun 2006 15:40:24 -0000 @@ -4,6 +4,7 @@ import org.eclipse.gmf.gmfgraph.util.*; import org.eclipse.gmf.common.codegen.*; import org.eclipse.gmf.graphdef.codegen.*; +import java.util.Iterator;; public class TopFigureGenerator { @@ -30,8 +31,19 @@ protected final String TEXT_11 = NL; protected final String TEXT_12 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = "; protected final String TEXT_13 = ";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected boolean useLocalCoordinates() {" + NL + "\t\treturn myUseLocalCoordinates;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setUseLocalCoordinates(boolean useLocalCoordinates) {" + NL + "\t\tmyUseLocalCoordinates = useLocalCoordinates;" + NL + "\t}" + NL + "\t"; - protected final String TEXT_14 = NL + "}"; - protected final String TEXT_15 = NL; + protected final String TEXT_14 = NL; + protected final String TEXT_15 = NL + "}" + NL + "\t"; + protected final String TEXT_16 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_17 = " "; + protected final String TEXT_18 = " = "; + protected final String TEXT_19 = ";"; + protected final String TEXT_20 = NL + "\t"; + protected final String TEXT_21 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; + protected final String TEXT_22 = " "; + protected final String TEXT_23 = " = "; + protected final String TEXT_24 = ";"; + protected final String TEXT_25 = NL + "}"; + protected final String TEXT_26 = NL; public String generate(Object argument) { @@ -42,6 +54,7 @@ final ImportAssistant importManager = (ImportAssistant) args[1]; final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2]; final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3]; +final boolean placeStaticFieldsOutsideClassBody = ((Boolean) args[4]).booleanValue(); importManager.emitPackageStatement(stringBuffer); stringBuffer.append(TEXT_1); @@ -81,8 +94,45 @@ stringBuffer.append(TEXT_13); } stringBuffer.append(TEXT_14); - importManager.emitSortedImports(); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean placeStaticFieldsOutsideClassBody +if (placeStaticFieldsOutsideClassBody){ stringBuffer.append(TEXT_15); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_16); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_17); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_18); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_19); + +} + + } else { + stringBuffer.append(TEXT_20); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); + stringBuffer.append(TEXT_21); + stringBuffer.append(next.getType()); + stringBuffer.append(TEXT_22); + stringBuffer.append(next.getName()); + stringBuffer.append(TEXT_23); + stringBuffer.append(next.getValue()); + stringBuffer.append(TEXT_24); + +} + + stringBuffer.append(TEXT_25); + } + importManager.emitSortedImports(); + stringBuffer.append(TEXT_26); return stringBuffer.toString(); } } Index: templates/Color.jetinc =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc,v retrieving revision 1.3 diff -u -r1.3 Color.jetinc --- templates/Color.jetinc 6 Feb 2006 18:10:23 -0000 1.3 +++ templates/Color.jetinc 26 Jun 2006 15:40:24 -0000 @@ -1 +1,22 @@ -<%if (colorVal instanceof RGBColor) {%>new <%=importManager.getImportedName("org.eclipse.swt.graphics.Color")%>(null, <%=((RGBColor) colorVal).getRed()%>, <%=((RGBColor) colorVal).getGreen()%>, <%=((RGBColor) colorVal).getBlue()%>)<%} else if (colorVal instanceof ConstantColor) {%><%=importManager.getImportedName("org.eclipse.draw2d.ColorConstants")%>.<%=((ConstantColor) colorVal).getValue().getLiteral()%><%}%> \ No newline at end of file +<% +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + +{ //namespace + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue; + if (colorVal instanceof RGBColor){ + staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + } else if (colorVal instanceof ConstantColor){ + staticFieldValue = importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral(); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } +%> +<%=dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)%> +<% +} //namespace +%> \ No newline at end of file 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.20 diff -u -r1.20 FigureGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java 23 May 2006 21:09:44 -0000 1.20 +++ src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java 26 Jun 2006 15:40:23 -0000 @@ -80,12 +80,14 @@ public class FigureGenerator implements TextEmitter { private GraphDefDispatcher myTopDispatcher; private GraphDefDispatcher myInnerDispatcher; + private final boolean myPlaceStaticFieldsOutsideClassBody; - public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch) { - this(figureNameSwitch, new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode()); + public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, boolean placeStaticFieldsOutsideClassBody) { + this(figureNameSwitch, new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode(), placeStaticFieldsOutsideClassBody); } - public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, MapModeCodeGenStrategy mapModeStrategy) { + public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, MapModeCodeGenStrategy mapModeStrategy, boolean placeStaticFieldsOutsideClassBody) { + myPlaceStaticFieldsOutsideClassBody = placeStaticFieldsOutsideClassBody; final Bundle thisBundle = Platform.getBundle("org.eclipse.gmf.graphdef.codegen"); final String[] variables = new String[] { "org.eclipse.gmf.graphdef", @@ -177,9 +179,9 @@ public String go(Figure fig, ImportAssistant importManager/*, Feedback feedback*/) { String res = null; - myTopDispatcher.setImportManager(importManager); - myInnerDispatcher.setImportManager(importManager); - Object args = new Object[] {fig, importManager, myTopDispatcher.getFQNSwitch(), myInnerDispatcher}; + myTopDispatcher.resetForNewClass(importManager); + myInnerDispatcher.resetForNewClass(importManager); + Object args = new Object[] {fig, importManager, myTopDispatcher.getFQNSwitch(), myInnerDispatcher, Boolean.valueOf(myPlaceStaticFieldsOutsideClassBody)}; res = myTopDispatcher.dispatch(fig, args); if (res == null) { throw new IllegalStateException(); Index: src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java,v retrieving revision 1.6 diff -u -r1.6 GraphDefDispatcher.java --- src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java 18 May 2006 19:12:40 -0000 1.6 +++ src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java 26 Jun 2006 15:40:23 -0000 @@ -27,12 +27,18 @@ private ImportAssistant myImportManager; private final FigureQualifiedNameSwitch myFqnSwitch; private final MapModeCodeGenStrategy myMapModeStrategy; + private final StaticFieldsManagerImpl myStaticFieldsManager; public GraphDefDispatcher(EmitterFactory factory, KeyMap keyMap, FigureQualifiedNameSwitch fqnSwitch, MapModeCodeGenStrategy mapModeStrategy) { super(factory, keyMap); assert mapModeStrategy != null; myFqnSwitch = fqnSwitch; - myMapModeStrategy = mapModeStrategy; + myMapModeStrategy = mapModeStrategy; + myStaticFieldsManager = new StaticFieldsManagerImpl(); + } + + public StaticFieldsManager getStaticFieldsManager(){ + return myStaticFieldsManager; } public String DPtoLP(int deviceUnit){ @@ -46,14 +52,12 @@ public ImportAssistant getImportManager() { return myImportManager; } - - /** - * Not good. Would be better to have importManager as part of Args, perhaps. - */ - /*package-local*/ void setImportManager(ImportAssistant manager) { - myImportManager = manager; + + /*package-local*/ void resetForNewClass(ImportAssistant assistant) { + setImportManager(assistant); + myStaticFieldsManager.reset(); } - + public FigureQualifiedNameSwitch getFQNSwitch() { return myFqnSwitch; } @@ -73,6 +77,10 @@ public LayoutArgs createLayoutArgs(Args inherit, String managerVarName, String constraintVarName) { return new LayoutArgs(inherit, managerVarName, constraintVarName); } + + private void setImportManager(ImportAssistant manager) { + myImportManager = manager; + } public static class Args { private final Figure myFigure; Index: src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java,v retrieving revision 1.10 diff -u -r1.10 StandaloneGenerator.java --- src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java 24 May 2006 14:57:46 -0000 1.10 +++ src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java 26 Jun 2006 15:40:23 -0000 @@ -129,7 +129,7 @@ strategy = new MapModeCodeGenStrategy.StaticIdentityMapMode(); } - myFigureGenerator = new FigureGenerator(fqnSwitch, strategy); + myFigureGenerator = new FigureGenerator(fqnSwitch, strategy, false); myAuxiliaryGenerators = new StandaloneEmitters(); } Index: templates/new/LineBorder.javajet =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet,v retrieving revision 1.1 diff -u -r1.1 LineBorder.javajet --- templates/new/LineBorder.javajet 31 Mar 2006 18:08:36 -0000 1.1 +++ templates/new/LineBorder.javajet 26 Jun 2006 15:40:24 -0000 @@ -14,6 +14,7 @@ boolean hasColor = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Color()); boolean hasWidth = border.eIsSet(GMFGraphPackage.eINSTANCE.getLineBorder_Width()); Color colorVal = (hasColor) ? border.getColor() : null; + String colorName = (hasColor) ? "BORDER" : null; if (hasColor && hasWidth){ %> new <%=borderClazz%>(<%@ include file="../Color.jetinc"%>, <%=dispatcher.DPtoLP(border.getWidth())%>) Index: src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java diff -N src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,26 @@ +/* + * 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.graphdef.codegen; + +import java.util.Iterator; + +public interface StaticFieldsManager { + public String addStaticField(String type, String nameHint, String value); + public Iterator /**/ allFields(); + + public static interface StaticField { + public String getName(); + public String getType(); + public String getValue(); + } +} Index: templates/top/staticFields.jetinc =================================================================== RCS file: templates/top/staticFields.jetinc diff -N templates/top/staticFields.jetinc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ templates/top/staticFields.jetinc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,12 @@ +<% +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) { + StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); %> + + /** + * @generated + */ + public static final <%=next.getType()%> <%=next.getName()%> = <%=next.getValue()%>; +<% +} +%> Index: src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManagerImpl.java =================================================================== RCS file: src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManagerImpl.java diff -N src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManagerImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManagerImpl.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,79 @@ +/* + * 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.graphdef.codegen; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class StaticFieldsManagerImpl implements StaticFieldsManager { + private final Map/**/ myFields = new HashMap/**/(); + private final Map/**/ myFieldsRO = Collections.unmodifiableMap(myFields); + private final String myDeclaringClassPrefix; + + public StaticFieldsManagerImpl(String declaringClassName){ + myDeclaringClassPrefix = (declaringClassName == null || declaringClassName.length() == 0) ? + "" : declaringClassName + "."; + } + + public StaticFieldsManagerImpl(){ + this(null); + } + + public String addStaticField(String type, String nameHint, String value) { + int suffix = 0; + String actualName; + do { + actualName = nameHint + ((suffix == 0) ? "" : "_" + suffix); + suffix++; + } while (myFields.containsKey(actualName)); + StaticField field = new StaticFieldImpl(type, actualName, value); + myFields.put(actualName, field); + return myDeclaringClassPrefix + actualName; + } + + public void reset() { + myFields.clear(); + } + + public Iterator allFields() { + return myFieldsRO.values().iterator(); + } + + private static class StaticFieldImpl implements StaticField { + private final String myType; + private final String myName; + private final String myValue; + + public StaticFieldImpl(String type, String name, String value){ + myType = type; + myName = name; + myValue = value; + } + + public String getName() { + return myName; + } + + public String getType() { + return myType; + } + + public String getValue() { + return myValue; + } + + } + +} Index: templates/top/classFooter.jetinc =================================================================== RCS file: templates/top/classFooter.jetinc diff -N templates/top/classFooter.jetinc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ templates/top/classFooter.jetinc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,10 @@ +<% +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean placeStaticFieldsOutsideClassBody +if (placeStaticFieldsOutsideClassBody){ %> +} + <%@ include file="staticFields.jetinc"%> +<% } else { %> + <%@ include file="staticFields.jetinc"%> +} +<%}%> #P org.eclipse.gmf.bridge Index: src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java,v retrieving revision 1.1 diff -u -r1.1 InnerClassViewmapProducer.java --- src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java 26 Jun 2006 14:05:04 -0000 1.1 +++ src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java 26 Jun 2006 15:40:26 -0000 @@ -63,7 +63,7 @@ assert figureNameSwitch != null; fqnSwitch = figureNameSwitch; processedFigures = new HashSet(); - figureGenerator = new FigureGenerator(fqnSwitch, mapModeCodeGenStrategy); + figureGenerator = new FigureGenerator(fqnSwitch, mapModeCodeGenStrategy, true); } public Viewmap create(Node node) { #P org.eclipse.gmf.tests Index: src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java,v retrieving revision 1.4 diff -u -r1.4 MapModeStrategyTest.java --- src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java 18 May 2006 19:12:43 -0000 1.4 +++ src/org/eclipse/gmf/tests/gen/MapModeStrategyTest.java 26 Jun 2006 15:40:27 -0000 @@ -79,6 +79,6 @@ } private FigureGenerator createGenerator(MapModeCodeGenStrategy strategy) { - return new FigureGenerator(new RuntimeFQNSwitch(), strategy); + return new FigureGenerator(new RuntimeFQNSwitch(), strategy, false); } } Index: src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java,v retrieving revision 1.2 diff -u -r1.2 ShapePropertiesTest.java --- src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java 17 May 2006 11:30:52 -0000 1.2 +++ src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java 26 Jun 2006 15:40:27 -0000 @@ -15,11 +15,10 @@ import java.util.Iterator; import org.eclipse.gmf.gmfgraph.BasicFont; -import org.eclipse.gmf.gmfgraph.Color; import org.eclipse.gmf.gmfgraph.ColorConstants; import org.eclipse.gmf.gmfgraph.CompoundBorder; -import org.eclipse.gmf.gmfgraph.ConstantColor; import org.eclipse.gmf.gmfgraph.Dimension; +import org.eclipse.gmf.gmfgraph.FontStyle; import org.eclipse.gmf.gmfgraph.GMFGraphFactory; import org.eclipse.gmf.gmfgraph.Insets; import org.eclipse.gmf.gmfgraph.LineBorder; @@ -53,6 +52,13 @@ shape.setName("Bold"); performTests(shape); } + + public void testShapeFont(){ + Shape shape = GMFGraphFactory.eINSTANCE.createRoundedRectangle(); + shape.setName("WithArialFont"); + shape.setFont(createBasicFont("Arial", 10, FontStyle.NORMAL_LITERAL)); + performTests(shape); + } public void testShapeInsets() { Rectangle withInsets = GMFGraphFactory.eINSTANCE.createRectangle(); @@ -192,8 +198,6 @@ performTests(root); } - - private Dimension createDimension(int x, int y){ Dimension result = GMFGraphFactory.eINSTANCE.createDimension(); result.setDx(x); @@ -201,12 +205,4 @@ return result; } - private Color createConstantColor(ColorConstants constant) { - ConstantColor result = GMFGraphFactory.eINSTANCE.createConstantColor(); - result.setValue(constant); - return result; - } - - - } 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.9 diff -u -r1.9 FigureCodegenTest.java --- src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java 18 May 2006 19:12:43 -0000 1.9 +++ src/org/eclipse/gmf/tests/gen/FigureCodegenTest.java 26 Jun 2006 15:40:27 -0000 @@ -11,6 +11,8 @@ */ package org.eclipse.gmf.tests.gen; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.Arrays; import org.eclipse.draw2d.BendpointConnectionRouter; @@ -28,11 +30,17 @@ import org.eclipse.gmf.gmfgraph.CustomFigure; import org.eclipse.gmf.gmfgraph.Dimension; import org.eclipse.gmf.gmfgraph.Figure; +import org.eclipse.gmf.gmfgraph.FontStyle; import org.eclipse.gmf.gmfgraph.GMFGraphFactory; import org.eclipse.gmf.gmfgraph.Insets; +import org.eclipse.gmf.gmfgraph.Label; +import org.eclipse.gmf.gmfgraph.LineBorder; +import org.eclipse.gmf.gmfgraph.Rectangle; import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch; import org.eclipse.gmf.graphdef.codegen.FigureGenerator; import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; /** * @author artem @@ -65,7 +73,7 @@ public void testGenFigureWithoutPackageStmt() { myFigurePackageName = null; - setCustomFigureGenerator(new FigureGenerator(new RuntimeFQNSwitch())); + setCustomFigureGenerator(new FigureGenerator(new RuntimeFQNSwitch(), false)); testGenComplexShape(); } @@ -206,4 +214,100 @@ custom.setName(CodeGenUtil.getSimpleClassName(ScrollBar.class.getName())); performTests(custom, CHECK_CAN_CREATE_INSTANCE); } + + public void testFigureWithTwoBorderedChildren(){ + //check that border color static fields do not clash with each other + Figure root = GMFGraphFactory.eINSTANCE.createRectangle(); + root.setName("MultiBorderedRoot"); + + Figure constantlyBordered = GMFGraphFactory.eINSTANCE.createRectangle(); + constantlyBordered.setName("WithRedConstantBorder"); + LineBorder constantRedBorder = GMFGraphFactory.eINSTANCE.createLineBorder(); + constantRedBorder.setColor(createConstantColor(ColorConstants.RED_LITERAL)); + constantRedBorder.setWidth(5); + constantlyBordered.setBorder(constantRedBorder); + root.getChildren().add(constantlyBordered); + + Figure rgbBordered = GMFGraphFactory.eINSTANCE.createRectangle(); + rgbBordered.setName("WithRedRGBBorder"); + LineBorder rgbRedBorder = GMFGraphFactory.eINSTANCE.createLineBorder(); + rgbRedBorder.setColor(createRGBColor(255, 0, 0)); + rgbRedBorder.setWidth(7); + rgbBordered.setBorder(rgbRedBorder); + root.getChildren().add(rgbBordered); + + FigureCheck staticFieldsCheck = new StaticFieldsChecker(2, Color.class); + performTests(root, combineChecks(new GenericFigureCheck(root), staticFieldsCheck)); + } + + public void testFigureWithStaticFieldsForColorAndFonts(){ + Figure root = GMFGraphFactory.eINSTANCE.createEllipse(); + root.setName("FullOfColorsAndFonts"); + root.setFont(createBasicFont("Arial", 23, FontStyle.BOLD_LITERAL)); + root.setForegroundColor(createConstantColor(ColorConstants.ORANGE_LITERAL)); + root.setBackgroundColor(createConstantColor(ColorConstants.GREEN_LITERAL)); + + Label sansLabel = GMFGraphFactory.eINSTANCE.createLabel(); + sansLabel.setName("SansLabel"); + sansLabel.setFont(createBasicFont("Sans", 8, FontStyle.ITALIC_LITERAL)); + sansLabel.setForegroundColor(createConstantColor(ColorConstants.BLUE_LITERAL)); + root.getChildren().add(sansLabel); + + Label tahomaLabel = GMFGraphFactory.eINSTANCE.createLabel(); + tahomaLabel.setName("TahomaLabel"); + tahomaLabel.setFont(createBasicFont("Tahoma", 12, FontStyle.NORMAL_LITERAL)); + tahomaLabel.setForegroundColor(createConstantColor(ColorConstants.YELLOW_LITERAL)); + root.getChildren().add(tahomaLabel); + + Rectangle deepLabelContainer = GMFGraphFactory.eINSTANCE.createRectangle(); + deepLabelContainer.setName("DeepLabelContainer"); + deepLabelContainer.setForegroundColor(createRGBColor(123, 23, 3)); + deepLabelContainer.setBackgroundColor(createRGBColor(2, 123, 23)); + root.getChildren().add(deepLabelContainer); + + Label defaultFontLabel = GMFGraphFactory.eINSTANCE.createLabel(); + defaultFontLabel.setName("DefaultFontLabel"); + defaultFontLabel.setFont(createBasicFont(null, 34, FontStyle.BOLD_LITERAL)); + defaultFontLabel.setForegroundColor(createConstantColor(ColorConstants.CYAN_LITERAL)); + deepLabelContainer.getChildren().add(defaultFontLabel); + + FigureCheck fontFieldsCheck = new StaticFieldsChecker(4, Font.class); //root + 3 labels + FigureCheck colorFieldsCheck = new StaticFieldsChecker(2 + 2 + 3, Color.class); //root * 2 + deepContainer * 2 + 3 labels * 1 + + performTests(root, combineChecks(fontFieldsCheck, colorFieldsCheck)); + } + + public void testConnectionWithColor(){ + org.eclipse.gmf.gmfgraph.PolylineConnection link = GMFGraphFactory.eINSTANCE.createPolylineConnection(); + link.setName("AlmostRedLink"); + link.setForegroundColor(createRGBColor(255, 1, 1)); + + FigureCheck colorFieldsCheck = new StaticFieldsChecker(1, Color.class); + performTests(link, colorFieldsCheck); + } + + private static class StaticFieldsChecker extends FigureCheck { + private final int myExpectedFieldCount; + private final Class myFieldClazz; + + public StaticFieldsChecker(int expectedFieldCount, Class fieldClazz){ + myExpectedFieldCount = expectedFieldCount; + myFieldClazz = fieldClazz; + } + + public void checkFigure(IFigure figure) { + Class figureClazz = figure.getClass(); + Field[] fields = figureClazz.getDeclaredFields(); + int staticFinalFields = 0; + for (int i = 0; i < fields.length; i++){ + Field next = fields[i]; + int modifiers = next.getModifiers(); + if (myFieldClazz.equals(next.getType()) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)){ + staticFinalFields++; + } + } + assertTrue("Expected: at least " + myExpectedFieldCount +" constants of type :" + myFieldClazz.getSimpleName() + ". Actual: " + staticFinalFields, staticFinalFields >= myExpectedFieldCount); + } + } + } 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.13 diff -u -r1.13 FigureCodegenTestBase.java --- src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 23 May 2006 21:09:48 -0000 1.13 +++ src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java 26 Jun 2006 15:40:27 -0000 @@ -33,6 +33,7 @@ import org.eclipse.gmf.gmfgraph.Ellipse; import org.eclipse.gmf.gmfgraph.Figure; import org.eclipse.gmf.gmfgraph.FigureGallery; +import org.eclipse.gmf.gmfgraph.Font; import org.eclipse.gmf.gmfgraph.FontStyle; import org.eclipse.gmf.gmfgraph.GMFGraphFactory; import org.eclipse.gmf.gmfgraph.Label; @@ -41,6 +42,7 @@ import org.eclipse.gmf.gmfgraph.Polygon; import org.eclipse.gmf.gmfgraph.PolygonDecoration; import org.eclipse.gmf.gmfgraph.PolylineConnection; +import org.eclipse.gmf.gmfgraph.RGBColor; import org.eclipse.gmf.gmfgraph.Rectangle; import org.eclipse.gmf.gmfgraph.RoundedRectangle; import org.eclipse.gmf.gmfgraph.util.RuntimeFQNSwitch; @@ -142,7 +144,7 @@ try { StandaloneGenerator generator = new StandaloneGenerator(new GalleryProcessor(gallery), config, new RuntimeFQNSwitch()); generator.run(); - assertTrue(generator.getRunStatus().getSeverity() < IStatus.ERROR); + assertTrue(generator.getRunStatus().toString(), generator.getRunStatus().getSeverity() < IStatus.ERROR); Bundle bundle = installPlugin(config.getPluginID()); @@ -210,22 +212,12 @@ Label l1 = GMFGraphFactory.eINSTANCE.createLabel(); l1.setText("aaaaa"); l1.setName("L1"); - BasicFont f1 = GMFGraphFactory.eINSTANCE.createBasicFont(); - f1.setFaceName("Arial"); - f1.setHeight(9); - f1.setStyle(FontStyle.ITALIC_LITERAL); - l1.setFont(f1); - ConstantColor c = GMFGraphFactory.eINSTANCE.createConstantColor(); - c.setValue(ColorConstants.CYAN_LITERAL); - l1.setForegroundColor(c); + l1.setFont(createBasicFont("Arial", 9, FontStyle.ITALIC_LITERAL)); + l1.setForegroundColor(createConstantColor(ColorConstants.CYAN_LITERAL)); Label l2 = GMFGraphFactory.eINSTANCE.createLabel(); l2.setText("bbbbb"); l2.setName("L2"); - BasicFont f2 = GMFGraphFactory.eINSTANCE.createBasicFont(); - f2.setFaceName("Helvetica"); - f2.setHeight(12); - f2.setStyle(FontStyle.BOLD_LITERAL); - l2.setFont(f2); + l2.setFont(createBasicFont("Helvetica", 12, FontStyle.BOLD_LITERAL)); r.getChildren().add(l1); r.getChildren().add(l2); return r; @@ -302,7 +294,7 @@ private FigureGenerator getGenerator() { if (figureGenerator == null) { - figureGenerator = new FigureGenerator(new RuntimeFQNSwitch()); + figureGenerator = new FigureGenerator(new RuntimeFQNSwitch(), false); } return figureGenerator; } @@ -350,6 +342,28 @@ return combineChecks(new FigureCheck[] {first, second}); } + protected static final ConstantColor createConstantColor(ColorConstants constant) { + ConstantColor result = GMFGraphFactory.eINSTANCE.createConstantColor(); + result.setValue(constant); + return result; + } + + protected static final RGBColor createRGBColor(int red, int green, int blue) { + RGBColor result = GMFGraphFactory.eINSTANCE.createRGBColor(); + result.setRed(red); + result.setGreen(green); + result.setBlue(blue); + return result; + } + + protected static final Font createBasicFont(String name, int height, FontStyle style){ + BasicFont result = GMFGraphFactory.eINSTANCE.createBasicFont(); + result.setFaceName(name); + result.setHeight(height); + result.setStyle(style); + return result; + } + protected static class GeneratedClassData { private final Figure myFigureDef; private final Class myLoadedClass;