From jbosstools-commits at lists.jboss.org Wed Jul 30 10:11:21 2008 Content-Type: multipart/mixed; boundary="===============4132450311114676108==" MIME-Version: 1.0 From: jbosstools-commits at lists.jboss.org To: jbosstools-commits at lists.jboss.org Subject: [jbosstools-commits] JBoss Tools SVN: r9432 - trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tools/flow/editor/action. Date: Wed, 30 Jul 2008 10:11:21 -0400 Message-ID: --===============4132450311114676108== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: koen.aers(a)jboss.com Date: 2008-07-30 10:11:21 -0400 (Wed, 30 Jul 2008) New Revision: 9432 Added: trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tools= /flow/editor/action/HorizontalAutoLayoutAction.java trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tools= /flow/editor/action/VerticalAutoLayoutAction.java Log: Added: trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/t= ools/flow/editor/action/HorizontalAutoLayoutAction.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tool= s/flow/editor/action/HorizontalAutoLayoutAction.java = (rev 0) +++ trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tool= s/flow/editor/action/HorizontalAutoLayoutAction.java 2008-07-30 14:11:21 UT= C (rev 9432) @@ -0,0 +1,56 @@ +package org.jboss.tools.flow.editor.action; + +/* + * Copyright 2005 JBoss Inc + * = + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * = + * http://www.apache.org/licenses/LICENSE-2.0 + * = + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.Map; + +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.graph.DirectedGraph; +import org.eclipse.draw2d.graph.Node; +import org.eclipse.gef.GraphicalViewer; +import org.eclipse.jface.resource.ImageDescriptor; +import org.jboss.tools.flow.Activator; + +/** + * Action for auto layouting a process. + * = + * @author Kris Verlaenen<= /a> + */ +public class HorizontalAutoLayoutAction extends VerticalAutoLayoutAction { + + public static final String ID =3D "org.jboss.tools.process.editor.action.= HorizontalAutoLayoutAction"; + = + public HorizontalAutoLayoutAction(GraphicalViewer diagramViewer) { + super(diagramViewer); + } + = + protected void initialize() { + setId(ID); + setText("Auto Layout (Horizontal)"); + setImageDescriptor( + ImageDescriptor.createFromURL( + Activator.getDefault().getBundle().getEntry("/icons/layoutH.gif"))); + setToolTipText("Auto layout the process (horizontal)"); + } + + protected DirectedGraph createDirectedGraph(Map mapping)= { + DirectedGraph graph =3D super.createDirectedGraph(mapping); + graph.setDirection(PositionConstants.HORIZONTAL); + return graph; + } + +} Added: trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/t= ools/flow/editor/action/VerticalAutoLayoutAction.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tool= s/flow/editor/action/VerticalAutoLayoutAction.java = (rev 0) +++ trunk/flow/plugins/org.jboss.tools.flow.common.graph/src/org/jboss/tool= s/flow/editor/action/VerticalAutoLayoutAction.java 2008-07-30 14:11:21 UTC = (rev 9432) @@ -0,0 +1,103 @@ +package org.jboss.tools.flow.editor.action; + +/* + * Copyright 2005 JBoss Inc + * = + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * = + * http://www.apache.org/licenses/LICENSE-2.0 + * = + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.draw2d.geometry.Dimension; +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.gef.GraphicalViewer; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.jboss.tools.flow.Activator; +import org.jboss.tools.flow.editor.core.AbstractConnectionWrapper; +import org.jboss.tools.flow.editor.core.AbstractFlowWrapper; +import org.jboss.tools.flow.editor.core.NodeWrapper; + +/** + * Action for auto layouting a process. + * = + * @author Kris Verlaenen<= /a> + */ +public class VerticalAutoLayoutAction extends Action implements IAction { + = + public static final String ID =3D "org.jboss.tools.process.editor.action.= VerticalAutoLayoutAction"; + = + private GraphicalViewer diagramViewer; + = + public VerticalAutoLayoutAction(GraphicalViewer diagramViewer) { + this.diagramViewer =3D diagramViewer; + initialize(); + } + = + protected void initialize() { + setId(ID); + setText("Auto Layout (Vertical)"); + setImageDescriptor( + ImageDescriptor.createFromURL( + Activator.getDefault().getBundle().getEntry("/icons/layoutV.gif"))); + setToolTipText("Auto layout the process (vertical)"); + } + + public void run() { + Map mapping =3D new HashMap(); + DirectedGraph graph =3D createDirectedGraph(mapping); + DirectedGraphLayout layout =3D new DirectedGraphLayout(); + layout.visit(graph); + for (Map.Entry entry: mapping.entrySet()) { + Node node =3D entry.getValue(); + NodeWrapper nodeWrapper =3D = + ((AbstractFlowWrapper)diagramViewer.getContents().getModel())= .getElement(entry.getKey()); + nodeWrapper.setConstraint(new Rectangle(node.x, node.y, node.w= idth, node.height)); + } + } + = + @SuppressWarnings("unchecked") + protected DirectedGraph createDirectedGraph(Map mapping)= { + DirectedGraph graph =3D new DirectedGraph(); + AbstractFlowWrapper processWrapper =3D (AbstractFlowWrapper)diagra= mViewer.getContents().getModel(); + for (NodeWrapper elementWrapper: processWrapper.getElements()) { + Node node =3D new Node(); + Integer width =3D (Integer) elementWrapper.getConstraint().wid= th; + Integer height =3D (Integer) elementWrapper.getConstraint().he= ight; + if (width =3D=3D null || width <=3D 0) { + width =3D 80; + } + if (height =3D=3D null || height <=3D 0) { + height =3D 40; + } + node.setSize(new Dimension(width, height)); + graph.nodes.add(node); + mapping.put(elementWrapper.getId(), node); + } + for (NodeWrapper elementWrapper: processWrapper.getElements()) { + for (AbstractConnectionWrapper connection: elementWrapper.getI= ncomingConnections()) { + Node source =3D mapping.get(connection.getSource().getId()= ); + Node target =3D mapping.get(connection.getTarget().getId()= ); + graph.edges.add(new Edge(source, target)); + } + } + return graph; + } + +} --===============4132450311114676108==--