Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-08-24 13:13:36 +0000
committeratikhomirov2006-08-24 13:13:36 +0000
commit602bd6b0125c6564436cf870100d413d0e0f6bd7 (patch)
tree42a39366e32d491ffc5bc0635acf7dd0f6d82983 /plugins
parent4000ac816f4a9f03d43ad13ce3eacca4868565bc (diff)
downloadorg.eclipse.gmf-tooling-602bd6b0125c6564436cf870100d413d0e0f6bd7.tar.gz
org.eclipse.gmf-tooling-602bd6b0125c6564436cf870100d413d0e0f6bd7.tar.xz
org.eclipse.gmf-tooling-602bd6b0125c6564436cf870100d413d0e0f6bd7.zip
[154683] mgolubev - Handle custom borders.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java7
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java54
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/CustomClassAttributesGenerator.java9
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewCustomBorderExpressionGenerator.java38
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java160
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java146
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet9
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/customBorderFactoryMethods.jetinc38
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/new/CustomBorder.javajet11
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet8
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet4
11 files changed, 375 insertions, 109 deletions
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 b7fb8860d..8780a3126 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
@@ -20,6 +20,7 @@ import org.eclipse.gmf.common.codegen.ImportAssistant;
import org.eclipse.gmf.gmfgraph.BorderLayout;
import org.eclipse.gmf.gmfgraph.BorderLayoutData;
import org.eclipse.gmf.gmfgraph.CompoundBorder;
+import org.eclipse.gmf.gmfgraph.CustomBorder;
import org.eclipse.gmf.gmfgraph.CustomFigure;
import org.eclipse.gmf.gmfgraph.CustomLayout;
import org.eclipse.gmf.gmfgraph.CustomLayoutData;
@@ -52,6 +53,7 @@ import org.eclipse.gmf.graphdef.codegen.templates.InitGridLayoutGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.InitXYLayoutDataGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.LabelAttrGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.NewCompoundBorderExpressionGenerator;
+import org.eclipse.gmf.graphdef.codegen.templates.NewCustomBorderExpressionGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.NewFigureGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutDataGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutGenerator;
@@ -78,8 +80,8 @@ import org.osgi.framework.Bundle;
*
*/
public class FigureGenerator implements TextEmitter {
- private GraphDefDispatcher myTopDispatcher;
- private GraphDefDispatcher myInnerDispatcher;
+ private final GraphDefDispatcher myTopDispatcher;
+ private final GraphDefDispatcher myInnerDispatcher;
private final boolean myIsInnerClassCode;
public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, boolean asInnerClass) {
@@ -166,6 +168,7 @@ public class FigureGenerator implements TextEmitter {
tr.put(LineBorder.class, "/new/LineBorder.javajet", NewLineBorderExpressionGenerator.class);
tr.put(MarginBorder.class, "/new/MarginBorder.javajet", NewMarginBorderExpressionGenerator.class);
tr.put(CompoundBorder.class, "/new/CompoundBorder.javajet", NewCompoundBorderExpressionGenerator.class);
+ tr.put(CustomBorder.class, "/new/CustomBorder.javajet", NewCustomBorderExpressionGenerator.class);
return tr;
}
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 14e6563db..0095debe8 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
@@ -11,6 +11,9 @@
*/
package org.eclipse.gmf.graphdef.codegen;
+import java.util.HashMap;
+
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.common.codegen.ImportAssistant;
import org.eclipse.gmf.gmfgraph.Figure;
import org.eclipse.gmf.gmfgraph.Layout;
@@ -28,6 +31,7 @@ public class GraphDefDispatcher extends DispatcherImpl {
private final FigureQualifiedNameSwitch myFqnSwitch;
private final MapModeCodeGenStrategy myMapModeStrategy;
private final StaticFieldsManager myStaticFieldsManager;
+ private final AuxiliaryDataStorage myAuxiliaryDataStorage;
public GraphDefDispatcher(EmitterFactory factory, KeyMap keyMap, FigureQualifiedNameSwitch fqnSwitch, MapModeCodeGenStrategy mapModeStrategy) {
super(factory, keyMap);
@@ -35,6 +39,7 @@ public class GraphDefDispatcher extends DispatcherImpl {
myFqnSwitch = fqnSwitch;
myMapModeStrategy = mapModeStrategy;
myStaticFieldsManager = new StaticFieldsManager();
+ myAuxiliaryDataStorage = new AuxiliaryDataStorage();
}
public StaticFieldsManager getStaticFieldsManager(){
@@ -53,12 +58,17 @@ public class GraphDefDispatcher extends DispatcherImpl {
return myImportManager;
}
+ public AuxiliaryDataStorage getAuxiliaryDataStorage(){
+ return myAuxiliaryDataStorage;
+ }
+
/**
* Not good. Would be better to have importManager as part of Args, perhaps.
*/
/*package-local*/ void resetForNewClass(ImportAssistant assistant) {
setImportManager(assistant);
myStaticFieldsManager.reset();
+ myAuxiliaryDataStorage.reset();
}
public FigureQualifiedNameSwitch getFQNSwitch() {
@@ -84,6 +94,50 @@ public class GraphDefDispatcher extends DispatcherImpl {
private void setImportManager(ImportAssistant manager) {
myImportManager = manager;
}
+
+ /**
+ * "Write-once" map that allows to associate arbitrary data with some
+ * gmfgraph instance.
+ *
+ * It allows to generate some auxiliary code (say, getter method) for given
+ * gmfgraph instance in one template, store the getter name in the Storage
+ * and retrieve it in different template to insert call for this getter into
+ * different place.
+ *
+ * To avoid unexpected data loss, any key may be set only once and remains
+ * available during generation of some compilation unit. It is the reason
+ * for data to be declared as Object instead of String. If you need to
+ * associate 2 different strings with given object use ad hoc class to store
+ * data.
+ *
+ * NOTE: This data storage is automatically reset when owning dispatcher is
+ * reset for new compilation unit generation.
+ */
+ public static class AuxiliaryDataStorage {
+ private final HashMap myData;
+
+ public AuxiliaryDataStorage(){
+ myData = new HashMap();
+ }
+
+ public void registerData(EObject owner, Object data){
+ if (myData.containsKey(owner)){
+ throw new IllegalArgumentException("EObject: " + owner + " has registered data: " + myData.get(owner));
+ }
+ if (data == null){
+ throw new NullPointerException("Null data for EObject: " + owner);
+ }
+ myData.put(owner, data);
+ }
+
+ public Object getRegisteredData(EObject owner){
+ return myData.get(owner);
+ }
+
+ private void reset(){
+ myData.clear();
+ }
+ }
public static class Args {
private final Figure myFigure;
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/CustomClassAttributesGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/CustomClassAttributesGenerator.java
index 58ded5025..3a19c610c 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/CustomClassAttributesGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/CustomClassAttributesGenerator.java
@@ -39,9 +39,12 @@ public class CustomClassAttributesGenerator
final CustomClass instance = (CustomClass) ((Object[]) argument)[0];
//final GraphDefDispatcher dispatcher = (GraphDefDispatcher) ((Object[]) argument)[1];
final String varName = (String) ((Object[]) argument)[2];
-final boolean hasAttributes = !instance.getAttributes().isEmpty();
+boolean insertingArbitraryCode = false;
+for (Iterator attributes = instance.getAttributes().iterator(); !insertingArbitraryCode && attributes.hasNext();){
+ insertingArbitraryCode = ((CustomAttribute)attributes.next()).isMultiStatementValue();
+}
- if (hasAttributes) {
+ if (insertingArbitraryCode) {
stringBuffer.append(TEXT_1);
}
@@ -84,7 +87,7 @@ for (Iterator attrs = instance.getAttributes().iterator(); attrs.hasNext(); attr
} //for
- if (hasAttributes) {
+ if (insertingArbitraryCode) {
stringBuffer.append(TEXT_13);
}
stringBuffer.append(TEXT_14);
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewCustomBorderExpressionGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewCustomBorderExpressionGenerator.java
new file mode 100644
index 000000000..5c3505185
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/NewCustomBorderExpressionGenerator.java
@@ -0,0 +1,38 @@
+package org.eclipse.gmf.graphdef.codegen.templates;
+
+import org.eclipse.gmf.gmfgraph.*;
+import org.eclipse.gmf.graphdef.codegen.*;
+
+public class NewCustomBorderExpressionGenerator
+{
+ protected static String nl;
+ public static synchronized NewCustomBorderExpressionGenerator create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ NewCustomBorderExpressionGenerator result = new NewCustomBorderExpressionGenerator();
+ nl = null;
+ return result;
+ }
+
+ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+ protected final String TEXT_1 = "()";
+ protected final String TEXT_2 = NL;
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+
+Object[] args = (Object[]) argument;
+final CustomBorder border = (CustomBorder)args[0];
+final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
+//final ImportAssistant importManager = dispatcher.getImportManager();
+
+//We want NEITHER insert any names into the scope NOR produce statement. We need expression instead.
+//@see customBorderFactoryMethod.jetinc
+
+ stringBuffer.append(dispatcher.getAuxiliaryDataStorage().getRegisteredData(border));
+ stringBuffer.append(TEXT_1);
+ stringBuffer.append(TEXT_2);
+ 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 383d2eeb2..d906304c8 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
@@ -4,7 +4,10 @@ import org.eclipse.gmf.gmfgraph.*;
import org.eclipse.gmf.gmfgraph.util.*;
import org.eclipse.gmf.common.codegen.*;
import org.eclipse.gmf.graphdef.codegen.*;
+import org.eclipse.emf.ecore.*;
import java.util.Iterator;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.codegen.util.CodeGenUtil;;
public class TopConnectionGenerator
{
@@ -21,34 +24,42 @@ public class TopConnectionGenerator
protected final String TEXT_1 = "";
protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
protected final String TEXT_3 = " extends ";
- protected final String TEXT_4 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
- protected final String TEXT_5 = "() {";
- protected final String TEXT_6 = NL;
- protected final String TEXT_7 = NL + "\t\tsetSourceDecoration(createSourceDecoration());";
- protected final String TEXT_8 = NL + "\t\tsetTargetDecoration(createTargetDecoration());";
- protected final String TEXT_9 = NL + "\t}" + NL;
- protected final String TEXT_10 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
- protected final String TEXT_11 = " createSourceDecoration() {";
- protected final String TEXT_12 = NL;
- protected final String TEXT_13 = NL + "\t\treturn df;" + NL + "\t}";
+ protected final String TEXT_4 = " {" + NL;
+ protected final String TEXT_5 = NL;
+ protected final String TEXT_6 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_7 = " ";
+ protected final String TEXT_8 = "() {" + NL + "\t\t";
+ protected final String TEXT_9 = " result = new ";
+ protected final String TEXT_10 = "();" + NL + "\t\t";
+ protected final String TEXT_11 = NL + "\t\treturn result;" + NL + "\t}";
+ protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
+ protected final String TEXT_13 = "() {";
protected final String TEXT_14 = NL;
- protected final String TEXT_15 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
- 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_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;
+ protected final String TEXT_15 = NL + "\t\tsetSourceDecoration(createSourceDecoration());";
+ protected final String TEXT_16 = NL + "\t\tsetTargetDecoration(createTargetDecoration());";
+ protected final String TEXT_17 = NL + "\t}" + NL;
+ protected final String TEXT_18 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_19 = " createSourceDecoration() {";
+ protected final String TEXT_20 = NL;
+ protected final String TEXT_21 = NL + "\t\treturn df;" + NL + "\t}";
+ protected final String TEXT_22 = NL;
+ protected final String TEXT_23 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_24 = " createTargetDecoration() {";
+ protected final String TEXT_25 = NL;
+ protected final String TEXT_26 = NL + "\t\treturn df;" + NL + "\t}";
+ protected final String TEXT_27 = NL;
+ protected final String TEXT_28 = NL + "}" + NL + "\t";
+ protected final String TEXT_29 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
+ protected final String TEXT_30 = " ";
+ protected final String TEXT_31 = " = ";
+ protected final String TEXT_32 = ";";
+ protected final String TEXT_33 = NL + "\t";
+ protected final String TEXT_34 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
+ protected final String TEXT_35 = " ";
+ protected final String TEXT_36 = " = ";
+ protected final String TEXT_37 = ";";
+ protected final String TEXT_38 = NL + "}";
+ protected final String TEXT_39 = NL;
public String generate(Object argument)
{
@@ -69,76 +80,119 @@ final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
stringBuffer.append(TEXT_3);
stringBuffer.append(fqnSwitch.get(figure, importManager));
stringBuffer.append(TEXT_4);
- stringBuffer.append(figure.getName());
stringBuffer.append(TEXT_5);
+
+//input: [oeg].common.codegen.ImportAssistant importManager
+//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
+//input: [oeg].gmfgraph.Figure figure
+
+{ //namespace -- use "bfm" (stands for BorderFactoryMethod) to avoid name clashes
+ int bfmNextIndex = 1;
+ String bfmLastFigureName = "";
+ for (Iterator bfmAllCustomBorders = EcoreUtil.getAllContents(figure, false); bfmAllCustomBorders.hasNext();){
+ EObject bfmNext = (EObject)bfmAllCustomBorders.next();
+ if (GMFGraphPackage.eINSTANCE.getFigure().isSuperTypeOf(bfmNext.eClass())){
+ bfmLastFigureName = (String)bfmNext.eGet(GMFGraphPackage.eINSTANCE.getIdentity_Name());
+ if (bfmLastFigureName == null){
+ bfmLastFigureName = "";
+ }
+ }
+ // XXX [artem] why not do this with ((Figure) bfmNext).getBorder()?
+ if (bfmNext.eClass().getClassifierID() != GMFGraphPackage.CUSTOM_BORDER){
+ continue;
+ }
+
+ String bfmNextImplClass = dispatcher.getFQNSwitch().get(bfmNext, importManager);
+ String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
+
+
stringBuffer.append(TEXT_6);
+ stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.Border"));
+ stringBuffer.append(TEXT_7);
+ stringBuffer.append(bfmNextMethodName);
+ stringBuffer.append(TEXT_8);
+ stringBuffer.append(bfmNextImplClass);
+ stringBuffer.append(TEXT_9);
+ stringBuffer.append(bfmNextImplClass);
+ stringBuffer.append(TEXT_10);
+ stringBuffer.append(dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} ));
+ stringBuffer.append(TEXT_11);
+
+ dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
+ }
+} //end of namespace
+
+ stringBuffer.append(TEXT_12);
+ stringBuffer.append(figure.getName());
+ stringBuffer.append(TEXT_13);
+ stringBuffer.append(TEXT_14);
stringBuffer.append(dispatcher.dispatch("Shape", dispatcher.create(figure, "this")));
if (figure.getSourceDecoration() != null) {
- stringBuffer.append(TEXT_7);
+ stringBuffer.append(TEXT_15);
}
if (figure.getTargetDecoration() != null) {
- stringBuffer.append(TEXT_8);
+ stringBuffer.append(TEXT_16);
}
- stringBuffer.append(TEXT_9);
+ stringBuffer.append(TEXT_17);
if (figure.getSourceDecoration() != null) {
final String className = fqnSwitch.get(figure.getSourceDecoration(), importManager);
- stringBuffer.append(TEXT_10);
+ stringBuffer.append(TEXT_18);
stringBuffer.append(className);
- stringBuffer.append(TEXT_11);
- stringBuffer.append(TEXT_12);
+ stringBuffer.append(TEXT_19);
+ stringBuffer.append(TEXT_20);
stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getSourceDecoration(), "df")));
- stringBuffer.append(TEXT_13);
+ stringBuffer.append(TEXT_21);
} /*if sourceDecoration != null */
- stringBuffer.append(TEXT_14);
+ stringBuffer.append(TEXT_22);
if (figure.getTargetDecoration() != null) {
final String className = fqnSwitch.get(figure.getTargetDecoration(), importManager);
- stringBuffer.append(TEXT_15);
+ stringBuffer.append(TEXT_23);
stringBuffer.append(className);
- stringBuffer.append(TEXT_16);
- stringBuffer.append(TEXT_17);
+ stringBuffer.append(TEXT_24);
+ stringBuffer.append(TEXT_25);
stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getTargetDecoration(), "df")));
- stringBuffer.append(TEXT_18);
+ stringBuffer.append(TEXT_26);
}
- stringBuffer.append(TEXT_19);
+ stringBuffer.append(TEXT_27);
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
//input: boolean isInnerClass
if (isInnerClass){ /*put fields out of inner class body*/
- stringBuffer.append(TEXT_20);
+ stringBuffer.append(TEXT_28);
//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(TEXT_29);
stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_22);
+ stringBuffer.append(TEXT_30);
stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_23);
+ stringBuffer.append(TEXT_31);
stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_24);
+ stringBuffer.append(TEXT_32);
}
} else {
- stringBuffer.append(TEXT_25);
+ stringBuffer.append(TEXT_33);
//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(TEXT_34);
stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_27);
+ stringBuffer.append(TEXT_35);
stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_28);
+ stringBuffer.append(TEXT_36);
stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_29);
+ stringBuffer.append(TEXT_37);
}
- stringBuffer.append(TEXT_30);
+ stringBuffer.append(TEXT_38);
}
importManager.emitSortedImports();
- stringBuffer.append(TEXT_31);
+ stringBuffer.append(TEXT_39);
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 cf51e8846..b68248cce 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,7 +4,10 @@ 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;;
+import org.eclipse.emf.ecore.*;
+import java.util.Iterator;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.codegen.util.CodeGenUtil;;
public class TopFigureGenerator
{
@@ -21,29 +24,37 @@ public class TopFigureGenerator
protected final String TEXT_1 = "";
protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
protected final String TEXT_3 = " extends ";
- protected final String TEXT_4 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
- protected final String TEXT_5 = "() {";
- protected final String TEXT_6 = "\t" + NL + "\t\t";
- protected final String TEXT_7 = NL + "\t\t";
- protected final String TEXT_8 = NL + "\t\tcreateContents();" + NL + "\t}" + NL;
- protected final String TEXT_9 = NL;
- protected final String TEXT_10 = NL;
- 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 + "}" + 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;
+ protected final String TEXT_4 = " {" + NL;
+ protected final String TEXT_5 = NL;
+ protected final String TEXT_6 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_7 = " ";
+ protected final String TEXT_8 = "() {" + NL + "\t\t";
+ protected final String TEXT_9 = " result = new ";
+ protected final String TEXT_10 = "();" + NL + "\t\t";
+ protected final String TEXT_11 = NL + "\t\treturn result;" + NL + "\t}";
+ protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
+ protected final String TEXT_13 = "() {";
+ protected final String TEXT_14 = NL + "\t\t";
+ protected final String TEXT_15 = NL + "\t\t";
+ protected final String TEXT_16 = NL + "\t\tcreateContents();" + NL + "\t}" + NL;
+ protected final String TEXT_17 = NL;
+ protected final String TEXT_18 = NL;
+ protected final String TEXT_19 = NL;
+ protected final String TEXT_20 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = ";
+ protected final String TEXT_21 = ";" + 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_22 = NL;
+ protected final String TEXT_23 = NL + "}" + NL + "\t";
+ protected final String TEXT_24 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
+ protected final String TEXT_25 = " ";
+ protected final String TEXT_26 = " = ";
+ protected final String TEXT_27 = ";";
+ protected final String TEXT_28 = NL + "\t";
+ protected final String TEXT_29 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
+ protected final String TEXT_30 = " ";
+ protected final String TEXT_31 = " = ";
+ protected final String TEXT_32 = ";";
+ protected final String TEXT_33 = NL + "}";
+ protected final String TEXT_34 = NL;
public String generate(Object argument)
{
@@ -54,6 +65,8 @@ Figure figure = (Figure) args[0];
final ImportAssistant importManager = (ImportAssistant) args[1];
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
+
+//[MG] FIXME: Why we need this? Is it in use somewhere?
final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
importManager.emitPackageStatement(stringBuffer);
@@ -64,21 +77,64 @@ final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
stringBuffer.append(TEXT_3);
stringBuffer.append(fqnSwitch.get(figure, importManager));
stringBuffer.append(TEXT_4);
- stringBuffer.append(figure.getName());
stringBuffer.append(TEXT_5);
-GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
+//input: [oeg].common.codegen.ImportAssistant importManager
+//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
+//input: [oeg].gmfgraph.Figure figure
+
+{ //namespace -- use "bfm" (stands for BorderFactoryMethod) to avoid name clashes
+ int bfmNextIndex = 1;
+ String bfmLastFigureName = "";
+ for (Iterator bfmAllCustomBorders = EcoreUtil.getAllContents(figure, false); bfmAllCustomBorders.hasNext();){
+ EObject bfmNext = (EObject)bfmAllCustomBorders.next();
+ if (GMFGraphPackage.eINSTANCE.getFigure().isSuperTypeOf(bfmNext.eClass())){
+ bfmLastFigureName = (String)bfmNext.eGet(GMFGraphPackage.eINSTANCE.getIdentity_Name());
+ if (bfmLastFigureName == null){
+ bfmLastFigureName = "";
+ }
+ }
+ // XXX [artem] why not do this with ((Figure) bfmNext).getBorder()?
+ if (bfmNext.eClass().getClassifierID() != GMFGraphPackage.CUSTOM_BORDER){
+ continue;
+ }
+
+ String bfmNextImplClass = dispatcher.getFQNSwitch().get(bfmNext, importManager);
+ String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
+
stringBuffer.append(TEXT_6);
- stringBuffer.append(dispatcher.dispatch("createLayout", dispatcherArgs));
+ stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.Border"));
stringBuffer.append(TEXT_7);
- stringBuffer.append(dispatcher.dispatch(figure, dispatcherArgs));
+ stringBuffer.append(bfmNextMethodName);
stringBuffer.append(TEXT_8);
+ stringBuffer.append(bfmNextImplClass);
stringBuffer.append(TEXT_9);
- stringBuffer.append(dispatcher.dispatch("Children", dispatcherArgs));
+ stringBuffer.append(bfmNextImplClass);
stringBuffer.append(TEXT_10);
- if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/
+ stringBuffer.append(dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} ));
stringBuffer.append(TEXT_11);
+
+ dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
+ }
+} //end of namespace
+
+ stringBuffer.append(TEXT_12);
+ stringBuffer.append(figure.getName());
+ stringBuffer.append(TEXT_13);
+
+GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
+
+ stringBuffer.append(TEXT_14);
+ stringBuffer.append(dispatcher.dispatch("createLayout", dispatcherArgs));
+ stringBuffer.append(TEXT_15);
+ stringBuffer.append(dispatcher.dispatch(figure, dispatcherArgs));
+ stringBuffer.append(TEXT_16);
+ stringBuffer.append(TEXT_17);
+ stringBuffer.append(dispatcher.dispatch("Children", dispatcherArgs));
+ stringBuffer.append(TEXT_18);
+ if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/
+ stringBuffer.append(TEXT_19);
// simple heuristic to detect need for local coordinates
boolean useLocalDefaultValue = false;
@@ -89,50 +145,50 @@ for (java.util.Iterator it = figure.getChildren().iterator(); it.hasNext(); ) {
}
}
- stringBuffer.append(TEXT_12);
+ stringBuffer.append(TEXT_20);
stringBuffer.append(useLocalDefaultValue);
- stringBuffer.append(TEXT_13);
+ stringBuffer.append(TEXT_21);
}
- stringBuffer.append(TEXT_14);
+ stringBuffer.append(TEXT_22);
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
//input: boolean isInnerClass
if (isInnerClass){ /*put fields out of inner class body*/
- stringBuffer.append(TEXT_15);
+ stringBuffer.append(TEXT_23);
//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(TEXT_24);
stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_17);
+ stringBuffer.append(TEXT_25);
stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_18);
+ stringBuffer.append(TEXT_26);
stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_19);
+ stringBuffer.append(TEXT_27);
}
} else {
- stringBuffer.append(TEXT_20);
+ stringBuffer.append(TEXT_28);
//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(TEXT_29);
stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_22);
+ stringBuffer.append(TEXT_30);
stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_23);
+ stringBuffer.append(TEXT_31);
stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_24);
+ stringBuffer.append(TEXT_32);
}
- stringBuffer.append(TEXT_25);
+ stringBuffer.append(TEXT_33);
}
importManager.emitSortedImports();
- stringBuffer.append(TEXT_26);
+ stringBuffer.append(TEXT_34);
return stringBuffer.toString();
}
}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet
index fa176f2d8..afd9d391e 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet
@@ -4,9 +4,12 @@
final CustomClass instance = (CustomClass) ((Object[]) argument)[0];
//final GraphDefDispatcher dispatcher = (GraphDefDispatcher) ((Object[]) argument)[1];
final String varName = (String) ((Object[]) argument)[2];
-final boolean hasAttributes = !instance.getAttributes().isEmpty();
+boolean insertingArbitraryCode = false;
+for (Iterator attributes = instance.getAttributes().iterator(); !insertingArbitraryCode && attributes.hasNext();){
+ insertingArbitraryCode = ((CustomAttribute)attributes.next()).isMultiStatementValue();
+}
%>
-<% if (hasAttributes) {%>
+<% if (insertingArbitraryCode) {%>
{
<% }%>
<%
@@ -34,7 +37,7 @@ for (Iterator attrs = instance.getAttributes().iterator(); attrs.hasNext(); attr
<%
} //for
%>
-<% if (hasAttributes) {%>
+<% if (insertingArbitraryCode) {%>
}
<% }%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/customBorderFactoryMethods.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/customBorderFactoryMethods.jetinc
new file mode 100644
index 000000000..78d4422f3
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/customBorderFactoryMethods.jetinc
@@ -0,0 +1,38 @@
+<%
+//input: [oeg].common.codegen.ImportAssistant importManager
+//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
+//input: [oeg].gmfgraph.Figure figure
+
+{ //namespace -- use "bfm" (stands for BorderFactoryMethod) to avoid name clashes
+ int bfmNextIndex = 1;
+ String bfmLastFigureName = "";
+ for (Iterator bfmAllCustomBorders = EcoreUtil.getAllContents(figure, false); bfmAllCustomBorders.hasNext();){
+ EObject bfmNext = (EObject)bfmAllCustomBorders.next();
+ if (GMFGraphPackage.eINSTANCE.getFigure().isSuperTypeOf(bfmNext.eClass())){
+ bfmLastFigureName = (String)bfmNext.eGet(GMFGraphPackage.eINSTANCE.getIdentity_Name());
+ if (bfmLastFigureName == null){
+ bfmLastFigureName = "";
+ }
+ }
+ // XXX [artem] why not do this with ((Figure) bfmNext).getBorder()?
+ if (bfmNext.eClass().getClassifierID() != GMFGraphPackage.CUSTOM_BORDER){
+ continue;
+ }
+
+ String bfmNextImplClass = dispatcher.getFQNSwitch().get(bfmNext, importManager);
+ String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
+
+%>
+ /**
+ * @generated
+ */
+ private <%=importManager.getImportedName("org.eclipse.draw2d.Border")%> <%=bfmNextMethodName%>() {
+ <%=bfmNextImplClass%> result = new <%=bfmNextImplClass%>();
+ <%=dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} )%>
+ return result;
+ }
+<%
+ dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
+ }
+} //end of namespace
+%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/CustomBorder.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/CustomBorder.javajet
new file mode 100644
index 000000000..e77fec827
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/CustomBorder.javajet
@@ -0,0 +1,11 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewCustomBorderExpressionGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+Object[] args = (Object[]) argument;
+final CustomBorder border = (CustomBorder)args[0];
+final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
+//final ImportAssistant importManager = dispatcher.getImportManager();
+
+//We want NEITHER insert any names into the scope NOR produce statement. We need expression instead.
+//@see customBorderFactoryMethod.jetinc
+%><%=dispatcher.getAuxiliaryDataStorage().getRegisteredData(border)%>()
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 aa4f4dba1..ffb3a645f 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,13 @@
<%@ 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.* java.util.Iterator;"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.emf.ecore.* java.util.Iterator org.eclipse.emf.ecore.util.EcoreUtil org.eclipse.emf.codegen.util.CodeGenUtil; "%>
<%
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];
+
+//[MG] FIXME: Why we need this? Is it in use somewhere?
final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
%>
<%importManager.emitPackageStatement(stringBuffer);%>
@@ -17,13 +19,15 @@ final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
*/
public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
+<%@ include file="../customBorderFactoryMethods.jetinc"%>
+
/**
* @generated
*/
public <%=figure.getName()%>() {
<%
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
-%>
+%>
<%=dispatcher.dispatch("createLayout", dispatcherArgs)%>
<%=dispatcher.dispatch(figure, dispatcherArgs)%>
createContents();
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 c20e4c0c8..4be7ba54c 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet
@@ -1,5 +1,5 @@
<%@ 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.* java.util.Iterator"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.emf.ecore.* java.util.Iterator org.eclipse.emf.ecore.util.EcoreUtil org.eclipse.emf.codegen.util.CodeGenUtil;"%>
<%
Object[] args = (Object[]) argument;
PolylineConnection figure = (PolylineConnection) args[0];
@@ -17,6 +17,8 @@ final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
*/
public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
+<%@ include file="../customBorderFactoryMethods.jetinc"%>
+
/**
* @generated
*/

Back to the top