View | Details | Raw Unified | Return to bug 154683
Collapse All | Expand All

(-)templates/top/PolylineConnection.javajet (-1 / +3 lines)
Lines 1-5 Link Here
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopConnectionGenerator"
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopConnectionGenerator"
2
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* java.util.Iterator"%>
2
	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;"%>
3
<%
3
<%
4
Object[] args = (Object[]) argument;
4
Object[] args = (Object[]) argument;
5
PolylineConnection figure = (PolylineConnection) args[0];
5
PolylineConnection figure = (PolylineConnection) args[0];
Lines 17-22 Link Here
17
 */
17
 */
18
public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
18
public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
19
19
20
<%@ include file="../customBorderFactoryMethods.jetinc"%>
21
20
	/**
22
	/**
21
	 * @generated
23
	 * @generated
22
	 */
24
	 */
(-)templates/top/Figure.javajet (-2 / +6 lines)
Lines 1-11 Link Here
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopFigureGenerator" 
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopFigureGenerator" 
2
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* java.util.Iterator;"%>
2
	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; "%>
3
<%
3
<%
4
Object[] args = (Object[]) argument;
4
Object[] args = (Object[]) argument;
5
Figure figure = (Figure) args[0];
5
Figure figure = (Figure) args[0];
6
final ImportAssistant importManager = (ImportAssistant) args[1];
6
final ImportAssistant importManager = (ImportAssistant) args[1];
7
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
7
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
8
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
8
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
9
10
//[MG] FIXME: Why we need this? Is it in use somewhere?
9
final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
11
final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
10
%>
12
%>
11
<%importManager.emitPackageStatement(stringBuffer);%>
13
<%importManager.emitPackageStatement(stringBuffer);%>
Lines 17-29 Link Here
17
 */
19
 */
18
public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
20
public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
19
21
22
<%@ include file="../customBorderFactoryMethods.jetinc"%>
23
20
	/**
24
	/**
21
	 * @generated
25
	 * @generated
22
	 */
26
	 */
23
	public <%=figure.getName()%>() {
27
	public <%=figure.getName()%>() {
24
<%
28
<%
25
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
29
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
26
%>	
30
%>
27
		<%=dispatcher.dispatch("createLayout", dispatcherArgs)%>
31
		<%=dispatcher.dispatch("createLayout", dispatcherArgs)%>
28
		<%=dispatcher.dispatch(figure, dispatcherArgs)%>
32
		<%=dispatcher.dispatch(figure, dispatcherArgs)%>
29
		createContents();
33
		createContents();
(-)templates/attr/CustomClass.javajet (-3 / +6 lines)
Lines 4-12 Link Here
4
final CustomClass instance = (CustomClass) ((Object[]) argument)[0];
4
final CustomClass instance = (CustomClass) ((Object[]) argument)[0];
5
//final GraphDefDispatcher dispatcher = (GraphDefDispatcher) ((Object[]) argument)[1];
5
//final GraphDefDispatcher dispatcher = (GraphDefDispatcher) ((Object[]) argument)[1];
6
final String varName = (String) ((Object[]) argument)[2];
6
final String varName = (String) ((Object[]) argument)[2];
7
final boolean hasAttributes = !instance.getAttributes().isEmpty();
7
boolean insertingArbitraryCode = false;
8
for (Iterator attributes = instance.getAttributes().iterator(); !insertingArbitraryCode && attributes.hasNext();){
9
	insertingArbitraryCode = ((CustomAttribute)attributes.next()).isMultiStatementValue();
10
}
8
%>
11
%>
9
<%	if (hasAttributes) {%>
12
<%	if (insertingArbitraryCode) {%>
10
		{
13
		{
11
<%	}%>
14
<%	}%>
12
<%
15
<%
Lines 34-40 Link Here
34
<%
37
<%
35
} //for 
38
} //for 
36
%>
39
%>
37
<%	if (hasAttributes) {%>
40
<%	if (insertingArbitraryCode) {%>
38
		}
41
		}
39
<%	}%>
42
<%	}%>
40
43
(-)src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java (-53 / +106 lines)
Lines 4-10 Link Here
4
import org.eclipse.gmf.gmfgraph.util.*;
4
import org.eclipse.gmf.gmfgraph.util.*;
5
import org.eclipse.gmf.common.codegen.*;
5
import org.eclipse.gmf.common.codegen.*;
6
import org.eclipse.gmf.graphdef.codegen.*;
6
import org.eclipse.gmf.graphdef.codegen.*;
7
import org.eclipse.emf.ecore.*;
7
import java.util.Iterator;
8
import java.util.Iterator;
9
import org.eclipse.emf.ecore.util.EcoreUtil;
10
import org.eclipse.emf.codegen.util.CodeGenUtil;;
8
11
9
public class TopConnectionGenerator
12
public class TopConnectionGenerator
10
{
13
{
Lines 21-54 Link Here
21
  protected final String TEXT_1 = "";
24
  protected final String TEXT_1 = "";
22
  protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
25
  protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
23
  protected final String TEXT_3 = " extends ";
26
  protected final String TEXT_3 = " extends ";
24
  protected final String TEXT_4 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
27
  protected final String TEXT_4 = " {" + NL;
25
  protected final String TEXT_5 = "() {";
28
  protected final String TEXT_5 = NL;
26
  protected final String TEXT_6 = NL;
29
  protected final String TEXT_6 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
27
  protected final String TEXT_7 = NL + "\t\tsetSourceDecoration(createSourceDecoration());";
30
  protected final String TEXT_7 = " ";
28
  protected final String TEXT_8 = NL + "\t\tsetTargetDecoration(createTargetDecoration());";
31
  protected final String TEXT_8 = "() {" + NL + "\t\t";
29
  protected final String TEXT_9 = NL + "\t}" + NL;
32
  protected final String TEXT_9 = " result = new ";
30
  protected final String TEXT_10 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
33
  protected final String TEXT_10 = "();" + NL + "\t\t";
31
  protected final String TEXT_11 = " createSourceDecoration() {";
34
  protected final String TEXT_11 = NL + "\t\treturn result;" + NL + "\t}";
32
  protected final String TEXT_12 = NL;
35
  protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
33
  protected final String TEXT_13 = NL + "\t\treturn df;" + NL + "\t}";
36
  protected final String TEXT_13 = "() {";
34
  protected final String TEXT_14 = NL;
37
  protected final String TEXT_14 = NL;
35
  protected final String TEXT_15 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
38
  protected final String TEXT_15 = NL + "\t\tsetSourceDecoration(createSourceDecoration());";
36
  protected final String TEXT_16 = " createTargetDecoration() {";
39
  protected final String TEXT_16 = NL + "\t\tsetTargetDecoration(createTargetDecoration());";
37
  protected final String TEXT_17 = NL;
40
  protected final String TEXT_17 = NL + "\t}" + NL;
38
  protected final String TEXT_18 = NL + "\t\treturn df;" + NL + "\t}";
41
  protected final String TEXT_18 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
39
  protected final String TEXT_19 = NL;
42
  protected final String TEXT_19 = " createSourceDecoration() {";
40
  protected final String TEXT_20 = NL + "}" + NL + "\t";
43
  protected final String TEXT_20 = NL;
41
  protected final String TEXT_21 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
44
  protected final String TEXT_21 = NL + "\t\treturn df;" + NL + "\t}";
42
  protected final String TEXT_22 = " ";
45
  protected final String TEXT_22 = NL;
43
  protected final String TEXT_23 = " = ";
46
  protected final String TEXT_23 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
44
  protected final String TEXT_24 = ";";
47
  protected final String TEXT_24 = " createTargetDecoration() {";
45
  protected final String TEXT_25 = NL + "\t";
48
  protected final String TEXT_25 = NL;
46
  protected final String TEXT_26 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
49
  protected final String TEXT_26 = NL + "\t\treturn df;" + NL + "\t}";
47
  protected final String TEXT_27 = " ";
50
  protected final String TEXT_27 = NL;
48
  protected final String TEXT_28 = " = ";
51
  protected final String TEXT_28 = NL + "}" + NL + "\t";
49
  protected final String TEXT_29 = ";";
52
  protected final String TEXT_29 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
50
  protected final String TEXT_30 = NL + "}";
53
  protected final String TEXT_30 = " ";
51
  protected final String TEXT_31 = NL;
54
  protected final String TEXT_31 = " = ";
55
  protected final String TEXT_32 = ";";
56
  protected final String TEXT_33 = NL + "\t";
57
  protected final String TEXT_34 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
58
  protected final String TEXT_35 = " ";
59
  protected final String TEXT_36 = " = ";
60
  protected final String TEXT_37 = ";";
61
  protected final String TEXT_38 = NL + "}";
62
  protected final String TEXT_39 = NL;
52
63
53
  public String generate(Object argument)
64
  public String generate(Object argument)
54
  {
65
  {
Lines 69-144 Link Here
69
    stringBuffer.append(TEXT_3);
80
    stringBuffer.append(TEXT_3);
70
    stringBuffer.append(fqnSwitch.get(figure, importManager));
81
    stringBuffer.append(fqnSwitch.get(figure, importManager));
71
    stringBuffer.append(TEXT_4);
82
    stringBuffer.append(TEXT_4);
72
    stringBuffer.append(figure.getName());
73
    stringBuffer.append(TEXT_5);
83
    stringBuffer.append(TEXT_5);
84
    
85
//input: [oeg].common.codegen.ImportAssistant importManager 
86
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
87
//input: [oeg].gmfgraph.Figure figure
88
 
89
{ //namespace -- use "bfm" (stands for BorderFactoryMethod) to avoid name clashes
90
	int bfmNextIndex = 1;
91
	String bfmLastFigureName = "";
92
	for (Iterator bfmAllCustomBorders = EcoreUtil.getAllContents(figure, false); bfmAllCustomBorders.hasNext();){
93
		EObject bfmNext = (EObject)bfmAllCustomBorders.next();
94
		if (GMFGraphPackage.eINSTANCE.getFigure().isSuperTypeOf(bfmNext.eClass())){
95
			bfmLastFigureName = (String)bfmNext.eGet(GMFGraphPackage.eINSTANCE.getIdentity_Name());
96
			if (bfmLastFigureName == null){
97
				bfmLastFigureName = "";
98
			}
99
		}
100
		if (bfmNext.eClass().getClassifierID() != GMFGraphPackage.CUSTOM_BORDER){
101
			continue;
102
		}
103
		
104
		String bfmNextImplClass = dispatcher.getFQNSwitch().get(bfmNext, importManager);	
105
		String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
106
		
107
74
    stringBuffer.append(TEXT_6);
108
    stringBuffer.append(TEXT_6);
109
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.Border"));
110
    stringBuffer.append(TEXT_7);
111
    stringBuffer.append(bfmNextMethodName);
112
    stringBuffer.append(TEXT_8);
113
    stringBuffer.append(bfmNextImplClass);
114
    stringBuffer.append(TEXT_9);
115
    stringBuffer.append(bfmNextImplClass);
116
    stringBuffer.append(TEXT_10);
117
    stringBuffer.append(dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} ));
118
    stringBuffer.append(TEXT_11);
119
    		
120
		dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
121
	}
122
} //end of namespace
123
124
    stringBuffer.append(TEXT_12);
125
    stringBuffer.append(figure.getName());
126
    stringBuffer.append(TEXT_13);
127
    stringBuffer.append(TEXT_14);
75
    stringBuffer.append(dispatcher.dispatch("Shape", dispatcher.create(figure, "this")));
128
    stringBuffer.append(dispatcher.dispatch("Shape", dispatcher.create(figure, "this")));
76
    if (figure.getSourceDecoration() != null) {
129
    if (figure.getSourceDecoration() != null) {
77
    stringBuffer.append(TEXT_7);
130
    stringBuffer.append(TEXT_15);
78
    }
131
    }
79
if (figure.getTargetDecoration() != null) {
132
if (figure.getTargetDecoration() != null) {
80
    stringBuffer.append(TEXT_8);
133
    stringBuffer.append(TEXT_16);
81
    }
134
    }
82
    stringBuffer.append(TEXT_9);
135
    stringBuffer.append(TEXT_17);
83
    if (figure.getSourceDecoration() != null) {
136
    if (figure.getSourceDecoration() != null) {
84
	final String className = fqnSwitch.get(figure.getSourceDecoration(), importManager);
137
	final String className = fqnSwitch.get(figure.getSourceDecoration(), importManager);
85
    stringBuffer.append(TEXT_10);
138
    stringBuffer.append(TEXT_18);
86
    stringBuffer.append(className);
139
    stringBuffer.append(className);
87
    stringBuffer.append(TEXT_11);
140
    stringBuffer.append(TEXT_19);
88
    stringBuffer.append(TEXT_12);
141
    stringBuffer.append(TEXT_20);
89
    stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getSourceDecoration(), "df")));
142
    stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getSourceDecoration(), "df")));
90
    stringBuffer.append(TEXT_13);
143
    stringBuffer.append(TEXT_21);
91
    } /*if sourceDecoration != null */ 
144
    } /*if sourceDecoration != null */ 
92
    stringBuffer.append(TEXT_14);
145
    stringBuffer.append(TEXT_22);
93
    if (figure.getTargetDecoration() != null) {
146
    if (figure.getTargetDecoration() != null) {
94
	final String className = fqnSwitch.get(figure.getTargetDecoration(), importManager);
147
	final String className = fqnSwitch.get(figure.getTargetDecoration(), importManager);
95
    stringBuffer.append(TEXT_15);
148
    stringBuffer.append(TEXT_23);
96
    stringBuffer.append(className);
149
    stringBuffer.append(className);
97
    stringBuffer.append(TEXT_16);
150
    stringBuffer.append(TEXT_24);
98
    stringBuffer.append(TEXT_17);
151
    stringBuffer.append(TEXT_25);
99
    stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getTargetDecoration(), "df")));
152
    stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getTargetDecoration(), "df")));
100
    stringBuffer.append(TEXT_18);
153
    stringBuffer.append(TEXT_26);
101
    }
154
    }
102
    stringBuffer.append(TEXT_19);
155
    stringBuffer.append(TEXT_27);
103
    
156
    
104
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
157
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
105
//input: boolean isInnerClass
158
//input: boolean isInnerClass
106
if (isInnerClass){ /*put fields out of inner class body*/ 
159
if (isInnerClass){ /*put fields out of inner class body*/ 
107
    stringBuffer.append(TEXT_20);
160
    stringBuffer.append(TEXT_28);
108
    
161
    
109
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
162
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
110
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
163
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
111
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
164
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
112
    stringBuffer.append(TEXT_21);
165
    stringBuffer.append(TEXT_29);
113
    stringBuffer.append(next.getType());
166
    stringBuffer.append(next.getType());
114
    stringBuffer.append(TEXT_22);
167
    stringBuffer.append(TEXT_30);
115
    stringBuffer.append(next.getName());
168
    stringBuffer.append(next.getName());
116
    stringBuffer.append(TEXT_23);
169
    stringBuffer.append(TEXT_31);
117
    stringBuffer.append(next.getValue());
170
    stringBuffer.append(next.getValue());
118
    stringBuffer.append(TEXT_24);
171
    stringBuffer.append(TEXT_32);
119
    
172
    
120
}
173
}
121
174
122
     } else { 
175
     } else { 
123
    stringBuffer.append(TEXT_25);
176
    stringBuffer.append(TEXT_33);
124
    
177
    
125
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
178
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
126
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
179
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
127
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
180
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
128
    stringBuffer.append(TEXT_26);
181
    stringBuffer.append(TEXT_34);
129
    stringBuffer.append(next.getType());
182
    stringBuffer.append(next.getType());
130
    stringBuffer.append(TEXT_27);
183
    stringBuffer.append(TEXT_35);
131
    stringBuffer.append(next.getName());
184
    stringBuffer.append(next.getName());
132
    stringBuffer.append(TEXT_28);
185
    stringBuffer.append(TEXT_36);
133
    stringBuffer.append(next.getValue());
186
    stringBuffer.append(next.getValue());
134
    stringBuffer.append(TEXT_29);
187
    stringBuffer.append(TEXT_37);
135
    
188
    
136
}
189
}
137
190
138
    stringBuffer.append(TEXT_30);
191
    stringBuffer.append(TEXT_38);
139
    }
192
    }
140
    importManager.emitSortedImports();
193
    importManager.emitSortedImports();
141
    stringBuffer.append(TEXT_31);
194
    stringBuffer.append(TEXT_39);
142
    return stringBuffer.toString();
195
    return stringBuffer.toString();
143
  }
196
  }
144
}
197
}
(-)src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java (-45 / +100 lines)
Lines 4-10 Link Here
4
import org.eclipse.gmf.gmfgraph.util.*;
4
import org.eclipse.gmf.gmfgraph.util.*;
5
import org.eclipse.gmf.common.codegen.*;
5
import org.eclipse.gmf.common.codegen.*;
6
import org.eclipse.gmf.graphdef.codegen.*;
6
import org.eclipse.gmf.graphdef.codegen.*;
7
import java.util.Iterator;;
7
import org.eclipse.emf.ecore.*;
8
import java.util.Iterator;
9
import org.eclipse.emf.ecore.util.EcoreUtil;
10
import org.eclipse.emf.codegen.util.CodeGenUtil;;
8
11
9
public class TopFigureGenerator
12
public class TopFigureGenerator
10
{
13
{
Lines 21-49 Link Here
21
  protected final String TEXT_1 = "";
24
  protected final String TEXT_1 = "";
22
  protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
25
  protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
23
  protected final String TEXT_3 = " extends ";
26
  protected final String TEXT_3 = " extends ";
24
  protected final String TEXT_4 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
27
  protected final String TEXT_4 = " {" + NL;
25
  protected final String TEXT_5 = "() {";
28
  protected final String TEXT_5 = NL;
26
  protected final String TEXT_6 = "\t" + NL + "\t\t";
29
  protected final String TEXT_6 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
27
  protected final String TEXT_7 = NL + "\t\t";
30
  protected final String TEXT_7 = " ";
28
  protected final String TEXT_8 = NL + "\t\tcreateContents();" + NL + "\t}" + NL;
31
  protected final String TEXT_8 = "() {" + NL + "\t\t";
29
  protected final String TEXT_9 = NL;
32
  protected final String TEXT_9 = " result = new ";
30
  protected final String TEXT_10 = NL;
33
  protected final String TEXT_10 = "();" + NL + "\t\t";
31
  protected final String TEXT_11 = NL;
34
  protected final String TEXT_11 = NL + "\t\treturn result;" + NL + "\t}";
32
  protected final String TEXT_12 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = ";
35
  protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
33
  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";
36
  protected final String TEXT_13 = "() {";
34
  protected final String TEXT_14 = NL;
37
  protected final String TEXT_14 = NL + "\t\t";
35
  protected final String TEXT_15 = NL + "}" + NL + "\t";
38
  protected final String TEXT_15 = NL + "\t\t";
36
  protected final String TEXT_16 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
39
  protected final String TEXT_16 = NL + "\t\tcreateContents();" + NL + "\t}" + NL;
37
  protected final String TEXT_17 = " ";
40
  protected final String TEXT_17 = NL;
38
  protected final String TEXT_18 = " = ";
41
  protected final String TEXT_18 = NL;
39
  protected final String TEXT_19 = ";";
42
  protected final String TEXT_19 = NL;
40
  protected final String TEXT_20 = NL + "\t";
43
  protected final String TEXT_20 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = ";
41
  protected final String TEXT_21 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
44
  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";
42
  protected final String TEXT_22 = " ";
45
  protected final String TEXT_22 = NL;
43
  protected final String TEXT_23 = " = ";
46
  protected final String TEXT_23 = NL + "}" + NL + "\t";
44
  protected final String TEXT_24 = ";";
47
  protected final String TEXT_24 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
45
  protected final String TEXT_25 = NL + "}";
48
  protected final String TEXT_25 = " ";
46
  protected final String TEXT_26 = NL;
49
  protected final String TEXT_26 = " = ";
50
  protected final String TEXT_27 = ";";
51
  protected final String TEXT_28 = NL + "\t";
52
  protected final String TEXT_29 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
53
  protected final String TEXT_30 = " ";
54
  protected final String TEXT_31 = " = ";
55
  protected final String TEXT_32 = ";";
56
  protected final String TEXT_33 = NL + "}";
57
  protected final String TEXT_34 = NL;
47
58
48
  public String generate(Object argument)
59
  public String generate(Object argument)
49
  {
60
  {
Lines 54-59 Link Here
54
final ImportAssistant importManager = (ImportAssistant) args[1];
65
final ImportAssistant importManager = (ImportAssistant) args[1];
55
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
66
final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
56
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
67
final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
68
69
//[MG] FIXME: Why we need this? Is it in use somewhere?
57
final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
70
final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
58
71
59
    importManager.emitPackageStatement(stringBuffer);
72
    importManager.emitPackageStatement(stringBuffer);
Lines 64-84 Link Here
64
    stringBuffer.append(TEXT_3);
77
    stringBuffer.append(TEXT_3);
65
    stringBuffer.append(fqnSwitch.get(figure, importManager));
78
    stringBuffer.append(fqnSwitch.get(figure, importManager));
66
    stringBuffer.append(TEXT_4);
79
    stringBuffer.append(TEXT_4);
67
    stringBuffer.append(figure.getName());
68
    stringBuffer.append(TEXT_5);
80
    stringBuffer.append(TEXT_5);
69
    
81
    
70
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
82
//input: [oeg].common.codegen.ImportAssistant importManager 
83
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
84
//input: [oeg].gmfgraph.Figure figure
85
 
86
{ //namespace -- use "bfm" (stands for BorderFactoryMethod) to avoid name clashes
87
	int bfmNextIndex = 1;
88
	String bfmLastFigureName = "";
89
	for (Iterator bfmAllCustomBorders = EcoreUtil.getAllContents(figure, false); bfmAllCustomBorders.hasNext();){
90
		EObject bfmNext = (EObject)bfmAllCustomBorders.next();
91
		if (GMFGraphPackage.eINSTANCE.getFigure().isSuperTypeOf(bfmNext.eClass())){
92
			bfmLastFigureName = (String)bfmNext.eGet(GMFGraphPackage.eINSTANCE.getIdentity_Name());
93
			if (bfmLastFigureName == null){
94
				bfmLastFigureName = "";
95
			}
96
		}
97
		if (bfmNext.eClass().getClassifierID() != GMFGraphPackage.CUSTOM_BORDER){
98
			continue;
99
		}
100
		
101
		String bfmNextImplClass = dispatcher.getFQNSwitch().get(bfmNext, importManager);	
102
		String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
103
		
71
104
72
    stringBuffer.append(TEXT_6);
105
    stringBuffer.append(TEXT_6);
73
    stringBuffer.append(dispatcher.dispatch("createLayout", dispatcherArgs));
106
    stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.Border"));
74
    stringBuffer.append(TEXT_7);
107
    stringBuffer.append(TEXT_7);
75
    stringBuffer.append(dispatcher.dispatch(figure, dispatcherArgs));
108
    stringBuffer.append(bfmNextMethodName);
76
    stringBuffer.append(TEXT_8);
109
    stringBuffer.append(TEXT_8);
110
    stringBuffer.append(bfmNextImplClass);
77
    stringBuffer.append(TEXT_9);
111
    stringBuffer.append(TEXT_9);
78
    stringBuffer.append(dispatcher.dispatch("Children", dispatcherArgs));
112
    stringBuffer.append(bfmNextImplClass);
79
    stringBuffer.append(TEXT_10);
113
    stringBuffer.append(TEXT_10);
80
    if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/
114
    stringBuffer.append(dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} ));
81
    stringBuffer.append(TEXT_11);
115
    stringBuffer.append(TEXT_11);
116
    		
117
		dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
118
	}
119
} //end of namespace
120
121
    stringBuffer.append(TEXT_12);
122
    stringBuffer.append(figure.getName());
123
    stringBuffer.append(TEXT_13);
124
    
125
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
126
127
    stringBuffer.append(TEXT_14);
128
    stringBuffer.append(dispatcher.dispatch("createLayout", dispatcherArgs));
129
    stringBuffer.append(TEXT_15);
130
    stringBuffer.append(dispatcher.dispatch(figure, dispatcherArgs));
131
    stringBuffer.append(TEXT_16);
132
    stringBuffer.append(TEXT_17);
133
    stringBuffer.append(dispatcher.dispatch("Children", dispatcherArgs));
134
    stringBuffer.append(TEXT_18);
135
    if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/
136
    stringBuffer.append(TEXT_19);
82
    
137
    
83
// simple heuristic to detect need for local coordinates
138
// simple heuristic to detect need for local coordinates
84
boolean useLocalDefaultValue = false;
139
boolean useLocalDefaultValue = false;
Lines 89-138 Link Here
89
	}
144
	}
90
}
145
}
91
146
92
    stringBuffer.append(TEXT_12);
147
    stringBuffer.append(TEXT_20);
93
    stringBuffer.append(useLocalDefaultValue);
148
    stringBuffer.append(useLocalDefaultValue);
94
    stringBuffer.append(TEXT_13);
149
    stringBuffer.append(TEXT_21);
95
    }
150
    }
96
    stringBuffer.append(TEXT_14);
151
    stringBuffer.append(TEXT_22);
97
    
152
    
98
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
153
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
99
//input: boolean isInnerClass
154
//input: boolean isInnerClass
100
if (isInnerClass){ /*put fields out of inner class body*/ 
155
if (isInnerClass){ /*put fields out of inner class body*/ 
101
    stringBuffer.append(TEXT_15);
156
    stringBuffer.append(TEXT_23);
102
    
157
    
103
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
158
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
104
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
159
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
105
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
160
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
106
    stringBuffer.append(TEXT_16);
161
    stringBuffer.append(TEXT_24);
107
    stringBuffer.append(next.getType());
162
    stringBuffer.append(next.getType());
108
    stringBuffer.append(TEXT_17);
163
    stringBuffer.append(TEXT_25);
109
    stringBuffer.append(next.getName());
164
    stringBuffer.append(next.getName());
110
    stringBuffer.append(TEXT_18);
165
    stringBuffer.append(TEXT_26);
111
    stringBuffer.append(next.getValue());
166
    stringBuffer.append(next.getValue());
112
    stringBuffer.append(TEXT_19);
167
    stringBuffer.append(TEXT_27);
113
    
168
    
114
}
169
}
115
170
116
     } else { 
171
     } else { 
117
    stringBuffer.append(TEXT_20);
172
    stringBuffer.append(TEXT_28);
118
    
173
    
119
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
174
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
120
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
175
for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
121
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
176
	StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next(); 
122
    stringBuffer.append(TEXT_21);
177
    stringBuffer.append(TEXT_29);
123
    stringBuffer.append(next.getType());
178
    stringBuffer.append(next.getType());
124
    stringBuffer.append(TEXT_22);
179
    stringBuffer.append(TEXT_30);
125
    stringBuffer.append(next.getName());
180
    stringBuffer.append(next.getName());
126
    stringBuffer.append(TEXT_23);
181
    stringBuffer.append(TEXT_31);
127
    stringBuffer.append(next.getValue());
182
    stringBuffer.append(next.getValue());
128
    stringBuffer.append(TEXT_24);
183
    stringBuffer.append(TEXT_32);
129
    
184
    
130
}
185
}
131
186
132
    stringBuffer.append(TEXT_25);
187
    stringBuffer.append(TEXT_33);
133
    }
188
    }
134
    importManager.emitSortedImports();
189
    importManager.emitSortedImports();
135
    stringBuffer.append(TEXT_26);
190
    stringBuffer.append(TEXT_34);
136
    return stringBuffer.toString();
191
    return stringBuffer.toString();
137
  }
192
  }
138
}
193
}
(-)src/org/eclipse/gmf/graphdef/codegen/templates/CustomClassAttributesGenerator.java (-3 / +6 lines)
Lines 39-47 Link Here
39
final CustomClass instance = (CustomClass) ((Object[]) argument)[0];
39
final CustomClass instance = (CustomClass) ((Object[]) argument)[0];
40
//final GraphDefDispatcher dispatcher = (GraphDefDispatcher) ((Object[]) argument)[1];
40
//final GraphDefDispatcher dispatcher = (GraphDefDispatcher) ((Object[]) argument)[1];
41
final String varName = (String) ((Object[]) argument)[2];
41
final String varName = (String) ((Object[]) argument)[2];
42
final boolean hasAttributes = !instance.getAttributes().isEmpty();
42
boolean insertingArbitraryCode = false;
43
for (Iterator attributes = instance.getAttributes().iterator(); !insertingArbitraryCode && attributes.hasNext();){
44
	insertingArbitraryCode = ((CustomAttribute)attributes.next()).isMultiStatementValue();
45
}
43
46
44
    	if (hasAttributes) {
47
    	if (insertingArbitraryCode) {
45
    stringBuffer.append(TEXT_1);
48
    stringBuffer.append(TEXT_1);
46
    	}
49
    	}
47
    
50
    
Lines 84-90 Link Here
84
    
87
    
85
} //for 
88
} //for 
86
89
87
    	if (hasAttributes) {
90
    	if (insertingArbitraryCode) {
88
    stringBuffer.append(TEXT_13);
91
    stringBuffer.append(TEXT_13);
89
    	}
92
    	}
90
    stringBuffer.append(TEXT_14);
93
    stringBuffer.append(TEXT_14);
(-)src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java (-2 / +5 lines)
Lines 20-25 Link Here
20
import org.eclipse.gmf.gmfgraph.BorderLayout;
20
import org.eclipse.gmf.gmfgraph.BorderLayout;
21
import org.eclipse.gmf.gmfgraph.BorderLayoutData;
21
import org.eclipse.gmf.gmfgraph.BorderLayoutData;
22
import org.eclipse.gmf.gmfgraph.CompoundBorder;
22
import org.eclipse.gmf.gmfgraph.CompoundBorder;
23
import org.eclipse.gmf.gmfgraph.CustomBorder;
23
import org.eclipse.gmf.gmfgraph.CustomFigure;
24
import org.eclipse.gmf.gmfgraph.CustomFigure;
24
import org.eclipse.gmf.gmfgraph.CustomLayout;
25
import org.eclipse.gmf.gmfgraph.CustomLayout;
25
import org.eclipse.gmf.gmfgraph.CustomLayoutData;
26
import org.eclipse.gmf.gmfgraph.CustomLayoutData;
Lines 52-57 Link Here
52
import org.eclipse.gmf.graphdef.codegen.templates.InitXYLayoutDataGenerator;
53
import org.eclipse.gmf.graphdef.codegen.templates.InitXYLayoutDataGenerator;
53
import org.eclipse.gmf.graphdef.codegen.templates.LabelAttrGenerator;
54
import org.eclipse.gmf.graphdef.codegen.templates.LabelAttrGenerator;
54
import org.eclipse.gmf.graphdef.codegen.templates.NewCompoundBorderExpressionGenerator;
55
import org.eclipse.gmf.graphdef.codegen.templates.NewCompoundBorderExpressionGenerator;
56
import org.eclipse.gmf.graphdef.codegen.templates.NewCustomBorderExpressionGenerator;
55
import org.eclipse.gmf.graphdef.codegen.templates.NewFigureGenerator;
57
import org.eclipse.gmf.graphdef.codegen.templates.NewFigureGenerator;
56
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutDataGenerator;
58
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutDataGenerator;
57
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutGenerator;
59
import org.eclipse.gmf.graphdef.codegen.templates.NewLayoutGenerator;
Lines 78-85 Link Here
78
 *
80
 *
79
 */
81
 */
80
public class FigureGenerator implements TextEmitter {
82
public class FigureGenerator implements TextEmitter {
81
	private GraphDefDispatcher myTopDispatcher;
83
	private final GraphDefDispatcher myTopDispatcher;
82
	private GraphDefDispatcher myInnerDispatcher;
84
	private final GraphDefDispatcher myInnerDispatcher;
83
	private final boolean myIsInnerClassCode;
85
	private final boolean myIsInnerClassCode;
84
86
85
	public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, boolean asInnerClass) {
87
	public FigureGenerator(FigureQualifiedNameSwitch figureNameSwitch, boolean asInnerClass) {
Lines 166-171 Link Here
166
		tr.put(LineBorder.class, "/new/LineBorder.javajet", NewLineBorderExpressionGenerator.class);
168
		tr.put(LineBorder.class, "/new/LineBorder.javajet", NewLineBorderExpressionGenerator.class);
167
		tr.put(MarginBorder.class, "/new/MarginBorder.javajet", NewMarginBorderExpressionGenerator.class);
169
		tr.put(MarginBorder.class, "/new/MarginBorder.javajet", NewMarginBorderExpressionGenerator.class);
168
		tr.put(CompoundBorder.class, "/new/CompoundBorder.javajet", NewCompoundBorderExpressionGenerator.class);
170
		tr.put(CompoundBorder.class, "/new/CompoundBorder.javajet", NewCompoundBorderExpressionGenerator.class);
171
		tr.put(CustomBorder.class, "/new/CustomBorder.javajet", NewCustomBorderExpressionGenerator.class);
169
172
170
		return tr;
173
		return tr;
171
	}
174
	}
(-)src/org/eclipse/gmf/graphdef/codegen/GraphDefDispatcher.java (+54 lines)
Lines 11-16 Link Here
11
 */
11
 */
12
package org.eclipse.gmf.graphdef.codegen;
12
package org.eclipse.gmf.graphdef.codegen;
13
13
14
import java.util.HashMap;
15
16
import org.eclipse.emf.ecore.EObject;
14
import org.eclipse.gmf.common.codegen.ImportAssistant;
17
import org.eclipse.gmf.common.codegen.ImportAssistant;
15
import org.eclipse.gmf.gmfgraph.Figure;
18
import org.eclipse.gmf.gmfgraph.Figure;
16
import org.eclipse.gmf.gmfgraph.Layout;
19
import org.eclipse.gmf.gmfgraph.Layout;
Lines 28-33 Link Here
28
	private final FigureQualifiedNameSwitch myFqnSwitch;
31
	private final FigureQualifiedNameSwitch myFqnSwitch;
29
	private final MapModeCodeGenStrategy myMapModeStrategy;
32
	private final MapModeCodeGenStrategy myMapModeStrategy;
30
	private final StaticFieldsManager myStaticFieldsManager;
33
	private final StaticFieldsManager myStaticFieldsManager;
34
	private final AuxiliaryDataStorage myAuxiliaryDataStorage;
31
	
35
	
32
	public GraphDefDispatcher(EmitterFactory factory, KeyMap keyMap, FigureQualifiedNameSwitch fqnSwitch, MapModeCodeGenStrategy mapModeStrategy) {
36
	public GraphDefDispatcher(EmitterFactory factory, KeyMap keyMap, FigureQualifiedNameSwitch fqnSwitch, MapModeCodeGenStrategy mapModeStrategy) {
33
		super(factory, keyMap);
37
		super(factory, keyMap);
Lines 35-40 Link Here
35
		myFqnSwitch = fqnSwitch;
39
		myFqnSwitch = fqnSwitch;
36
		myMapModeStrategy = mapModeStrategy;
40
		myMapModeStrategy = mapModeStrategy;
37
		myStaticFieldsManager = new StaticFieldsManager();
41
		myStaticFieldsManager = new StaticFieldsManager();
42
		myAuxiliaryDataStorage = new AuxiliaryDataStorage();
38
	}
43
	}
39
	
44
	
40
	public StaticFieldsManager getStaticFieldsManager(){
45
	public StaticFieldsManager getStaticFieldsManager(){
Lines 53-64 Link Here
53
		return myImportManager;
58
		return myImportManager;
54
	}
59
	}
55
	
60
	
61
	public AuxiliaryDataStorage getAuxiliaryDataStorage(){
62
		return myAuxiliaryDataStorage;
63
	}
64
	
56
	/**
65
	/**
57
	 * Not good. Would be better to have importManager as part of Args, perhaps. 
66
	 * Not good. Would be better to have importManager as part of Args, perhaps. 
58
	 */
67
	 */
59
	/*package-local*/ void resetForNewClass(ImportAssistant assistant) {
68
	/*package-local*/ void resetForNewClass(ImportAssistant assistant) {
60
		setImportManager(assistant);
69
		setImportManager(assistant);
61
		myStaticFieldsManager.reset();
70
		myStaticFieldsManager.reset();
71
		myAuxiliaryDataStorage.reset();
62
	}
72
	}
63
73
64
	public FigureQualifiedNameSwitch getFQNSwitch() {
74
	public FigureQualifiedNameSwitch getFQNSwitch() {
Lines 84-89 Link Here
84
	private void setImportManager(ImportAssistant manager) {
94
	private void setImportManager(ImportAssistant manager) {
85
		myImportManager = manager; 
95
		myImportManager = manager; 
86
	}
96
	}
97
	
98
	/**
99
	 * "Write-once" map that allows to associate arbitrary data with some
100
	 * gmfgraph instance.
101
	 * 
102
	 * It allows to generate some auxiliary code (say, getter method) for given
103
	 * gmfgraph instance in one template, store the getter name in the Storage
104
	 * and retrieve it in different template to insert call for this getter into
105
	 * different place.
106
	 * 
107
	 * To avoid unexpected data loss, any key may be set only once and remains
108
	 * available during generation of some compilation unit. It is the reason
109
	 * for data to be declared as Object instead of String. If you need to
110
	 * associate 2 different strings with given object use ad hoc class to store
111
	 * data.
112
	 * 
113
	 * NOTE: This data storage is automatically reset when owning dispatcher is
114
	 * reset for new compilation unit generation.
115
	 */
116
	public static class AuxiliaryDataStorage {
117
		private final HashMap myData;
118
		
119
		public AuxiliaryDataStorage(){
120
			myData = new HashMap();
121
		}
122
		
123
		public void registerData(EObject owner, Object data){
124
			if (myData.containsKey(owner)){
125
				throw new IllegalArgumentException("EObject: " + owner + " has registered data: " + myData.get(owner));
126
			}
127
			if (data == null){
128
				throw new NullPointerException("Null data for EObject: " + owner);
129
			}
130
			myData.put(owner, data);
131
		}
132
		
133
		public Object getRegisteredData(EObject owner){
134
			return myData.get(owner);
135
		}
136
		
137
		private void reset(){
138
			myData.clear();
139
		}
140
	}
87
141
88
	public static class Args {
142
	public static class Args {
89
		private final Figure myFigure;
143
		private final Figure myFigure;
(-)src/org/eclipse/gmf/graphdef/codegen/templates/NewCustomBorderExpressionGenerator.java (+36 lines)
Added Link Here
1
package org.eclipse.gmf.graphdef.codegen.templates;
2
3
import org.eclipse.gmf.gmfgraph.*;
4
import org.eclipse.gmf.graphdef.codegen.*;
5
6
public class NewCustomBorderExpressionGenerator
7
{
8
  protected static String nl;
9
  public static synchronized NewCustomBorderExpressionGenerator create(String lineSeparator)
10
  {
11
    nl = lineSeparator;
12
    NewCustomBorderExpressionGenerator result = new NewCustomBorderExpressionGenerator();
13
    nl = null;
14
    return result;
15
  }
16
17
  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
18
  protected final String TEXT_1 = "()";
19
20
  public String generate(Object argument)
21
  {
22
    final StringBuffer stringBuffer = new StringBuffer();
23
    
24
Object[] args = (Object[]) argument;
25
final CustomBorder border = (CustomBorder)args[0];
26
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
27
//final ImportAssistant importManager = dispatcher.getImportManager();
28
29
//We want NEITHER insert any names into the scope NOR produce statement. We need expression instead.
30
//@see customBorderFactoryMethod.jetinc
31
32
    stringBuffer.append(dispatcher.getAuxiliaryDataStorage().getRegisteredData(border));
33
    stringBuffer.append(TEXT_1);
34
    return stringBuffer.toString();
35
  }
36
}
(-)templates/customBorderFactoryMethods.jetinc (+37 lines)
Added Link Here
1
<%
2
//input: [oeg].common.codegen.ImportAssistant importManager 
3
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
4
//input: [oeg].gmfgraph.Figure figure
5
 
6
{ //namespace -- use "bfm" (stands for BorderFactoryMethod) to avoid name clashes
7
	int bfmNextIndex = 1;
8
	String bfmLastFigureName = "";
9
	for (Iterator bfmAllCustomBorders = EcoreUtil.getAllContents(figure, false); bfmAllCustomBorders.hasNext();){
10
		EObject bfmNext = (EObject)bfmAllCustomBorders.next();
11
		if (GMFGraphPackage.eINSTANCE.getFigure().isSuperTypeOf(bfmNext.eClass())){
12
			bfmLastFigureName = (String)bfmNext.eGet(GMFGraphPackage.eINSTANCE.getIdentity_Name());
13
			if (bfmLastFigureName == null){
14
				bfmLastFigureName = "";
15
			}
16
		}
17
		if (bfmNext.eClass().getClassifierID() != GMFGraphPackage.CUSTOM_BORDER){
18
			continue;
19
		}
20
		
21
		String bfmNextImplClass = dispatcher.getFQNSwitch().get(bfmNext, importManager);	
22
		String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
23
		
24
%>		
25
	/**
26
	 * @generated
27
	 */
28
	private <%=importManager.getImportedName("org.eclipse.draw2d.Border")%> <%=bfmNextMethodName%>() {
29
		<%=bfmNextImplClass%> result = new <%=bfmNextImplClass%>();
30
		<%=dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} )%>
31
		return result;
32
	}
33
<%		
34
		dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
35
	}
36
} //end of namespace
37
%>
(-)templates/new/CustomBorder.javajet (+11 lines)
Added Link Here
1
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewCustomBorderExpressionGenerator"
2
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
3
<%
4
Object[] args = (Object[]) argument;
5
final CustomBorder border = (CustomBorder)args[0];
6
final GraphDefDispatcher dispatcher = (GraphDefDispatcher)args[1];
7
//final ImportAssistant importManager = dispatcher.getImportManager();
8
9
//We want NEITHER insert any names into the scope NOR produce statement. We need expression instead.
10
//@see customBorderFactoryMethod.jetinc
11
%><%=dispatcher.getAuxiliaryDataStorage().getRegisteredData(border)%>()
(-)src/org/eclipse/gmf/tests/setup/figures/GenericFigureCheck.java (+57 lines)
Lines 13-29 Link Here
13
package org.eclipse.gmf.tests.setup.figures;
13
package org.eclipse.gmf.tests.setup.figures;
14
14
15
import java.lang.reflect.Field;
15
import java.lang.reflect.Field;
16
import java.lang.reflect.InvocationTargetException;
17
import java.lang.reflect.Method;
16
import java.util.Iterator;
18
import java.util.Iterator;
17
import java.util.List;
19
import java.util.List;
18
20
19
import org.eclipse.draw2d.Graphics;
21
import org.eclipse.draw2d.Graphics;
20
import org.eclipse.draw2d.IFigure;
22
import org.eclipse.draw2d.IFigure;
21
import org.eclipse.draw2d.geometry.PointList;
23
import org.eclipse.draw2d.geometry.PointList;
24
import org.eclipse.emf.codegen.util.CodeGenUtil;
22
import org.eclipse.gmf.gmfgraph.BasicFont;
25
import org.eclipse.gmf.gmfgraph.BasicFont;
23
import org.eclipse.gmf.gmfgraph.Border;
26
import org.eclipse.gmf.gmfgraph.Border;
24
import org.eclipse.gmf.gmfgraph.Color;
27
import org.eclipse.gmf.gmfgraph.Color;
25
import org.eclipse.gmf.gmfgraph.CompoundBorder;
28
import org.eclipse.gmf.gmfgraph.CompoundBorder;
26
import org.eclipse.gmf.gmfgraph.ConstantColor;
29
import org.eclipse.gmf.gmfgraph.ConstantColor;
30
import org.eclipse.gmf.gmfgraph.CustomAttribute;
31
import org.eclipse.gmf.gmfgraph.CustomBorder;
27
import org.eclipse.gmf.gmfgraph.Dimension;
32
import org.eclipse.gmf.gmfgraph.Dimension;
28
import org.eclipse.gmf.gmfgraph.Figure;
33
import org.eclipse.gmf.gmfgraph.Figure;
29
import org.eclipse.gmf.gmfgraph.Font;
34
import org.eclipse.gmf.gmfgraph.Font;
Lines 288-296 Link Here
288
			checkCompoundBorder((CompoundBorder) eBorder, d2dBorder, mainD2DFigure);
293
			checkCompoundBorder((CompoundBorder) eBorder, d2dBorder, mainD2DFigure);
289
		} else if (eBorder instanceof MarginBorder) {
294
		} else if (eBorder instanceof MarginBorder) {
290
			checkMarginBorder((MarginBorder) eBorder, d2dBorder, mainD2DFigure);
295
			checkMarginBorder((MarginBorder) eBorder, d2dBorder, mainD2DFigure);
296
		} else if (eBorder instanceof CustomBorder) {
297
			checkCustomBorder((CustomBorder) eBorder, d2dBorder, mainD2DFigure);
291
		}
298
		}
292
	}
299
	}
293
300
301
	protected final void checkCustomBorder(CustomBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure) {
302
		assertEquals(eBorder.getQualifiedClassName(), d2dBorder.getClass().getName());
303
		for (Iterator attributes = eBorder.getAttributes().iterator(); attributes.hasNext();){
304
			CustomAttribute next = (CustomAttribute)attributes.next();
305
			checkCustomAttribute(next, d2dBorder);
306
		}
307
	}
308
	
309
	protected final void checkCustomAttribute(CustomAttribute eAttribute, Object instance){
310
		assertNotNull(eAttribute.getValue());
311
		assertNotNull(eAttribute.getName());
312
		String expectedValue = eAttribute.getValue().trim();
313
		String getterName = "get" + CodeGenUtil.capName(eAttribute.getName());
314
		Object result;
315
		try {
316
			Method getter = instance.getClass().getMethod(getterName, new Class[0]);
317
			if (!getter.getReturnType().equals(String.class) && !getter.getReturnType().isPrimitive()){
318
				//we do not want to write a lot of code to check static 
319
				//constructs like "org.eclipse.draw2d.ColorConstants.blue"
320
				return;
321
			}
322
			if (getter.getReturnType().equals(String.class)){
323
				if (expectedValue.startsWith("\"")){
324
					expectedValue = expectedValue.substring(1);
325
				}
326
				if (expectedValue.endsWith("\"")){
327
					expectedValue = expectedValue.substring(0, expectedValue.length() - 1);
328
				}
329
			}
330
			getter.setAccessible(true);
331
			result = getter.invoke(instance, new Object[0]);
332
		} catch (NoSuchMethodException e) {
333
			//we are not sure that instance provides getter, 
334
			//just skip the check if getter is not found
335
			return;
336
		} catch (SecurityException e) {
337
			//strange 
338
			throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
339
		} catch (IllegalArgumentException e) {
340
			throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
341
		} catch (IllegalAccessException e) {
342
			throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
343
		} catch (InvocationTargetException e) {
344
			throw new RuntimeException("getter: " + getterName + ", instance: " + instance, e);
345
		}
346
		
347
		//it is pure check, but it should be enough for integers/strings
348
		assertEquals(expectedValue, String.valueOf(result));
349
	}
350
294
	protected final void checkMarginBorder(MarginBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure) {
351
	protected final void checkMarginBorder(MarginBorder eBorder, org.eclipse.draw2d.Border d2dBorder, IFigure mainD2DFigure) {
295
		assertTrue(d2dBorder instanceof org.eclipse.draw2d.MarginBorder);
352
		assertTrue(d2dBorder instanceof org.eclipse.draw2d.MarginBorder);
296
		org.eclipse.draw2d.MarginBorder actual = (org.eclipse.draw2d.MarginBorder) d2dBorder;
353
		org.eclipse.draw2d.MarginBorder actual = (org.eclipse.draw2d.MarginBorder) d2dBorder;
(-)src/org/eclipse/gmf/tests/setup/figures/ShapePropertiesSetup.java (+51 lines)
Lines 16-21 Link Here
16
import org.eclipse.gmf.gmfgraph.BasicFont;
16
import org.eclipse.gmf.gmfgraph.BasicFont;
17
import org.eclipse.gmf.gmfgraph.ColorConstants;
17
import org.eclipse.gmf.gmfgraph.ColorConstants;
18
import org.eclipse.gmf.gmfgraph.CompoundBorder;
18
import org.eclipse.gmf.gmfgraph.CompoundBorder;
19
import org.eclipse.gmf.gmfgraph.CustomAttribute;
20
import org.eclipse.gmf.gmfgraph.CustomBorder;
19
import org.eclipse.gmf.gmfgraph.Figure;
21
import org.eclipse.gmf.gmfgraph.Figure;
20
import org.eclipse.gmf.gmfgraph.FigureGallery;
22
import org.eclipse.gmf.gmfgraph.FigureGallery;
21
import org.eclipse.gmf.gmfgraph.FontStyle;
23
import org.eclipse.gmf.gmfgraph.FontStyle;
Lines 40-45 Link Here
40
	private Figure myRainbow;
42
	private Figure myRainbow;
41
	private Figure myWithMinAndMaxSize;
43
	private Figure myWithMinAndMaxSize;
42
	private Figure myRoot;
44
	private Figure myRoot;
45
	private Figure myCustomBorderTester;
43
46
44
	protected void addFigures(FigureGallery gallery) {
47
	protected void addFigures(FigureGallery gallery) {
45
		gallery.getFigures().add(getContainer());
48
		gallery.getFigures().add(getContainer());
Lines 52-57 Link Here
52
		gallery.getFigures().add(getRainbow());
55
		gallery.getFigures().add(getRainbow());
53
		gallery.getFigures().add(getWithMinAndMaxSize());
56
		gallery.getFigures().add(getWithMinAndMaxSize());
54
		gallery.getFigures().add(getRoot());
57
		gallery.getFigures().add(getRoot());
58
		gallery.getFigures().add(getCustomBorderTester());
55
	}
59
	}
56
60
57
	public Figure getRoot() {
61
	public Figure getRoot() {
Lines 116-121 Link Here
116
		}
120
		}
117
		return myMarginTester;
121
		return myMarginTester;
118
	}
122
	}
123
	
124
	public Figure getCustomBorderTester(){
125
		if (myCustomBorderTester == null){
126
			myCustomBorderTester = GMFGraphFactory.eINSTANCE.createRectangle();
127
			myCustomBorderTester.setName("CustomBorderTester");
128
			
129
			CustomBorder singleCustomBorder = GMFGraphFactory.eINSTANCE.createCustomBorder();
130
			singleCustomBorder.setQualifiedClassName(org.eclipse.draw2d.LineBorder.class.getName());
131
			CustomAttribute borderColor = GMFGraphFactory.eINSTANCE.createCustomAttribute();
132
			borderColor.setName("color");
133
			borderColor.setValue("org.eclipse.draw2d.ColorConstants.blue");
134
			CustomAttribute borderWidth = GMFGraphFactory.eINSTANCE.createCustomAttribute();
135
			borderWidth.setName("width");
136
			borderWidth.setValue("2");
137
			singleCustomBorder.getAttributes().add(borderColor);
138
			singleCustomBorder.getAttributes().add(borderWidth);
139
			myCustomBorderTester.setBorder(singleCustomBorder);
140
			
141
			Figure innerRectangle = GMFGraphFactory.eINSTANCE.createRectangle();
142
			innerRectangle.setName("TesterOfCompoundBorderWithCustomComponent");
143
			myCustomBorderTester.getChildren().add(innerRectangle);
144
			
145
			CompoundBorder compoundBorderWithCustomComponent = GMFGraphFactory.eINSTANCE.createCompoundBorder();
146
			MarginBorder justSomeGMFBorder = GMFGraphFactory.eINSTANCE.createMarginBorder();
147
			justSomeGMFBorder.setInsets(GMFGraphFactory.eINSTANCE.createInsets());
148
			justSomeGMFBorder.getInsets().setBottom(5);
149
			justSomeGMFBorder.getInsets().setTop(5);
150
			justSomeGMFBorder.getInsets().setLeft(5);
151
			justSomeGMFBorder.getInsets().setRight(5);
152
			compoundBorderWithCustomComponent.setInner(justSomeGMFBorder);
153
			
154
			CustomBorder customBorderAsComponent = GMFGraphFactory.eINSTANCE.createCustomBorder();
155
			customBorderAsComponent.setQualifiedClassName(org.eclipse.draw2d.TitleBarBorder.class.getName());
156
			CustomAttribute labelAttribute = GMFGraphFactory.eINSTANCE.createCustomAttribute();
157
			labelAttribute.setName("label");
158
			labelAttribute.setValue("\"Label Text\"");
159
			
160
			CustomAttribute paddingAttribute = GMFGraphFactory.eINSTANCE.createCustomAttribute();
161
			paddingAttribute.setName("padding");
162
			paddingAttribute.setValue("5");
163
			customBorderAsComponent.getAttributes().add(labelAttribute);
164
			customBorderAsComponent.getAttributes().add(paddingAttribute);
165
			compoundBorderWithCustomComponent.setOuter(customBorderAsComponent);
166
			innerRectangle.setBorder(compoundBorderWithCustomComponent);
167
		}
168
		return myCustomBorderTester;
169
	}
119
170
120
	public Figure getTester() {
171
	public Figure getTester() {
121
		if (myTester == null) {
172
		if (myTester == null) {
(-)src/org/eclipse/gmf/tests/gen/ShapePropertiesTest.java (-1 / +8 lines)
Lines 23-29 Link Here
23
	}
23
	}
24
	
24
	
25
	private ShapePropertiesSetup getSessionSetup() {
25
	private ShapePropertiesSetup getSessionSetup() {
26
		Assert.assertTrue("Incorrect session setup was used, use FigureCodegenSetup instead of: " + mySessionSetup, mySessionSetup instanceof ShapePropertiesSetup);
26
		if (mySessionSetup == null){
27
			configure(new ShapePropertiesSetup());
28
		}
29
		Assert.assertTrue("Incorrect session setup was used, use ShapePropertiesSetup instead of: " + mySessionSetup, mySessionSetup instanceof ShapePropertiesSetup);
27
		return (ShapePropertiesSetup) mySessionSetup;
30
		return (ShapePropertiesSetup) mySessionSetup;
28
	}
31
	}
29
	
32
	
Lines 55-60 Link Here
55
		performTests(getSessionSetup().getMarginTester());
58
		performTests(getSessionSetup().getMarginTester());
56
	}
59
	}
57
	
60
	
61
	public void testCustomBorder(){
62
		performTests(getSessionSetup().getCustomBorderTester());
63
	}
64
	
58
	public void testConstantColors(){
65
	public void testConstantColors(){
59
		performTests(getSessionSetup().getRainbow());
66
		performTests(getSessionSetup().getRainbow());
60
	}
67
	}
(-)src/org/eclipse/gmf/tests/gen/FigureCodegenTestBase.java (-1 lines)
Lines 23-29 Link Here
23
23
24
/**
24
/**
25
 * @author artem
25
 * @author artem
26
 * @author michael.golubev
27
 */
26
 */
28
public class FigureCodegenTestBase extends TestCase implements NeedsSetup {
27
public class FigureCodegenTestBase extends TestCase implements NeedsSetup {
29
28

Return to bug 154683