Author: DartPeng
Date: 2009-10-27 12:59:27 -0400 (Tue, 27 Oct 2009)
New Revision: 18314
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/IAutoLayout.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/JavaMappingAutoLayout.java
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksJavaMappingGraphicalEditor.java
Log:
JBIDE-4648
Done
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java 2009-10-27
16:54:36 UTC (rev 18313)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/editor/AbstractSmooksFormEditor.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -560,12 +560,14 @@
if (resourceList != null) {
smooksGraphicsExt = GraphFactory.eINSTANCE.createSmooksGraphicsExtType();
+ smooksGraphicsExt.setGraph(GraphFactory.eINSTANCE.createGraphType());
+ smooksGraphicsExt.setProcesses(GraphFactory.eINSTANCE.createProcessesType());
smooksGraphicsExt.setInputType(inputType);
smooksGraphicsExt.setPlatformVersion(version);
AddCommand.create(
this.editingDomain,
resourceList,
- SmooksPackage.Literals.SMOOKS_RESOURCE_LIST_TYPE__ABSTRACT_READER_GROUP,
+ SmooksPackage.Literals.SMOOKS_RESOURCE_LIST_TYPE__ABSTRACT_RESOURCE_CONFIG_GROUP,
FeatureMapUtil.createEntry(
GraphPackage.Literals.SMOOKS_GRAPH_EXTENSION_DOCUMENT_ROOT__SMOOKS_GRAPHICS_EXT,
smooksGraphicsExt)).execute();
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -0,0 +1,133 @@
+package org.jboss.tools.smooks.gef.tree.figures;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.GraphicalEditPart;
+
+public class GraphAnimation {
+
+ private int minsteplegth = 30;
+
+ private int maxstep = 50;
+
+ private Map<GraphicalEditPart, Rectangle> initMap = new
HashMap<GraphicalEditPart, Rectangle>();
+
+ private Map<GraphicalEditPart, Rectangle> finalMap = new
HashMap<GraphicalEditPart, Rectangle>();
+
+ public void recordInit(GraphicalEditPart editpart) {
+ initMap.put(editpart, editpart.getFigure().getBounds());
+ }
+
+ public void recordFinal(GraphicalEditPart editpart, Rectangle rectangle) {
+ finalMap.put(editpart, rectangle);
+ }
+
+ public void start(List<GraphicalEditPart> figureList) {
+ // if(true) return;
+ Map<IFigure, Integer> ystepmap = new HashMap<IFigure, Integer>();
+ Map<IFigure, Integer> xstepmap = new HashMap<IFigure, Integer>();
+ for (Iterator<?> iterator = figureList.iterator(); iterator.hasNext();) {
+ GraphicalEditPart editPart = (GraphicalEditPart) iterator.next();
+ IFigure figure = editPart.getFigure();
+ Rectangle rect = initMap.get(editPart);
+ int initx = rect.x;
+ int inity = rect.y;
+ Rectangle rect1 = finalMap.get(editPart);
+ int finalx = rect1.x;
+ int finaly = rect1.y;
+
+ int chax = finalx - initx;
+ // if(Math.abs(chax) < minsteplegth){
+ // chax = minsteplegth;
+ // }
+ int xstep = minsteplegth;
+ if (chax < 0)
+ xstep = -xstep;
+ if (Math.abs(chax / minsteplegth) > maxstep) {
+ // xstep = chax / maxstep;
+ }
+
+ int chay = finaly - inity;
+ int ystep = minsteplegth;
+ if (chay < 0)
+ ystep = -ystep;
+ if (Math.abs(chay / minsteplegth) > maxstep) {
+ // ystep = chay / maxstep;
+ }
+
+ ystepmap.put(figure, ystep);
+ xstepmap.put(figure, xstep);
+ }
+ int allfigure = 0;
+ List<GraphicalEditPart> processedParts = new
ArrayList<GraphicalEditPart>();
+ while (figureList.size() > allfigure) {
+ for (Iterator<?> iterator = figureList.iterator(); iterator.hasNext();) {
+ GraphicalEditPart editPart = (GraphicalEditPart) iterator.next();
+ if (processedParts.contains(editPart)) {
+ continue;
+ }
+ IFigure figure = editPart.getFigure();
+ Rectangle rect = figure.getBounds();
+ int initx = rect.x;
+ int inity = rect.y;
+
+ Rectangle rect1 = finalMap.get(editPart);
+ int finalx = rect1.x;
+ int finaly = rect1.y;
+
+ int xstep = xstepmap.get(figure);
+ int ystep = ystepmap.get(figure);
+
+ int x = initx + xstep;
+ int y = inity + ystep;
+ if (initx != finalx) {
+ if (Math.abs(x - finalx) <= minsteplegth) {
+ initx = finalx;
+ } else {
+ initx = x;
+ }
+ }
+
+ if (inity != finaly) {
+ if (Math.abs(y - finaly) <= minsteplegth) {
+ inity = finaly;
+ } else {
+ inity = y;
+ }
+ }
+
+ if (initx == finalx && inity == finaly) {
+ processedParts.add(editPart);
+ allfigure++;
+ }
+
+ Point location = new Point(initx, inity);
+ Dimension size = figure.getPreferredSize();
+ figure.setLocation(new Point(initx, inity));
+ figure.getUpdateManager().performUpdate();
+ try {
+ ((GraphicalEditPart) editPart.getParent()).setLayoutConstraint(editPart, figure, new
Rectangle(
+ location, size));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ try {
+ Thread.sleep(10);
+ Thread.yield();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/gef/tree/figures/GraphAnimation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.graphical.actions;
+
+import org.eclipse.gef.ui.actions.SelectionAction;
+import org.eclipse.ui.IWorkbenchPart;
+import org.jboss.tools.smooks.graphical.editors.SmooksGraphicalEditorPart;
+import org.jboss.tools.smooks.graphical.editors.editparts.IAutoLayout;
+
+/**
+ * @author Dart
+ *
+ */
+public class AutoLayoutAction extends SelectionAction{
+
+ public static final String ID = "_smooks_auto_layout";
+
+ public AutoLayoutAction(IWorkbenchPart part, int style) {
+ super(part, style);
+ }
+
+ public AutoLayoutAction(IWorkbenchPart part) {
+ super(part);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#init()
+ */
+ @Override
+ protected void init() {
+ super.init();
+ this.setText("Auto Layout");
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
+ */
+ @Override
+ protected boolean calculateEnabled() {
+ IWorkbenchPart part = this.getWorkbenchPart();
+ if(part instanceof SmooksGraphicalEditorPart){
+ IAutoLayout layout = ((SmooksGraphicalEditorPart)part).getAutoLayout();
+ return (layout != null);
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ IWorkbenchPart part = this.getWorkbenchPart();
+ if(part instanceof SmooksGraphicalEditorPart){
+ ((SmooksGraphicalEditorPart)part).autoLayout(true);
+ }
+ }
+
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/actions/AutoLayoutAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java 2009-10-27
16:54:36 UTC (rev 18313)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/ProcessAnalyzer.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -91,7 +91,7 @@
*/
public boolean analyzeSmooksModels(SmooksResourceListType resourceList) {
boolean modelWasChanged = false;
- SmooksGraphicsExtType ext = getSmooksGraphicsType(resourceList);
+ SmooksGraphicsExtType ext = this. getSmooksGraphicsType(resourceList);
if (ext == null)
throw new RuntimeException("Can't find the smooks-graph-ext element");
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java 2009-10-27
16:54:36 UTC (rev 18313)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorMenuContextProvider.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -15,12 +15,12 @@
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.GEFActionConstants;
-import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.jboss.tools.smooks.gef.common.SmooksGraphicalMenuContextProvider;
import org.jboss.tools.smooks.graphical.actions.AddSmooksModelAction;
+import org.jboss.tools.smooks.graphical.actions.AutoLayoutAction;
import org.jboss.tools.smooks.graphical.actions.xsltemplate.AddAttributeAction;
import org.jboss.tools.smooks.graphical.actions.xsltemplate.AddElementAction;
@@ -60,21 +60,10 @@
}
}
}
-
- Action layout = new Action(){
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- }
-
- };
-
- layout.setText("Auto Layout");
-
-// menu.appendToGroup(GEFActionConstants.ADD_EXT, layout);
+ IAction action = getActionRegistry().getAction(AutoLayoutAction.ID);
+ if (action != null) {
+ menu.appendToGroup(GEFActionConstants.GROUP_VIEW, action);
+ }
}
}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java 2009-10-27
16:54:36 UTC (rev 18313)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -16,12 +16,13 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.graph.DirectedGraph;
-import org.eclipse.draw2d.graph.DirectedGraphLayout;
import org.eclipse.draw2d.graph.Edge;
import org.eclipse.draw2d.graph.Node;
import org.eclipse.emf.common.command.Command;
@@ -34,6 +35,7 @@
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
@@ -47,6 +49,7 @@
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.gef.ui.parts.GraphicalEditorWithPalette;
import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.util.TransferDropTargetListener;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
@@ -76,11 +79,14 @@
import org.jboss.tools.smooks.gef.common.RootModel;
import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
import org.jboss.tools.smooks.gef.tree.editparts.TreeNodeEditPart;
+import org.jboss.tools.smooks.gef.tree.figures.GraphAnimation;
import org.jboss.tools.smooks.gef.tree.figures.IMoveableModel;
import org.jboss.tools.smooks.gef.tree.model.TreeContainerModel;
import org.jboss.tools.smooks.gef.tree.model.TreeNodeConnection;
import org.jboss.tools.smooks.gef.tree.model.TreeNodeModel;
+import org.jboss.tools.smooks.graphical.actions.AutoLayoutAction;
import org.jboss.tools.smooks.graphical.editors.commands.IgnoreException;
+import org.jboss.tools.smooks.graphical.editors.editparts.IAutoLayout;
import org.jboss.tools.smooks.graphical.editors.editparts.InputDataContainerEditPart;
import org.jboss.tools.smooks.graphical.editors.editparts.SmooksGraphUtil;
import org.jboss.tools.smooks.graphical.editors.model.InputDataContianerModel;
@@ -256,6 +262,10 @@
@Override
protected void createActions() {
super.createActions();
+ IAction autoLayout = new AutoLayoutAction(this);
+ autoLayout.setId(AutoLayoutAction.ID);
+ this.getActionRegistry().registerAction(autoLayout);
+ getSelectionActions().add(autoLayout.getId());
}
private void deleteRelatedConnection(AbstractSmooksGraphicalModel effecedNode,
EStructuralFeature feature,
@@ -572,13 +582,16 @@
keyHandler.put(org.eclipse.gef.KeyStroke.getPressed(SWT.DEL, 0),
this.getActionRegistry().getAction(
ActionFactory.DELETE.getId()));
- SmooksGraphicalEditorMenuContextProvider provider = new
SmooksGraphicalEditorMenuContextProvider(
- getGraphicalViewer(), this.getActionRegistry());
+ ContextMenuProvider provider = getContextMenuProvider();
getGraphicalViewer().setContextMenu(provider);
hookSelectionActions();
}
+ protected ContextMenuProvider getContextMenuProvider() {
+ return new SmooksGraphicalEditorMenuContextProvider(getGraphicalViewer(),
this.getActionRegistry());
+ }
+
private void hookSelectionActions() {
Iterator<?> actions = getActionRegistry().getActions();
while (actions.hasNext()) {
@@ -891,6 +904,26 @@
applyGraphicalInformation(graph1, graphicalModel);
}
+ protected boolean needToAutoLayout(List<AbstractSmooksGraphicalModel> list,
GraphType graph) {
+ int missFigure = 0;
+ for (Iterator<?> iterator = list.iterator(); iterator.hasNext();) {
+ AbstractSmooksGraphicalModel abstractSmooksGraphicalModel =
(AbstractSmooksGraphicalModel) iterator.next();
+ String id = SmooksGraphUtil.generateFigureID(abstractSmooksGraphicalModel);
+ if (id != null) {
+ FigureType ft = SmooksGraphUtil.findFigureType(graph, id);
+ if (ft == null) {
+ missFigure++;
+ }
+ } else {
+ missFigure++;
+ }
+ }
+ if (missFigure >= (list.size() / 2)) {
+ return true;
+ }
+ return false;
+ }
+
protected void applyGraphicalInformation(GraphType graph, AbstractSmooksGraphicalModel
graphicalModel) {
if (graphicalModel instanceof IMoveableModel) {
String id = SmooksGraphUtil.generateFigureID(graphicalModel);
@@ -905,67 +938,107 @@
}
}
}
+
+ public boolean autoLayout() {
+ return autoLayout(false);
+ }
- protected void initModelGraphicsInformation(SmooksGraphicsExtType ext) {
- if (false) {
- DirectedGraph graph = new DirectedGraph();
- EditPart rootEditorPart = this.getGraphicalViewer().getContents();
- List<?> children = rootEditorPart.getChildren();
- HashMap<Object, Node> nodeMap = new HashMap<Object, Node>();
- // HashMap<Object, Edge> edgeMap = new HashMap<Object, Edge>();
- for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
- Object object = (Object) iterator.next();
- if (object instanceof GraphicalEditPart) {
- IFigure figure = ((GraphicalEditPart) object).getFigure();
- Node node = new Node();
- nodeMap.put(object, node);
- node.height = figure.getPreferredSize().height;
- node.width = figure.getPreferredSize().width;
- graph.nodes.add(node);
- }
- }
-
- for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
- GraphicalEditPart object = (GraphicalEditPart) iterator.next();
- for (Iterator<?> iterator2 = children.iterator(); iterator2.hasNext();) {
- GraphicalEditPart testEditPart = (GraphicalEditPart) iterator2.next();
- Node node = nodeMap.get(object);
- Node testNode = nodeMap.get(testEditPart);
- if (node != null && testNode != null) {
- if (hasConnectionAssociation(object, testEditPart, SOURCE_CONNECT_TYPE)) {
- Edge edge = new Edge(node, testNode);
- graph.edges.add(edge);
- }
- if (hasConnectionAssociation(object, testEditPart, TARGET_CONNECT_TYPE)) {
- Edge edge = new Edge(testNode, node);
- graph.edges.add(edge);
- }
- }
- }
- }
-
- DirectedGraphLayout layout = new DirectedGraphLayout();
- layout.visit(graph);
+ public boolean autoLayout(boolean animation) {
+ GraphAnimation graphAnimation = new GraphAnimation();
+ HashMap<Object, Node> nodeMap = new HashMap<Object, Node>();
+ DirectedGraph directedGraph = collectionGraphInformation(nodeMap);
+ IAutoLayout layout = getAutoLayout();
+ if (layout != null) {
+ layout.visit(directedGraph);
Iterator<?> it = nodeMap.keySet().iterator();
+ Map<IMoveableModel, Point> map = new HashMap<IMoveableModel, Point>();
+ List<GraphicalEditPart> figureList = new ArrayList<GraphicalEditPart>();
while (it.hasNext()) {
GraphicalEditPart part = (GraphicalEditPart) it.next();
Node node = (Node) nodeMap.get(part);
+ figureList.add(part);
+ graphAnimation.recordInit(part);
IMoveableModel graphicalModel = (IMoveableModel) part.getModel();
- ((IMoveableModel) graphicalModel).setLocation(new Point(node.x, node.y));
+ map.put(graphicalModel, new Point(node.x, node.y));
+ graphAnimation.recordFinal(part, new Rectangle(node.x, node.y, 0, 0));
}
- return;
+ if (animation) {
+ graphAnimation.start(figureList);
+ }
+ Iterator<IMoveableModel> it1 = map.keySet().iterator();
+ while (it1.hasNext()) {
+ IMoveableModel graphModel = it1.next();
+ Point p = map.get(graphModel);
+ ((IMoveableModel) graphModel).setLocation(p);
+ }
+ return true;
+ }
+ return false;
+ }
+ protected void initModelGraphicsInformation(SmooksGraphicsExtType ext) {
+ List<AbstractSmooksGraphicalModel> list = root.getChildren();
+ GraphType graph = ext.getGraph();
+ if (needToAutoLayout(list, graph)) {
+ if (autoLayout()) {
+ return;
+ }
}
- GraphType graph = ext.getGraph();
if (graph == null)
return;
- List<AbstractSmooksGraphicalModel> list = root.getChildren();
for (Iterator<?> iterator = list.iterator(); iterator.hasNext();) {
AbstractSmooksGraphicalModel treeNodeModel = (AbstractSmooksGraphicalModel)
iterator.next();
applyGraphicalInformation(graph, treeNodeModel);
}
}
+ public IAutoLayout getAutoLayout() {
+ return null;
+ }
+
+ protected DirectedGraph collectionGraphInformation(HashMap<Object, Node> nodeMap)
{
+ DirectedGraph graph = new DirectedGraph();
+ if (getGraphicalViewer() == null) {
+ return graph;
+ }
+ EditPart rootEditorPart = this.getGraphicalViewer().getContents();
+ List<?> children = rootEditorPart.getChildren();
+ // HashMap<Object, Edge> edgeMap = new HashMap<Object, Edge>();
+ for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
+ Object object = (Object) iterator.next();
+ if (object instanceof GraphicalEditPart) {
+ IFigure figure = ((GraphicalEditPart) object).getFigure();
+ Node node = new Node();
+ node.data = object;
+ nodeMap.put(object, node);
+ node.height = figure.getPreferredSize().height;
+ node.width = figure.getPreferredSize().width;
+ graph.nodes.add(node);
+ }
+ }
+
+ for (Iterator<?> iterator = children.iterator(); iterator.hasNext();) {
+ GraphicalEditPart object = (GraphicalEditPart) iterator.next();
+ for (Iterator<?> iterator2 = children.iterator(); iterator2.hasNext();) {
+ GraphicalEditPart testEditPart = (GraphicalEditPart) iterator2.next();
+ Node node = nodeMap.get(object);
+ Node testNode = nodeMap.get(testEditPart);
+ if (node != null && testNode != null) {
+ if (hasConnectionAssociation(object, testEditPart, SOURCE_CONNECT_TYPE)) {
+ Edge edge = new Edge(node, testNode);
+ edge.data = testEditPart;
+ graph.edges.add(edge);
+ }
+ if (hasConnectionAssociation(object, testEditPart, TARGET_CONNECT_TYPE)) {
+ Edge edge = new Edge(testNode, node);
+ graph.edges.add(edge);
+ }
+ }
+ }
+ }
+ return graph;
+ }
+
private boolean hasAssociation(Object model, GraphicalEditPart editPart) {
if (model == editPart.getModel()) {
return true;
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksJavaMappingGraphicalEditor.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksJavaMappingGraphicalEditor.java 2009-10-27
16:54:36 UTC (rev 18313)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/SmooksJavaMappingGraphicalEditor.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -21,6 +21,8 @@
import org.jboss.tools.smooks.configuration.editors.actions.JavaBean11ActionGrouper;
import org.jboss.tools.smooks.editor.ISmooksModelProvider;
import org.jboss.tools.smooks.gef.model.AbstractSmooksGraphicalModel;
+import org.jboss.tools.smooks.graphical.editors.editparts.IAutoLayout;
+import org.jboss.tools.smooks.graphical.editors.editparts.JavaMappingAutoLayout;
import org.jboss.tools.smooks.graphical.editors.model.JavaBeanGraphModel;
import org.jboss.tools.smooks.model.javabean.BindingsType;
import org.jboss.tools.smooks.model.javabean.ExpressionType;
@@ -34,12 +36,12 @@
*/
public class SmooksJavaMappingGraphicalEditor extends SmooksGraphicalEditorPart {
+ private IAutoLayout javaMappingAutoLayout;
+
public SmooksJavaMappingGraphicalEditor(ISmooksModelProvider provider) {
super(provider);
// TODO Auto-generated constructor stub
}
-
-
/* (non-Javadoc)
* @see
org.jboss.tools.smooks.graphical.editors.SmooksGraphicalEditorPart#getPaletteRoot()
@@ -63,7 +65,19 @@
}
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.smooks.graphical.editors.SmooksGraphicalEditorPart#getAutoLayout()
+ */
+ @Override
+ public IAutoLayout getAutoLayout() {
+ if(javaMappingAutoLayout == null){
+ javaMappingAutoLayout = new JavaMappingAutoLayout();
+ }
+ return javaMappingAutoLayout;
+ }
+
+
/*
* (non-Javadoc)
*
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/IAutoLayout.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/IAutoLayout.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/IAutoLayout.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.graphical.editors.editparts;
+
+import org.eclipse.draw2d.graph.DirectedGraph;
+
+/**
+ * @author Dart
+ *
+ */
+public interface IAutoLayout {
+ public void visit(DirectedGraph graph);
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/IAutoLayout.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/JavaMappingAutoLayout.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/JavaMappingAutoLayout.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/JavaMappingAutoLayout.java 2009-10-27
16:59:27 UTC (rev 18314)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.smooks.graphical.editors.editparts;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.graph.DirectedGraph;
+import org.eclipse.draw2d.graph.Node;
+import org.eclipse.draw2d.graph.NodeList;
+
+/**
+ * @author Dart
+ *
+ */
+public class JavaMappingAutoLayout implements IAutoLayout{
+
+ private int INPUT_JAVA_WIDTH = 200;
+
+ private int SPACE_JAVA = 20;
+
+ private int INIT_X = 50;
+
+ private int INIT_Y = 50;
+
+ public void visit(DirectedGraph graph){
+ NodeList nodeList = graph.nodes;
+ // place the java-mapping nodes;
+ int javaHeight = 0;
+ Node inputNode = null;
+ int java_y = INIT_Y;
+ List<Node> javaNodes = new ArrayList<Node>();
+ for (Iterator<?> iterator = nodeList.iterator(); iterator.hasNext();) {
+ Node node = (Node) iterator.next();
+ Object data = node.data;
+ if(data instanceof JavaBeanEditPart){
+ javaHeight = javaHeight + SPACE_JAVA + node.height;
+ node.y = java_y;
+ java_y = java_y + SPACE_JAVA + node.height;
+ javaNodes.add(node);
+ }
+ if(data instanceof InputDataContainerEditPart){
+ inputNode = node;
+ }
+ }
+ javaHeight = javaHeight - INIT_Y;
+ int java_x = INIT_X;
+ if(inputNode != null){
+ inputNode.x = INIT_X;
+ int input_y = INIT_Y;
+ if(javaHeight > inputNode.height){
+ int cha = (javaHeight - inputNode.height)/2;
+ input_y = cha;
+ }
+ inputNode.y = input_y;
+ java_x = inputNode.x + inputNode.width + INPUT_JAVA_WIDTH;
+ }
+
+ for (Iterator<?> iterator = javaNodes.iterator(); iterator.hasNext();) {
+ Node node = (Node) iterator.next();
+ node.x = java_x;
+ }
+
+ }
+}
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/graphical/editors/editparts/JavaMappingAutoLayout.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain