Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3a1192f49557acbec474326d370fe12ca1483910 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="FigureChildrenGenerator"
	imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.emf.codegen.util.CodeGenUtil java.util.*"%>
<%
GraphDefDispatcher.LayoutArgs parentArgs = (GraphDefDispatcher.LayoutArgs) argument;
final Figure root = parentArgs.getFigure();
final GraphDefDispatcher dispatcher = parentArgs.getDispatcher();
final ImportAssistant importManager = dispatcher.getImportManager();

final List/*<Figure>*/ fieldsRequired = new LinkedList/*<Figure>*/();
final Stack/*GraphDefDispatcher.LayoutArgs*/ contextStack = new Stack/*GraphDefDispatcher.LayoutArgs*/();
final LinkedList queue = new LinkedList();
final Object marker = new Object();

class FieldSupport {
	private final Figure myRoot;

	public FieldSupport(Figure root){
		myRoot = root;
	}
	
	public boolean isFieldRequired(Figure descendant){
		return myRoot.equals(descendant.getParent()) || !descendant.getReferencingElements().isEmpty();
	}
}
final FieldSupport fieldSupport = new FieldSupport(root);

%>

	/**
	 * @generated
	 */
	private void createContents(){
<%
queue.addAll(root.getChildren());
int figureCount = 0;
while (!queue.isEmpty()){
	Object _nxt = queue.removeFirst();
	if (_nxt == marker){
		parentArgs = (GraphDefDispatcher.LayoutArgs)contextStack.pop();
		continue;
	}
	if (_nxt instanceof FigureRef) {
		throw new IllegalStateException("FIXME: sorry, don't support FigureRef for a while");
	}
	final Figure nextChild = (Figure) _nxt;	
	final String childVarName = "fig_" + figureCount;
	final String childLayoutManager = "layouter" + figureCount;
	final String childConstraint = "layData" + figureCount;
	figureCount++;
	
	// FIXME instantiate - FigureRef - dispatch to 'instantiate' template?
	GraphDefDispatcher.LayoutArgs nextLevelArgs = dispatcher.createLayoutArgs(nextChild, childVarName, childLayoutManager, childConstraint);%>
		<%=dispatcher.dispatch("instantiate", nextLevelArgs)%>
<%
if (fieldSupport.isFieldRequired(nextChild)){
	fieldsRequired.add(nextChild); %>
		setFigure<%=nextChild.getName()%>(<%=childVarName%>);
<%}%>
		<%=dispatcher.dispatch("createLayoutData", nextLevelArgs)%>
		<%=parentArgs.getVariableName()%>.add(<%=childVarName%>, <%=childConstraint%>);
<%
	if (!nextChild.getChildren().isEmpty()) {
		queue.addFirst(marker);
		queue.addAll(0, nextChild.getChildren());
		contextStack.push(parentArgs);
		parentArgs = nextLevelArgs; // go on processing children of new parentFigure
	} 
} // while
%>
	}
	
<%
	final FigureQualifiedNameSwitch fqnSwitch = dispatcher.getFQNSwitch();
	for (Iterator fieldFigures = fieldsRequired.iterator(); fieldFigures.hasNext();){
		Figure next = (Figure)fieldFigures.next(); 
		final String nextClassName = fqnSwitch.get(next, importManager);%>
		
	/**
	 * @generated
	 */
	private <%=nextClassName%> f<%=CodeGenUtil.capName(next.getName())%>; 

	/**
	 * @generated
	 */
	public <%=nextClassName%> getFigure<%=next.getName()%>() {
		return f<%=CodeGenUtil.capName(next.getName())%>;
	}
	
	/**
	 * @generated
	 */
	private void setFigure<%=next.getName()%>(<%=nextClassName%> fig){
		f<%=CodeGenUtil.capName(next.getName())%> = fig;
	}

<%	}%>

Back to the top