[jboss-svn-commits] JBL Code SVN: r6878 - in labs/jbossrules/branches/3.0.x: drools-core/src/main/java/org/drools/reteoo drools-core/src/main/java/org/drools/visualize drools-ide/src/main/java/org/drools/ide drools-ide/src/main/java/org/drools/ide/editors drools-ide/src/main/java/org/drools/ide/editors/rete
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 17 20:09:25 EDT 2006
Author: ahtik
Date: 2006-10-17 20:09:04 -0400 (Tue, 17 Oct 2006)
New Revision: 6878
Added:
labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteViewer.java
Removed:
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewer.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewerPanel.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayoutSolver.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/Row.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/RowList.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexColorSet.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexFunctions.java
labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexLabelPaintFunction.java
labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java
Modified:
labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/DroolsIDEPlugin.java
labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor2.java
labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditorActionContributor.java
Log:
JBRULES-517: Port ReteOO viewer from Jung /Swing to GEF
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,385 +0,0 @@
-package org.drools.reteoo;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.awt.Color;
-import java.awt.Paint;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.drools.base.ClassFieldExtractor;
-import org.drools.rule.LiteralConstraint;
-import org.drools.spi.FieldConstraint;
-import org.drools.util.ReflectiveVisitor;
-import org.drools.visualize.ReteooJungViewer.DroolsVertex;
-
-import edu.uci.ics.jung.graph.Graph;
-import edu.uci.ics.jung.graph.Vertex;
-import edu.uci.ics.jung.graph.impl.DirectedSparseEdge;
-import edu.uci.ics.jung.graph.impl.DirectedSparseVertex;
-
-/**
- * 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 ReteooToJungVisitor extends ReflectiveVisitor {
- /** String displayed for Null values. */
- private static final String NULL_STRING = "<NULL>";
-
- /** Amount of indention for Node and Edge lines. */
- private static final String INDENT = " ";
-
- /**
- * 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 Graph graph;
-
- private Vertex rootVertex;
-
- private Vertex parentVertex;
-
- /**
- * Constructor.
- */
- public ReteooToJungVisitor(final Graph graph) {
- this.graph = graph;
- }
-
- public Graph getGraph() {
- return this.graph;
- }
-
- public Vertex 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 = (ReteNodeVertex) this.visitedNodes.get( dotId( rete ) );
- if ( this.rootVertex == null ) {
- this.rootVertex = new ReteNodeVertex( rete );
- this.visitedNodes.put( dotId( rete ),
- this.rootVertex );
- }
-
- this.graph.addVertex( 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) {
- Vertex vertex = (Vertex) 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.ReteooToJungVisitor$" + name );
- vertex = (Vertex) clazz.getConstructor( new Class[]{node.getClass()} ).newInstance( new Object[]{node} );
- } catch ( final Exception e ) {
- throw new RuntimeException( "problem visiting node " + node.getClass().getName(),
- e );
- }
- this.graph.addVertex( vertex );
- this.visitedNodes.put( dotId( node ),
- vertex );
- this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex,
- vertex ) );
- final Vertex 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 {
- this.graph.addEdge( new DroolsDirectedEdge( 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();
- }
-
- class DroolsDirectedEdge extends DirectedSparseEdge {
- public DroolsDirectedEdge(final Vertex v1,
- final Vertex v2) {
- super( v1,
- v2 );
- }
-
- // public String toString() {
- // return null;
- // }
- }
-
- static class ReteNodeVertex extends BaseNodeVertex {
- private final Rete node;
-
- public ReteNodeVertex(final Rete node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "Rete : " + this.node.getId();
- }
-
- public String toString() {
- return "Rete";
- }
- }
-
- static class ObjectTypeNodeVertex extends BaseNodeVertex {
- private final ObjectTypeNode node;
-
- public ObjectTypeNodeVertex(final ObjectTypeNode node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "ObjectTypeNode : " + this.node.getObjectType();
- }
-
- public String toString() {
- return "ObjectTypeNode";
- }
-
- public Paint getFillPaint() {
- return Color.RED;
- }
- }
-
- static class AlphaNodeVertex extends BaseNodeVertex {
- private final AlphaNode node;
-
- public AlphaNodeVertex(final AlphaNode node) {
- super();
- this.node = node;
- }
-
- 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();
- }
-
- public String toString() {
- return this.node.toString();
- }
-
- public Paint getFillPaint() {
- return Color.BLUE;
- }
- }
-
- static class LeftInputAdapterNodeVertex extends BaseNodeVertex {
- private final LeftInputAdapterNode node;
-
- public LeftInputAdapterNodeVertex(final LeftInputAdapterNode node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "LeftInputAdapterNode<br>" + dumpConstraints( this.node.getConstraints() );
- }
-
- public String toString() {
- return this.node.toString();
- }
-
- public Paint getFillPaint() {
- return Color.YELLOW;
- }
- }
-
- static class RightInputAdapterNodeVertex extends BaseNodeVertex {
- private final RightInputAdapterNode node;
-
- public RightInputAdapterNodeVertex(final RightInputAdapterNode node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "RightInputAdapterNode";
- }
-
- public String toString() {
- return "RightInputAdapterNode";
- }
-
- public Paint getFillPaint() {
- return Color.ORANGE;
- }
- }
-
- static class JoinNodeVertex extends BaseNodeVertex {
- private final JoinNode node;
-
- public JoinNodeVertex(final JoinNode node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "JoinNode<br> " + dumpConstraints( this.node.getConstraints() );
- }
-
- public String toString() {
- return "JoinNode";
- }
-
- public Paint getFillPaint() {
- return Color.GREEN;
- }
- }
-
- static class NotNodeVertex extends BaseNodeVertex {
- private final NotNode node;
-
- public NotNodeVertex(final NotNode node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "NotNode : " + this.node.getId();
- }
-
- public String toString() {
- return "NotNode";
- }
-
- public Paint getFillPaint() {
- return Color.CYAN;
- }
- }
-
- static class EvalConditionNodeVertex extends BaseNodeVertex {
- private final EvalConditionNode node;
-
- public EvalConditionNodeVertex(final EvalConditionNode node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "EvalConditionNode : " + this.node.getId();
- }
-
- public String toString() {
- return "EvalConditionNode";
- }
- }
-
- static class TerminalNodeVertex extends BaseNodeVertex {
- private final TerminalNode node;
-
- public TerminalNodeVertex(final TerminalNode node) {
- super();
- this.node = node;
- }
-
- public String getHtml() {
- return "TerminalNode : " + this.node.getId() + " : " + this.node.getRule();
- }
-
- public String toString() {
- return "TerminalNode";
- }
-
- public Paint getFillPaint() {
- return Color.DARK_GRAY;
- }
- }
-
- public static abstract class BaseNodeVertex extends DirectedSparseVertex
- implements
- DroolsVertex {
- public BaseNodeVertex() {
- super();
-
- }
-
- public String getHtml() {
- return this.getClass().getName().toString();
- }
-
- public Paint getFillPaint() {
- return Color.WHITE;
- }
-
- public Paint getDrawPaint() {
- return Color.BLACK;
- }
- }
-
- public static String dumpConstraints(final FieldConstraint[] constraints) {
- final StringBuffer buffer = new StringBuffer();
- for ( int i = 0, length = constraints.length; i < length; i++ ) {
- buffer.append( constraints[i].toString() + "<br>" );
- }
- return buffer.toString();
- }
-}
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewer.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewer.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewer.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,239 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.GridLayout;
-import java.awt.Paint;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JEditorPane;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
-
-import org.drools.RuleBase;
-import org.drools.reteoo.ReteooToJungVisitor;
-
-import edu.uci.ics.jung.graph.Graph;
-import edu.uci.ics.jung.graph.Vertex;
-import edu.uci.ics.jung.graph.decorators.ConstantVertexAspectRatioFunction;
-import edu.uci.ics.jung.graph.decorators.ConstantVertexSizeFunction;
-import edu.uci.ics.jung.graph.decorators.DefaultToolTipFunction;
-import edu.uci.ics.jung.graph.decorators.EdgeShape;
-import edu.uci.ics.jung.graph.decorators.EllipseVertexShapeFunction;
-import edu.uci.ics.jung.graph.decorators.PickableEdgePaintFunction;
-import edu.uci.ics.jung.graph.decorators.VertexPaintFunction;
-import edu.uci.ics.jung.graph.impl.DirectedSparseGraph;
-import edu.uci.ics.jung.visualization.DefaultGraphLabelRenderer;
-import edu.uci.ics.jung.visualization.GraphMouseListener;
-import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
-import edu.uci.ics.jung.visualization.Layout;
-import edu.uci.ics.jung.visualization.PluggableRenderer;
-import edu.uci.ics.jung.visualization.ShapePickSupport;
-import edu.uci.ics.jung.visualization.VisualizationViewer;
-import edu.uci.ics.jung.visualization.control.CrossoverScalingControl;
-import edu.uci.ics.jung.visualization.control.CrossoverScalingGraphMousePlugin;
-import edu.uci.ics.jung.visualization.control.PickingGraphMousePlugin;
-import edu.uci.ics.jung.visualization.control.PluggableGraphMouse;
-import edu.uci.ics.jung.visualization.control.RotatingGraphMousePlugin;
-import edu.uci.ics.jung.visualization.control.ScalingControl;
-import edu.uci.ics.jung.visualization.control.ViewScalingGraphMousePlugin;
-
-public class ReteooJungViewer extends JFrame {
-
- /**
- *
- */
- private static final long serialVersionUID = 7932462960592652709L;
-
- /**
- * the graph
- */
- Graph graph;
-
- /**
- * the visual component and renderer for the graph
- */
- VisualizationViewer vv;
-
- private boolean running = true;
-
- public ReteooJungViewer(final RuleBase ruleBase) {
- // Setup a standard left/right splitPane
- final JPanel leftPanel = new JPanel( new BorderLayout() );
- final JPanel rightPanel = new JPanel( new BorderLayout() );
- final JSplitPane splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
- leftPanel,
- rightPanel );
- splitPane.setDividerLocation( 0.75 );
- splitPane.setResizeWeight( 1 );
- getContentPane().add( splitPane );
-
- // Create the graph and parse it to the visitor where it will parse the rulebase and attach the vertices
- this.graph = new DirectedSparseGraph();
- final ReteooToJungVisitor visitor = new ReteooToJungVisitor( this.graph );
- visitor.visit( ruleBase );
-
- final PluggableRenderer pr = new PluggableRenderer();
-
- pr.setEdgeShapeFunction( new EdgeShape.QuadCurve() );
-
- pr.setVertexPaintFunction( new VertexPaintFunction() {
- public Paint getFillPaint(final Vertex v) {
- return ((DroolsVertex) v).getFillPaint();
- }
-
- public Paint getDrawPaint(final Vertex v) {
- return ((DroolsVertex) v).getDrawPaint();
- }
- } );
-
- pr.setEdgePaintFunction( new PickableEdgePaintFunction( pr,
- Color.black,
- Color.cyan ) );
- pr.setGraphLabelRenderer( new DefaultGraphLabelRenderer( Color.cyan,
- Color.cyan ) );
-
- // Sets the size of the nodes
- pr.setVertexShapeFunction( new EllipseVertexShapeFunction( new ConstantVertexSizeFunction( 14 ),
- new ConstantVertexAspectRatioFunction( 1.0f ) ) );
-
- final ReteooLayoutSolver solver = new ReteooLayoutSolver( visitor.getRootVertex() );
-
- final Layout layout = new ReteooLayout( this.graph,
- new VertexFunctions(),
- solver.getRowList() );
- /*
- Layout layout = new DAGLayout( this.graph );
- */
-
- this.vv = new VisualizationViewer( layout,
- pr,
- new Dimension( 800,
- 800 ) );
-
- this.vv.setBackground( Color.white );
- this.vv.setPickSupport( new ShapePickSupport() );
- this.vv.setToolTipFunction( new DefaultToolTipFunction() );
-
- final PluggableGraphMouse graphMouse = new PluggableGraphMouse();
- graphMouse.add( new PickingGraphMousePlugin() );
- graphMouse.add( new ViewScalingGraphMousePlugin() );
- graphMouse.add( new CrossoverScalingGraphMousePlugin() );
- graphMouse.add( new RotatingGraphMousePlugin() );
-
- this.vv.setGraphMouse( graphMouse );
-
- final ScalingControl scaler = new CrossoverScalingControl();
-
- final JButton plus = new JButton( "+" );
- plus.addActionListener( new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- scaler.scale( ReteooJungViewer.this.vv,
- 1.1f,
- ReteooJungViewer.this.vv.getCenter() );
- }
- } );
- final JButton minus = new JButton( "-" );
- minus.addActionListener( new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- scaler.scale( ReteooJungViewer.this.vv,
- 0.9f,
- ReteooJungViewer.this.vv.getCenter() );
- }
- } );
-
- final GraphZoomScrollPane graphPanel = new GraphZoomScrollPane( this.vv );
- leftPanel.add( graphPanel );
-
- // Add the zoom controls
- final JPanel scaleGrid = new JPanel( new GridLayout( 1,
- 0 ) );
- scaleGrid.setBorder( BorderFactory.createTitledBorder( "Zoom" ) );
- final JPanel controls = new JPanel();
- scaleGrid.add( plus );
- scaleGrid.add( minus );
- controls.add( scaleGrid );
- leftPanel.add( controls,
- BorderLayout.SOUTH );
-
- final JEditorPane infoPane = new JEditorPane();
- infoPane.setEditable( false );
- infoPane.setContentType( "text/html" );
-
- // Put the editor pane in a scroll pane.
- final JScrollPane infoScrollPane = new JScrollPane( infoPane );
- infoScrollPane.setPreferredSize( new Dimension( 250,
- 800 ) );
- infoScrollPane.setMinimumSize( new Dimension( 50,
- 800 ) );
-
- // Add a mouse listener to update the info panel when a node is clicked
- this.vv.addGraphMouseListener( new GraphMouseListener() {
-
- public void graphClicked(final Vertex vertex,
- final MouseEvent e) {
- infoPane.setText( ((DroolsVertex) vertex).getHtml() );
- }
-
- public void graphPressed(final Vertex vertex,
- final MouseEvent e) {
- }
-
- public void graphReleased(final Vertex vertex,
- final MouseEvent e) {
- }
-
- } );
-
- rightPanel.add( infoScrollPane );
- }
-
- public void showGUI() {
- pack();
- setVisible( true );
-
- addWindowListener( new WindowAdapter() {
- public void windowClosing(final WindowEvent e) {
- final ReteooJungViewer viewer = (ReteooJungViewer) e.getSource();
- viewer.running = false;
- }
- } );
- }
-
- public synchronized boolean isRunning() {
- return this.running;
- }
-
- public interface DroolsVertex {
- public String getHtml();
-
- public Paint getFillPaint();
-
- public Paint getDrawPaint();
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewerPanel.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewerPanel.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooJungViewerPanel.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,212 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.GridLayout;
-import java.awt.Paint;
-import java.awt.Rectangle;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JEditorPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
-
-import org.drools.RuleBase;
-import org.drools.reteoo.ReteooToJungVisitor;
-import org.drools.visualize.ReteooJungViewer.DroolsVertex;
-
-import edu.uci.ics.jung.graph.Graph;
-import edu.uci.ics.jung.graph.Vertex;
-import edu.uci.ics.jung.graph.decorators.ConstantVertexAspectRatioFunction;
-import edu.uci.ics.jung.graph.decorators.ConstantVertexSizeFunction;
-import edu.uci.ics.jung.graph.decorators.DefaultToolTipFunction;
-import edu.uci.ics.jung.graph.decorators.EdgeShape;
-import edu.uci.ics.jung.graph.decorators.EllipseVertexShapeFunction;
-import edu.uci.ics.jung.graph.decorators.PickableEdgePaintFunction;
-import edu.uci.ics.jung.graph.decorators.VertexPaintFunction;
-import edu.uci.ics.jung.graph.impl.DirectedSparseGraph;
-import edu.uci.ics.jung.visualization.DefaultGraphLabelRenderer;
-import edu.uci.ics.jung.visualization.GraphMouseListener;
-import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
-import edu.uci.ics.jung.visualization.Layout;
-import edu.uci.ics.jung.visualization.PluggableRenderer;
-import edu.uci.ics.jung.visualization.ShapePickSupport;
-import edu.uci.ics.jung.visualization.VisualizationViewer;
-import edu.uci.ics.jung.visualization.control.CrossoverScalingControl;
-import edu.uci.ics.jung.visualization.control.CrossoverScalingGraphMousePlugin;
-import edu.uci.ics.jung.visualization.control.PickingGraphMousePlugin;
-import edu.uci.ics.jung.visualization.control.PluggableGraphMouse;
-import edu.uci.ics.jung.visualization.control.RotatingGraphMousePlugin;
-import edu.uci.ics.jung.visualization.control.ScalingControl;
-import edu.uci.ics.jung.visualization.control.ViewScalingGraphMousePlugin;
-
-public class ReteooJungViewerPanel extends JPanel {
-
- private static final long serialVersionUID = 73294554831916314L;
-
- /**
- * the graph
- */
- private Graph graph;
-
- /**
- * the visual component and renderer for the graph
- */
- private VisualizationViewer vv;
-
- public ReteooJungViewerPanel(final RuleBase ruleBase) {
- setLayout( new BorderLayout() );
- // Setup a standard left/right splitPane
- final JPanel leftPanel = new JPanel( new BorderLayout() );
- final JPanel rightPanel = new JPanel( new BorderLayout() );
- final JSplitPane splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
- leftPanel,
- rightPanel );
- splitPane.setDividerLocation( 0.75 );
- splitPane.setResizeWeight( 1 );
- add( splitPane );
-
- // Create the graph and parse it to the visitor where it will parse the rulebase and attach the vertices
- this.graph = new DirectedSparseGraph();
- final ReteooToJungVisitor visitor = new ReteooToJungVisitor( this.graph );
- visitor.visit( ruleBase );
-
- final PluggableRenderer pr = new PluggableRenderer();
-
- pr.setEdgeShapeFunction( new EdgeShape.QuadCurve() );
-
- pr.setVertexPaintFunction( new VertexPaintFunction() {
- public Paint getFillPaint(final Vertex v) {
- return ((DroolsVertex) v).getFillPaint();
- }
-
- public Paint getDrawPaint(final Vertex v) {
- return ((DroolsVertex) v).getDrawPaint();
- }
- } );
-
- pr.setEdgePaintFunction( new PickableEdgePaintFunction( pr,
- Color.black,
- Color.cyan ) );
- pr.setGraphLabelRenderer( new DefaultGraphLabelRenderer( Color.cyan,
- Color.cyan ) );
-
- // Sets the size of the nodes
- pr.setVertexShapeFunction( new EllipseVertexShapeFunction( new ConstantVertexSizeFunction( 14 ),
- new ConstantVertexAspectRatioFunction( 1.0f ) ) );
-
- final ReteooLayoutSolver solver = new ReteooLayoutSolver( visitor.getRootVertex() );
-
- final Layout layout = new ReteooLayout( this.graph,
- new VertexFunctions(),
- solver.getRowList() );
- /*
- Layout layout = new DAGLayout( this.graph );
- */
-
- this.vv = new VisualizationViewer( layout,
- pr );
-
- this.vv.setBackground( Color.white );
- this.vv.setPickSupport( new ShapePickSupport() );
- this.vv.setToolTipFunction( new DefaultToolTipFunction() );
-
- final PluggableGraphMouse graphMouse = new PluggableGraphMouse();
- graphMouse.add( new PickingGraphMousePlugin() );
- graphMouse.add( new ViewScalingGraphMousePlugin() );
- graphMouse.add( new CrossoverScalingGraphMousePlugin() );
- graphMouse.add( new RotatingGraphMousePlugin() );
-
- this.vv.setGraphMouse( graphMouse );
-
- final ScalingControl scaler = new CrossoverScalingControl();
-
- final JButton plus = new JButton( "+" );
- plus.addActionListener( new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- scaler.scale( ReteooJungViewerPanel.this.vv,
- 1.1f,
- ReteooJungViewerPanel.this.vv.getCenter() );
- }
- } );
- final JButton minus = new JButton( "-" );
- minus.addActionListener( new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- scaler.scale( ReteooJungViewerPanel.this.vv,
- 0.9f,
- ReteooJungViewerPanel.this.vv.getCenter() );
- }
- } );
-
- final GraphZoomScrollPane graphPanel = new GraphZoomScrollPane( this.vv );
- graphPanel.scrollRectToVisible( new Rectangle( 1,
- 1,
- 1,
- 1 ) );
- leftPanel.add( graphPanel );
-
- // Add the zoom controls
- final JPanel scaleGrid = new JPanel( new GridLayout( 1,
- 0 ) );
- scaleGrid.setBorder( BorderFactory.createTitledBorder( "Zoom" ) );
- final JPanel controls = new JPanel();
- scaleGrid.add( plus );
- scaleGrid.add( minus );
- controls.add( scaleGrid );
- leftPanel.add( controls,
- BorderLayout.SOUTH );
-
- final JEditorPane infoPane = new JEditorPane();
- infoPane.setEditable( false );
- infoPane.setContentType( "text/html" );
-
- // Put the editor pane in a scroll pane.
- final JScrollPane infoScrollPane = new JScrollPane( infoPane );
- infoScrollPane.setPreferredSize( new Dimension( 150,
- 10 ) );
- infoScrollPane.setMinimumSize( new Dimension( 150,
- 10 ) );
-
- // Add a mouse listener to update the info panel when a node is clicked
- this.vv.addGraphMouseListener( new GraphMouseListener() {
-
- public void graphClicked(final Vertex vertex,
- final MouseEvent e) {
- infoPane.setText( ((DroolsVertex) vertex).getHtml() );
- }
-
- public void graphPressed(final Vertex vertex,
- final MouseEvent e) {
- }
-
- public void graphReleased(final Vertex vertex,
- final MouseEvent e) {
- }
-
- } );
-
- rightPanel.add( infoScrollPane );
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayout.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,152 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.Iterator;
-import java.util.Set;
-
-import edu.uci.ics.jung.graph.ArchetypeVertex;
-import edu.uci.ics.jung.graph.Graph;
-import edu.uci.ics.jung.graph.Vertex;
-import edu.uci.ics.jung.utils.UserDataContainer;
-import edu.uci.ics.jung.visualization.AbstractLayout;
-import edu.uci.ics.jung.visualization.Coordinates;
-
-public class ReteooLayout extends AbstractLayout {
-
- public final static String COORDS = "drools.ReteooLayout.coords";
-
- private static final int COLUMN_SPACE = 20;
- private static final int ROW_HEIGHT_MULTIPLIER = 3;
-
- private RowList rowList;
-
- private VertexFunctions vertexFunctions;
- private int columnWidth;
- private int rowHeight;
-
- public ReteooLayout(final Graph g,
- final VertexFunctions vertexFunctions,
- final RowList rowList) {
- super( g );
- this.vertexFunctions = vertexFunctions;
- this.rowList = rowList;
- computeSize();
- }
-
- public VertexFunctions getVertexFunctions() {
- return this.vertexFunctions;
- }
-
- public int getColumnWidth() {
- return this.columnWidth;
- }
-
- public int getRowHeight() {
- return this.rowHeight;
- }
-
- public int getPreferredWidth() {
- return this.rowList.getWidth() * this.columnWidth;
- }
-
- public int getPreferredHeight() {
- return this.rowList.getDepth() * getRowHeight() * ReteooLayout.ROW_HEIGHT_MULTIPLIER;
- }
-
- protected void computeSize() {
- final Set vertices = getGraph().getVertices();
-
- for ( final Iterator vertexIter = vertices.iterator(); vertexIter.hasNext(); ) {
- final Vertex vertex = (Vertex) vertexIter.next();
-
- final int width = this.vertexFunctions.getShapeDimension( vertex ).width;
- final int height = this.vertexFunctions.getShapeDimension( vertex ).height;
-
- if ( width > this.columnWidth ) {
- this.columnWidth = width;
- }
-
- if ( height > this.rowHeight ) {
- this.rowHeight = height;
- }
- }
-
- this.columnWidth = this.columnWidth + ReteooLayout.COLUMN_SPACE;
- }
-
- protected void initialize_local_vertex(final Vertex vertex) {
- final int row = this.rowList.getRow( vertex );
- final int col = this.rowList.getColumn( vertex );
-
- final int widthPx = this.getCurrentSize().width;
- final int heightPx = this.getCurrentSize().height;
-
- final int rowWidth = this.rowList.getWidth( row );
-
- final int columnWidthPx = getColumnWidth();
- final int rowHeightPx = getRowHeight();
-
- final Coordinates coords = new Coordinates();
-
- double x = (col * columnWidthPx);
- double y = (row * (rowHeightPx * ReteooLayout.ROW_HEIGHT_MULTIPLIER));
-
- x = x + (widthPx / 2) - ((rowWidth - 1) * (columnWidthPx / 2));
- y = y + (rowHeightPx / 2) + 3;
-
- coords.setX( x );
- coords.setY( y );
-
- //System.err.println( vertex + " -> " + coords.getX() + "," + coords.getY() + " / " + row + "," + col );
-
- vertex.setUserDatum( ReteooLayout.COORDS,
- coords,
- new UserDataContainer.CopyAction.Shared() );
- }
-
- public double getX(final Vertex vertex) {
- //System.err.println( "getX" );
- return getCoordinates( vertex ).getX();
- }
-
- public double getY(final Vertex vertex) {
- //System.err.println( "getY" );
- return getCoordinates( vertex ).getY();
- }
-
- public Coordinates getCoordinates(final ArchetypeVertex vertex) {
- //System.err.println( vertex + " --> " + (Coordinates) vertex.getUserDatum( COORDS ) );
- return (Coordinates) vertex.getUserDatum( ReteooLayout.COORDS );
- }
-
- public void advancePositions() {
- }
-
- public boolean isIncremental() {
- return false;
- }
-
- public boolean incrementsAreDone() {
- return false;
- }
-
- protected void initialize_local() {
- // nothing
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayoutSolver.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayoutSolver.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/ReteooLayoutSolver.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,83 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import edu.uci.ics.jung.graph.Edge;
-import edu.uci.ics.jung.graph.Vertex;
-
-public class ReteooLayoutSolver {
-
- private Vertex root;
-
- private RowList rowList;
-
- public ReteooLayoutSolver(final Vertex root) {
- this.root = root;
- solve();
- }
-
- protected void solve() {
- this.rowList = new RowList();
-
- this.rowList.add( 0,
- this.root );
-
- int curRow = 0;
-
- final Set seenVertices = new HashSet();
- seenVertices.add( this.root );
-
- while ( curRow < this.rowList.getDepth() ) {
- final List rowVertices = this.rowList.get( curRow ).getVertices();
-
- for ( final Iterator rowVertexIter = rowVertices.iterator(); rowVertexIter.hasNext(); ) {
- final Vertex rowVertex = (Vertex) rowVertexIter.next();
-
- final Set edges = rowVertex.getOutEdges();
-
- for ( final Iterator edgeIter = edges.iterator(); edgeIter.hasNext(); ) {
-
- final Edge edge = (Edge) edgeIter.next();
- final Vertex destVertex = edge.getOpposite( rowVertex );
-
- if ( !seenVertices.contains( destVertex ) ) {
- this.rowList.add( curRow + 1,
- destVertex );
- seenVertices.add( destVertex );
- }
- }
-
- seenVertices.add( rowVertex );
- }
-
- ++curRow;
- }
-
- this.rowList.optimize();
-
- this.rowList.dump();
- }
-
- public RowList getRowList() {
- return this.rowList;
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/Row.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/Row.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/Row.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,99 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import edu.uci.ics.jung.graph.Vertex;
-
-public class Row {
- private final int depth;
-
- private List /*Vertex*/vertices;
-
- public Row(final int depth) {
- super();
- this.vertices = new ArrayList();
- this.depth = depth;
- }
-
- public int getDepth() {
- return this.depth;
- }
-
- public void add(final Vertex vertex) {
- this.vertices.add( vertex );
- }
-
- public List /*Vertex*/getVertices() {
- return this.vertices;
- }
-
- public boolean contains(final Vertex vertex) {
- return this.vertices.contains( vertex );
- }
-
- public int getWidth() {
- return this.vertices.size();
- }
-
- 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 Vertex v1 = (Vertex) o1;
- final Vertex v2 = (Vertex) o2;
-
- if ( v1.outDegree() < v2.outDegree() ) {
- return 1;
- }
-
- if ( v1.outDegree() > v2.outDegree() ) {
- return -1;
- }
-
- return 0;
- }
- } );
-
- final LinkedList optimized = new LinkedList();
-
- boolean front = false;
-
- for ( final Iterator vertexIter = sorted.iterator(); vertexIter.hasNext(); ) {
- final Vertex vertex = (Vertex) vertexIter.next();
-
- if ( front ) {
- optimized.addFirst( vertex );
- } else {
- optimized.addLast( vertex );
- }
-
- front = !front;
- }
-
- this.vertices = optimized;
- }
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/RowList.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/RowList.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/RowList.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,121 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import edu.uci.ics.jung.graph.Vertex;
-
-public class RowList {
-
- private List /*Row*/rows;
-
- public RowList() {
- super();
- this.rows = new ArrayList();
- }
-
- public void add(final int depth,
- final Vertex 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 );
- }
-
- public int getDepth() {
- return this.rows.size();
- }
-
- public Row get(final int row) {
- return (Row) this.rows.get( row );
- }
-
- public int getRow(final Vertex 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;
- }
-
- 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;
- }
-
- public int getWidth(final int row) {
- return ((Row) this.rows.get( row )).getWidth();
- }
-
- public int getColumn(final Vertex 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;
- }
-
- public void dump() {
- final int numRows = this.rows.size();
-
- for ( int i = 0; i < numRows; ++i ) {
- System.err.println( i + ": " + get( i ).getVertices() );
- }
- }
-
- 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
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexColorSet.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexColorSet.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexColorSet.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,65 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.awt.Color;
-
-public class VertexColorSet {
-
- private Color fill;
- private Color stroke;
- private Color text;
-
- public VertexColorSet(final Color fill,
- final Color stroke,
- final Color text) {
- this.fill = fill;
- this.stroke = stroke;
- this.text = text;
- }
-
- public VertexColorSet() {
- this.fill = Color.white;
- this.stroke = Color.black;
- this.text = Color.black;
- }
-
- public Color getFill() {
- return this.fill;
- }
-
- public void setFill(final Color fill) {
- this.fill = fill;
- }
-
- public Color getStroke() {
- return this.stroke;
- }
-
- public void setStroke(final Color stroke) {
- this.stroke = stroke;
- }
-
- public Color getText() {
- return this.text;
- }
-
- public void setText(final Color text) {
- this.text = text;
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexFunctions.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexFunctions.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexFunctions.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,120 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics;
-import java.awt.Paint;
-import java.awt.Shape;
-import java.awt.geom.RoundRectangle2D;
-import java.awt.image.BufferedImage;
-
-import edu.uci.ics.jung.graph.ArchetypeVertex;
-import edu.uci.ics.jung.graph.Vertex;
-import edu.uci.ics.jung.graph.decorators.VertexFontFunction;
-import edu.uci.ics.jung.graph.decorators.VertexPaintFunction;
-import edu.uci.ics.jung.graph.decorators.VertexShapeFunction;
-import edu.uci.ics.jung.graph.decorators.VertexStringer;
-
-public class VertexFunctions
- implements
- VertexStringer,
- VertexFontFunction,
- VertexShapeFunction,
- VertexPaintFunction,
- VertexLabelPaintFunction {
- private VertexColorSet defaultColors;
-
- private Graphics graphics;
-
- private Font font;
-
- public VertexFunctions() {
- final BufferedImage image = new BufferedImage( 100,
- 100,
- BufferedImage.TYPE_INT_RGB );
- this.graphics = image.createGraphics();
- this.defaultColors = new VertexColorSet();
- this.font = new Font( "Verdana",
- Font.BOLD,
- 10 );
- }
-
- public void setDefaultColors(final Color fill,
- final Color stroke,
- final Color text) {
- this.defaultColors = new VertexColorSet( fill,
- stroke,
- text );
- }
-
- public void setFont(final Font font) {
- this.font = font;
- }
-
- public Paint getLabelDrawPaint(final Vertex vertex) {
- return this.defaultColors.getText();
- }
-
- public Font getFont(final Vertex vertex) {
- return this.font;
- }
-
- public Shape getShape(final Vertex vertex) {
- final Dimension dim = getShapeDimension( vertex );
-
- return new RoundRectangle2D.Double( 0 - (dim.width / 2),
- 0 - (dim.height / 2),
- dim.width,
- dim.height,
- 10,
- 10 );
- }
-
- public Dimension getShapeDimension(final Vertex vertex) {
- final String label = getLabel( vertex );
-
- final Font font = getFont( vertex );
-
- final FontMetrics fm = this.graphics.getFontMetrics( getFont( vertex ) );
-
- int width = fm.stringWidth( label );
- int height = fm.getHeight();
-
- width = (width + font.getSize());
- height = (height + font.getSize());
-
- return new Dimension( width,
- height );
- }
-
- public Paint getFillPaint(final Vertex vertex) {
- return this.defaultColors.getFill();
- }
-
- public Paint getDrawPaint(final Vertex vertex) {
- return this.defaultColors.getStroke();
- }
-
- public String getLabel(final ArchetypeVertex vertex) {
- return "node";
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexLabelPaintFunction.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexLabelPaintFunction.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-core/src/main/java/org/drools/visualize/VertexLabelPaintFunction.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,25 +0,0 @@
-package org.drools.visualize;
-
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.awt.Paint;
-
-import edu.uci.ics.jung.graph.Vertex;
-
-public interface VertexLabelPaintFunction {
- Paint getLabelDrawPaint(Vertex vertex);
-}
\ No newline at end of file
Modified: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/DroolsIDEPlugin.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/DroolsIDEPlugin.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/DroolsIDEPlugin.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,4 +1,4 @@
-package org.drools.ide;
+ package org.drools.ide;
/*
* Copyright 2005 JBoss Inc
*
Modified: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor2.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor2.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditor2.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,7 +1,25 @@
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.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.editors.rete.ReteViewer;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.ui.actions.ZoomComboContributionItem;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
@@ -10,58 +28,161 @@
/**
* This is a multi table editor wrapper for both the text editor and the RETE
* viewer.
- * @author Kris.
+ *
+ * @author Kris
+ * @author Ahti Kitsik
*/
public class DRLRuleEditor2 extends FormEditor {
+
+ private DRLRuleEditor textEditor;
- private DRLRuleEditor textEditor;
+ private ReteViewer reteViewer;
- private ReteViewer reteViewer;
+ private ZoomComboContributionItem zitem;
- public void init(IEditorSite site, IEditorInput input) throws PartInitException {
- super.init(site, input);
- setPartName(input.getName());
- }
+ private ZoomInAction2 zoomIn;
+ private ZoomOutAction2 zoomOut;
- protected void addPages() {
- try {
- textEditor = new DRLRuleEditor() {
- public void close(boolean save) {
- super.close(save);
- DRLRuleEditor2.this.close(save);
- }
- protected void setPartName(String partName) {
- super.setPartName(partName);
- DRLRuleEditor2.this.setPartName(partName);
- }
- };
- reteViewer = new ReteViewer(this, textEditor.getDocumentProvider());
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+ */
+ public void init(IEditorSite site,
+ IEditorInput input) throws PartInitException {
+ super.init( site,
+ input );
+ setPartName( input.getName() );
+
+ }
- int text = addPage(textEditor, getEditorInput());
- int rete = addPage(reteViewer, getEditorInput());
+ /**
+ * Adds Text Editor for rules and Rete graph viewer
+ *
+ * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
+ */
+ protected void addPages() {
+ try {
+ textEditor = new DRLRuleEditor() {
+ public void close(boolean save) {
+ super.close( save );
+ DRLRuleEditor2.this.close( save );
+ }
- setPageText(text, "Text Editor");
- setPageText(rete, "Rete Tree");
- } catch (PartInitException e) {
- DroolsIDEPlugin.log(e);
- }
- }
+ protected void setPartName(String partName) {
+ super.setPartName( partName );
+ DRLRuleEditor2.this.setPartName( partName );
+ }
+ };
+ reteViewer = new ReteViewer(textEditor.getDocumentProvider() );
- public void doSave(IProgressMonitor monitor) {
- textEditor.doSave(monitor);
- setInput(getEditorInput());
- reteViewer.clear();
- }
+ int text = addPage( textEditor,
+ getEditorInput() );
- public void doSaveAs() {
- textEditor.doSaveAs();
- }
+ int rete = addPage( reteViewer,
+ getEditorInput() );
- public boolean isSaveAsAllowed() {
- return textEditor.isSaveAsAllowed();
- }
+ setPageText( text,
+ "Text Editor" );
+ setPageText( rete,
+ "Rete Tree" );
+ } catch ( PartInitException e ) {
+ DroolsIDEPlugin.log( e );
+ }
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void doSave(IProgressMonitor monitor) {
+ textEditor.doSave( monitor );
+ setInput( getEditorInput() );
+ reteViewer.loadReteModel();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorPart#doSaveAs()
+ */
+ public void doSaveAs() {
+ textEditor.doSaveAs();
+ reteViewer.loadReteModel();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
+ */
+ public boolean isSaveAsAllowed() {
+ return textEditor.isSaveAsAllowed();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.MultiPageEditorPart#getAdapter(java.lang.Class)
+ */
public Object getAdapter(Class adapter) {
- return textEditor.getAdapter(adapter);
+ if (adapter == ZoomManager.class) {
+
+ if ( getActiveEditor() instanceof ReteViewer ) {
+ return reteViewer.getAdapter( adapter );
+ } else if ( getActiveEditor() instanceof DRLRuleEditor ) {
+ return null;
+ }
+
+ }
+ return textEditor.getAdapter( adapter );
}
+
+ /**
+ * Updates ZoomManagers for contributed actions.
+ */
+ private void updateZoomItems() {
+ final ZoomManager zoomManager = (ZoomManager) getAdapter( ZoomManager.class );
+
+ boolean zoomActive = zoomManager != null;
+
+ if (zoomIn!=null && zoomOut!=null && zitem!=null) {
+
+ zoomIn.setZoomManager( zoomManager );
+ zoomIn.setEnabled( zoomActive );
+
+ zoomOut.setZoomManager( zoomManager );
+ zoomOut.setEnabled( zoomActive );
+
+ zitem.setZoomManager( zoomManager );
+
+ }
+
+ }
+
+ /**
+ * Sets ZoomComboContributionItem to be used for updating it's
+ * ZoomManager when multipage tab is switched.
+ *
+ * @param zitem contribution item
+ */
+ public void setZoomComboContributionItem(ZoomComboContributionItem zitem) {
+ this.zitem = zitem;
+ }
+
+ /**
+ * Sets ZoomOutAction2 to be used for updating it's
+ * ZoomManager when multipage tab is switched.
+ *
+ * @param zoomOut zoom action
+ */
+ public void setZoomZoomOutAction(ZoomOutAction2 zoomOut) {
+ this.zoomOut = zoomOut;
+ }
+
+ /**
+ * Sets ZoomInAction to be used for updating it's
+ * ZoomManager when multipage tab is switched.
+ * @param zoomIn zoom action
+ */
+ public void setZoomZoomInAction(ZoomInAction2 zoomIn) {
+ this.zoomIn = zoomIn;
+ }
+
+ public void setFocus() {
+ super.setFocus();
+ updateZoomItems();
+ }
+
}
Modified: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditorActionContributor.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditorActionContributor.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/DRLRuleEditorActionContributor.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,5 +1,24 @@
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.gef.editparts.ZoomManager;
+import org.eclipse.gef.ui.actions.ZoomComboContributionItem;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
@@ -7,22 +26,85 @@
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;
+/**
+ * ActionContributors for DRLRuleEditor2
+ *
+ * Currently implements contributors to zoom feature at rete viewer.
+ *
+ * @author Ahti Kitsik
+ *
+ */
public class DRLRuleEditorActionContributor extends MultiPageEditorActionBarContributor {
- private TextEditorActionContributor contributor = new TextEditorActionContributor();
-
- public void init(IActionBars bars, IWorkbenchPage page) {
- contributor.init(bars);
- super.init(bars, page);
- }
-
- public void setActivePage(IEditorPart activeEditor) {
- IActionBars bars = getActionBars();
- if (activeEditor instanceof ITextEditor) {
- if (bars != null) {
- contributor.setActiveEditor(activeEditor);
- }
- }
- }
+ private TextEditorActionContributor contributor = new TextEditorActionContributor();
+ private ZoomComboContributionItem zitem;
+ private ZoomOutAction2 zoomOut;
+ private ZoomInAction2 zoomIn;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorActionBarContributor#init(org.eclipse.ui.IActionBars, org.eclipse.ui.IWorkbenchPage)
+ */
+ public void init(IActionBars bars,
+ IWorkbenchPage page) {
+ contributor.init( bars );
+ super.init( bars,
+ page );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActivePage(org.eclipse.ui.IEditorPart)
+ */
+ public void setActivePage(IEditorPart activeEditor) {
+ IActionBars bars = getActionBars();
+ if ( activeEditor instanceof ITextEditor ) {
+ if ( bars != null ) {
+ contributor.setActiveEditor( activeEditor );
+ }
+ }
+ }
+
+ /**
+ * In addition to @link org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActiveEditor(org.eclipse.ui.IEditorPart)
+ * it sets contribution items to DRLRuleEditor2 for later use when
+ * multipageditor tabs are switched.
+ *
+ */
+ public void setActiveEditor(IEditorPart part) {
+ super.setActiveEditor( part );
+ if ( part instanceof DRLRuleEditor2 ) {
+ DRLRuleEditor2 p = (DRLRuleEditor2) part;
+ p.setZoomComboContributionItem( zitem );
+ p.setZoomZoomInAction( zoomIn );
+ p.setZoomZoomOutAction( zoomOut );
+ }
+ }
+
+ /**
+ * Adds Zoom-related contributions.
+ *
+ * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(org.eclipse.jface.action.IToolBarManager)
+ */
+ public void contributeToToolBar(IToolBarManager toolBarManager) {
+ super.contributeToToolBar( toolBarManager );
+ toolBarManager.add( new Separator() );
+ String[] zoomStrings = new String[]{ZoomManager.FIT_ALL, ZoomManager.FIT_HEIGHT, ZoomManager.FIT_WIDTH};
+
+ zitem = new ZoomComboContributionItem( getPage(),
+ zoomStrings );
+ zitem.setZoomManager( null );
+ zitem.setVisible( false );
+
+ zoomIn = new ZoomInAction2();
+ zoomIn.setEnabled( false );
+
+ zoomOut = new ZoomOutAction2();
+ zoomOut.setEnabled( false );
+
+ toolBarManager.add( zitem );
+ toolBarManager.add( zoomIn );
+ toolBarManager.add( zoomOut );
+
+ }
+
}
Deleted: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java
===================================================================
--- labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-10-18 00:08:55 UTC (rev 6877)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -1,185 +0,0 @@
-package org.drools.ide.editors;
-
-import java.awt.BorderLayout;
-import java.awt.Frame;
-import java.io.Reader;
-
-import org.drools.RuleBase;
-import org.drools.compiler.DrlParser;
-import org.drools.compiler.PackageBuilder;
-import org.drools.ide.DroolsIDEPlugin;
-import org.drools.ide.builder.DroolsBuilder;
-import org.drools.ide.util.ProjectClassLoader;
-import org.drools.lang.descr.PackageDescr;
-import org.drools.reteoo.ReteooRuleBase;
-import org.drools.rule.Package;
-import org.drools.visualize.ReteooJungViewerPanel;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.awt.SWT_AWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-
-public class ReteViewer extends EditorPart {
-
- private DRLRuleEditor2 drlEditor;
-
- private IDocumentProvider documentProvider;
-
- private Frame frame;
-
- private Composite parent;
-
- public ReteViewer(DRLRuleEditor2 drlEditor,
- IDocumentProvider documentProvider) {
- this.drlEditor = drlEditor;
- this.documentProvider = documentProvider;
- }
-
- public void createPartControl(Composite parent) {
- this.parent = parent;
- GridLayout layout = new GridLayout();
- layout.numColumns = 1;
- parent.setLayout(layout);
- Button generateButton = new Button(parent, SWT.PUSH);
- generateButton.setText("Generate Rete View");
- generateButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- generateReteView();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- generateReteView();
- }
- });
-
- try {
- Composite frameParent = new Composite(parent, SWT.EMBEDDED);
- frameParent.setLayoutData(new GridData(GridData.FILL_BOTH));
- frame = SWT_AWT.new_Frame(frameParent);
- frame.setLayout(new BorderLayout());
- } catch (SWTError exc) {
- // it is possible that this exception is thrown if
- // SWT is not supported, e.g. in Mac
- DroolsIDEPlugin.log(exc);
- }
- }
-
- private RuleBase getRuleBase() {
- if (getEditorInput() instanceof IFileEditorInput) {
- try {
- String contents = documentProvider.getDocument(getEditorInput()).get();
-
- ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
- ClassLoader newLoader = DroolsBuilder.class.getClassLoader();
- IFile file = ((IFileEditorInput) getEditorInput()).getFile();
- if (file.getProject().getNature("org.eclipse.jdt.core.javanature") != null) {
- IJavaProject project = JavaCore.create(file.getProject());
- newLoader = ProjectClassLoader.getProjectClassLoader(project);
- }
-
- Reader dslReader = DSLAdapter.getDSLContent(contents, file);
-
- try {
- Thread.currentThread().setContextClassLoader(newLoader);
-
- DrlParser parser = new DrlParser();
-
- PackageDescr packageDescr = null;
- if (dslReader == null) {
- packageDescr = parser.parse(contents);
- } else {
- packageDescr = parser.parse(contents, dslReader);
- }
-
- //pre build the package
- PackageBuilder builder = new PackageBuilder();
- builder.addPackage(packageDescr);
- Package pkg = builder.getPackage();
-
- //add the package to a rulebase
- ReteooRuleBase ruleBase = new ReteooRuleBase();
- ruleBase.addPackage(pkg);
- return ruleBase;
-
- } catch (Exception t) {
- throw t;
- } finally {
- Thread.currentThread().setContextClassLoader(oldLoader);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- return null;
- }
-
- public void doSave(IProgressMonitor monitor) {
- // Do nothing
- }
-
- public void doSaveAs() {
- // Do nothing
- }
-
- public void init(IEditorSite site, IEditorInput input)
- throws PartInitException {
- setSite(site);
- setInput(input);
- }
-
- public void clear() {
- if (frame != null) { // possible if frame creation failed
- frame.removeAll();
- }
- }
-
- public boolean isDirty() {
- return false;
- }
-
- public boolean isSaveAsAllowed() {
- return false;
- }
-
- public void setFocus() {
- if (drlEditor.isDirty()) {
- clear();
- }
- }
-
- private void generateReteView() {
- if (frame != null) { // possible if frame creation failed
- clear();
- try {
- RuleBase ruleBase = getRuleBase();
- if (ruleBase == null) {
- // TODO signal user that rule cannot be parsed
- } else {
- ReteooJungViewerPanel viewer = new ReteooJungViewerPanel(
- ruleBase);
- frame.add(viewer);
- frame.validate();
- parent.layout();
- }
- } catch (Throwable t) {
- t.printStackTrace();
- DroolsIDEPlugin.log(t);
- }
- }
- }
-}
Copied: labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteViewer.java (from rev 6253, labs/jbossrules/tags/3.0.3-GA/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java)
===================================================================
--- labs/jbossrules/tags/3.0.3-GA/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-09-16 20:17:49 UTC (rev 6253)
+++ labs/jbossrules/branches/3.0.x/drools-ide/src/main/java/org/drools/ide/editors/rete/ReteViewer.java 2006-10-18 00:09:04 UTC (rev 6878)
@@ -0,0 +1,291 @@
+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.io.Reader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.PackageIntegrationException;
+import org.drools.RuleBase;
+import org.drools.compiler.DrlParser;
+import org.drools.compiler.DroolsParserException;
+import org.drools.compiler.PackageBuilder;
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.builder.DroolsBuilder;
+import org.drools.ide.editors.DSLAdapter;
+import org.drools.ide.editors.rete.model.ReteGraph;
+import org.drools.ide.editors.rete.part.VertexEditPartFactory;
+import org.drools.ide.util.ProjectClassLoader;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.reteoo.BaseVertex;
+import org.drools.reteoo.ReteooRuleBase;
+import org.drools.reteoo.ReteooVisitor;
+import org.drools.rule.Package;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.DefaultEditDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.MouseWheelHandler;
+import org.eclipse.gef.MouseWheelZoomHandler;
+import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.ui.parts.GraphicalEditor;
+import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+/**
+ * GEF-based RETE Viewer
+ *
+ * @author Ahti Kitsik
+ *
+ */
+public class ReteViewer extends GraphicalEditor {
+
+ ScalableFreeformRootEditPart rootEditPart = new ScalableFreeformRootEditPart();
+
+ private IDocumentProvider documentProvider;
+
+ private ReteGraph diagram = new ReteGraph();
+
+ /**
+ * Constructor.
+ *
+ * @param documentProvider documentProvider must contain Document with rules.
+ */
+ public ReteViewer(IDocumentProvider documentProvider) {
+ super();
+ this.documentProvider = documentProvider;
+ setEditDomain( new DefaultEditDomain( this ) );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()
+ */
+ protected void configureGraphicalViewer() {
+ super.configureGraphicalViewer();
+ GraphicalViewer viewer = getGraphicalViewer();
+ viewer.getControl().setBackground( ColorConstants.white );
+ viewer.setEditPartFactory( new VertexEditPartFactory() );
+ viewer.setRootEditPart( rootEditPart );
+ viewer.setKeyHandler( new GraphicalViewerKeyHandler( viewer ) );
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gef.ui.parts.GraphicalEditor#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class type) {
+
+ if ( type == ZoomManager.class ) return ((ScalableFreeformRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager();
+ if ( type == GraphicalViewer.class ) return getGraphicalViewer();
+ if ( type == EditPart.class && getGraphicalViewer() != null ) return getGraphicalViewer().getRootEditPart();
+ if ( type == IFigure.class && getGraphicalViewer() != null ) return ((GraphicalEditPart) getGraphicalViewer().getRootEditPart()).getFigure();
+ return super.getAdapter( type );
+ }
+
+ private RuleBase getRuleBase() {
+ if ( getEditorInput() instanceof IFileEditorInput ) {
+ try {
+ String contents = documentProvider.getDocument( getEditorInput() ).get();
+
+ ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader newLoader = DroolsBuilder.class.getClassLoader();
+ IFile file = ((IFileEditorInput) getEditorInput()).getFile();
+ if ( file.getProject().getNature( "org.eclipse.jdt.core.javanature" ) != null ) {
+ IJavaProject project = JavaCore.create( file.getProject() );
+ newLoader = ProjectClassLoader.getProjectClassLoader( project );
+ }
+
+ Reader dslReader = DSLAdapter.getDSLContent( contents,
+ file );
+
+ try {
+ Thread.currentThread().setContextClassLoader( newLoader );
+
+ return parseRuleBase( contents,
+ dslReader );
+
+ } catch ( Exception t ) {
+ throw t;
+ } finally {
+ Thread.currentThread().setContextClassLoader( oldLoader );
+ }
+ } catch ( Throwable t ) {
+ DroolsIDEPlugin.log(t);
+ }
+ }
+
+ return null;
+
+ }
+
+ /**
+ *
+ *
+ * @param contents
+ * @param dslReader
+ * @return
+ * @throws DroolsParserException
+ * @throws PackageIntegrationException
+ */
+ public static RuleBase parseRuleBase(String contents,
+ Reader dslReader) throws DroolsParserException,
+ PackageIntegrationException {
+ DrlParser parser = new DrlParser();
+
+ PackageDescr packageDescr = null;
+ if ( dslReader == null ) {
+ packageDescr = parser.parse( contents );
+ } else {
+ packageDescr = parser.parse( contents,
+ dslReader );
+ }
+
+ //pre build the package
+ PackageBuilder builder = new PackageBuilder();
+ builder.addPackage( packageDescr );
+ Package pkg = builder.getPackage();
+
+ //add the package to a rulebase
+ ReteooRuleBase ruleBase = new ReteooRuleBase();
+ ruleBase.addPackage( pkg );
+ return ruleBase;
+ }
+
+ /**
+ * Loads model from rule base,
+ * calculates rete view and initializes diagram model.
+ */
+ public void loadReteModel() {
+ try {
+
+ diagram.removeAll();
+
+ RuleBase ruleBase = getRuleBase();
+ if ( ruleBase == null ) {
+ DroolsIDEPlugin.log(new Exception("Unable to load rule base!"));
+ } else {
+
+ final ReteooVisitor visitor = new ReteooVisitor( diagram );
+ visitor.visit( ruleBase );
+
+ BaseVertex rootVertex = visitor.getRootVertex();
+
+ RowList rowList = ReteooLayoutFactory.calculateReteRows( rootVertex );
+ ReteooLayoutFactory.layoutRowList( diagram,
+ rowList );
+
+ }
+ } catch ( Throwable t ) {
+ t.printStackTrace();
+ DroolsIDEPlugin.log( t );
+ }
+ }
+
+ private ReteGraph getModel() {
+ return diagram;
+ }
+
+ /**
+ * Loads Rete model and initializes zoom manager.
+ *
+ */
+ protected void initializeGraphicalViewer() {
+ GraphicalViewer viewer = getGraphicalViewer();
+
+ // Generate rete and layout
+ loadReteModel();
+
+ zeroBaseDiagram();
+
+ // Make rete graph visible
+ viewer.setContents( getModel() ); // set the contents of this editor
+
+ ZoomManager zoomManager = rootEditPart.getZoomManager();
+
+ //List<String>
+ List zoomLevels = new ArrayList( 3 );
+
+ zoomLevels.add( ZoomManager.FIT_ALL );
+ zoomLevels.add( ZoomManager.FIT_HEIGHT );
+ zoomLevels.add( ZoomManager.FIT_WIDTH );
+
+ zoomManager.setZoomLevelContributions( zoomLevels );
+
+ // Zoom mousewheel - Ctrl+Mousewheel for zoom in/out
+ getGraphicalViewer().setProperty( MouseWheelHandler.KeyGenerator.getKey( SWT.MOD1 ),
+ MouseWheelZoomHandler.SINGLETON );
+
+ }
+
+ /**
+ * Moves all <code>diagram</code> nodes to upper left corner
+ * and shifting to right if neccessary to get rid of negative XY coordinates.
+ *
+ */
+ private void zeroBaseDiagram() {
+ int minx = 0;
+ int miny = 0;
+
+ final Iterator nodeIter = diagram.getChildren().iterator();
+ while ( nodeIter.hasNext() ) {
+ Point loc = ((BaseVertex) (nodeIter.next())).getLocation();
+ minx = Math.min( loc.x,
+ minx );
+ miny = Math.min( loc.y,
+ miny );
+ }
+
+ minx = minx - 10;
+
+ final Iterator nodeIter2 = diagram.getChildren().iterator();
+ while ( nodeIter2.hasNext() ) {
+ final BaseVertex vertex = (BaseVertex) (nodeIter2.next());
+ Point loc = vertex.getLocation();
+ vertex.setLocation( new Point( loc.x - minx,
+ loc.y - miny ) );
+ }
+ }
+
+ /**
+ * No save operation in ReteViewer
+ */
+ public void doSave(IProgressMonitor monitor) {
+
+ }
+
+ /**
+ * ReteViewer is never dirty.
+ * This prevents editor close mechanism to ask file save confirmation
+ * even after one of the vertices is moved.
+ */
+ public boolean isDirty() {
+ return false;
+ }
+
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list