[jboss-svn-commits] JBL Code SVN: r15037 - in labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property: constraint and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 11 20:13:28 EDT 2007
Author: KrisVerlaenen
Date: 2007-09-11 20:13:28 -0400 (Tue, 11 Sep 2007)
New Revision: 15037
Added:
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowGlobalsDialog.java
Modified:
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionDialog.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ConstraintCompletionProcessor.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/MilestoneConstraintDialog.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java
Log:
JBRULES-1183: Add global support in ruleflow
- added support for globals in ruleflow
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionDialog.java 2007-09-12 00:13:23 UTC (rev 15036)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/action/ActionDialog.java 2007-09-12 00:13:28 UTC (rev 15037)
@@ -16,9 +16,11 @@
*/
import java.util.List;
+import java.util.Map;
import org.drools.eclipse.editors.scanners.DRLPartionScanner;
import org.drools.eclipse.flow.common.view.property.EditBeanDialog;
+import org.drools.eclipse.flow.ruleflow.view.property.constraint.RuleFlowGlobalsDialog;
import org.drools.eclipse.flow.ruleflow.view.property.constraint.RuleFlowImportsDialog;
import org.drools.ruleflow.core.ActionNode;
import org.drools.ruleflow.core.RuleFlowProcess;
@@ -150,9 +152,19 @@
}
});
gd = new GridData();
- gd.horizontalAlignment = GridData.END;
importButton.setLayoutData(gd);
+ Button globalButton = new Button(top, SWT.PUSH);
+ globalButton.setText("Globals ...");
+ globalButton.setFont(JFaceResources.getDialogFont());
+ globalButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ globalButtonPressed();
+ }
+ });
+ gd = new GridData();
+ globalButton.setLayoutData(gd);
+
tabFolder = new TabFolder(parent, SWT.NONE);
gd = new GridData();
gd.horizontalSpan = 3;
@@ -184,4 +196,21 @@
};
r.run();
}
+
+ private void globalButtonPressed() {
+ final Runnable r = new Runnable() {
+ public void run() {
+ RuleFlowGlobalsDialog dialog =
+ new RuleFlowGlobalsDialog(getShell(), process);
+ dialog.create();
+ int code = dialog.open();
+ if (code != CANCEL) {
+ Map globals = dialog.getGlobals();
+ process.setGlobals(globals);
+// completionProcessor.reset();
+ }
+ }
+ };
+ r.run();
+ }
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ConstraintCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ConstraintCompletionProcessor.java 2007-09-12 00:13:23 UTC (rev 15036)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ConstraintCompletionProcessor.java 2007-09-12 00:13:28 UTC (rev 15037)
@@ -17,6 +17,7 @@
*/
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -45,6 +46,7 @@
private RuleFlowProcess process;
private List imports;
+ private List globals;
public ConstraintCompletionProcessor(RuleFlowProcess process) {
super(null);
@@ -98,6 +100,17 @@
}
}
+ public List getGlobals() {
+ if (globals == null) {
+ loadGlobals();
+ }
+ return globals;
+ }
+
+ private void loadGlobals() {
+ this.globals = Arrays.asList(process.getGlobalNames());
+ }
+
private IJavaProject getJavaProject() {
IEditorPart editor = getEditor();
if (editor != null && editor.getEditorInput() instanceof IFileEditorInput) {
@@ -115,5 +128,6 @@
public void reset() {
this.imports = null;
+ this.globals = null;
}
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/MilestoneConstraintDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/MilestoneConstraintDialog.java 2007-09-12 00:13:23 UTC (rev 15036)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/MilestoneConstraintDialog.java 2007-09-12 00:13:28 UTC (rev 15037)
@@ -16,6 +16,7 @@
*/
import java.util.List;
+import java.util.Map;
import org.drools.eclipse.editors.DRLSourceViewerConfig;
import org.drools.eclipse.editors.scanners.DRLPartionScanner;
@@ -143,9 +144,19 @@
}
});
gd = new GridData();
- gd.horizontalAlignment = GridData.END;
importButton.setLayoutData(gd);
+ Button globalButton = new Button(top, SWT.PUSH);
+ globalButton.setText("Globals ...");
+ globalButton.setFont(JFaceResources.getDialogFont());
+ globalButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ globalButtonPressed();
+ }
+ });
+ gd = new GridData();
+ globalButton.setLayoutData(gd);
+
tabFolder = new TabFolder(parent, SWT.NONE);
gd = new GridData();
gd.horizontalSpan = 3;
@@ -177,4 +188,22 @@
};
r.run();
}
+
+ private void globalButtonPressed() {
+ final Runnable r = new Runnable() {
+ public void run() {
+ RuleFlowGlobalsDialog dialog =
+ new RuleFlowGlobalsDialog(getShell(), process);
+ dialog.create();
+ int code = dialog.open();
+ if (code != CANCEL) {
+ Map globals = dialog.getGlobals();
+ process.setGlobals(globals);
+ completionProcessor.reset();
+ }
+ }
+ };
+ r.run();
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java 2007-09-12 00:13:23 UTC (rev 15036)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowConstraintDialog.java 2007-09-12 00:13:28 UTC (rev 15037)
@@ -16,6 +16,7 @@
*/
import java.util.List;
+import java.util.Map;
import org.drools.eclipse.editors.DRLSourceViewerConfig;
import org.drools.eclipse.editors.scanners.DRLPartionScanner;
@@ -139,7 +140,7 @@
top.setLayoutData(gd);
layout = new GridLayout();
- layout.numColumns = 3;
+ layout.numColumns = 4;
top.setLayout(layout);
Label l1 = new Label(top, SWT.None);
@@ -150,7 +151,7 @@
gd = new GridData();
gd.horizontalAlignment = GridData.FILL;
gd.widthHint = 200;
- gd.horizontalSpan = 2;
+ gd.horizontalSpan = 3;
nameText.setLayoutData(gd);
Label l2 = new Label(top, SWT.NONE);
@@ -160,7 +161,7 @@
priorityText = new Text(top, SWT.BORDER);
gd = new GridData();
gd.widthHint = 200;
- gd.horizontalSpan = 2;
+ gd.horizontalSpan = 3;
priorityText.setLayoutData(gd);
alwaysTrue = new Button(top, SWT.CHECK);
@@ -178,12 +179,25 @@
}
});
gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.END;
importButton.setLayoutData(gd);
+ Button globalButton = new Button(top, SWT.PUSH);
+ globalButton.setText("Globals ...");
+ globalButton.setFont(JFaceResources.getDialogFont());
+ globalButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ globalButtonPressed();
+ }
+ });
+ gd = new GridData();
+ gd.horizontalAlignment = GridData.END;
+ globalButton.setLayoutData(gd);
+
tabFolder = new TabFolder(parent, SWT.NONE);
gd = new GridData();
- gd.horizontalSpan = 3;
+ gd.horizontalSpan = 4;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = GridData.FILL;
@@ -224,6 +238,23 @@
r.run();
}
+ private void globalButtonPressed() {
+ final Runnable r = new Runnable() {
+ public void run() {
+ RuleFlowGlobalsDialog dialog =
+ new RuleFlowGlobalsDialog(getShell(), process);
+ dialog.create();
+ int code = dialog.open();
+ if (code != CANCEL) {
+ Map globals = dialog.getGlobals();
+ process.setGlobals(globals);
+ completionProcessor.reset();
+ }
+ }
+ };
+ r.run();
+ }
+
protected void okPressed() {
int selectionIndex = tabFolder.getSelectionIndex();
if (selectionIndex == 1) {
Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowGlobalsDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowGlobalsDialog.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowGlobalsDialog.java 2007-09-12 00:13:28 UTC (rev 15037)
@@ -0,0 +1,139 @@
+package org.drools.eclipse.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.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.eclipse.editors.DRLSourceViewerConfig;
+import org.drools.ruleflow.core.RuleFlowProcess;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+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.Shell;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+
+/**
+ * Dialog for editing imports.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class RuleFlowGlobalsDialog extends Dialog {
+
+ private static final Pattern GLOBAL_PATTERN = Pattern.compile(
+ "\\n\\s*global\\s+([^\\s;#]+)\\s+([^\\s;#]+);?", Pattern.DOTALL);
+
+ private RuleFlowProcess process;
+ private boolean success;
+ private TabFolder tabFolder;
+ private SourceViewer globalsViewer;
+ private Map globals;
+
+ public RuleFlowGlobalsDialog(Shell parentShell, RuleFlowProcess process) {
+ super(parentShell);
+ this.process = process;
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ }
+
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText("Globals editor");
+ }
+
+ protected Point getInitialSize() {
+ return new Point(600, 450);
+ }
+
+ private Control createTextualEditor(Composite parent) {
+ globalsViewer = new SourceViewer(parent, null, SWT.BORDER);
+ globalsViewer.configure(new DRLSourceViewerConfig(null) {
+ public IReconciler getReconciler(ISourceViewer sourceViewer) {
+ return null;
+ }
+ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+ return null;
+ }
+ });
+ IDocument document = new Document(getProcessImports());
+ globalsViewer.setDocument(document);
+ return globalsViewer.getControl();
+ }
+
+ private String getProcessImports() {
+ String result = "# define your globals here: e.g. global java.util.List myList\n";
+ Map globals = process.getGlobals();
+ if (globals != null) {
+ for (Iterator iterator = globals.entrySet().iterator(); iterator.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ result += "global " + entry.getValue() + " " + entry.getKey() + "\n";
+ }
+ }
+ return result;
+ }
+
+ public Control createDialogArea(Composite parent) {
+ GridLayout layout = new GridLayout();
+ parent.setLayout(layout);
+ layout.numColumns = 1;
+ tabFolder = new TabFolder(parent, SWT.NONE);
+ GridData gd = new GridData();
+ 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("Globals");
+ textEditorTab.setControl(createTextualEditor(tabFolder));
+ return tabFolder;
+ }
+
+ protected void okPressed() {
+ success = true;
+ updateGlobals();
+ super.okPressed();
+ }
+
+ public boolean isSuccess() {
+ return success;
+ }
+
+ public Map getGlobals() {
+ return globals;
+ }
+
+ private void updateGlobals() {
+ this.globals = new HashMap();
+ Matcher matcher = GLOBAL_PATTERN.matcher(globalsViewer.getDocument().get());
+ while (matcher.find()) {
+ this.globals.put(matcher.group(2), matcher.group(1));
+ }
+ }
+}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java 2007-09-12 00:13:23 UTC (rev 15036)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java 2007-09-12 00:13:28 UTC (rev 15037)
@@ -109,7 +109,7 @@
gd.horizontalAlignment = GridData.FILL;
tabFolder.setLayoutData(gd);
TabItem textEditorTab = new TabItem(tabFolder, SWT.NONE);
- textEditorTab.setText("Textual Editor");
+ textEditorTab.setText("Imports");
textEditorTab.setControl(createTextualEditor(tabFolder));
return tabFolder;
}
More information about the jboss-svn-commits
mailing list