[jboss-svn-commits] JBL Code SVN: r6880 - in labs/jbossrules/branches/3.0.x/drools-ide/src: main/java/org/drools/ide/editors main/java/org/drools/ide/editors/rete main/java/org/drools/ide/editors/rete/commands main/java/org/drools/ide/editors/rete/figure main/java/org/drools/ide/editors/rete/model main/java/org/drools/ide/editors/rete/part main/java/org/drools/reteoo test/java/org/drools/ide/editors/rete test/resources

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 17 20:11:30 EDT 2006


Author: ahtik
Date: 2006-10-17 20:11:09 -0400 (Tue, 17 Oct 2006)
New Revision: 6880

Added:
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomInAction2.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomOutAction2.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteooLayoutFactory.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/Row.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/RowList.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/commands/NodeSetConstraintCommand.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/ConnectionFigure.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/VertexFigure.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/Connection.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/GraphicalVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ModelElement.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ReteGraph.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/VertexPropertySource.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/ConnectionEditPart.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/DiagramEditPart.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPart.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPartFactory.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/AlphaNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/BaseVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/EvalConditionNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/JoinNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/LeftInputAdapterNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/NotNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ObjectTypeNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteooVisitor.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/RightInputAdapterNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/TerminalNodeVertex.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ReteooLayoutFactoryTest.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ZoomControlTest.java
   labs/jbossrules/branches/3.0.x/drools-ide/src/test/resources/simplerule.drl
Log:
JBRULES-517: Port ReteOO viewer from Jung /Swing to GEF

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomInAction2.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomInAction2.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomInAction2.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,70 @@
+package org.drools.ide.editors;
+/*
+ * Copyright 2006 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.draw2d.ScalableFigure;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.ui.actions.ZoomInAction;
+
+/**
+ * Similar to ZoomInAction but adds setZoomManager(..) functionality.
+ * 
+ * ZoomInAction2 provides default constructor for initializing
+ * ZoomInAction without the need for ZoomManager.
+ * 
+ * Please note that ZoomInAction2 is not very functional until it has
+ * correct zoomManager set by setZoomManager(ZoomManager manager).<br/>
+ * 
+ * setZoomManager(ZoomManager manager) can be used several times.
+ * 
+ * @author Ahti Kitsik
+ *
+ */
+public class ZoomInAction2 extends ZoomInAction {
+
+    final private static ZoomManager FAKE_ZOOM_MANAGER = new ZoomManager( (ScalableFigure) null,
+                                                                          null );
+
+    /**
+     * Default constructor to allow ZoomInActions without specified
+     * ZoomManager.
+     */
+    public ZoomInAction2() {
+        super( FAKE_ZOOM_MANAGER );
+    }
+
+    /**
+     * Replaces existing zoomManager with the new one.
+     * 
+     * Implementation is null-safe.
+     * 
+     * @param newManager new zoom manager
+     */
+    public void setZoomManager(ZoomManager newManager) {
+
+        if ( zoomManager != null ) {
+            zoomManager.removeZoomListener( this );
+        }
+
+        zoomManager = newManager;
+
+        if ( zoomManager != null ) {
+            zoomManager.addZoomListener( this );
+        }
+
+    }
+
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomInAction2.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomOutAction2.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomOutAction2.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomOutAction2.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,70 @@
+package org.drools.ide.editors;
+/*
+ * Copyright 2006 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.draw2d.ScalableFigure;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.ui.actions.ZoomOutAction;
+
+/**
+ * Similar to ZoomOutAction but adds setZoomManager(..) functionality.
+ * 
+ * ZoomOutAction2 provides default constructor for initializing
+ * ZoomOutAction without the need for ZoomManager.
+ * 
+ * Please note that ZoomOutAction2 is not very functional until it has
+ * correct zoomManager set by setZoomManager(ZoomManager manager).<br/>
+ * 
+ * setZoomManager(ZoomManager manager) can be used several times.
+ * 
+ * @author Ahti Kitsik
+ *
+ */
+public class ZoomOutAction2 extends ZoomOutAction {
+
+    final private static ZoomManager FAKE_ZOOM_MANAGER = new ZoomManager( (ScalableFigure) null,
+                                                                          null );
+
+    /**
+     * Default constructor to allow ZoomOutActions without specified
+     * ZoomManager.
+     */
+    public ZoomOutAction2() {
+        super( FAKE_ZOOM_MANAGER );
+    }
+
+    /**
+     * Replaces existing zoomManager with the new one.
+     * 
+     * Implementation is null-safe.
+     * 
+     * @param newManager new zoom manager
+     */
+    public void setZoomManager(ZoomManager manager) {
+
+        if ( zoomManager != null ) {
+            zoomManager.removeZoomListener( this );
+        }
+
+        zoomManager = manager;
+
+        if ( zoomManager != null ) {
+            zoomManager.addZoomListener( this );
+        }
+
+    }
+
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ZoomOutAction2.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteooLayoutFactory.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteooLayoutFactory.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteooLayoutFactory.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,155 @@
+package org.drools.ide.editors.rete;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.drools.ide.editors.rete.model.Connection;
+import org.drools.ide.editors.rete.model.ReteGraph;
+import org.drools.reteoo.BaseVertex;
+import org.eclipse.draw2d.geometry.Point;
+
+/**
+ * Factory methods for calculating and layouting reteoo graph
+ *
+ */
+public class ReteooLayoutFactory {
+
+    /**
+     * Calculates layouting for provided graph.
+     * 
+     * @param root graph root vertex
+     * 
+     * @return Optimally layouted rows from provided graph
+     */
+    public static RowList calculateReteRows(BaseVertex root) {
+        RowList rowList;
+        rowList = new RowList();
+
+        rowList.add( 0,
+                     root );
+
+        int curRow = 0;
+
+        final Set seenVertices = new HashSet();
+        seenVertices.add( root );
+
+        while ( curRow < rowList.getDepth() ) {
+            final List rowVertices = rowList.get( curRow ).getVertices();
+
+            for ( final Iterator rowNodeIter = rowVertices.iterator(); rowNodeIter.hasNext(); ) {
+                final BaseVertex rowNode = (BaseVertex) rowNodeIter.next();
+
+                final List edges = rowNode.getSourceConnections();
+
+                for ( final Iterator edgeIter = edges.iterator(); edgeIter.hasNext(); ) {
+
+                    final Connection edge = (Connection) edgeIter.next();
+                    final BaseVertex destNode = edge.getOpposite( rowNode );
+
+                    if ( !seenVertices.contains( destNode ) ) {
+                        rowList.add( curRow + 1,
+                                     destNode );
+                        seenVertices.add( destNode );
+                    }
+                }
+
+                seenVertices.add( rowNode );
+            }
+
+            ++curRow;
+        }
+
+        rowList.optimize();
+
+        return rowList;
+    }
+
+    /**
+     * Adds all vertices from rowList to the graph.
+     * 
+     * @param graph
+     * @param rowList
+     */
+    public static void layoutRowList(ReteGraph graph,
+                                     RowList rowList) {
+        new LayoutCalculator( graph,
+                              rowList );
+    }
+
+    private static class LayoutCalculator {
+
+        public final static String COORDS                = "drools.LayoutCalculator.coords";
+
+        private static final int   COLUMN_SPACE          = 40;
+        private static final int   ROW_HEIGHT_MULTIPLIER = 6;
+
+        private RowList            rowList;
+
+        private int                columnWidth;
+        private int                rowHeight;
+
+        private ReteGraph          graph;
+
+        private LayoutCalculator(final ReteGraph graph,
+                                final RowList rowList) {
+            this.graph = graph;
+            this.rowList = rowList;
+            computeSize();
+
+            List vertices = getGraph().getChildren();
+            Iterator iter = vertices.iterator();
+            while ( iter.hasNext() ) {
+                BaseVertex v = (BaseVertex) iter.next();
+                initialize_local_vertex( v );
+            }
+
+        }
+
+        private void computeSize() {
+            final List vertices = getGraph().getChildren();
+
+            for ( final Iterator vertexIter = vertices.iterator(); vertexIter.hasNext(); ) {
+                final BaseVertex vertex = (BaseVertex) vertexIter.next();
+
+                final int width = vertex.getSize().width;
+                final int height = vertex.getSize().height;
+
+                if ( width > this.columnWidth ) {
+                    this.columnWidth = width;
+                }
+
+                if ( height > this.rowHeight ) {
+                    this.rowHeight = height;
+                }
+            }
+
+            this.columnWidth = this.columnWidth + LayoutCalculator.COLUMN_SPACE;
+        }
+
+        private void initialize_local_vertex(final BaseVertex vertex) {
+            final int row = this.rowList.getRow( vertex );
+            final int col = this.rowList.getColumn( vertex );
+
+            final int rowWidth = this.rowList.getWidth( row );
+
+            final int columnWidthPx = columnWidth;
+            final int rowHeightPx = rowHeight;
+
+            double x = (col * columnWidthPx);
+            double y = (row * (rowHeightPx * LayoutCalculator.ROW_HEIGHT_MULTIPLIER));
+
+            x = x + (columnWidthPx / 2) - ((rowWidth - 1) * (columnWidthPx / 2));
+            y = y + (rowHeightPx / 2) + 3;
+
+            vertex.setLocation( new Point( x,
+                                           y ) );
+        }
+
+        private ReteGraph getGraph() {
+            return graph;
+        }
+    }
+
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteooLayoutFactory.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/Row.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/Row.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/Row.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,139 @@
+package org.drools.ide.editors.rete;
+
+/*
+ * Copyright 2006 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.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.drools.reteoo.BaseVertex;
+
+/**
+ * Represents one row in rete graph
+ *
+ */
+public class Row {
+
+    private final int depth;
+
+    //List<BaseVertex>
+    private List      vertices;
+
+    /**
+     * Default constructor.
+     * 
+     * @param depth row depth 
+     */
+    public Row(final int depth) {
+        super();
+        this.vertices = new ArrayList();
+        this.depth = depth;
+    }
+
+    /**
+     * Returns row depth
+     * 
+     * @return row depth
+     */
+    public int getDepth() {
+        return this.depth;
+    }
+
+    /**
+     * Adds new vertex to this row.
+     * 
+     * @param vertex new vertex to be added 
+     */
+    public void add(final BaseVertex vertex) {
+        this.vertices.add( vertex );
+    }
+
+    /**
+     * Returns all vertices from this row.
+     * 
+     * @return list of vertices with type BaseVertex
+     */
+    public List getVertices() {
+        return this.vertices;
+    }
+
+    /**
+     * @param vertex
+     * @return <code>true</code> if vertex is found in row. <code>false</code> otherwise.
+     */
+    public boolean contains(final BaseVertex vertex) {
+        return this.vertices.contains( vertex );
+    }
+
+    /**
+     * @return number of vertices in row 
+     */
+    public int getWidth() {
+        return this.vertices.size();
+    }
+
+    /**
+     * Optimizing vertices for optimal presentation
+     * 
+     */
+    public void optimize() {
+        final List sorted = new ArrayList( this.vertices );
+
+        Collections.sort( sorted,
+                          new Comparator() {
+                              public int compare(final Object o1,
+                                                 final Object o2) {
+                                  final BaseVertex v1 = (BaseVertex) o1;
+                                  final BaseVertex v2 = (BaseVertex) o2;
+
+                                  int v1OutDegree = v1.getSourceConnections().size();
+                                  int v2OutDegree = v2.getSourceConnections().size();
+
+                                  if ( v1OutDegree < v2OutDegree ) {
+                                      return 1;
+                                  }
+
+                                  if ( v1OutDegree > v2OutDegree ) {
+                                      return -1;
+                                  }
+
+                                  return 0;
+                              }
+                          } );
+
+        final LinkedList optimized = new LinkedList();
+
+        boolean front = false;
+
+        for ( final Iterator vertexIter = sorted.iterator(); vertexIter.hasNext(); ) {
+            final BaseVertex vertex = (BaseVertex) vertexIter.next();
+
+            if ( front ) {
+                optimized.addFirst( vertex );
+            } else {
+                optimized.addLast( vertex );
+            }
+
+            front = !front;
+        }
+
+        this.vertices = optimized;
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/Row.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/RowList.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/RowList.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/RowList.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,169 @@
+package org.drools.ide.editors.rete;
+
+/*
+ * Copyright 2006 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.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.reteoo.BaseVertex;
+
+/**
+ * Holder for Row elements.
+ * 
+ */
+public class RowList {
+
+    // List<Row>
+    private List rows;
+
+    /**
+     * Default constructor.
+     */
+    public RowList() {
+        super();
+        this.rows = new ArrayList();
+    }
+
+    /**
+     * Adds new vertex to specified depth
+     * 
+     * @param depth depth for vertex
+     * @param vertex vertex
+     */
+    public void add(final int depth,
+                    final BaseVertex vertex) {
+        if ( this.rows.size() < (depth + 1) ) {
+            final int addRows = depth - this.rows.size() + 1;
+
+            for ( int i = 0; i < addRows; ++i ) {
+                this.rows.add( new Row( (depth - addRows) + i ) );
+            }
+        }
+
+        ((Row) this.rows.get( depth )).add( vertex );
+    }
+
+    /**
+     * @return number of rows in RowList
+     */
+    public int getDepth() {
+        return this.rows.size();
+    }
+
+    /**
+     * @param row index of the row to be returned (0..n-1)
+     * @return specified row
+     */
+    public Row get(final int row) {
+        return (Row) this.rows.get( row );
+    }
+
+    /**
+     * Finds specified vertex from the rows.
+     * 
+     * @param vertex vertex
+     * 
+     * @return row number where vertex was found (0..n-1). <code>-1</code> if not found. 
+     */
+    public int getRow(final BaseVertex vertex) {
+        final int numRows = this.rows.size();
+
+        for ( int i = 0; i < numRows; ++i ) {
+            if ( ((Row) this.rows.get( i )).contains( vertex ) ) {
+                return i;
+            }
+        }
+
+        return -1;
+    }
+
+    /**
+     * Finds the longest row width.
+     * 
+     * @return width of the longest row
+     */
+    public int getWidth() {
+        int width = 0;
+
+        for ( final Iterator rowIter = this.rows.iterator(); rowIter.hasNext(); ) {
+            final Row row = (Row) rowIter.next();
+            final int rowWidth = row.getWidth();
+
+            if ( rowWidth > width ) {
+                width = rowWidth;
+            }
+        }
+
+        return width;
+    }
+
+    /**
+     * Width of the row at specified index.
+     * 
+     * @param row
+     * @return width
+     */
+    public int getWidth(final int row) {
+        return ((Row) this.rows.get( row )).getWidth();
+    }
+
+    /**
+     * @param vertex vertex to search
+     * @return column where vertex was found
+     */
+    public int getColumn(final BaseVertex vertex) {
+        final int row = getRow( vertex );
+
+        if ( row < 0 ) {
+            return -1;
+        }
+
+        final List rowVertices = get( row ).getVertices();
+
+        final int numCols = rowVertices.size();
+
+        for ( int i = 0; i < numCols; ++i ) {
+            if ( rowVertices.get( i ).equals( vertex ) ) {
+                return i;
+            }
+        }
+
+        return -1;
+    }
+
+    /**
+     * Dumps all row vertices to System.err
+     */
+    public void dump() {
+        final int numRows = this.rows.size();
+
+        for ( int i = 0; i < numRows; ++i ) {
+            System.err.println( i + ": " + get( i ).getVertices() );
+        }
+    }
+
+    /**
+     * Optimizes all rows for optimal presentation
+     */
+    public void optimize() {
+        final int numRows = this.rows.size();
+
+        for ( int i = 0; i < numRows; ++i ) {
+            get( i ).optimize();
+        }
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/RowList.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/commands/NodeSetConstraintCommand.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/commands/NodeSetConstraintCommand.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/commands/NodeSetConstraintCommand.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,79 @@
+package org.drools.ide.editors.rete.commands;
+
+import org.drools.reteoo.BaseVertex;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+
+/**
+ * A command to move a vertex.
+ * 
+ */
+public class NodeSetConstraintCommand extends Command {
+    
+    /** Stores the new size and location. */
+    private final Rectangle           newBounds;
+    
+    /** Stores the old size and location. */
+    private Rectangle                 oldBounds;
+    
+    /** A request to move/resize an edit part. */
+    private final ChangeBoundsRequest request;
+
+    /** BaseVertex to manipulate. */
+    private final BaseVertex              vertex;
+
+    /**
+     * Create a command that can resize and/or move a vertex.
+     *  
+     * @param vertex the vertex to manipulate
+     * @param req       the move request
+     * @param newBounds the new location. size is ignored
+     * @throws IllegalArgumentException if any of the parameters is null
+     */
+    public NodeSetConstraintCommand(BaseVertex vertex,
+                                    ChangeBoundsRequest req,
+                                    Rectangle newBounds) {
+        if ( vertex == null || req == null || newBounds == null ) {
+            throw new IllegalArgumentException();
+        }
+        this.vertex = vertex;
+        this.request = req;
+        this.newBounds = newBounds.getCopy();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.commands.Command#canExecute()
+     */
+    public boolean canExecute() {
+        Object type = request.getType();
+        return (RequestConstants.REQ_MOVE.equals( type ) || RequestConstants.REQ_MOVE_CHILDREN.equals( type ));
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.commands.Command#execute()
+     */
+    public void execute() {
+        oldBounds = new Rectangle( vertex.getLocation(),
+                                   vertex.getSize() );
+        redo();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.commands.Command#redo()
+     */
+    public void redo() {
+        vertex.setSize( newBounds.getSize() );
+        vertex.setLocation( newBounds.getLocation() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.commands.Command#undo()
+     */
+    public void undo() {
+        vertex.setSize( oldBounds.getSize() );
+        vertex.setLocation( oldBounds.getLocation() );
+    }
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/commands/NodeSetConstraintCommand.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/ConnectionFigure.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/ConnectionFigure.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/ConnectionFigure.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,20 @@
+package org.drools.ide.editors.rete.figure;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.swt.SWT;
+
+/**
+ * ConnectionFigure between two Vertices. 
+ *
+ */
+public class ConnectionFigure extends PolylineConnection {
+
+    /**
+     * Painting antialiased connector
+     */
+    public void paint(Graphics g) {
+        g.setAntialias( SWT.ON );
+        super.paint( g );
+    }
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/ConnectionFigure.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/VertexFigure.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/VertexFigure.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/VertexFigure.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,54 @@
+package org.drools.ide.editors.rete.figure;
+
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Figure representing BaseVertex
+ *
+ */
+public class VertexFigure extends Figure {
+
+    final private Color backgroundColor;
+    final private Color borderColor;
+
+    /**
+     * Initializing Figure
+     * 
+     * @param backgroundColor background color
+     * @param borderColor border color
+     */
+    public VertexFigure(Color backgroundColor,
+                        Color borderColor) {
+        this.backgroundColor = backgroundColor;
+        this.borderColor = borderColor;
+    }
+
+    /**
+     * Painting antialiased vertex
+     */
+    public void paint(Graphics g) {
+        g.setAntialias( SWT.ON );
+        Rectangle r = getBounds().getCopy();
+        g.translate( r.getLocation() );
+        g.setBackgroundColor( backgroundColor );
+        g.setForegroundColor( borderColor );
+        g.fillArc( 0,
+                   0,
+                   15,
+                   15,
+                   0,
+                   360 );
+        g.drawArc( 0,
+                   0,
+                   14,
+                   14,
+                   0,
+                   360 );
+        super.paint( g );
+    }
+
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/figure/VertexFigure.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/Connection.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/Connection.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/Connection.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,80 @@
+package org.drools.ide.editors.rete.model;
+
+import org.drools.reteoo.BaseVertex;
+
+/**
+ * A connection between two distinct vertices.
+ */
+public class Connection extends ModelElement {
+
+    private boolean isConnected;
+
+    private BaseVertex  source;
+
+    private BaseVertex  target;
+
+    /** 
+     * Creating a connection between two distinct vertices.
+     * 
+     * @param source a source endpoint
+     * @param target a target endpoint
+     * @throws IllegalArgumentException if any of the parameters are null or source == target
+     */
+    public Connection(BaseVertex source,
+                      BaseVertex target) {
+        this.source = source;
+        this.target = target;
+        source.addConnection( this );
+        target.addConnection( this );
+        isConnected = true;
+    }
+
+    /** 
+     * Disconnect this connection from the vertices it is attached to.
+     */
+    public void disconnect() {
+        if ( isConnected ) {
+            source.removeConnection( this );
+            target.removeConnection( this );
+            isConnected = false;
+        }
+    }
+
+    /**
+     * Returns the source endpoint of this connection.
+     * 
+     * @return BaseVertex vertex
+     */
+    public BaseVertex getSource() {
+        return source;
+    }
+
+    /**
+     * Returns the target endpoint of this connection.
+     * 
+     * @return BaseVertex vertex
+     */
+    public BaseVertex getTarget() {
+        return target;
+    }
+
+    /**
+     * Gets opposite of specified vertex.
+     * 
+     * Returning <code>null</code> if specified not does not belong into this connection.
+     * 
+     * @param vertex
+     * @return opposite of vertex
+     */
+    public BaseVertex getOpposite(BaseVertex vertex) {
+        // If null or not part of this connection
+        if ( vertex == null || (!vertex.equals( getSource() ) && !vertex.equals( getTarget() )) ) {
+            return null;
+        }
+        if ( vertex.equals( getSource() ) ) {
+            return getTarget();
+        }
+        return getSource();
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/Connection.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/GraphicalVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/GraphicalVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/GraphicalVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,282 @@
+package org.drools.ide.editors.rete.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.spi.FieldConstraint;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.TextPropertyDescriptor;
+
+/**
+ * Visual vertex representation for ReteGraph.
+ * 
+ * Base impl for all rete vertices.
+ * 
+ * Can be connected with another BaseVertex with a Connector.
+ * 
+ * @author Ahti Kitsik
+ * 
+ */
+abstract public class GraphicalVertex extends ModelElement {
+    
+    private static IPropertyDescriptor[] descriptors;
+
+    /** ID for the Height property value (used for by the corresponding property descriptor). */
+    private static final String          HEIGHT_PROP             = "BaseVertex.Height";
+
+    /** Property ID to use when the location of this shape is modified. */
+    public static final String           LOCATION_PROP           = "BaseVertex.Location";
+
+    /** Property ID to use then the size of this shape is modified. */
+    public static final String           SIZE_PROP               = "BaseVertex.Size";
+
+    /** Property ID to use when the list of outgoing connections is modified. */
+    public static final String           SOURCE_CONNECTIONS_PROP = "BaseVertex.SourceConn";
+
+    /** Property ID to use when the list of incoming connections is modified. */
+    public static final String           TARGET_CONNECTIONS_PROP = "BaseVertex.TargetConn";
+
+    /** ID for the Width property value (used for by the corresponding property descriptor). */
+    private static final String          WIDTH_PROP              = "BaseVertex.Width";
+
+    /** ID for the X property value (used for by the corresponding property descriptor).  */
+    private static final String          XPOS_PROP               = "BaseVertex.xPos";
+
+    /** ID for the Y property value (used for by the corresponding property descriptor).  */
+    private static final String          YPOS_PROP               = "BaseVertex.yPos";
+
+    /*
+     * Initializes the property descriptors array.
+     * @see #getPropertyDescriptors()
+     * @see #getPropertyValue(Object)
+     * @see #setPropertyValue(Object, Object)
+     */
+    static {
+        descriptors = new IPropertyDescriptor[]{new TextPropertyDescriptor( XPOS_PROP,
+                                                                            "X" ), // id and description pair
+            new TextPropertyDescriptor( YPOS_PROP,
+                                        "Y" ), new TextPropertyDescriptor( WIDTH_PROP,
+                                                                           "Width" ), new TextPropertyDescriptor( HEIGHT_PROP,
+                                                                                                                  "Height" ),};
+    } // static
+
+    /** Location of this vertex. */
+    private Point                        location                = new Point( 0,
+                                                                              0 );
+    /** Size of this vertex. */
+    private final static Dimension                    size                    = new Dimension( 16,
+                                                                                  16 );
+    /** List of outgoing Connections. */
+    private List                         sourceConnections       = new ArrayList();
+    /** List of incoming Connections. */
+    private List                         targetConnections       = new ArrayList();
+
+
+    /**
+     * HTML formatted representation of this node
+     * 
+     * @return #getHtml
+     */
+    abstract public String getHtml();
+    
+    /**
+     * Color used for filling vertex figure
+     * 
+     * @return color
+     */
+    abstract public Color getFillColor();
+
+    /**
+     * Add an incoming or outgoing connection to this vertex.
+     * @param conn a non-null connection instance
+     * @throws IllegalArgumentException if the connection is null or has not distinct endpoints
+     */
+    public void addConnection(Connection conn) {
+        if ( conn == null || conn.getSource() == conn.getTarget() ) {
+            throw new IllegalArgumentException();
+        }
+        if ( conn.getSource() == this ) {
+            sourceConnections.add( conn );
+            firePropertyChange( SOURCE_CONNECTIONS_PROP,
+                                null,
+                                conn );
+        } else if ( conn.getTarget() == this ) {
+            targetConnections.add( conn );
+            firePropertyChange( TARGET_CONNECTIONS_PROP,
+                                null,
+                                conn );
+        }
+    }
+
+    /**
+     * Return the Location of this vertex.
+     * 
+     * @return a non-null copy of location instance
+     */
+    public Point getLocation() {
+        return location.getCopy();
+    }
+
+    /**
+     * Returns an array of IPropertyDescriptors for this vertex.
+     * 
+     */
+    public IPropertyDescriptor[] getPropertyDescriptors() {
+        return descriptors;
+    }
+
+    /**
+     * Return the property value for the given propertyId, or null.
+     */
+    public Object getPropertyValue(Object propertyId) {
+        if ( XPOS_PROP.equals( propertyId ) ) {
+            return Integer.toString( location.x );
+        }
+        if ( YPOS_PROP.equals( propertyId ) ) {
+            return Integer.toString( location.y );
+        }
+        if ( HEIGHT_PROP.equals( propertyId ) ) {
+            return Integer.toString( size.height );
+        }
+        if ( WIDTH_PROP.equals( propertyId ) ) {
+            return Integer.toString( size.width );
+        }
+        return null;
+    }
+
+    /**
+     * Return the Size of this vertex.
+     * @return a non-null copy of Dimension instance
+     */
+    public Dimension getSize() {
+        return size.getCopy();
+    }
+
+    /**
+     * Return a List of outgoing Connections.
+     */
+    public List getSourceConnections() {
+        return new ArrayList( sourceConnections );
+    }
+
+    /**
+     * Return a List of incoming Connections.
+     */
+    public List getTargetConnections() {
+        return new ArrayList( targetConnections );
+    }
+
+    /**
+     * Remove an incoming or outgoing connection from this vertex.
+     * 
+     * @param conn a non-null connection instance
+     * @throws IllegalArgumentException if the parameter is null
+     */
+    public void removeConnection(Connection conn) {
+        if ( conn == null ) {
+            throw new IllegalArgumentException();
+        }
+        if ( conn.getSource() == this ) {
+            sourceConnections.remove( conn );
+            firePropertyChange( SOURCE_CONNECTIONS_PROP,
+                                null,
+                                conn );
+        } else if ( conn.getTarget() == this ) {
+            targetConnections.remove( conn );
+            firePropertyChange( TARGET_CONNECTIONS_PROP,
+                                null,
+                                conn );
+        }
+    }
+
+    /**
+     * Set the Location of this vertex.
+     * @param newLocation a non-null Point instance
+     * @throws IllegalArgumentException if the parameter is null
+     */
+    public void setLocation(Point newLocation) {
+        if ( newLocation == null ) {
+            throw new IllegalArgumentException();
+        }
+        location.setLocation( newLocation );
+        firePropertyChange( LOCATION_PROP,
+                            null,
+                            location );
+    }
+
+    /**
+     * Set the property value for the given property id.
+     */
+    public void setPropertyValue(Object propertyId,
+                                 Object value) {
+        if ( XPOS_PROP.equals( propertyId ) ) {
+            int x = Integer.parseInt( (String) value );
+            setLocation( new Point( x,
+                                    location.y ) );
+        } else if ( YPOS_PROP.equals( propertyId ) ) {
+            int y = Integer.parseInt( (String) value );
+            setLocation( new Point( location.x,
+                                    y ) );
+        } else if ( HEIGHT_PROP.equals( propertyId ) ) {
+            int height = Integer.parseInt( (String) value );
+            setSize( new Dimension( size.width,
+                                    height ) );
+        } else if ( WIDTH_PROP.equals( propertyId ) ) {
+            int width = Integer.parseInt( (String) value );
+            setSize( new Dimension( width,
+                                    size.height ) );
+        }
+    }
+
+    /**
+     * Set the Size of this vertex.
+     * Will not modify the size if newSize is null.
+     * @param newSize a non-null Dimension instance or null
+     */
+    public void setSize(Dimension newSize) {
+        if ( newSize != null ) {
+            size.setSize( newSize );
+            firePropertyChange( SIZE_PROP,
+                                null,
+                                size );
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return "BaseVertex " + hashCode();
+    }
+
+    /**
+     * Color used for borders
+     * 
+     * @return draw color
+     */
+    public Color getDrawColor() {
+        return ColorConstants.black;
+    }
+
+    /**
+     * Constructs constraints string
+     * 
+     * @param constraints array of constraints 
+     * @return html-formatted constraints representation
+     */
+    public static String dumpConstraints(final FieldConstraint[] constraints) {
+        if ( constraints == null ) {
+            return null;
+        }
+        final StringBuffer buffer = new StringBuffer();
+        for ( int i = 0, length = constraints.length; i < length; i++ ) {
+            buffer.append( constraints[i].toString() + "<br>" );
+        }
+        return buffer.toString();
+    }
+ 
+}

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ModelElement.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ModelElement.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ModelElement.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,65 @@
+package org.drools.ide.editors.rete.model;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+
+/**
+ * Abstract prototype of a model element.
+ */
+public abstract class ModelElement
+    implements
+    Serializable {
+
+    /** Delegate used to implemenent property-change-support. */
+    private transient PropertyChangeSupport pcsDelegate = new PropertyChangeSupport( this );
+
+    /** 
+     * Attach a non-null PropertyChangeListener to this object.
+     * 
+     * @param l a non-null PropertyChangeListener instance
+     * @throws IllegalArgumentException if the parameter is null
+     */
+    public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
+        if ( l == null ) {
+            throw new IllegalArgumentException();
+        }
+        pcsDelegate.addPropertyChangeListener( l );
+    }
+
+    /** 
+     * Report a property change to registered listeners (for example edit parts).
+     * 
+     * @param property the programmatic name of the property that changed
+     * @param oldValue the old value of this property
+     * @param newValue the new value of this property
+     */
+    protected void firePropertyChange(String property,
+                                      Object oldValue,
+                                      Object newValue) {
+        if ( pcsDelegate.hasListeners( property ) ) {
+            pcsDelegate.firePropertyChange( property,
+                                            oldValue,
+                                            newValue );
+        }
+    }
+
+    /**
+     * Children should override this. The default implementation returns false.
+     */
+    public boolean isPropertySet(Object id) {
+        return false;
+    }
+
+    /** 
+     * Remove a PropertyChangeListener from this component.
+     * 
+     * @param l a PropertyChangeListener instance
+     */
+    public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
+        if ( l != null ) {
+            pcsDelegate.removePropertyChangeListener( l );
+        }
+    }
+
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ModelElement.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ReteGraph.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ReteGraph.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ReteGraph.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,80 @@
+package org.drools.ide.editors.rete.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.reteoo.BaseVertex;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+/**
+ * Rete graph containing a set of vertices that form the graph itself.
+ */
+public class ReteGraph extends ModelElement {
+
+    /** Property ID to use when a child is added to this diagram. */
+    public static final String PROP_CHILD_ADDED   = "ReteGraph.ChildAdded";
+
+    /** Property ID to use when a child is removed from this diagram. */
+    public static final String PROP_CHILD_REMOVED = "ReteGraph.ChildRemoved";
+
+    private List               vertices           = new ArrayList();
+
+    /** 
+     * Add new BaseVertex to the graph
+     * 
+     * @param vertex
+     * 
+     * @return true, if vertex was added, false otherwise
+     */
+    public boolean addChild(BaseVertex vertex) {
+        if ( vertex != null && vertices.add( vertex ) ) {
+            firePropertyChange( PROP_CHILD_ADDED,
+                                null,
+                                vertex );
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Return all Vertices in this graph
+     */
+    public List getChildren() {
+        return vertices;
+    }
+
+    /**
+     * Remove a vertex from this graph
+     * 
+     * @param vertex vertex to be removed
+     * @return true, if the vertex removal succeeded, false otherwise
+     */
+    public boolean removeChild(BaseVertex vertex) {
+        if ( vertex != null && vertices.remove( vertex ) ) {
+            firePropertyChange( PROP_CHILD_REMOVED,
+                                null,
+                                vertex );
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Removes all vertices from graph.
+     */
+    public void removeAll() {
+        while ( vertices.size() > 0 ) {
+            removeChild( ((BaseVertex) vertices.get( 0 )) );
+        }
+    }
+
+    /**
+     * Not implemented. Not required if graph editing functionality is not required.
+     * 
+     * @param event property change event
+     */
+    public void propertyChange(PropertyChangeEvent event) {
+        // Not relevant
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/ReteGraph.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/VertexPropertySource.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/VertexPropertySource.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/VertexPropertySource.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,396 @@
+package org.drools.ide.editors.rete.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.reteoo.AlphaNodeVertex;
+import org.drools.reteoo.BaseVertex;
+import org.drools.reteoo.EvalConditionNodeVertex;
+import org.drools.reteoo.JoinNodeVertex;
+import org.drools.reteoo.LeftInputAdapterNodeVertex;
+import org.drools.reteoo.NotNodeVertex;
+import org.drools.reteoo.ObjectTypeNodeVertex;
+import org.drools.reteoo.ReteVertex;
+import org.drools.reteoo.RightInputAdapterNodeVertex;
+import org.drools.reteoo.TerminalNodeVertex;
+import org.drools.spi.FieldConstraint;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+/**
+ * Providing IPropertySource for property sheets that show
+ * rete graph vertex properties.
+ * 
+ */
+public class VertexPropertySource
+    implements
+    IPropertySource {
+
+    public String                     ID_ROOT               = "vertex";                               //$NON-NLS-1$
+
+    public String                     ID_ID                 = "id";                                   //$NON-NLS-1$
+    public String                     ID_HTML               = "html";                                 //$NON-NLS-1$
+
+    private IPropertyDescriptor[]     descriptors;
+
+    private final IPropertyDescriptor PROP_NAME             = new PropertyDescriptor( "name",
+                                                                                      "Name" );
+    private final IPropertyDescriptor PROP_ID               = new PropertyDescriptor( "id",
+                                                                                      "ID" );
+    private final IPropertyDescriptor PROP_RULE             = new PropertyDescriptor( "rule",
+                                                                                      "Rule" );
+
+    // Alpha-specific
+    private final IPropertyDescriptor PROP_ALPHA_FIELD_NAME = new PropertyDescriptor( "fieldName",
+                                                                                      "Field Name" );
+    private final IPropertyDescriptor PROP_ALPHA_EVALUATOR  = new PropertyDescriptor( "evaluator",
+                                                                                      "Evaluator" );
+    private final IPropertyDescriptor PROP_ALPHA_VALUE      = new PropertyDescriptor( "value",
+                                                                                      "Value" );
+
+    // ObjectType specific
+    private final IPropertyDescriptor PROP_OBJ_TYPE         = new PropertyDescriptor( "objectType",
+                                                                                      "Object Type" );
+
+    private final static String       CAT_GENERAL           = "General";
+    private final static String       CAT_OTHER             = "Other";
+
+    protected BaseVertex                  vertex                = null;
+
+    // Map<String,NodeValue>
+    private Map                       values                = new HashMap();
+
+    /**
+     * Constructor initializing properties from <code>vertex</code>
+     * 
+     * @param vertex source vertex for this property source
+     */
+    public VertexPropertySource(BaseVertex vertex) {
+        this.vertex = vertex;
+
+        initProperties( vertex );
+    }
+
+    final private void initProperties(BaseVertex vertex) {
+
+        List descriptorList = new ArrayList();
+
+        if ( vertex instanceof TerminalNodeVertex ) {
+            initTerminalNodeProperties( (TerminalNodeVertex) vertex,
+                                        descriptorList,
+                                        values );
+        } else if ( vertex instanceof EvalConditionNodeVertex ) {
+            initEvalConditionNodeProperties( (EvalConditionNodeVertex) vertex,
+                                             descriptorList,
+                                             values );
+        } else if ( vertex instanceof NotNodeVertex ) {
+            initNotNodeProperties( (NotNodeVertex) vertex,
+                                   descriptorList,
+                                   values );
+        } else if ( vertex instanceof JoinNodeVertex ) {
+            initJoinNodeProperties( (JoinNodeVertex) vertex,
+                                    descriptorList,
+                                    values );
+        } else if ( vertex instanceof RightInputAdapterNodeVertex ) {
+            initRightInputAdapterNodeProperties( (RightInputAdapterNodeVertex) vertex,
+                                                 descriptorList,
+                                                 values );
+        } else if ( vertex instanceof LeftInputAdapterNodeVertex ) {
+            initLeftInputAdapterNodeProperties( (LeftInputAdapterNodeVertex) vertex,
+                                                descriptorList,
+                                                values );
+        } else if ( vertex instanceof AlphaNodeVertex ) {
+            initAlphaNodeProperties( (AlphaNodeVertex) vertex,
+                                     descriptorList,
+                                     values );
+        } else if ( vertex instanceof ObjectTypeNodeVertex ) {
+            initObjectTypeNodeProperties( (ObjectTypeNodeVertex) vertex,
+                                          descriptorList,
+                                          values );
+        } else if ( vertex instanceof ReteVertex ) {
+            initReteNodeProperties( (ReteVertex) vertex,
+                                    descriptorList,
+                                    values );
+        }
+
+        descriptors = (IPropertyDescriptor[]) descriptorList.toArray( new IPropertyDescriptor[0] );
+    }
+
+    private void initReteNodeProperties(ReteVertex vertex,
+                                        List descriptorList,
+                                        Map valueMap) {
+        addProperty( PROP_NAME,
+                     "Rete BaseVertex",
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ID,
+                     Integer.toString( vertex.getId() ),
+                     descriptorList,
+                     valueMap );
+    }
+
+    private void initObjectTypeNodeProperties(ObjectTypeNodeVertex vertex,
+                                              List descriptorList,
+                                              Map valueMap) {
+        addProperty( PROP_NAME,
+                     "Object Type BaseVertex",
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_OBJ_TYPE,
+                     vertex.getObjectType(),
+                     descriptorList,
+                     valueMap );
+
+    }
+
+    private void initAlphaNodeProperties(AlphaNodeVertex vertex,
+                                         List descriptorList,
+                                         Map valueMap) {
+        addProperty( PROP_NAME,
+                     "Alpha BaseVertex",
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ALPHA_FIELD_NAME,
+                     vertex.getFieldName(),
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ALPHA_EVALUATOR,
+                     vertex.getEvaluator(),
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ALPHA_VALUE,
+                     vertex.getValue(),
+                     descriptorList,
+                     valueMap );
+
+        FieldConstraint constraint = vertex.getConstraint();
+        if ( constraint == null ) {
+            return;
+        }
+        IPropertyDescriptor prop = new PropertyDescriptor( "constraint",
+                                                           "Constraint" );
+        addProperty( prop,
+                     constraint.toString(),
+                     descriptorList,
+                     valueMap );
+
+    }
+
+    private void initLeftInputAdapterNodeProperties(LeftInputAdapterNodeVertex vertex,
+                                                    List descriptorList,
+                                                    Map valueMap) {
+        addProperty( PROP_NAME,
+                     "Left Input Adapter BaseVertex",
+                     descriptorList,
+                     valueMap );
+
+        FieldConstraint[] constraints = vertex.getConstraints();
+        if ( constraints == null ) {
+            return;
+        }
+        for ( int i = 0, length = constraints.length; i < length; i++ ) {
+            PropertyDescriptor prop = new PropertyDescriptor( "constraint" + (i + 1),
+                                                              "Constraint " + (i + 1) );
+            addOther( prop,
+                      constraints[i].toString(),
+                      descriptorList,
+                      valueMap );
+        }
+
+    }
+
+    private void initRightInputAdapterNodeProperties(RightInputAdapterNodeVertex vertex,
+                                                     List descriptorList,
+                                                     Map valueMap) {
+        addProperty( PROP_NAME,
+                     "Right Input Adapter BaseVertex",
+                     descriptorList,
+                     valueMap );
+    }
+
+    private void initJoinNodeProperties(JoinNodeVertex vertex,
+                                        List descriptorList,
+                                        Map valueMap) {
+
+        addProperty( PROP_NAME,
+                     "Join BaseVertex",
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ID,
+                     Integer.toString( vertex.getId() ),
+                     descriptorList,
+                     valueMap );
+
+        FieldConstraint[] constraints = vertex.getConstraints();
+
+        if ( constraints == null ) {
+            return;
+        }
+
+        for ( int i = 0, length = constraints.length; i < length; i++ ) {
+            PropertyDescriptor prop = new PropertyDescriptor( "constraint" + (i + 1),
+                                                              "Constraint " + (i + 1) );
+            addOther( prop,
+                      constraints[i].toString(),
+                      descriptorList,
+                      valueMap );
+        }
+
+    }
+
+    private void initNotNodeProperties(NotNodeVertex vertex,
+                                       List descriptorList,
+                                       Map valueMap) {
+        addProperty( PROP_NAME,
+                     "Not BaseVertex",
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ID,
+                     Integer.toString( vertex.getId() ),
+                     descriptorList,
+                     valueMap );
+    }
+
+    private void initEvalConditionNodeProperties(EvalConditionNodeVertex vertex,
+                                                 List descriptorList,
+                                                 Map valueMap) {
+        addProperty( PROP_NAME,
+                     "Eval Condition BaseVertex",
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ID,
+                     Integer.toString( vertex.getId() ),
+                     descriptorList,
+                     valueMap );
+    }
+
+    private void initTerminalNodeProperties(TerminalNodeVertex node,
+                                            List descriptorList,
+                                            Map valueMap) {
+
+        addProperty( PROP_NAME,
+                     "Terminal BaseVertex",
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_ID,
+                     Integer.toString( node.getId() ),
+                     descriptorList,
+                     valueMap );
+        addProperty( PROP_RULE,
+                     node.getRuleName(),
+                     descriptorList,
+                     valueMap );
+
+    }
+
+    private void addProperty(IPropertyDescriptor field,
+                             String value,
+                             List descriptorList,
+                             Map valueMap) {
+        descriptorList.add( field );
+        valueMap.put( field.getId().toString(),
+                      new NodeValue( CAT_GENERAL,
+                                     value ) );
+        if ( field instanceof PropertyDescriptor ) {
+            ((PropertyDescriptor) field).setAlwaysIncompatible( true );
+            ((PropertyDescriptor) field).setCategory( CAT_GENERAL );
+        }
+        
+    }
+
+    private void addOther(IPropertyDescriptor field,
+                          String value,
+                          List descriptorList,
+                          Map valueMap) {
+        descriptorList.add( field );
+        valueMap.put( field.getId().toString(),
+                      new NodeValue( CAT_OTHER,
+                                     value ) );
+
+        if ( field instanceof PropertyDescriptor ) {
+            ((PropertyDescriptor) field).setAlwaysIncompatible( true );
+            ((PropertyDescriptor) field).setCategory( CAT_OTHER );
+        }
+        
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
+     */
+    public Object getEditableValue() {
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
+     */
+    public Object getPropertyValue(Object propName) {
+        return getPropertyValue( (String) propName );
+    }
+
+    /**
+     * Property value.
+     * 
+     * @param propName
+     * @return
+     */
+    public Object getPropertyValue(String propName) {
+        return ((NodeValue) (values.get( propName ))).value;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
+     */
+    public void setPropertyValue(Object propName,
+                                 Object value) {
+        setPropertyValue( (String) propName,
+                          value );
+    }
+
+    /**
+     * Doing nothing as changing properties from property sheet is not possible.
+     * 
+     * @param propName
+     * @param value
+     */
+    public void setPropertyValue(String propName,
+                                 Object value) {
+        // Can't be changed
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
+     */
+    public IPropertyDescriptor[] getPropertyDescriptors() {
+        return descriptors;
+    }
+
+    /**
+     * Doing nothing as resetting properties from property sheet is not possible.
+     */
+    public void resetPropertyValue(Object propName) {
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
+     */
+    public boolean isPropertySet(Object propName) {
+        return values.containsKey( propName );
+    }
+
+    private class NodeValue {
+        final String category;
+        final String value;
+
+        NodeValue(String category,
+                  String value) {
+            this.category = category;
+            this.value = value;
+        }
+    }
+
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/model/VertexPropertySource.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/ConnectionEditPart.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/ConnectionEditPart.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/ConnectionEditPart.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2006 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.
+ */
+package org.drools.ide.editors.rete.part;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import org.drools.ide.editors.rete.figure.ConnectionFigure;
+import org.drools.ide.editors.rete.model.ModelElement;
+import org.eclipse.draw2d.BendpointConnectionRouter;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.draw2d.PolylineDecoration;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
+
+/**
+ * Edit part for Connection model elements.
+ */
+class ConnectionEditPart extends AbstractConnectionEditPart
+    implements
+    PropertyChangeListener {
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#activate()
+     */
+    public void activate() {
+        if ( !isActive() ) {
+            super.activate();
+            ((ModelElement) getModel()).addPropertyChangeListener( this );
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
+     */
+    protected void createEditPolicies() {
+        installEditPolicy( EditPolicy.CONNECTION_ENDPOINTS_ROLE,
+                           new ConnectionEndpointEditPolicy() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
+     */
+    protected IFigure createFigure() {
+        PolylineConnection connection = new ConnectionFigure();
+        PolylineDecoration decoration = new PolylineDecoration();
+        connection.setTargetDecoration( decoration );
+        BendpointConnectionRouter router = new BendpointConnectionRouter();
+        connection.setConnectionRouter( router );
+        return connection;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#deactivate()
+     */
+    public void deactivate() {
+        if ( isActive() ) {
+            super.deactivate();
+            ((ModelElement) getModel()).removePropertyChangeListener( this );
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+     */
+    public void propertyChange(PropertyChangeEvent evt) {
+        // Doing nothing   
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/ConnectionEditPart.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/DiagramEditPart.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/DiagramEditPart.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/DiagramEditPart.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2006 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.
+ */
+package org.drools.ide.editors.rete.part;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.List;
+
+import org.drools.ide.editors.rete.commands.NodeSetConstraintCommand;
+import org.drools.ide.editors.rete.model.ModelElement;
+import org.drools.ide.editors.rete.model.ReteGraph;
+import org.drools.reteoo.BaseVertex;
+import org.eclipse.draw2d.ConnectionLayer;
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.FreeformLayer;
+import org.eclipse.draw2d.FreeformLayout;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.ShortestPathConnectionRouter;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.NodeEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
+import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.requests.CreateRequest;
+
+/**
+ * EditPart for ReteGraph
+ * 
+ */
+class DiagramEditPart extends AbstractGraphicalEditPart
+    implements
+    PropertyChangeListener {
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#activate()
+     */
+    public void activate() {
+        if ( !isActive() ) {
+            super.activate();
+            ((ModelElement) getModel()).addPropertyChangeListener( this );
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
+     */
+    protected void createEditPolicies() {
+        installEditPolicy( EditPolicy.COMPONENT_ROLE,
+                           new RootComponentEditPolicy() );
+        installEditPolicy( EditPolicy.LAYOUT_ROLE,
+                           new NodesXYLayoutEditPolicy() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
+     */
+    protected IFigure createFigure() {
+        Figure f = new FreeformLayer();
+        f.setBorder( new MarginBorder( 3 ) );
+        f.setLayoutManager( new FreeformLayout() );
+
+        ConnectionLayer connLayer = (ConnectionLayer) getLayer( LayerConstants.CONNECTION_LAYER );
+        connLayer.setConnectionRouter( new ShortestPathConnectionRouter( f ) );
+        return f;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#deactivate()
+     */
+    public void deactivate() {
+        if ( isActive() ) {
+            super.deactivate();
+            ((ModelElement) getModel()).removePropertyChangeListener( this );
+        }
+    }
+
+    private ReteGraph getCastedModel() {
+        return (ReteGraph) getModel();
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
+     */
+    protected List getModelChildren() {
+        return getCastedModel().getChildren(); // return a list of nodes
+    }
+
+    /* (non-Javadoc)
+     * @see java.beans.PropertyChangeListener#propertyChange(PropertyChangeEvent)
+     */
+    public void propertyChange(PropertyChangeEvent evt) {
+        String prop = evt.getPropertyName();
+        if ( ReteGraph.PROP_CHILD_ADDED.equals( prop ) || ReteGraph.PROP_CHILD_REMOVED.equals( prop ) ) {
+            refreshChildren();
+        }
+    }
+
+    private static class NodesXYLayoutEditPolicy extends XYLayoutEditPolicy {
+
+        /* (non-Javadoc)
+         * @see ConstrainedLayoutEditPolicy#createChangeConstraintCommand(ChangeBoundsRequest, EditPart, Object)
+         */
+        protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
+                                                        EditPart child,
+                                                        Object constraint) {
+            if ( child instanceof NodeEditPart && constraint instanceof Rectangle ) {
+                // return a command that can move and/or resize a BaseVertex
+                return new NodeSetConstraintCommand( (BaseVertex) child.getModel(),
+                                                     request,
+                                                     (Rectangle) constraint );
+            }
+            return super.createChangeConstraintCommand( request,
+                                                        child,
+                                                        constraint );
+        }
+
+        /* (non-Javadoc)
+         * @see ConstrainedLayoutEditPolicy#createChangeConstraintCommand(EditPart, Object)
+         */
+        protected Command createChangeConstraintCommand(EditPart child,
+                                                        Object constraint) {
+            return null;
+        }
+
+        /* (non-Javadoc)
+         * @see LayoutEditPolicy#getCreateCommand(CreateRequest)
+         */
+        protected Command getCreateCommand(CreateRequest request) {
+            return null;
+        }
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getAdapter(java.lang.Class)
+     */
+    public Object getAdapter(Class key) {
+        return super.getAdapter( key );
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/DiagramEditPart.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPart.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPart.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPart.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,167 @@
+package org.drools.ide.editors.rete.part;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.List;
+
+import org.drools.ide.editors.rete.figure.VertexFigure;
+import org.drools.ide.editors.rete.model.GraphicalVertex;
+import org.drools.ide.editors.rete.model.ModelElement;
+import org.drools.ide.editors.rete.model.VertexPropertySource;
+import org.drools.reteoo.BaseVertex;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.EllipseAnchor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.ui.views.properties.IPropertySource;
+
+/**
+ * EditPart used for Vertices
+ */
+class VertexEditPart extends AbstractGraphicalEditPart
+    implements
+    PropertyChangeListener,
+    org.eclipse.gef.NodeEditPart {
+
+    private IPropertySource  propertySource;
+
+    private ConnectionAnchor anchor;
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#activate()
+     */
+    public void activate() {
+        if ( !isActive() ) {
+            super.activate();
+            ((ModelElement) getModel()).addPropertyChangeListener( this );
+            propertySource = new VertexPropertySource( getCastedModel() );
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
+     */
+    protected void createEditPolicies() {
+    }
+
+    /*(non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
+     */
+    protected IFigure createFigure() {
+        return new VertexFigure( getCastedModel().getFillColor(),
+                                 getCastedModel().getDrawColor());
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#deactivate()
+     */
+    public void deactivate() {
+        if ( isActive() ) {
+            super.deactivate();
+            ((ModelElement) getModel()).removePropertyChangeListener( this );
+            propertySource = null;
+        }
+    }
+
+    private BaseVertex getCastedModel() {
+        return (BaseVertex) getModel();
+    }
+
+    private ConnectionAnchor getConnectionAnchor() {
+        if ( anchor == null ) {
+            if ( getModel() instanceof BaseVertex ) anchor = new EllipseAnchor( getFigure() );
+            else
+            // if Nodes gets extended the conditions above must be updated
+            throw new IllegalArgumentException( "unexpected model" );
+        }
+        return anchor;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelSourceConnections()
+     */
+    protected List getModelSourceConnections() {
+        return getCastedModel().getSourceConnections();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelTargetConnections()
+     */
+    protected List getModelTargetConnections() {
+        return getCastedModel().getTargetConnections();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
+     */
+    public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
+        return getConnectionAnchor();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request)
+     */
+    public ConnectionAnchor getSourceConnectionAnchor(Request request) {
+        return getConnectionAnchor();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
+     */
+    public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
+        return getConnectionAnchor();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request)
+     */
+    public ConnectionAnchor getTargetConnectionAnchor(Request request) {
+        return getConnectionAnchor();
+    }
+
+    /* (non-Javadoc)
+     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+     */
+    public void propertyChange(PropertyChangeEvent evt) {
+        String prop = evt.getPropertyName();
+        if ( GraphicalVertex.SIZE_PROP.equals( prop ) || GraphicalVertex.LOCATION_PROP.equals( prop ) ) {
+            refreshVisuals();
+        } else if ( GraphicalVertex.SOURCE_CONNECTIONS_PROP.equals( prop ) ) {
+            refreshSourceConnections();
+        } else if ( GraphicalVertex.TARGET_CONNECTIONS_PROP.equals( prop ) ) {
+            refreshTargetConnections();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals()
+     */
+    protected void refreshVisuals() {
+        Rectangle bounds = new Rectangle( getCastedModel().getLocation(),
+                                          getCastedModel().getSize() );
+        ((GraphicalEditPart) getParent()).setLayoutConstraint( this,
+                                                               getFigure(),
+                                                               bounds );
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getAdapter(java.lang.Class)
+     */
+    public Object getAdapter(Class key) {
+        if ( key == IPropertySource.class ) {
+            return propertySource;
+        }
+        return super.getAdapter( key );
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPart.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPartFactory.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPartFactory.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPartFactory.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,48 @@
+package org.drools.ide.editors.rete.part;
+
+import org.drools.ide.editors.rete.model.Connection;
+import org.drools.ide.editors.rete.model.ReteGraph;
+import org.drools.reteoo.BaseVertex;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartFactory;
+
+/**
+ * Factory mapping model elements to edit parts
+ */
+public class VertexEditPartFactory
+    implements
+    EditPartFactory {
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, java.lang.Object)
+     */
+    public EditPart createEditPart(EditPart context,
+                                   Object modelElement) {
+        // get EditPart for model element
+        EditPart part = getPartForElement( modelElement );
+        // store model element in EditPart
+        part.setModel( modelElement );
+        return part;
+    }
+
+    /**
+     * Maps object to EditPart.
+     *  
+     * @throws RuntimeException if no match was found
+     */
+    private EditPart getPartForElement(Object modelElement) {
+        if ( modelElement instanceof ReteGraph ) {
+            return new DiagramEditPart();
+        }
+        if ( modelElement instanceof BaseVertex ) {
+            return new VertexEditPart();
+        }
+        if ( modelElement instanceof Connection ) {
+            return new ConnectionEditPart();
+        }
+        //TODO Add logging and consider "return null"
+        throw new RuntimeException( "Can't create part for model element: " + ((modelElement != null) ? modelElement.getClass().getName() : "null") );
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/part/VertexEditPartFactory.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/AlphaNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/AlphaNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/AlphaNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,94 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.drools.base.ClassFieldExtractor;
+import org.drools.rule.LiteralConstraint;
+import org.drools.spi.FieldConstraint;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link AlphaNode} and adds visual extras like color information
+ *
+ */
+public class AlphaNodeVertex extends BaseVertex {
+
+    private final AlphaNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public AlphaNodeVertex(final AlphaNode node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        final LiteralConstraint constraint = (LiteralConstraint) this.node.getConstraint();
+        final ClassFieldExtractor extractor = (ClassFieldExtractor) constraint.getFieldExtractor();
+        return "AlphaNode<br>field : " + extractor.getFieldName() + "<br>evaluator : " + constraint.getEvaluator() + "<br>value :  " + constraint.getField();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return this.node.toString();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.blue;
+    }
+
+    /**
+     * Constraint has field extractor and this method is returning fieldName
+     * it.
+     * 
+     * @return field name
+     */
+    public String getFieldName() {
+        LiteralConstraint constraint = (LiteralConstraint) this.node.getConstraint();
+        ClassFieldExtractor extractor = (ClassFieldExtractor) constraint.getFieldExtractor();
+        return extractor.getFieldName();
+    }
+
+    /**
+     * Constraint's evaluator string
+     * 
+     * @return evaluator string
+     */
+    public String getEvaluator() {
+        LiteralConstraint constraint = (LiteralConstraint) this.node.getConstraint();
+        return constraint.getEvaluator().toString();
+    }
+
+    /**
+     * Constraint field string
+     * 
+     * @return field string
+     */
+    public String getValue() {
+        LiteralConstraint constraint = (LiteralConstraint) this.node.getConstraint();
+        return constraint.getField().toString();
+    }
+
+    /**
+     * Constraint
+     * 
+     * @return constraint
+     */
+    public FieldConstraint getConstraint() {
+        return this.node.getConstraint();
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/AlphaNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/BaseVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/BaseVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/BaseVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 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.
+ */
+package org.drools.reteoo;
+
+import org.drools.ide.editors.rete.model.GraphicalVertex;
+
+
+
+/**
+ * Intermediate class to have a workaround for *Node default visibility  
+ * and ReteooVisitor.
+ * 
+ * It's not good to have {@link GraphicalVertex} dependency in
+ * org.drools.reteoo package. 
+ * 
+ * @author Ahti Kitsik
+ *
+ */
+abstract public class BaseVertex extends GraphicalVertex {
+
+   
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/BaseVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/EvalConditionNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/EvalConditionNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/EvalConditionNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,55 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link EvalConditionNode} and adds visual extras like color information
+ *
+ */
+public class EvalConditionNodeVertex extends BaseVertex {
+    private final EvalConditionNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public EvalConditionNodeVertex(final EvalConditionNode node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        return "EvalConditionNode : " + this.node.getId();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return "EvalConditionNode";
+    }
+
+    /**
+     * Node ID
+     * 
+     * @return node id
+     */
+    public int getId() {
+        return node.getId();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.white;
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/EvalConditionNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/JoinNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/JoinNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/JoinNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,66 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.drools.spi.FieldConstraint;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link JoinNode} and adds visual extras like color information
+ *
+ */
+public class JoinNodeVertex extends BaseVertex {
+    private final JoinNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public JoinNodeVertex(final JoinNode node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        return "JoinNode<br> " + dumpConstraints( this.node.getConstraints() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return "JoinNode";
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.green;
+    }
+
+    /**
+     * Node constraints
+     * 
+     * @return array of constraints
+     */
+    public FieldConstraint[] getConstraints() {
+        return node.getConstraints();
+    }
+
+    /**
+     * Node ID
+     * 
+     * @return node id
+     */
+    public int getId() {
+        return node.getId();
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/JoinNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/LeftInputAdapterNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/LeftInputAdapterNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/LeftInputAdapterNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,56 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.drools.spi.FieldConstraint;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link LeftInputAdapterNode} and adds visual extras like color information
+ *
+ */
+public class LeftInputAdapterNodeVertex extends BaseVertex {
+    private final LeftInputAdapterNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public LeftInputAdapterNodeVertex(final LeftInputAdapterNode node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        return "LeftInputAdapterNode<br>" + dumpConstraints( this.node.getConstraints() );
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return this.node.toString();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.yellow;
+    }
+
+    /**
+     * Node constraints
+     * 
+     * @return array of node constraints
+     */
+    public FieldConstraint[] getConstraints() {
+        return node.getConstraints();
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/LeftInputAdapterNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/NotNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/NotNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/NotNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,56 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link NotNode} and adds visual extras like color information
+ *
+ */
+public class NotNodeVertex extends BaseVertex {
+    private final NotNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public NotNodeVertex(final NotNode node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        return "NotNode : " + this.node.getId();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return "NotNode";
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.cyan;
+    }
+
+    /**
+     * Node ID
+     * 
+     * @return node id
+     */
+    public int getId() {
+        return node.getId();
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/NotNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ObjectTypeNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ObjectTypeNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ObjectTypeNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,56 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.drools.spi.ObjectType;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link ObjectTypeNode} and adds visual extras like color information
+ *
+ */
+public class ObjectTypeNodeVertex extends BaseVertex {
+    private final ObjectTypeNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public ObjectTypeNodeVertex(final ObjectTypeNode node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        return "ObjectTypeNode : " + this.node.getObjectType();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return "ObjectTypeNode";
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.red;
+    }
+
+    /**
+     * {@link ObjectType} as {@link String}
+     * 
+     * @return object type as string
+     */
+    public String getObjectType() {
+        return node.getObjectType().toString();
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ObjectTypeNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,56 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link Rete} and adds visual extras like color information
+ *
+ */
+public class ReteVertex extends BaseVertex {
+    private final Rete node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public ReteVertex(final Rete node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        return "Rete : " + this.node.getId();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return "Rete";
+    }
+
+    /**
+     * Node ID
+     * 
+     * @return node id
+     */
+    public int getId() {
+        return node.getId();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.white;
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteooVisitor.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteooVisitor.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteooVisitor.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,132 @@
+package org.drools.reteoo;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.ide.editors.rete.model.Connection;
+import org.drools.ide.editors.rete.model.ReteGraph;
+import org.drools.util.ReflectiveVisitor;
+
+/**
+ * Produces a graph in GraphViz DOT format.
+ *
+ * @see http://www.research.att.com/sw/tools/graphviz/ 
+ * @see http://www.pixelglow.com/graphviz/
+ *
+ * @author Andy Barnett
+ */
+public class ReteooVisitor extends ReflectiveVisitor {
+
+    /**
+     * Keeps track of visited JoinNode DOT IDs. This mapping allows the visitor
+     * to recognize JoinNodes it has already visited and as a consequence link
+     * existing nodes back together. This is vital to the Visitor being able to
+     * link two JoinNodeInputs together through their common JoinNode.
+     */
+    private final Map           visitedNodes = new HashMap();
+
+    private ReteGraph               graph;
+
+    private BaseVertex              rootVertex;
+
+    private BaseVertex              parentVertex;
+
+    /**
+     * Constructor.
+     */
+    public ReteooVisitor(final ReteGraph graph) {
+        this.graph = graph;
+    }
+
+    public ReteGraph getGraph() {
+        return this.graph;
+    }
+
+    public BaseVertex getRootVertex() {
+        return this.rootVertex;
+    }
+
+    /**
+     * RuleBaseImpl visits its Rete.
+     */
+    public void visitReteooRuleBase(final ReteooRuleBase ruleBase) {
+        visit( (ruleBase).getRete() );
+    }
+
+    /**
+     * Rete visits each of its ObjectTypeNodes.
+     */
+    public void visitRete(final Rete rete) {
+        this.rootVertex = (ReteVertex) this.visitedNodes.get( dotId( rete ) );
+        if ( this.rootVertex == null ) {
+            this.rootVertex = new ReteVertex( rete );
+            this.visitedNodes.put( dotId( rete ),
+                                   this.rootVertex );
+        }
+
+        this.graph.addChild( this.rootVertex );
+        this.parentVertex = this.rootVertex;
+        for ( final Iterator i = rete.objectTypeNodeIterator(); i.hasNext(); ) {
+            final Object nextNode = i.next();
+            visitNode( nextNode );
+        }
+    }
+
+    public void visitBaseNode(final BaseNode node) {
+        BaseVertex vertex = (BaseVertex) this.visitedNodes.get( dotId( node ) );
+        if ( vertex == null ) {
+            try {
+                String name = node.getClass().getName();
+                name = name.substring( name.lastIndexOf( '.' ) + 1 ) + "Vertex";
+                final Class clazz = Class.forName( "org.drools.reteoo." + name );
+                vertex = (BaseVertex) clazz.getConstructor( new Class[]{node.getClass()} ).newInstance( new Object[]{node} );
+            } catch ( final Exception e ) {
+                throw new RuntimeException( "problem visiting vertex " + node.getClass().getName(),
+                                            e );
+            }
+            this.graph.addChild( vertex );
+            this.visitedNodes.put( dotId( node ),
+                                   vertex );
+            
+            new Connection(this.parentVertex,vertex);
+            
+            final BaseVertex oldParentVertex = this.parentVertex;
+            this.parentVertex = vertex;
+
+            List list = null;
+            if ( node instanceof ObjectSource ) {
+                list = ((ObjectSource) node).getObjectSinksAsList();
+            } else if ( node instanceof TupleSource ) {
+                list = ((TupleSource) node).getTupleSinks();
+            }
+
+            if ( list != null ) {
+                for ( final Iterator it = list.iterator(); it.hasNext(); ) {
+                    final Object nextNode = it.next();
+                    visitNode( nextNode );
+                }
+            }
+            this.parentVertex = oldParentVertex;
+        } else {
+            new Connection(this.parentVertex, vertex );
+        }
+    }
+
+    /**
+     * Helper method to ensure nodes are not visited more than once.
+     */
+    private void visitNode(final Object node) {
+        visit( node );
+    }
+
+    /**
+     * The identity hashCode for the given object is used as its unique DOT
+     * identifier.
+     */
+    private static String dotId(final Object object) {
+        return Integer.toHexString( System.identityHashCode( object ) ).toUpperCase();
+    }
+
+}


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/ReteooVisitor.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/RightInputAdapterNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/RightInputAdapterNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/RightInputAdapterNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,39 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link RightInputAdapterNode} and adds visual extras like color information
+ *
+ */
+public class RightInputAdapterNodeVertex extends BaseVertex {
+    
+    private final RightInputAdapterNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public RightInputAdapterNodeVertex(final RightInputAdapterNode node) {
+        super();
+        this.node = node;
+    }
+
+    public String getHtml() {
+        return "RightInputAdapterNode";
+    }
+
+    public String toString() {
+        return "RightInputAdapterNode";
+    }
+
+    public Color getFillColor() {
+        return ColorConstants.orange;
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/RightInputAdapterNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/TerminalNodeVertex.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/TerminalNodeVertex.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/TerminalNodeVertex.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,63 @@
+/**
+ * 
+ */
+package org.drools.reteoo;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Wraps {@link TerminalNode} and adds visual extras like color information
+ *
+ */
+public class TerminalNodeVertex extends BaseVertex {
+    private final TerminalNode node;
+
+    /**
+     * Constructor
+     * 
+     * @param node node to be wrapped
+     */
+    public TerminalNodeVertex(final TerminalNode node) {
+        super();
+        this.node = node;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getHtml()
+     */
+    public String getHtml() {
+        return "TerminalNode : " + this.node.getId() + " : " + this.node.getRule();
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.ide.editors.rete.model.BaseVertex#toString()
+     */
+    public String toString() {
+        return "TerminalNode";
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.reteoo.BaseNodeVertex#getFillColor()
+     */
+    public Color getFillColor() {
+        return ColorConstants.darkGray;
+    }
+
+    /**
+     * Node ID
+     * 
+     * @return id
+     */
+    public int getId() {
+        return this.node.getId();
+    }
+
+    /**
+     * @return
+     */
+    public String getRuleName() {
+        return node.getRule().getName();
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/reteoo/TerminalNodeVertex.java
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ReteooLayoutFactoryTest.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ReteooLayoutFactoryTest.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ReteooLayoutFactoryTest.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,209 @@
+package org.drools.ide.editors.rete;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.drools.PackageIntegrationException;
+import org.drools.RuleBase;
+import org.drools.compiler.DroolsParserException;
+import org.drools.ide.editors.rete.model.ReteGraph;
+import org.drools.reteoo.AlphaNodeVertex;
+import org.drools.reteoo.BaseVertex;
+import org.drools.reteoo.LeftInputAdapterNodeVertex;
+import org.drools.reteoo.ObjectTypeNodeVertex;
+import org.drools.reteoo.ReteVertex;
+import org.drools.reteoo.ReteooVisitor;
+import org.drools.reteoo.TerminalNodeVertex;
+
+/**
+ * 
+ * Integration-like tests
+ * 
+ * Testing {@link ReteooLayoutFactory}
+ * It is using following components:
+ * {@link Row},
+ * {@link RowList},
+ * org.drools.reteoo.*Vertex,
+ * org.drools.ide.editors.rete.model.*
+ * 
+ * @author Ahti Kitsik
+ *
+ */
+public class ReteooLayoutFactoryTest extends TestCase {
+
+    /**
+     * Constructor.
+     * 
+     * @param name case name
+     */
+    public ReteooLayoutFactoryTest(String name) {
+        super( name );
+    }
+
+    /**
+     * Test method for {@link org.drools.ide.editors.rete.ReteooLayoutFactory#calculateReteRows(org.drools.reteoo.BaseVertex)}.
+     * @throws IOException 
+     * @throws DroolsParserException 
+     * @throws PackageIntegrationException 
+     */
+    public final void testCalculateReteRows() throws IOException,
+                                             PackageIntegrationException,
+                                             DroolsParserException {
+        ReteGraph graph = new ReteGraph();
+        BaseVertex root = loadRete( graph );
+        final RowList rows = ReteooLayoutFactory.calculateReteRows( root );
+
+        int rownum = rows.getDepth();
+
+        assertEquals( 5,
+                      rownum );
+
+        int[] expectedDepths = new int[]{-1, 0, 1, 2, 3};
+        int[] expectedSizes = new int[]{1, 1, 2, 2, 2};
+
+        for ( int j = 0; j < rownum; j++ ) {
+            final Row row = rows.get( j );
+            final int rowDepth = row.getDepth();
+            assertEquals( expectedDepths[j],
+                          rowDepth );
+            assertEquals( expectedSizes[j],
+                          row.getVertices().size() );
+        }
+
+    }
+
+    /**
+     * Test method for {@link org.drools.ide.editors.rete.ReteooLayoutFactory#layoutRowList(org.drools.ide.editors.rete.model.ReteGraph, org.drools.ide.editors.rete.RowList)}.
+     * 
+     * @throws IOException 
+     * @throws DroolsParserException 
+     * @throws PackageIntegrationException 
+     */
+    public final void testLayoutRowList() throws PackageIntegrationException,
+                                         DroolsParserException,
+                                         IOException {
+        ReteGraph graph = new ReteGraph();
+        BaseVertex root = loadRete( graph );
+        final RowList rows = ReteooLayoutFactory.calculateReteRows( root );
+
+        ReteooLayoutFactory.layoutRowList( graph,
+                                           rows );
+
+        final List nodes = graph.getChildren();
+
+        BaseVertex[] yOrder = (BaseVertex[]) nodes.toArray( new BaseVertex[0] );
+        Arrays.sort( yOrder,
+                     new Comparator() {
+                         public int compare(Object o1,
+                                            Object o2) {
+                             BaseVertex v1 = (BaseVertex) o1;
+                             BaseVertex v2 = (BaseVertex) o2;
+                             int y1 = v1.getLocation().y;
+                             int y2 = v2.getLocation().y;
+                             return new Integer( y1 ).compareTo( new Integer( y2 ) );
+                         }
+
+                     } );
+
+        Class[] expectedTypes = new Class[]{ReteVertex.class, ObjectTypeNodeVertex.class, AlphaNodeVertex.class, AlphaNodeVertex.class, LeftInputAdapterNodeVertex.class, LeftInputAdapterNodeVertex.class, TerminalNodeVertex.class,
+                TerminalNodeVertex.class};
+
+        for ( int i = 0; i < yOrder.length; i++ ) {
+            assertEquals( expectedTypes[i],
+                          yOrder[i].getClass() );
+            if ( i > 0 ) {
+                // If current vertex has same type as previous then
+                // y-pos should match and x-pos should not match.                
+                // If type is different then y-pos should *not* match.
+
+                BaseVertex current = yOrder[i];
+                BaseVertex previous = yOrder[i - 1];
+                if ( current.getClass().equals( previous.getClass() ) ) {
+                    assertEquals( current.getLocation().y,
+                                  previous.getLocation().y );
+                    assertNotSame( new Integer( current.getLocation().x ),
+                                   new Integer( previous.getLocation().x ) );
+                } else {
+                    assertNotSame( new Integer( current.getLocation().y ),
+                                   new Integer( previous.getLocation().y ) );
+                }
+            }
+        }
+
+    }
+
+    private BaseVertex loadRete(ReteGraph graph) throws IOException,
+                                            DroolsParserException,
+                                            PackageIntegrationException {
+        final InputStream is = getClass().getClassLoader().getResourceAsStream( "simplerule.drl" );
+        String drl = streamToString( is );
+
+        final RuleBase ruleBase = ReteViewer.parseRuleBase( drl,
+                                                            null );
+
+        final ReteooVisitor visitor = new ReteooVisitor( graph );
+        visitor.visit( ruleBase );
+
+        BaseVertex root = visitor.getRootVertex();
+        return root;
+    }
+
+    private String streamToString(InputStream is) throws IOException {
+        byte[] buffer = new byte[4096];
+        OutputStream outputStream = new ByteArrayOutputStream();
+
+        while ( true ) {
+            int read = is.read( buffer );
+
+            if ( read == -1 ) {
+                break;
+            }
+
+            outputStream.write( buffer,
+                                0,
+                                read );
+        }
+
+        outputStream.close();
+        is.close();
+
+        return outputStream.toString();
+    }
+
+    /**
+     * Used by simplerule.drl
+     *
+     */
+    public static class Message {
+        public static final int HELLO   = 0;
+        public static final int GOODBYE = 1;
+
+        private String          message;
+
+        private int             status;
+
+        public String getMessage() {
+            return this.message;
+        }
+
+        public void setMessage(final String message) {
+            this.message = message;
+        }
+
+        public int getStatus() {
+            return this.status;
+        }
+
+        public void setStatus(final int status) {
+            this.status = status;
+        }
+    }
+
+}

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ZoomControlTest.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ZoomControlTest.java	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/test/java/org/drools/ide/editors/rete/ZoomControlTest.java	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,21 @@
+package org.drools.ide.editors.rete;
+
+import org.drools.ide.editors.DRLRuleEditor2;
+
+import junit.framework.TestCase;
+
+public class ZoomControlTest extends TestCase {
+
+    public ZoomControlTest(String name) {
+        super( name );
+    }
+
+    public void testMultipleEditors() {
+        DRLRuleEditor2 editor1 = new DRLRuleEditor2();
+        DRLRuleEditor2 editor2 = new DRLRuleEditor2();
+        
+        //TODO Implement proper test for multiple pages with zoom controls at rete tree
+        
+    }
+    
+}

Added: labs/jbossrules/branches/3.0.x/drools-ide/src/test/resources/simplerule.drl
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/test/resources/simplerule.drl	2006-10-18 00:10:53 UTC (rev 6879)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/test/resources/simplerule.drl	2006-10-18 00:11:09 UTC (rev 6880)
@@ -0,0 +1,24 @@
+package org.drools.examples
+
+// Rules for ReteooLayoutFactoryTest
+
+import org.drools.ide.editors.rete.ReteooLayoutFactoryTest.Message;
+
+rule "Hello World"
+        when
+                m : Message( status == Message.HELLO, message : message )
+        then
+                System.out.println( message );
+                m.setMessage( "Goodbye cruel world" );
+                m.setStatus( Message.GOODBYE );
+                modify( m );
+end
+
+rule "GoodBye"
+        no-loop true
+        when
+                m : Message( status == Message.GOODBYE, message : message )
+        then
+                System.out.println( message );
+                m.setMessage( message );
+end




More information about the jboss-svn-commits mailing list