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
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.
-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
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java1
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java9
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java57
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/ShapePropertiesSetup.java51
15 files changed, 491 insertions, 111 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
*/
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java
index 78267f7bf..2b6216cd6 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java
@@ -23,7 +23,6 @@ import org.eclipse.gmf.tests.setup.figures.GenericFigureCheck;
/**
* @author artem
- * @author michael.golubev
*/
public class FigureCodegenTestBase extends TestCase implements NeedsSetup {
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java
index 438587e9e..73173a133 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java
@@ -23,7 +23,10 @@ public class ShapePropertiesTest extends FigureCodegenTestBase {
}
private ShapePropertiesSetup getSessionSetup() {
- Assert.assertTrue("Incorrect session setup was used, use FigureCodegenSetup instead of: " + mySessionSetup, mySessionSetup instanceof ShapePropertiesSetup);
+ if (mySessionSetup == null){
+ configure(new ShapePropertiesSetup());
+ }
+ Assert.assertTrue("Incorrect session setup was used, use ShapePropertiesSetup instead of: " + mySessionSetup, mySessionSetup instanceof ShapePropertiesSetup);
return (ShapePropertiesSetup) mySessionSetup;
}
@@ -55,6 +58,10 @@ public class ShapePropertiesTest extends FigureCodegenTestBase {
performTests(getSessionSetup().getMarginTester());
}
+ public void testCustomBorder(){
+ performTests(getSessionSetup().getCustomBorderTester());
+ }
+
public void testConstantColors(){
performTests(getSessionSetup().getRainbow());
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java
index 8ec1fa995..3ebae3801 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java
@@ -13,17 +13,22 @@
package org.eclipse.gmf.tests.setup.figures;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.gmf.gmfgraph.BasicFont;
import org.eclipse.gmf.gmfgraph.Border;
import org.eclipse.gmf.gmfgraph.Color;
import org.eclipse.gmf.gmfgraph.CompoundBorder;
import org.eclipse.gmf.gmfgraph.ConstantColor;
+import org.eclipse.gmf.gmfgraph.CustomAttribute;
+import org.eclipse.gmf.gmfgraph.CustomBorder;
import org.eclipse.gmf.gmfgraph.Dimension;
import org.eclipse.gmf.gmfgraph.Figure;
import org.eclipse.gmf.gmfgraph.Font;
@@ -288,9 +293,61 @@ public class GenericFigureCheck extends FigureCheck {
checkCompoundBorder((CompoundBorder) eBorder, d2dBorder, mainD2DFigure);
} else if (eBorder instanceof MarginBorder) {
checkMarginBorder((MarginBorder) eBorder, d2dBorder, mainD2DFigure);
+ } else if (eBorder instanceof CustomBorder) {
+ checkCustomBorder((CustomBorder) eBorder, d2dBorder, mainD2DFigure);
}
}
+ protected final void checkCustomBorder(CustomBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure) {
+ assertEquals(eBorder.getQualifiedClassName(), d2dBorder.getClass().getName());
+ for (Iterator attributes = eBorder.getAttributes().iterator(); attributes.hasNext();){
+ CustomAttribute next = (CustomAttribute)attributes.next();
+ checkCustomAttribute(next, d2dBorder);
+ }
+ }
+
+ protected final void checkCustomAttribute(CustomAttribute eAttribute, Object instance){
+ assertNotNull(eAttribute.getValue());
+ assertNotNull(eAttribute.getName());
+ String expectedValue = eAttribute.getValue().trim();
+ String getterName = "get" + CodeGenUtil.capName(eAttribute.getName());
+ Object result;
+ try {
+ Method getter = instance.getClass().getMethod(getterName, new Class[0]);
+ if (!getter.getReturnType().equals(String.class) && !getter.getReturnType().isPrimitive()){
+ //we do not want to write a lot of code to check static
+ //constructs like "org.eclipse.draw2d.ColorConstants.blue"
+ return;
+ }
+ if (getter.getReturnType().equals(String.class)){
+ if (expectedValue.startsWith("\"")){
+ expectedValue = expectedValue.substring(1);
+ }
+ if (expectedValue.endsWith("\"")){
+ expectedValue = expectedValue.substring(0, expectedValue.length() - 1);
+ }
+ }
+ getter.setAccessible(true);
+ result = getter.invoke(instance, new Object[0]);
+ } catch (NoSuchMethodException e) {
+ //we are not sure that instance provides getter,
+ //just skip the check if getter is not found
+ return;
+ } catch (SecurityException e) {
+ //strange
+ throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
+ }
+
+ //it is pure check, but it should be enough for integers/strings
+ assertEquals(expectedValue, String.valueOf(result));
+ }
+
protected final void checkMarginBorder(MarginBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure) {
assertTrue(d2dBorder instanceof org.eclipse.draw2d.MarginBorder);
org.eclipse.draw2d.MarginBorder actual = (org.eclipse.draw2d.MarginBorder) d2dBorder;
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/ShapePropertiesSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/ShapePropertiesSetup.java
index fd21cb10e..469504100 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/ShapePropertiesSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/figures/ShapePropertiesSetup.java
@@ -16,6 +16,8 @@ import java.util.Iterator;
import org.eclipse.gmf.gmfgraph.BasicFont;
import org.eclipse.gmf.gmfgraph.ColorConstants;
import org.eclipse.gmf.gmfgraph.CompoundBorder;
+import org.eclipse.gmf.gmfgraph.CustomAttribute;
+import org.eclipse.gmf.gmfgraph.CustomBorder;
import org.eclipse.gmf.gmfgraph.Figure;
import org.eclipse.gmf.gmfgraph.FigureGallery;
import org.eclipse.gmf.gmfgraph.FontStyle;
@@ -40,6 +42,7 @@ public class ShapePropertiesSetup extends AbstractFigureGeneratorSetup {
private Figure myRainbow;
private Figure myWithMinAndMaxSize;
private Figure myRoot;
+ private Figure myCustomBorderTester;
protected void addFigures(FigureGallery gallery) {
gallery.getFigures().add(getContainer());
@@ -52,6 +55,7 @@ public class ShapePropertiesSetup extends AbstractFigureGeneratorSetup {
gallery.getFigures().add(getRainbow());
gallery.getFigures().add(getWithMinAndMaxSize());
gallery.getFigures().add(getRoot());
+ gallery.getFigures().add(getCustomBorderTester());
}
public Figure getRoot() {
@@ -116,6 +120,53 @@ public class ShapePropertiesSetup extends AbstractFigureGeneratorSetup {
}
return myMarginTester;
}
+
+ public Figure getCustomBorderTester(){
+ if (myCustomBorderTester == null){
+ myCustomBorderTester = GMFGraphFactory.eINSTANCE.createRectangle();
+ myCustomBorderTester.setName("CustomBorderTester");
+
+ CustomBorder singleCustomBorder = GMFGraphFactory.eINSTANCE.createCustomBorder();
+ singleCustomBorder.setQualifiedClassName(org.eclipse.draw2d.LineBorder.class.getName());
+ CustomAttribute borderColor = GMFGraphFactory.eINSTANCE.createCustomAttribute();
+ borderColor.setName("color");
+ borderColor.setValue("org.eclipse.draw2d.ColorConstants.blue");
+ CustomAttribute borderWidth = GMFGraphFactory.eINSTANCE.createCustomAttribute();
+ borderWidth.setName("width");
+ borderWidth.setValue("2");
+ singleCustomBorder.getAttributes().add(borderColor);
+ singleCustomBorder.getAttributes().add(borderWidth);
+ myCustomBorderTester.setBorder(singleCustomBorder);
+
+ Figure innerRectangle = GMFGraphFactory.eINSTANCE.createRectangle();
+ innerRectangle.setName("TesterOfCompoundBorderWithCustomComponent");
+ myCustomBorderTester.getChildren().add(innerRectangle);
+
+ CompoundBorder compoundBorderWithCustomComponent = GMFGraphFactory.eINSTANCE.createCompoundBorder();
+ MarginBorder justSomeGMFBorder = GMFGraphFactory.eINSTANCE.createMarginBorder();
+ justSomeGMFBorder.setInsets(GMFGraphFactory.eINSTANCE.createInsets());
+ justSomeGMFBorder.getInsets().setBottom(5);
+ justSomeGMFBorder.getInsets().setTop(5);
+ justSomeGMFBorder.getInsets().setLeft(5);
+ justSomeGMFBorder.getInsets().setRight(5);
+ compoundBorderWithCustomComponent.setInner(justSomeGMFBorder);
+
+ CustomBorder customBorderAsComponent = GMFGraphFactory.eINSTANCE.createCustomBorder();
+ customBorderAsComponent.setQualifiedClassName(org.eclipse.draw2d.TitleBarBorder.class.getName());
+ CustomAttribute labelAttribute = GMFGraphFactory.eINSTANCE.createCustomAttribute();
+ labelAttribute.setName("label");
+ labelAttribute.setValue("\"Label Text\"");
+
+ CustomAttribute paddingAttribute = GMFGraphFactory.eINSTANCE.createCustomAttribute();
+ paddingAttribute.setName("padding");
+ paddingAttribute.setValue("5");
+ customBorderAsComponent.getAttributes().add(labelAttribute);
+ customBorderAsComponent.getAttributes().add(paddingAttribute);
+ compoundBorderWithCustomComponent.setOuter(customBorderAsComponent);
+ innerRectangle.setBorder(compoundBorderWithCustomComponent);
+ }
+ return myCustomBorderTester;
+ }
public Figure getTester() {
if (myTester == null) {

Back to the top