[jboss-svn-commits] JBL Code SVN: r20365 - in labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin: icons and 11 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 9 07:05:57 EDT 2008


Author: KrisVerlaenen
Date: 2008-06-09 07:05:57 -0400 (Mon, 09 Jun 2008)
New Revision: 20365

Added:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/icons/processV.gif
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/schema/
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/schema/processExtension.exsd
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/ProcessExtension.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/HorizontalAutoLayoutAction.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/VerticalAutoLayoutAction.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/core/ProcessWrapperBuilder.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/editpart/ProcessEditPartFactory.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/RuleFlowExtension.java
Modified:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstanceViewer.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesView.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/core/RuleFlowWrapperBuilder.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java
Log:
JBRULES-1637: Auto layout for workflow processes
 - horizontal and vertical auto layout action
 - improved pluggability of workflow processes

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/icons/processV.gif
===================================================================
(Binary files differ)


Property changes on: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/icons/processV.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml	2008-06-08 15:08:18 UTC (rev 20364)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml	2008-06-09 11:05:57 UTC (rev 20365)
@@ -450,6 +450,30 @@
             class="org.drools.eclipse.flow.ruleflow.editor.action.CheckRuleFlowAction"
          />
       </editorContribution>
+      <editorContribution
+            id="org.drools.eclipse.flow.common.editor.action.VerticalAutoLayoutAction"
+            targetID="org.drools.eclipse.flow.ruleflow.editor.RuleFlowModelEditor">
+	     <action
+	        id="org.drools.eclipse.flow.common.editor.action.VerticalAutoLayoutAction"
+            label="Auto Layout (Vertical)"
+	        toolbarPath="Drools"
+            icon="icons/processV.gif"
+            tooltip="Auto layout the workflow (vertical)"
+            class="org.drools.eclipse.flow.common.editor.action.VerticalAutoLayoutAction"
+         />
+      </editorContribution>
+      <editorContribution
+            id="org.drools.eclipse.flow.common.editor.action.HorizontalAutoLayoutAction"
+            targetID="org.drools.eclipse.flow.ruleflow.editor.RuleFlowModelEditor">
+	     <action
+	        id="org.drools.eclipse.flow.common.editor.action.HorizontalAutoLayoutAction"
+            label="Auto Layout (Horizontal)"
+	        toolbarPath="Drools"
+            icon="icons/process.gif"
+            tooltip="Auto layout the workflow (horizontal)"
+            class="org.drools.eclipse.flow.common.editor.action.HorizontalAutoLayoutAction"
+         />
+      </editorContribution>
    </extension>
 
    <extension
@@ -469,6 +493,15 @@
 	  </wizard>
    </extension>
 
+   <extension-point id="processExtension" name="Process Extension" schema="schema/processExtension.exsd"/>
+
+   <extension
+         point="org.drools.eclipse.processExtension">
+      <processExtension
+            className="org.drools.eclipse.flow.ruleflow.RuleFlowExtension">
+      </processExtension>
+   </extension>
+   
    <!-- RuleBuilder Extensions -->
       <extension
          point="org.eclipse.ui.editors">

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/schema/processExtension.exsd
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/schema/processExtension.exsd	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/schema/processExtension.exsd	2008-06-09 11:05:57 UTC (rev 20365)
@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.drools.eclipse">
+<annotation>
+      <appInfo>
+         <meta.schema plugin="org.drools.eclipse" id="processwrapperbuilder" name="ProcessWrapper Builder"/>
+      </appInfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <complexType>
+         <sequence>
+            <element ref="processExtension"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appInfo>
+                  <meta.attribute translatable="true"/>
+               </appInfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="processExtension">
+      <complexType>
+         <attribute name="className" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="since"/>
+      </appInfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="examples"/>
+      </appInfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="apiInfo"/>
+      </appInfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="implementation"/>
+      </appInfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appInfo>
+         <meta.section type="copyright"/>
+      </appInfo>
+      <documentation>
+         
+      </documentation>
+   </annotation>
+
+</schema>

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java	2008-06-08 15:08:18 UTC (rev 20364)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -41,6 +41,7 @@
 import org.drools.process.core.Process;
 import org.drools.rule.builder.dialect.java.JavaDialectConfiguration;
 import org.drools.ruleflow.core.RuleFlowProcess;
+import org.drools.workflow.core.WorkflowProcess;
 import org.drools.xml.XmlProcessReader;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
@@ -421,20 +422,12 @@
                 Thread.currentThread().setContextClassLoader(newLoader);
                 PackageBuilderConfiguration configuration = new PackageBuilderConfiguration();
                 XmlProcessReader xmlReader = new XmlProcessReader( configuration.getSemanticModules() );
-                
-                Process o = xmlReader.read(new StringReader(input));
-                if (o instanceof RuleFlowProcess) {
-                    RuleFlowProcess process = (RuleFlowProcess) o;
-                    PackageBuilder packageBuilder = new PackageBuilder();
-                    ProcessBuilder processBuilder = new ProcessBuilder(packageBuilder);
-                    processBuilder.buildProcess(process);
-                    ProcessInfo processInfo = new ProcessInfo(process.getId(), process);
-                    processInfo.setErrors(processBuilder.getErrors());
-                    if (useCachePreference) {
-                        processInfos.put(resource, processInfo);
-                        processInfosById.put(process.getId(), processInfo);
-                    }
-                    return processInfo;
+                Process process = xmlReader.read(new StringReader(input));
+                if (process != null) {
+                    return parseProcess(process, resource);
+                } else {
+                    throw new IllegalArgumentException(
+                        "Could not parse process " + resource);
                 }
             } finally {
                 Thread.currentThread().setContextClassLoader(oldLoader);
@@ -448,6 +441,19 @@
 	public ProcessInfo getProcessInfo(String processId) {
 	    return processInfosById.get(processId);
 	}
+	
+	public ProcessInfo parseProcess(Process process, IResource resource) {
+        PackageBuilder packageBuilder = new PackageBuilder();
+        ProcessBuilder processBuilder = new ProcessBuilder(packageBuilder);
+        processBuilder.buildProcess(process);
+        ProcessInfo processInfo = new ProcessInfo(process.getId(), process);
+        processInfo.setErrors(processBuilder.getErrors());
+        if (useCachePreference) {
+            processInfos.put(resource, processInfo);
+            processInfosById.put(process.getId(), processInfo);
+        }
+        return processInfo;
+	}
 
     /**
      * Form Colors, default colors for now.

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java	2008-06-08 15:08:18 UTC (rev 20364)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -115,7 +115,7 @@
         }
     }
     
-    private boolean parseResource(IResource res, boolean clean) {
+    protected boolean parseResource(IResource res, boolean clean) {
         try {
             IJavaProject project = JavaCore.create(res.getProject());
             // exclude files that are located in the output directory,
@@ -316,7 +316,7 @@
         return (DroolsBuildMarker[]) markers.toArray(new DroolsBuildMarker[markers.size()]);
     }
     
-    private DroolsBuildMarker[] parseRuleFlowFile(IFile file) {
+    protected DroolsBuildMarker[] parseRuleFlowFile(IFile file) {
         if (!file.exists()) {
             return new DroolsBuildMarker[0];
         }
@@ -339,7 +339,7 @@
         return (DroolsBuildMarker[]) markers.toArray(new DroolsBuildMarker[markers.size()]);
     }
     
-    private static String convertToString(final InputStream inputStream) throws IOException {
+    protected static String convertToString(final InputStream inputStream) throws IOException {
     	Reader reader = new InputStreamReader(inputStream);
     	final StringBuffer text = new StringBuffer();
         final char[] buf = new char[1024];
@@ -354,7 +354,7 @@
      * This will create markers for parse errors.
      * Parse errors mean that antlr has picked up some major typos in the input source.
      */
-    private void markParseErrors(List markers, List parserErrors) {
+    protected void markParseErrors(List markers, List parserErrors) {
         for ( Iterator iter = parserErrors.iterator(); iter.hasNext(); ) {
         	Object error = iter.next();
         	if (error instanceof ParserError) {
@@ -424,7 +424,7 @@
         }
     }
 
-    private void createMarker(final IResource res, final String message, final int lineNumber) {
+    protected void createMarker(final IResource res, final String message, final int lineNumber) {
         try {
         	IWorkspaceRunnable r= new IWorkspaceRunnable() {
         		public void run(IProgressMonitor monitor) throws CoreException {
@@ -442,7 +442,7 @@
         }
     }
     
-    private void removeProblemsFor(IResource resource) {
+    protected void removeProblemsFor(IResource resource) {
         try {
             if (resource != null && resource.exists()) {
                 resource.deleteMarkers(

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstanceViewer.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstanceViewer.java	2008-06-08 15:08:18 UTC (rev 20364)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstanceViewer.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -7,18 +7,20 @@
 
 import org.drools.eclipse.DroolsEclipsePlugin;
 import org.drools.eclipse.ProcessInfo;
+import org.drools.eclipse.flow.common.editor.ProcessExtension;
 import org.drools.eclipse.flow.common.editor.core.ElementWrapper;
 import org.drools.eclipse.flow.common.editor.core.ProcessWrapper;
 import org.drools.eclipse.flow.common.editor.editpart.ElementEditPart;
 import org.drools.eclipse.flow.common.editor.editpart.ProcessEditPart;
+import org.drools.eclipse.flow.common.editor.editpart.ProcessEditPartFactory;
 import org.drools.eclipse.flow.common.editor.editpart.figure.ElementFigure;
-import org.drools.eclipse.flow.ruleflow.core.RuleFlowProcessWrapper;
-import org.drools.eclipse.flow.ruleflow.core.RuleFlowWrapperBuilder;
-import org.drools.eclipse.flow.ruleflow.editor.editpart.RuleFlowEditPartFactory;
-import org.drools.ruleflow.core.RuleFlowProcess;
+import org.drools.process.core.Process;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.gef.GraphicalViewer;
 import org.eclipse.gef.editparts.ScalableRootEditPart;
@@ -93,21 +95,35 @@
             graphicalViewer.getControl().setBackground(ColorConstants.listBackground);
             graphicalViewer.setRootEditPart(new ScalableRootEditPart());
             IJavaProject javaProject = getJavaProject(projectName);
-            graphicalViewer.setEditPartFactory(new RuleFlowEditPartFactory(javaProject));
-            setProcess(processInfo);
+            
+            IExtensionRegistry reg = Platform.getExtensionRegistry();
+            IConfigurationElement[] extensions =
+                reg.getConfigurationElementsFor(
+                    "org.drools.eclipse.processExtension");
+            for (IConfigurationElement element: extensions) {
+                try {
+                    ProcessExtension processExtension = (ProcessExtension)
+                        element.createExecutableExtension("className");
+                    Process process = processInfo.getProcess();
+                    if (processExtension.acceptsProcess(process.getType())) {
+                        ProcessEditPartFactory editPartFactory = processExtension.getProcessEditPartFactory();
+                        editPartFactory.setProject(javaProject);
+                        graphicalViewer.setEditPartFactory(editPartFactory);
+                        ProcessWrapper processWrapper = processExtension.getProcessWrapperBuilder().getProcessWrapper(process, javaProject);
+                        graphicalViewer.setContents(processWrapper);
+                        break;
+                    }
+                } catch (CoreException e) {
+                    DroolsEclipsePlugin.log(e);
+                }
+            }
+
             for (String nodeId: nodeIds) {
             	handleNodeInstanceSelection(nodeId);
             }
             folder.setSelection(tabItem);
         }
         
-        private void setProcess(ProcessInfo processInfo) {
-            RuleFlowProcess process = (RuleFlowProcess) processInfo.getProcess();
-            ProcessWrapper processWrapper = RuleFlowWrapperBuilder.getProcessWrapper(process, getJavaProject(projectName));
-            graphicalViewer.setContents(
-                processWrapper == null ? new RuleFlowProcessWrapper() : processWrapper);
-        }
-
         private void handleNodeInstanceSelection(String nodeId) {
             boolean found = false;
             Iterator iterator = ((ProcessEditPart) graphicalViewer.getContents()).getChildren().iterator();

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesView.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesView.java	2008-06-08 15:08:18 UTC (rev 20364)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ProcessInstancesView.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -91,6 +91,7 @@
                     IVariable var = vars[j];
                     if ("nodeId".equals(var.getName())) {
                         nodeId = ((IJavaValue) var.getValue()).getValueString();
+                        break;
                     }
                 }
                 nodeIds.add(nodeId);

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/ProcessExtension.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/ProcessExtension.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/ProcessExtension.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -0,0 +1,14 @@
+package org.drools.eclipse.flow.common.editor;
+
+import org.drools.eclipse.flow.common.editor.core.ProcessWrapperBuilder;
+import org.drools.eclipse.flow.common.editor.editpart.ProcessEditPartFactory;
+
+public interface ProcessExtension {
+
+    boolean acceptsProcess(String type);
+    
+    ProcessWrapperBuilder getProcessWrapperBuilder();
+    
+    ProcessEditPartFactory getProcessEditPartFactory();
+    
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/HorizontalAutoLayoutAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/HorizontalAutoLayoutAction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/HorizontalAutoLayoutAction.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -0,0 +1,37 @@
+package org.drools.eclipse.flow.common.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;
+
+/**
+ * Action for auto layouting a RuleFlow.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class HorizontalAutoLayoutAction extends VerticalAutoLayoutAction {
+
+    protected DirectedGraph createDirectedGraph(Map<Long, Node> mapping) {
+        DirectedGraph graph = super.createDirectedGraph(mapping);
+        graph.setDirection(PositionConstants.HORIZONTAL);
+        return graph;
+    }
+
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/VerticalAutoLayoutAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/VerticalAutoLayoutAction.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/action/VerticalAutoLayoutAction.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -0,0 +1,100 @@
+package org.drools.eclipse.flow.common.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.List;
+import java.util.Map;
+
+import org.drools.eclipse.flow.common.editor.GenericModelEditor;
+import org.drools.eclipse.flow.common.editor.core.ProcessWrapper;
+import org.drools.eclipse.flow.ruleflow.core.AbstractNodeWrapper;
+import org.drools.workflow.core.Connection;
+import org.drools.workflow.core.WorkflowProcess;
+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.jface.action.IAction;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ActionDelegate;
+
+/**
+ * Action for auto layouting a RuleFlow.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class VerticalAutoLayoutAction extends ActionDelegate implements IEditorActionDelegate {
+
+    private IEditorPart editor;
+    
+    public void run(IAction action) {
+        execute();
+    }
+
+    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+        editor = targetEditor;
+    }
+
+    private void execute() {
+        editor.doSave(null);
+        Map<Long, Node> mapping = new HashMap<Long, Node>();
+        DirectedGraph graph = createDirectedGraph(mapping);
+        DirectedGraphLayout layout = new DirectedGraphLayout();
+        layout.visit(graph);
+        for (Map.Entry<Long, Node> entry: mapping.entrySet()) {
+            Node node = entry.getValue();
+            AbstractNodeWrapper nodeWrapper = (AbstractNodeWrapper)
+                ((ProcessWrapper) ((GenericModelEditor) editor).getModel()).getElement(entry.getKey() + "");
+            nodeWrapper.setConstraint(new Rectangle(node.x, node.y, node.width, node.height));
+        }
+        // TODO: implement changes as a command, so we can support undo
+        editor.doSave(null);
+    }
+    
+    protected DirectedGraph createDirectedGraph(Map<Long, Node> mapping) {
+        DirectedGraph graph = new DirectedGraph();
+        WorkflowProcess process = (WorkflowProcess) ((ProcessWrapper) ((GenericModelEditor) editor).getModel()).getProcess();
+        for (org.drools.workflow.core.Node processNode: process.getNodes()) {
+            Node node = new Node();
+            Integer width = (Integer) processNode.getMetaData("width");
+            Integer height = (Integer) processNode.getMetaData("height");
+            if (width == null || width <= 0) {
+                width = 80;
+            }
+            if (height == null || height <= 0) {
+                height = 40;
+            }
+            node.setSize(new Dimension(width, height));
+            graph.nodes.add(node);
+            mapping.put(processNode.getId(), node);
+        }
+        for (org.drools.workflow.core.Node processNode: process.getNodes()) {
+            for (List<Connection> connections: processNode.getIncomingConnections().values()) {
+                for (Connection connection: connections) {
+                    Node source = mapping.get(connection.getFrom().getId());
+                    Node target = mapping.get(connection.getTo().getId());
+                    graph.edges.add(new Edge(source, target));
+                }
+            }
+        }
+        return graph;
+    }
+
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/core/ProcessWrapperBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/core/ProcessWrapperBuilder.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/core/ProcessWrapperBuilder.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -0,0 +1,10 @@
+package org.drools.eclipse.flow.common.editor.core;
+
+import org.drools.process.core.Process;
+import org.eclipse.jdt.core.IJavaProject;
+
+public interface ProcessWrapperBuilder {
+    
+    ProcessWrapper getProcessWrapper(Process process, IJavaProject project);
+
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/editpart/ProcessEditPartFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/editpart/ProcessEditPartFactory.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/common/editor/editpart/ProcessEditPartFactory.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -0,0 +1,30 @@
+package org.drools.eclipse.flow.common.editor.editpart;
+/*
+ * 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 org.eclipse.gef.EditPartFactory;
+import org.eclipse.jdt.core.IJavaProject;
+
+/**
+ * Factory for RuleFlow EditParts.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface ProcessEditPartFactory extends EditPartFactory {
+    
+    void setProject(IJavaProject project);
+    
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/RuleFlowExtension.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/RuleFlowExtension.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/RuleFlowExtension.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -0,0 +1,23 @@
+package org.drools.eclipse.flow.ruleflow;
+
+import org.drools.eclipse.flow.common.editor.ProcessExtension;
+import org.drools.eclipse.flow.common.editor.core.ProcessWrapperBuilder;
+import org.drools.eclipse.flow.common.editor.editpart.ProcessEditPartFactory;
+import org.drools.eclipse.flow.ruleflow.core.RuleFlowWrapperBuilder;
+import org.drools.eclipse.flow.ruleflow.editor.editpart.RuleFlowEditPartFactory;
+
+public class RuleFlowExtension implements ProcessExtension {
+
+    public boolean acceptsProcess(String type) {
+        return "RuleFlow".equals(type);
+    }
+    
+    public ProcessEditPartFactory getProcessEditPartFactory() {
+        return new RuleFlowEditPartFactory();
+    }
+
+    public ProcessWrapperBuilder getProcessWrapperBuilder() {
+        return new RuleFlowWrapperBuilder();
+    }
+
+}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/core/RuleFlowWrapperBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/core/RuleFlowWrapperBuilder.java	2008-06-08 15:08:18 UTC (rev 20364)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/core/RuleFlowWrapperBuilder.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -10,6 +10,9 @@
 import org.drools.eclipse.DroolsEclipsePlugin;
 import org.drools.eclipse.WorkItemDefinitions;
 import org.drools.eclipse.flow.common.editor.core.ElementContainer;
+import org.drools.eclipse.flow.common.editor.core.ProcessWrapper;
+import org.drools.eclipse.flow.common.editor.core.ProcessWrapperBuilder;
+import org.drools.process.core.Process;
 import org.drools.process.core.Work;
 import org.drools.process.core.WorkDefinition;
 import org.drools.process.core.impl.WorkDefinitionImpl;
@@ -29,19 +32,20 @@
 import org.drools.workflow.core.node.WorkItemNode;
 import org.eclipse.jdt.core.IJavaProject;
 
-public class RuleFlowWrapperBuilder {
+public class RuleFlowWrapperBuilder implements ProcessWrapperBuilder {
     
-    public static RuleFlowProcessWrapper getProcessWrapper(RuleFlowProcess process, IJavaProject project) {
-        if (process == null) {
-            return null;
+    public ProcessWrapper getProcessWrapper(Process process, IJavaProject project) {
+        if (process instanceof RuleFlowProcess) {
+            RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process;
+            RuleFlowProcessWrapper processWrapper = new RuleFlowProcessWrapper();
+            processWrapper.localSetProcess(process);
+            Set<Node> nodes = new HashSet<Node>();
+            nodes.addAll(Arrays.asList(ruleFlowProcess.getNodes()));
+            Set<Connection> connections = new HashSet<Connection>();
+            processNodes(nodes, connections, processWrapper, project);
+            return processWrapper;
         }
-        RuleFlowProcessWrapper processWrapper = new RuleFlowProcessWrapper();
-        processWrapper.localSetProcess(process);
-        Set<Node> nodes = new HashSet<Node>();
-        nodes.addAll(Arrays.asList(process.getNodes()));
-        Set<Connection> connections = new HashSet<Connection>();
-        processNodes(nodes, connections, processWrapper, project);
-        return processWrapper;
+        return null;
     }
     
     private static void processNodes(Set<Node> nodes, Set<Connection> connections, ElementContainer container, IJavaProject project) {

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java	2008-06-08 15:08:18 UTC (rev 20364)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java	2008-06-09 11:05:57 UTC (rev 20365)
@@ -17,6 +17,7 @@
 
 import org.drools.eclipse.flow.common.editor.editpart.ElementContainerEditPart;
 import org.drools.eclipse.flow.common.editor.editpart.ProcessEditPart;
+import org.drools.eclipse.flow.common.editor.editpart.ProcessEditPartFactory;
 import org.drools.eclipse.flow.ruleflow.core.ActionWrapper;
 import org.drools.eclipse.flow.ruleflow.core.CompositeNodeWrapper;
 import org.drools.eclipse.flow.ruleflow.core.ConnectionWrapper;
@@ -30,9 +31,7 @@
 import org.drools.eclipse.flow.ruleflow.core.SubProcessWrapper;
 import org.drools.eclipse.flow.ruleflow.core.TimerWrapper;
 import org.drools.eclipse.flow.ruleflow.core.WorkItemWrapper;
-import org.drools.eclipse.flow.ruleflow.editor.RuleFlowModelEditor;
 import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartFactory;
 import org.eclipse.jdt.core.IJavaProject;
 
 /**
@@ -40,11 +39,11 @@
  * 
  * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  */
-public class RuleFlowEditPartFactory implements EditPartFactory {
+public class RuleFlowEditPartFactory implements ProcessEditPartFactory {
     
     private IJavaProject project;
     
-    public RuleFlowEditPartFactory(IJavaProject project) {
+    public void setProject(IJavaProject project) {
         this.project = project;
     }
     




More information about the jboss-svn-commits mailing list