[jboss-svn-commits] JBL Code SVN: r31329 - in labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse: core and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jan 29 18:17:32 EST 2010
Author: KrisVerlaenen
Date: 2010-01-29 18:17:31 -0500 (Fri, 29 Jan 2010)
New Revision: 31329
Added:
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ActivationGroup.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/AgendaGroup.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DefaultRuleGroup.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleFlowGroup.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleGroup.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsGroupByRuleGroupContentProvider.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/GroupOrderedAction.java
Modified:
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsPluginImages.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsElement.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsModelBuilder.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Package.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Rule.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsContentProvider.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsFilter.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsLabelProvider.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsTreeSorter.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/FilterActionGroup.java
labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/outline/RuleContentOutlinePage.java
Log:
JBRULES-135: Group Rules in outline view
- applied patch
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsPluginImages.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsPluginImages.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsPluginImages.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,154 +1,161 @@
-package org.drools.eclipse;
-/*
- * 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.net.MalformedURLException;
-import java.net.URL;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Handles the images used in this plugin.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- */
-public class DroolsPluginImages {
-
- public static final String IMG_LOGICAL = "ImageLogical";
- public static final String IMG_LOGICAL_DISABLED = "ImageLogicalDisabled";
- public static final String REFRESH_LOG = "RefreshLog";
- public static final String REFRESH_LOG_DISABLED = "RefreshLogDisabled";
- public static final String OPEN_LOG = "OpenLog";
- public static final String DELETE_LOG = "ClearLog";
- public static final String DELETE_LOG_DISABLED = "ClearLogDisabled";
- public static final String INSERT = "Insert";
- public static final String UPDATE = "Update";
- public static final String RETRACT = "RetractO";
- public static final String CREATE_ACTIVATION = "CreateActivation";
- public static final String CANCEL_ACTIVATION = "CancelActivation";
- public static final String EXECUTE_ACTIVATION = "ExecuteActivation";
- public static final String CLASS = "Class";
- public static final String PACKAGE = "Package";
- public static final String METHOD = "Method";
- public static final String VARIABLE = "Variable";
- public static final String DROOLS = "Drools";
- public static final String RULE = "DroolsRule";
- public static final String QUERY = "DroolsQuery";
- public static final String DSL_EXPRESSION = "DslExpression";
- public static final String IMPORT = "Import";
- public static final String DSL = "DSL";
- public static final String GLOBAL = "Global";
- public static final String RULEFLOW = "RuleFlow";
- public static final String RULEFLOW_GROUP = "RuleFlowGroup";
- public static final String RULEFLOW_NODE_TRIGGERED = "RuleFlowNodeTriggered";
-
- private static ImageRegistry imageRegistry;
- private static final String PATH_SUFFIX = "/icons/";
- private static final URL ICON_BASE_URL =
- DroolsEclipsePlugin.getDefault().getBundle().getEntry(PATH_SUFFIX);
-
- private static void declareImages() {
- declareRegistryImage(IMG_LOGICAL, "logical_structure.gif");
- declareRegistryImage(IMG_LOGICAL_DISABLED, "logical_structure_disabled.gif");
- declareRegistryImage(REFRESH_LOG, "refresh.gif");
- declareRegistryImage(REFRESH_LOG_DISABLED, "refresh_disabled.gif");
- declareRegistryImage(OPEN_LOG, "open.gif");
- declareRegistryImage(DELETE_LOG, "clear.gif");
- declareRegistryImage(DELETE_LOG_DISABLED, "clear_disabled.gif");
- declareRegistryImage(INSERT, "greensquare.GIF");
- declareRegistryImage(UPDATE, "yellowsquare.GIF");
- declareRegistryImage(RETRACT, "redsquare.GIF");
- declareRegistryImage(CREATE_ACTIVATION, "arrowright.GIF");
- declareRegistryImage(CANCEL_ACTIVATION, "arrowleft.GIF");
- declareRegistryImage(EXECUTE_ACTIVATION, "bluediamond.GIF");
- declareRegistryImage(CLASS, "class_obj.gif");
- declareRegistryImage(PACKAGE, "package_obj.gif");
- declareRegistryImage(METHOD, "methpub_obj.gif");
- declareRegistryImage(VARIABLE, "field_private_obj.gif");
- declareRegistryImage(DROOLS, "drools.gif");
- declareRegistryImage(RULE, "drools-rule.GIF");
- declareRegistryImage(QUERY, "drools-query.GIF");
- declareRegistryImage(DSL_EXPRESSION, "dsl_expression.gif");
- declareRegistryImage(IMPORT, "import.gif");
- declareRegistryImage(DSL, "dsl.GIF");
- declareRegistryImage(GLOBAL, "field_public_obj.gif");
- declareRegistryImage(RULEFLOW, "process.gif");
- declareRegistryImage(RULEFLOW_GROUP, "activity.gif");
- declareRegistryImage(RULEFLOW_NODE_TRIGGERED, "node-triggered.gif");
- }
-
- /**
- * Declare an Image in the registry table.
- * @param key The key to use when registering the image
- * @param path The path where the image can be found. This path is relative to where
- * this plugin class is found (i.e. typically the packages directory)
- */
- public final static void declareRegistryImage(String key, String path) {
- ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor();
- try {
- desc= ImageDescriptor.createFromURL(makeIconFileURL(path));
- } catch (MalformedURLException e) {
- DroolsEclipsePlugin.log(e);
- }
- imageRegistry.put(key, desc);
- }
-
- /**
- * Returns the ImageRegistry.
- */
- public static ImageRegistry getImageRegistry() {
- if (imageRegistry == null) {
- initializeImageRegistry();
- }
- return imageRegistry;
- }
-
- public static ImageRegistry initializeImageRegistry() {
- imageRegistry = new ImageRegistry();
- declareImages();
- return imageRegistry;
- }
-
- /**
- * Returns the <code>Image</code> identified by the given key,
- * or <code>null</code> if it does not exist.
- */
- public static Image getImage(String key) {
- return getImageRegistry().get(key);
- }
-
- public static void putImage(String key, Image image) {
- getImageRegistry().put(key, image);
- }
-
- /**
- * Returns the <code>ImageDescriptor</code> identified by the given key,
- * or <code>null</code> if it does not exist.
- */
- public static ImageDescriptor getImageDescriptor(String key) {
- return getImageRegistry().getDescriptor(key);
- }
-
- private static URL makeIconFileURL(String iconPath) throws MalformedURLException {
- if (ICON_BASE_URL == null) {
- throw new MalformedURLException();
- }
-
- return new URL(ICON_BASE_URL, iconPath);
- }
+package org.drools.eclipse;
+/*
+ * 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.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Handles the images used in this plugin.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ */
+public class DroolsPluginImages {
+
+ public static final String IMG_LOGICAL = "ImageLogical";
+ public static final String IMG_LOGICAL_DISABLED = "ImageLogicalDisabled";
+ public static final String REFRESH_LOG = "RefreshLog";
+ public static final String REFRESH_LOG_DISABLED = "RefreshLogDisabled";
+ public static final String OPEN_LOG = "OpenLog";
+ public static final String DELETE_LOG = "ClearLog";
+ public static final String DELETE_LOG_DISABLED = "ClearLogDisabled";
+ public static final String INSERT = "Insert";
+ public static final String UPDATE = "Update";
+ public static final String RETRACT = "RetractO";
+ public static final String CREATE_ACTIVATION = "CreateActivation";
+ public static final String CANCEL_ACTIVATION = "CancelActivation";
+ public static final String EXECUTE_ACTIVATION = "ExecuteActivation";
+ public static final String CLASS = "Class";
+ public static final String PACKAGE = "Package";
+ public static final String METHOD = "Method";
+ public static final String VARIABLE = "Variable";
+ public static final String DROOLS = "Drools";
+ public static final String RULE = "DroolsRule";
+ public static final String QUERY = "DroolsQuery";
+ public static final String DSL_EXPRESSION = "DslExpression";
+ public static final String IMPORT = "Import";
+ public static final String DSL = "DSL";
+ public static final String GLOBAL = "Global";
+ public static final String RULEFLOW = "RuleFlow";
+ public static final String RULEFLOW_GROUP = "RuleFlowGroup";
+ public static final String RULEFLOW_NODE_TRIGGERED = "RuleFlowNodeTriggered";
+ public static final String RULEGROUP = "RuleGroup";
+ public static final String DEFAULTRULEGROUP = "DefaultRuleGroup";
+
+ // TODO : Change Image
+ public static final String GROUPS = "RuleFlowGroup";
+
+ private static ImageRegistry imageRegistry;
+ private static final String PATH_SUFFIX = "/icons/";
+ private static final URL ICON_BASE_URL =
+ DroolsEclipsePlugin.getDefault().getBundle().getEntry(PATH_SUFFIX);
+
+ private static void declareImages() {
+ declareRegistryImage(IMG_LOGICAL, "logical_structure.gif");
+ declareRegistryImage(IMG_LOGICAL_DISABLED, "logical_structure_disabled.gif");
+ declareRegistryImage(REFRESH_LOG, "refresh.gif");
+ declareRegistryImage(REFRESH_LOG_DISABLED, "refresh_disabled.gif");
+ declareRegistryImage(OPEN_LOG, "open.gif");
+ declareRegistryImage(DELETE_LOG, "clear.gif");
+ declareRegistryImage(DELETE_LOG_DISABLED, "clear_disabled.gif");
+ declareRegistryImage(INSERT, "greensquare.GIF");
+ declareRegistryImage(UPDATE, "yellowsquare.GIF");
+ declareRegistryImage(RETRACT, "redsquare.GIF");
+ declareRegistryImage(CREATE_ACTIVATION, "arrowright.GIF");
+ declareRegistryImage(CANCEL_ACTIVATION, "arrowleft.GIF");
+ declareRegistryImage(EXECUTE_ACTIVATION, "bluediamond.GIF");
+ declareRegistryImage(CLASS, "class_obj.gif");
+ declareRegistryImage(PACKAGE, "package_obj.gif");
+ declareRegistryImage(METHOD, "methpub_obj.gif");
+ declareRegistryImage(VARIABLE, "field_private_obj.gif");
+ declareRegistryImage(DROOLS, "drools.gif");
+ declareRegistryImage(RULE, "drools-rule.GIF");
+ declareRegistryImage(QUERY, "drools-query.GIF");
+ declareRegistryImage(DSL_EXPRESSION, "dsl_expression.gif");
+ declareRegistryImage(IMPORT, "import.gif");
+ declareRegistryImage(DSL, "dsl.GIF");
+ declareRegistryImage(GLOBAL, "field_public_obj.gif");
+ declareRegistryImage(RULEFLOW, "process.gif");
+ declareRegistryImage(RULEFLOW_GROUP, "activity.gif");
+ declareRegistryImage(RULEFLOW_NODE_TRIGGERED, "node-triggered.gif");
+ declareRegistryImage(RULEGROUP, "rulegroup.gif");
+ declareRegistryImage(DEFAULTRULEGROUP, "defaultrulegroup.gif");
+ }
+
+ /**
+ * Declare an Image in the registry table.
+ * @param key The key to use when registering the image
+ * @param path The path where the image can be found. This path is relative to where
+ * this plugin class is found (i.e. typically the packages directory)
+ */
+ public final static void declareRegistryImage(String key, String path) {
+ ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor();
+ try {
+ desc= ImageDescriptor.createFromURL(makeIconFileURL(path));
+ } catch (MalformedURLException e) {
+ DroolsEclipsePlugin.log(e);
+ }
+ imageRegistry.put(key, desc);
+ }
+
+ /**
+ * Returns the ImageRegistry.
+ */
+ public static ImageRegistry getImageRegistry() {
+ if (imageRegistry == null) {
+ initializeImageRegistry();
+ }
+ return imageRegistry;
+ }
+
+ public static ImageRegistry initializeImageRegistry() {
+ imageRegistry = new ImageRegistry();
+ declareImages();
+ return imageRegistry;
+ }
+
+ /**
+ * Returns the <code>Image</code> identified by the given key,
+ * or <code>null</code> if it does not exist.
+ */
+ public static Image getImage(String key) {
+ return getImageRegistry().get(key);
+ }
+
+ public static void putImage(String key, Image image) {
+ getImageRegistry().put(key, image);
+ }
+
+ /**
+ * Returns the <code>ImageDescriptor</code> identified by the given key,
+ * or <code>null</code> if it does not exist.
+ */
+ public static ImageDescriptor getImageDescriptor(String key) {
+ return getImageRegistry().getDescriptor(key);
+ }
+
+ private static URL makeIconFileURL(String iconPath) throws MalformedURLException {
+ if (ICON_BASE_URL == null) {
+ throw new MalformedURLException();
+ }
+
+ return new URL(ICON_BASE_URL, iconPath);
+ }
}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ActivationGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ActivationGroup.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ActivationGroup.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -0,0 +1,15 @@
+package org.drools.eclipse.core;
+
+public class ActivationGroup extends RuleGroup {
+
+ protected ActivationGroup(Package parent, Rule rule, String groupName) {
+ super(parent, rule, groupName);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public int getType() {
+ // TODO Auto-generated method stub
+ return ACTIVATION_GROUP;
+ }
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/AgendaGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/AgendaGroup.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/AgendaGroup.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -0,0 +1,15 @@
+package org.drools.eclipse.core;
+
+public class AgendaGroup extends RuleGroup {
+
+ protected AgendaGroup(Package parent, Rule rule, String groupName) {
+ super(parent, rule, groupName);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public int getType() {
+ // TODO Auto-generated method stub
+ return AGENDA_GROUP;
+ }
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DefaultRuleGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DefaultRuleGroup.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DefaultRuleGroup.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -0,0 +1,21 @@
+package org.drools.eclipse.core;
+
+public class DefaultRuleGroup extends RuleGroup {
+
+ protected DefaultRuleGroup(Package parent, Rule rule, String groupName) {
+ super(parent, rule, groupName);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public int getType() {
+ // TODO Auto-generated method stub
+ return DEFAULT_RULE_GROUP;
+ }
+
+ @Override
+ public String toString() {
+ // TODO Auto-generated method stub
+ return "*default*";
+ }
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsElement.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsElement.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsElement.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,67 +1,72 @@
-package org.drools.eclipse.core;
-
-import org.eclipse.core.resources.IFile;
-
-/**
- * This represents a drools model element. It is linked to its direct
- * parents and its children. If relevant, Drools model elements refer
- * to the file they are defined in and the offset and length of that
- * element in the file.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- */
-public abstract class DroolsElement {
-
- public static final int RULESET = 0;
- public static final int PACKAGE = 1;
- public static final int RULE = 2;
- public static final int QUERY = 3;
- public static final int FUNCTION = 4;
- public static final int TEMPLATE = 5;
- public static final int EXPANDER = 6;
- public static final int GLOBAL = 7;
- public static final int IMPORT = 8;
- public static final int RULE_ATTRIBUTE = 9;
- public static final int PROCESS = 10;
-
- protected static final DroolsElement[] NO_ELEMENTS = new DroolsElement[0];
-
- private DroolsElement parent;
- private IFile file;
- private int offset;
- private int length;
-
- protected DroolsElement(DroolsElement parent) {
- this.parent = parent;
- }
-
- public abstract int getType();
-
- public DroolsElement getParent() {
- return parent;
- }
-
- public abstract DroolsElement[] getChildren();
-
- public IFile getFile() {
- return file;
- }
-
- public int getOffset() {
- return offset;
- }
-
- public int getLength() {
- return length;
- }
-
- // These are helper methods for creating the model and should not
- // be used directly. Use DroolsModelBuilder instead.
-
- void setFile(IFile file, int offset, int length) {
- this.file = file;
- this.offset = offset;
- this.length = length;
- }
-
-}
+package org.drools.eclipse.core;
+
+import org.eclipse.core.resources.IFile;
+
+/**
+ * This represents a drools model element. It is linked to its direct
+ * parents and its children. If relevant, Drools model elements refer
+ * to the file they are defined in and the offset and length of that
+ * element in the file.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ */
+public abstract class DroolsElement {
+
+ public static final int RULESET = 0;
+ public static final int PACKAGE = 1;
+ public static final int RULE = 2;
+ public static final int QUERY = 3;
+ public static final int FUNCTION = 4;
+ public static final int TEMPLATE = 5;
+ public static final int EXPANDER = 6;
+ public static final int GLOBAL = 7;
+ public static final int IMPORT = 8;
+ public static final int RULE_ATTRIBUTE = 9;
+ public static final int PROCESS = 10;
+
+ public static final int DEFAULT_RULE_GROUP = 11;
+ public static final int ACTIVATION_GROUP = 12;
+ public static final int AGENDA_GROUP = 13;
+ public static final int RULEFLOW_GROUP = 14;
+
+ protected static final DroolsElement[] NO_ELEMENTS = new DroolsElement[0];
+
+ private DroolsElement parent;
+ private IFile file;
+ private int offset;
+ private int length;
+
+ protected DroolsElement(DroolsElement parent) {
+ this.parent = parent;
+ }
+
+ public abstract int getType();
+
+ public DroolsElement getParent() {
+ return parent;
+ }
+
+ public abstract DroolsElement[] getChildren();
+
+ public IFile getFile() {
+ return file;
+ }
+
+ public int getOffset() {
+ return offset;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ // These are helper methods for creating the model and should not
+ // be used directly. Use DroolsModelBuilder instead.
+
+ void setFile(IFile file, int offset, int length) {
+ this.file = file;
+ this.offset = offset;
+ this.length = length;
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsModelBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsModelBuilder.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/DroolsModelBuilder.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,204 +1,254 @@
-package org.drools.eclipse.core;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.resources.IFile;
-
-public class DroolsModelBuilder {
-
- public static RuleSet createRuleSet() {
- return new RuleSet();
- }
-
- public static Package createPackage(String packageName, int offset, int length) {
- Package pkg = new Package(null, packageName);
- pkg.setFile(null, offset, length);
- return pkg;
- }
-
- public static Package addPackage(RuleSet ruleSet, String packageName, int offset, int length) {
- Package pkg = new Package(ruleSet, packageName);
- pkg.setFile(null, offset, length);
- ruleSet.addPackage(pkg);
- return pkg;
- }
-
- public static void removePackage(Package pkg) {
- RuleSet ruleSet = pkg.getParentRuleSet();
- if (ruleSet != null) {
- ruleSet.removePackage(pkg.getPackageName());
- }
- }
-
- public static void clearRuleSet(RuleSet ruleSet) {
- ruleSet.clear();
- }
-
- public static Rule addRule(Package pkg, String ruleName, IFile file, int offset, int length, Map attributes) {
- Rule rule = new Rule(pkg, ruleName);
- rule.setFile(file, offset, length);
- if (attributes != null) {
- for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- RuleAttribute attribute = new RuleAttribute(rule, (String) entry.getKey(), entry.getValue());
- attribute.setFile(file, offset, length);
- rule.addAttribute(attribute);
- }
- }
- pkg.addRule(rule);
- return rule;
- }
-
- public static void removeRule(Rule rule) {
- Package pkg = rule.getParentPackage();
- if (pkg != null) {
- pkg.removeRule(rule);
- if (pkg.getChildren().length == 0) {
- removePackage(pkg);
- }
- }
- }
-
- public static Function addFunction(Package pkg, String functionName, IFile file, int offset, int length) {
- Function function = new Function(pkg, functionName);
- function.setFile(file, offset, length);
- pkg.addFunction(function);
- return function;
- }
-
- public static void removeFunction(Function function) {
- Package pkg = function.getParentPackage();
- if (pkg != null) {
- pkg.removeFunction(function);
- }
- }
-
- public static void addExpander(Package pkg, String expanderName, IFile file, int offset, int length) {
- Expander expander = new Expander(pkg, expanderName);
- expander.setFile(file, offset, length);
- pkg.addExpander(expander);
- }
-
- public static void removeExpander(Expander expander) {
- Package pkg = expander.getParentPackage();
- if (pkg != null) {
- pkg.removeExpander(expander);
- }
- }
-
- public static void addImport(Package pkg, String importClass, IFile file, int offset, int length) {
- Import imp = new Import(pkg, importClass);
- imp.setFile(file, offset, length);
- pkg.addImport(imp);
- }
-
- public static void removeImport(Import imp) {
- Package pkg = imp.getParentPackage();
- if (pkg != null) {
- pkg.removeImport(imp);
- }
- }
-
- public static Global addGlobal(Package pkg, String globalName, IFile file, int offset, int length) {
- Global global = new Global(pkg, globalName);
- global.setFile(file, offset, length);
- pkg.addGlobal(global);
- return global;
- }
-
- public static void removeGlobal(Global global) {
- Package pkg = global.getParentPackage();
- if (pkg != null) {
- pkg.removeGlobal(global);
- }
- }
-
- public static Query addQuery(Package pkg, String queryName, IFile file, int offset, int length) {
- Query query = new Query(pkg, queryName);
- query.setFile(file, offset, length);
- pkg.addQuery(query);
- return query;
- }
-
- public static void removeQuery(Query query) {
- Package pkg = query.getParentPackage();
- if (pkg != null) {
- pkg.removeQuery(query);
- }
- }
-
- public static Template addTemplate(Package pkg, String templateName, IFile file, int offset, int length) {
- Template template = new Template(pkg, templateName);
- template.setFile(file, offset, length);
- pkg.addTemplate(template);
- return template;
- }
-
- public static void removeTemplate(Template template) {
- Package pkg = template.getParentPackage();
- if (pkg != null) {
- pkg.removeTemplate(template);
- }
- }
-
- public static Process addProcess(Package pkg, String processId, IFile file) {
- Process process = new Process(pkg, processId);
- process.setFile(file, -1, -1);
- pkg.addProcess(process);
- return process;
- }
-
- public static void removeProcess(Process process) {
- Package pkg = process.getParentPackage();
- if (pkg != null) {
- pkg.removeProcess(process);
- }
- }
-
- public static void removeElement(DroolsElement element) {
- switch (element.getType()) {
- case DroolsElement.RULESET:
- clearRuleSet((RuleSet) element);
- break;
- case DroolsElement.PACKAGE:
- removePackage((Package) element);
- break;
- case DroolsElement.RULE:
- removeRule((Rule) element);
- removePackageIfEmpty(((Rule) element).getParentPackage());
- break;
- case DroolsElement.QUERY:
- removeQuery((Query) element);
- removePackageIfEmpty(((Query) element).getParentPackage());
- break;
- case DroolsElement.FUNCTION:
- removeFunction((Function) element);
- removePackageIfEmpty(((Function) element).getParentPackage());
- break;
- case DroolsElement.TEMPLATE:
- removeTemplate((Template) element);
- removePackageIfEmpty(((Template) element).getParentPackage());
- break;
- case DroolsElement.EXPANDER:
- removeExpander((Expander) element);
- removePackageIfEmpty(((Expander) element).getParentPackage());
- break;
- case DroolsElement.GLOBAL:
- removeGlobal((Global) element);
- removePackageIfEmpty(((Global) element).getParentPackage());
- break;
- case DroolsElement.PROCESS:
- removeProcess((Process) element);
- removePackageIfEmpty(((Process) element).getParentPackage());
- break;
- }
- }
-
- private static void removePackageIfEmpty(Package pkg) {
- if (pkg.getChildren().length == 0) {
- removePackage(pkg);
- }
- }
-
-}
+package org.drools.eclipse.core;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+
+public class DroolsModelBuilder {
+
+ public static RuleSet createRuleSet() {
+ return new RuleSet();
+ }
+
+ public static Package createPackage(String packageName, int offset,
+ int length) {
+ Package pkg = new Package(null, packageName);
+ pkg.setFile(null, offset, length);
+ return pkg;
+ }
+
+ public static Package addPackage(RuleSet ruleSet, String packageName,
+ int offset, int length) {
+ Package pkg = new Package(ruleSet, packageName);
+ pkg.setFile(null, offset, length);
+ ruleSet.addPackage(pkg);
+ return pkg;
+ }
+
+ public static void removePackage(Package pkg) {
+ RuleSet ruleSet = pkg.getParentRuleSet();
+ if (ruleSet != null) {
+ ruleSet.removePackage(pkg.getPackageName());
+ }
+ }
+
+ public static void clearRuleSet(RuleSet ruleSet) {
+ ruleSet.clear();
+ }
+
+ public static Rule addRule(Package pkg, String ruleName, IFile file,
+ int offset, int length, Map attributes) {
+ Rule rule = new Rule(pkg, ruleName);
+ rule.setFile(file, offset, length);
+ if (attributes != null) {
+ for (Iterator iterator = attributes.entrySet().iterator(); iterator
+ .hasNext();) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ String attributeKey = (String) entry.getKey();
+ String attributeValue = (String) entry.getValue();
+ RuleAttribute attribute = new RuleAttribute(rule, attributeKey,
+ attributeValue);
+ attribute.setFile(file, offset, length);
+ rule.addAttribute(attribute);
+ // TODO Create constant for Attribute ??
+ RuleGroup group = null;
+ if (attributeKey.equals("agenda-group")) {
+ group = pkg.getGroup(attributeValue,
+ DroolsElement.AGENDA_GROUP);
+ if (group != null) {
+ group.addRule(rule);
+ } else {
+ group = new AgendaGroup(pkg, rule, attributeValue);
+ }
+ }
+ if (attributeKey.equals("ruleflow-group")) {
+ group = pkg.getGroup(attributeValue,
+ DroolsElement.RULEFLOW_GROUP);
+ if (group != null) {
+ group.addRule(rule);
+ } else {
+ group = new RuleFlowGroup(pkg, rule, attributeValue);
+ }
+ }
+ if (attributeKey.equals("activation-group")) {
+ group = pkg.getGroup(attributeValue,
+ DroolsElement.ACTIVATION_GROUP);
+ if (group != null) {
+ group.addRule(rule);
+ } else {
+ group = new ActivationGroup(pkg, rule, attributeValue);
+ }
+ }
+ if (group != null) {
+ rule.setGroup(group);
+ group.setFile(file, offset, length);
+ }
+
+ }
+ if (rule.getGroup() == null) {
+ pkg.getDefaultGroup().addRule(rule);
+ }
+ }
+ pkg.addRule(rule);
+ return rule;
+ }
+
+ public static void removeRule(Rule rule) {
+ Package pkg = rule.getParentPackage();
+ if (pkg != null) {
+ pkg.removeRule(rule);
+ if (pkg.getChildren().length == 0) {
+ removePackage(pkg);
+ }
+ }
+ }
+
+ public static Function addFunction(Package pkg, String functionName,
+ IFile file, int offset, int length) {
+ Function function = new Function(pkg, functionName);
+ function.setFile(file, offset, length);
+ pkg.addFunction(function);
+ return function;
+ }
+
+ public static void removeFunction(Function function) {
+ Package pkg = function.getParentPackage();
+ if (pkg != null) {
+ pkg.removeFunction(function);
+ }
+ }
+
+ public static void addExpander(Package pkg, String expanderName,
+ IFile file, int offset, int length) {
+ Expander expander = new Expander(pkg, expanderName);
+ expander.setFile(file, offset, length);
+ pkg.addExpander(expander);
+ }
+
+ public static void removeExpander(Expander expander) {
+ Package pkg = expander.getParentPackage();
+ if (pkg != null) {
+ pkg.removeExpander(expander);
+ }
+ }
+
+ public static void addImport(Package pkg, String importClass, IFile file,
+ int offset, int length) {
+ Import imp = new Import(pkg, importClass);
+ imp.setFile(file, offset, length);
+ pkg.addImport(imp);
+ }
+
+ public static void removeImport(Import imp) {
+ Package pkg = imp.getParentPackage();
+ if (pkg != null) {
+ pkg.removeImport(imp);
+ }
+ }
+
+ public static Global addGlobal(Package pkg, String globalName, IFile file,
+ int offset, int length) {
+ Global global = new Global(pkg, globalName);
+ global.setFile(file, offset, length);
+ pkg.addGlobal(global);
+ return global;
+ }
+
+ public static void removeGlobal(Global global) {
+ Package pkg = global.getParentPackage();
+ if (pkg != null) {
+ pkg.removeGlobal(global);
+ }
+ }
+
+ public static Query addQuery(Package pkg, String queryName, IFile file,
+ int offset, int length) {
+ Query query = new Query(pkg, queryName);
+ query.setFile(file, offset, length);
+ pkg.addQuery(query);
+ return query;
+ }
+
+ public static void removeQuery(Query query) {
+ Package pkg = query.getParentPackage();
+ if (pkg != null) {
+ pkg.removeQuery(query);
+ }
+ }
+
+ public static Template addTemplate(Package pkg, String templateName,
+ IFile file, int offset, int length) {
+ Template template = new Template(pkg, templateName);
+ template.setFile(file, offset, length);
+ pkg.addTemplate(template);
+ return template;
+ }
+
+ public static void removeTemplate(Template template) {
+ Package pkg = template.getParentPackage();
+ if (pkg != null) {
+ pkg.removeTemplate(template);
+ }
+ }
+
+ public static Process addProcess(Package pkg, String processId, IFile file) {
+ Process process = new Process(pkg, processId);
+ process.setFile(file, -1, -1);
+ pkg.addProcess(process);
+ return process;
+ }
+
+ public static void removeProcess(Process process) {
+ Package pkg = process.getParentPackage();
+ if (pkg != null) {
+ pkg.removeProcess(process);
+ }
+ }
+
+ public static void removeElement(DroolsElement element) {
+ switch (element.getType()) {
+ case DroolsElement.RULESET:
+ clearRuleSet((RuleSet) element);
+ break;
+ case DroolsElement.PACKAGE:
+ removePackage((Package) element);
+ break;
+ case DroolsElement.RULE:
+ removeRule((Rule) element);
+ removePackageIfEmpty(((Rule) element).getParentPackage());
+ break;
+ case DroolsElement.QUERY:
+ removeQuery((Query) element);
+ removePackageIfEmpty(((Query) element).getParentPackage());
+ break;
+ case DroolsElement.FUNCTION:
+ removeFunction((Function) element);
+ removePackageIfEmpty(((Function) element).getParentPackage());
+ break;
+ case DroolsElement.TEMPLATE:
+ removeTemplate((Template) element);
+ removePackageIfEmpty(((Template) element).getParentPackage());
+ break;
+ case DroolsElement.EXPANDER:
+ removeExpander((Expander) element);
+ removePackageIfEmpty(((Expander) element).getParentPackage());
+ break;
+ case DroolsElement.GLOBAL:
+ removeGlobal((Global) element);
+ removePackageIfEmpty(((Global) element).getParentPackage());
+ break;
+ case DroolsElement.PROCESS:
+ removeProcess((Process) element);
+ removePackageIfEmpty(((Process) element).getParentPackage());
+ break;
+ }
+ }
+
+ private static void removePackageIfEmpty(Package pkg) {
+ if (pkg.getChildren().length == 0) {
+ removePackage(pkg);
+ }
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Package.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Package.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Package.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,125 +1,175 @@
-package org.drools.eclipse.core;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This represents a package.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
- */
-public class Package extends DroolsElement {
-
- private String packageName;
- private List rules = new ArrayList();
- private List functions = new ArrayList();
- private List expanders = new ArrayList();
- private List imports = new ArrayList();
- private List globals = new ArrayList();
- private List queries = new ArrayList();
- private List templates = new ArrayList();
- private List processes = new ArrayList();
-
- Package(RuleSet parent, String packageName) {
- super(parent);
- this.packageName =
- packageName == null ? "(default package)" : packageName;
- }
-
- public RuleSet getParentRuleSet() {
- return (RuleSet) getParent();
- }
-
- public String getPackageName() {
- return packageName;
- }
-
- public int getType() {
- return PACKAGE;
- }
-
- public DroolsElement[] getChildren() {
- List children = new ArrayList();
- children.addAll(rules);
- children.addAll(queries);
- children.addAll(globals);
- children.addAll(functions);
- children.addAll(expanders);
- children.addAll(imports);
- children.addAll(templates);
- children.addAll(processes);
- return (DroolsElement[]) children.toArray(new DroolsElement[0]);
- }
-
- public String toString() {
- return packageName;
- }
-
- // These are helper methods for creating the model and should not
- // be used directly. Use DroolsModelBuilder instead.
-
- void addRule(Rule rule) {
- rules.add(rule);
- }
-
- void removeRule(Rule rule) {
- rules.remove(rule);
- }
-
- void addFunction(Function function) {
- functions.add(function);
- }
-
- void removeFunction(Function function) {
- functions.remove(function);
- }
-
- void addExpander(Expander expander) {
- expanders.add(expander);
- }
-
- void removeExpander(Expander expander) {
- expanders.remove(expander);
- }
-
- void addImport(Import imp) {
- imports.add(imp);
- }
-
- void removeImport(Import imp) {
- imports.remove(imp);
- }
-
- void addGlobal(Global global) {
- globals.add(global);
- }
-
- void removeGlobal(Global global) {
- globals.remove(global);
- }
-
- void addQuery(Query query) {
- queries.add(query);
- }
-
- void removeQuery(Query query) {
- queries.remove(query);
- }
-
- void addTemplate(Template template) {
- templates.add(template);
- }
-
- void removeTemplate(Template template) {
- templates.remove(template);
- }
-
- void addProcess(Process process) {
- processes.add(process);
- }
-
- void removeProcess(Process process) {
- processes.remove(process);
- }
-
-}
+package org.drools.eclipse.core;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * This represents a package.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class Package extends DroolsElement {
+
+ private String packageName;
+ private List rules = new ArrayList();
+ private List functions = new ArrayList();
+ private List expanders = new ArrayList();
+ private List imports = new ArrayList();
+ private List globals = new ArrayList();
+ private List queries = new ArrayList();
+ private List templates = new ArrayList();
+ private List processes = new ArrayList();
+ private Map groups = new HashMap();
+
+ private DefaultRuleGroup defaultGroup = null;
+
+ Package(RuleSet parent, String packageName) {
+ super(parent);
+ this.packageName = packageName == null ? "(default package)"
+ : packageName;
+ defaultGroup = new DefaultRuleGroup(this, null, "MAIN");
+ }
+
+ public RuleSet getParentRuleSet() {
+ return (RuleSet) getParent();
+ }
+
+ public String getPackageName() {
+ return packageName;
+ }
+
+ public int getType() {
+ return PACKAGE;
+ }
+
+ public DroolsElement[] getChildren() {
+ List children = new ArrayList();
+ children.addAll(rules);
+ children.addAll(queries);
+ children.addAll(globals);
+ children.addAll(functions);
+ children.addAll(expanders);
+ children.addAll(imports);
+ children.addAll(templates);
+ children.addAll(processes);
+ // }
+ return (DroolsElement[]) children.toArray(new DroolsElement[0]);
+ }
+
+ public String toString() {
+ return packageName;
+ }
+
+ // These are helper methods for creating the model and should not
+ // be used directly. Use DroolsModelBuilder instead.
+
+ void addRule(Rule rule) {
+ rules.add(rule);
+ }
+
+ void removeRule(Rule rule) {
+ rules.remove(rule);
+ }
+
+ void addFunction(Function function) {
+ functions.add(function);
+ }
+
+ void removeFunction(Function function) {
+ functions.remove(function);
+ }
+
+ void addExpander(Expander expander) {
+ expanders.add(expander);
+ }
+
+ void removeExpander(Expander expander) {
+ expanders.remove(expander);
+ }
+
+ void addImport(Import imp) {
+ imports.add(imp);
+ }
+
+ void removeImport(Import imp) {
+ imports.remove(imp);
+ }
+
+ void addGlobal(Global global) {
+ globals.add(global);
+ }
+
+ void removeGlobal(Global global) {
+ globals.remove(global);
+ }
+
+ void addQuery(Query query) {
+ queries.add(query);
+ }
+
+ void removeQuery(Query query) {
+ queries.remove(query);
+ }
+
+ void addTemplate(Template template) {
+ templates.add(template);
+ }
+
+ void removeTemplate(Template template) {
+ templates.remove(template);
+ }
+
+ void addProcess(Process process) {
+ processes.add(process);
+ }
+
+ void removeProcess(Process process) {
+ processes.remove(process);
+ }
+
+ public RuleGroup getGroup(String name, int type) {
+ Map entries = (Map) groups.get(type);
+ if ((entries != null) && (entries.containsKey(name))) {
+ return (RuleGroup) entries.get(name);
+ }
+ return null;
+ }
+
+ void addGroup(RuleGroup group) {
+ Map entries = (Map) groups.get(group.getType());
+ if (entries == null) {
+ entries = new HashMap();
+ entries.put(group.toString(), group);
+ groups.put(group.getType(), entries);
+ } else {
+ if (!entries.containsKey(group.toString())) {
+ entries.put(group.toString(), group);
+ }
+ }
+ }
+
+ public RuleGroup getDefaultGroup() {
+ return defaultGroup;
+ }
+
+ void removeGroup(RuleGroup group) {
+ Map entries = (Map) groups.get(group.getType());
+ if (entries.containsValue(group)) {
+ entries.remove(group);
+ }
+ }
+
+ public DroolsElement[] getGroups() {
+ List returnedValue = new ArrayList();
+ for (Iterator it = groups.keySet().iterator(); it.hasNext();) {
+ int key = (Integer) it.next();
+ Map entries = (Map) groups.get(key);
+ returnedValue.addAll(entries.values());
+ }
+ return (DroolsElement[]) returnedValue.toArray(new DroolsElement[0]);
+ }
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Rule.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Rule.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/Rule.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,52 +1,67 @@
-package org.drools.eclipse.core;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * This represents a rule.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- */
-public class Rule extends DroolsElement {
-
- private final String ruleName;
- private Map attributes = new HashMap();
-
- Rule(Package parent, String ruleName) {
- super(parent);
- this.ruleName = ruleName;
- }
-
- public Package getParentPackage() {
- return (Package) getParent();
- }
-
- public String getRuleName() {
- return ruleName;
- }
-
- public RuleAttribute getAttribute(String attributeName) {
- return (RuleAttribute) attributes.get(attributeName);
- }
-
- public int getType() {
- return RULE;
- }
-
- public DroolsElement[] getChildren() {
- return NO_ELEMENTS;
- }
-
- public String toString() {
- return ruleName;
- }
-
- // These are helper methods for creating the model and should not
- // be used directly. Use DroolsModelBuilder instead.
-
- void addAttribute(RuleAttribute attribute) {
- attributes.put(attribute.getAttributeName(), attribute);
- }
-
-}
+package org.drools.eclipse.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.ui.internal.views.markers.GroupsContribution;
+
+/**
+ * This represents a rule.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ */
+public class Rule extends DroolsElement {
+
+ private final String ruleName;
+ private Map attributes = new HashMap();
+ private RuleGroup group = null;
+
+ Rule(Package parent, String ruleName) {
+ super(parent);
+ this.ruleName = ruleName;
+ }
+
+ public Package getParentPackage() {
+ return (Package) getParent();
+ }
+
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ public RuleGroup getGroup() {
+ Package pkg = (Package)getParent();
+ if (pkg.getDefaultGroup().equals(group)) {
+ return null;
+ }
+ return group;
+ }
+
+ public void setGroup(RuleGroup group) {
+ this.group = group;
+ }
+
+ public RuleAttribute getAttribute(String attributeName) {
+ return (RuleAttribute) attributes.get(attributeName);
+ }
+
+ public int getType() {
+ return RULE;
+ }
+
+ public DroolsElement[] getChildren() {
+ return NO_ELEMENTS;
+ }
+
+ public String toString() {
+ return ruleName;
+ }
+
+ // These are helper methods for creating the model and should not
+ // be used directly. Use DroolsModelBuilder instead.
+
+ void addAttribute(RuleAttribute attribute) {
+ attributes.put(attribute.getAttributeName(), attribute);
+ }
+
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleFlowGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleFlowGroup.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleFlowGroup.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -0,0 +1,15 @@
+package org.drools.eclipse.core;
+
+public class RuleFlowGroup extends RuleGroup {
+
+ protected RuleFlowGroup(Package parent, Rule rule, String groupName) {
+ super(parent, rule, groupName);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public int getType() {
+ // TODO Auto-generated method stub
+ return RULEFLOW_GROUP;
+ }
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleGroup.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/RuleGroup.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -0,0 +1,54 @@
+package org.drools.eclipse.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represent a rule group of type Agenda-Group Or RuleFlow-Group
+ *
+ * @author gDelebecque
+ *
+ */
+public abstract class RuleGroup extends DroolsElement {
+ private String groupName = null;
+ private List rules = new ArrayList();
+
+ protected RuleGroup(Package parent, Rule rule, String groupName) {
+ super(parent);
+ this.groupName = groupName;
+ addRule(rule);
+ parent.addGroup(this);
+ }
+
+ public DroolsElement[] getRules() {
+ return (DroolsElement[]) rules.toArray(new DroolsElement[0]);
+ }
+
+ @Override
+ public DroolsElement[] getChildren() {
+ return NO_ELEMENTS;
+ }
+
+ @Override
+ public abstract int getType();
+
+ @Override
+ public String toString() {
+ return groupName;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof String) {
+ String other = (String) obj;
+ return toString().equals(other.toString());
+ }
+ return false;
+ }
+
+ protected void addRule(Rule rule) {
+ if (rule!=null) {
+ if (!rules.contains(rule)) rules.add(rule);
+ }
+ }
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsContentProvider.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsContentProvider.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,44 +1,52 @@
-package org.drools.eclipse.core.ui;
-
-import org.drools.eclipse.core.DroolsElement;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-/**
- * Content provider for Drools model elements.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- */
-public class DroolsContentProvider implements ITreeContentProvider {
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof DroolsElement) {
- return ((DroolsElement) parentElement).getChildren();
- }
- return new Object[0];
- }
-
- public Object getParent(Object element) {
- if (element instanceof DroolsElement) {
- return ((DroolsElement) element).getParent();
- }
- return null;
- }
-
- public boolean hasChildren(Object element) {
- return getChildren(element).length > 0;
- }
-
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
- public void dispose() {
- // do nothing
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // do nothing
- }
-
-}
+package org.drools.eclipse.core.ui;
+
+import org.drools.eclipse.core.DroolsElement;
+import org.drools.eclipse.core.Rule;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Content provider for Drools model elements.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ */
+public class DroolsContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Rule) {
+ Rule rule = (Rule) parentElement;
+ if (rule.getGroup()==null) {
+ return new Object[]{};
+ }
+ return new Object[]{rule.getGroup()};
+ }
+ if (parentElement instanceof DroolsElement) {
+ return ((DroolsElement) parentElement).getChildren();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ if (element instanceof DroolsElement) {
+ return ((DroolsElement) element).getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public void dispose() {
+ // do nothing
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // do nothing
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsFilter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsFilter.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsFilter.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,59 +1,63 @@
-package org.drools.eclipse.core.ui;
-
-import org.drools.eclipse.core.DroolsElement;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerFilter;
-
-/**
- * Filter for the rules viewer.
- */
-public class DroolsFilter extends ViewerFilter {
-
- public static final int FILTER_RULES = 1;
- public static final int FILTER_QUERIES = 2;
- public static final int FILTER_FUNCTIONS = 4;
- public static final int FILTER_TEMPLATES = 8;
- public static final int FILTER_GLOBALS = 16;
-
- private int filterProperties;
-
- public final void addFilter(int filter) {
- filterProperties |= filter;
- }
-
- public final void removeFilter(int filter) {
- filterProperties &= (-1 ^ filter);
- }
-
- public final boolean hasFilter(int filter) {
- return (filterProperties & filter) != 0;
- }
-
- public boolean isFilterProperty(Object element, Object property) {
- return false;
- }
-
- public boolean select(Viewer viewer, Object parentElement, Object element) {
- if (element instanceof DroolsElement) {
- DroolsElement droolsElement = (DroolsElement) element;
- int type = droolsElement.getType();
- if (hasFilter(FILTER_RULES) && type == DroolsElement.RULE) {
- return false;
- }
- if (hasFilter(FILTER_QUERIES) && type == DroolsElement.QUERY) {
- return false;
- }
- if (hasFilter(FILTER_FUNCTIONS) && type == DroolsElement.FUNCTION) {
- return false;
- }
- if (hasFilter(FILTER_TEMPLATES) && type == DroolsElement.TEMPLATE) {
- return false;
- }
- if (hasFilter(FILTER_GLOBALS) && type == DroolsElement.GLOBAL) {
- return false;
- }
- }
- return true;
- }
-
-}
+package org.drools.eclipse.core.ui;
+
+import org.drools.eclipse.core.DroolsElement;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+
+/**
+ * Filter for the rules viewer.
+ */
+public class DroolsFilter extends ViewerFilter {
+
+ public static final int FILTER_RULES = 1;
+ public static final int FILTER_QUERIES = 2;
+ public static final int FILTER_FUNCTIONS = 4;
+ public static final int FILTER_TEMPLATES = 8;
+ public static final int FILTER_GLOBALS = 16;
+ public static final int FILTER_GROUPS = 32;
+
+ private int filterProperties;
+
+ public final void addFilter(int filter) {
+ filterProperties |= filter;
+ }
+
+ public final void removeFilter(int filter) {
+ filterProperties &= (-1 ^ filter);
+ }
+
+ public final boolean hasFilter(int filter) {
+ return (filterProperties & filter) != 0;
+ }
+
+ public boolean isFilterProperty(Object element, Object property) {
+ return false;
+ }
+
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof DroolsElement) {
+ DroolsElement droolsElement = (DroolsElement) element;
+ int type = droolsElement.getType();
+ if (hasFilter(FILTER_RULES) && type == DroolsElement.RULE) {
+ return false;
+ }
+ if (hasFilter(FILTER_QUERIES) && type == DroolsElement.QUERY) {
+ return false;
+ }
+ if (hasFilter(FILTER_FUNCTIONS) && type == DroolsElement.FUNCTION) {
+ return false;
+ }
+ if (hasFilter(FILTER_TEMPLATES) && type == DroolsElement.TEMPLATE) {
+ return false;
+ }
+ if (hasFilter(FILTER_GLOBALS) && type == DroolsElement.GLOBAL) {
+ return false;
+ }
+ if (hasFilter(FILTER_GROUPS) && ((type == DroolsElement.AGENDA_GROUP)||(type == DroolsElement.RULEFLOW_GROUP)||(type == DroolsElement.ACTIVATION_GROUP)||(type == DroolsElement.DEFAULT_RULE_GROUP))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsGroupByRuleGroupContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsGroupByRuleGroupContentProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsGroupByRuleGroupContentProvider.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -0,0 +1,60 @@
+package org.drools.eclipse.core.ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.drools.eclipse.core.DroolsElement;
+import org.drools.eclipse.core.Package;
+import org.drools.eclipse.core.RuleGroup;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Content provider for Drools model elements.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ */
+public class DroolsGroupByRuleGroupContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Package) {
+ Package pkg = (Package) parentElement;
+ return pkg.getGroups();
+ }
+ if (parentElement instanceof RuleGroup) {
+ RuleGroup group = (RuleGroup) parentElement;
+ return group.getRules();
+ }
+ if (parentElement instanceof DroolsElement) {
+ return ((DroolsElement) parentElement).getChildren();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ if (element instanceof DroolsElement) {
+ return ((DroolsElement) element).getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public void dispose() {
+ // do nothing
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // do nothing
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsLabelProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsLabelProvider.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsLabelProvider.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,32 +1,36 @@
-package org.drools.eclipse.core.ui;
-
-import org.drools.eclipse.DroolsPluginImages;
-import org.drools.eclipse.core.DroolsElement;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.graphics.Image;
-
-public class DroolsLabelProvider extends LabelProvider {
-
- private static final String[] ICONS = new String[] {
- DroolsPluginImages.PACKAGE, // ruleset
- DroolsPluginImages.PACKAGE, // package
- DroolsPluginImages.DROOLS, // rule
- DroolsPluginImages.DROOLS, // query
- DroolsPluginImages.METHOD, // function
- DroolsPluginImages.CLASS, // template
- DroolsPluginImages.DSL, // expander
- DroolsPluginImages.GLOBAL, // global
- DroolsPluginImages.IMPORT, // import
- DroolsPluginImages.DROOLS, // rule attribute
- DroolsPluginImages.RULEFLOW, // process
- };
-
- public Image getImage(Object element) {
- if (element instanceof DroolsElement) {
- String icon = ICONS[((DroolsElement) element).getType()];
- return DroolsPluginImages.getImageRegistry().get(icon);
- }
- return null;
- }
-
-}
+package org.drools.eclipse.core.ui;
+
+import org.drools.eclipse.DroolsPluginImages;
+import org.drools.eclipse.core.DroolsElement;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+public class DroolsLabelProvider extends LabelProvider {
+
+ private static final String[] ICONS = new String[] {
+ DroolsPluginImages.PACKAGE, // ruleset
+ DroolsPluginImages.PACKAGE, // package
+ DroolsPluginImages.DROOLS, // rule
+ DroolsPluginImages.DROOLS, // query
+ DroolsPluginImages.METHOD, // function
+ DroolsPluginImages.CLASS, // template
+ DroolsPluginImages.DSL, // expander
+ DroolsPluginImages.GLOBAL, // global
+ DroolsPluginImages.IMPORT, // import
+ DroolsPluginImages.DROOLS, // rule attribute
+ DroolsPluginImages.RULEFLOW, // process
+ DroolsPluginImages.DEFAULTRULEGROUP, // Default Rule Group
+ DroolsPluginImages.RULEGROUP, // Activation Group
+ DroolsPluginImages.RULEGROUP, // Agenda Group
+ DroolsPluginImages.RULEGROUP, // RuleFlow Group
+ };
+
+ public Image getImage(Object element) {
+ if (element instanceof DroolsElement) {
+ String icon = ICONS[((DroolsElement) element).getType()];
+ return DroolsPluginImages.getImageRegistry().get(icon);
+ }
+ return null;
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsTreeSorter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsTreeSorter.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/DroolsTreeSorter.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,82 +1,100 @@
-package org.drools.eclipse.core.ui;
-
-import org.drools.eclipse.core.DroolsElement;
-import org.drools.eclipse.core.Expander;
-import org.drools.eclipse.core.Function;
-import org.drools.eclipse.core.Global;
-import org.drools.eclipse.core.Import;
-import org.drools.eclipse.core.Package;
-import org.drools.eclipse.core.Query;
-import org.drools.eclipse.core.Rule;
-import org.drools.eclipse.core.RuleAttribute;
-import org.drools.eclipse.core.RuleSet;
-import org.drools.eclipse.core.Template;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerSorter;
-
-public class DroolsTreeSorter extends ViewerSorter {
-
- // level 0
- private static final int RULESET = 0;
-
- // level 1
- private static final int PACKAGE = 1;
-
- // level 2
- private static final int RULE = 2;
- private static final int QUERY = 3;
- private static final int FUNCTION = 4;
- private static final int TEMPLATE = 5;
- private static final int EXPANDER = 6;
- private static final int GLOBAL = 7;
- private static final int IMPORT = 8;
-
- // level 3
- private static final int RULE_ATTRIBUTE = 9;
-
- private static final int UNKNOWN = 10;
-
- private static DroolsLabelProvider labelProvider = new DroolsLabelProvider();
-
- public int compare(Viewer viewer, Object e1, Object e2) {
- DroolsElement node1 = (DroolsElement) e1;
- DroolsElement node2 = (DroolsElement) e2;
- int type1 = getElementType(node1);
- int type2 = getElementType(node2);
- if (type1 != type2) {
- return type1 - type2;
- }
- String label1 = labelProvider.getText(node1);
- String label2 = labelProvider.getText(node2);
- if (label1 == null) {
- return (label2 == null ? 0 : -1);
- }
- return label1.compareTo(label2);
- }
-
- private int getElementType(DroolsElement o) {
- if (o instanceof RuleSet) {
- return RULESET;
- } else if (o instanceof Package) {
- return PACKAGE;
- } else if (o instanceof Rule) {
- return RULE;
- } else if (o instanceof Query) {
- return QUERY;
- } else if (o instanceof Function) {
- return FUNCTION;
- } else if (o instanceof Template) {
- return TEMPLATE;
- } else if (o instanceof Expander) {
- return EXPANDER;
- } else if (o instanceof Global) {
- return GLOBAL;
- } else if (o instanceof Import) {
- return IMPORT;
- } else if (o instanceof RuleAttribute) {
- return RULE_ATTRIBUTE;
- }
- return UNKNOWN;
- }
-
-}
+package org.drools.eclipse.core.ui;
+
+import org.drools.eclipse.core.ActivationGroup;
+import org.drools.eclipse.core.AgendaGroup;
+import org.drools.eclipse.core.DefaultRuleGroup;
+import org.drools.eclipse.core.DroolsElement;
+import org.drools.eclipse.core.Expander;
+import org.drools.eclipse.core.Function;
+import org.drools.eclipse.core.Global;
+import org.drools.eclipse.core.Import;
+import org.drools.eclipse.core.Package;
+import org.drools.eclipse.core.Query;
+import org.drools.eclipse.core.Rule;
+import org.drools.eclipse.core.RuleAttribute;
+import org.drools.eclipse.core.RuleFlowGroup;
+import org.drools.eclipse.core.RuleGroup;
+import org.drools.eclipse.core.RuleSet;
+import org.drools.eclipse.core.Template;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+public class DroolsTreeSorter extends ViewerSorter {
+
+ // level 0
+ private static final int RULESET = 0;
+
+ // level 1
+ private static final int PACKAGE = 1;
+
+ // level 2
+ private static final int RULE = 2;
+ private static final int QUERY = 3;
+ private static final int FUNCTION = 4;
+ private static final int TEMPLATE = 5;
+ private static final int EXPANDER = 6;
+ private static final int GLOBAL = 7;
+ private static final int IMPORT = 8;
+
+ private static final int DEFAULT_RULE_GROUP = 11;
+ private static final int ACTIVATION_GROUP = 12;
+ private static final int AGENDA_GROUP = 13;
+ private static final int RULEFLOW_GROUP = 14;
+
+ // level 3
+ private static final int RULE_ATTRIBUTE = 9;
+
+ private static final int UNKNOWN = 10;
+
+ private static DroolsLabelProvider labelProvider = new DroolsLabelProvider();
+
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ DroolsElement node1 = (DroolsElement) e1;
+ DroolsElement node2 = (DroolsElement) e2;
+ int type1 = getElementType(node1);
+ int type2 = getElementType(node2);
+ if (type1 != type2) {
+ return type1 - type2;
+ }
+ String label1 = labelProvider.getText(node1);
+ String label2 = labelProvider.getText(node2);
+ if (label1 == null) {
+ return (label2 == null ? 0 : -1);
+ }
+ return label1.compareTo(label2);
+ }
+
+ private int getElementType(DroolsElement o) {
+ if (o instanceof RuleSet) {
+ return RULESET;
+ } else if (o instanceof Package) {
+ return PACKAGE;
+ } else if (o instanceof Rule) {
+ return RULE;
+ } else if (o instanceof Query) {
+ return QUERY;
+ } else if (o instanceof Function) {
+ return FUNCTION;
+ } else if (o instanceof Template) {
+ return TEMPLATE;
+ } else if (o instanceof Expander) {
+ return EXPANDER;
+ } else if (o instanceof Global) {
+ return GLOBAL;
+ } else if (o instanceof Import) {
+ return IMPORT;
+ } else if (o instanceof RuleAttribute) {
+ return RULE_ATTRIBUTE;
+ } else if (o instanceof RuleFlowGroup) {
+ return RULEFLOW_GROUP;
+ } else if (o instanceof AgendaGroup) {
+ return AGENDA_GROUP;
+ } else if (o instanceof ActivationGroup) {
+ return ACTIVATION_GROUP;
+ } else if (o instanceof DefaultRuleGroup) {
+ return DEFAULT_RULE_GROUP;
+ }
+ return UNKNOWN;
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/FilterActionGroup.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/FilterActionGroup.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/FilterActionGroup.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,112 +1,113 @@
-package org.drools.eclipse.core.ui;
-
-import org.drools.eclipse.DroolsEclipsePlugin;
-import org.drools.eclipse.DroolsPluginImages;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.util.Assert;
-import org.eclipse.jface.viewers.StructuredViewer;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.actions.ActionGroup;
-
-/**
- * Action Group that contributes filter buttons.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- */
-public class FilterActionGroup extends ActionGroup {
-
- private FilterAction[] filterActions;
- private DroolsFilter filter;
- public int i;
-
- private StructuredViewer viewer;
- private String viewerId;
-
- public FilterActionGroup(StructuredViewer viewer, String viewerId) {
- this.viewer = viewer;
- this.viewerId = viewerId;
- filter = new DroolsFilter();
- filterActions = new FilterAction[] {
- addFilterForType(DroolsFilter.FILTER_RULES, "Hide Rules", DroolsPluginImages.RULE),
- addFilterForType(DroolsFilter.FILTER_QUERIES, "Hide Queries", DroolsPluginImages.QUERY),
- addFilterForType(DroolsFilter.FILTER_FUNCTIONS, "Hide Functions", DroolsPluginImages.METHOD),
- addFilterForType(DroolsFilter.FILTER_GLOBALS, "Hide Globals", DroolsPluginImages.GLOBAL),
- addFilterForType(DroolsFilter.FILTER_TEMPLATES, "Hide Templates", DroolsPluginImages.CLASS),
- };
- viewer.addFilter(filter);
- }
-
- private FilterAction addFilterForType(int filterType, String tooltip, String imageDescriptorKey) {
- boolean filterEnabled = DroolsEclipsePlugin.getDefault()
- .getPreferenceStore().getBoolean(getPreferenceKey(filterType));
- if (filterEnabled) {
- filter.addFilter(filterType);
- }
- FilterAction hideAction = new FilterAction(this, tooltip, filterType, filterEnabled, imageDescriptorKey);
- hideAction.setToolTipText(tooltip);
- return hideAction;
- }
-
- private String getPreferenceKey(int filterProperty) {
- return "DroolsFilterActionGroup." + viewerId + '.' + String.valueOf(filterProperty);
- }
-
- public void setFilter(int filterType, boolean set) {
- setDroolsFilters(new int[] {filterType}, new boolean[] {set}, true);
- }
-
- private void setDroolsFilters(int[] propertyKeys, boolean[] propertyValues, boolean refresh) {
- if (propertyKeys.length == 0)
- return;
- Assert.isTrue(propertyKeys.length == propertyValues.length);
-
- for (int i= 0; i < propertyKeys.length; i++) {
- int filterProperty= propertyKeys[i];
- boolean set= propertyValues[i];
-
- IPreferenceStore store = DroolsEclipsePlugin.getDefault().getPreferenceStore();
- boolean found = false;
- for (int j= 0; j < filterActions.length; j++) {
- int currProperty= filterActions[j].getFilterType();
- if (currProperty == filterProperty) {
- filterActions[j].setChecked(set);
- found= true;
- store.setValue(getPreferenceKey(filterProperty), set);
- }
- }
- if (found) {
- if (set) {
- filter.addFilter(filterProperty);
- } else {
- filter.removeFilter(filterProperty);
- }
- }
- }
- if (refresh) {
- viewer.getControl().setRedraw(false);
- BusyIndicator.showWhile(viewer.getControl().getDisplay(), new Runnable() {
- public void run() {
- viewer.refresh();
- }
- });
- viewer.getControl().setRedraw(true);
- }
- }
-
- public boolean hasDroolsFilter(int filterType) {
- return filter.hasFilter(filterType);
- }
-
- public void fillActionBars(IActionBars actionBars) {
- contributeToToolBar(actionBars.getToolBarManager());
- }
-
- public void contributeToToolBar(IToolBarManager tbm) {
- for (int i= 0; i < filterActions.length; i++) {
- tbm.add(filterActions[i]);
- }
- }
-
+package org.drools.eclipse.core.ui;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.DroolsPluginImages;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.actions.ActionGroup;
+
+/**
+ * Action Group that contributes filter buttons.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ */
+public class FilterActionGroup extends ActionGroup {
+
+ private FilterAction[] filterActions;
+ private DroolsFilter filter;
+ public int i;
+
+ private StructuredViewer viewer;
+ private String viewerId;
+
+ public FilterActionGroup(StructuredViewer viewer, String viewerId) {
+ this.viewer = viewer;
+ this.viewerId = viewerId;
+ filter = new DroolsFilter();
+ filterActions = new FilterAction[] {
+ addFilterForType(DroolsFilter.FILTER_RULES, "Hide Rules", DroolsPluginImages.RULE),
+ addFilterForType(DroolsFilter.FILTER_QUERIES, "Hide Queries", DroolsPluginImages.QUERY),
+ addFilterForType(DroolsFilter.FILTER_FUNCTIONS, "Hide Functions", DroolsPluginImages.METHOD),
+ addFilterForType(DroolsFilter.FILTER_GLOBALS, "Hide Globals", DroolsPluginImages.GLOBAL),
+ addFilterForType(DroolsFilter.FILTER_TEMPLATES, "Hide Templates", DroolsPluginImages.CLASS),
+ addFilterForType(DroolsFilter.FILTER_GROUPS, "Hide Agenda/RuleFlow Groups", DroolsPluginImages.GROUPS),
+ };
+ viewer.addFilter(filter);
+ }
+
+ private FilterAction addFilterForType(int filterType, String tooltip, String imageDescriptorKey) {
+ boolean filterEnabled = DroolsEclipsePlugin.getDefault()
+ .getPreferenceStore().getBoolean(getPreferenceKey(filterType));
+ if (filterEnabled) {
+ filter.addFilter(filterType);
+ }
+ FilterAction hideAction = new FilterAction(this, tooltip, filterType, filterEnabled, imageDescriptorKey);
+ hideAction.setToolTipText(tooltip);
+ return hideAction;
+ }
+
+ private String getPreferenceKey(int filterProperty) {
+ return "DroolsFilterActionGroup." + viewerId + '.' + String.valueOf(filterProperty);
+ }
+
+ public void setFilter(int filterType, boolean set) {
+ setDroolsFilters(new int[] {filterType}, new boolean[] {set}, true);
+ }
+
+ private void setDroolsFilters(int[] propertyKeys, boolean[] propertyValues, boolean refresh) {
+ if (propertyKeys.length == 0)
+ return;
+ Assert.isTrue(propertyKeys.length == propertyValues.length);
+
+ for (int i= 0; i < propertyKeys.length; i++) {
+ int filterProperty= propertyKeys[i];
+ boolean set= propertyValues[i];
+
+ IPreferenceStore store = DroolsEclipsePlugin.getDefault().getPreferenceStore();
+ boolean found = false;
+ for (int j= 0; j < filterActions.length; j++) {
+ int currProperty= filterActions[j].getFilterType();
+ if (currProperty == filterProperty) {
+ filterActions[j].setChecked(set);
+ found= true;
+ store.setValue(getPreferenceKey(filterProperty), set);
+ }
+ }
+ if (found) {
+ if (set) {
+ filter.addFilter(filterProperty);
+ } else {
+ filter.removeFilter(filterProperty);
+ }
+ }
+ }
+ if (refresh) {
+ viewer.getControl().setRedraw(false);
+ BusyIndicator.showWhile(viewer.getControl().getDisplay(), new Runnable() {
+ public void run() {
+ viewer.refresh();
+ }
+ });
+ viewer.getControl().setRedraw(true);
+ }
+ }
+
+ public boolean hasDroolsFilter(int filterType) {
+ return filter.hasFilter(filterType);
+ }
+
+ public void fillActionBars(IActionBars actionBars) {
+ contributeToToolBar(actionBars.getToolBarManager());
+ }
+
+ public void contributeToToolBar(IToolBarManager tbm) {
+ for (int i= 0; i < filterActions.length; i++) {
+ tbm.add(filterActions[i]);
+ }
+ }
+
}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/GroupOrderedAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/GroupOrderedAction.java (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/core/ui/GroupOrderedAction.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -0,0 +1,30 @@
+package org.drools.eclipse.core.ui;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.custom.BusyIndicator;
+
+public class GroupOrderedAction extends Action {
+ private StructuredViewer viewer;
+ private String viewerId;
+
+ public GroupOrderedAction(StructuredViewer viewer, String viewerId) {
+ this.viewer = viewer;
+ this.viewerId = viewerId;
+ }
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+ if (true) {
+ viewer.getControl().setRedraw(false);
+ BusyIndicator.showWhile(viewer.getControl().getDisplay(), new Runnable() {
+ public void run() {
+ viewer.refresh();
+ }
+ });
+ viewer.getControl().setRedraw(true);
+ }
+ }
+
+}
Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/outline/RuleContentOutlinePage.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/outline/RuleContentOutlinePage.java 2010-01-29 22:06:11 UTC (rev 31328)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/outline/RuleContentOutlinePage.java 2010-01-29 23:17:31 UTC (rev 31329)
@@ -1,254 +1,319 @@
-package org.drools.eclipse.editors.outline;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.drools.compiler.DroolsParserException;
-import org.drools.eclipse.DRLInfo;
-import org.drools.eclipse.DroolsEclipsePlugin;
-import org.drools.eclipse.core.DroolsElement;
-import org.drools.eclipse.core.DroolsModelBuilder;
-import org.drools.eclipse.core.Package;
-import org.drools.eclipse.core.RuleSet;
-import org.drools.eclipse.core.ui.DroolsContentProvider;
-import org.drools.eclipse.core.ui.DroolsLabelProvider;
-import org.drools.eclipse.core.ui.DroolsTreeSorter;
-import org.drools.eclipse.core.ui.FilterActionGroup;
-import org.drools.eclipse.editors.AbstractRuleEditor;
-import org.drools.lang.descr.AttributeDescr;
-import org.drools.lang.descr.PackageDescr;
-import org.drools.lang.descr.RuleDescr;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
-
-/**
- * Simple outline view of a DRL file. At present this is not wired in with the Parser, so it is fault
- * tolerant of incorrect syntax.
- * Should provide navigation assistance in large rule files.
- *
- * @author "Jeff Brown" <brown_j at ociweb.com>
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- */
-public class RuleContentOutlinePage extends ContentOutlinePage {
-
- private AbstractRuleEditor editor;
- private RuleSet ruleSet = DroolsModelBuilder.createRuleSet();
- private Map<String, RuleDescr> rules;
-
- ///////////////////////////////////
- // Patterns that the parser uses
- // TODO: this should just reuse the existing parser to avoid inconsistencies
- // with for example comments
- ///////////////////////////////////
- private static final Pattern RULE_PATTERN1 = Pattern.compile(
- "\\n\\s*rule\\s+\"([^\"]+)\"", Pattern.DOTALL);
-
- private static final Pattern RULE_PATTERN2 = Pattern.compile(
- "\\n\\s*rule\\s+([^\\s;#\"]+)", Pattern.DOTALL);
-
- private static final Pattern PACKAGE_PATTERN = Pattern.compile(
- "\\s*package\\s+([^\\s;#]+);?", Pattern.DOTALL);
-
- private static final Pattern FUNCTION_PATTERN = Pattern.compile(
- "\\n\\s*function\\s+(\\S+)\\s+(\\S+)\\(.*?\\)", Pattern.DOTALL);
-
- private static final Pattern TEMPLATE_PATTERN = Pattern.compile(
- "\\n\\s*template\\s+([^\\s;#\"]+)", Pattern.DOTALL);
-
- private static final Pattern IMPORT_PATTERN = Pattern.compile(
- "\\n\\s*import\\s+([^\\s;#]+);?", Pattern.DOTALL);
-
- private static final Pattern EXPANDER_PATTERN = Pattern.compile(
- "\\n\\s*expander\\s+([^\\s;#]+);?", Pattern.DOTALL);
-
- private static final Pattern GLOBAL_PATTERN = Pattern.compile(
- "\\n\\s*global\\s+(\\S+)\\s+([^\\s;#]+);?", Pattern.DOTALL);
-
- private static final Pattern QUERY_PATTERN1 = Pattern.compile(
- "\\n\\s*query\\s+\"([^\"]+)\"", Pattern.DOTALL);
-
- private static final Pattern QUERY_PATTERN2 = Pattern.compile(
- "\\n\\s*query\\s+([^\\s;#\"]+)", Pattern.DOTALL);
-
- public RuleContentOutlinePage(AbstractRuleEditor editor) {
- this.editor = editor;
- }
-
- public void createControl(Composite parent) {
- super.createControl(parent);
- TreeViewer viewer = getTreeViewer();
- viewer.setContentProvider(new DroolsContentProvider());
- viewer.setLabelProvider(new DroolsLabelProvider());
- viewer.setSorter(new DroolsTreeSorter());
- viewer.setInput(ruleSet);
- FilterActionGroup filterActionGroup = new FilterActionGroup(
- viewer, "org.drools.eclipse.editors.outline.RuleContentOutlinePage");
- filterActionGroup.fillActionBars(getSite().getActionBars());
- update();
-
- // add the listener for navigation of the rule document.
- super.addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- Object selectionObj = event.getSelection();
- if (selectionObj != null && selectionObj instanceof StructuredSelection) {
- StructuredSelection sel = (StructuredSelection) selectionObj;
- DroolsElement element = (DroolsElement) sel.getFirstElement();
- if (element != null) {
- editor.selectAndReveal(element.getOffset(),
- element.getLength());
- }
- }
- }
- });
- }
-
- /**
- * Updates the outline page.
- */
- public void update() {
- TreeViewer viewer = getTreeViewer();
- if (viewer != null) {
- Control control = viewer.getControl();
- if (control != null && !control.isDisposed()) {
- initRules();
- populatePackageTreeNode();
- viewer.refresh();
- control.setRedraw(false);
- viewer.expandToLevel(2);
- control.setRedraw(true);
- }
- }
- }
-
- /**
- * populates the PackageTreeNode with all of its child elements
- *
- * @param packageTreeNode the node to populate
- */
- public void populatePackageTreeNode() {
- String ruleFileContents = editor.getContent();
- populatePackageTreeNode(ruleFileContents);
- }
-
- void populatePackageTreeNode(String ruleFileContents) {
- DroolsModelBuilder.clearRuleSet(ruleSet);
- Matcher matcher = PACKAGE_PATTERN.matcher(ruleFileContents);
- String packageName = null;
- int startChar = 0;
- int endChar = 0;
- if (matcher.find()) {
- packageName = matcher.group(1);
- startChar = matcher.start(1);
- endChar = matcher.end(1);
- }
- Package pkg = DroolsModelBuilder.addPackage(ruleSet, packageName,
- startChar, endChar - startChar);
-
- matcher = RULE_PATTERN1.matcher(ruleFileContents);
- while (matcher.find()) {
- String ruleName = matcher.group(1);
- RuleDescr descr = (RuleDescr) rules.get(ruleName);
- if (descr != null) {
- DroolsModelBuilder.addRule(pkg, ruleName, null,
- matcher.start(1), matcher.end(1) - matcher.start(1),
- extractAttributes(descr));
- }
- }
- matcher = RULE_PATTERN2.matcher(ruleFileContents);
- while (matcher.find()) {
- String ruleName = matcher.group(1);
- RuleDescr descr = (RuleDescr) rules.get(ruleName);
- if (descr != null) {
- DroolsModelBuilder.addRule(pkg, ruleName, null,
- matcher.start(1), matcher.end(1) - matcher.start(1),
- extractAttributes(descr));
- }
- }
- matcher = FUNCTION_PATTERN.matcher(ruleFileContents);
- while (matcher.find()) {
- String functionName = matcher.group(2);
- DroolsModelBuilder.addFunction(pkg, functionName + "()", null,
- matcher.start(2), matcher.end(2) - matcher.start(2));
- }
- matcher = EXPANDER_PATTERN.matcher(ruleFileContents);
- if (matcher.find()) {
- String expanderName = matcher.group(1);
- DroolsModelBuilder.addExpander(pkg, expanderName, null,
- matcher.start(1), matcher.end(1) - matcher.start(1));
- }
- matcher = IMPORT_PATTERN.matcher(ruleFileContents);
- while (matcher.find()) {
- String importName = matcher.group(1);
- DroolsModelBuilder.addImport(pkg, importName, null,
- matcher.start(1), matcher.end(1) - matcher.start(1));
- }
- matcher = GLOBAL_PATTERN.matcher(ruleFileContents);
- while (matcher.find()) {
- String globalType = matcher.group(1);
- String globalName = matcher.group(2);
- String name = globalName + " : " + globalType;
- DroolsModelBuilder.addGlobal(pkg, name, null,
- matcher.start(2), matcher.end(2) - matcher.start(2));
- }
- matcher = QUERY_PATTERN1.matcher(ruleFileContents);
- while (matcher.find()) {
- String queryName = matcher.group(1);
- DroolsModelBuilder.addQuery(pkg, queryName, null,
- matcher.start(1), matcher.end(1) - matcher.start(1));
- }
- matcher = QUERY_PATTERN2.matcher(ruleFileContents);
- while (matcher.find()) {
- String queryName = matcher.group(1);
- DroolsModelBuilder.addQuery(pkg, queryName, null,
- matcher.start(1), matcher.end(1) - matcher.start(1));
- }
- matcher = TEMPLATE_PATTERN.matcher(ruleFileContents);
- while (matcher.find()) {
- String templateName = matcher.group(1);
- DroolsModelBuilder.addTemplate(pkg, templateName, null,
- matcher.start(1), matcher.end(1) - matcher.start(1));
- }
- }
-
- RuleSet getRuleSet() {
- return ruleSet;
- }
-
- private Map<String, String> extractAttributes(RuleDescr ruleDescr) {
- Map<String, String> attributes = null;
- if (ruleDescr != null) {
- attributes = new HashMap<String, String>();
- for (AttributeDescr attribute: ruleDescr.getAttributes().values()) {
- if (attribute != null && attribute.getName() != null) {
- attributes.put(attribute.getName(), attribute.getValue());
- }
- }
- }
- return attributes;
- }
-
- public void initRules() {
- rules = new HashMap<String, RuleDescr>();
- try {
- DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(editor, true, false);
- if (drlInfo != null) {
- PackageDescr packageDescr = drlInfo.getPackageDescr();
- if (packageDescr != null) {
- for (RuleDescr ruleDescr: packageDescr.getRules()) {
- rules.put(ruleDescr.getName(), ruleDescr);
- }
- }
- }
- } catch (DroolsParserException e) {
- DroolsEclipsePlugin.log(e);
- }
- }
-
+package org.drools.eclipse.editors.outline;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.compiler.DroolsParserException;
+import org.drools.eclipse.DRLInfo;
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.DroolsPluginImages;
+import org.drools.eclipse.core.DroolsElement;
+import org.drools.eclipse.core.DroolsModelBuilder;
+import org.drools.eclipse.core.Package;
+import org.drools.eclipse.core.RuleSet;
+import org.drools.eclipse.core.ui.DroolsContentProvider;
+import org.drools.eclipse.core.ui.DroolsGroupByRuleGroupContentProvider;
+import org.drools.eclipse.core.ui.DroolsLabelProvider;
+import org.drools.eclipse.core.ui.DroolsTreeSorter;
+import org.drools.eclipse.core.ui.FilterActionGroup;
+import org.drools.eclipse.editors.AbstractRuleEditor;
+import org.drools.lang.descr.AttributeDescr;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.lang.descr.RuleDescr;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+
+/**
+ * Simple outline view of a DRL file. At present this is not wired in with the Parser, so it is fault
+ * tolerant of incorrect syntax.
+ * Should provide navigation assistance in large rule files.
+ *
+ * @author "Jeff Brown" <brown_j at ociweb.com>
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ */
+public class RuleContentOutlinePage extends ContentOutlinePage {
+
+ private AbstractRuleEditor editor;
+ private RuleSet ruleSet = DroolsModelBuilder.createRuleSet();
+ private Map<String, RuleDescr> rules;
+
+ private boolean groupByRulegroup = false;
+ private TreeViewer viewer = null;
+ ///////////////////////////////////
+ // Patterns that the parser uses
+ // TODO: this should just reuse the existing parser to avoid inconsistencies
+ // with for example comments
+ ///////////////////////////////////
+ private static final Pattern RULE_PATTERN1 = Pattern.compile(
+ "\\n\\s*rule\\s+\"([^\"]+)\"", Pattern.DOTALL);
+
+ private static final Pattern RULE_PATTERN2 = Pattern.compile(
+ "\\n\\s*rule\\s+([^\\s;#\"]+)", Pattern.DOTALL);
+
+ private static final Pattern PACKAGE_PATTERN = Pattern.compile(
+ "\\s*package\\s+([^\\s;#]+);?", Pattern.DOTALL);
+
+ private static final Pattern FUNCTION_PATTERN = Pattern.compile(
+ "\\n\\s*function\\s+(\\S+)\\s+(\\S+)\\(.*?\\)", Pattern.DOTALL);
+
+ private static final Pattern TEMPLATE_PATTERN = Pattern.compile(
+ "\\n\\s*template\\s+([^\\s;#\"]+)", Pattern.DOTALL);
+
+ private static final Pattern IMPORT_PATTERN = Pattern.compile(
+ "\\n\\s*import\\s+([^\\s;#]+);?", Pattern.DOTALL);
+
+ private static final Pattern EXPANDER_PATTERN = Pattern.compile(
+ "\\n\\s*expander\\s+([^\\s;#]+);?", Pattern.DOTALL);
+
+ private static final Pattern GLOBAL_PATTERN = Pattern.compile(
+ "\\n\\s*global\\s+(\\S+)\\s+([^\\s;#]+);?", Pattern.DOTALL);
+
+ private static final Pattern QUERY_PATTERN1 = Pattern.compile(
+ "\\n\\s*query\\s+\"([^\"]+)\"", Pattern.DOTALL);
+
+ private static final Pattern QUERY_PATTERN2 = Pattern.compile(
+ "\\n\\s*query\\s+([^\\s;#\"]+)", Pattern.DOTALL);
+
+ public RuleContentOutlinePage(AbstractRuleEditor editor) {
+ this.editor = editor;
+ }
+
+ DroolsContentProvider contentProvider = null;
+ DroolsGroupByRuleGroupContentProvider groupByRuleGroupContentProvider = null;
+
+ private void setContentProvider() {
+ IPreferenceStore preferenceStore= DroolsEclipsePlugin.getDefault().getPreferenceStore();
+ groupByRulegroup = preferenceStore.getBoolean("GroupByRuleGroupAction.isChecked");
+
+ contentProvider = new DroolsContentProvider();
+ groupByRuleGroupContentProvider = new DroolsGroupByRuleGroupContentProvider();
+
+ if (groupByRulegroup) {
+ viewer.setContentProvider(groupByRuleGroupContentProvider);
+ } else {
+ viewer.setContentProvider(contentProvider);
+ }
+ }
+
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+
+ viewer = getTreeViewer();
+ setContentProvider();
+ viewer.setLabelProvider(new DroolsLabelProvider());
+ viewer.setSorter(new DroolsTreeSorter());
+ viewer.setInput(ruleSet);
+ FilterActionGroup filterActionGroup = new FilterActionGroup(
+ viewer, "org.drools.eclipse.editors.outline.RuleContentOutlinePage");
+ filterActionGroup.fillActionBars(getSite().getActionBars());
+ update();
+
+ // add the listener for navigation of the rule document.
+ super.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object selectionObj = event.getSelection();
+ if (selectionObj != null && selectionObj instanceof StructuredSelection) {
+ StructuredSelection sel = (StructuredSelection) selectionObj;
+ DroolsElement element = (DroolsElement) sel.getFirstElement();
+ if (element != null) {
+ editor.selectAndReveal(element.getOffset(),
+ element.getLength());
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Updates the outline page.
+ */
+ public void update() {
+ TreeViewer viewer = getTreeViewer();
+ if (viewer != null) {
+ Control control = viewer.getControl();
+ if (control != null && !control.isDisposed()) {
+ initRules();
+ populatePackageTreeNode();
+ viewer.refresh();
+ control.setRedraw(false);
+ viewer.expandToLevel(2);
+ control.setRedraw(true);
+ }
+ }
+ }
+
+ /**
+ * populates the PackageTreeNode with all of its child elements
+ *
+ * @param packageTreeNode the node to populate
+ */
+ public void populatePackageTreeNode() {
+ String ruleFileContents = editor.getContent();
+ populatePackageTreeNode(ruleFileContents);
+ }
+
+ void populatePackageTreeNode(String ruleFileContents) {
+ DroolsModelBuilder.clearRuleSet(ruleSet);
+ Matcher matcher = PACKAGE_PATTERN.matcher(ruleFileContents);
+ String packageName = null;
+ int startChar = 0;
+ int endChar = 0;
+ if (matcher.find()) {
+ packageName = matcher.group(1);
+ startChar = matcher.start(1);
+ endChar = matcher.end(1);
+ }
+ Package pkg = DroolsModelBuilder.addPackage(ruleSet, packageName,
+ startChar, endChar - startChar);
+
+ matcher = RULE_PATTERN1.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String ruleName = matcher.group(1);
+ RuleDescr descr = (RuleDescr) rules.get(ruleName);
+ if (descr != null) {
+ DroolsModelBuilder.addRule(pkg, ruleName, null,
+ matcher.start(1), matcher.end(1) - matcher.start(1),
+ extractAttributes(descr));
+ }
+ }
+ matcher = RULE_PATTERN2.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String ruleName = matcher.group(1);
+ RuleDescr descr = (RuleDescr) rules.get(ruleName);
+ if (descr != null) {
+ DroolsModelBuilder.addRule(pkg, ruleName, null,
+ matcher.start(1), matcher.end(1) - matcher.start(1),
+ extractAttributes(descr));
+ }
+ }
+ matcher = FUNCTION_PATTERN.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String functionName = matcher.group(2);
+ DroolsModelBuilder.addFunction(pkg, functionName + "()", null,
+ matcher.start(2), matcher.end(2) - matcher.start(2));
+ }
+ matcher = EXPANDER_PATTERN.matcher(ruleFileContents);
+ if (matcher.find()) {
+ String expanderName = matcher.group(1);
+ DroolsModelBuilder.addExpander(pkg, expanderName, null,
+ matcher.start(1), matcher.end(1) - matcher.start(1));
+ }
+ matcher = IMPORT_PATTERN.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String importName = matcher.group(1);
+ DroolsModelBuilder.addImport(pkg, importName, null,
+ matcher.start(1), matcher.end(1) - matcher.start(1));
+ }
+ matcher = GLOBAL_PATTERN.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String globalType = matcher.group(1);
+ String globalName = matcher.group(2);
+ String name = globalName + " : " + globalType;
+ DroolsModelBuilder.addGlobal(pkg, name, null,
+ matcher.start(2), matcher.end(2) - matcher.start(2));
+ }
+ matcher = QUERY_PATTERN1.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String queryName = matcher.group(1);
+ DroolsModelBuilder.addQuery(pkg, queryName, null,
+ matcher.start(1), matcher.end(1) - matcher.start(1));
+ }
+ matcher = QUERY_PATTERN2.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String queryName = matcher.group(1);
+ DroolsModelBuilder.addQuery(pkg, queryName, null,
+ matcher.start(1), matcher.end(1) - matcher.start(1));
+ }
+ matcher = TEMPLATE_PATTERN.matcher(ruleFileContents);
+ while (matcher.find()) {
+ String templateName = matcher.group(1);
+ DroolsModelBuilder.addTemplate(pkg, templateName, null,
+ matcher.start(1), matcher.end(1) - matcher.start(1));
+ }
+ }
+
+ RuleSet getRuleSet() {
+ return ruleSet;
+ }
+
+ private Map<String, String> extractAttributes(RuleDescr ruleDescr) {
+ Map<String, String> attributes = null;
+ if (ruleDescr != null) {
+ attributes = new HashMap<String, String>();
+ for (AttributeDescr attribute: ruleDescr.getAttributes().values()) {
+ if (attribute != null && attribute.getName() != null) {
+ attributes.put(attribute.getName(), attribute.getValue());
+ }
+ }
+ }
+ return attributes;
+ }
+
+ public void initRules() {
+ rules = new HashMap<String, RuleDescr>();
+ try {
+ DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(editor, true, false);
+ if (drlInfo != null) {
+ PackageDescr packageDescr = drlInfo.getPackageDescr();
+ if (packageDescr != null) {
+ for (RuleDescr ruleDescr: packageDescr.getRules()) {
+ rules.put(ruleDescr.getName(), ruleDescr);
+ }
+ }
+ }
+ } catch (DroolsParserException e) {
+ DroolsEclipsePlugin.log(e);
+ }
+ }
+
+ class GroupByRuleGroupAction extends Action {
+
+ public GroupByRuleGroupAction() {
+ super();
+ setText("Group by Rule Group");
+ setToolTipText("Group by Rule Group");
+ setDescription("Group by agenda-group, activation-group or ruleflow-group");
+ setChecked(groupByRulegroup);
+ }
+
+ @Override
+ public void run() {
+ setGroupByRuleGroup(!groupByRulegroup);
+ }
+
+ private void setGroupByRuleGroup(boolean groupBy) {
+ groupByRulegroup = groupBy;
+ setChecked(groupBy);
+
+ IPreferenceStore preferenceStore= DroolsEclipsePlugin.getDefault().getPreferenceStore();
+ preferenceStore.setValue("GroupByRuleGroupAction.isChecked", groupBy);
+
+ setContentProvider();
+ viewer.refresh(true);
+
+ }
+
+ }
+
+ @Override
+ public void makeContributions(IMenuManager menuManager,
+ IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
+ // TODO Auto-generated method stub
+ GroupByRuleGroupAction groupByAction = new GroupByRuleGroupAction ();
+ menuManager.add(groupByAction);
+ super.makeContributions(menuManager, toolBarManager, statusLineManager);
+ }
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list