diff options
author | atikhomirov | 2006-06-26 16:49:24 +0000 |
---|---|---|
committer | atikhomirov | 2006-06-26 16:49:24 +0000 |
commit | 9093b1177a22db7285ea170ba61cba9949ccb6b7 (patch) | |
tree | 55c46fa43eab0565e78f9fb22133f74c35a995dd /plugins | |
parent | d77721c7f3422e6108bea6de89e0016c1a40c0d7 (diff) | |
download | org.eclipse.gmf-tooling-9093b1177a22db7285ea170ba61cba9949ccb6b7.tar.gz org.eclipse.gmf-tooling-9093b1177a22db7285ea170ba61cba9949ccb6b7.tar.xz org.eclipse.gmf-tooling-9093b1177a22db7285ea170ba61cba9949ccb6b7.zip |
[mgolubev] #148402 Do not create unlimited number of font/color resources.
Diffstat (limited to 'plugins')
16 files changed, 441 insertions, 215 deletions
diff --git a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java index e26d13720..fe46c5abf 100644 --- a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java +++ b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/InnerClassViewmapProducer.java @@ -63,7 +63,7 @@ public class InnerClassViewmapProducer extends DefaultViewmapProducer { assert figureNameSwitch != null; fqnSwitch = figureNameSwitch; processedFigures = new HashSet(); - figureGenerator = new FigureGenerator(fqnSwitch, mapModeCodeGenStrategy); + figureGenerator = new FigureGenerator(fqnSwitch, mapModeCodeGenStrategy, true); } public Viewmap create(Node node) { diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java index 9d7e34145..b7fb8860d 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java @@ -80,12 +80,14 @@ import org.osgi.framework.Bundle; public class FigureGenerator implements TextEmitter { private GraphDefDispatcher myTopDispatcher; private GraphDefDispatcher myInnerDispatcher; + private final boolean myIsInnerClassCode; - public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch) { - this(figureNameSwitch, new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode()); + public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, boolean asInnerClass) { + this(figureNameSwitch, new MapModeCodeGenStrategy.RuntimeUnspecifiedMapMode(), asInnerClass); } - public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, MapModeCodeGenStrategy mapModeStrategy) { + public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, MapModeCodeGenStrategy mapModeStrategy, boolean placeStaticFieldsOutsideClassBody) { + myIsInnerClassCode = 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 class FigureGenerator implements TextEmitter { 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(myIsInnerClassCode)}; res = myTopDispatcher.dispatch(fig, args); if (res == null) { throw new IllegalStateException(); diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java index 9eb244038..14e6563db 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java @@ -27,12 +27,18 @@ public class GraphDefDispatcher extends DispatcherImpl { private ImportAssistant myImportManager; private final FigureQualifiedNameSwitch myFqnSwitch; private final MapModeCodeGenStrategy myMapModeStrategy; + private final StaticFieldsManager 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 StaticFieldsManager(); + } + + public StaticFieldsManager getStaticFieldsManager(){ + return myStaticFieldsManager; } public String DPtoLP(int deviceUnit){ @@ -46,12 +52,13 @@ public class GraphDefDispatcher extends DispatcherImpl { 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() { @@ -73,6 +80,10 @@ public class GraphDefDispatcher extends DispatcherImpl { 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; diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java index 06955f8ef..74fe79487 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java @@ -129,7 +129,7 @@ public class StandaloneGenerator extends GeneratorBase { strategy = new MapModeCodeGenStrategy.StaticIdentityMapMode(); } - myFigureGenerator = new FigureGenerator(fqnSwitch, strategy); + myFigureGenerator = new FigureGenerator(fqnSwitch, strategy, false); myAuxiliaryGenerators = new StandaloneEmitters(); } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java new file mode 100644 index 000000000..9499bf30a --- /dev/null +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StaticFieldsManager.java @@ -0,0 +1,77 @@ +/* + * 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 StaticFieldsManager { + private final Map/*<String, StaticField>*/ myFields = new HashMap/*<String, StaticField>*/(); + private final Map/*<String, StaticField>*/ myFieldsRO = Collections.unmodifiableMap(myFields); + private final String myDeclaringClassPrefix; + + public StaticFieldsManager(String declaringClassName){ + myDeclaringClassPrefix = (declaringClassName == null || declaringClassName.length() == 0) ? + "" : declaringClassName + "."; + } + + public StaticFieldsManager(){ + 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 StaticField(type, actualName, value); + myFields.put(actualName, field); + return myDeclaringClassPrefix + actualName; + } + + public void reset() { + myFields.clear(); + } + + public Iterator allFields() { + return myFieldsRO.values().iterator(); + } + + public static class StaticField { + private final String myType; + private final String myName; + private final String myValue; + + public StaticField(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; + } + } +} diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java index 45d63e1be..08ff21c27 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/FigureAttrGenerator.java @@ -18,58 +18,41 @@ public class FigureAttrGenerator 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_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_25 = ", "; - 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_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_3 = NL + NL + ");"; + protected final String TEXT_4 = NL + "\t\t"; + protected final String TEXT_5 = ".setBackgroundColor("; + protected final String TEXT_6 = NL + NL + ");"; + protected final String TEXT_7 = NL + "\t\t"; + protected final String TEXT_8 = ".setPreferredSize("; + protected final String TEXT_9 = ", "; + protected final String TEXT_10 = ");"; + protected final String TEXT_11 = NL + "\t\t"; + protected final String TEXT_12 = ".setSize("; + protected final String TEXT_13 = ", "; + protected final String TEXT_14 = ");"; + protected final String TEXT_15 = NL + "\t\t"; + protected final String TEXT_16 = ".setMaximumSize(new "; + protected final String TEXT_17 = "("; + protected final String TEXT_18 = ", "; + protected final String TEXT_19 = "));"; + protected final String TEXT_20 = NL + "\t\t"; + protected final String TEXT_21 = ".setMinimumSize(new "; + protected final String TEXT_22 = "("; + protected final String TEXT_23 = ", "; + protected final String TEXT_24 = "));"; + protected final String TEXT_25 = NL + "\t\t"; + protected final String TEXT_26 = ".setFont(" + NL + "\t\t\t"; + protected final String TEXT_27 = ");"; + protected final String TEXT_28 = NL + "\t\t"; + protected final String TEXT_29 = ".setBorder(new "; + protected final String TEXT_30 = "("; + protected final String TEXT_31 = ", "; + protected final String TEXT_32 = ", "; + protected final String TEXT_33 = ", "; + protected final String TEXT_34 = "));"; + protected final String TEXT_35 = NL + "\t\t"; + protected final String TEXT_36 = ".setBorder("; + protected final String TEXT_37 = ");"; public String generate(Object argument) { @@ -81,89 +64,99 @@ final String figureVarName = args.getVariableName(); 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 + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(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(TEXT_4); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_5); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_6); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_7); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - 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); + colorName = figureInstance.getName().toUpperCase() + "_BACK"; + stringBuffer.append(TEXT_4); 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); + stringBuffer.append(TEXT_5); + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + + stringBuffer.append(TEXT_6); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_PreferredSize())) { Dimension d = figureInstance.getPreferredSize(); - stringBuffer.append(TEXT_19); + stringBuffer.append(TEXT_7); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_8); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_9); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_10); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Size())) { Point p = figureInstance.getSize(); - stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_11); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_12); stringBuffer.append(dispatcher.DPtoLP(p.getX())); - stringBuffer.append(TEXT_25); + stringBuffer.append(TEXT_13); stringBuffer.append(dispatcher.DPtoLP(p.getY())); - stringBuffer.append(TEXT_26); + stringBuffer.append(TEXT_14); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MaximumSize())) { Dimension d = figureInstance.getMaximumSize(); - stringBuffer.append(TEXT_27); + stringBuffer.append(TEXT_15); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_28); + stringBuffer.append(TEXT_16); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")); - stringBuffer.append(TEXT_29); + stringBuffer.append(TEXT_17); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_30); + stringBuffer.append(TEXT_18); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_31); + stringBuffer.append(TEXT_19); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_MinimumSize())) { Dimension d = figureInstance.getMinimumSize(); - stringBuffer.append(TEXT_32); + stringBuffer.append(TEXT_20); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_33); + stringBuffer.append(TEXT_21); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.geometry.Dimension")); - stringBuffer.append(TEXT_34); + stringBuffer.append(TEXT_22); stringBuffer.append(dispatcher.DPtoLP(d.getDx())); - stringBuffer.append(TEXT_35); + stringBuffer.append(TEXT_23); stringBuffer.append(dispatcher.DPtoLP(d.getDy())); - stringBuffer.append(TEXT_36); + stringBuffer.append(TEXT_24); } 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 +168,37 @@ if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor()) } } - stringBuffer.append(TEXT_37); + stringBuffer.append(TEXT_25); 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_26); + 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_27); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Insets())) { Insets insets = figureInstance.getInsets(); - stringBuffer.append(TEXT_45); + stringBuffer.append(TEXT_28); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_46); + stringBuffer.append(TEXT_29); stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.MarginBorder")); - stringBuffer.append(TEXT_47); + stringBuffer.append(TEXT_30); stringBuffer.append(dispatcher.DPtoLP(insets.getTop())); - stringBuffer.append(TEXT_48); + stringBuffer.append(TEXT_31); stringBuffer.append(dispatcher.DPtoLP(insets.getLeft())); - stringBuffer.append(TEXT_49); + stringBuffer.append(TEXT_32); stringBuffer.append(dispatcher.DPtoLP(insets.getBottom())); - stringBuffer.append(TEXT_50); + stringBuffer.append(TEXT_33); stringBuffer.append(dispatcher.DPtoLP(insets.getRight())); - stringBuffer.append(TEXT_51); + stringBuffer.append(TEXT_34); } if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_Border())) { Border border = figureInstance.getBorder(); - stringBuffer.append(TEXT_52); + stringBuffer.append(TEXT_35); stringBuffer.append(figureVarName); - stringBuffer.append(TEXT_53); + stringBuffer.append(TEXT_36); stringBuffer.append(dispatcher.dispatch(border, new Object[] {border, dispatcher})); - stringBuffer.append(TEXT_54); + stringBuffer.append(TEXT_37); } return stringBuffer.toString(); } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java index fa91cb5c9..17476b376 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewLineBorderExpressionGenerator.java @@ -18,29 +18,17 @@ public class NewLineBorderExpressionGenerator 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_3 = NL + NL + ", "; + protected final String TEXT_4 = ")"; + protected final String TEXT_5 = NL + "new "; + protected final String TEXT_6 = "("; + protected final String TEXT_7 = NL + NL + ")"; + protected final String TEXT_8 = NL + "new "; + 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_12 = "()"; + protected final String TEXT_13 = NL; public String generate(Object argument) { @@ -59,69 +47,76 @@ final ImportAssistant importManager = dispatcher.getImportManager(); 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 + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(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(TEXT_4); - stringBuffer.append(((RGBColor) colorVal).getRed()); - stringBuffer.append(TEXT_5); - stringBuffer.append(((RGBColor) colorVal).getGreen()); - stringBuffer.append(TEXT_6); - stringBuffer.append(((RGBColor) colorVal).getBlue()); - stringBuffer.append(TEXT_7); - } else if (colorVal instanceof ConstantColor) { - stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants")); - 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(TEXT_4); } else if (hasColor && !hasWidth) { - stringBuffer.append(TEXT_11); + stringBuffer.append(TEXT_5); 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_6); + +//input: [oeg].gmfgraph.Color colorVal +//input: String colorName +//input: [oeg].common.codegen.ImportAssistant importManager +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; + + stringBuffer.append(dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)); + } else if (colorVal instanceof ConstantColor) { + stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()); + } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } + + stringBuffer.append(TEXT_7); } else if (!hasColor && hasWidth){ - stringBuffer.append(TEXT_20); + stringBuffer.append(TEXT_8); stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_21); + stringBuffer.append(TEXT_9); stringBuffer.append(dispatcher.DPtoLP(border.getWidth())); - stringBuffer.append(TEXT_22); + stringBuffer.append(TEXT_10); } else { - stringBuffer.append(TEXT_23); + stringBuffer.append(TEXT_11); stringBuffer.append(borderClazz); - stringBuffer.append(TEXT_24); + stringBuffer.append(TEXT_12); } - stringBuffer.append(TEXT_25); + stringBuffer.append(TEXT_13); return stringBuffer.toString(); } } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java index c534fc735..383d2eeb2 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java @@ -3,7 +3,8 @@ package org.eclipse.gmf.graphdef.codegen.templates; 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,19 @@ public class TopConnectionGenerator 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 + "}"; + protected final String TEXT_31 = NL; public String generate(Object argument) { @@ -46,6 +59,7 @@ 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 isInnerClass = ((Boolean) args[4]).booleanValue(); importManager.emitPackageStatement(stringBuffer); stringBuffer.append(TEXT_1); @@ -86,7 +100,45 @@ if (figure.getTargetDecoration() != null) { stringBuffer.append(TEXT_18); } stringBuffer.append(TEXT_19); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean isInnerClass +if (isInnerClass){ /*put fields out of inner class body*/ + 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(); + stringBuffer.append(TEXT_31); return stringBuffer.toString(); } } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java index 2709ef656..cf51e8846 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java +++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java @@ -4,6 +4,7 @@ import org.eclipse.gmf.gmfgraph.*; 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 @@ public class TopFigureGenerator 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 @@ 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 isInnerClass = ((Boolean) args[4]).booleanValue(); importManager.emitPackageStatement(stringBuffer); stringBuffer.append(TEXT_1); @@ -81,8 +94,45 @@ for (java.util.Iterator it = figure.getChildren().iterator(); it.hasNext(); ) { stringBuffer.append(TEXT_13); } stringBuffer.append(TEXT_14); - importManager.emitSortedImports(); + +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean isInnerClass +if (isInnerClass){ /*put fields out of inner class body*/ 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(); } } diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc index 9ed864a0e..a88e72277 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/Color.jetinc @@ -1 +1,17 @@ -<%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 + + if (colorVal instanceof RGBColor) { + String staticFieldType = importManager.getImportedName("org.eclipse.swt.graphics.Color"); + String staticFieldName = (colorName == null) ? "COLOR" : colorName; + String staticFieldValue = "new " + staticFieldType + "(null, " + ((RGBColor)colorVal).getRed() + ", " + ((RGBColor)colorVal).getGreen() + ", " + ((RGBColor)colorVal).getBlue() + ")"; +%><%=dispatcher.getStaticFieldsManager().addStaticField(staticFieldType, staticFieldName, staticFieldValue)%> +<% } else if (colorVal instanceof ConstantColor) {%><%=importManager.getImportedName("org.eclipse.draw2d.ColorConstants") + "." + ((ConstantColor) colorVal).getValue().getLiteral()%> +<% } else { + throw new IllegalStateException("Unknown color: " + colorVal); + } +%> + diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet index 5cac62da6..d15a4f8a5 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/Figure.javajet @@ -7,12 +7,16 @@ final String figureVarName = args.getVariableName(); 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 @@ if (figureInstance.eIsSet(GMFGraphPackage.eINSTANCE.getFigure_ForegroundColor()) } } %> - <%=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())%>)); diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet index 9a1e9de42..35824e222 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LineBorder.javajet @@ -14,6 +14,7 @@ final ImportAssistant importManager = dispatcher.getImportManager(); 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())%>) diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet index b84b34cef..aa4f4dba1 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet @@ -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 isInnerClass = ((Boolean) args[4]).booleanValue(); %> <%importManager.emitPackageStatement(stringBuffer);%> @@ -33,4 +34,5 @@ GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figur <%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();%> diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet index 3ee0477b8..c20e4c0c8 100644 --- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet @@ -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 isInnerClass = ((Boolean) args[4]).booleanValue(); %> <%importManager.emitPackageStatement(stringBuffer);%> @@ -50,4 +51,5 @@ if (figure.getTargetDecoration() != null) {%> return df; } <%}%> -}<%importManager.emitSortedImports();%>
\ No newline at end of file +<%@ include file="classFooter.jetinc"%> +<%importManager.emitSortedImports();%> diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc new file mode 100644 index 000000000..2143d1a51 --- /dev/null +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc @@ -0,0 +1,10 @@ +<% +//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher +//input: boolean isInnerClass +if (isInnerClass){ /*put fields out of inner class body*/ %> +} + <%@ include file="staticFields.jetinc"%> +<% } else { %> + <%@ include file="staticFields.jetinc"%> +} +<%}%> diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/staticFields.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/staticFields.jetinc new file mode 100644 index 000000000..2ddbf7166 --- /dev/null +++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/staticFields.jetinc @@ -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()%>; +<% +} +%> |