[jboss-svn-commits] JBL Code SVN: r9867 - in labs/jbossrules/trunk/drools-ide: icons and 26 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Feb 28 21:40:43 EST 2007
Author: KrisVerlaenen
Date: 2007-02-28 21:40:42 -0500 (Wed, 28 Feb 2007)
New Revision: 9867
Added:
labs/jbossrules/trunk/drools-ide/icons/activity.gif
labs/jbossrules/trunk/drools-ide/icons/connection.gif
labs/jbossrules/trunk/drools-ide/icons/join.gif
labs/jbossrules/trunk/drools-ide/icons/process.gif
labs/jbossrules/trunk/drools-ide/icons/process_start.gif
labs/jbossrules/trunk/drools-ide/icons/process_stop.gif
labs/jbossrules/trunk/drools-ide/icons/split.gif
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/DefaultDataTypeRegistry.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/IDataTypeRegistry.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/impl/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/impl/DataTypeRegistry.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericActionBarContributor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericContextMenuProvider.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericModelEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/ObjectInputStreamWithLoader.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/OverviewOutlinePage.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/DefaultElementWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnection.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnectionFactory.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelEvent.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelListener.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ProcessWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/AddElementCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ChangeConstraintCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/CreateBendpointCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteBendpointCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteConnectionCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteElementCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ElementConnectionCreateCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/MoveBendpointCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionSourceCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionTargetCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/RenameElementCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/SplitConnectionCommand.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementCellEditorLocator.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementConnectionEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ProcessEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/figure/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/figure/ElementFigure.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionBendpointEditPolicy.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionEditPolicy.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditManager.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditPolicy.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementEditPolicy.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementNodeEditPolicy.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ProcessLayoutEditPolicy.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IDataTypeEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/BooleanEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeCombo.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeEditorComposite.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EditorComposite.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EmptyEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/FloatEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/IntegerEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/StringEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/BeanDialogCellEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditBeanDialog.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditListDialog.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/ListPropertyDescriptor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFilePage.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFileWizard.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/SampleRuleFlow.rf.template
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapperFactory.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/EndNodeWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/JoinWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/NodeWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleFlowProcessWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleSetNodeWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/SplitWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/StartNodeWrapper.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowModelEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowPaletteFactory.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/action/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/action/CheckRuleFlowAction.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/EndNodeEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/JoinEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowConnectionEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleSetNodeEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/SplitEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/StartNodeEditPart.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListCellEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListDialog.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintsPropertyDescriptor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableDialog.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListCellEditor.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListDialog.java
Modified:
labs/jbossrules/trunk/drools-ide/plugin.xml
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java
Log:
JBRULES-711: Ruleflow IDE integration
- first implementation of ruleflow in IDE
Added: labs/jbossrules/trunk/drools-ide/icons/activity.gif
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-ide/icons/activity.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-ide/icons/connection.gif
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-ide/icons/connection.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-ide/icons/join.gif
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-ide/icons/join.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-ide/icons/process.gif
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-ide/icons/process.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-ide/icons/process_start.gif
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-ide/icons/process_start.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-ide/icons/process_stop.gif
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-ide/icons/process_stop.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/drools-ide/icons/split.gif
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/drools-ide/icons/split.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossrules/trunk/drools-ide/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-ide/plugin.xml 2007-03-01 02:36:54 UTC (rev 9866)
+++ labs/jbossrules/trunk/drools-ide/plugin.xml 2007-03-01 02:40:42 UTC (rev 9867)
@@ -134,7 +134,7 @@
</extension>
<extension
- id="droolsbuilder" name="Drools Builder" point="org.eclipse.core.resources.builders">
+ id="droolsbuilder" name="JBoss Rules Builder" point="org.eclipse.core.resources.builders">
<builder>
<run class="org.drools.ide.builder.DroolsBuilder"/>
</builder>
@@ -152,7 +152,7 @@
<extension
id="droolsBreakpointMarker"
point="org.eclipse.core.resources.markers"
- name="Drools Breakpoint Marker">
+ name="JBoss Rules Breakpoint Marker">
<super type="org.eclipse.debug.core.breakpointMarker"/>
<persistent value="true"/>
</extension>
@@ -199,7 +199,7 @@
<extension point = "org.eclipse.debug.core.launchConfigurationTypes">
<launchConfigurationType
id="org.drools.ide.launching.DroolsLaunchConfigurationDelegate"
- name="Drools Application"
+ name="JBoss Rules Application"
delegate="org.drools.ide.launching.DroolsLaunchConfigurationDelegate"
sourceLocatorId="org.drools.ide.launching.DroolsSourceLookupDirector"
sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"
@@ -235,7 +235,7 @@
<extension
point="org.eclipse.debug.core.sourceLocators">
<sourceLocator
- name="Drools Source Lookup Director"
+ name="JBoss Rules Source Lookup Director"
class="org.drools.ide.launching.DroolsSourceLookupDirector"
id="org.drools.ide.launching.DroolsSourceLookupDirector">
</sourceLocator>
@@ -324,4 +324,50 @@
</objectContribution>
</extension>
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="RuleFlow Editor"
+ extensions="rf, ruleflow, rflow"
+ icon="icons/process.gif"
+ contributorClass="org.drools.ide.flow.common.editor.GenericActionBarContributor"
+ class="org.drools.ide.flow.ruleflow.editor.RuleFlowModelEditor"
+ id="org.drools.ide.flow.ruleflow.editor.RuleFlowModelEditor">
+ </editor>
+ </extension>
+
+ <extension
+ point = "org.eclipse.ui.editorActions">
+ <editorContribution
+ id="org.drools.ide.flow.ruleflow.editor.action.CheckRuleFlowAction"
+ targetID="org.drools.ide.flow.ruleflow.editor.RuleFlowModelEditor">
+ <action
+ id="org.drools.ide.flow.ruleflow.editor.action.CheckRuleFlowAction"
+ label="Check RuleFlow"
+ toolbarPath="JBoss Rules"
+ icon="icons/check.gif"
+ tooltip="Check the ruleflow model"
+ class="org.drools.ide.flow.ruleflow.editor.action.CheckRuleFlowAction"
+ />
+ </editorContribution>
+ </extension>
+
+ <extension
+ point = "org.eclipse.ui.newWizards">
+ <category
+ id = "org.drools.ide.flow.new"
+ name="RuleFlow">
+ </category>
+ <wizard
+ id = "org.drools.ide.flow.ruleflow.NewRuleFlowFileWizard"
+ name = "RuleFlow File"
+ class="org.drools.ide.flow.ruleflow.NewRuleFlowFileWizard"
+ category="org.drools.ide.new"
+ icon="icons/process.gif">
+ <description>A wizard that creates a new ruleflow file</description>
+ <selection class="org.eclipse.core.resources.IResource"/>
+ </wizard>
+ </extension>
+
+
</plugin>
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2007-03-01 02:36:54 UTC (rev 9866)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -742,6 +742,8 @@
"date-expires \"dd-MMM-yyyy\"", 14, droolsIcon));
list.add(new RuleCompletionProposal(prefix.length(), "enabled",
"enabled false", droolsIcon));
+ list.add(new RuleCompletionProposal(prefix.length(), "ruleflow-group",
+ "ruleflow-group \"\"", 16, droolsIcon));
}
private void addDSLProposals(final List list, final String prefix,
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/DefaultDataTypeRegistry.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/DefaultDataTypeRegistry.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/DefaultDataTypeRegistry.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,74 @@
+package org.drools.ide.flow.common.datatype;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.datatype.impl.DataTypeRegistry;
+import org.drools.ide.flow.common.view.datatype.editor.impl.BooleanEditor;
+import org.drools.ide.flow.common.view.datatype.editor.impl.EmptyEditor;
+import org.drools.ide.flow.common.view.datatype.editor.impl.IntegerEditor;
+import org.drools.ruleflow.common.datatype.IDataTypeFactory;
+import org.drools.ruleflow.common.datatype.impl.InstanceDataTypeFactory;
+import org.drools.ruleflow.common.datatype.impl.type.BooleanDataType;
+import org.drools.ruleflow.common.datatype.impl.type.FloatDataType;
+import org.drools.ruleflow.common.datatype.impl.type.IntegerDataType;
+import org.drools.ruleflow.common.datatype.impl.type.StringDataType;
+import org.drools.ruleflow.common.datatype.impl.type.UndefinedDataType;
+
+import sun.beans.editors.FloatEditor;
+import sun.beans.editors.StringEditor;
+
+/**
+ * Default datatype registry containing default datatypes.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DefaultDataTypeRegistry {
+
+ private static final IDataTypeRegistry variableDataTypeRegistry = new DataTypeRegistry();
+
+ private DefaultDataTypeRegistry() {
+ }
+
+ static {
+ registerVariableDataType(UndefinedDataType.class,
+ new InstanceDataTypeFactory(UndefinedDataType.class),
+ "Undefined", EmptyEditor.class, EmptyEditor.class);
+ registerVariableDataType(BooleanDataType.class,
+ new InstanceDataTypeFactory(BooleanDataType.class), "Boolean",
+ BooleanEditor.class, EmptyEditor.class);
+ registerVariableDataType(IntegerDataType.class,
+ new InstanceDataTypeFactory(IntegerDataType.class), "Integer",
+ IntegerEditor.class, EmptyEditor.class);
+ registerVariableDataType(FloatDataType.class,
+ new InstanceDataTypeFactory(FloatDataType.class), "Float",
+ FloatEditor.class, EmptyEditor.class);
+ registerVariableDataType(StringDataType.class,
+ new InstanceDataTypeFactory(StringDataType.class), "String",
+ StringEditor.class, EmptyEditor.class);
+ }
+
+ public static void registerVariableDataType(Class type,
+ IDataTypeFactory dataTypeFactory, String name,
+ Class valueEditorClass, Class dataTypeEditorClass) {
+ variableDataTypeRegistry.registerDataType(type, dataTypeFactory, name,
+ valueEditorClass, dataTypeEditorClass);
+ }
+
+ public static IDataTypeRegistry getInstance() {
+ return variableDataTypeRegistry;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/IDataTypeRegistry.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/IDataTypeRegistry.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/IDataTypeRegistry.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,52 @@
+package org.drools.ide.flow.common.datatype;
+/*
+ * 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.Set;
+
+import org.drools.ruleflow.common.datatype.IDataTypeFactory;
+
+/**
+ * A registry of datatypes.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface IDataTypeRegistry {
+
+ /**
+ * Returns all registered data types.
+ */
+ Set getDataTypes();
+
+ void registerDataType(Class type, IDataTypeFactory dataTypeFactory, String name,
+ Class valueEditorClass, Class dataTypeEditorClass);
+
+ /**
+ * Returns the data type info of the data type with the given type
+ * @param type
+ * @return the data type info
+ * @throws IllegalArgumentException if the data type info of this type cannot be found
+ */
+ IDataTypeInfo getDataTypeInfo(Class type);
+
+ interface IDataTypeInfo {
+ Class getType();
+ IDataTypeFactory getDataTypeFactory();
+ String getName();
+ Class getDataTypeEditorClass();
+ Class getValueEditorClass();
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/impl/DataTypeRegistry.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/impl/DataTypeRegistry.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/datatype/impl/DataTypeRegistry.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,95 @@
+package org.drools.ide.flow.common.datatype.impl;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.drools.ide.flow.common.datatype.IDataTypeRegistry;
+import org.drools.ruleflow.common.datatype.IDataTypeFactory;
+
+/**
+ * Default implementation of a datatype registry.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DataTypeRegistry implements IDataTypeRegistry {
+
+ private Map dataTypes = new HashMap();
+
+ public Set getDataTypes() {
+ return new HashSet(dataTypes.values());
+ }
+
+ public void registerDataType(Class type, IDataTypeFactory dataTypeFactory, String name,
+ Class valueEditorClass, Class dataTypeEditorClass) {
+ if (dataTypeFactory == null) {
+ throw new NullPointerException("Data type factory may not be null");
+ }
+ if (name == null) {
+ throw new NullPointerException("Name may not be null");
+ }
+ if (valueEditorClass == null) {
+ throw new NullPointerException("valueEditorClass may not be null");
+ }
+ if (dataTypeEditorClass == null) {
+ throw new NullPointerException("dataTypeEditorClass may not be null");
+ }
+ dataTypes.put(type, new DataTypeInfo(
+ type, dataTypeFactory, name, valueEditorClass, dataTypeEditorClass));
+ }
+
+ public IDataTypeInfo getDataTypeInfo(Class type) {
+ IDataTypeInfo dataTypeInfo = (IDataTypeInfo) dataTypes.get(type);
+ if (dataTypeInfo == null) {
+ throw new IllegalArgumentException("Cannot find data type info with type " + type);
+ }
+ return dataTypeInfo;
+ }
+
+ public class DataTypeInfo implements IDataTypeInfo {
+ private Class type;
+ private IDataTypeFactory dataTypeFactory;
+ private String name;
+ private Class valueEditorClass;
+ private Class dataTypeEditorClass;
+ private DataTypeInfo(Class type, IDataTypeFactory dataTypeFactory, String name,
+ Class valueEditorClass, Class dataTypeEditorClass) {
+ this.type = type;
+ this.dataTypeFactory = dataTypeFactory;
+ this.name = name;
+ this.valueEditorClass = valueEditorClass;
+ this.dataTypeEditorClass = dataTypeEditorClass;
+ }
+ public Class getType() {
+ return type;
+ }
+ public IDataTypeFactory getDataTypeFactory() {
+ return dataTypeFactory;
+ }
+ public String getName() {
+ return name;
+ }
+ public Class getValueEditorClass() {
+ return valueEditorClass;
+ }
+ public Class getDataTypeEditorClass() {
+ return dataTypeEditorClass;
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericActionBarContributor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericActionBarContributor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericActionBarContributor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,74 @@
+package org.drools.ide.flow.common.editor;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.ui.actions.ActionBarContributor;
+import org.eclipse.gef.ui.actions.AlignmentRetargetAction;
+import org.eclipse.gef.ui.actions.DeleteRetargetAction;
+import org.eclipse.gef.ui.actions.GEFActionConstants;
+import org.eclipse.gef.ui.actions.RedoRetargetAction;
+import org.eclipse.gef.ui.actions.UndoRetargetAction;
+import org.eclipse.gef.ui.actions.ZoomComboContributionItem;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.actions.ActionFactory;
+
+/**
+ * Common implementation of a ActionBarContributor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class GenericActionBarContributor extends ActionBarContributor {
+
+ protected void buildActions() {
+ addRetargetAction(new UndoRetargetAction());
+ addRetargetAction(new RedoRetargetAction());
+ addRetargetAction(new DeleteRetargetAction());
+
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM));
+ }
+
+ public void contributeToToolBar(IToolBarManager toolBarManager) {
+ toolBarManager.add(getAction(ActionFactory.UNDO.getId()));
+ toolBarManager.add(getAction(ActionFactory.REDO.getId()));
+ toolBarManager.add(new Separator());
+ toolBarManager.add(new ZoomComboContributionItem(getPage()));
+ toolBarManager.add(new Separator());
+ toolBarManager.add(getActionRegistry().getAction(
+ GEFActionConstants.ALIGN_LEFT));
+ toolBarManager.add(getActionRegistry().getAction(
+ GEFActionConstants.ALIGN_CENTER));
+ toolBarManager.add(getActionRegistry().getAction(
+ GEFActionConstants.ALIGN_RIGHT));
+ toolBarManager.add(new Separator());
+ toolBarManager.add(getActionRegistry().getAction(
+ GEFActionConstants.ALIGN_TOP));
+ toolBarManager.add(getActionRegistry().getAction(
+ GEFActionConstants.ALIGN_MIDDLE));
+ toolBarManager.add(getActionRegistry().getAction(
+ GEFActionConstants.ALIGN_BOTTOM));
+
+ }
+
+ protected void declareGlobalActionKeys() {
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericContextMenuProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericContextMenuProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericContextMenuProvider.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,65 @@
+package org.drools.ide.flow.common.editor;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.gef.ContextMenuProvider;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.GEFActionConstants;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.ui.actions.ActionFactory;
+
+/**
+ * Common implementation of a ContextMenuProvider.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class GenericContextMenuProvider extends ContextMenuProvider {
+
+ private ActionRegistry actionRegistry;
+
+ public GenericContextMenuProvider(EditPartViewer viewer,
+ ActionRegistry registry) {
+ super(viewer);
+ setActionRegistry(registry);
+ }
+
+ public void buildContextMenu(IMenuManager menu) {
+ GEFActionConstants.addStandardActionGroups(menu);
+
+ IAction action = getActionRegistry().getAction(
+ ActionFactory.UNDO.getId());
+ menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
+
+ action = getActionRegistry().getAction(ActionFactory.REDO.getId());
+ menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);
+
+ action = getActionRegistry().getAction(ActionFactory.DELETE.getId());
+ if (action.isEnabled()) {
+ menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
+ }
+ }
+
+ private ActionRegistry getActionRegistry() {
+ return actionRegistry;
+ }
+
+ public void setActionRegistry(ActionRegistry registry) {
+ actionRegistry = registry;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericModelEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericModelEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/GenericModelEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,304 @@
+package org.drools.ide.flow.common.editor;
+/*
+ * 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.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.EventObject;
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.ContextMenuProvider;
+import org.eclipse.gef.DefaultEditDomain;
+import org.eclipse.gef.EditPartFactory;
+import org.eclipse.gef.KeyHandler;
+import org.eclipse.gef.KeyStroke;
+import org.eclipse.gef.editparts.ScalableRootEditPart;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.AlignmentAction;
+import org.eclipse.gef.ui.actions.DirectEditAction;
+import org.eclipse.gef.ui.actions.GEFActionConstants;
+import org.eclipse.gef.ui.parts.GraphicalEditorWithPalette;
+import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.dialogs.SaveAsDialog;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+/**
+ * Abstract implementation of a graphical editor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class GenericModelEditor extends GraphicalEditorWithPalette {
+
+ private Object model;
+ private boolean savePreviouslyNeeded = false;
+ private KeyHandler sharedKeyHandler;
+ private PaletteRoot root;
+ private OverviewOutlinePage overviewOutlinePage;
+
+ public GenericModelEditor() {
+ setEditDomain(new DefaultEditDomain(this));
+ }
+
+ protected void setModel(Object model) {
+ this.model = model;
+ }
+
+ protected Object getModel() {
+ return model;
+ }
+
+ protected void createActions() {
+ super.createActions();
+ ActionRegistry registry = getActionRegistry();
+
+ IAction action = new DirectEditAction((IWorkbenchPart) this);
+ registry.registerAction(action);
+ getSelectionActions().add(action.getId());
+
+ action = new AlignmentAction((IWorkbenchPart) this,
+ PositionConstants.LEFT);
+ registry.registerAction(action);
+ getSelectionActions().add(action.getId());
+
+ action = new AlignmentAction((IWorkbenchPart) this,
+ PositionConstants.CENTER);
+ registry.registerAction(action);
+ getSelectionActions().add(action.getId());
+
+ action = new AlignmentAction((IWorkbenchPart) this,
+ PositionConstants.RIGHT);
+ registry.registerAction(action);
+ getSelectionActions().add(action.getId());
+
+ action = new AlignmentAction((IWorkbenchPart) this,
+ PositionConstants.TOP);
+ registry.registerAction(action);
+ getSelectionActions().add(action.getId());
+
+ action = new AlignmentAction((IWorkbenchPart) this,
+ PositionConstants.MIDDLE);
+ registry.registerAction(action);
+ getSelectionActions().add(action.getId());
+
+ action = new AlignmentAction((IWorkbenchPart) this,
+ PositionConstants.BOTTOM);
+ registry.registerAction(action);
+ getSelectionActions().add(action.getId());
+ }
+
+ public void commandStackChanged(EventObject event) {
+ if (isDirty()) {
+ if (!savePreviouslyNeeded()) {
+ setSavePreviouslyNeeded(true);
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ } else {
+ setSavePreviouslyNeeded(false);
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+ super.commandStackChanged(event);
+ }
+
+ protected void createOutputStream(OutputStream os) throws IOException {
+ ObjectOutputStream out = new ObjectOutputStream(os);
+ out.writeObject(model);
+ out.close();
+ }
+
+ protected void configureGraphicalViewer() {
+ super.configureGraphicalViewer();
+ getGraphicalViewer().setRootEditPart(new ScalableRootEditPart());
+ getGraphicalViewer().setEditPartFactory(createEditPartFactory());
+ getGraphicalViewer().setKeyHandler(
+ new GraphicalViewerKeyHandler(getGraphicalViewer())
+ .setParent(getCommonKeyHandler()));
+
+ ContextMenuProvider provider = new GenericContextMenuProvider(
+ getGraphicalViewer(), getActionRegistry());
+ getGraphicalViewer().setContextMenu(provider);
+ getSite().registerContextMenu("org.drools.ide.flow.editor.contextmenu",
+ provider, getGraphicalViewer());
+ }
+
+ protected abstract EditPartFactory createEditPartFactory();
+
+ protected void initializeGraphicalViewer() {
+ getGraphicalViewer().setContents(model);
+ }
+
+ public void doSave(IProgressMonitor monitor) {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ createOutputStream(out);
+ IFile file = ((IFileEditorInput) getEditorInput()).getFile();
+ file.setContents(new ByteArrayInputStream(out.toByteArray()), true,
+ false, monitor);
+ out.close();
+ getCommandStack().markSaveLocation();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void doSaveAs() {
+ SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow()
+ .getShell());
+ dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
+ dialog.open();
+ IPath path = dialog.getResult();
+
+ if (path == null) {
+ return;
+ }
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IFile file = workspace.getRoot().getFile(path);
+
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ public void execute(final IProgressMonitor monitor)
+ throws CoreException {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ createOutputStream(out);
+ file.create(new ByteArrayInputStream(out.toByteArray()),
+ true, monitor);
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ try {
+ new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell())
+ .run(false, true, op);
+ setInput(new FileEditorInput(file));
+ getCommandStack().markSaveLocation();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected KeyHandler getCommonKeyHandler() {
+ if (sharedKeyHandler == null) {
+ sharedKeyHandler = new KeyHandler();
+ sharedKeyHandler
+ .put(KeyStroke.getPressed(SWT.DEL, 127, 0),
+ getActionRegistry().getAction(
+ ActionFactory.DELETE.getId()));
+ sharedKeyHandler.put(KeyStroke.getPressed(SWT.F2, 0),
+ getActionRegistry().getAction(
+ GEFActionConstants.DIRECT_EDIT));
+ }
+ return sharedKeyHandler;
+ }
+
+ public boolean isDirty() {
+ return isSaveOnCloseNeeded();
+ }
+
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ public boolean isSaveOnCloseNeeded() {
+ return getCommandStack().isDirty();
+ }
+
+ private boolean savePreviouslyNeeded() {
+ return savePreviouslyNeeded;
+ }
+
+ private void setSavePreviouslyNeeded(boolean value) {
+ savePreviouslyNeeded = value;
+ }
+
+ protected PaletteRoot getPaletteRoot() {
+ if (root == null) {
+ root = createPalette();
+ }
+ return root;
+ }
+
+ protected abstract PaletteRoot createPalette();
+
+ protected void setInput(IEditorInput input) {
+ super.setInput(input);
+
+ IFile file = ((IFileEditorInput) input).getFile();
+ setPartName(file.getName());
+ try {
+ InputStream is = file.getContents(false);
+ createInputStream(is);
+ } catch (Exception e) {
+ DroolsIDEPlugin.log(e);
+ model = createModel();
+ }
+ }
+
+ protected void createInputStream(InputStream is) throws Exception {
+ ObjectInputStream ois = new ObjectInputStreamWithLoader(is, getClass()
+ .getClassLoader());
+ model = ois.readObject();
+ ois.close();
+ }
+
+ protected abstract Object createModel();
+
+ public Object getAdapter(Class type) {
+ if (type == IContentOutlinePage.class) {
+ return getOverviewOutlinePage();
+ }
+ if (type == ZoomManager.class) {
+ return ((ScalableRootEditPart) getGraphicalViewer()
+ .getRootEditPart()).getZoomManager();
+ }
+ return super.getAdapter(type);
+ }
+
+ protected OverviewOutlinePage getOverviewOutlinePage() {
+ if (null == overviewOutlinePage && null != getGraphicalViewer()) {
+ ScalableRootEditPart rootEditPart = (ScalableRootEditPart) getGraphicalViewer()
+ .getRootEditPart();
+ overviewOutlinePage = new OverviewOutlinePage(rootEditPart);
+ }
+ return overviewOutlinePage;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/ObjectInputStreamWithLoader.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/ObjectInputStreamWithLoader.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/ObjectInputStreamWithLoader.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,92 @@
+package org.drools.ide.flow.common.editor;
+/*
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.io.StreamCorruptedException;
+import java.lang.reflect.Array;
+
+/**
+ * Implementation of an ObjectInputStream that has a custom classloader.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ObjectInputStreamWithLoader extends ObjectInputStream {
+
+ private ClassLoader loader;
+
+ /**
+ * Loader must be non-null;
+ */
+ public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
+ throws IOException, StreamCorruptedException {
+ super(in);
+ if (loader == null) {
+ throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
+ }
+ this.loader = loader;
+ }
+
+ /**
+ * Make a primitive array class
+ */
+ private Class primitiveType(char type) {
+ switch (type) {
+ case 'B': return byte.class;
+ case 'C': return char.class;
+ case 'D': return double.class;
+ case 'F': return float.class;
+ case 'I': return int.class;
+ case 'J': return long.class;
+ case 'S': return short.class;
+ case 'Z': return boolean.class;
+ default: return null;
+ }
+ }
+
+ /**
+ * Use the given ClassLoader rather than using the system class
+ */
+ protected Class resolveClass(ObjectStreamClass classDesc)
+ throws IOException, ClassNotFoundException {
+ String cname = classDesc.getName();
+ if (cname.startsWith("[")) {
+ // An array
+ Class component = null; // component class
+ int dcount; // dimension
+ for (dcount=1; cname.charAt(dcount)=='['; dcount++);
+ if (cname.charAt(dcount) == 'L') {
+ String className = cname.substring(dcount+1, cname.length()-1);
+ component = loader.loadClass(className);
+ } else {
+ if (cname.length() != dcount + 1) {
+ throw new ClassNotFoundException(cname);// malformed
+ }
+ component = primitiveType(cname.charAt(dcount));
+ }
+ int dim[] = new int[dcount];
+ for (int i = 0; i < dcount; i++) {
+ dim[i]=0;
+ }
+ return Array.newInstance(component, dim).getClass();
+ }
+ return loader.loadClass(cname);
+ }
+}
+
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/OverviewOutlinePage.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/OverviewOutlinePage.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/OverviewOutlinePage.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,90 @@
+package org.drools.ide.flow.common.editor;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.draw2d.LightweightSystem;
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.Viewport;
+import org.eclipse.draw2d.parts.ScrollableThumbnail;
+import org.eclipse.draw2d.parts.Thumbnail;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.editparts.ScalableRootEditPart;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+/**
+ * Common implementation of an outline page.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class OverviewOutlinePage extends Page implements IContentOutlinePage {
+
+ private Canvas overview;
+ private ScalableRootEditPart rootEditPart;
+ private Thumbnail thumbnail;
+
+ public OverviewOutlinePage(ScalableRootEditPart rootEditPart) {
+ this.rootEditPart = rootEditPart;
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ }
+
+ public void createControl(Composite parent) {
+ overview = new Canvas(parent, SWT.NONE);
+ LightweightSystem lws = new LightweightSystem(overview);
+ thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
+ thumbnail.setBorder(new MarginBorder(3));
+ thumbnail.setSource(rootEditPart
+ .getLayer(LayerConstants.PRINTABLE_LAYERS));
+ lws.setContents(thumbnail);
+ }
+
+ public void dispose() {
+ if (null != thumbnail) {
+ thumbnail.deactivate();
+ }
+ super.dispose();
+ }
+
+ public Control getControl() {
+ return overview;
+ }
+
+ public ISelection getSelection() {
+ return StructuredSelection.EMPTY;
+ }
+
+ public void removeSelectionChangedListener(
+ ISelectionChangedListener listener) {
+ }
+
+ public void setFocus() {
+ if (getControl() != null) {
+ getControl().setFocus();
+ }
+ }
+
+ public void setSelection(ISelection selection) {
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/DefaultElementWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/DefaultElementWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/DefaultElementWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,205 @@
+package org.drools.ide.flow.common.editor.core;
+/*
+ * 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.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.TextPropertyDescriptor;
+
+/**
+ * Default wrapper of a model element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class DefaultElementWrapper implements IPropertySource, ElementWrapper, Serializable {
+
+ protected static IPropertyDescriptor[] descriptors;
+
+ public static final String NAME = "Name";
+ static {
+ descriptors = new IPropertyDescriptor[] {
+ new TextPropertyDescriptor(NAME, "Name"),
+ };
+ }
+
+ private Object element;
+ private Rectangle constraint;
+ private ProcessWrapper parent;
+ private List incomingConnections = new ArrayList();
+ private List outgoingConnections = new ArrayList();
+ private transient List listeners = new ArrayList();
+
+ protected void setElement(Object element) {
+ this.element = element;
+ }
+
+ public Object getElement() {
+ return element;
+ }
+
+ public void setConstraint(Rectangle constraint) {
+ this.constraint = constraint;
+ notifyListeners(CHANGE_CONSTRAINT);
+ }
+
+ public Rectangle getConstraint() {
+ return constraint;
+ }
+
+ public void setParent(ProcessWrapper parent) {
+ this.parent = parent;
+ }
+
+ protected ProcessWrapper getParent() {
+ return parent;
+ }
+
+ public List getOutgoingConnections() {
+ return Collections.unmodifiableList(outgoingConnections);
+ }
+
+ public List getIncomingConnections() {
+ return Collections.unmodifiableList(incomingConnections);
+ }
+
+ public void addIncomingConnection(ElementConnection connection) {
+ incomingConnections.add(connection);
+ internalAddIncomingConnection(connection);
+ notifyListeners(CHANGE_INCOMING_CONNECTIONS);
+ }
+
+ protected void internalAddIncomingConnection(ElementConnection connection) {
+ }
+
+ public void removeIncomingConnection(ElementConnection connection) {
+ incomingConnections.remove(connection);
+ internalRemoveIncomingConnection(connection);
+ notifyListeners(CHANGE_INCOMING_CONNECTIONS);
+ }
+
+ protected void internalRemoveIncomingConnection(ElementConnection connection) {
+ }
+
+ public void addOutgoingConnection(ElementConnection connection) {
+ outgoingConnections.add(connection);
+ internalAddOutgoingConnection(connection);
+ notifyListeners(CHANGE_OUTGOING_CONNECTIONS);
+ }
+
+ protected void internalAddOutgoingConnection(ElementConnection connection) {
+ }
+
+ public void removeOutgoingConnection(ElementConnection connection) {
+ outgoingConnections.remove(connection);
+ internalRemoveOutgoingConnection(connection);
+ notifyListeners(CHANGE_OUTGOING_CONNECTIONS);
+ }
+
+ protected void internalRemoveOutgoingConnection(ElementConnection connection) {
+ }
+
+ public void setName(String name) {
+ internalSetName(name);
+ notifyListeners(CHANGE_NAME);
+ }
+
+ protected void internalSetName(String name) {
+ }
+
+ public List getOutgoingConnections(int type) {
+ List result = new ArrayList();
+ for (Iterator it = outgoingConnections.iterator(); it.hasNext();) {
+ ElementConnection connection = (ElementConnection) it.next();
+ if (connection.getType() == type) {
+ result.add(connection);
+ }
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ public List getIncomingConnections(int type) {
+ List result = new ArrayList();
+ for (Iterator it = incomingConnections.iterator(); it.hasNext();) {
+ ElementConnection connection = (ElementConnection) it.next();
+ if (connection.getType() == type) {
+ result.add(connection);
+ }
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ public void addListener(ModelListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(ModelListener listener) {
+ listeners.remove(listener);
+ }
+
+ protected void notifyListeners(int change) {
+ ModelEvent event = new ModelEvent(change);
+ for (Iterator it = listeners.iterator(); it.hasNext();) {
+ ModelListener listener = (ModelListener) it.next();
+ listener.modelChanged(event);
+ }
+ }
+
+ private void readObject(ObjectInputStream aInputStream)
+ throws ClassNotFoundException, IOException {
+ aInputStream.defaultReadObject();
+ listeners = new ArrayList();
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ return descriptors;
+ }
+
+ public Object getEditableValue() {
+ return this;
+ }
+
+ public boolean isPropertySet(Object id) {
+ return true;
+ }
+
+ public Object getPropertyValue(Object id) {
+ if (NAME.equals(id)) {
+ return getName();
+ }
+ return null;
+ }
+
+ public void resetPropertyValue(Object id) {
+ if (NAME.equals(id)) {
+ setName("");
+ }
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ if (NAME.equals(id)) {
+ setName((String) value);
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnection.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnection.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnection.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,146 @@
+package org.drools.ide.flow.common.editor.core;
+/*
+ * 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.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+
+/**
+ * A connection between two model elements.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementConnection implements Serializable {
+
+ private static final long serialVersionUID = 3690752912666015536L;
+
+ public static final int CHANGE_BENDPOINTS = 1;
+
+ private ElementWrapper source;
+ private ElementWrapper target;
+ private int type;
+ private List bendpoints = new ArrayList();
+ private transient List listeners = new ArrayList();
+
+ public ElementConnection(int type) {
+ this.type = type;
+ }
+
+ public ElementConnection(ElementWrapper source, ElementWrapper target, int type) {
+ this(type);
+ if (source == null) {
+ throw new IllegalArgumentException("source is null");
+ }
+ if (target == null) {
+ throw new IllegalArgumentException("target is null");
+ }
+ this.source = source;
+ this.target = target;
+ }
+
+ public void disconnect() {
+ if (source == null) {
+ throw new IllegalStateException("Can't disconnect, source is null");
+ }
+ if (target == null) {
+ throw new IllegalStateException("Can't disconnect, target is null");
+ }
+ source.removeOutgoingConnection(this);
+ target.removeIncomingConnection(this);
+ source = null;
+ target = null;
+ }
+
+ public void connect(ElementWrapper source, ElementWrapper target) {
+ if (source == null) {
+ throw new IllegalArgumentException("source is null");
+ }
+ if (this.source != null) {
+ throw new IllegalStateException("The source of a connection cannot be changed");
+ }
+ if (target == null) {
+ throw new IllegalArgumentException("target is null");
+ }
+ if (this.target != null) {
+ throw new IllegalStateException("The target of a connection cannot be changed");
+ }
+ this.source = source;
+ this.target = target;
+ source.addOutgoingConnection(this);
+ target.addIncomingConnection(this);
+ }
+
+
+ public ElementWrapper getSource() {
+ return source;
+ }
+
+
+ public ElementWrapper getTarget() {
+ return target;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void addBendpoint(int index, Point point) {
+ bendpoints.add(index, point);
+ notifyListeners(CHANGE_BENDPOINTS);
+ }
+
+ public void removeBendpoint(int index) {
+ bendpoints.remove(index);
+ notifyListeners(CHANGE_BENDPOINTS);
+ }
+
+ public void replaceBendpoint(int index, Point point) {
+ bendpoints.set(index, point);
+ notifyListeners(CHANGE_BENDPOINTS);
+ }
+
+ public List getBendpoints() {
+ return bendpoints;
+ }
+
+ public void addListener(ModelListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(ModelListener listener) {
+ listeners.remove(listener);
+ }
+
+ protected void notifyListeners(int change) {
+ ModelEvent event = new ModelEvent(change);
+ for (Iterator it = listeners.iterator(); it.hasNext(); ) {
+ ModelListener listener = (ModelListener) it.next();
+ listener.modelChanged(event);
+ }
+ }
+
+ private void readObject(ObjectInputStream aInputStream)
+ throws ClassNotFoundException, IOException {
+ aInputStream.defaultReadObject();
+ listeners = new ArrayList();
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnectionFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnectionFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementConnectionFactory.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,39 @@
+package org.drools.ide.flow.common.editor.core;
+/*
+ * 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.
+ */
+
+/**
+ * Factory for creating element connections.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementConnectionFactory {
+
+ private int type;
+
+ public ElementConnectionFactory(int type) {
+ this.type = type;
+ }
+
+ public ElementConnection createElementConnection() {
+ ElementConnection connection = new ElementConnection(type);
+ return connection;
+ }
+
+ protected int getType() {
+ return this.type;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ElementWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,57 @@
+package org.drools.ide.flow.common.editor.core;
+/*
+ * 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.List;
+
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ * Wrapper of a model element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface ElementWrapper {
+
+ static final int CHANGE_INCOMING_CONNECTIONS = 1;
+ static final int CHANGE_OUTGOING_CONNECTIONS = 2;
+ static final int CHANGE_CONSTRAINT = 3;
+ static final int CHANGE_NAME = 4;
+
+ String getId();
+ String getName();
+ void setName(String name);
+
+ void setConstraint(Rectangle constraint);
+ Rectangle getConstraint();
+
+ void setParent(ProcessWrapper parent);
+
+ List getOutgoingConnections();
+ List getIncomingConnections();
+ void addIncomingConnection(ElementConnection connection);
+ void removeIncomingConnection(ElementConnection connection);
+ void addOutgoingConnection(ElementConnection connection);
+ void removeOutgoingConnection(ElementConnection connection);
+ boolean acceptsIncomingConnection(ElementConnection connection);
+ boolean acceptsOutgoingConnection(ElementConnection connection);
+ List getOutgoingConnections(int type);
+ List getIncomingConnections(int type);
+
+ void addListener(ModelListener listener);
+ void removeListener(ModelListener listener);
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelEvent.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelEvent.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelEvent.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,35 @@
+package org.drools.ide.flow.common.editor.core;
+/*
+ * 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.
+ */
+
+/**
+ * Event notifying a change in a model element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ModelEvent {
+
+ private int change;
+
+ public ModelEvent(int change) {
+ this.change = change;
+ }
+
+ public int getChange() {
+ return change;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelListener.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelListener.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ModelListener.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,27 @@
+package org.drools.ide.flow.common.editor.core;
+/*
+ * 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.
+ */
+
+/**
+ * A listener for model events.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface ModelListener {
+
+ void modelChanged(ModelEvent event);
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ProcessWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ProcessWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/ProcessWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,185 @@
+package org.drools.ide.flow.common.editor.core;
+/*
+ * 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.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.ruleflow.common.core.IProcess;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySource;
+import org.eclipse.ui.views.properties.TextPropertyDescriptor;
+
+/**
+ * A wrapper for process element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class ProcessWrapper implements IPropertySource, Serializable {
+
+ public static final int CHANGE_ELEMENTS = 1;
+
+ protected static IPropertyDescriptor[] descriptors;
+
+ public static final String NAME = "name";
+ public static final String VERSION = "version";
+ public static final String ID = "id";
+ static {
+ descriptors = new IPropertyDescriptor[] {
+ new TextPropertyDescriptor(NAME, "Name"),
+ new TextPropertyDescriptor(VERSION, "Version"),
+ new TextPropertyDescriptor(ID, "Id"),
+ };
+ }
+
+ private IProcess process;
+ private Map elements = new HashMap();
+ private transient List listeners = new ArrayList();
+
+ public ProcessWrapper() {
+ process = createProcess();
+ }
+
+ protected abstract IProcess createProcess();
+
+ public IProcess getProcess() {
+ return process;
+ }
+
+ public String getName() {
+ return process.getName() == null ? "" : process.getName();
+ }
+
+ public void setName(String name) {
+ process.setName(name);
+ }
+
+ public String getVersion() {
+ return process.getVersion() == null ? "" : process.getVersion();
+ }
+
+ public void setVersion(String version) {
+ process.setVersion(version);
+ }
+
+ public String getId() {
+ return process.getId();
+ }
+
+ public void setId(String id) {
+ process.setId(id);
+ }
+
+ public List getElements() {
+ return Collections.unmodifiableList(new ArrayList(elements.values()));
+ }
+
+ public ElementWrapper getElement(String id) {
+ return (ElementWrapper) elements.get(id);
+ }
+
+ public void addElement(ElementWrapper element) {
+ internalAddElement(element);
+ //id is set in methode above
+ elements.put(element.getId(), element);
+ notifyListeners(CHANGE_ELEMENTS);
+ }
+
+ protected abstract void internalAddElement(ElementWrapper element);
+
+ public void removeElement(ElementWrapper element) {
+ elements.remove(element.getId());
+ notifyListeners(CHANGE_ELEMENTS);
+ internalRemoveElement(element);
+ }
+
+ protected abstract void internalRemoveElement(ElementWrapper element);
+
+ public void addListener(ModelListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(ModelListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void notifyListeners(int change) {
+ ModelEvent event = new ModelEvent(change);
+ for (Iterator it = listeners.iterator(); it.hasNext(); ) {
+ ModelListener listener = (ModelListener) it.next();
+ listener.modelChanged(event);
+ }
+ }
+
+ private void readObject(ObjectInputStream aInputStream) throws ClassNotFoundException, IOException {
+ aInputStream.defaultReadObject();
+ listeners = new ArrayList();
+ }
+
+ public Object getEditableValue() {
+ return this;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ if (NAME.equals(id)) {
+ return getName();
+ }
+ if (VERSION.equals(id)) {
+ return getVersion();
+ }
+ if (ID.equals(id)) {
+ return getId() + "";
+ }
+ return null;
+ }
+
+ public boolean isPropertySet(Object id) {
+ return true;
+ }
+
+ public void resetPropertyValue(Object id) {
+ if (NAME.equals(id)) {
+ setName("");
+ }
+ if (VERSION.equals(id)) {
+ setVersion("");
+ }
+ if (ID.equals(id)) {
+ setId("");
+ }
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ if (NAME.equals(id)) {
+ setName((String) value);
+ } else if (VERSION.equals(id)) {
+ setVersion((String) value);
+ } else if (ID.equals(id)) {
+ setId((String) value);
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/AddElementCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/AddElementCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/AddElementCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,58 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for adding an element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class AddElementCommand extends Command {
+
+ private ElementWrapper child;
+ private ProcessWrapper parent;
+
+ public void execute() {
+ parent.addElement(child);
+ child.setParent(parent);
+ }
+
+ protected ProcessWrapper getParent() {
+ return parent;
+ }
+
+ protected ElementWrapper getChild() {
+ return child;
+ }
+
+ public void setChild(ElementWrapper newChild) {
+ child = newChild;
+ }
+
+ public void setParent(ProcessWrapper newParent) {
+ parent = newParent;
+ }
+
+ public void undo() {
+ parent.removeElement(child);
+ child.setParent(null);
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ChangeConstraintCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ChangeConstraintCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ChangeConstraintCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,49 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for changing a constraint.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ChangeConstraintCommand extends Command {
+
+ private ElementWrapper element;
+ private Rectangle constraint;
+ private Rectangle oldConstraint;
+
+ public void execute() {
+ element.setConstraint(constraint);
+ }
+
+ public void setConstraint(Rectangle rect) {
+ constraint = rect;
+ }
+
+ public void setElement(ElementWrapper element) {
+ this.element = element;
+ oldConstraint = element.getConstraint();
+ }
+
+ public void undo() {
+ element.setConstraint(oldConstraint);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/CreateBendpointCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/CreateBendpointCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/CreateBendpointCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,52 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for creating a bendpoint.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class CreateBendpointCommand extends Command {
+
+ private ElementConnection connection;
+ private Point location;
+ private int index;
+
+ public void execute() {
+ connection.addBendpoint(index, location);
+ }
+
+ public void setConnection(Object model) {
+ connection = (ElementConnection) model;
+ }
+
+ public void setIndex(int i) {
+ index = i;
+ }
+
+ public void setLocation(Point point) {
+ location = point;
+ }
+
+ public void undo() {
+ connection.removeBendpoint(index);
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteBendpointCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteBendpointCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteBendpointCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,50 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.commands.Command;
+
+
+/**
+ * A command for deleting a bendpoint.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DeleteBendpointCommand extends Command {
+
+ private ElementConnection connection;
+ private Point oldLocation;
+ private int index;
+
+ public void execute() {
+ oldLocation = (Point) connection.getBendpoints().get(index);
+ connection.removeBendpoint(index);
+ }
+
+ public void setConnectionModel(Object model) {
+ connection = (ElementConnection) model;
+ }
+
+ public void setIndex(int i) {
+ index = i;
+ }
+
+ public void undo() {
+ connection.addBendpoint(index, oldLocation);
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteConnectionCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteConnectionCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteConnectionCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,52 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for deleting a connection.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DeleteConnectionCommand extends Command {
+
+ private ElementWrapper source;
+ private ElementWrapper target;
+ private ElementConnection connection;
+
+ public void execute() {
+ connection.disconnect();
+ }
+
+ public void setSource(ElementWrapper action) {
+ source = action;
+ }
+
+ public void setTarget(ElementWrapper action) {
+ target = action;
+ }
+
+ public void setAntecedentTaskConnection(ElementConnection connection) {
+ this.connection = connection;
+ }
+
+ public void undo() {
+ connection.connect(source, target);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteElementCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteElementCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/DeleteElementCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,101 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * 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 org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for deleting an element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DeleteElementCommand extends Command {
+
+ private ElementWrapper child;
+ private ProcessWrapper parent;
+
+ private List incomingElementWrappers = new ArrayList();
+ private List outgoingElementWrappers = new ArrayList();
+ private List incomingConnections = new ArrayList();
+ private List outgoingConnections = new ArrayList();
+
+
+ private void deleteConnections(ElementWrapper element) {
+ for (Iterator it = element.getIncomingConnections().iterator(); it.hasNext(); ) {
+ ElementConnection connection = (ElementConnection) it.next();
+ incomingElementWrappers.add(connection.getSource());
+ incomingConnections.add(connection);
+ }
+ for (Iterator it = element.getOutgoingConnections().iterator(); it.hasNext(); ) {
+ ElementConnection connection = (ElementConnection) it.next();
+ outgoingElementWrappers.add(connection.getTarget());
+ outgoingConnections.add(connection);
+ }
+ for (Iterator it = incomingConnections.iterator(); it.hasNext(); ) {
+ ElementConnection connection = (ElementConnection) it.next();
+ connection.disconnect();
+ }
+ for (Iterator it = outgoingConnections.iterator(); it.hasNext(); ) {
+ ElementConnection connection = (ElementConnection) it.next();
+ connection.disconnect();
+ }
+ }
+
+ public void execute() {
+ deleteConnections(child);
+ parent.removeElement(child);
+ }
+
+ private void restoreConnections() {
+ int i = 0;
+ for (Iterator it = incomingConnections.iterator(); it.hasNext(); ) {
+ ElementConnection connection = (ElementConnection) it.next();
+ connection.connect((ElementWrapper) incomingElementWrappers.get(i), child);
+ i++;
+ }
+ i = 0;
+ for (Iterator it = outgoingConnections.iterator(); it.hasNext(); ) {
+ ElementConnection connection = (ElementConnection) it.next();
+ connection.connect(child, (ElementWrapper) outgoingElementWrappers.get(i));
+ i++;
+ }
+ incomingConnections.clear();
+ incomingElementWrappers.clear();
+ outgoingConnections.clear();
+ outgoingElementWrappers.clear();
+ }
+
+ public void setChild(ElementWrapper child) {
+ this.child = child;
+ }
+
+ public void setParent(ProcessWrapper parent) {
+ this.parent = parent;
+ }
+
+ public void undo() {
+ parent.addElement(child);
+ restoreConnections();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ElementConnectionCreateCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ElementConnectionCreateCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ElementConnectionCreateCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,87 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * 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.List;
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for creating an element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementConnectionCreateCommand extends Command {
+
+ private ElementConnection connection;
+ private ElementWrapper source;
+ private ElementWrapper target;
+
+ public boolean canExecute() {
+ if (source.equals(target)) {
+ return false;
+ }
+
+ // Check for existence of connection already
+ List connections = source.getOutgoingConnections(connection.getType());
+ for (Iterator it = connections.iterator(); it.hasNext(); ) {
+ ElementConnection conn = (ElementConnection) it.next();
+ if (conn.getTarget().equals(target)) {
+ return false;
+ }
+ }
+ return source.acceptsOutgoingConnection(connection)
+ && target != null && target.acceptsIncomingConnection(connection);
+ }
+
+ public void execute() {
+ connection.connect(source, target);
+ }
+
+ public ElementWrapper getSource() {
+ return source;
+ }
+
+ public ElementWrapper getTarget() {
+ return target;
+ }
+
+
+
+ public void redo() {
+ connection.connect(source, target);
+ }
+
+ public void setSource(ElementWrapper source) {
+ this.source = source;
+ }
+
+ public void setConnection(ElementConnection connection) {
+ this.connection = connection;
+ }
+
+ public void setTarget(ElementWrapper target) {
+ this.target = target;
+ }
+
+ public void undo() {
+ connection.disconnect();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/MoveBendpointCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/MoveBendpointCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/MoveBendpointCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,53 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for moving a bendpoint.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class MoveBendpointCommand extends Command {
+
+ private ElementConnection connection;
+ private Point oldLocation, newLocation;
+ private int index;
+
+ public void execute() {
+ oldLocation = (Point) connection.getBendpoints().get(index);
+ connection.replaceBendpoint(index, newLocation);
+ }
+
+ public void setConnectionModel(Object model) {
+ connection = (ElementConnection) model;
+ }
+
+ public void setIndex(int i) {
+ index = i;
+ }
+
+ public void setNewLocation(Point point) {
+ newLocation = point;
+ }
+
+ public void undo() {
+ connection.replaceBendpoint(index, oldLocation);
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionSourceCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionSourceCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionSourceCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,75 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * 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.List;
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for reconnecting the source of a connection.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ReconnectElementConnectionSourceCommand extends Command {
+
+ private ElementConnection connection;
+ private ElementWrapper target;
+ private ElementWrapper oldSource;
+ private ElementWrapper newSource;
+
+ public boolean canExecute() {
+ if (connection.getTarget().equals(newSource))
+ return false;
+
+ List connections = newSource.getOutgoingConnections(connection.getType());
+ for (int i = 0; i < connections.size(); i++) {
+ ElementConnection connection = ((ElementConnection)(connections.get(i)));
+ if (connection.getTarget().equals(target) && !connection.getSource().equals(oldSource))
+ return false;
+ }
+ return newSource.acceptsOutgoingConnection(connection); //XXX
+ }
+
+ public void execute() {
+ if (newSource != null) {
+ connection.disconnect();
+ connection.connect(newSource, target);
+ }
+ }
+
+ public void setSource(ElementWrapper source) {
+ this.newSource = source;
+ }
+
+ public void setConnection(ElementConnection connection) {
+ this.connection = connection;
+ this.target = connection.getTarget();
+ this.oldSource = connection.getSource();
+ }
+
+ public void undo() {
+ connection.disconnect();
+ connection.connect(oldSource, target);
+ }
+
+ public void redo() {
+ connection.disconnect();
+ connection.connect(newSource, target);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionTargetCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionTargetCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/ReconnectElementConnectionTargetCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,77 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * 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.List;
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for reconnecting the target of a connection.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ReconnectElementConnectionTargetCommand extends Command {
+
+ private ElementConnection connection;
+ private ElementWrapper oldTarget;
+ private ElementWrapper newTarget;
+ private ElementWrapper source;
+
+
+ public boolean canExecute() {
+ if (connection.getSource().equals(newTarget))
+ return false;
+
+ List connections = newTarget.getIncomingConnections(connection.getType());
+ for (Iterator it = connections.iterator(); it.hasNext(); ) {
+ ElementConnection connection = (ElementConnection) it.next();
+ if (connection.getSource().equals(source) && !connection.getTarget().equals(oldTarget))
+ return false;
+ }
+ return newTarget.acceptsIncomingConnection(connection);
+ }
+
+ public void execute() {
+ if (newTarget != null) {
+ connection.disconnect();
+ connection.connect(source, newTarget);
+ }
+ }
+
+ public void setTarget(ElementWrapper target) {
+ this.newTarget = target;
+ }
+
+ public void setConnection(ElementConnection connection) {
+ this.connection = connection;
+ this.source = connection.getSource();
+ this.oldTarget = connection.getTarget();
+ }
+
+ public void undo() {
+ connection.disconnect();
+ connection.connect(source, oldTarget);
+ }
+
+ public void redo() {
+ connection.disconnect();
+ connection.connect(source, newTarget);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/RenameElementCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/RenameElementCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/RenameElementCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,51 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for renaming an element.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RenameElementCommand extends Command {
+
+ private ElementWrapper source;
+ private String name;
+ private String oldName;
+
+ public void execute() {
+ source.setName(name);
+ }
+
+ public void setName(String string) {
+ name = string;
+ }
+
+ public void setOldName(String string) {
+ oldName = string;
+ }
+
+ public void setSource(ElementWrapper action) {
+ source = action;
+ }
+
+ public void undo() {
+ source.setName(oldName);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/SplitConnectionCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/SplitConnectionCommand.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/core/command/SplitConnectionCommand.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,87 @@
+package org.drools.ide.flow.common.editor.core.command;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A command for splitting a connection.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class SplitConnectionCommand extends Command {
+
+ private ProcessWrapper parent;
+ private ElementWrapper oldSource;
+ private ElementWrapper oldTarget;
+ private ElementConnection oldConnection;
+ private ElementConnection secondConnection;
+ private ElementWrapper newElement;
+
+ public void setNewSecondConnection(ElementConnection connection) {
+ if (connection == null) {
+ throw new IllegalArgumentException("new second connection cannot be null");
+ }
+ this.secondConnection = connection;
+ }
+
+ public void execute() {
+ if (secondConnection == null) {
+ throw new IllegalStateException("new second connection is still null");
+ }
+ oldConnection.disconnect();
+ parent.addElement(newElement);
+ newElement.setParent(parent);
+ oldConnection.connect(oldSource, newElement);
+ secondConnection.connect(newElement, oldTarget);
+ }
+
+ public void setParent(ProcessWrapper process) {
+ if (process == null) {
+ throw new IllegalArgumentException("process is null");
+ }
+ parent = process;
+ }
+
+ public void setElementConnection(ElementConnection connection) {
+ if (connection == null) {
+ throw new IllegalArgumentException("Element connection is null");
+ }
+ this.oldConnection = connection;
+ oldSource = connection.getSource();
+ oldTarget = connection.getTarget();
+ }
+
+ public void setNewElement(ElementWrapper newElement) {
+ if (newElement == null) {
+ throw new IllegalArgumentException("NewElement is null");
+ }
+ this.newElement = newElement;
+
+ }
+
+ public void undo() {
+ oldConnection.disconnect();
+ secondConnection.disconnect();
+ parent.removeElement(newElement);
+ newElement.setParent(null);
+ oldConnection.connect(oldSource, oldTarget);
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementCellEditorLocator.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementCellEditorLocator.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementCellEditorLocator.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,57 @@
+package org.drools.ide.flow.common.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.jface.viewers.CellEditor;
+
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+import org.eclipse.gef.tools.CellEditorLocator;
+
+/**
+ * A CellEditorLocator for elements.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementCellEditorLocator implements CellEditorLocator {
+
+ private Label label;
+
+ public ElementCellEditorLocator(Label label) {
+ setLabel(label);
+ }
+
+ public void relocate(CellEditor cellEditor) {
+ Text text = (Text) cellEditor.getControl();
+ Point pref = text.computeSize(-1, -1);
+ Rectangle rect = label.getTextBounds().getCopy();
+ label.translateToAbsolute(rect);
+ text.setBounds(rect.x - 1, rect.y - 1, pref.x + 1, pref.y + 1);
+ }
+
+ protected Label getLabel() {
+ return label;
+ }
+
+ protected void setLabel(Label label) {
+ this.label = label;
+ }
+
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementConnectionEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementConnectionEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementConnectionEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,101 @@
+package org.drools.ide.flow.common.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementConnectionFactory;
+import org.drools.ide.flow.common.editor.core.ModelEvent;
+import org.drools.ide.flow.common.editor.core.ModelListener;
+import org.drools.ide.flow.common.editor.policy.ConnectionBendpointEditPolicy;
+import org.drools.ide.flow.common.editor.policy.ConnectionEditPolicy;
+import org.eclipse.draw2d.AbsoluteBendpoint;
+import org.eclipse.draw2d.BendpointConnectionRouter;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PolygonDecoration;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
+
+/**
+ * Implementation of a connection EditPart.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementConnectionEditPart extends AbstractConnectionEditPart implements ModelListener {
+
+ protected void createEditPolicies() {
+ ConnectionEditPolicy connectionEditPolicy = new ConnectionEditPolicy();
+ connectionEditPolicy.setDefaultElementConnectionFactory(getDefaultElementConnectionFactory());
+ installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new ConnectionEndpointEditPolicy());
+ installEditPolicy(EditPolicy.CONNECTION_ROLE, connectionEditPolicy);
+ installEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE, new ConnectionBendpointEditPolicy());
+ }
+
+ protected ElementConnectionFactory getDefaultElementConnectionFactory() {
+ return new ElementConnectionFactory(0);
+ }
+
+ protected IFigure createFigure() {
+ PolylineConnection result = new PolylineConnection();
+ result.setConnectionRouter(new BendpointConnectionRouter());
+ result.setTargetDecoration(new PolygonDecoration());
+ return result;
+ }
+
+ public void setSelected(int value) {
+ super.setSelected(value);
+ if (value != EditPart.SELECTED_NONE) {
+ ((PolylineConnection)getFigure()).setLineWidth(2);
+ } else {
+ ((PolylineConnection)getFigure()).setLineWidth(1);
+ }
+ }
+
+ public void modelChanged(ModelEvent event) {
+ if (event.getChange() == ElementConnection.CHANGE_BENDPOINTS) {
+ refreshBendpoints();
+ }
+ }
+
+ public void activate() {
+ super.activate();
+ ((ElementConnection) getModel()).addListener(this);
+ }
+
+ public void deactivate() {
+ ((ElementConnection) getModel()).removeListener(this);
+ super.deactivate();
+ }
+
+ protected void refreshBendpoints() {
+ List bendpoints = ((ElementConnection) getModel()).getBendpoints();
+ List constraint = new ArrayList();
+ for (int i = 0; i < bendpoints.size(); i++) {
+ constraint.add(new AbsoluteBendpoint((Point) bendpoints.get(i)));
+ }
+ getConnectionFigure().setRoutingConstraint(constraint);
+ }
+
+ protected void refreshVisuals() {
+ refreshBendpoints();
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ElementEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,132 @@
+package org.drools.ide.flow.common.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.List;
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ModelEvent;
+import org.drools.ide.flow.common.editor.core.ModelListener;
+import org.drools.ide.flow.common.editor.editpart.figure.ElementFigure;
+import org.drools.ide.flow.common.editor.policy.ElementDirectEditManager;
+import org.drools.ide.flow.common.editor.policy.ElementDirectEditPolicy;
+import org.drools.ide.flow.common.editor.policy.ElementEditPolicy;
+import org.drools.ide.flow.common.editor.policy.ElementNodeEditPolicy;
+import org.eclipse.draw2d.ChopboxAnchor;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.NodeEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.tools.DirectEditManager;
+import org.eclipse.jface.viewers.TextCellEditor;
+
+/**
+ * Default implementation of an element EditPart.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class ElementEditPart extends AbstractGraphicalEditPart implements NodeEditPart, ModelListener {
+
+ private DirectEditManager manager;
+
+ protected void createEditPolicies() {
+ installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new ElementNodeEditPolicy());
+ installEditPolicy(EditPolicy.COMPONENT_ROLE, new ElementEditPolicy());
+ installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new ElementDirectEditPolicy());
+ }
+
+ protected List getModelSourceConnections() {
+ ElementWrapper task = (ElementWrapper) getModel();
+ return task.getOutgoingConnections();
+ }
+
+ protected List getModelTargetConnections() {
+ ElementWrapper task = (ElementWrapper) getModel();
+ return task.getIncomingConnections();
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
+ return new ChopboxAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
+ return new ChopboxAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(Request request) {
+ return new ChopboxAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(Request request) {
+ return new ChopboxAnchor(getFigure());
+ }
+
+ protected void refreshVisuals() {
+ ElementWrapper element = (ElementWrapper) getModel();
+ ElementFigure figure = (ElementFigure) getFigure();
+ figure.setText(element.getName());
+ if (element.getConstraint().width == -1) {
+ element.getConstraint().width = figure.getBounds().width;
+ }
+ if (element.getConstraint().height == -1) {
+ element.getConstraint().height = figure.getBounds().height;
+ }
+ ((GraphicalEditPart) getParent()).setLayoutConstraint(this, figure, element.getConstraint());
+ }
+
+ public void modelChanged(ModelEvent event) {
+ if (event.getChange() == ElementWrapper.CHANGE_INCOMING_CONNECTIONS) {
+ refreshTargetConnections();
+ } else if (event.getChange() == ElementWrapper.CHANGE_OUTGOING_CONNECTIONS) {
+ refreshSourceConnections();
+ } else if (event.getChange() == ElementWrapper.CHANGE_NAME) {
+ refreshVisuals();
+ } else if (event.getChange() == ElementWrapper.CHANGE_CONSTRAINT) {
+ refreshVisuals();
+ }
+ }
+
+ public void activate() {
+ super.activate();
+ ((ElementWrapper) getModel()).addListener(this);
+ }
+
+ public void deactivate() {
+ ((ElementWrapper) getModel()).removeListener(this);
+ super.deactivate();
+ }
+
+ public void performRequest(Request request) {
+ if (request.getType() == RequestConstants.REQ_DIRECT_EDIT) {
+ performDirectEdit();
+ } else {
+ super.performRequest(request);
+ }
+ }
+
+ private void performDirectEdit() {
+ if (manager == null) {
+ manager = new ElementDirectEditManager(this, TextCellEditor.class,
+ new ElementCellEditorLocator(((ElementFigure) getFigure()).getLabel()));
+ }
+ manager.show();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ProcessEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ProcessEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/ProcessEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,72 @@
+package org.drools.ide.flow.common.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.List;
+
+import org.drools.ide.flow.common.editor.core.ModelEvent;
+import org.drools.ide.flow.common.editor.core.ModelListener;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.drools.ide.flow.common.editor.policy.ProcessLayoutEditPolicy;
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.XYLayout;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
+
+/**
+ * Default implementation of a process EditPart.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ProcessEditPart extends AbstractGraphicalEditPart implements ModelListener {
+
+ protected IFigure createFigure() {
+ Figure f = new Figure();
+ f.setOpaque(true);
+ f.setLayoutManager(new XYLayout());
+ return f;
+ }
+
+ protected void createEditPolicies() {
+ installEditPolicy(EditPolicy.NODE_ROLE, null);
+ installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, null);
+ installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, null);
+ installEditPolicy(EditPolicy.LAYOUT_ROLE, new ProcessLayoutEditPolicy());
+ installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy());
+ }
+
+ protected List getModelChildren() {
+ return ((ProcessWrapper) getModel()).getElements();
+ }
+
+ public void activate() {
+ super.activate();
+ ((ProcessWrapper) getModel()).addListener(this);
+ }
+
+ public void deactivate() {
+ ((ProcessWrapper) getModel()).removeListener(this);
+ super.deactivate();
+ }
+
+ public void modelChanged(ModelEvent event) {
+ if (event.getChange() == ProcessWrapper.CHANGE_ELEMENTS) {
+ refreshChildren();
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/figure/ElementFigure.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/figure/ElementFigure.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/editpart/figure/ElementFigure.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,69 @@
+package org.drools.ide.flow.common.editor.editpart.figure;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.Panel;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Default implementation of an element Figure.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class ElementFigure extends Panel {
+
+ private boolean selected;
+ private Label label = new Label();
+
+ public ElementFigure() {
+ add(label);
+ customizeFigure();
+ setSize(80, 40);
+ }
+
+ public void setIcon(Image icon) {
+ label.setIcon(icon);
+ }
+
+ public void setText(String text) {
+ label.setText(text);
+ }
+
+ public Label getLabel() {
+ return label;
+ }
+
+ public void setBounds(Rectangle bounds) {
+ super.setBounds(bounds);
+ label.setBounds(bounds);
+ }
+
+ protected abstract void customizeFigure();
+
+ public void setSelected(boolean b) {
+ selected = b;
+ }
+
+ public boolean isSelected() {
+ return selected;
+ }
+
+ public void setFocus(boolean b) {
+ repaint();
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionBendpointEditPolicy.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionBendpointEditPolicy.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionBendpointEditPolicy.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,64 @@
+package org.drools.ide.flow.common.editor.policy;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.command.CreateBendpointCommand;
+import org.drools.ide.flow.common.editor.core.command.DeleteBendpointCommand;
+import org.drools.ide.flow.common.editor.core.command.MoveBendpointCommand;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.BendpointEditPolicy;
+import org.eclipse.gef.requests.BendpointRequest;
+
+/**
+ * Policy for bendpoints of connections.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ConnectionBendpointEditPolicy extends BendpointEditPolicy {
+
+ protected Command getCreateBendpointCommand(BendpointRequest request) {
+ Point point = request.getLocation();
+ getConnection().translateToRelative(point);
+
+ CreateBendpointCommand command = new CreateBendpointCommand();
+ command.setLocation(point);
+ command.setConnection(getHost().getModel());
+ command.setIndex(request.getIndex());
+
+ return command;
+ }
+
+ protected Command getDeleteBendpointCommand(BendpointRequest request) {
+ DeleteBendpointCommand command = new DeleteBendpointCommand();
+ command.setConnectionModel(getHost().getModel());
+ command.setIndex(request.getIndex());
+ return command;
+ }
+
+ protected Command getMoveBendpointCommand(BendpointRequest request) {
+ Point location = request.getLocation();
+ getConnection().translateToRelative(location);
+
+ MoveBendpointCommand command = new MoveBendpointCommand();
+ command.setConnectionModel(getHost().getModel());
+ command.setIndex(request.getIndex());
+ command.setNewLocation(location);
+
+ return command;
+
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionEditPolicy.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionEditPolicy.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ConnectionEditPolicy.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,101 @@
+package org.drools.ide.flow.common.editor.policy;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementConnectionFactory;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.drools.ide.flow.common.editor.core.command.DeleteConnectionCommand;
+import org.drools.ide.flow.common.editor.core.command.SplitConnectionCommand;
+import org.drools.ide.flow.common.editor.editpart.ElementConnectionEditPart;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gef.requests.GroupRequest;
+
+/**
+ * Policy for editing connections.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ConnectionEditPolicy extends org.eclipse.gef.editpolicies.ConnectionEditPolicy {
+
+ private ElementConnectionFactory elementConnectionFactory;
+
+
+ public void setDefaultElementConnectionFactory(ElementConnectionFactory factory) {
+ if (factory == null) {
+ throw new IllegalArgumentException("ElementConnectionFactory is null");
+ }
+ this.elementConnectionFactory = factory;
+ }
+
+ public ElementConnectionFactory getDefaultElementConnectionFactory() {
+ return elementConnectionFactory;
+ }
+
+ public Command getCommand(Request request) {
+ if (REQ_CREATE.equals(request.getType()))
+ return getSplitTransitionCommand(request);
+ return super.getCommand(request);
+ }
+
+ private PolylineConnection getConnectionFigure() {
+ return ((PolylineConnection) ((ElementConnectionEditPart) getHost()).getFigure());
+ }
+
+ protected Command getDeleteCommand(GroupRequest request) {
+ DeleteConnectionCommand cmd = new DeleteConnectionCommand();
+ ElementConnection connection = (ElementConnection) getHost().getModel();
+ cmd.setAntecedentTaskConnection(connection);
+ cmd.setSource(connection.getSource());
+ cmd.setTarget(connection.getTarget());
+ return cmd;
+ }
+
+ protected Command getSplitTransitionCommand(Request request) {
+ if (elementConnectionFactory == null) {
+ throw new IllegalStateException("DefaultElementConnectionFactory is null");
+ }
+ SplitConnectionCommand cmd = new SplitConnectionCommand();
+ cmd.setElementConnection(((ElementConnection) getHost().getModel()));
+ cmd.setNewSecondConnection(elementConnectionFactory.createElementConnection());
+ cmd.setParent(((ProcessWrapper) ((ElementConnectionEditPart) getHost())
+ .getSource().getParent().getModel()));
+ cmd.setNewElement(((ElementWrapper) ((CreateRequest) request).getNewObject()));
+ return cmd;
+ }
+
+ public EditPart getTargetEditPart(Request request) {
+ if (REQ_CREATE.equals(request.getType()))
+ return getHost();
+ return null;
+ }
+
+ public void eraseTargetFeedback(Request request) {
+ if (REQ_CREATE.equals(request.getType()))
+ getConnectionFigure().setLineWidth(1);
+ }
+
+ public void showTargetFeedback(Request request) {
+ if (REQ_CREATE.equals(request.getType()))
+ getConnectionFigure().setLineWidth(2);
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditManager.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditManager.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditManager.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,44 @@
+package org.drools.ide.flow.common.editor.policy;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.tools.CellEditorLocator;
+import org.eclipse.gef.tools.DirectEditManager;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Manager for directly editing elements.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementDirectEditManager extends DirectEditManager {
+
+ private ElementWrapper element;
+
+ public ElementDirectEditManager(GraphicalEditPart source, Class editorType,
+ CellEditorLocator locator) {
+ super(source, editorType, locator);
+ element = (ElementWrapper) source.getModel();
+ }
+
+ protected void initCellEditor() {
+ getCellEditor().setValue(element.getName());
+ Text text = (Text) getCellEditor().getControl();
+ text.selectAll();
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditPolicy.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditPolicy.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementDirectEditPolicy.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,45 @@
+package org.drools.ide.flow.common.editor.policy;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.command.RenameElementCommand;
+import org.drools.ide.flow.common.editor.editpart.figure.ElementFigure;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.DirectEditPolicy;
+import org.eclipse.gef.requests.DirectEditRequest;
+
+/**
+ * Policy for directly editing elements.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementDirectEditPolicy extends DirectEditPolicy {
+
+ protected Command getDirectEditCommand(DirectEditRequest request) {
+ RenameElementCommand cmd = new RenameElementCommand();
+ cmd.setSource((ElementWrapper) getHost().getModel());
+ cmd.setOldName(((ElementWrapper) getHost().getModel()).getName());
+ cmd.setName((String) request.getCellEditor().getValue());
+ return cmd;
+ }
+
+ protected void showCurrentEditValue(DirectEditRequest request) {
+ String value = (String) request.getCellEditor().getValue();
+ ((ElementFigure) getHostFigure()).setText(value);
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementEditPolicy.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementEditPolicy.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementEditPolicy.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,40 @@
+package org.drools.ide.flow.common.editor.policy;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.drools.ide.flow.common.editor.core.command.DeleteElementCommand;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.ComponentEditPolicy;
+import org.eclipse.gef.requests.GroupRequest;
+
+/**
+ * Policy for editing elements.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementEditPolicy extends ComponentEditPolicy {
+
+ protected Command createDeleteCommand(GroupRequest deleteRequest) {
+ ProcessWrapper parent = (ProcessWrapper) getHost().getParent().getModel();
+ DeleteElementCommand deleteCmd = new DeleteElementCommand();
+ deleteCmd.setParent(parent);
+ deleteCmd.setChild((ElementWrapper) (getHost().getModel()));
+ return deleteCmd;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementNodeEditPolicy.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementNodeEditPolicy.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ElementNodeEditPolicy.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,77 @@
+package org.drools.ide.flow.common.editor.policy;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.command.ElementConnectionCreateCommand;
+import org.drools.ide.flow.common.editor.core.command.ReconnectElementConnectionSourceCommand;
+import org.drools.ide.flow.common.editor.core.command.ReconnectElementConnectionTargetCommand;
+import org.drools.ide.flow.common.editor.editpart.ElementEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
+import org.eclipse.gef.requests.CreateConnectionRequest;
+import org.eclipse.gef.requests.ReconnectRequest;
+
+/**
+ * Policy for editing an element node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ElementNodeEditPolicy extends GraphicalNodeEditPolicy {
+
+ protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
+ ElementConnectionCreateCommand cmd =
+ (ElementConnectionCreateCommand) request.getStartCommand();
+ cmd.setConnection((ElementConnection) request.getNewObject());
+ cmd.setTarget(getElement());
+ return cmd;
+ }
+
+ protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
+ ElementConnectionCreateCommand cmd =
+ new ElementConnectionCreateCommand();
+ cmd.setConnection((ElementConnection) request.getNewObject());
+ cmd.setSource(getElement());
+ request.setStartCommand(cmd);
+ return cmd;
+ }
+
+ protected ElementEditPart getActivityPart() {
+ return (ElementEditPart) getHost();
+ }
+
+ protected ElementWrapper getElement() {
+ return (ElementWrapper) getHost().getModel();
+ }
+
+ protected Command getReconnectSourceCommand(ReconnectRequest request) {
+ ReconnectElementConnectionSourceCommand cmd
+ = new ReconnectElementConnectionSourceCommand();
+ cmd.setConnection((ElementConnection) request.getConnectionEditPart().getModel());
+ cmd.setSource(getElement());
+ return cmd;
+ }
+
+ protected Command getReconnectTargetCommand(ReconnectRequest request) {
+ ReconnectElementConnectionTargetCommand cmd
+ = new ReconnectElementConnectionTargetCommand();
+ cmd.setConnection((ElementConnection) request.getConnectionEditPart().getModel());
+ cmd.setTarget(getElement());
+ return cmd;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ProcessLayoutEditPolicy.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ProcessLayoutEditPolicy.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/editor/policy/ProcessLayoutEditPolicy.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,63 @@
+package org.drools.ide.flow.common.editor.policy;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.drools.ide.flow.common.editor.core.command.AddElementCommand;
+import org.drools.ide.flow.common.editor.core.command.ChangeConstraintCommand;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
+import org.eclipse.gef.requests.CreateRequest;
+
+/**
+ * Policy for performing layout of a process.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ProcessLayoutEditPolicy extends XYLayoutEditPolicy {
+
+ protected Command getCreateCommand(CreateRequest request) {
+ AddElementCommand command = new AddElementCommand();
+ command.setParent((ProcessWrapper) getHost().getModel());
+ ElementWrapper element = (ElementWrapper) request.getNewObject();
+ element.setConstraint((Rectangle) getConstraintFor(request));
+ command.setChild(element);
+ return command;
+ }
+
+ protected Command getDeleteDependantCommand(Request request) {
+ return null;
+ }
+
+ protected Command createAddCommand(EditPart child, Object constraint) {
+ ElementWrapper element = (ElementWrapper) child.getModel();
+ AddElementCommand add = new AddElementCommand();
+ add.setParent((ProcessWrapper) getHost().getModel());
+ add.setChild(element);
+ return add;
+ }
+
+ protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
+ ChangeConstraintCommand command = new ChangeConstraintCommand();
+ command.setElement((ElementWrapper) child.getModel());
+ command.setConstraint((Rectangle)constraint);
+ return command;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IDataTypeEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IDataTypeEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IDataTypeEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,40 @@
+package org.drools.ide.flow.common.view.datatype.editor;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ruleflow.common.datatype.IDataType;
+
+/**
+ * An editor for a datatype.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface IDataTypeEditor {
+
+ void setDataType(IDataType dataType);
+
+ IDataType getDataType();
+
+ void reset();
+
+ void addListener(DataTypeListener listener);
+
+ void removeListener(DataTypeListener listener);
+
+ public interface DataTypeListener {
+ void dataTypeChanged(IDataType dataType);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/IEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,38 @@
+package org.drools.ide.flow.common.view.datatype.editor;
+/*
+ * 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.io.Serializable;
+
+import org.drools.ruleflow.common.datatype.IDataType;
+
+
+/**
+ * An editor for an object with a given datatype.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public interface IEditor {
+
+ void setDataType(IDataType dataType);
+
+ Serializable getValue();
+
+ void setValue(Serializable value);
+
+ void reset();
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/BooleanEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/BooleanEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/BooleanEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,75 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * 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.io.Serializable;
+
+import org.drools.ide.flow.common.view.datatype.editor.IEditor;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.drools.ruleflow.common.datatype.impl.type.BooleanDataType;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Default boolean editor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class BooleanEditor extends Composite implements IEditor {
+
+ private static final String[] TF = { "true", "false" };
+
+ private Combo combo;
+
+ public BooleanEditor(Composite parent) {
+ super(parent, SWT.NONE);
+ setLayout(new FillLayout());
+ combo = new Combo(this, SWT.READ_ONLY);
+ combo.setItems(TF);
+ combo.select(1);
+ }
+
+ public void setDataType(IDataType dataType) {
+ if (!(dataType instanceof BooleanDataType)) {
+ throw new IllegalArgumentException("Illegal data type " + dataType);
+ }
+ }
+
+ public Serializable getValue() {
+ return Boolean.valueOf(combo.getSelectionIndex() == 0);
+ }
+
+ public void setValue(Serializable value) {
+ if (value == null) {
+ combo.select(1);
+ } else if (value instanceof Boolean) {
+ combo.select(((Boolean) value).booleanValue() ? 0 : 1);
+ } else {
+ throw new IllegalArgumentException("Value must be a boolean: " + value);
+ }
+ }
+
+ public void reset() {
+ combo.select(1);
+ }
+
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ combo.setEnabled(enabled);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeCombo.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeCombo.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeCombo.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,96 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.datatype.IDataTypeRegistry;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Combobox for datatypes based on a datatype registry.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DataTypeCombo extends Composite {
+
+ private IDataTypeRegistry registry;
+ private ComboViewer dataTypeCombo;
+
+ public DataTypeCombo(Composite parent, int style, IDataTypeRegistry registry) {
+ super(parent, style);
+ this.registry = registry;
+ setLayout(new FillLayout());
+ dataTypeCombo = new ComboViewer(this, SWT.READ_ONLY);
+ dataTypeCombo.setLabelProvider(new LabelProvider() {
+ public String getText(Object element) {
+ return ((IDataTypeRegistry.IDataTypeInfo) element).getName();
+ }
+ });
+ dataTypeCombo.add(registry.getDataTypes().toArray(
+ new IDataTypeRegistry.IDataTypeInfo[0]));
+ }
+
+ private IDataTypeRegistry.IDataTypeInfo getSelectedTypeInfo() {
+ ISelection selection = dataTypeCombo.getSelection();
+ if (!selection.isEmpty()) {
+ return (IDataTypeRegistry.IDataTypeInfo)
+ ((StructuredSelection) selection).getFirstElement();
+ }
+ return null;
+ }
+
+ public void setDataType(IDataType dataType) {
+ if (dataType == null) {
+ dataTypeCombo.setSelection(null);
+ } else {
+ // TODO : check what happens if dataType not in combo
+ try {
+ dataTypeCombo.setSelection(new StructuredSelection(registry.getDataTypeInfo(dataType.getClass())));
+ } catch (IllegalArgumentException e) {
+ // "DataTypeInfo not found in registry: " + dataType.getClass()
+ DroolsIDEPlugin.log(e);
+ }
+ }
+ }
+
+ public IDataType getDataType() {
+ IDataTypeRegistry.IDataTypeInfo dataTypeInfo =
+ getSelectedTypeInfo();
+ return dataTypeInfo == null ? null :
+ dataTypeInfo.getDataTypeFactory().createDataType();
+ }
+
+ public void reset() {
+ dataTypeCombo.setSelection(null);
+ }
+
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ dataTypeCombo.getCombo().setEnabled(enabled);
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ dataTypeCombo.addSelectionChangedListener(listener);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeEditorComposite.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeEditorComposite.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/DataTypeEditorComposite.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,125 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * 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.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.datatype.IDataTypeRegistry;
+import org.drools.ide.flow.common.view.datatype.editor.IDataTypeEditor;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.drools.ruleflow.common.datatype.impl.type.UndefinedDataType;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Default editor for a datatype.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DataTypeEditorComposite extends Composite implements IDataTypeEditor.DataTypeListener {
+ private IDataTypeRegistry registry;
+ private IDataTypeEditor dataTypeEditor;
+ private List listeners = new ArrayList();
+
+ public DataTypeEditorComposite(Composite parent, int style, IDataTypeRegistry registry) {
+ super(parent, style);
+ this.registry = registry;
+ setLayout(new FillLayout());
+ dataTypeEditor = new EmptyEditor(this);
+ }
+ public void setDataType(IDataType dataType) {
+ if (dataType == null) {
+ reset();
+ } else {
+ // update data type editor
+ dataTypeEditor.removeListener(this);
+ ((Composite) dataTypeEditor).dispose();
+ dataTypeEditor = null;
+ Class editorClass = null;
+ try {
+ editorClass = registry.getDataTypeInfo(dataType.getClass()).getDataTypeEditorClass();
+ dataTypeEditor = (IDataTypeEditor) editorClass.getConstructor(
+ new Class[] { Composite.class }).newInstance(new Object[] { this });
+ } catch (IllegalArgumentException e) {
+ // "Could not find data type info for type " + dataType.getClass()
+ DroolsIDEPlugin.log(e);
+ } catch (InstantiationException e) {
+ // "Could not create editor for type " + editorClass
+ DroolsIDEPlugin.log(e);
+ } catch (NoSuchMethodException e) {
+ // "Could not create editor for type " + editorClass
+ DroolsIDEPlugin.log(e);
+ } catch (InvocationTargetException e) {
+ // "Could not create editor for type " + editorClass
+ DroolsIDEPlugin.log(e);
+ } catch (IllegalAccessException e) {
+ // "Could not create editor for type " + editorClass
+ DroolsIDEPlugin.log(e);
+ }
+
+ if (dataTypeEditor == null) {
+ dataTypeEditor = new EmptyEditor(this);
+ }
+ dataTypeEditor.addListener(this);
+ dataTypeEditor.setDataType(dataType);
+ ((Composite) dataTypeEditor).setBackground(getBackground());
+ layout();
+ }
+ }
+
+ public IDataType getDataType() {
+ return dataTypeEditor.getDataType();
+ }
+
+ public void reset() {
+ setDataType(UndefinedDataType.getInstance());
+ }
+
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ ((Composite) dataTypeEditor).setEnabled(enabled);
+ }
+
+ public void addListener(IDataTypeEditor.DataTypeListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeListener(IDataTypeEditor.DataTypeListener listener) {
+ listeners.remove(listener);
+ }
+
+ private void notifyListeners() {
+ IDataType dataType = getDataType();
+ for (Iterator it = listeners.iterator(); it.hasNext(); ) {
+ IDataTypeEditor.DataTypeListener listener = (IDataTypeEditor.DataTypeListener) it.next();
+ listener.dataTypeChanged(dataType);
+ }
+ }
+
+ public void dataTypeChanged(IDataType dataType) {
+ notifyListeners();
+ }
+
+ public void setBackground(Color color) {
+ super.setBackground(color);
+ ((Composite) dataTypeEditor).setBackground(color);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EditorComposite.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EditorComposite.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EditorComposite.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,97 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * 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.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.datatype.IDataTypeRegistry;
+import org.drools.ide.flow.common.view.datatype.editor.IEditor;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Container for an editor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class EditorComposite extends Composite {
+
+ private IDataTypeRegistry registry;
+ private IEditor editor;
+
+ public EditorComposite(Composite parent, int style, IDataTypeRegistry registry) {
+ super(parent, style);
+ this.registry = registry;
+ setLayout(new FillLayout());
+ editor = new EmptyEditor(this);
+ }
+
+ public void setDataType(IDataType type) {
+ ((Composite) editor).dispose();
+ if (type == null) {
+ editor = new EmptyEditor(this);
+ } else {
+ Class editorClass = null;
+ try {
+ editorClass = registry.getDataTypeInfo(type.getClass()).getValueEditorClass();
+ editor = (IEditor) editorClass.getConstructor(
+ new Class[] { Composite.class }).newInstance(new Object[] { this });
+ } catch (IllegalArgumentException e) {
+ // "Could not find data type info for type " + type.getClass()
+ DroolsIDEPlugin.log(e);
+ editor = new EmptyEditor(this);
+ } catch (InstantiationException e) {
+ // "Could not create editor for editor " + editorClass
+ DroolsIDEPlugin.log(e);
+ editor = new EmptyEditor(this);
+ } catch (NoSuchMethodException e) {
+ // "Could not create editor for editor " + editorClass
+ DroolsIDEPlugin.log(e);
+ editor = new EmptyEditor(this);
+ } catch (InvocationTargetException e) {
+ // "Could not create editor for editor " + editorClass
+ DroolsIDEPlugin.log(e);
+ editor = new EmptyEditor(this);
+ } catch (IllegalAccessException e) {
+ // "Could not create editor for editor " + editorClass
+ DroolsIDEPlugin.log(e);
+ editor = new EmptyEditor(this);
+ }
+ editor.setDataType(type);
+ layout();
+ }
+ }
+
+ public void setValue(Serializable value) {
+ editor.setValue(value);
+ }
+
+ public Serializable getValue() {
+ return editor.getValue();
+ }
+
+ public void reset() {
+ editor.reset();
+ }
+
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ ((Composite) editor).setEnabled(enabled);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EmptyEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EmptyEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/EmptyEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,79 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * 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.io.Serializable;
+
+import org.drools.ide.flow.common.view.datatype.editor.IDataTypeEditor;
+import org.drools.ide.flow.common.view.datatype.editor.IEditor;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * Default empty editor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class EmptyEditor extends Composite implements IEditor, IDataTypeEditor {
+
+ private IDataType dataType;
+ private Serializable value;
+ private Label label;
+
+ public EmptyEditor(Composite parent) {
+ super(parent, SWT.NONE);
+ setSize(0, 0);
+ setLayout(new FillLayout());
+ label = new Label(this, SWT.NONE);
+ }
+
+ public IDataType getDataType() {
+ return dataType;
+ }
+
+ public void setDataType(IDataType dataType) {
+ this.dataType = dataType;
+ }
+
+ public Serializable getValue() {
+ return value;
+ }
+
+ public void setValue(Serializable value) {
+ this.value = value;
+ }
+
+ public void reset() {
+ // do nothing
+ }
+
+ public void addListener(IDataTypeEditor.DataTypeListener listener) {
+ // do nothing
+ }
+
+ public void removeListener(IDataTypeEditor.DataTypeListener listener) {
+ // do nothing
+ }
+
+ public void setBackground(Color color) {
+ super.setBackground(color);
+ label.setBackground(color);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/FloatEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/FloatEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/FloatEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,80 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * 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.io.Serializable;
+
+import org.drools.ide.flow.common.view.datatype.editor.IEditor;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.drools.ruleflow.common.datatype.impl.type.FloatDataType;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Default float editor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class FloatEditor extends Composite implements IEditor {
+
+ private Text text;
+
+ public FloatEditor(Composite parent) {
+ super(parent, SWT.NONE);
+ setLayout(new FillLayout());
+ text = new Text(this, SWT.NONE);
+ }
+
+ public void setDataType(IDataType dataType) {
+ if (!(dataType instanceof FloatDataType)) {
+ throw new IllegalArgumentException("Illegal data type " + dataType);
+ }
+ }
+
+ public Serializable getValue() throws IllegalArgumentException {
+ String valueString = text.getText();
+ if ("".equals(valueString)) {
+ return null;
+ }
+ try {
+ return new Float(valueString);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("The value " + valueString
+ + " is not a valid float.");
+ }
+ }
+
+ public void setValue(Serializable value) {
+ if (value == null) {
+ text.setText("");
+ } else if (value instanceof Float) {
+ text.setText(((Float) value).toString());
+ } else {
+ throw new IllegalArgumentException("Value must be a float: " + value);
+ }
+ }
+
+ public void reset() {
+ text.setText("");
+ }
+
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ text.setEnabled(enabled);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/IntegerEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/IntegerEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/IntegerEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,80 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * 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.io.Serializable;
+
+import org.drools.ide.flow.common.view.datatype.editor.IEditor;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.drools.ruleflow.common.datatype.impl.type.IntegerDataType;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Default integer editor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class IntegerEditor extends Composite implements IEditor {
+
+ private Text text;
+
+ public IntegerEditor(Composite parent) {
+ super(parent, SWT.NONE);
+ setLayout(new FillLayout());
+ text = new Text(this, SWT.NONE);
+ }
+
+ public void setDataType(IDataType dataType) {
+ if (!(dataType instanceof IntegerDataType)) {
+ throw new IllegalArgumentException("Illegal data type " + dataType);
+ }
+ }
+
+ public Serializable getValue() {
+ String valueString = text.getText();
+ if ("".equals(valueString)) {
+ return null;
+ }
+ try {
+ return new Integer(valueString);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("The value " + valueString
+ + " is not a valid integer.");
+ }
+ }
+
+ public void setValue(Serializable value) {
+ if (value == null) {
+ text.setText("");
+ } else if (value instanceof Integer) {
+ text.setText(((Integer) value).toString());
+ } else {
+ throw new IllegalArgumentException("Value must be an integer: " + value);
+ }
+ }
+
+ public void reset() {
+ text.setText("");
+ }
+
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ text.setEnabled(enabled);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/StringEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/StringEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/datatype/editor/impl/StringEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,71 @@
+package org.drools.ide.flow.common.view.datatype.editor.impl;
+/*
+ * 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.io.Serializable;
+
+import org.drools.ide.flow.common.view.datatype.editor.IEditor;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.drools.ruleflow.common.datatype.impl.type.StringDataType;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Default string editor.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class StringEditor extends Composite implements IEditor {
+
+ private Text text;
+
+ public StringEditor(Composite parent) {
+ super(parent, SWT.NONE);
+ setLayout(new FillLayout());
+ text = new Text(this, SWT.NONE);
+ }
+
+ public void setDataType(IDataType dataType) {
+ if (!(dataType instanceof StringDataType)) {
+ throw new IllegalArgumentException("Illegal data type " + dataType);
+ }
+ }
+
+ public Serializable getValue() {
+ return text.getText();
+ }
+
+ public void setValue(Serializable value) {
+ if (value == null) {
+ text.setText("");
+ } else if (value instanceof String) {
+ text.setText(value == null ? "" : (String) value);
+ } else {
+ throw new IllegalArgumentException("Value must be a string: " + value);
+ }
+ }
+
+ public void reset() {
+ text.setText("");
+ }
+
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ text.setEnabled(enabled);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/BeanDialogCellEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/BeanDialogCellEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/BeanDialogCellEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,60 @@
+package org.drools.ide.flow.common.view.property;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.jface.viewers.DialogCellEditor;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Cell editor for a JavaBean.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class BeanDialogCellEditor extends DialogCellEditor {
+
+ public BeanDialogCellEditor(Composite parent) {
+ super(parent);
+ }
+
+ protected Object openDialogBox(Control cellEditorWindow) {
+ EditBeanDialog dialog = createDialog(cellEditorWindow.getShell());
+ Object value = getValue();
+ if (value != null) {
+ dialog.setValue(value);
+ }
+ int result = dialog.open();
+ if (result == Window.CANCEL) {
+ return null;
+ }
+ return dialog.getValue();
+ }
+
+ protected abstract EditBeanDialog createDialog(Shell shell);
+
+ protected void updateContents(Object value) {
+ getDefaultLabel().setText(getLabelText(value));
+ }
+
+ protected String getLabelText(Object value) {
+ if (value == null) {
+ return "";
+ }
+ return value.toString();
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditBeanDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditBeanDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditBeanDialog.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,66 @@
+package org.drools.ide.flow.common.view.property;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog for editing a JavaBean.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class EditBeanDialog extends Dialog {
+
+ private String title;
+ private Object value;
+
+ protected EditBeanDialog(Shell parentShell, String title) {
+ super(parentShell);
+ this.title = title;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(title);
+ }
+
+ protected Point getInitialSize() {
+ return new Point(400, 200);
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ protected void okPressed() {
+ try {
+ value = updateValue(value);
+ super.okPressed();
+ } catch (IllegalArgumentException e) {
+ // value could not be set, ignoring ok
+ }
+ }
+
+ protected abstract Object updateValue(Object value);
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditListDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditListDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/EditListDialog.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,177 @@
+package org.drools.ide.flow.common.view.property;
+/*
+ * 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.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog for editing a list.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class EditListDialog extends EditBeanDialog {
+
+ private Class editItemDialogClass;
+ private List newList;
+ private ListViewer listViewer;
+ private Button removeButton;
+ private Button editButton;
+
+ protected EditListDialog(Shell parentShell, String title, Class editItemDialogClass) {
+ super(parentShell, title);
+ this.editItemDialogClass = editItemDialogClass;
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ composite.setLayout(gridLayout);
+
+ listViewer = new ListViewer(composite, SWT.SINGLE);
+ listViewer.add(newList.toArray());
+ listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ removeButton.setEnabled(!event.getSelection().isEmpty());
+ editButton.setEnabled(!event.getSelection().isEmpty());
+ }
+ });
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.verticalSpan = 3;
+ listViewer.getList().setLayoutData(gridData);
+
+ Button addButton = new Button(composite, SWT.NONE);
+ addButton.setText("Add");
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.BEGINNING;
+ addButton.setLayoutData(gridData);
+ addButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ addItem();
+ }
+ });
+
+ removeButton = new Button(composite, SWT.NONE);
+ removeButton.setText("Remove");
+ removeButton.setEnabled(false);
+ gridData = new GridData();
+ gridData.verticalAlignment = GridData.BEGINNING;
+ removeButton.setLayoutData(gridData);
+ removeButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ removeItem();
+ }
+ });
+
+ editButton = new Button(composite, SWT.NONE);
+ editButton.setText("Edit");
+ editButton.setEnabled(false);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.verticalAlignment = GridData.BEGINNING;
+ editButton.setLayoutData(gridData);
+ editButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ editItem();
+ }
+ });
+
+ return composite;
+ }
+
+ public void setValue(Object value) {
+ super.setValue(value);
+ this.newList = new ArrayList((List) value);
+ }
+
+ protected Object updateValue(Object value) {
+ return newList;
+ }
+
+ private void addItem() {
+ EditBeanDialog dialog = createEditItemDialog();
+ dialog.setValue(createItem());
+ int code = dialog.open();
+ Object result = dialog.getValue();
+ if (code != CANCEL) {
+ newList.add(result);
+ listViewer.add(result);
+ }
+ }
+
+ protected abstract Object createItem();
+
+ private void editItem() {
+ EditBeanDialog dialog = createEditItemDialog();
+ Iterator iterator = ((StructuredSelection) listViewer.getSelection()).iterator();
+ if (iterator.hasNext()) {
+ dialog.setValue(iterator.next());
+ int code = dialog.open();
+ Object result = dialog.getValue();
+ if (code != CANCEL) {
+ listViewer.update(result, null);
+ }
+ }
+ }
+
+ private void removeItem() {
+ Iterator iterator = ((StructuredSelection) listViewer.getSelection()).iterator();
+ // single selection only allowed
+ if (iterator.hasNext()) {
+ Object item = iterator.next();
+ newList.remove(item);
+ listViewer.remove(item);
+ }
+ }
+
+ private EditBeanDialog createEditItemDialog() {
+ try {
+ return (EditBeanDialog) editItemDialogClass.getConstructor(
+ new Class[] { Shell.class }).newInstance(
+ new Object[] { getShell() });
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/ListPropertyDescriptor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/ListPropertyDescriptor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/common/view/property/ListPropertyDescriptor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,55 @@
+package org.drools.ide.flow.common.view.property;
+/*
+ * 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.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+/**
+ * Property descriptor for a list.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ListPropertyDescriptor extends PropertyDescriptor {
+
+ private Class cellEditorClass;
+
+ public ListPropertyDescriptor(Object id, String displayName, Class cellEditorClass) {
+ super(id, displayName);
+ this.cellEditorClass = cellEditorClass;
+ }
+
+ public CellEditor createPropertyEditor(Composite parent) {
+ try {
+ CellEditor editor = (CellEditor) cellEditorClass.getConstructor(new Class[] { Composite.class }).newInstance(new Object[] { parent });
+ if (getValidator() != null) {
+ editor.setValidator(getValidator());
+ }
+ return editor;
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFilePage.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFilePage.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFilePage.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,73 @@
+package org.drools.ide.flow.ruleflow;
+/*
+ * 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.io.InputStream;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * Page for creating a new RuleFlow file.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class NewRuleFlowFilePage extends WizardNewFileCreationPage {
+
+ private IWorkbench workbench;
+
+ public NewRuleFlowFilePage(IWorkbench workbench, IStructuredSelection selection) {
+ super("createRuleFlowPage", selection);
+ setTitle("Create RuleFlow File");
+ setDescription("Create a new RuleFlow file");
+ this.workbench = workbench;
+ }
+
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ setPageComplete(true);
+ }
+
+ public boolean finish() {
+ String fileName = getFileName();
+ if (!fileName.endsWith(".rf")) {
+ setFileName(fileName + ".rf");
+ }
+ org.eclipse.core.resources.IFile newFile = createNewFile();
+ if (newFile == null)
+ return false;
+ try {
+ IWorkbenchWindow dwindow = workbench.getActiveWorkbenchWindow();
+ org.eclipse.ui.IWorkbenchPage page = dwindow.getActivePage();
+ if (page != null)
+ IDE.openEditor(page, newFile, true);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ protected InputStream getInitialContents() {
+ String s = "org/drools/ide/flow/ruleflow/SampleRuleFlow.rf.template";
+ return getClass().getClassLoader().getResourceAsStream(s);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFileWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFileWizard.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/NewRuleFlowFileWizard.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,49 @@
+package org.drools.ide.flow.ruleflow;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * Wizard for creating a new RuleFlow file.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class NewRuleFlowFileWizard extends Wizard implements INewWizard {
+
+ private IWorkbench workbench;
+ private IStructuredSelection selection;
+ private NewRuleFlowFilePage mainPage;
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+ this.selection = selection;
+ setWindowTitle("New RuleFlow File");
+ }
+
+ public void addPages() {
+ mainPage = new NewRuleFlowFilePage(workbench, selection);
+ addPage(mainPage);
+ }
+
+ public boolean performFinish() {
+ return mainPage.finish();
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/SampleRuleFlow.rf.template
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/SampleRuleFlow.rf.template (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/SampleRuleFlow.rf.template 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,44 @@
+<org.drools.ide.flow.ruleflow.core.WorkflowProcessWrapper id="1" serialization="custom">
+ <org.drools.ide.flow.common.editor.core.ProcessWrapper>
+ <default>
+ <elements id="2">
+ <entry>
+ <string>1-Wrapper</string>
+ <org.drools.ide.flow.ruleflow.core.StartNodeWrapper id="3" serialization="custom">
+ <org.drools.ide.flow.common.editor.core.DefaultElementWrapper>
+ <default>
+ <constraint id="4">
+ <x>100</x>
+ <y>100</y>
+ <width>80</width>
+ <height>40</height>
+ </constraint>
+ <element class="org.drools.ruleflow.core.impl.StartNode" id="5">
+ <id>1</id>
+ <name>Start</name>
+ <incomingConnections id="6"/>
+ <outgoingConnections id="7"/>
+ </element>
+ <incomingConnections id="8"/>
+ <outgoingConnections id="9"/>
+ </default>
+ </org.drools.ide.flow.common.editor.core.DefaultElementWrapper>
+ </org.drools.ide.flow.ruleflow.core.StartNodeWrapper>
+ </entry>
+ </elements>
+ <process class="org.drools.ruleflow.core.impl.RuleFlowProcess" id="10">
+ <nodes id="11">
+ <entry>
+ <long>1</long>
+ <org.drools.ruleflow.core.impl.StartNode reference="5"/>
+ </entry>
+ </nodes>
+ <variables id="12"/>
+ <lastNodeId>1</lastNodeId>
+ <id>0</id>
+ <name>flow</name>
+ <type>Workflow</type>
+ </process>
+ </default>
+ </org.drools.ide.flow.common.editor.core.ProcessWrapper>
+</org.drools.ide.flow.ruleflow.core.WorkflowProcessWrapper>
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,56 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ruleflow.core.IConnection;
+import org.drools.ruleflow.core.INode;
+import org.drools.ruleflow.core.impl.Connection;
+
+/**
+ * Wrapper for a connection.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ConnectionWrapper extends ElementConnection {
+
+ private static final long serialVersionUID = 4049352037223445809L;
+
+ private IConnection connection;
+
+ public ConnectionWrapper(int type) {
+ super(type);
+ }
+
+ public ConnectionWrapper(NodeWrapper source, NodeWrapper target, int type) {
+ super(source, target, type);
+ }
+
+ public void disconnect() {
+ super.disconnect();
+ connection.terminate();
+ connection = null;
+ }
+
+ public void connect(ElementWrapper source, ElementWrapper target) {
+ super.connect(source, target);
+ INode from = ((NodeWrapper) getSource()).getNode();
+ INode to = ((NodeWrapper) getTarget()).getNode();
+ int type = getType();
+ connection = new Connection(from, to, type);
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapperFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapperFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/ConnectionWrapperFactory.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,37 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementConnectionFactory;
+
+/**
+ * Factory for creating a connection wrapper.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ConnectionWrapperFactory extends ElementConnectionFactory {
+
+ public ConnectionWrapperFactory(int type) {
+ super(type);
+ }
+
+ public ElementConnection createElementConnection() {
+ ConnectionWrapper connection = new ConnectionWrapper(getType());
+ return connection;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/EndNodeWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/EndNodeWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/EndNodeWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,47 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ruleflow.core.IEndNode;
+import org.drools.ruleflow.core.impl.EndNode;
+
+/**
+ * Wrapper for an end node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class EndNodeWrapper extends NodeWrapper {
+
+ private static final long serialVersionUID = 3617855270152385336L;
+
+ public EndNodeWrapper() {
+ setNode(new EndNode());
+ getEndNode().setName("End");
+ }
+
+ public IEndNode getEndNode() {
+ return (IEndNode) getNode();
+ }
+
+ public boolean acceptsIncomingConnection(ElementConnection connection) {
+ return getIncomingConnections().isEmpty();
+ }
+
+ public boolean acceptsOutgoingConnection(ElementConnection connection) {
+ return false;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/JoinWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/JoinWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/JoinWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,88 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.DefaultElementWrapper;
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ruleflow.core.IConnection;
+import org.drools.ruleflow.core.IJoin;
+import org.drools.ruleflow.core.impl.Join;
+import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+
+/**
+ * Wrapper for a join node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class JoinWrapper extends NodeWrapper {
+
+ private static final long serialVersionUID = 3258415019233588272L;
+ private static IPropertyDescriptor[] descriptors;
+
+ public static final String TYPE = "type";
+ static {
+ descriptors = new IPropertyDescriptor[DefaultElementWrapper.descriptors.length + 1];
+ System.arraycopy(DefaultElementWrapper.descriptors, 0, descriptors, 0, DefaultElementWrapper.descriptors.length);
+ descriptors[descriptors.length - 1] =
+ new ComboBoxPropertyDescriptor(TYPE, "Type", new String[] { "", "AND", "XOR" });
+ }
+
+ public JoinWrapper() {
+ setNode(new Join());
+ getJoin().setName("Join");
+ }
+
+ public IJoin getJoin() {
+ return (IJoin) getNode();
+ }
+
+ public boolean acceptsIncomingConnection(ElementConnection connection) {
+ return true;
+ }
+
+ public boolean acceptsOutgoingConnection(ElementConnection connection) {
+ return connection.getType() == IConnection.TYPE_NORMAL
+ && getOutgoingConnections().isEmpty();
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ if (TYPE.equals(id)) {
+ return new Integer(getJoin().getType());
+ }
+ return super.getPropertyValue(id);
+ }
+
+ public void resetPropertyValue(Object id) {
+ if (TYPE.equals(id)) {
+ getJoin().setType(IJoin.TYPE_UNDEFINED);
+ } else {
+ super.resetPropertyValue(id);
+ }
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ if (TYPE.equals(id)) {
+ getJoin().setType(((Integer) value).intValue());
+ } else {
+ super.setPropertyValue(id, value);
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/NodeWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/NodeWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/NodeWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,50 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.DefaultElementWrapper;
+import org.drools.ruleflow.core.INode;
+
+/**
+ * Wrapper for a node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class NodeWrapper extends DefaultElementWrapper {
+
+ protected void setNode(INode node) {
+ setElement(node);
+ }
+
+ public INode getNode() {
+ return (INode) getElement();
+ }
+
+ public String getId() {
+ long id = getNode().getId();
+ return id == -1 ? null : getNode().getId() + "-Wrapper";
+ }
+
+ public String getName() {
+ return getNode().getName();
+ }
+
+ public void internalSetName(String name) {
+ getNode().setName(name);
+ notifyListeners(CHANGE_NAME);
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleFlowProcessWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleFlowProcessWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleFlowProcessWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,85 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementWrapper;
+import org.drools.ide.flow.common.editor.core.ProcessWrapper;
+import org.drools.ruleflow.common.core.IProcess;
+import org.drools.ruleflow.core.IRuleFlowProcess;
+import org.drools.ruleflow.core.impl.RuleFlowProcess;
+
+/**
+ * Wrapper for a RuleFlow process.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleFlowProcessWrapper extends ProcessWrapper {
+
+ private static final long serialVersionUID = 3258415040708293944L;
+
+// private static IPropertyDescriptor[] descriptors;
+//
+// public static final String VARIABLES = "variables";
+// static {
+// descriptors = new IPropertyDescriptor[ProcessWrapper.descriptors.length + 1];
+// System.arraycopy(ProcessWrapper.descriptors, 0, descriptors, 0, ProcessWrapper.descriptors.length);
+// descriptors[descriptors.length - 1] =
+// new ListPropertyDescriptor(VARIABLES, "Variables", VariableListCellEditor.class);
+// }
+
+ public IRuleFlowProcess getRuleFlowProcess() {
+ return (IRuleFlowProcess) getProcess();
+ }
+
+ protected IProcess createProcess() {
+ return new RuleFlowProcess();
+ }
+
+ protected void internalAddElement(ElementWrapper element) {
+ getRuleFlowProcess().addNode(((NodeWrapper) element).getNode());
+ }
+
+ protected void internalRemoveElement(ElementWrapper element) {
+ getRuleFlowProcess().removeNode(((NodeWrapper) element).getNode());
+ }
+
+// public IPropertyDescriptor[] getPropertyDescriptors() {
+// return descriptors;
+// }
+//
+// public Object getPropertyValue(Object id) {
+// if (VARIABLES.equals(id)) {
+// return getRuleFlowProcess().getVariables();
+// }
+// return super.getPropertyValue(id);
+// }
+//
+// public void resetPropertyValue(Object id) {
+// if (VARIABLES.equals(id)) {
+// getRuleFlowProcess().setVariables(new ArrayList());
+// } else {
+// super.resetPropertyValue(id);
+// }
+// }
+//
+// public void setPropertyValue(Object id, Object value) {
+// if (VARIABLES.equals(id)) {
+// getRuleFlowProcess().setVariables((List) value);
+// } else {
+// super.setPropertyValue(id, value);
+// }
+// }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleSetNodeWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleSetNodeWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/RuleSetNodeWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,87 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.DefaultElementWrapper;
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ruleflow.core.IRuleSetNode;
+import org.drools.ruleflow.core.impl.RuleSetNode;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.TextPropertyDescriptor;
+
+/**
+ * Wrapper for a RuleSet node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleSetNodeWrapper extends NodeWrapper {
+
+ private static final long serialVersionUID = 3257007648627765553L;
+ private static IPropertyDescriptor[] descriptors;
+
+ public static final String RULE_FLOW_GROUP = "RuleFlowGroup";
+ static {
+ descriptors = new IPropertyDescriptor[DefaultElementWrapper.descriptors.length + 1];
+ System.arraycopy(DefaultElementWrapper.descriptors, 0, descriptors, 0, DefaultElementWrapper.descriptors.length);
+ descriptors[descriptors.length - 1] =
+ new TextPropertyDescriptor(RULE_FLOW_GROUP, "RuleFlowGroup");
+ }
+
+ public RuleSetNodeWrapper() {
+ setNode(new RuleSetNode());
+ getRuleSetNode().setName("RuleSet");
+ getRuleSetNode().setRuleFlowGroup("");
+ }
+
+ public IRuleSetNode getRuleSetNode() {
+ return (IRuleSetNode) getNode();
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ return descriptors;
+ }
+
+ public boolean acceptsIncomingConnection(ElementConnection connection) {
+ return getIncomingConnections().isEmpty();
+ }
+
+ public boolean acceptsOutgoingConnection(ElementConnection connection) {
+ return getOutgoingConnections().isEmpty();
+ }
+
+ public Object getPropertyValue(Object id) {
+ if (RULE_FLOW_GROUP.equals(id)) {
+ return getRuleSetNode().getRuleFlowGroup();
+ }
+ return super.getPropertyValue(id);
+ }
+
+ public void resetPropertyValue(Object id) {
+ if (RULE_FLOW_GROUP.equals(id)) {
+ getRuleSetNode().setRuleFlowGroup("");
+ } else {
+ super.resetPropertyValue(id);
+ }
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ if (RULE_FLOW_GROUP.equals(id)) {
+ getRuleSetNode().setRuleFlowGroup((String) value);
+ } else {
+ super.setPropertyValue(id, value);
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/SplitWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/SplitWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/SplitWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,140 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * 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.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.drools.ide.flow.common.editor.core.DefaultElementWrapper;
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.ruleflow.view.property.constraint.ConstraintsPropertyDescriptor;
+import org.drools.ruleflow.core.IConnection;
+import org.drools.ruleflow.core.IConstraint;
+import org.drools.ruleflow.core.ISplit;
+import org.drools.ruleflow.core.impl.Split;
+import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+
+/**
+ * Wrapper for a split node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class SplitWrapper extends NodeWrapper {
+
+ public static final String TYPE = "type";
+ public static final String CONSTRAINTS = "constraints";
+
+ private static final long serialVersionUID = 3256728394048944185L;
+ private transient IPropertyDescriptor[] descriptors;
+
+ public SplitWrapper() {
+ setNode(new Split());
+ getSplit().setName("Split");
+ setDescriptors();
+ }
+
+ private void setDescriptors() {
+ descriptors = new IPropertyDescriptor[DefaultElementWrapper.descriptors.length + 1];
+ System.arraycopy(DefaultElementWrapper.descriptors, 0, descriptors, 0, DefaultElementWrapper.descriptors.length);
+ descriptors[descriptors.length - 1] =
+ new ComboBoxPropertyDescriptor(TYPE, "Type",
+ new String[] { "", "AND" }); //, "XOR", "OR" });
+ }
+
+ public ISplit getSplit() {
+ return (ISplit) getNode();
+ }
+
+ public boolean acceptsIncomingConnection(ElementConnection connection) {
+ return getIncomingConnections().isEmpty();
+ }
+
+ public boolean acceptsOutgoingConnection(ElementConnection connection) {
+ return connection.getType() == IConnection.TYPE_NORMAL;
+ }
+
+ public IPropertyDescriptor[] getPropertyDescriptors() {
+ if (getParent() != null && (getSplit().getType() == Split.TYPE_XOR
+ || getSplit().getType() == Split.TYPE_OR)) {
+ IPropertyDescriptor[] result = new IPropertyDescriptor[descriptors.length + 1];
+ System.arraycopy(descriptors, 0, result, 0, descriptors.length);
+ result[descriptors.length] =
+ new ConstraintsPropertyDescriptor(CONSTRAINTS, "Constraints", getSplit(), ((RuleFlowProcessWrapper) getParent()).getRuleFlowProcess());
+ return result;
+ }
+ return descriptors;
+ }
+
+ public Object getPropertyValue(Object id) {
+ if (TYPE.equals(id)) {
+ return new Integer(getSplit().getType());
+ }
+ if (CONSTRAINTS.equals(id)) {
+ return getSplit().getType() == Split.TYPE_XOR
+ || getSplit().getType() == Split.TYPE_OR
+ ? new MyHashMap(getSplit().getConstraints()) : new MyHashMap();
+ }
+ return super.getPropertyValue(id);
+ }
+
+ public void resetPropertyValue(Object id) {
+ if (TYPE.equals(id)) {
+ getSplit().setType(ISplit.TYPE_UNDEFINED);
+ } else if (CONSTRAINTS.equals(id)) {
+ for (Iterator it = getSplit().getOutgoingConnections().iterator(); it.hasNext(); ) {
+ IConnection connection = (IConnection) it.next();
+ getSplit().setConstraint(connection, null);
+ }
+ } else {
+ super.resetPropertyValue(id);
+ }
+ }
+
+ public void setPropertyValue(Object id, Object value) {
+ if (TYPE.equals(id)) {
+ getSplit().setType(((Integer) value).intValue());
+ } else if (CONSTRAINTS.equals(id)) {
+ Iterator iterator = ((Map) value).entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry element = (Map.Entry) iterator.next();
+ getSplit().setConstraint((IConnection) element.getKey(), (IConstraint) element.getValue());
+ }
+ } else {
+ super.setPropertyValue(id, value);
+ }
+ }
+
+ private void readObject(ObjectInputStream aInputStream) throws ClassNotFoundException, IOException {
+ aInputStream.defaultReadObject();
+ setDescriptors();
+ }
+
+ public class MyHashMap extends HashMap {
+ private static final long serialVersionUID = -1748055291307174539L;
+ public MyHashMap() {
+ }
+ public MyHashMap(Map map) {
+ super(map);
+ }
+ public String toString() {
+ return "";
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/StartNodeWrapper.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/StartNodeWrapper.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/core/StartNodeWrapper.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,49 @@
+package org.drools.ide.flow.ruleflow.core;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ruleflow.core.IConnection;
+import org.drools.ruleflow.core.IStartNode;
+import org.drools.ruleflow.core.impl.StartNode;
+
+/**
+ * Wrapper for a start node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class StartNodeWrapper extends NodeWrapper {
+
+ private static final long serialVersionUID = 3978428031117375030L;
+
+ public StartNodeWrapper() {
+ setNode(new StartNode());
+ setName("Start");
+ }
+
+ public IStartNode getStartNode() {
+ return (IStartNode) getNode();
+ }
+
+ public boolean acceptsIncomingConnection(ElementConnection connection) {
+ return false;
+ }
+
+ public boolean acceptsOutgoingConnection(ElementConnection connection) {
+ return connection.getType() == IConnection.TYPE_NORMAL
+ && getOutgoingConnections().isEmpty();
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowModelEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowModelEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowModelEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,165 @@
+package org.drools.ide.flow.ruleflow.editor;
+/*
+ * 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.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.editor.GenericModelEditor;
+import org.drools.ide.flow.ruleflow.core.StartNodeWrapper;
+import org.drools.ide.flow.ruleflow.core.RuleFlowProcessWrapper;
+import org.drools.ide.flow.ruleflow.editor.editpart.RuleFlowEditPartFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPartFactory;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.eclipse.ui.part.FileEditorInput;
+
+import com.thoughtworks.xstream.XStream;
+
+/**
+ * Graphical editor for a RuleFlow.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleFlowModelEditor extends GenericModelEditor {
+
+ protected EditPartFactory createEditPartFactory() {
+ return new RuleFlowEditPartFactory();
+ }
+
+ protected PaletteRoot createPalette() {
+ return RuleFlowPaletteFactory.createPalette();
+ }
+
+ protected Object createModel() {
+ RuleFlowProcessWrapper result = new RuleFlowProcessWrapper();
+ StartNodeWrapper start = new StartNodeWrapper();
+ start.setConstraint(new Rectangle(100, 100, -1, -1));
+ result.addElement(start);
+ IFile file = ((IFileEditorInput)getEditorInput()).getFile();
+ String name = file.getName();
+ result.setName(name.substring(0, name.length() - 3));
+ return result;
+ }
+
+ public RuleFlowProcessWrapper getRuleFlowModel() {
+ return (RuleFlowProcessWrapper) getModel();
+ }
+
+ protected void createOutputStream(OutputStream os) throws IOException {
+ createOutputStream(os, true);
+ }
+
+
+ protected void createOutputStream(OutputStream os, boolean includeGraphics) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(os);
+ try {
+ XStream stream = new XStream();
+ stream.setMode(XStream.ID_REFERENCES);
+ if (includeGraphics) {
+ stream.toXML(getRuleFlowModel(), writer);
+ } else {
+ stream.toXML(getRuleFlowModel().getProcess(), writer);
+ }
+ writer.close();
+ } catch (Throwable t) {
+ DroolsIDEPlugin.log(t);
+ }
+ }
+
+ public void doSave(IProgressMonitor monitor) {
+ super.doSave(monitor);
+ // save process as separate model file as well
+ IFile file = ((IFileEditorInput) getEditorInput()).getFile();
+ final IFile modelFile = getModelFile(file);
+
+ if (!modelFile.exists()) {
+ WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
+ public void execute(final IProgressMonitor monitor)
+ throws CoreException {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ createOutputStream(out, false);
+ modelFile.create(new ByteArrayInputStream(out.toByteArray()),
+ true, monitor);
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ try {
+ new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell())
+ .run(false, true, op);
+ setInput(new FileEditorInput(file));
+ getCommandStack().markSaveLocation();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ createOutputStream(out, false);
+ modelFile.setContents(
+ new ByteArrayInputStream(out.toByteArray()),
+ true, false, monitor);
+ out.close();
+ } catch (Throwable t) {
+ DroolsIDEPlugin.log(t);
+ }
+ }
+ }
+
+ private IFile getModelFile(IFile file) {
+ IProject project = file.getProject();
+ IPath path = file.getProjectRelativePath();
+ String fileName = file.getName().substring(0, file.getName().length() - 2) + "rfm";
+ IPath modelPath = path.removeLastSegments(1).append(fileName);
+ IFile modelFile = project.getFile(modelPath);
+ return modelFile;
+ }
+
+ protected void createInputStream(InputStream is) throws Exception {
+ InputStreamReader reader = new InputStreamReader(is);
+ XStream stream = new XStream();
+ stream.setMode(XStream.ID_REFERENCES);
+
+ ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader newLoader = this.getClass().getClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(newLoader);
+ setModel(stream.fromXML(reader));
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldLoader);
+ }
+ reader.close();
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowPaletteFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowPaletteFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/RuleFlowPaletteFactory.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,157 @@
+package org.drools.ide.flow.ruleflow.editor;
+/*
+ * 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.List;
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.editor.core.ElementConnectionFactory;
+import org.drools.ide.flow.ruleflow.core.ConnectionWrapper;
+import org.drools.ide.flow.ruleflow.core.ConnectionWrapperFactory;
+import org.drools.ide.flow.ruleflow.core.EndNodeWrapper;
+import org.drools.ide.flow.ruleflow.core.JoinWrapper;
+import org.drools.ide.flow.ruleflow.core.RuleSetNodeWrapper;
+import org.drools.ide.flow.ruleflow.core.SplitWrapper;
+import org.drools.ide.flow.ruleflow.core.StartNodeWrapper;
+import org.drools.ruleflow.core.IConnection;
+import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
+import org.eclipse.gef.palette.ConnectionCreationToolEntry;
+import org.eclipse.gef.palette.MarqueeToolEntry;
+import org.eclipse.gef.palette.PaletteContainer;
+import org.eclipse.gef.palette.PaletteDrawer;
+import org.eclipse.gef.palette.PaletteGroup;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.gef.palette.SelectionToolEntry;
+import org.eclipse.gef.palette.ToolEntry;
+import org.eclipse.gef.requests.CreationFactory;
+import org.eclipse.gef.requests.SimpleFactory;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * Factory for creating a RuleFlow palette.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleFlowPaletteFactory {
+
+ public static PaletteRoot createPalette() {
+ PaletteRoot flowPalette = new PaletteRoot();
+ flowPalette.addAll(createCategories(flowPalette));
+ return flowPalette;
+ }
+
+ private static List createCategories(PaletteRoot root) {
+ List categories = new ArrayList();
+ categories.add(createControlGroup(root));
+ categories.add(createComponentsDrawer());
+ return categories;
+ }
+
+ private static PaletteContainer createComponentsDrawer() {
+
+ PaletteDrawer drawer = new PaletteDrawer("Components", null);
+
+ List entries = new ArrayList();
+
+ CombinedTemplateCreationEntry combined = new CombinedTemplateCreationEntry(
+ "Start",
+ "Create a new Start",
+ StartNodeWrapper.class,
+ new SimpleFactory(StartNodeWrapper.class),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/process_start.gif")),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/process_start.gif"))
+ );
+ entries.add(combined);
+
+ combined = new CombinedTemplateCreationEntry(
+ "End",
+ "Create a new End",
+ EndNodeWrapper.class,
+ new SimpleFactory(EndNodeWrapper.class),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/process_stop.gif")),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/process_stop.gif"))
+ );
+ entries.add(combined);
+
+ combined = new CombinedTemplateCreationEntry(
+ "RuleFlowGroup",
+ "Create a new RuleFlowGroup",
+ RuleSetNodeWrapper.class,
+ new SimpleFactory(RuleSetNodeWrapper.class),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/activity.gif")),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/activity.gif"))
+ );
+ entries.add(combined);
+
+ combined = new CombinedTemplateCreationEntry(
+ "Split",
+ "Create a new Split",
+ SplitWrapper.class,
+ new SimpleFactory(SplitWrapper.class),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/split.gif")),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/split.gif"))
+ );
+ entries.add(combined);
+
+ combined = new CombinedTemplateCreationEntry(
+ "Join",
+ "Create a new Join",
+ JoinWrapper.class,
+ new SimpleFactory(JoinWrapper.class),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/join.gif")),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/join.gif"))
+ );
+ entries.add(combined);
+
+ drawer.addAll(entries);
+ return drawer;
+ }
+
+ private static PaletteContainer createControlGroup(PaletteRoot root) {
+ PaletteGroup controlGroup = new PaletteGroup("Control Group");
+
+ List entries = new ArrayList();
+
+ ToolEntry tool = new SelectionToolEntry();
+ entries.add(tool);
+ root.setDefaultEntry(tool);
+
+ tool = new MarqueeToolEntry();
+ entries.add(tool);
+
+ final ElementConnectionFactory normalConnectionFactory = new ConnectionWrapperFactory(IConnection.TYPE_NORMAL);
+
+ tool = new ConnectionCreationToolEntry(
+ "Connection Creation",
+ "Creating connections",
+ new CreationFactory() {
+ public Object getNewObject() {
+ return normalConnectionFactory.createElementConnection();
+ }
+ public Object getObjectType() {
+ return ConnectionWrapper.class;
+ }
+ },
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/connection.gif")),
+ ImageDescriptor.createFromURL(DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/connection.gif"))
+ );
+ entries.add(tool);
+
+ controlGroup.addAll(entries);
+ return controlGroup;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/action/CheckRuleFlowAction.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/action/CheckRuleFlowAction.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/action/CheckRuleFlowAction.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,74 @@
+package org.drools.ide.flow.ruleflow.editor.action;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.ruleflow.editor.RuleFlowModelEditor;
+import org.drools.ruleflow.core.IRuleFlowProcessValidationError;
+import org.drools.ruleflow.core.impl.RuleFlowProcessValidator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ActionDelegate;
+
+/**
+ * Action for checking a RuleFlow.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class CheckRuleFlowAction extends ActionDelegate implements IEditorActionDelegate {
+
+ private IEditorPart editor;
+
+ public void run(IAction action) {
+ execute();
+ }
+
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ editor = targetEditor;
+ }
+
+ private void execute() {
+ IRuleFlowProcessValidationError[] errors = RuleFlowProcessValidator.getInstance().validateProcess(
+ ((RuleFlowModelEditor) editor).getRuleFlowModel().getRuleFlowProcess());
+ if (errors.length == 0) {
+ MessageDialog.openInformation(editor.getSite().getShell(),
+ "Check RuleFlow", "The RuleFlow model was checked successfully.");
+ } else {
+ StringBuilder error = new StringBuilder(errors[0].toString());
+ error.append("\n");
+ for (int i = 1; i < errors.length; i++) {
+ error.append(" ");
+ error.append(errors[i]);
+ error.append("\n");
+ }
+ ErrorDialog.openError(editor.getSite().getShell(),
+ "Check RuleFlow", "The RuleFlow model contains errors.",
+ new Status(
+ IStatus.ERROR,
+ DroolsIDEPlugin.getDefault().getBundle().getSymbolicName(),
+ IStatus.ERROR,
+ error.toString(),
+ null)
+ );
+ }
+
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/EndNodeEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/EndNodeEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/EndNodeEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,53 @@
+package org.drools.ide.flow.ruleflow.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.editor.editpart.ElementEditPart;
+import org.drools.ide.flow.common.editor.editpart.figure.ElementFigure;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LineBorder;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * EditPart for an end node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class EndNodeEditPart extends ElementEditPart {
+
+ protected IFigure createFigure() {
+ return new EndNodeFigure();
+ }
+
+ public static class EndNodeFigure extends ElementFigure {
+
+ private static Image icon = ImageDescriptor.createFromURL(
+ DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/process_stop.gif")).createImage();
+
+ protected void customizeFigure() {
+ setIcon(icon);
+ setBorder(new LineBorder(1));
+ }
+
+ public void setSelected(boolean b) {
+ super.setSelected(b);
+ ((LineBorder) getBorder()).setWidth(b ? 3 : 1);
+ repaint();
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/JoinEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/JoinEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/JoinEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,81 @@
+package org.drools.ide.flow.ruleflow.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.editpart.ElementEditPart;
+import org.drools.ide.flow.common.editor.editpart.figure.ElementFigure;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.Ellipse;
+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.Request;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * EditPart for a join node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class JoinEditPart extends ElementEditPart {
+
+ private static final Color color = new Color(Display.getCurrent(), 70, 130, 180);
+
+ protected IFigure createFigure() {
+ return new JoinFigure();
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(Request request) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(Request request) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public class JoinFigure extends ElementFigure {
+
+ private Ellipse ellipse;
+
+ protected void customizeFigure() {
+ ellipse = new Ellipse();
+ add(ellipse, 0);
+ ellipse.setBackgroundColor(color);
+ ellipse.setBounds(getBounds());
+ }
+
+ public void setBounds(Rectangle rectangle) {
+ super.setBounds(rectangle);
+ ellipse.setBounds(rectangle);
+ }
+
+ public void setSelected(boolean b) {
+ super.setSelected(b);
+ ellipse.setLineWidth(b ? 3 : 1);
+ repaint();
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowConnectionEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowConnectionEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowConnectionEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,53 @@
+package org.drools.ide.flow.ruleflow.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.core.ElementConnectionFactory;
+import org.drools.ide.flow.common.editor.editpart.ElementConnectionEditPart;
+import org.drools.ide.flow.ruleflow.core.ConnectionWrapperFactory;
+import org.drools.ruleflow.core.IConnection;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PolygonDecoration;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.draw2d.geometry.PointList;
+
+/**
+ * EditPart for an element connection.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleFlowConnectionEditPart extends ElementConnectionEditPart {
+
+ protected ElementConnectionFactory getDefaultElementConnectionFactory() {
+ return new ConnectionWrapperFactory(IConnection.TYPE_NORMAL);
+ }
+
+ protected IFigure createFigure() {
+ PolylineConnection result = (PolylineConnection) super.createFigure();
+ if (((ElementConnection) getModel()).getType() == IConnection.TYPE_ABORT) {
+ PolygonDecoration decoration = new PolygonDecoration();
+ PointList decorationPointList = new PointList();
+ decorationPointList.addPoint(0,0);
+ decorationPointList.addPoint(-1,1);
+ decorationPointList.addPoint(-2,0);
+ decorationPointList.addPoint(-1,-1);
+ decoration.setTemplate(decorationPointList);
+ result.setSourceDecoration(decoration);
+ }
+ return result;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleFlowEditPartFactory.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,60 @@
+package org.drools.ide.flow.ruleflow.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.core.ElementConnection;
+import org.drools.ide.flow.common.editor.editpart.ProcessEditPart;
+import org.drools.ide.flow.ruleflow.core.EndNodeWrapper;
+import org.drools.ide.flow.ruleflow.core.JoinWrapper;
+import org.drools.ide.flow.ruleflow.core.RuleSetNodeWrapper;
+import org.drools.ide.flow.ruleflow.core.SplitWrapper;
+import org.drools.ide.flow.ruleflow.core.StartNodeWrapper;
+import org.drools.ide.flow.ruleflow.core.RuleFlowProcessWrapper;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartFactory;
+
+/**
+ * Factory for RuleFlow EditParts.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleFlowEditPartFactory implements EditPartFactory {
+
+ public EditPart createEditPart(EditPart context, Object model) {
+ EditPart result = null;
+ if (model instanceof RuleFlowProcessWrapper) {
+ result = new ProcessEditPart();
+ } else if (model instanceof RuleSetNodeWrapper) {
+ result = new RuleSetNodeEditPart();
+ } else if (model instanceof ElementConnection) {
+ result = new RuleFlowConnectionEditPart();
+ } else if (model instanceof StartNodeWrapper) {
+ result = new StartNodeEditPart();
+ } else if (model instanceof EndNodeWrapper) {
+ result = new EndNodeEditPart();
+ } else if (model instanceof SplitWrapper) {
+ result = new SplitEditPart();
+ } else if (model instanceof JoinWrapper) {
+ result = new JoinEditPart();
+ } else {
+ throw new IllegalArgumentException(
+ "Unknown model object " + model);
+ }
+ result.setModel(model);
+ return result;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleSetNodeEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleSetNodeEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/RuleSetNodeEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,64 @@
+package org.drools.ide.flow.ruleflow.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.editpart.ElementEditPart;
+import org.drools.ide.flow.common.editor.editpart.figure.ElementFigure;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.RoundedRectangle;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * EditPart for a RuleSet node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleSetNodeEditPart extends ElementEditPart {
+
+ private static final Color color = new Color(Display.getCurrent(), 255, 250, 205);
+
+ protected IFigure createFigure() {
+ return new RuleSetNodeFigure();
+ }
+
+ public class RuleSetNodeFigure extends ElementFigure {
+
+ private RoundedRectangle rectangle;
+
+ protected void customizeFigure() {
+ rectangle = new RoundedRectangle();
+ rectangle.setCornerDimensions(new Dimension(25, 25));
+ add(rectangle, 0);
+ rectangle.setBackgroundColor(color);
+ rectangle.setBounds(getBounds());
+ setSelected(false);
+ }
+
+ public void setBounds(Rectangle rectangle) {
+ super.setBounds(rectangle);
+ this.rectangle.setBounds(rectangle);
+ }
+
+ public void setSelected(boolean b) {
+ super.setSelected(b);
+ rectangle.setLineWidth(b ? 3 : 1);
+ repaint();
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/SplitEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/SplitEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/SplitEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,81 @@
+package org.drools.ide.flow.ruleflow.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.editor.editpart.ElementEditPart;
+import org.drools.ide.flow.common.editor.editpart.figure.ElementFigure;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.Ellipse;
+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.Request;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * EditPart for a split node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class SplitEditPart extends ElementEditPart {
+
+ private static final Color color = new Color(Display.getCurrent(), 70, 130, 180);
+
+ protected IFigure createFigure() {
+ return new SplitFigure();
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(Request request) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(Request request) {
+ return new EllipseAnchor(getFigure());
+ }
+
+ public class SplitFigure extends ElementFigure {
+
+ private Ellipse ellipse;
+
+ protected void customizeFigure() {
+ ellipse = new Ellipse();
+ add(ellipse, 0);
+ ellipse.setBackgroundColor(color);
+ ellipse.setBounds(getBounds());
+ }
+
+ public void setBounds(Rectangle rectangle) {
+ super.setBounds(rectangle);
+ ellipse.setBounds(rectangle);
+ }
+
+ public void setSelected(boolean b) {
+ super.setSelected(b);
+ ellipse.setLineWidth(b ? 3 : 1);
+ repaint();
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/StartNodeEditPart.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/StartNodeEditPart.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/editor/editpart/StartNodeEditPart.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,53 @@
+package org.drools.ide.flow.ruleflow.editor.editpart;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.editor.editpart.ElementEditPart;
+import org.drools.ide.flow.common.editor.editpart.figure.ElementFigure;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LineBorder;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * EditPart for a start node.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class StartNodeEditPart extends ElementEditPart {
+
+ protected IFigure createFigure() {
+ return new StartNodeFigure();
+ }
+
+ public static class StartNodeFigure extends ElementFigure {
+
+ private static Image icon = ImageDescriptor.createFromURL(
+ DroolsIDEPlugin.getDefault().getBundle().getEntry("icons/process_start.gif")).createImage();
+
+ protected void customizeFigure() {
+ setIcon(icon);
+ setBorder(new LineBorder(1));
+ }
+
+ public void setSelected(boolean b) {
+ super.setSelected(b);
+ ((LineBorder) getBorder()).setWidth(b ? 3 : 1);
+ repaint();
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListCellEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListCellEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListCellEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,48 @@
+package org.drools.ide.flow.ruleflow.view.property.constraint;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.view.property.BeanDialogCellEditor;
+import org.drools.ide.flow.common.view.property.EditBeanDialog;
+import org.drools.ruleflow.core.ISplit;
+import org.drools.ruleflow.core.IRuleFlowProcess;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Cell editor for constraints.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ConstraintListCellEditor extends BeanDialogCellEditor {
+
+ private IRuleFlowProcess process;
+ private ISplit split;
+
+ public ConstraintListCellEditor(Composite parent, IRuleFlowProcess process, ISplit split) {
+ super(parent);
+ this.process = process;
+ this.split = split;
+ }
+
+ protected EditBeanDialog createDialog(Shell shell) {
+ return new ConstraintListDialog(shell, process, split);
+ }
+
+ protected String getLabelText(Object value) {
+ return "";
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintListDialog.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,146 @@
+package org.drools.ide.flow.ruleflow.view.property.constraint;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.ide.flow.common.view.property.EditBeanDialog;
+import org.drools.ruleflow.core.IConnection;
+import org.drools.ruleflow.core.IConstraint;
+import org.drools.ruleflow.core.ISplit;
+import org.drools.ruleflow.core.IRuleFlowProcess;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog for editing constraints.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ConstraintListDialog extends EditBeanDialog {
+
+ private IRuleFlowProcess process;
+ private ISplit split;
+ private Map newMap;
+ private Map labels = new HashMap();
+
+ protected ConstraintListDialog(Shell parentShell, IRuleFlowProcess process,
+ ISplit split) {
+ super(parentShell, "Edit Constraints");
+ this.process = process;
+ this.split = split;
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ composite.setLayout(gridLayout);
+
+ List outgoingConnections = split.getOutgoingConnections();
+ labels.clear();
+ for (Iterator it = outgoingConnections.iterator(); it.hasNext(); ) {
+ IConnection outgoingConnection = (IConnection) it.next();
+ Label label1 = new Label(composite, SWT.NONE);
+ label1.setText("To node " + outgoingConnection.getTo().getName()
+ + ": ");
+
+ Label label2 = new Label(composite, SWT.NONE);
+ labels.put(outgoingConnection, label2);
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ label2.setLayoutData(gridData);
+ IConstraint constraint = (IConstraint) newMap.get(outgoingConnection);
+ if (constraint != null) {
+ label2.setText(constraint.getName());
+ }
+
+ Button editButton = new Button(composite, SWT.NONE);
+ editButton.setText("Edit");
+ editButton.addSelectionListener(new EditButtonListener(
+ outgoingConnection));
+ }
+
+ return composite;
+ }
+
+ public void setValue(Object value) {
+ super.setValue(value);
+ this.newMap = new HashMap((Map) value);
+ }
+
+ protected Object updateValue(Object value) {
+ return newMap;
+ }
+
+ private void editItem(final IConnection connection) {
+
+ final Runnable r = new Runnable() {
+ public void run() {
+
+ // swt version
+ RuleFlowConstraintDialog dialog = new RuleFlowConstraintDialog(
+ getShell(), process);
+ dialog.create();
+ IConstraint constraint = (IConstraint) newMap.get(connection);
+ dialog.setConstraint(constraint);
+ int code = dialog.open();
+ if (code != CANCEL) {
+ constraint = dialog.getConstraint();
+ newMap.put(connection, constraint);
+ setConnectionText((Label) labels.get(connection), constraint
+ .getName());
+ }
+ }
+
+ };
+
+ r.run();
+ }
+
+ private void setConnectionText(final Label connection, final String name) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ connection.setText(name);
+ }
+ });
+ }
+
+ private class EditButtonListener extends SelectionAdapter {
+ private IConnection connection;
+
+ public EditButtonListener(IConnection connection) {
+ this.connection = connection;
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ editItem(connection);
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintsPropertyDescriptor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintsPropertyDescriptor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/ConstraintsPropertyDescriptor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,51 @@
+package org.drools.ide.flow.ruleflow.view.property.constraint;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ruleflow.core.ISplit;
+import org.drools.ruleflow.core.IRuleFlowProcess;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.properties.PropertyDescriptor;
+
+/**
+ * Property descriptor for constraints.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ConstraintsPropertyDescriptor extends PropertyDescriptor {
+
+ private IRuleFlowProcess process;
+ private ISplit split;
+
+ public ConstraintsPropertyDescriptor(Object id, String displayName, ISplit split, IRuleFlowProcess process) {
+ super(id, displayName);
+ this.split = split;
+ this.process = process;
+ }
+
+ public IRuleFlowProcess getProcess() {
+ return process;
+ }
+
+ public CellEditor createPropertyEditor(Composite parent) {
+ ConstraintListCellEditor editor = new ConstraintListCellEditor(parent, process, split);
+ if (getValidator() != null) {
+ editor.setValidator(getValidator());
+ }
+ return editor;
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,203 @@
+package org.drools.ide.flow.ruleflow.view.property.constraint;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ruleflow.core.IConstraint;
+import org.drools.ruleflow.core.IRuleFlowProcess;
+import org.drools.ruleflow.core.impl.Constraint;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+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.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Dialog for editing constraints.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleFlowConstraintDialog extends Dialog {
+
+ private IConstraint constraint;
+ private boolean success;
+ private Button alwaysTrue;
+ private Text nameText;
+ private Text priorityText;
+ private TabFolder tabFolder;
+ private Text translation;
+
+ public RuleFlowConstraintDialog(Shell parentShell, IRuleFlowProcess process) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Constraint editor");
+ }
+
+ protected Point getInitialSize() {
+ return new Point(600, 450);
+ }
+
+ private Control createTextualEditor(Composite parent) {
+ translation = new Text(parent, SWT.BORDER);
+ return translation;
+ }
+
+ public Control createDialogArea(Composite parent) {
+
+ GridLayout layout = new GridLayout();
+ parent.setLayout(layout);
+ layout.numColumns = 2;
+
+ Composite top = new Composite(parent, SWT.NONE);
+ GridData gd = new GridData();
+ gd.horizontalSpan = 2;
+ gd.grabExcessHorizontalSpace = true;
+ top.setLayoutData(gd);
+
+ layout = new GridLayout();
+ layout.numColumns = 2;
+ top.setLayout(layout);
+
+ Label l1 = new Label(top, SWT.None);
+ l1.setText("Name:");
+ gd = new GridData();
+ l1.setLayoutData(gd);
+ nameText = new Text(top, SWT.BORDER);
+ gd = new GridData();
+ gd.horizontalAlignment = GridData.FILL;
+ gd.widthHint = 200;
+ nameText.setLayoutData(gd);
+
+ Label l2 = new Label(top, SWT.NONE);
+ gd = new GridData();
+ l2.setLayoutData(gd);
+ l2.setText("Priority:");
+ priorityText = new Text(top, SWT.BORDER);
+ gd = new GridData();
+ gd.widthHint = 200;
+ priorityText.setLayoutData(gd);
+
+ alwaysTrue = new Button(top, SWT.CHECK);
+ alwaysTrue.setText("Always true");
+ gd = new GridData();
+ gd.horizontalSpan = 2;
+ alwaysTrue.setLayoutData(gd);
+
+ tabFolder = new TabFolder(parent, SWT.NONE);
+ gd = new GridData();
+ gd.horizontalSpan = 2;
+ gd.grabExcessHorizontalSpace = true;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = GridData.FILL;
+ gd.horizontalAlignment = GridData.FILL;
+ tabFolder.setLayoutData(gd);
+ TabItem textEditorTab = new TabItem(tabFolder, SWT.NONE);
+ textEditorTab.setText("Textual Editor");
+
+ textEditorTab.setControl(createTextualEditor(tabFolder));
+
+ alwaysTrue.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ tabFolder.setVisible(!alwaysTrue.getSelection());
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+
+ return tabFolder;
+ }
+
+ protected void okPressed() {
+ int selectionIndex = tabFolder.getSelectionIndex();
+ if (selectionIndex == 1) {
+ updateTranslation();
+ } else {
+ updateConstraint();
+ }
+ super.okPressed();
+ }
+
+ private void updateTranslation() {
+ // TODO add custom token model checker
+ success = true;
+ constraint = new Constraint();
+ constraint.setConstraint(null);
+ constraint.setConstraint(translation.getText());
+ constraint.setName(nameText.getText());
+ try {
+ constraint.setPriority(Integer.parseInt(priorityText.getText()));
+ } catch (NumberFormatException exc) {
+ constraint.setPriority(1);
+ }
+ }
+
+ public boolean isSuccess() {
+ return success;
+ }
+
+ public void updateConstraint() {
+ constraint = new Constraint();
+ if (!alwaysTrue.getSelection()) {
+ constraint.setConstraint(translation.getText());
+ } else {
+ constraint.setConstraint("true");
+ }
+ constraint.setName(nameText.getText());
+ try {
+ constraint.setPriority(Integer.parseInt(priorityText.getText()));
+ } catch (NumberFormatException exc) {
+ constraint.setPriority(1);
+ }
+ }
+
+ public IConstraint getConstraint() {
+ return constraint;
+ }
+
+ public void setConstraint(IConstraint constraint) {
+ this.constraint = constraint;
+ if (constraint != null) {
+ if ("true".equals(constraint.getConstraint())) {
+ alwaysTrue.setSelection(true);
+ } else {
+ translation.setText(constraint.getConstraint().toString());
+ }
+ tabFolder.setVisible(!alwaysTrue.getSelection());
+ nameText.setText(constraint.getName() == null ? "" : constraint
+ .getName());
+ priorityText.setText(constraint.getPriority() + "");
+ translation.setText(constraint.getConstraint());
+ } else {
+ priorityText.setText("1");
+ nameText.setText("constraint");
+ }
+ }
+}
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableDialog.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,151 @@
+package org.drools.ide.flow.ruleflow.view.property.variable;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.DroolsIDEPlugin;
+import org.drools.ide.flow.common.datatype.DefaultDataTypeRegistry;
+import org.drools.ide.flow.common.view.datatype.editor.IDataTypeEditor;
+import org.drools.ide.flow.common.view.datatype.editor.impl.DataTypeCombo;
+import org.drools.ide.flow.common.view.datatype.editor.impl.DataTypeEditorComposite;
+import org.drools.ide.flow.common.view.datatype.editor.impl.EditorComposite;
+import org.drools.ide.flow.common.view.property.EditBeanDialog;
+import org.drools.ruleflow.common.datatype.IDataType;
+import org.drools.ruleflow.core.IVariable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Dialog for editing variables.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class VariableDialog extends EditBeanDialog {
+
+ private Text nameText;
+ private DataTypeCombo dataTypeCombo;
+ private DataTypeEditorComposite dataTypeEditorComposite;
+ private EditorComposite editorComposite;
+
+ public VariableDialog(Shell parentShell) {
+ super(parentShell, "Edit Variable");
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ final Composite composite = (Composite) super.createDialogArea(parent);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ composite.setLayout(gridLayout);
+
+ Label nameLabel = new Label(composite, SWT.NONE);
+ nameLabel.setText("Name: ");
+ nameText = new Text(composite, SWT.NONE);
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ nameText.setLayoutData(gridData);
+ String name = ((IVariable) getValue()).getName();
+ nameText.setText(name == null ? "" : name);
+
+ Label typeLabel = new Label(composite, SWT.NONE);
+ typeLabel.setText("Type: ");
+
+ dataTypeCombo = new DataTypeCombo(composite,
+ SWT.NONE, DefaultDataTypeRegistry.getInstance());
+ IDataType dataType = ((IVariable) getValue()).getType();
+ dataTypeCombo.setDataType(dataType);
+ dataTypeCombo.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ IDataType dataType = dataTypeCombo.getDataType();
+ dataTypeEditorComposite.setDataType(dataType);
+ editorComposite.setDataType(dataType);
+ composite.layout();
+ }
+ });
+
+ new Label(composite, SWT.NONE);
+
+ dataTypeEditorComposite = new DataTypeEditorComposite(composite,
+ SWT.NONE, DefaultDataTypeRegistry.getInstance());
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ dataTypeEditorComposite.setLayoutData(gridData);
+ dataTypeEditorComposite.setDataType(dataType);
+ dataTypeEditorComposite.addListener(new IDataTypeEditor.DataTypeListener() {
+ public void dataTypeChanged(IDataType dataType) {
+ editorComposite.setDataType(dataType);
+ composite.layout();
+ }
+ });
+
+ Label valueLabel = new Label(composite, SWT.NONE);
+ valueLabel.setText("Value: ");
+ gridData = new GridData();
+ gridData.verticalAlignment = SWT.TOP;
+ valueLabel.setLayoutData(gridData);
+ editorComposite = new EditorComposite(composite,
+ SWT.NONE, DefaultDataTypeRegistry.getInstance());
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ editorComposite.setLayoutData(gridData);
+ editorComposite.setDataType(dataType);
+ editorComposite.setValue(((IVariable) getValue()).getValue());
+
+ Composite bottom = new Composite(composite, SWT.NONE);
+ gridData = new GridData();
+ gridData.grabExcessVerticalSpace = true;
+ gridData.horizontalSpan = 2;
+ bottom.setLayoutData(gridData);
+
+ return composite;
+ }
+
+ protected Object updateValue(Object value) {
+ IVariable variable = (IVariable) getValue();
+ variable.setName(nameText.getText());
+ try {
+ variable.setType(dataTypeEditorComposite.getDataType());
+ } catch (IllegalArgumentException e) {
+ showError(e.getMessage());
+ throw e;
+ }
+ try {
+ variable.setValue(editorComposite.getValue());
+ } catch (IllegalArgumentException e) {
+ showError(e.getMessage());
+ throw e;
+ }
+ return variable;
+ }
+
+ private void showError(String error) {
+ ErrorDialog.openError(getShell(), "Error", error, new Status(
+ IStatus.ERROR, DroolsIDEPlugin.getDefault().getBundle().getSymbolicName(),
+ IStatus.ERROR, error, null));
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListCellEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListCellEditor.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListCellEditor.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,37 @@
+package org.drools.ide.flow.ruleflow.view.property.variable;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.view.property.BeanDialogCellEditor;
+import org.drools.ide.flow.common.view.property.EditBeanDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Cell edtior for variables.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class VariableListCellEditor extends BeanDialogCellEditor {
+
+ public VariableListCellEditor(Composite parent) {
+ super(parent);
+ }
+
+ protected EditBeanDialog createDialog(Shell shell) {
+ return new VariableListDialog(shell);
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/flow/ruleflow/view/property/variable/VariableListDialog.java 2007-03-01 02:40:42 UTC (rev 9867)
@@ -0,0 +1,36 @@
+package org.drools.ide.flow.ruleflow.view.property.variable;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.drools.ide.flow.common.view.property.EditListDialog;
+import org.drools.ruleflow.core.impl.Variable;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog for editing a list of variables.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class VariableListDialog extends EditListDialog {
+
+ protected VariableListDialog(Shell parentShell) {
+ super(parentShell, "Variable List Editor", VariableDialog.class);
+ }
+
+ protected Object createItem() {
+ return new Variable();
+ }
+}
More information about the jboss-svn-commits
mailing list