Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-02-13 17:36:07 +0000
committeratikhomirov2006-02-13 17:36:07 +0000
commitf8757a97d7e3a5e73cbc0be2d438e3921bc2a2e8 (patch)
treec3712afb5d03429a0b1f9a44a2694d1fb180ef5b /plugins/org.eclipse.gmf.graphdef.codegen/templates
parent80e4035d3bf83b8a35983bc23587f49485a14d3e (diff)
downloadorg.eclipse.gmf-tooling-f8757a97d7e3a5e73cbc0be2d438e3921bc2a2e8.tar.gz
org.eclipse.gmf-tooling-f8757a97d7e3a5e73cbc0be2d438e3921bc2a2e8.tar.xz
org.eclipse.gmf-tooling-f8757a97d7e3a5e73cbc0be2d438e3921bc2a2e8.zip
[mgolubev] #127252 layout support
Diffstat (limited to 'plugins/org.eclipse.gmf.graphdef.codegen/templates')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet36
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/children/Figure.javajet10
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/BorderLayout.javajet17
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/CustomLayout.javajet8
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/GridLayout.javajet25
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/BorderLayoutData.javajet40
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/CustomLayoutData.javajet10
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/GridLayoutData.javajet31
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Figure.javajet5
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Layout.javajet21
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LayoutData.javajet16
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Shape.javajet18
12 files changed, 227 insertions, 10 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet
new file mode 100644
index 000000000..5d7424e22
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/attr/CustomClass.javajet
@@ -0,0 +1,36 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="CustomClassAttributesGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.emf.codegen.util.CodeGenUtil java.util.* "%>
+<%
+final CustomClass instance = (CustomClass) ((Object[]) argument)[0];
+//final GraphDefDispatcher dispatcher = (GraphDefDispatcher) ((Object[]) argument)[1];
+final String varName = (String) ((Object[]) argument)[2];
+%>
+
+ {
+<%
+int attrIndex = 0;
+for (Iterator attrs = instance.getAttributes().iterator(); attrs.hasNext(); attrIndex++){
+ CustomAttribute next = (CustomAttribute) attrs.next();
+ String varValue;
+ if (next.isMultiStatementValue()){
+ varValue = "attr" + attrIndex;
+%>
+ <%=java.text.MessageFormat.format(next.getValue(), new Object[] {varValue})%>;
+<% } else {
+ varValue = next.getValue();
+}
+ if (next.isDirectAccess()) {
+%>
+ <%=varName%>.<%=next.getName()%> = <%=varValue%>;
+<%
+ } else {
+%>
+ <%=varName%>.set<%=CodeGenUtil.capName(next.getName())%>(<%=varValue%>);
+<%
+ }
+%>
+<%
+} //for
+%>
+ }
+
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/children/Figure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/children/Figure.javajet
index f2a51c57a..eb76ac6cc 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/children/Figure.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/children/Figure.javajet
@@ -1,5 +1,5 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="FigureChildrenGenerator"
- imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher java.util.*"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.* java.util.*"%>
<%
Object[] args = (Object[]) argument;
List/*<Figure>*/ figureChildren = (List) args[0];
@@ -23,10 +23,14 @@ while (!l.isEmpty()) {
if (figureMarker instanceof FigureRef) {
throw new IllegalStateException("FIXME: sorry, don't support FigureRef for a while");
}
- final String figureVarName = "fig" + (figureCount++);%>
+ final String figureVarName = "fig" + figureCount;
+ final String layoutDataVarName = "layData" + figureCount;
+ figureCount++;%>
// FIXME instantiate - FigureRef - dispatch to 'instantiate' template?
- <%=dispatcher.dispatch("instantiate", dispatcher.create((Figure) figureMarker, figureVarName))%>
+ <%GraphDefDispatcher.Args dargs = dispatcher.create((Figure) figureMarker, figureVarName);%>
+ <%=dispatcher.dispatch("instantiate", dargs)%>
<%=parentFigureVarName%>.add(<%=figureVarName%>);
+ <%=dispatcher.dispatch("createLayoutData", dispatcher.createLayoutArgs(dargs, layoutDataVarName))%>
<%
if (_nxt instanceof Figure && !((Figure) _nxt).getChildren().isEmpty()) {
l.addFirst(marker);
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/BorderLayout.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/BorderLayout.javajet
new file mode 100644
index 000000000..f86fb4889
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/BorderLayout.javajet
@@ -0,0 +1,17 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="InitBorderLayoutGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
+final BorderLayout gmfLayout = (BorderLayout) argsBundle.getLayout();
+final String layouterVarName = argsBundle.getLayoutVariableName();
+%>
+
+<%
+Dimension spacing = gmfLayout.getSpacing();
+if (spacing != null){
+%>
+ <%=layouterVarName%>.setHorizontalSpacing(<%=spacing.getDx()%>);
+ <%=layouterVarName%>.setVerticalSpacing(<%=spacing.getDy()%>);
+<%
+}
+%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/CustomLayout.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/CustomLayout.javajet
new file mode 100644
index 000000000..0345832a6
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/CustomLayout.javajet
@@ -0,0 +1,8 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="InitCustomLayoutGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
+final CustomLayout layout = (CustomLayout) argsBundle.getLayout();
+final GraphDefDispatcher dispatcher = argsBundle.getDispatcher();
+%>
+<%=dispatcher.dispatch("customAttributes", new Object[] {layout, dispatcher, argsBundle.getLayoutVariableName()} )%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/GridLayout.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/GridLayout.javajet
new file mode 100644
index 000000000..4f162a721
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layout/GridLayout.javajet
@@ -0,0 +1,25 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="InitGridLayoutGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
+final GridLayout gmfLayout = (GridLayout) argsBundle.getLayout();
+final String layouterVarName = argsBundle.getLayoutVariableName();
+%>
+ <%=layouterVarName%>.numColumns = <%=gmfLayout.getNumColumns()%>;
+ <%=layouterVarName%>.makeColumnsEqualWidth = <%=gmfLayout.isEqualWidth()%>;
+<%
+Dimension margins = gmfLayout.getMargins();
+if (margins != null){
+%>
+ <%=layouterVarName%>.marginWidth = <%=margins.getDx()%>;
+ <%=layouterVarName%>.marginHeight = <%=margins.getDy()%>;
+<%
+}
+Dimension spacing = gmfLayout.getSpacing();
+if (spacing != null){
+%>
+ <%=layouterVarName%>.horizontalSpacing = <%=spacing.getDx()%>;
+ <%=layouterVarName%>.verticalSpacing = <%=spacing.getDy()%>;
+<%
+}
+%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/BorderLayoutData.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/BorderLayoutData.javajet
new file mode 100644
index 000000000..18525aaf2
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/BorderLayoutData.javajet
@@ -0,0 +1,40 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="InitBorderLayoutDataGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
+final BorderLayoutData gmfLayoutData = (BorderLayoutData) argsBundle.getData();
+final String figureVarName = argsBundle.getVariableName();
+final GraphDefDispatcher dispatcher = argsBundle.getDispatcher();
+%>
+
+<%
+Alignment alignment = gmfLayoutData.getAlignment();
+if (alignment == null){
+ alignment = Alignment.CENTER_LITERAL;
+}
+final String constantName;
+switch(alignment.getValue()){
+ case Alignment.CENTER:
+ case Alignment.FILL:
+ constantName = "CENTER";
+ break;
+ case Alignment.BEGINNING:
+ if (gmfLayoutData.isVertical()){
+ constantName = "TOP";
+ } else {
+ constantName = "LEFT";
+ }
+ break;
+ case Alignment.END:
+ if (gmfLayoutData.isVertical()){
+ constantName = "BOTTOM";
+ } else {
+ constantName = "RIGHT";
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown Alignment: " + gmfLayoutData.getAlignment());
+}
+%>
+ <%=figureVarName%>.getParent().getLayoutManager().setConstraint(<%=figureVarName%>, <%=dispatcher.getImportManager().getImportedName("org.eclipse.draw2d.BorderLayout")%>.<%=constantName%>);
+
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/CustomLayoutData.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/CustomLayoutData.javajet
new file mode 100644
index 000000000..4dec5729f
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/CustomLayoutData.javajet
@@ -0,0 +1,10 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="InitCustomLayoutDataGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+GraphDefDispatcher.LayoutArgs args = (GraphDefDispatcher.LayoutArgs) argument;
+final CustomLayoutData layoutData = (CustomLayoutData) args.getData();
+final GraphDefDispatcher dispatcher = args.getDispatcher();
+final String layoutImplClassName = dispatcher.getImportManager().getImportedName((String) dispatcher.getFQNSwitch().doSwitch(layoutData));
+%>
+<%=layoutImplClassName%> <%=args.getLayoutVariableName()%> = new <%=layoutImplClassName%>();
+<%=dispatcher.dispatch("customAttributes", new Object[] {layoutData, dispatcher, args.getLayoutVariableName()})%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/GridLayoutData.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/GridLayoutData.javajet
new file mode 100644
index 000000000..362940518
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/layoutData/GridLayoutData.javajet
@@ -0,0 +1,31 @@
+
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="InitGridLayoutDataGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
+final GridLayoutData gmfLayoutData = (GridLayoutData) argsBundle.getData();
+final String figureVarName = argsBundle.getVariableName();
+final GraphDefDispatcher dispatcher = argsBundle.getDispatcher();
+final String layoutConstraintVarName = argsBundle.getLayoutVariableName();
+
+final String layoutImplClassName = dispatcher.getImportManager().getImportedName((String) dispatcher.getFQNSwitch().doSwitch(gmfLayoutData));
+%>
+ <%=layoutImplClassName%> <%=layoutConstraintVarName%> = new <%=layoutImplClassName%>();
+ <%=layoutConstraintVarName%>.verticalAlignment = <%=gmfLayoutData.getVerticalAlignment().getValue()%>;
+ <%=layoutConstraintVarName%>.horizontalAlignment = <%=gmfLayoutData.getHorizontalAlignment().getValue()%>;
+<%
+Dimension sizeHint = gmfLayoutData.getSizeHint();
+if (sizeHint != null){
+%>
+ <%=layoutConstraintVarName%>.widthHint = <%=sizeHint.getDx()%>;
+ <%=layoutConstraintVarName%>.heightHint = <%=sizeHint.getDy()%>;
+<%
+}
+%>
+ <%=layoutConstraintVarName%>.horizontalIndent = <%=gmfLayoutData.getHorizontalIndent()%>;
+ <%=layoutConstraintVarName%>.horizontalSpan = <%=gmfLayoutData.getHorizontalSpan()%>;
+ <%=layoutConstraintVarName%>.verticalSpan = <%=gmfLayoutData.getVerticalSpan()%>;
+ <%=layoutConstraintVarName%>.grabExcessHorizontalSpace = <%=gmfLayoutData.isGrabExcessHorizontalSpace()%>;
+ <%=layoutConstraintVarName%>.grabExcessVerticalSpace = <%=gmfLayoutData.isGrabExcessVerticalSpace()%>;
+ <%=figureVarName%>.getParent().getLayoutManager().setConstraint(<%=figureVarName%>, <%=layoutConstraintVarName%>);
+
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Figure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Figure.javajet
index eecabf0fd..39bff0a20 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Figure.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Figure.javajet
@@ -1,5 +1,5 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewFigureGenerator"
- imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
<%
GraphDefDispatcher.Args args = (GraphDefDispatcher.Args) argument;
final Figure figureInstance = args.getFigure();
@@ -10,4 +10,5 @@ final String figureClassName = dispatcher.getImportManager().getImportedName((St
// PRODUCES instance AND (!) initializes attributes
%>
<%=figureClassName%> <%=figureVarName%> = new <%=figureClassName%>();
-<%=args.getDispatcher().dispatch(figureInstance, args)%> \ No newline at end of file
+<%=args.getDispatcher().dispatch(figureInstance, args)%>
+<%=args.getDispatcher().dispatch("createLayout", dispatcher.createLayoutArgs(args))%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Layout.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Layout.javajet
new file mode 100644
index 000000000..ac8bd568b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/Layout.javajet
@@ -0,0 +1,21 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewLayoutGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
+final FigureMarker figureMarker = argsBundle.getFigure();
+final String figureVarName = argsBundle.getVariableName();
+final String layouterVarName = argsBundle.getLayoutVariableName();
+final GraphDefDispatcher dispatcher = argsBundle.getDispatcher();
+%>
+
+<%
+Layout gmfLayout= figureMarker.getLayout();
+if (gmfLayout != null){
+ final String layouterImplClass = dispatcher.getImportManager().getImportedName((String) dispatcher.getFQNSwitch().doSwitch(gmfLayout));
+%>
+ <%=layouterImplClass%> <%=layouterVarName%> = new <%=layouterImplClass%>();
+ <%=argsBundle.getDispatcher().dispatch(gmfLayout, argsBundle)%>
+ <%=figureVarName%>.setLayoutManager(<%=layouterVarName%>);
+<%
+}
+%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LayoutData.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LayoutData.javajet
new file mode 100644
index 000000000..efe9f349f
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/new/LayoutData.javajet
@@ -0,0 +1,16 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="NewLayoutDataGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.graphdef.codegen.*"%>
+<%
+// NOTE: this code expects that constrainted figure is already added to its parent
+
+GraphDefDispatcher.LayoutArgs argsBundle = (GraphDefDispatcher.LayoutArgs) argument;
+final GraphDefDispatcher dispatcher = argsBundle.getDispatcher();
+final LayoutData gmfLayoutData = argsBundle.getData();
+final Figure figureInstance = argsBundle.getFigure();
+
+// merely makes sure layoutData present
+// and parent figure got chance to have layout initialized
+
+if (gmfLayoutData != null && figureInstance.getParent() != null && figureInstance.getParent().getLayout() != null) {%>
+<%=dispatcher.dispatch(gmfLayoutData, argsBundle)%>
+<%}%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Shape.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Shape.javajet
index 34d9f1df9..c5854561c 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Shape.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Shape.javajet
@@ -1,5 +1,5 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopShapeGenerator"
- imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.GraphDefDispatcher java.util.*"%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* java.util.*"%>
<%
Object[] args = (Object[]) argument;
Shape figure = (Shape) args[0];
@@ -18,12 +18,20 @@ public class <%=figure.getName()%> extends <%=importManager.getImportedName((Str
* @generated
*/
public <%=figure.getName()%>() {
- <%=dispatcher.dispatch(figure, dispatcher.create(figure, "this"))%>
+<%
+GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager");
+%>
+ <%=dispatcher.dispatch("createLayout", dispatcherArgs)%>
+ <%=dispatcher.dispatch(figure, dispatcherArgs)%>
<%
for (Iterator it = figure.getResolvedChildren().iterator(); it.hasNext();) {
- Figure next = (Figure) it.next();%>
- setFigure<%=next.getName()%>(createFigure<%=next.getName()%>());
- add(getFigure<%=next.getName()%>());
+ Figure next = (Figure) it.next();
+ final String childVarName = "child" + next.getName();%>
+
+ org.eclipse.draw2d.IFigure <%=childVarName%> = createFigure<%=next.getName()%>();
+ setFigure<%=next.getName()%>(<%=childVarName%>);
+ add(<%=childVarName%>);
+ <%=dispatcher.dispatch("createLayoutData", dispatcher.createLayoutArgs(next, childVarName, "layout" + next.getName()))%>
<%}%>
}

Back to the top