[jboss-svn-commits] JBL Code SVN: r11663 - in labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin: src/main/java/org/drools/eclipse and 9 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu May 3 21:27:24 EDT 2007


Author: KrisVerlaenen
Date: 2007-05-03 21:27:23 -0400 (Thu, 03 May 2007)
New Revision: 11663

Added:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor2.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleSourceViewerConfig.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocument.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocumentProvider.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLRuleViewer.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/TransformedDocument.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java
Removed:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/BRLSourceViewerConfig.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DSLAdapter.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/RuleEditorPlugin.java
Modified:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/AgendaViewContentProvider.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ApplicationDataViewContentProvider.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/DroolsDebugEventHandlerView.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/WorkingMemoryViewContentProvider.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLContentProvider.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/ColorManager.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLAnnotationModel.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLDocumentProvider.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLProblemAnnotation.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLRuleEditor.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLSourceViewerConfig.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DescrUtil.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessor.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/wizard/project/RuleLauncherSample.java.template
Log:
 - Fixed issues with DSL in IDE
 - Updated IDE due to changes in core and compiler
 - removed redundant parsing in IDE

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/.classpath	2007-05-04 01:27:23 UTC (rev 11663)
@@ -2,8 +2,11 @@
 <classpath>
 	<classpathentry kind="src" path="src/main/java"/>
 	<classpathentry kind="src" path="src/main/resources"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/drools-decisiontables"/>
 	<classpathentry exported="true" kind="lib" path="lib/antlr.jar"/>
-	<classpathentry exported="true" kind="lib" path="lib/drools-compiler.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/drools-compiler.jar" sourcepath="/drools-compiler"/>
 	<classpathentry exported="true" kind="lib" path="lib/drools-core.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/drools-decisiontables.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/drools-jsr94.jar"/>
@@ -17,8 +20,5 @@
 	<classpathentry exported="true" kind="lib" path="lib/xstream.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/drools-compiler"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/drools-core"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/drools-decisiontables"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/plugin.xml	2007-05-04 01:27:23 UTC (rev 11663)
@@ -61,14 +61,13 @@
             icon="icons/drools.gif"
             id="org.drools.eclipse.editors.DRLRuleEditor"
             name="Rule Editor"/>
-      <!--
       <editor
-            class="org.drools.eclipse.editors.dsl.DSLRuleEditor2"
+            class="org.drools.eclipse.dsl.editor.DSLRuleEditor2"
             contributorClass="org.drools.eclipse.editors.DRLRuleEditorActionContributor"
             extensions="dslr,dslrule"
             icon="icons/drools.gif"
-            id="org.drools.eclipse.editors.dsl.DSLRuleEditor"
-            name="DSL Rule Editor"/> -->
+            id="org.drools.eclipse.editors.DSLRuleEditor"
+            name="DSL Rule Editor"/>
       <editor
             class="org.drools.eclipse.dsl.editor.DSLEditor"
             contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -30,8 +30,8 @@
 import org.drools.eclipse.DRLInfo.RuleInfo;
 import org.drools.eclipse.builder.DroolsBuilder;
 import org.drools.eclipse.builder.Util;
+import org.drools.eclipse.dsl.editor.DSLAdapter;
 import org.drools.eclipse.editors.AbstractRuleEditor;
-import org.drools.eclipse.editors.DSLAdapter;
 import org.drools.eclipse.preferences.IDroolsConstants;
 import org.drools.eclipse.util.ProjectClassLoader;
 import org.drools.lang.descr.PackageDescr;

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/builder/DroolsBuilder.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -117,7 +117,9 @@
             // do nothing
         }
 
-        if (res instanceof IFile && "drl".equals(res.getFileExtension())) {
+        if (res instanceof IFile
+        		&& ("drl".equals(res.getFileExtension())
+    				|| "dslr".equals(res.getFileExtension()))) {
             removeProblemsFor(res);
             try {
             	DroolsBuildMarker[] markers = parseDRLFile((IFile) res, new String(Util.getResourceContentsAsCharArray((IFile) res)));

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/AgendaViewContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/AgendaViewContentProvider.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/AgendaViewContentProvider.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -33,7 +33,7 @@
         try {
             Object[] variables = null;
             if (obj != null && obj instanceof IJavaObject
-                    && "org.drools.reteoo.ReteooWorkingMemory".equals(
+                    && "org.drools.reteoo.ReteooStatefulSession".equals(
                         ((IJavaObject) obj).getReferenceTypeName())) {
                 variables = getAgendaElements((IJavaObject) obj);
             } else if (obj instanceof IVariable) {

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ApplicationDataViewContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ApplicationDataViewContentProvider.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/ApplicationDataViewContentProvider.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -32,7 +32,7 @@
         try {
             IVariable[] variables = null;
             if (obj != null && obj instanceof IJavaObject
-                    && "org.drools.reteoo.ReteooWorkingMemory".equals(
+                    && "org.drools.reteoo.ReteooStatefulSession".equals(
                         ((IJavaObject) obj).getReferenceTypeName())) {
                 variables = getApplicationDataElements((IJavaObject) obj);
             } else if (obj instanceof IVariable) {

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/DroolsDebugEventHandlerView.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/DroolsDebugEventHandlerView.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/DroolsDebugEventHandlerView.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -69,7 +69,7 @@
             try {
                 IValue value = ((IVariable) context).getValue();
                 if (value != null && value instanceof IJavaObject
-                        && "org.drools.reteoo.ReteooWorkingMemory".equals(
+                        && "org.drools.reteoo.ReteooStatefulSession".equals(
                             variable.getValue().getReferenceTypeName())) {
                     input = value;
                 }
@@ -91,7 +91,7 @@
                             IJavaObject stackObj = ((IJavaStackFrame) frames[i]).getThis();
                             if ((stackObj != null)
                                     && (stackObj.getJavaType() != null)
-                                    && ("org.drools.reteoo.ReteooWorkingMemory".equals(
+                                    && ("org.drools.reteoo.ReteooStatefulSession".equals(
                                         stackObj.getJavaType().getName()))) {
                                 input = stackObj;
                                 break;

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/WorkingMemoryViewContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/WorkingMemoryViewContentProvider.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/WorkingMemoryViewContentProvider.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -37,7 +37,7 @@
         try {
             IVariable[] variables = null;
             if (obj != null && obj instanceof IJavaObject
-                    && "org.drools.reteoo.ReteooWorkingMemory".equals(
+                    && "org.drools.reteoo.ReteooStatefulSession".equals(
                         ((IJavaObject) obj).getReferenceTypeName())) {
                 variables = getWorkingMemoryElements((IJavaObject) obj);
             } else if (obj instanceof IVariable) {
@@ -62,7 +62,7 @@
     }
     
     private IVariable[] getWorkingMemoryElements(IJavaObject stackObj) throws DebugException {
-        IValue objects = DebugUtil.getValueByExpression("return getObjects().toArray();", stackObj);
+        IValue objects = DebugUtil.getValueByExpression("return iterateObjectsToList().toArray();", stackObj);
         if (objects instanceof IJavaArray) {
             IJavaArray array = (IJavaArray) objects;
             List result = new ArrayList();

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -91,7 +91,7 @@
 				if (ruleInfo != null) {
 					if (ruleInfo.getConsequenceDrlLineNumber() < lineNumber) {
 						return ruleInfo.getConsequenceJavaLineNumber()
-							+ (lineNumber - ruleInfo.getConsequenceDrlLineNumber());
+							+ (lineNumber - ruleInfo.getConsequenceDrlLineNumber() + 1);
 					}
 				}
 				FunctionInfo functionInfo = drlInfo.getFunctionInfo(lineNumber);

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -97,7 +97,7 @@
 		synchronized (fThread) {
 			RuleInfo ruleInfo = getExecutingRuleInfo();
 			if (ruleInfo != null) {
-				return ruleInfo.getConsequenceDrlLineNumber() + (getInternalLineNumber() - ruleInfo.getConsequenceJavaLineNumber());
+				return ruleInfo.getConsequenceDrlLineNumber() + (getInternalLineNumber() - ruleInfo.getConsequenceJavaLineNumber() - 1);
 			}
 			FunctionInfo functionInfo = getExecutingFunctionInfo();
 			if (functionInfo != null) {

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLAdapter.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,179 @@
+package org.drools.eclipse.dsl.editor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.eclipse.editors.completion.DSLTree;
+import org.drools.lang.dsl.DSLMapping;
+import org.drools.lang.dsl.DSLMappingEntry;
+import org.drools.lang.dsl.DSLMappingFile;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * This holds the DSL configuration for an editor instance.
+ * When loading, it will find the DSL file, and load the applicable lists.
+ * 
+ * This provides a link between the editor and the DSL features of the rule language.  
+ * 
+ * It will look for a DSL configuration, as named in the rule file, in the same directory as the rule file.
+ * Failing this, it will search one directory above the rule file. 
+ * Failing that, it will search the root of the project in the workspace.
+ * 
+ * @author Michael Neale
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DSLAdapter {
+
+    private String dslConfigName;
+    private boolean valid = false;
+    private List conditionProposals = new ArrayList();
+    private List consequenceProposals = new ArrayList();
+	private DSLTree dslTree = new DSLTree();
+    
+    //to dig out the expander, without using the parser.
+    private static final Pattern expander = Pattern.compile( "\\n?\\s*expander\\s*(.*)\\.dsl\\s", 
+                                                             Pattern.DOTALL | Pattern.MULTILINE );
+    /**
+     * This will sniff out the DSL config file name from the content.
+     * It will then use the IFile input to search around for the file itself.
+     * TODO: provide an alternative that just loads off a stream (for non IDEs workbenches like jlibrary).
+     * @param content Rule source
+     * @param input File from the FileEditorInput
+     */
+    public DSLAdapter(String content, IFile input) {
+        dslConfigName = findDSLConfigName( content );
+        if (dslConfigName == null) return;
+        loadConfig( input );
+    }
+    
+    /** Get a reader to the DSL contents */
+    public static Reader getDSLContent(String ruleSource, IResource input) throws CoreException {
+        String dslFileName = findDSLConfigName( ruleSource );
+        if (dslFileName == null) return null;
+        IResource res = findDSLResource( input, dslFileName );
+        if (res instanceof IFile) {
+            IFile dslConf = (IFile) res;
+            if (dslConf.exists()) {
+                return new InputStreamReader(dslConf.getContents());
+            }
+        }
+        return null;
+    }
+
+    /**
+     * This does the hunting around the projec to find the .dsl file.
+     */
+    private void loadConfig(IFile input) {
+        IResource res = findDSLResource( input, dslConfigName );
+        if (res instanceof IFile) {
+            IFile dslConf = (IFile) res;
+            if (dslConf.exists()) {
+                InputStream stream = null; 
+                try {
+                    stream = dslConf.getContents();
+                    readConfig( stream );
+                    valid = true;
+                } catch ( Exception e ) {
+                    throw new IllegalStateException("Unable to open DSL config file. (Exception: " + e.getMessage() + ")");
+                } finally {
+                    closeStream( stream );
+                }
+                
+            }
+        }
+    }
+
+    private static IResource findDSLResource(IResource input, String dslFileName) {
+        IResource res = input.getParent().findMember( dslFileName );
+        if (res == null) res = input.getParent().getParent().findMember( dslFileName ); //try parent directory
+        if (res == null) res = input.getProject().findMember( dslFileName ); //try root of project.
+        return res;
+    }
+
+    
+    /** This will load in the DSL config file, using the DSLMapping from drools-compiler */
+    void readConfig(InputStream stream) throws IOException, CoreException {
+        DSLMappingFile file = new DSLMappingFile();
+        file.parseAndLoad(new InputStreamReader(stream));
+
+        DSLMapping grammar = file.getMapping();
+        List conditions = grammar.getEntries( DSLMappingEntry.CONDITION );
+        List consequences = grammar.getEntries( DSLMappingEntry.CONSEQUENCE );
+        
+        conditionProposals = buildProposals(conditions);
+        consequenceProposals = buildProposals(consequences);
+        
+		dslTree.buildTree(grammar);
+    }
+
+    private List buildProposals(List suggestions) {
+    	List result = new ArrayList(suggestions.size());
+    	Iterator iterator = suggestions.iterator();
+        while (iterator.hasNext()) {
+            DSLMappingEntry text = (DSLMappingEntry) iterator.next();
+            result.add(text.getMappingKey());
+        }
+        return result;
+    }
+
+    private void closeStream(InputStream stream) {
+        if (stream != null) try {
+            stream.close();
+        } catch ( IOException e ) {}
+    }
+
+    DSLAdapter() {
+        
+    }
+
+    /** Sniffs out the expander/DSL config name as best it can. */
+    static String findDSLConfigName(String content) {
+        String name = null;
+        Matcher matches = expander.matcher( content );
+        if (matches.find()) {
+            name = matches.group(1) + ".dsl";
+        }
+        return name;
+    }
+    
+    
+    String getDSLConfigName() {
+        return dslConfigName;
+    }
+    
+    
+    public boolean isValid() {
+        return valid;
+    }
+    
+    
+    public boolean hasConditions() {
+        return conditionProposals.size() > 0;
+    }
+    
+    public boolean hasConsequences() {
+        return consequenceProposals.size() > 0;
+    }
+    
+    public List listConditionItems() {
+        return conditionProposals;
+    }
+    
+    public List listConsequenceItems() {
+        return consequenceProposals;
+    }    
+    
+    public DSLTree getDSLTree() {
+    	return dslTree;
+    }
+    
+}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLContentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLContentProvider.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLContentProvider.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -8,6 +8,7 @@
 /**
  * Content provider for the Domain Specific Language editor.
  * @author Michael Neale
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  */
 public class DSLContentProvider
     implements

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,32 @@
+package org.drools.eclipse.dsl.editor;
+
+import org.drools.eclipse.editors.DRLRuleEditor;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.ui.part.FileEditorInput;
+
+public class DSLRuleEditor extends DRLRuleEditor {
+
+    protected DSLAdapter dslAdapter;
+
+	public DSLAdapter getDSLAdapter() {
+		if (dslAdapter == null) {
+			String content = getSourceViewer().getDocument().get();
+			dslAdapter = new DSLAdapter(content, ((FileEditorInput) getEditorInput()).getFile());
+			if (!dslAdapter.isValid()) {
+				dslAdapter = null;
+			}
+		}
+		return dslAdapter;
+	}
+
+	protected SourceViewerConfiguration createSourceViewerConfiguration() {
+		return new DSLRuleSourceViewerConfig(this); 
+	}
+
+	public void doSave(IProgressMonitor monitor) {
+		super.doSave(monitor);
+		// remove cached content
+		dslAdapter = null;
+	}
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor2.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor2.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleEditor2.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,118 @@
+package org.drools.eclipse.dsl.editor;
+
+import java.io.Reader;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.lang.dsl.DSLMappingFile;
+import org.drools.lang.dsl.DefaultExpander;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormEditor;
+
+/**
+ * Editor for rules using a domain-specific language.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DSLRuleEditor2 extends FormEditor {
+
+	private DSLRuleEditor dslRuleEditor;
+	private DSLtoDRLRuleViewer drlRuleViewer;
+
+	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
+		super.init(site, input);
+		setPartName(input.getName());
+	}
+
+	protected void addPages() {
+		try {
+			dslRuleEditor = new DSLRuleEditor() {
+				public void close(boolean save) {
+					super.close(save);
+					DSLRuleEditor2.this.close(save);
+				}
+				protected void setPartName(String partName) {
+					super.setPartName(partName);
+					DSLRuleEditor2.this.setPartName(partName);
+				}
+			};
+			int text = addPage(dslRuleEditor, getEditorInput());
+			setPageText(text, "Text Editor");
+			drlRuleViewer = new DSLtoDRLRuleViewer(dslRuleEditor);
+			text = addPage(drlRuleViewer, getEditorInput());
+			setPageText(text, "DRL Viewer");
+		} catch (PartInitException e) {
+			DroolsEclipsePlugin.log(e);
+		}
+	}
+
+	public void doSave(IProgressMonitor monitor) {
+		dslRuleEditor.doSave(monitor);
+		setInput(getEditorInput());
+	}
+
+	public void doSaveAs() {
+		dslRuleEditor.doSaveAs();
+	}
+
+	public boolean isSaveAsAllowed() {
+		return dslRuleEditor.isSaveAsAllowed();
+	}
+
+	public Object getAdapter(Class adapter) {
+		return dslRuleEditor.getAdapter(adapter);
+	}
+
+	public void setFocus() {
+		if (getActivePage() == 1) {
+			// check if translation does succeed
+			try {
+		        DefaultExpander expander = new DefaultExpander();
+		        String content = dslRuleEditor.getContent();
+	        	Reader reader = DSLAdapter.getDSLContent(content, dslRuleEditor.getResource());
+	        	if (reader == null) {
+	        		throw new IllegalArgumentException("Could not find dsl definition.");
+	        	}
+	            DSLMappingFile mapping = new DSLMappingFile();
+	            mapping.parseAndLoad(reader);
+	            reader.close();
+	            expander.addDSLMapping(mapping.getMapping());
+	            expander.expand(content);
+	            // if translation succeeds, change to drl viewer
+				drlRuleViewer.setInput(getEditorInput());
+	        } catch (Throwable t) {
+	        	// if translation fails, show error and go to first page
+	        	handleError(t);
+	        	setActivePage(0);
+	        }
+		}
+		super.setFocus();
+	}
+
+    private void handleError(Throwable t) {
+        DroolsEclipsePlugin.log( t );
+        Throwable cause = t.getCause();
+        if ( cause == null ) {
+            cause = t;
+        }
+        String message = cause.getClass().getName()+": "+cause.getMessage();
+        if ( message == null || message.length() == 0 ) {
+            message = "Uncategorized Error!";
+        }
+        IStatus status = new Status( IStatus.ERROR,
+                                     DroolsEclipsePlugin.getUniqueIdentifier(),
+                                     -1,
+                                     message,
+                                     null);
+        ErrorDialog.openError( getSite().getShell(),
+                               "DSL Rule Translation Error!",
+                               "DSL Rule Translation Error!",
+                               status );
+
+    }
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleSourceViewerConfig.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleSourceViewerConfig.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLRuleSourceViewerConfig.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,38 @@
+package org.drools.eclipse.dsl.editor;
+
+import org.drools.eclipse.dsl.editor.completion.DSLRuleCompletionProcessor;
+import org.drools.eclipse.editors.DRLSourceViewerConfig;
+import org.drools.eclipse.editors.completion.DefaultCompletionProcessor;
+import org.drools.eclipse.editors.scanners.DRLPartionScanner;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+/**
+ * Source viewer config wires up the syntax highlighting, partitioning
+ * and content assistance.
+ * 
+ * @author Michael Neale
+ *
+ */
+public class DSLRuleSourceViewerConfig extends DRLSourceViewerConfig {
+
+	public DSLRuleSourceViewerConfig(DSLRuleEditor editor) {
+		super(editor);
+	}
+
+	/**
+	 * Get the appropriate content assistance, for each partition.
+	 */
+	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+		ContentAssistant assistant = new ContentAssistant();
+		assistant.setContentAssistProcessor(
+			new DefaultCompletionProcessor(getEditor()), IDocument.DEFAULT_CONTENT_TYPE);
+		assistant.setContentAssistProcessor(
+			new DSLRuleCompletionProcessor(getEditor()), DRLPartionScanner.RULE_PART_CONTENT);
+		assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
+		assistant.setAutoActivationDelay(0);
+		return assistant;
+	}
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocument.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocument.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocument.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,34 @@
+package org.drools.eclipse.dsl.editor;
+
+import java.io.Reader;
+
+import org.drools.lang.dsl.DSLMappingFile;
+import org.drools.lang.dsl.DefaultExpander;
+import org.eclipse.jface.text.IDocument;
+
+public class DSLtoDRLDocument extends TransformedDocument {
+
+	private DSLtoDRLRuleViewer viewer;
+	
+	public DSLtoDRLDocument(IDocument dslDocument, DSLtoDRLRuleViewer viewer) {
+		super(dslDocument);
+		this.viewer = viewer;
+	}
+	
+	protected String transformInput(String content) {
+        DefaultExpander expander = new DefaultExpander();
+        try {
+        	Reader reader = DSLAdapter.getDSLContent(content, viewer.getResource());
+            DSLMappingFile mapping = new DSLMappingFile();
+            mapping.parseAndLoad(reader);
+            reader.close();
+            expander.addDSLMapping(mapping.getMapping());
+            return expander.expand(content);
+        } catch (Throwable t) {
+        	//viewer.handleError(t);
+        	return content;
+        }
+
+	}
+
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocumentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocumentProvider.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLDocumentProvider.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,27 @@
+package org.drools.eclipse.dsl.editor;
+
+import org.drools.eclipse.editors.DRLDocumentProvider;
+import org.eclipse.jface.text.IDocument;
+
+public class DSLtoDRLDocumentProvider extends DRLDocumentProvider {
+
+	private DSLtoDRLRuleViewer drlViewer;
+	private IDocument document;
+	
+	public DSLtoDRLDocumentProvider(DSLtoDRLRuleViewer drlViewer) {
+		this.drlViewer = drlViewer;
+	}
+	
+	public IDocument getDocument(Object element) {
+		if (document == null) {
+			IDocument superDocument = super.getDocument(element);
+			document = new DSLtoDRLDocument(superDocument, drlViewer);
+		}
+		return document;
+    }
+	
+	public boolean isModifiable(Object element) {
+		return false;
+	}
+	
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLRuleViewer.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLRuleViewer.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/DSLtoDRLRuleViewer.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,43 @@
+package org.drools.eclipse.dsl.editor;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.editors.AbstractRuleEditor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+public class DSLtoDRLRuleViewer extends AbstractRuleEditor {
+	
+	private DSLRuleEditor dslRuleEditor;
+
+	public DSLtoDRLRuleViewer(DSLRuleEditor dslRuleEditor) {
+		this.dslRuleEditor = dslRuleEditor;
+	}
+	
+    protected IDocumentProvider createDocumentProvider() {
+    	return new DSLtoDRLDocumentProvider(this);
+    }
+    
+    public String getDSLRuleContent() {
+    	return dslRuleEditor.getContent();
+    }
+
+	public void handleError(Throwable t) {
+		DroolsEclipsePlugin.log(t);
+		Throwable cause = t.getCause();
+		if (cause == null) {
+			cause = t;
+		}
+		String message = cause.getClass().getName() + ": " + cause.getMessage();
+		if (message == null || message.length() == 0) {
+			message = "Uncategorized Error!";
+		}
+		IStatus status = new Status(IStatus.ERROR, DroolsEclipsePlugin
+				.getUniqueIdentifier(), -1, message, null);
+		ErrorDialog.openError(getSite().getShell(),
+				"DSL Rule Translation Error!", "DSL Rule Translation Error!",
+				status);
+
+	}
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/TransformedDocument.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/TransformedDocument.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/TransformedDocument.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,93 @@
+package org.drools.eclipse.dsl.editor;
+
+import org.eclipse.jface.text.AbstractDocument;
+import org.eclipse.jface.text.DefaultLineTracker;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.ITextStore;
+
+/**
+ * A document that transforms the input of the original document
+ * to something else.  Changing something in this document will
+ * NOT change the original document (as the transformation is only
+ * defined in one way). All changes will also be overridden as soon
+ * as the original document changes.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public abstract class TransformedDocument extends AbstractDocument {
+	
+	private IDocument parentDocument;
+	private boolean changed = true;
+		
+	public TransformedDocument(IDocument parentDocument) {
+		this.parentDocument = parentDocument;
+		parentDocument.addDocumentListener(new IDocumentListener() {
+			public void documentAboutToBeChanged(DocumentEvent event) {
+				// Do nothing
+			}
+			public void documentChanged(DocumentEvent event) {
+				changed = true;
+			}
+		});
+		setTextStore(new StringTextStore());
+		setLineTracker(new DefaultLineTracker());
+		completeInitialization();
+	}
+	
+	/** 
+	 * Always check that the store is up-to-date.
+	 * All read operations access the store so this method makes sure
+	 * that the document is updated whenever necessary.
+	 */
+	protected ITextStore getStore() {
+		if (changed) {
+			update();
+		}
+		return super.getStore();
+	}
+	
+	private void update() {
+		String translation = transformInput(parentDocument.get());
+		super.getStore().set(translation);
+		getTracker().set(translation);
+		changed = false;
+	}
+	
+	/**
+	 * Transforms the original content of the document.
+	 */
+	protected abstract String transformInput(String content);
+
+	/**
+	 * Default text store.
+	 */
+	private static class StringTextStore implements ITextStore {
+
+		private String fContent;
+
+		public StringTextStore() {
+		}
+
+		public char get(int offset) {
+			return fContent.charAt(offset);
+		}
+
+		public String get(int offset, int length) {
+			return fContent.substring(offset, offset + length);
+		}
+
+		public int getLength() {
+			return fContent.length();
+		}
+
+		public void replace(int offset, int length, String text) {
+		}
+
+		public void set(String text) {
+			this.fContent = text;
+		}
+	}
+
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -0,0 +1,168 @@
+package org.drools.eclipse.dsl.editor.completion;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.eclipse.DroolsPluginImages;
+import org.drools.eclipse.dsl.editor.DSLAdapter;
+import org.drools.eclipse.dsl.editor.DSLRuleEditor;
+import org.drools.eclipse.editors.AbstractRuleEditor;
+import org.drools.eclipse.editors.completion.RuleCompletionProcessor;
+import org.drools.eclipse.editors.completion.RuleCompletionProposal;
+import org.drools.eclipse.editors.completion.LocationDeterminator.Location;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * For handling DSL rules.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class DSLRuleCompletionProcessor extends RuleCompletionProcessor {
+
+	private static final Image DSL_ICON = 
+		DroolsPluginImages.getImage(DroolsPluginImages.DSL_EXPRESSION);
+
+	public DSLRuleCompletionProcessor(AbstractRuleEditor editor) {
+		super(editor);
+	}
+
+    protected DSLRuleEditor getDSLRuleEditor() {
+    	return (DSLRuleEditor) getEditor();
+    }
+    
+	protected void addRHSCompletionProposals(List list, String prefix, String backText,
+			String conditions, String consequence) {
+		super.addRHSCompletionProposals(list, prefix, backText, conditions, consequence);
+		DSLAdapter adapter = getDSLRuleEditor().getDSLAdapter();
+		if (adapter != null) {
+			List dslConsequences = adapter.getDSLTree().getConsequenceChildrenList(prefix, true);
+			addDSLProposals(list, prefix, dslConsequences);
+		}
+	}
+	
+	protected void addLHSCompletionProposals(List list,
+			Location location, String prefix, String backText) {
+		super.addLHSCompletionProposals(list, location, prefix, backText);
+		DSLAdapter adapter = getDSLRuleEditor().getDSLAdapter();
+		if (adapter != null) {
+			String lastobj = this.getLastNonDashLine(backText);
+			String last = this.getLastLine(backText);
+			// we have to check if the last line is when. if it is we set
+			// the last line to zero length string
+			if (last.equals("when")) {
+				last = "";
+				lastobj = "*";
+			}
+			// pass the last string in the backText to getProposals
+			List dslConditions = this.getProposals(adapter, lastobj, last);
+			// if we couldn't find any matches, we add the list from
+			// the DSLAdapter so that there's something
+			if (dslConditions.size() == 0) {
+				dslConditions.addAll(adapter.listConditionItems());
+			}
+			addDSLProposals(list, prefix, dslConditions);
+		}
+	}
+	
+	private void addDSLProposals(final List list, final String prefix, List dslItems) {
+		Iterator iterator = dslItems.iterator();
+		while (iterator.hasNext()) {
+			String consequence = (String) iterator.next();
+			RuleCompletionProposal p = new RuleCompletionProposal(
+				prefix.length(), consequence);
+			p.setImage(DSL_ICON);
+			list.add(p);
+		}
+	}
+
+	/**
+	 * because of how the backText works, we need to get the last line, so that
+	 * we can pass it to the DSLUtility
+	 * 
+	 * @param backText
+	 * @return
+	 */
+	public String getLastLine(String backText) {
+		BufferedReader breader = new BufferedReader(new StringReader(backText));
+		String last = "";
+		String line = null;
+		try {
+			while ((line = breader.readLine()) != null) {
+				// only if the line has text do we set last to it
+				if (line.length() > 0) {
+					last = line;
+				}
+			}
+		} catch (IOException e) {
+			// TODO need to log this.
+			// I'm leaving this for mic_hat, so he has something to do
+		}
+		// now that all the conditions for a single object are on the same line
+		// we need to check for the left parenthesis
+		if (last.indexOf("(") > -1) {
+			last = last.substring(last.lastIndexOf("(") + 1);
+		}
+		// if the string has a comma "," we get the substring starting from
+		// the index after the last comma
+		if (last.indexOf(",") > -1) {
+			last = last.substring(last.lastIndexOf(",") + 1);
+		}
+		// if the line ends with right parenthesis, we change it to zero length
+		// string
+		if (last.endsWith(")")) {
+			last = "";
+		}
+		return last;
+	}
+
+	/**
+	 * Returns the last line that doesn't start with a dash
+	 * 
+	 * @param backText
+	 * @return
+	 */
+	public String getLastNonDashLine(String backText) {
+		BufferedReader breader = new BufferedReader(new StringReader(backText));
+		String last = "";
+		String line = null;
+		try {
+			while ((line = breader.readLine()) != null) {
+				// there may be blank lines, so we trim first
+				line = line.trim();
+				// only if the line has text do we set last to it
+				if (line.length() > 0 && !line.startsWith("-")) {
+					last = line;
+				}
+			}
+		} catch (IOException e) {
+			// TODO need to log this.
+			// I'm leaving this for mic_hat, so he has something to do
+		}
+		if (last.indexOf("(") > -1 && !last.endsWith(")")) {
+			last = last.substring(0, last.indexOf("("));
+		} else if (last.indexOf("(") > -1 && last.endsWith(")")) {
+			last = "";
+		}
+		return last;
+	}
+
+	/**
+	 * The DSLTree is configurable. It can either return just the child of the
+	 * last token found, or it can traverse the tree and generate all the
+	 * combinations beneath the last matching node. TODO I don't know how to add
+	 * configuration to the editor, so it needs to be hooked up to the
+	 * configuration for the editor later.
+	 * 
+	 * @param last
+	 * @return
+	 */
+	protected List getProposals(DSLAdapter adapter, String obj, String last) {
+		if (last.length() == 0) {
+			last = " ";
+		}
+		return adapter.getDSLTree().getChildrenList(obj, last, true);
+	}
+}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -1,44 +1,30 @@
 package org.drools.eclipse.editors;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
-import org.drools.compiler.DroolsParserException;
-import org.drools.eclipse.DRLInfo;
 import org.drools.eclipse.DroolsEclipsePlugin;
-import org.drools.eclipse.debug.core.IDroolsDebugConstants;
 import org.drools.eclipse.editors.outline.RuleContentOutlinePage;
 import org.drools.eclipse.editors.scanners.RuleEditorMessages;
 import org.drools.eclipse.preferences.IDroolsConstants;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.FactTemplateDescr;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
 import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
-import org.eclipse.jdt.core.CompletionRequestor;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
 import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
 import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
 import org.eclipse.jface.text.source.projection.ProjectionSupport;
 import org.eclipse.jface.text.source.projection.ProjectionViewer;
+import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.IDocumentProvider;
 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
@@ -47,18 +33,12 @@
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
 
 /**
- * Generic rule editor for drools.
- * @author Michael Neale
+ * Abstract text-based rule editor.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  */
-public abstract class AbstractRuleEditor extends TextEditor {
+public class AbstractRuleEditor extends TextEditor {
 
-	//used to provide additional content assistance/popups when DSLs are used.
-    protected DSLAdapter dslAdapter;
-    protected List imports;
-    protected List functions;
-    protected Map templates;
-    protected String packageName;
-    protected List classesInPackage;
 	protected RuleContentOutlinePage ruleContentOutline = null;
 
     protected Annotation[] oldAnnotations;
@@ -66,9 +46,20 @@
 	protected DroolsPairMatcher bracketMatcher = new DroolsPairMatcher();
 	
 	public AbstractRuleEditor() {
-        super();
+		setSourceViewerConfiguration(createSourceViewerConfiguration());
+		setDocumentProvider(createDocumentProvider());
+		getPreferenceStore().setDefault(IDroolsConstants.DRL_EDITOR_MATCHING_BRACKETS, true);
+		PreferenceConverter.setDefault(getPreferenceStore(), IDroolsConstants.DRL_EDITOR_MATCHING_BRACKETS_COLOR, new RGB(192, 192, 192));
     }
+	
+	protected SourceViewerConfiguration createSourceViewerConfiguration() {
+		return new DRLSourceViewerConfig(this); 
+	}
 
+    protected IDocumentProvider createDocumentProvider() {
+    	return new DRLDocumentProvider();
+    }
+
 	public void createPartControl(Composite parent) {
 		super.createPartControl(parent);
 		ProjectionViewer viewer = (ProjectionViewer) getSourceViewer();
@@ -134,23 +125,14 @@
 
 	}
 	
-	/** Return the DSL adapter if one is present */
-	public DSLAdapter getDSLAdapter() {
-		return dslAdapter;
-	}
+    protected ContentOutlinePage getContentOutline() {
+        if (ruleContentOutline == null) {
+            ruleContentOutline = new RuleContentOutlinePage(this);
+            ruleContentOutline.update();
+        }
+        return ruleContentOutline;
+    }
 
-	/** Set the DSL adapter, used for content assistance */
-	public void setDSLAdapter(DSLAdapter adapter) {
-		dslAdapter = adapter;
-	}
-
-	public List getImports() {
-		if (imports == null) {
-			loadImportsAndFunctions();
-		}
-		return imports;
-	}
-	
 	public String getContent() {
 		return getSourceViewer().getDocument().get();
 	}
@@ -162,114 +144,13 @@
 		return null;
 	}
 	
-	protected abstract void loadImportsAndFunctions();
-
-	public List getFunctions() {
-		if (functions == null) {
-			loadImportsAndFunctions();
-		}
-		return functions;
-	}
-	
-	public Set getTemplates() {
-		if (templates == null) {
-			loadImportsAndFunctions();
-		}
-		return templates.keySet();
-	}
-	
-	public FactTemplateDescr getTemplate(String name) {
-		if (templates == null) {
-			loadImportsAndFunctions();
-		}
-		return (FactTemplateDescr) templates.get(name);
-	}
-	
-	public String getPackage() {
-		if (packageName == null) {
-			loadImportsAndFunctions();
-		}
-		return packageName;
-	}
-	
-	public List getClassesInPackage() {
-		if (classesInPackage == null) {
-			classesInPackage = getAllClassesInPackage(getPackage());
-		}
-		return classesInPackage;
-	}
-	
-	protected List getAllClassesInPackage(String packageName) {
-		final List list = new ArrayList();
-		if (packageName != null) {
-			IEditorInput input = getEditorInput();
-			if (input instanceof IFileEditorInput) {
-				IProject project = ((IFileEditorInput) input).getFile().getProject();
-				IJavaProject javaProject = JavaCore.create(project);
-				
-				CompletionRequestor requestor = new CompletionRequestor() {
-					public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
-						String className = new String(proposal.getCompletion());
-						if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF) {
-							list.add(className);
-						}
-						// ignore all other proposals
-					}
-				};
-	
-				try {
-					javaProject.newEvaluationContext().codeComplete(packageName + ".", packageName.length() + 1, requestor);
-				} catch (Throwable t) {
-					DroolsEclipsePlugin.log(t);
-				}
-			}
-		}
-		return list;
-	}
-
-	protected List getAllStaticMethodsInClass(String className) {
-		final List list = new ArrayList();
-		if (className != null) {
-			IEditorInput input = getEditorInput();
-			if (input instanceof IFileEditorInput) {
-				IProject project = ((IFileEditorInput) input).getFile().getProject();
-				IJavaProject javaProject = JavaCore.create(project);
-				
-				CompletionRequestor requestor = new CompletionRequestor() {
-					public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
-						String functionName = new String(proposal.getCompletion());
-						if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.METHOD_REF) {
-							list.add(functionName.substring(0, functionName.length() - 2)); // remove the ()
-						}
-						// ignore all other proposals
-					}
-				};
-	
-				try {
-					javaProject.newEvaluationContext().codeComplete(className + ".", className.length() + 1, requestor);
-				} catch (Throwable t) {
-					DroolsEclipsePlugin.log(t);
-				}
-			}
-		}
-		return list;
-	}
-	
 	public Object getAdapter(Class adapter) {
 		if (adapter.equals(IContentOutlinePage.class)) {
 			return getContentOutline();
-		} else if (adapter.equals(IToggleBreakpointsTarget.class)) {
-			return getBreakpointAdapter();
 		}
 		return super.getAdapter(adapter);
 	}
 
-	protected abstract ContentOutlinePage getContentOutline();
-
-	private Object getBreakpointAdapter() {
-		return new DroolsLineBreakpointAdapter();
-	}
-
 	public void doSave(IProgressMonitor monitor) {
 		// invalidate cached parsed rules
 		DroolsEclipsePlugin.getDefault().invalidateResource(getResource());
@@ -279,35 +160,8 @@
 		if (ruleContentOutline != null) {
 			ruleContentOutline.update();
 		}
-		// remove cached content
-		dslAdapter = null;
-		imports = null;
-		functions = null;
-		templates = null;
-		packageName = null;
-		classesInPackage = null;
 	}
 
-	public void gotoMarker(IMarker marker) {
-		try {
-			if (marker.getType().equals(IDroolsDebugConstants.DROOLS_MARKER_TYPE)) {
-				int line = marker.getAttribute(IDroolsDebugConstants.DRL_LINE_NUMBER, -1);
-	            if (line > -1)
-	            	--line;
-	                try {
-	                    IDocument document = getDocumentProvider().getDocument(getEditorInput());
-	                    selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
-	                } catch(BadLocationException exc) {
-	                	DroolsEclipsePlugin.log(exc);
-	                }
-			} else {
-				super.gotoMarker(marker);
-			}
-		} catch (CoreException exc) {
-			DroolsEclipsePlugin.log(exc);
-		}
-	}
-	
 	public void dispose() {
 		super.dispose();
 		if (bracketMatcher != null) {
@@ -315,13 +169,4 @@
 			bracketMatcher = null;
 		}
 	}
-	
-	public BaseDescr getDescr(int offset) {
-		try {
-			DRLInfo info = DroolsEclipsePlugin.getDefault().parseResource(this, true, false);
-			return DescrUtil.getDescr(info.getPackageDescr(), offset);
-		} catch (DroolsParserException exc) {
-			return null;
-		}
-	}
 }

Deleted: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/BRLSourceViewerConfig.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/BRLSourceViewerConfig.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/BRLSourceViewerConfig.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -1,127 +0,0 @@
-package org.drools.eclipse.editors;
-
-import org.drools.eclipse.editors.completion.DefaultCompletionProcessor;
-import org.drools.eclipse.editors.completion.RuleCompletionProcessor;
-import org.drools.eclipse.editors.scanners.DRLPartionScanner;
-import org.drools.eclipse.editors.scanners.DRLScanner;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistant;
-import org.eclipse.jface.text.presentation.IPresentationReconciler;
-import org.eclipse.jface.text.presentation.PresentationReconciler;
-import org.eclipse.jface.text.reconciler.IReconciler;
-import org.eclipse.jface.text.reconciler.MonoReconciler;
-import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.source.DefaultAnnotationHover;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-import org.eclipse.swt.graphics.Color;
-
-/**
- * Source viewer config wires up the syntax highlighting, partitioning
- * and content assistance.
- * 
- * @author Michael Neale
- *
- */
-public class BRLSourceViewerConfig extends SourceViewerConfiguration {
-
-	private DRLScanner scanner;
-
-	private static Color DEFAULT_COLOR =
-		ColorManager.getInstance().getColor(ColorManager.DEFAULT);
-
-	private AbstractRuleEditor editor;
-
-	public BRLSourceViewerConfig(AbstractRuleEditor editor) {
-		this.editor = editor;
-	}
-
-	protected DRLScanner getScanner() {
-		if (scanner == null) {
-			scanner = new DRLScanner();
-			scanner.setDefaultReturnToken(new Token(new TextAttribute(DEFAULT_COLOR)));
-		}
-		return scanner;
-	}
-
-	/**
-	 * Define reconciler - this has to be done for each partition.
-	 * Currently there are 3 partitions, Inside rule, outside rule and inside comment.
-	 */
-	public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
-		PresentationReconciler reconciler = new PresentationReconciler();
-
-		//bucket partition... (everything else outside a rule)
-		DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getScanner());
-		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
-		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
-
-		//inside a rule partition
-		dr = new DefaultDamagerRepairer(getScanner());
-		reconciler.setDamager(dr, DRLPartionScanner.RULE_PART_CONTENT);
-		reconciler.setRepairer(dr, DRLPartionScanner.RULE_PART_CONTENT);
-
-		//finally, inside a multi line comment.
-		dr = new DefaultDamagerRepairer(new SingleTokenScanner(
-				new TextAttribute(ColorManager.getInstance().getColor(
-						ColorManager.SINGLE_LINE_COMMENT))));
-		reconciler.setDamager(dr, DRLPartionScanner.RULE_COMMENT);
-		reconciler.setRepairer(dr, DRLPartionScanner.RULE_COMMENT);
-
-		return reconciler;
-	}
-
-	/**
-	 * Single token scanner, used for scanning for multiline comments mainly.
-	 */
-	static class SingleTokenScanner extends BufferedRuleBasedScanner {
-		public SingleTokenScanner(TextAttribute attribute) {
-			setDefaultReturnToken(new Token(attribute));
-		}
-	}
-
-	/**
-	 * Get the appropriate content assistance, for each partition.
-	 */
-	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
-		ContentAssistant assistant = new ContentAssistant();
-		//setup the content assistance, which is
-		//sensitive to the partition that it is in.
-        assistant.setAutoActivationDelay(1);
-		assistant.setContentAssistProcessor(
-			new DefaultCompletionProcessor(editor), IDocument.DEFAULT_CONTENT_TYPE);
-		assistant.setContentAssistProcessor(
-			new RuleCompletionProcessor(editor), DRLPartionScanner.RULE_PART_CONTENT);
-		assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
-		return assistant;
-	}
-
-	public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
-		return DRLPartionScanner.LEGAL_CONTENT_TYPES;
-	}
-
-	public IReconciler getReconciler(ISourceViewer sourceViewer) {
-		MonoReconciler reconciler = null;
-		if (sourceViewer != null) {
-			reconciler = new MonoReconciler(
-				new DRLReconcilingStrategy(sourceViewer, editor), false);
-			reconciler.setDelay(500);
-			reconciler.setProgressMonitor(new NullProgressMonitor());
-		}
-		return reconciler;
-	}
-
-	public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
-		return new DefaultAnnotationHover();
-	}
-
-	public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
-		return new DefaultAnnotationHover();
-	}
-}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/ColorManager.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/ColorManager.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/ColorManager.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -8,39 +8,38 @@
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.widgets.Display;
 
+/**
+ * Drools color manager.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
 public class ColorManager {
 
+    private static final ColorManager INSTANCE = new ColorManager();
     
-    private final static ColorManager instance = new ColorManager();
-    
-    public static final RGB MULTI_LINE_COMMENT = new RGB(128, 0, 0);
     public static final RGB SINGLE_LINE_COMMENT = new RGB(128, 128, 0);
-    public static final RGB KEYWORD= new RGB(150, 0, 0);
-    public static final RGB TYPE= new RGB(0, 0, 128);
-    public static final RGB STRING= new RGB(0, 128, 0); 
-    public static final RGB DEFAULT= new RGB(0, 0, 0);
-    public static final RGB JAVADOC_KEYWORD= new RGB(0, 128, 0);
-    public static final RGB JAVADOC_TAG= new RGB(128, 128, 128);
-    public static final RGB JAVADOC_LINK= new RGB(128, 128, 128);
-    public static final RGB JAVADOC_DEFAULT= new RGB(0, 128, 128);    
+    public static final RGB KEYWORD = new RGB(150, 0, 0);
+    public static final RGB STRING = new RGB(0, 128, 0); 
+    public static final RGB DEFAULT = new RGB(0, 0, 0);
 
-	protected Map fColorTable = new HashMap(10);
+	protected Map colorTable = new HashMap(10);
 
 	void dispose() {
-		Iterator e = fColorTable.values().iterator();
-		while (e.hasNext())
+		Iterator e = colorTable.values().iterator();
+		while (e.hasNext()) {
 			 ((Color) e.next()).dispose();
+		}
 	}
     
     public static ColorManager getInstance() {
-        return instance;
+        return INSTANCE;
     }
     
 	public Color getColor(RGB rgb) {
-		Color color = (Color) fColorTable.get(rgb);
+		Color color = (Color) colorTable.get(rgb);
 		if (color == null) {
 			color = new Color(Display.getCurrent(), rgb);
-			fColorTable.put(rgb, color);
+			colorTable.put(rgb, color);
 		}
 		return color;
 	}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLAnnotationModel.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLAnnotationModel.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLAnnotationModel.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -9,6 +9,11 @@
 import org.eclipse.jface.text.Position;
 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
 
+/**
+ * Drools annotation model.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
 public class DRLAnnotationModel extends ResourceMarkerAnnotationModel {
 
 	public DRLAnnotationModel(IResource resource) {

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLDocumentProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLDocumentProvider.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLDocumentProvider.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -11,12 +11,12 @@
 
 /**
  * Simple document provider.
- * @author Michael Neale
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  */
-public class DRLDocumentProvider
-    extends TextFileDocumentProvider {
-    
-    public IDocument getDocument(Object element) {
+public class DRLDocumentProvider extends TextFileDocumentProvider {
+	
+	public IDocument getDocument(Object element) {
         IDocument document = super.getDocument(element);
         if (document != null) {
             IDocumentPartitioner partitioner =

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLProblemAnnotation.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLProblemAnnotation.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLProblemAnnotation.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -2,6 +2,11 @@
 
 import org.eclipse.jface.text.source.Annotation;
 
+/**
+ * Problem annotation for Drools.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
 public class DRLProblemAnnotation extends Annotation {
 
 	public static final String ERROR = "org.drools.eclipse.editors.error_annotation";

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLRuleEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLRuleEditor.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLRuleEditor.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -4,43 +4,145 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.drools.compiler.DroolsParserException;
 import org.drools.eclipse.DRLInfo;
 import org.drools.eclipse.DroolsEclipsePlugin;
-import org.drools.eclipse.editors.outline.RuleContentOutlinePage;
-import org.drools.eclipse.preferences.IDroolsConstants;
+import org.drools.eclipse.debug.core.IDroolsDebugConstants;
+import org.drools.lang.descr.BaseDescr;
 import org.drools.lang.descr.FactTemplateDescr;
 import org.drools.lang.descr.FunctionDescr;
 import org.drools.lang.descr.FunctionImportDescr;
 import org.drools.lang.descr.ImportDescr;
 import org.drools.lang.descr.PackageDescr;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
+import org.eclipse.jdt.core.CompletionRequestor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
 
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
-
 /**
  * Generic rule editor for drools.
  * @author Michael Neale
  */
 public class DRLRuleEditor extends AbstractRuleEditor {
 
-	public DRLRuleEditor() {
-		setSourceViewerConfiguration(new DRLSourceViewerConfig(this));
-		setDocumentProvider(new DRLDocumentProvider());
-		getPreferenceStore().setDefault(IDroolsConstants.DRL_EDITOR_MATCHING_BRACKETS, true);
-		PreferenceConverter.setDefault(getPreferenceStore(), IDroolsConstants.DRL_EDITOR_MATCHING_BRACKETS_COLOR, new RGB(192, 192, 192));
+    protected List imports;
+    protected List functions;
+    protected Map templates;
+    protected String packageName;
+    protected List classesInPackage;
+
+    public DRLRuleEditor() {
 	}
+    
+	public List getImports() {
+		if (imports == null) {
+			loadImportsAndFunctions();
+		}
+		return imports;
+	}
+	
+	public List getFunctions() {
+		if (functions == null) {
+			loadImportsAndFunctions();
+		}
+		return functions;
+	}
+	
+	public Set getTemplates() {
+		if (templates == null) {
+			loadImportsAndFunctions();
+		}
+		return templates.keySet();
+	}
+	
+	public FactTemplateDescr getTemplate(String name) {
+		if (templates == null) {
+			loadImportsAndFunctions();
+		}
+		return (FactTemplateDescr) templates.get(name);
+	}
+	
+	public String getPackage() {
+		if (packageName == null) {
+			loadImportsAndFunctions();
+		}
+		return packageName;
+	}
+	
+	public List getClassesInPackage() {
+		if (classesInPackage == null) {
+			classesInPackage = getAllClassesInPackage(getPackage());
+		}
+		return classesInPackage;
+	}
+	
+	protected List getAllClassesInPackage(String packageName) {
+		final List list = new ArrayList();
+		if (packageName != null) {
+			IEditorInput input = getEditorInput();
+			if (input instanceof IFileEditorInput) {
+				IProject project = ((IFileEditorInput) input).getFile().getProject();
+				IJavaProject javaProject = JavaCore.create(project);
+				
+				CompletionRequestor requestor = new CompletionRequestor() {
+					public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
+						String className = new String(proposal.getCompletion());
+						if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF) {
+							list.add(className);
+						}
+						// ignore all other proposals
+					}
+				};
+	
+				try {
+					javaProject.newEvaluationContext().codeComplete(packageName + ".", packageName.length() + 1, requestor);
+				} catch (Throwable t) {
+					DroolsEclipsePlugin.log(t);
+				}
+			}
+		}
+		return list;
+	}
 
-    protected ContentOutlinePage getContentOutline() {
-        if (ruleContentOutline == null) {
-            ruleContentOutline = new RuleContentOutlinePage(this);
-            ruleContentOutline.update();
-        }
-        return ruleContentOutline;
-    }
-
+	protected List getAllStaticMethodsInClass(String className) {
+		final List list = new ArrayList();
+		if (className != null) {
+			IEditorInput input = getEditorInput();
+			if (input instanceof IFileEditorInput) {
+				IProject project = ((IFileEditorInput) input).getFile().getProject();
+				IJavaProject javaProject = JavaCore.create(project);
+				
+				CompletionRequestor requestor = new CompletionRequestor() {
+					public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
+						String functionName = new String(proposal.getCompletion());
+						if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.METHOD_REF) {
+							list.add(functionName.substring(0, functionName.length() - 2)); // remove the ()
+						}
+						// ignore all other proposals
+					}
+				};
+	
+				try {
+					javaProject.newEvaluationContext().codeComplete(className + ".", className.length() + 1, requestor);
+				} catch (Throwable t) {
+					DroolsEclipsePlugin.log(t);
+				}
+			}
+		}
+		return list;
+	}
+	
     protected void loadImportsAndFunctions() {
         try {
             DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(this, true, false);
@@ -94,4 +196,54 @@
         }
     }
 
+	public Object getAdapter(Class adapter) {
+		if (adapter.equals(IToggleBreakpointsTarget.class)) {
+			return getBreakpointAdapter();
+		}
+		return super.getAdapter(adapter);
+	}
+
+	private Object getBreakpointAdapter() {
+		return new DroolsLineBreakpointAdapter();
+	}
+
+	public void doSave(IProgressMonitor monitor) {
+		super.doSave(monitor);
+		// remove cached content
+		imports = null;
+		functions = null;
+		templates = null;
+		packageName = null;
+		classesInPackage = null;
+	}
+
+	public void gotoMarker(IMarker marker) {
+		try {
+			if (marker.getType().equals(IDroolsDebugConstants.DROOLS_MARKER_TYPE)) {
+				int line = marker.getAttribute(IDroolsDebugConstants.DRL_LINE_NUMBER, -1);
+	            if (line > -1)
+	            	--line;
+	                try {
+	                    IDocument document = getDocumentProvider().getDocument(getEditorInput());
+	                    selectAndReveal(document.getLineOffset(line), document.getLineLength(line));
+	                } catch(BadLocationException exc) {
+	                	DroolsEclipsePlugin.log(exc);
+	                }
+			} else {
+				super.gotoMarker(marker);
+			}
+		} catch (CoreException exc) {
+			DroolsEclipsePlugin.log(exc);
+		}
+	}
+	
+	
+	public BaseDescr getDescr(int offset) {
+		try {
+			DRLInfo info = DroolsEclipsePlugin.getDefault().parseResource(this, true, false);
+			return DescrUtil.getDescr(info.getPackageDescr(), offset);
+		} catch (DroolsParserException exc) {
+			return null;
+		}
+	}
 }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLSourceViewerConfig.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLSourceViewerConfig.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DRLSourceViewerConfig.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -27,7 +27,7 @@
  * and content assistance.
  * 
  * @author Michael Neale
- *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  */
 public class DRLSourceViewerConfig extends SourceViewerConfiguration {
 
@@ -41,6 +41,10 @@
 	public DRLSourceViewerConfig(AbstractRuleEditor editor) {
 		this.editor = editor;
 	}
+	
+	protected AbstractRuleEditor getEditor() {
+		return editor;
+	}
 
 	protected DRLScanner getScanner() {
 		if (scanner == null) {

Deleted: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DSLAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DSLAdapter.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DSLAdapter.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -1,172 +0,0 @@
-package org.drools.eclipse.editors;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.drools.lang.dsl.DSLMapping;
-import org.drools.lang.dsl.DSLMappingEntry;
-import org.drools.lang.dsl.DSLMappingFile;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-
-/**
- * This holds the DSL configuration for an editor instance.
- * When loading, it will find the DSL file, and load the applicable lists.
- * 
- * This provides a link between the editor and the DSL features of the rule language.  
- * 
- * It will look for a DSL configuration, as named in the rule file, in the same directory as the rule file.
- * Failing this, it will search one directory above the rule file. 
- * Failing that, it will search the root of the project in the workspace.
- * 
- * @author Michael Neale
- */
-public class DSLAdapter {
-
-    private String dslConfigName;
-    private boolean valid = false;
-    private List conditionProposals = new ArrayList();
-    private List consequenceProposals = new ArrayList();
-    
-    
-    //to dig out the expander, without using the parser.
-    private static final Pattern expander = Pattern.compile( "^.*expander\\s*(.*)\\.dsl.*", 
-                                                             Pattern.DOTALL | Pattern.MULTILINE );
-    /**
-     * This will sniff out the DSL config file name from the content.
-     * It will then use the IFile input to search around for the file itself.
-     * TODO: provide an alternative that just loads off a stream (for non IDEs workbenches like jlibrary).
-     * @param content Rule source
-     * @param input File from the FileEditorInput
-     */
-    public DSLAdapter(String content, IFile input) {
-        
-        dslConfigName = findDSLConfigName( content );
-        if (dslConfigName == null) return;
-        loadConfig( input );
-    }
-    
-    /** Get a reader to the DSL contents */
-    public static Reader getDSLContent(String ruleSource, IResource input) throws CoreException {
-        String dslFileName = findDSLConfigName( ruleSource );
-        if (dslFileName == null) return null;
-        IResource res = findDSLResource( input, dslFileName );
-        if (res instanceof IFile) {
-            IFile dslConf = (IFile) res;
-            if (dslConf.exists()) {
-                return new InputStreamReader(dslConf.getContents());
-            }
-        }
-        return null;
-    }
-
-    /**
-     * This does the hunting around the projec to find the .dsl file.
-     */
-    private void loadConfig(IFile input) {
-        IResource res = findDSLResource( input, dslConfigName );
-        if (res instanceof IFile) {
-            IFile dslConf = (IFile) res;
-            if (dslConf.exists()) {
-                InputStream stream = null; 
-                try {
-                    stream = dslConf.getContents();
-                    readConfig( stream );
-                    valid = true;
-                } catch ( Exception e ) {
-                    throw new IllegalStateException("Unable to open DSL config file. (Exception: " + e.getMessage() + ")");
-                } finally {
-                    closeStream( stream );
-                }
-                
-            }
-        }
-    }
-
-    private static IResource findDSLResource(IResource input, String dslFileName) {
-        IResource res = input.getParent().findMember( dslFileName );
-        if (res == null) res = input.getParent().getParent().findMember( dslFileName ); //try parent directory
-        if (res == null) res = input.getProject().findMember( dslFileName ); //try root of project.
-        return res;
-    }
-
-    
-    /** This will load in the DSL config file, using the DSLMapping from drools-compiler */
-    void readConfig(InputStream stream) throws IOException, CoreException {
-        DSLMappingFile file = new DSLMappingFile();
-        file.parseAndLoad( new InputStreamReader(stream) );
-
-        DSLMapping grammar = file.getMapping();
-        List conditions = grammar.getEntries( DSLMappingEntry.CONDITION );
-        List consequences = grammar.getEntries( DSLMappingEntry.CONSEQUENCE );
-        
-        conditionProposals = buildProposals(conditions);
-        consequenceProposals = buildProposals(consequences);
-    }
-
-    private List buildProposals(List suggestions) {
-    	List result = new ArrayList(suggestions.size());
-    	Iterator iterator = suggestions.iterator();
-        while (iterator.hasNext()) {
-            DSLMappingEntry text = (DSLMappingEntry) iterator.next();
-            result.add(text.getMappingKey());
-        }
-        return result;
-    }
-
-    private void closeStream(InputStream stream) {
-        if (stream != null) try {
-            stream.close();
-        } catch ( IOException e ) {}
-    }
-
-    DSLAdapter() {
-        
-    }
-
-    /** Sniffs out the expander/DSL config name as best it can. */
-    static String findDSLConfigName(String content) {
-        String name = null;
-        Matcher matches = expander.matcher( content );
-        if (matches.matches()) {
-            name = matches.group(1) + ".dsl";
-        }
-        return name;
-    }
-    
-    
-    String getDSLConfigName() {
-        return dslConfigName;
-    }
-    
-    
-    public boolean isValid() {
-        return valid;
-    }
-    
-    
-    public boolean hasConditions() {
-        return conditionProposals.size() > 0;
-    }
-    
-    public boolean hasConsequences() {
-        return consequenceProposals.size() > 0;
-    }
-    
-    public List listConditionItems() {
-        return conditionProposals;
-    }
-    
-    public List listConsequenceItems() {
-        return consequenceProposals;
-    }    
-    
-}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DescrUtil.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DescrUtil.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DescrUtil.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -12,6 +12,11 @@
 import org.drools.lang.descr.PackageDescr;
 import org.drools.lang.descr.RuleDescr;
 
+/**
+ * Util class for searching Descr tree.
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
 public final class DescrUtil {
 	
 	private DescrUtil() {

Deleted: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/RuleEditorPlugin.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/RuleEditorPlugin.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/RuleEditorPlugin.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -1,65 +0,0 @@
-package org.drools.eclipse.editors;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-/**
- * The main plugin class to be used in the desktop.
- */
-public class RuleEditorPlugin extends AbstractUIPlugin {
-	//The shared instance.
-	private static RuleEditorPlugin plugin;
-	//Resource bundle.
-	private ResourceBundle resourceBundle;
-	
-	/**
-	 * The constructor.
-	 */
-	public RuleEditorPlugin() {
-		super();
-		plugin = this;
-		try {
-			resourceBundle= ResourceBundle.getBundle("org.drools.eclipse.editors.DRLEditorResources");
-		} catch (MissingResourceException x) {
-			resourceBundle = null;
-		}
-	}
-
-	/**
-	 * Returns the shared instance.
-	 */
-	public static RuleEditorPlugin getDefault() {
-		return plugin;
-	}
-
-	/**
-	 * Returns the workspace instance.
-	 */
-	public static IWorkspace getWorkspace() {
-		return ResourcesPlugin.getWorkspace();
-	}
-
-	/**
-	 * Returns the string from the plugin's resource bundle,
-	 * or 'key' if not found.
-	 */
-	public static String getResourceString(String key) {
-		ResourceBundle bundle= RuleEditorPlugin.getDefault().getResourceBundle();
-		try {
-			return bundle.getString(key);
-		} catch (MissingResourceException e) {
-			return key;
-		}
-	}
-
-	/**
-	 * Returns the plugin's resource bundle,
-	 */
-	public ResourceBundle getResourceBundle() {
-		return resourceBundle;
-	}
-}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessor.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessor.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -4,6 +4,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.contentassist.CompletionProposal;
 import org.eclipse.jface.text.contentassist.ICompletionProposal;
@@ -12,10 +14,9 @@
 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
 import org.eclipse.ui.part.EditorPart;
 
-
 /**
  * 
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
  */
 public abstract class AbstractCompletionProcessor implements IContentAssistProcessor {
 
@@ -76,6 +77,18 @@
     	}
     }
 
+    /**
+     * Read some text from behind the cursor position.
+     * This provides context to both filter what is shown based
+     * on what the user has typed in, and also to provide more information for the 
+     * list of suggestions based on context.
+     */
+    protected String readBackwards(int documentOffset, IDocument doc) throws BadLocationException {
+        int startPart = doc.getPartition(documentOffset).getOffset();
+        String prefix = doc.get(startPart, documentOffset - startPart);
+        return prefix;
+    }
+
 	/* 
 	 * @see IContentAssistProcessor
 	 */

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -8,25 +8,29 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.StringTokenizer;
 
+import org.drools.lang.dsl.DSLMapping;
+import org.drools.lang.dsl.DSLMappingEntry;
+import org.drools.lang.dsl.DSLMappingEntry.Section;
+
 public class DSLTree {
 
-    public static final String when = "[when]";
-    public static final String then = "[then]";
-    public static final String wildcard = "[*]";
     public static final String separator = "=";
     public static final String tab = "  ";
     
     private Node current = null;
     private Node last = null;
-    private Node root = null;
+    private Node rootCond = null;
+    private Node rootConseq = null;
     private boolean empty = true;
     private ArrayList suggestions = new ArrayList();
     private HashMap objToNL = new HashMap();
     
     public DSLTree() {
-        this.root = new Node("root");
+        this.rootCond = new Node("root");
+        this.rootConseq = new Node("root");
     }
     
     /**
@@ -35,16 +39,7 @@
      * @param dslFile
      */
     public void buildTree(String dslFile) {
-        // first we clear the children
-        this.root.clearChildren();
-        BufferedReader breader = openDSLFile(dslFile);
-        parseFile(breader);
-        try {
-            breader.close();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        this.empty = false;
+        buildTree(openDSLFile(dslFile));
     }
 
     /**
@@ -53,8 +48,12 @@
      * @param dslcontents
      */
     public void buildTree(Reader dslcontents) {
-        this.root.clearChildren();
-        BufferedReader breader = this.createBufferedReader(dslcontents);
+    	buildTree(createBufferedReader(dslcontents));
+    }
+    
+    private void buildTree(BufferedReader breader) {
+        this.rootCond.clearChildren();
+        this.rootConseq.clearChildren();
         parseFile(breader);
         try {
             breader.close();
@@ -108,30 +107,64 @@
         String line = null;
         try {
             while ( (line = reader.readLine()) != null) {
+            	Section section = getSection(line);
                 String nl = stripHeadingAndCode(line);
                 String objname = this.getObjMetadata(nl);
                 nl = this.stripObjMetadata(nl);
-                if (!nl.startsWith("-")) {
-                    this.addObjToNLMap(objname, nl);
-                    StringTokenizer tokenz = new StringTokenizer(nl);
-                    addTokens(tokenz);
-                } else {
-                	String res = (String)this.objToNL.get(objname);
-                    StringTokenizer tokenz = new StringTokenizer(nl);
-                    addTokens(res,tokenz);
-                }
+                addEntry(section, nl, objname);
             }
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
     
+    public void buildTree(DSLMapping mapping) {
+    	List entries = mapping.getEntries();
+    	for (Iterator iterator = entries.iterator(); iterator.hasNext(); ) {
+    		DSLMappingEntry entry = (DSLMappingEntry) iterator.next();
+        	Section section = entry.getSection();
+            String nl = entry.getMappingKey();
+            String objname = entry.getMetaData().getMetaData();
+            addEntry(section, nl, objname);
+    	}
+    }
+    
+    private void addEntry(Section section, String nl, String objname) {
+        if (!nl.startsWith("-")) {
+            this.addObjToNLMap(objname, nl);
+            String[] tokenz = nl.split("\\s");
+            if (section == DSLMappingEntry.CONDITION || section == DSLMappingEntry.ANY) {
+            	addTokens(tokenz, rootCond);
+            }
+            if (section == DSLMappingEntry.CONSEQUENCE || section == DSLMappingEntry.ANY) {
+            	addTokens(tokenz, rootConseq);
+            }
+        } else {
+        	String res = (String)this.objToNL.get(objname);
+            StringTokenizer tokenz = new StringTokenizer(nl);
+            addTokens(res,tokenz);
+        }
+    }
+    
     public void addObjToNLMap(String objname, String nl) {
     	if (!objname.startsWith("-")) {
     		this.objToNL.put(objname, nl);
     	}
     }
     
+    protected Section getSection(String text) {
+        if (text.startsWith(DSLMappingEntry.CONDITION.getSymbol())) {
+            return DSLMappingEntry.CONDITION;
+        } else if (text.startsWith(DSLMappingEntry.CONSEQUENCE.getSymbol())) {
+            return DSLMappingEntry.CONSEQUENCE;
+        } else if (text.startsWith(DSLMappingEntry.ANY.getSymbol())) {
+            return DSLMappingEntry.ANY;
+        } else if (text.startsWith(DSLMappingEntry.KEYWORD.getSymbol())) {
+        	return DSLMappingEntry.KEYWORD;
+        }
+        return null; 
+    }
+    
     /**
      * method will strip out the when, then, * at the beginning of each 
      * line and the mapped drl expression
@@ -139,12 +172,12 @@
      * @return
      */
     protected String stripHeadingAndCode(String text) {
-        if (text.startsWith(when)) {
-            return text.substring(6,text.indexOf("="));
-        } else if (text.startsWith(then)) {
-            return text.substring(6,text.indexOf("="));
-        } else if (text.startsWith(wildcard)) {
-            return text.substring(3,text.indexOf("="));
+        if (text.startsWith(DSLMappingEntry.CONDITION.getSymbol())) {
+            return text.substring(DSLMappingEntry.CONDITION.getSymbol().length() + 2,text.indexOf("="));
+        } else if (text.startsWith(DSLMappingEntry.CONSEQUENCE.getSymbol())) {
+            return text.substring(DSLMappingEntry.CONSEQUENCE.getSymbol().length() + 2,text.indexOf("="));
+        } else if (text.startsWith(DSLMappingEntry.ANY.getSymbol())) {
+            return text.substring(DSLMappingEntry.ANY.getSymbol().length() + 2,text.indexOf("="));
         } else if (text.startsWith("#")) {
             return "";
         } else {
@@ -187,7 +220,7 @@
      * @param tokens
      */
     public void addTokens(String metadata, StringTokenizer tokens) {
-    	Node mnode = this.root.addToken(metadata);
+    	Node mnode = this.rootCond.addToken(metadata);
     	Node thenode = mnode;
     	while (tokens.hasMoreTokens()) {
     		Node newnode = thenode.addToken(tokens.nextToken());
@@ -199,10 +232,10 @@
      * method adds the token to root
      * @param tokens
      */
-    public void addTokens(StringTokenizer tokens) {
-        Node thenode = this.root;
-        while (tokens.hasMoreTokens()) {
-            Node newnode = thenode.addToken(tokens.nextToken());
+    public void addTokens(String[] tokens, Node rootNode) {
+        Node thenode = rootNode;
+        for (int i = 0; i < tokens.length; i++) {
+            Node newnode = thenode.addToken(tokens[i]);
             thenode = newnode;
         }
     }
@@ -215,8 +248,8 @@
      * @param text
      * @return
      */
-    public Node[] getChildren(String text) {
-        Node thenode = this.root;
+    public Node[] getConditionChildren(String text) {
+        Node thenode = this.rootCond;
     	if (text.length() > 0) {
             StringTokenizer tokenz = new StringTokenizer(text);
             this.last = this.current;
@@ -230,7 +263,7 @@
                     break;
                 }
             }
-            if (thenode != this.root) {
+            if (thenode != this.rootCond) {
                 this.current = thenode;
             }
     	}
@@ -240,13 +273,45 @@
     }
 
     /**
+     * the method will tokenize the text and try to find
+     * the node that matches and return the children. the method
+     * will traverse down the network as far as it can and return
+     * the children at that level.
+     * @param text
+     * @return
+     */
+    public Node[] getConsequenceChildren(String text) {
+        Node thenode = this.rootConseq;
+    	if (text.length() >= 0) {
+            StringTokenizer tokenz = new StringTokenizer(text);
+            this.last = this.current;
+            while (tokenz.hasMoreTokens()) {
+                String strtk = tokenz.nextToken();
+                Node ch = thenode.getChild(strtk);
+                // if a child is found, we set thenode to the child Node
+                if (ch != null) {
+                    thenode = ch;
+                } else {
+                    break;
+                }
+            }
+            if (thenode != this.rootConseq) {
+                this.current = thenode;
+            }
+    	}
+        Collection children = thenode.getChildren();
+        Node[] nchild = new Node[children.size()];
+        return (Node[]) children.toArray(nchild);
+    }
+
+    /**
      * the method expects the caller to pass the object
      * @param obj
      * @param text
      * @return
      */
     public Node[] getChildren(String obj, String text) {
-        Node thenode = this.root.getChild(obj);
+        Node thenode = this.rootCond.getChild(obj);
     	if (thenode != null && text.length() > 0) {
             StringTokenizer tokenz = new StringTokenizer(text);
             this.last = this.current;
@@ -260,12 +325,12 @@
                     break;
                 }
             }
-            if (thenode != this.root) {
+            if (thenode != this.rootCond) {
                 this.current = thenode;
             }
     	}
     	if (thenode == null) {
-    		thenode = this.root;
+    		thenode = this.rootCond;
     	}
         Collection children = thenode.getChildren();
         Node[] nchild = new Node[children.size()];
@@ -280,8 +345,8 @@
      * @param text
      * @return
      */
-    public ArrayList getChildrenList(String text, boolean addChildren) {
-    	Node[] c = getChildren(text);
+    public ArrayList getConditionChildrenList(String text, boolean addChildren) {
+    	Node[] c = getConditionChildren(text);
     	this.suggestions.clear();
     	for (int idx=0; idx < c.length; idx++) {
     		this.suggestions.add(c[idx].getToken());
@@ -293,6 +358,26 @@
     }
     
     /**
+     * for convienance, the method will return a list of strings
+     * that are children of the last node found. If the editor
+     * wants to generate the children strings, call the method
+     * with true
+     * @param text
+     * @return
+     */
+    public ArrayList getConsequenceChildrenList(String text, boolean addChildren) {
+    	Node[] c = getConsequenceChildren(text);
+    	this.suggestions.clear();
+    	for (int idx=0; idx < c.length; idx++) {
+    		this.suggestions.add(c[idx].getToken());
+    		if (addChildren) {
+        		this.addChildToList(c[idx], c[idx].getToken(), this.suggestions);
+    		}
+    	}
+    	return this.suggestions;
+    }
+    
+    /**
      * 
      * @param obj
      * @param text
@@ -311,7 +396,7 @@
     	// in the event the line is zero length after it is trimmed, we also add
     	// the top level nodes
     	if (text.trim().length() == 0) {
-    		Iterator top = this.root.getChildren().iterator();
+    		Iterator top = this.rootCond.getChildren().iterator();
         	while (top.hasNext()) {
         		Node t = (Node)top.next();
         		if (!this.suggestions.contains(t.getToken())) {
@@ -365,7 +450,7 @@
      */
     public void printTree() {
         System.out.println("ROOT");
-        Iterator itr = this.root.getChildren().iterator();
+        Iterator itr = this.rootCond.getChildren().iterator();
         while (itr.hasNext()) {
             Node n = (Node)itr.next();
             printNode(n);

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -11,6 +11,7 @@
 import org.drools.eclipse.DroolsEclipsePlugin;
 import org.drools.eclipse.DroolsPluginImages;
 import org.drools.eclipse.editors.AbstractRuleEditor;
+import org.drools.eclipse.editors.DRLRuleEditor;
 import org.drools.util.StringUtils;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.jdt.core.CompletionProposal;
@@ -18,7 +19,6 @@
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.eval.IEvaluationContext;
-import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.swt.graphics.Image;
@@ -46,15 +46,15 @@
     // TODO: doesn't work for { inside functions
     private static final Pattern FUNCTION_PATTERN = Pattern.compile( ".*\n\\W*function\\s+(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)\\s*\\{([^\\}]*)", Pattern.DOTALL);
     protected static final Image VARIABLE_ICON = DroolsPluginImages.getImage(DroolsPluginImages.VARIABLE);
-    protected static final Image methodIcon = DroolsPluginImages.getImage(DroolsPluginImages.METHOD);
-    protected static final Pattern START_OF_NEW_JAVA_STATEMENT = Pattern.compile(".*[;{}]\\s*", Pattern.DOTALL);
+    protected static final Image METHOD_ICON = DroolsPluginImages.getImage(DroolsPluginImages.METHOD);
+    private static final Pattern START_OF_NEW_JAVA_STATEMENT = Pattern.compile(".*[;{}]\\s*", Pattern.DOTALL);
 
     public DefaultCompletionProcessor(AbstractRuleEditor editor) {
     	super(editor);
     }
     
-    protected AbstractRuleEditor getDRLEditor() {
-    	return (AbstractRuleEditor) getEditor();
+    protected DRLRuleEditor getDRLEditor() {
+    	return (DRLRuleEditor) getEditor();
     }
     
 	protected List getCompletionProposals(ITextViewer viewer, int documentOffset) {
@@ -146,26 +146,6 @@
         return list;
     }
 
-    /**
-     * Read some text from behind the cursor position.
-     * This provides context to both filter what is shown based
-     * on what the user has typed in, and also to provide more information for the 
-     * list of suggestions based on context.
-     */
-    protected String readBackwards(int documentOffset, IDocument doc) throws BadLocationException {
-        int startPart = doc.getPartition(documentOffset).getOffset();
-//        if (startPart == 0) {
-//            if (documentOffset < 32) {
-//                startPart = 0;
-//            } else {
-//                startPart = documentOffset - 32;
-//            }
-//        }
-        
-        String prefix = doc.get(startPart, documentOffset - startPart);
-        return prefix;
-    }
-
 	protected List getJavaCompletionProposals(final String javaText, final String prefix, Map params) {
 		final List list = new ArrayList();
 		IEditorInput input = getEditor().getEditorInput();
@@ -188,7 +168,7 @@
 							if ("".equals(javaTextWithoutPrefix.trim()) || START_OF_NEW_JAVA_STATEMENT.matcher(javaTextWithoutPrefix).matches()) {
 								return;
 							}
-							prop.setImage(methodIcon);
+							prop.setImage(METHOD_ICON);
 							break;
 						default:
 					}
@@ -219,5 +199,9 @@
 		}
 		return list;
 	}
+	
+	protected boolean isStartOfJavaExpression(String text) {
+		return "".equals(text.trim()) || START_OF_NEW_JAVA_STATEMENT.matcher(text).matches();
+	}
 
 }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -47,29 +47,35 @@
     static final Pattern ACCUMULATE_PATTERN_RESULT = Pattern.compile(".*,\\s*init\\s*\\(\\s*(.*)\\)\\s*,\\s*action\\s*\\(\\s*(.*)\\)\\s*,\\s*result\\s*\\(\\s*(.*)", Pattern.DOTALL);
     static final Pattern COLLECT_PATTERN = Pattern.compile(".*\\)\\s+from\\s+collect\\s*\\(\\s*", Pattern.DOTALL);
     
-	static final int LOCATION_UNKNOWN = 0;
-	static final int LOCATION_BEGIN_OF_CONDITION = 1;
-	static final int LOCATION_BEGIN_OF_CONDITION_EXISTS = 2;
-	static final int LOCATION_BEGIN_OF_CONDITION_AND_OR = 3;
-	static final int LOCATION_BEGIN_OF_CONDITION_NOT = 4;
+    static final Pattern THEN_PATTERN = Pattern.compile(".*\n\\s*when\\s*(.*)\n\\s*then\\s*(.*)", Pattern.DOTALL);
+
+    static final int LOCATION_UNKNOWN = 0;
 	
-	static final int LOCATION_INSIDE_CONDITION_START = 100;
-	static final int LOCATION_INSIDE_CONDITION_OPERATOR = 101;
-	static final int LOCATION_INSIDE_CONDITION_ARGUMENT = 102;
-	static final int LOCATION_INSIDE_CONDITION_END = 103;
+	static final int LOCATION_LHS_BEGIN_OF_CONDITION = 1;
+	static final int LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS = 2;
+	static final int LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR = 3;
+	static final int LOCATION_LHS_BEGIN_OF_CONDITION_NOT = 4;
+	
+	static final int LOCATION_LHS_INSIDE_CONDITION_START = 100;
+	static final int LOCATION_LHS_INSIDE_CONDITION_OPERATOR = 101;
+	static final int LOCATION_LHS_INSIDE_CONDITION_ARGUMENT = 102;
+	static final int LOCATION_LHS_INSIDE_CONDITION_END = 103;
 
-	static final int LOCATION_INSIDE_EVAL = 200;
+	static final int LOCATION_LHS_INSIDE_EVAL = 200;
 	
-	static final int LOCATION_FROM = 300;
-	static final int LOCATION_FROM_COLLECT = 301;
-	static final int LOCATION_FROM_ACCUMULATE = 302;
-	static final int LOCATION_FROM_ACCUMULATE_INIT = 303;
-	static final int LOCATION_FROM_ACCUMULATE_INIT_INSIDE = 304;
-	static final int LOCATION_FROM_ACCUMULATE_ACTION = 305;
-	static final int LOCATION_FROM_ACCUMULATE_ACTION_INSIDE = 306;
-	static final int LOCATION_FROM_ACCUMULATE_RESULT = 307;
-	static final int LOCATION_FROM_ACCUMULATE_RESULT_INSIDE = 308;
+	static final int LOCATION_LHS_FROM = 300;
+	static final int LOCATION_LHS_FROM_COLLECT = 301;
+	static final int LOCATION_LHS_FROM_ACCUMULATE = 302;
+	static final int LOCATION_LHS_FROM_ACCUMULATE_INIT = 303;
+	static final int LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE = 304;
+	static final int LOCATION_LHS_FROM_ACCUMULATE_ACTION = 305;
+	static final int LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE = 306;
+	static final int LOCATION_LHS_FROM_ACCUMULATE_RESULT = 307;
+	static final int LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE = 308;
 	
+	static final int LOCATION_RHS = 1000;
+	static final int LOCATION_RULE_HEADER = 2000;
+	
 	static final String LOCATION_PROPERTY_CLASS_NAME = "ClassName";
 	static final String LOCATION_PROPERTY_PROPERTY_NAME = "PropertyName";
 	static final String LOCATION_PROPERTY_OPERATOR = "Operator";
@@ -78,6 +84,9 @@
 	static final String LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT = "FromAccumulateInitContent";
 	static final String LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT = "FromAccumulateActionContent";
 	static final String LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT = "FromAccumulateResultContent";
+	static final String LOCATION_LHS_CONTENT = "LHSContent";
+	static final String LOCATION_RHS_CONTENT = "RHSContent";
+	static final String LOCATION_HEADER_CONTENT = "HeaderContent";
 	
     private LocationDeterminator() {
 	}
@@ -107,7 +116,7 @@
     	}
     }
     
-	public static Location getLocationInCondition(String backText) {
+	public static Location getLocation(String backText) {
 		DrlParser parser = new DrlParser();
     	try {
     		PackageDescr packageDescr = parser.parse(backText);
@@ -124,30 +133,44 @@
 	public static Location determineLocationForDescr(BaseDescr descr, String backText) {
 		if (descr instanceof RuleDescr) {
 			RuleDescr ruleDescr = (RuleDescr) descr;
-			List subDescrs = ruleDescr.getLhs().getDescrs();
+			Object o = ruleDescr.getConsequence();
+			if (o == null) {
+				Matcher matcher = THEN_PATTERN.matcher(backText);
+				if (matcher.matches()) {
+					Location location = new Location(LOCATION_RHS);
+					location.setProperty(LOCATION_LHS_CONTENT, matcher.group(1));
+					location.setProperty(LOCATION_RHS_CONTENT, matcher.group(2));
+					return location;
+				}
+			}
+			AndDescr lhs = ruleDescr.getLhs();
+			if (lhs == null) {
+				return new Location(LOCATION_RULE_HEADER);
+			}
+			List subDescrs = lhs.getDescrs();
 			if (subDescrs.size() == 0) {
 				Matcher matcher = EXISTS_PATTERN.matcher(backText);
 				if (matcher.matches()) {
-					return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+					return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
 				}
 				matcher = NOT_PATTERN.matcher(backText);
 				if (matcher.matches()) {
-					return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+					return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
 				}
 				matcher = FROM_PATTERN.matcher(backText);
 				if (matcher.matches()) {
-					Location location = new Location(LOCATION_FROM);
+					Location location = new Location(LOCATION_LHS_FROM);
 					location.setProperty(LOCATION_FROM_CONTENT, "");
 					return location;
 				}
-				return new Location(LOCATION_BEGIN_OF_CONDITION);
+				return new Location(LOCATION_LHS_BEGIN_OF_CONDITION);
 			}
 			BaseDescr subDescr = (BaseDescr) subDescrs.get(subDescrs.size() - 1);
 			if (subDescr == null) {
-				return new Location(LOCATION_BEGIN_OF_CONDITION);
+				return new Location(LOCATION_LHS_BEGIN_OF_CONDITION);
 			}
 			if (endReached(subDescr)) {
-				return new Location(LOCATION_BEGIN_OF_CONDITION);
+				return new Location(LOCATION_LHS_BEGIN_OF_CONDITION);
 			}
 			return determineLocationForDescr(subDescr, backText);
 		} else if (descr instanceof PatternDescr) {
@@ -200,7 +223,7 @@
 				patternContents = "(" + matcher.group(2);
 			}
 			if (patternContents == null) {
-				return new Location(LOCATION_BEGIN_OF_CONDITION);
+				return new Location(LOCATION_LHS_BEGIN_OF_CONDITION);
 			}
 			List subDescrs = patternDescr.getDescrs();
 			if (subDescrs.size() > 0) {
@@ -221,7 +244,7 @@
 							int connectiveLocation = patternContents.lastIndexOf(connective);
 							patternContents = "( " + lastFieldDescr.getFieldName() + " " + patternContents.substring(connectiveLocation + 1);
 						} else {
-							Location location = new Location(LOCATION_INSIDE_CONDITION_END);
+							Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_END);
 							location.setProperty(LOCATION_PROPERTY_CLASS_NAME, patternDescr.getObjectType());
 							return location;
 						}
@@ -232,16 +255,16 @@
 		} else if (descr instanceof ExistsDescr) {
 			List subDescrs = ((ExistsDescr) descr).getDescrs();
 			if (subDescrs.size() == 0) {
-				return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+				return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
 			}
 			if (subDescrs.size() == 1) {
 				BaseDescr subDescr = (BaseDescr) subDescrs.get(0);
 				if (subDescr == null) {
-					return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+					return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
 				}
 				Location result = determineLocationForDescr(subDescr, backText);
-				if (result.getType() == LOCATION_BEGIN_OF_CONDITION) {
-					result.setType(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+				if (result.getType() == LOCATION_LHS_BEGIN_OF_CONDITION) {
+					result.setType(LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
 				}
 				return result;
 			}
@@ -249,16 +272,16 @@
 		} else if (descr instanceof NotDescr) {
 			List subDescrs = ((NotDescr) descr).getDescrs();
 			if (subDescrs.size() == 0) {
-				return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+				return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
 			}
 			if (subDescrs.size() == 1) {
 				BaseDescr subDescr = (BaseDescr) subDescrs.get(0);
 				if (subDescr == null) {
-					return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+					return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
 				}
 				Location location = determineLocationForDescr(subDescr, backText);
-				if (location.getType() == LOCATION_BEGIN_OF_CONDITION) {
-					return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+				if (location.getType() == LOCATION_LHS_BEGIN_OF_CONDITION) {
+					return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
 				}
 				return location;
 			}
@@ -271,17 +294,17 @@
 				if (subDescr == null) {
 					Matcher matcher = EXISTS_PATTERN.matcher(backText);
 					if (matcher.matches()) {
-						return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+						return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
 					}
 					matcher = NOT_PATTERN.matcher(backText);
 					if (matcher.matches()) {
-						return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+						return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
 					}
-					return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+					return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
 				} else {
 					Location location = determineLocationForDescr(subDescr, backText);
-					if (location.getType() == LOCATION_BEGIN_OF_CONDITION) {
-						return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+					if (location.getType() == LOCATION_LHS_BEGIN_OF_CONDITION) {
+						return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
 					}
 					return location;
 				}
@@ -295,23 +318,23 @@
 				if (subDescr == null) {
 					Matcher matcher = EXISTS_PATTERN.matcher(backText);
 					if (matcher.matches()) {
-						return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+						return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
 					}
 					matcher = NOT_PATTERN.matcher(backText);
 					if (matcher.matches()) {
-						return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
-					}return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+						return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
+					}return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
 				} else {
 					Location location = determineLocationForDescr(subDescr, backText);
-					if (location.getType() == LOCATION_BEGIN_OF_CONDITION) {
-						return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+					if (location.getType() == LOCATION_LHS_BEGIN_OF_CONDITION) {
+						return new Location(LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
 					}
 					return location;
 				}
 			}
 			return new Location(LOCATION_UNKNOWN);
 		} else if (descr instanceof FromDescr) {
-			Location location = new Location(LOCATION_FROM);
+			Location location = new Location(LOCATION_LHS_FROM);
 			String content = CompletionUtil.stripWhiteSpace(backText);
 			location.setProperty(LOCATION_FROM_CONTENT, content);
 			return location;
@@ -324,7 +347,7 @@
 			String accumulateText = backText.substring(end);
 			matcher = ACCUMULATE_PATTERN_RESULT.matcher(accumulateText);
 			if (matcher.matches()) {
-				Location location = new Location(LOCATION_FROM_ACCUMULATE_RESULT_INSIDE);
+				Location location = new Location(LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE);
 				location.setProperty(LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
 				location.setProperty(LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, matcher.group(2));
 				location.setProperty(LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT, matcher.group(3));
@@ -332,14 +355,14 @@
 			}
 			matcher = ACCUMULATE_PATTERN_ACTION.matcher(accumulateText);
 			if (matcher.matches()) {
-				Location location =  new Location(LOCATION_FROM_ACCUMULATE_ACTION_INSIDE);
+				Location location =  new Location(LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE);
 				location.setProperty(LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
 				location.setProperty(LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, matcher.group(2));
 				return location;
 			}
 			matcher = ACCUMULATE_PATTERN_INIT.matcher(accumulateText);
 			if (matcher.matches()) {
-				Location location =  new Location(LOCATION_FROM_ACCUMULATE_INIT_INSIDE);
+				Location location =  new Location(LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE);
 				location.setProperty(LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
 				return location;
 			}
@@ -349,7 +372,7 @@
 				String patternContents = matcher.group(4);
 				return getLocationForPatttern(patternContents, className);
 			}
-			return new Location(LOCATION_FROM_ACCUMULATE);
+			return new Location(LOCATION_LHS_FROM_ACCUMULATE);
 		} else if (descr instanceof CollectDescr) {
 			Matcher matcher = COLLECT_PATTERN.matcher(backText);
 			int end = -1;
@@ -363,12 +386,12 @@
 				String columnContents = matcher.group(4);
 				return getLocationForPatttern(columnContents, className);
 			}
-			return new Location(LOCATION_FROM_COLLECT);
+			return new Location(LOCATION_LHS_FROM_COLLECT);
 		} else if (descr instanceof EvalDescr) {
 			Matcher matcher = EVAL_PATTERN.matcher(backText);
 			if (matcher.matches()) {
 				String content = matcher.group(1);
-				Location location = new Location(LOCATION_INSIDE_EVAL);
+				Location location = new Location(LOCATION_LHS_INSIDE_EVAL);
 				location.setProperty(LOCATION_EVAL_CONTENT, content);
 				return location;
 			}
@@ -430,14 +453,14 @@
 	private static Location getLocationForPatttern(String patternContents, String className) {
 		Matcher matcher = PATTERN_PATTERN_OPERATOR.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_OPERATOR);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			location.setProperty(LOCATION_PROPERTY_PROPERTY_NAME, matcher.group(3));
 			return location;
         }
         matcher = PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_ARGUMENT);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			location.setProperty(LOCATION_PROPERTY_PROPERTY_NAME, matcher.group(3));
 			location.setProperty(LOCATION_PROPERTY_OPERATOR, matcher.group(4));
@@ -445,7 +468,7 @@
         }
         matcher = PATTERN_PATTERN_CONTAINS_ARGUMENT.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_ARGUMENT);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			location.setProperty(LOCATION_PROPERTY_PROPERTY_NAME, matcher.group(3));
 			location.setProperty(LOCATION_PROPERTY_OPERATOR, "contains");
@@ -453,7 +476,7 @@
         }
         matcher = PATTERN_PATTERN_EXCLUDES_ARGUMENT.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_ARGUMENT);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			location.setProperty(LOCATION_PROPERTY_PROPERTY_NAME, matcher.group(3));
 			location.setProperty(LOCATION_PROPERTY_OPERATOR, "excludes");
@@ -461,7 +484,7 @@
         }
         matcher = PATTERN_PATTERN_MATCHES_ARGUMENT.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_ARGUMENT);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			location.setProperty(LOCATION_PROPERTY_PROPERTY_NAME, matcher.group(3));
 			location.setProperty(LOCATION_PROPERTY_OPERATOR, "matches");
@@ -469,35 +492,35 @@
         }
         matcher = PATTERN_PATTERN_CONTAINS_END.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_END);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_END);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			return location;
         }
         matcher = PATTERN_PATTERN_MATCHES_END.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_END);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_END);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			return location;
         }
         matcher = PATTERN_PATTERN_EXCLUDES_END.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_END);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_END);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			return location;
         }
         matcher = PATTERN_PATTERN_COMPARATOR_END.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_END);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_END);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			return location;
         }
 		matcher = PATTERN_PATTERN_START.matcher(patternContents);
         if (matcher.matches()) {
-			Location location = new Location(LOCATION_INSIDE_CONDITION_START);
+			Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_START);
 			location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 			return location;
         }
-		Location location = new Location(LOCATION_INSIDE_CONDITION_START);
+		Location location = new Location(LOCATION_LHS_INSIDE_CONDITION_START);
 		location.setProperty(LOCATION_PROPERTY_CLASS_NAME, className);
 		return location;
 	}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -1,17 +1,12 @@
 package org.drools.eclipse.editors.completion;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.regex.Pattern;
 
 import org.drools.base.ClassTypeResolver;
 import org.drools.compiler.DrlParser;
@@ -19,12 +14,11 @@
 import org.drools.eclipse.DroolsEclipsePlugin;
 import org.drools.eclipse.DroolsPluginImages;
 import org.drools.eclipse.editors.AbstractRuleEditor;
-import org.drools.eclipse.editors.DSLAdapter;
+import org.drools.eclipse.editors.completion.LocationDeterminator.Location;
 import org.drools.eclipse.util.ProjectClassLoader;
 import org.drools.lang.descr.AccumulateDescr;
 import org.drools.lang.descr.AndDescr;
 import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.PatternDescr;
 import org.drools.lang.descr.ExistsDescr;
 import org.drools.lang.descr.FactTemplateDescr;
 import org.drools.lang.descr.FieldBindingDescr;
@@ -33,103 +27,51 @@
 import org.drools.lang.descr.NotDescr;
 import org.drools.lang.descr.OrDescr;
 import org.drools.lang.descr.PackageDescr;
+import org.drools.lang.descr.PatternDescr;
 import org.drools.lang.descr.RuleDescr;
 import org.drools.util.asm.ClassFieldInspector;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.part.FileEditorInput;
 
 /**
- * For handling within rules, including DSLs. At present this provides a fixed
- * list, plus what is available in the DSL configuration.
+ * For handling within rules. 
  * 
- * TODO: This can be enhanced to look back for declarations, and introspect to
- * get field names. (More can be done as well, this would just be the first
- * step).
- * 
- * This also handles queries, as they are just a type of rule essentially.
- * 
  * @author Michael Neale, Kris Verlanen
  */
 public class RuleCompletionProcessor extends DefaultCompletionProcessor {
 
-	private static final Pattern query = Pattern.compile(".*\\Wquery\\W.*",
-			Pattern.DOTALL);
+	private static final Image DROOLS_ICON = 
+		DroolsPluginImages.getImage(DroolsPluginImages.DROOLS);
 
-	private static final Image droolsIcon = DroolsPluginImages
-			.getImage(DroolsPluginImages.DROOLS);
+	private static final Image CLASS_ICON = 
+		DroolsPluginImages.getImage(DroolsPluginImages.CLASS);
 
-	private static final Image dslIcon = DroolsPluginImages
-			.getImage(DroolsPluginImages.DSL_EXPRESSION);
-
-	private static final Image classIcon = DroolsPluginImages
-			.getImage(DroolsPluginImages.CLASS);
-
-	private static final Pattern START_OF_CONSEQUENCE = Pattern.compile(
-			".*then\\s*", Pattern.DOTALL);
-
-	private DSLTree dslTree = new DSLTree();
-
 	public RuleCompletionProcessor(AbstractRuleEditor editor) {
 		super(editor);
 	}
 
-	protected List getCompletionProposals(ITextViewer viewer,
-			final int documentOffset) {
+	protected List getCompletionProposals(ITextViewer viewer, int documentOffset) {
 		try {
 			final List list = new ArrayList();
-			DSLAdapter adapter = getDSLAdapter(viewer);
 
 			IDocument doc = viewer.getDocument();
 			String backText = readBackwards(documentOffset, doc);
-
 			final String prefix = CompletionUtil.stripLastWord(backText);
 
 			if (backText.length() < 5) {
 				return list;
 			}
 
-			if (consequence(backText)) {
-				List dslConsequences = adapter.listConsequenceItems();
-				addDSLProposals(list, prefix, dslConsequences);
-				if (!adapter.hasConsequences()) {
-					// only add functions and keywords if at the beginning of a
-					// new statement
-					String backTextWithoutPrefix = backText.substring(0,
-							backText.length() - prefix.length());
-					if (START_OF_CONSEQUENCE.matcher(backTextWithoutPrefix)
-							.matches()
-							|| START_OF_NEW_JAVA_STATEMENT.matcher(
-									backTextWithoutPrefix).matches()) {
-						addRHSCompletionProposals(list, prefix);
-						addRHSFunctionCompletionProposals(viewer, list, prefix);
-					}
-					addRHSJavaCompletionProposals(list, backText, prefix);
-				}
-			} else if (condition(backText) || query(backText)) {
-				String lastobj = this.getLastNonDashLine(backText);
-				String last = this.getLastLine(backText);
-				// we have to check if the last line is when. if it is we set
-				// the last line to zero length string
-				if (last.equals("when")) {
-					last = "";
-					lastobj = "*";
-				}
-				// pass the last string in the backText to getProposals
-				List dslConditions = this.getProposals(lastobj, last);
-				// if we couldn't find any matches, we add the list from
-				// the DSLAdapter so that there's something
-				if (dslConditions.size() == 0) {
-					dslConditions.addAll(adapter.listConditionItems());
-				}
-				addDSLProposals(list, prefix, dslConditions);
-				addLHSCompletionProposals(viewer, list, adapter, prefix,
-						backText);
+			Location location = LocationDeterminator.getLocation(backText);
+			if (location.getType() == LocationDeterminator.LOCATION_RULE_HEADER) {
+				addRuleHeaderProposals(list, prefix, backText);
+			} else if (location.getType() == LocationDeterminator.LOCATION_RHS) {
+				addRHSCompletionProposals(list, prefix, backText,
+					(String) location.getProperty(LocationDeterminator.LOCATION_LHS_CONTENT),
+					(String) location.getProperty(LocationDeterminator.LOCATION_RHS_CONTENT));
 			} else {
-				// we are in rule header
-				addRuleHeaderItems(list, prefix);
+				addLHSCompletionProposals(list, location, prefix, backText);
 			}
 
 			filterProposalsOnPrefix(prefix, list);
@@ -139,296 +81,301 @@
 		}
 		return null;
 	}
+	
+	protected void addRHSCompletionProposals(List list, String prefix, String backText,
+			String conditions, String consequence) {
+		// only add functions and keywords if at the beginning of a
+		// new statement
+		String consequenceWithoutPrefix = consequence.substring(0,
+				consequence.length() - prefix.length());
+		if (isStartOfJavaExpression(consequenceWithoutPrefix)) {
+			addRHSKeywordCompletionProposals(list, prefix);
+			addRHSFunctionCompletionProposals(list, prefix);
+		}
+		addRHSJavaCompletionProposals(list, prefix, backText, conditions, consequence);
+	}
 
-	private void addLHSCompletionProposals(ITextViewer viewer, final List list,
-			DSLAdapter adapter, final String prefix, String backText)
-			throws CoreException, DroolsParserException {
-		Iterator iterator;
-		if (!adapter.hasConditions()) {
-			// determine location in condition
-			LocationDeterminator.Location location = LocationDeterminator
-					.getLocationInCondition(backText);
-
-			switch (location.getType()) {
-			case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION:
-				// if we are at the beginning of a new condition
-				// add drools keywords
-				list.add(new RuleCompletionProposal(prefix.length(), "and",
-						"and ", droolsIcon));
-				list.add(new RuleCompletionProposal(prefix.length(), "or",
-						"or ", droolsIcon));
-				list.add(new RuleCompletionProposal(prefix.length(), "from",
-						"from ", droolsIcon));
-				RuleCompletionProposal prop = new RuleCompletionProposal(prefix
-						.length(), "eval", "eval(  )", 6);
-				prop.setImage(droolsIcon);
-				list.add(prop);
-				prop = new RuleCompletionProposal(prefix.length(), "then",
-						"then" + System.getProperty("line.separator") + "\t");
-				prop.setImage(droolsIcon);
-				list.add(prop);
-				// we do not break but also add all elements that are needed for
-				// and/or
-			case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR:
-				list.add(new RuleCompletionProposal(prefix.length(), "not",
-						"not ", droolsIcon));
-				// we do not break but also add all elements that are needed for
-				// not
-			case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT:
-				list.add(new RuleCompletionProposal(prefix.length(), "exists",
-						"exists ", droolsIcon));
-				// we do not break but also add all elements that are needed for
-				// exists
-			case LocationDeterminator.LOCATION_FROM_ACCUMULATE:
-			case LocationDeterminator.LOCATION_FROM_COLLECT:
-			case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS:
-				// and add imported classes
-				List imports = getDRLEditor().getImports();
-				iterator = imports.iterator();
-				while (iterator.hasNext()) {
-					String name = (String) iterator.next();
-					int index = name.lastIndexOf(".");
-					if (index != -1) {
-						String className = name.substring(index + 1);
-						RuleCompletionProposal p = new RuleCompletionProposal(
-								prefix.length(), className, className + "(  )",
-								className.length() + 2);
-						p.setPriority(-1);
-						p.setImage(classIcon);
-						list.add(p);
-					}
+	protected void addLHSCompletionProposals(List list,
+			Location location, String prefix, String backText) {
+		switch (location.getType()) {
+		case LocationDeterminator.LOCATION_LHS_BEGIN_OF_CONDITION:
+			// if we are at the beginning of a new condition
+			// add drools keywords
+			list.add(new RuleCompletionProposal(prefix.length(), "and",
+					"and ", DROOLS_ICON));
+			list.add(new RuleCompletionProposal(prefix.length(), "or",
+					"or ", DROOLS_ICON));
+			list.add(new RuleCompletionProposal(prefix.length(), "from",
+					"from ", DROOLS_ICON));
+			RuleCompletionProposal prop = new RuleCompletionProposal(prefix
+					.length(), "eval", "eval(  )", 6);
+			prop.setImage(DROOLS_ICON);
+			list.add(prop);
+			prop = new RuleCompletionProposal(prefix.length(), "then",
+					"then" + System.getProperty("line.separator") + "\t");
+			prop.setImage(DROOLS_ICON);
+			list.add(prop);
+			// we do not break but also add all elements that are needed for
+			// and/or
+		case LocationDeterminator.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR:
+			list.add(new RuleCompletionProposal(prefix.length(), "not",
+					"not ", DROOLS_ICON));
+			// we do not break but also add all elements that are needed for
+			// not
+		case LocationDeterminator.LOCATION_LHS_BEGIN_OF_CONDITION_NOT:
+			list.add(new RuleCompletionProposal(prefix.length(), "exists",
+					"exists ", DROOLS_ICON));
+			// we do not break but also add all elements that are needed for
+			// exists
+		case LocationDeterminator.LOCATION_LHS_FROM_ACCUMULATE:
+		case LocationDeterminator.LOCATION_LHS_FROM_COLLECT:
+		case LocationDeterminator.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS:
+			// and add imported classes
+			List imports = getDRLEditor().getImports();
+			Iterator iterator = imports.iterator();
+			while (iterator.hasNext()) {
+				String name = (String) iterator.next();
+				int index = name.lastIndexOf(".");
+				if (index != -1) {
+					String className = name.substring(index + 1);
+					RuleCompletionProposal p = new RuleCompletionProposal(
+							prefix.length(), className, className + "(  )",
+							className.length() + 2);
+					p.setPriority(-1);
+					p.setImage(CLASS_ICON);
+					list.add(p);
 				}
-				List classesInPackage = getDRLEditor().getClassesInPackage();
-				iterator = classesInPackage.iterator();
-				while (iterator.hasNext()) {
-					String name = (String) iterator.next();
-					int index = name.lastIndexOf(".");
-					if (index != -1) {
-						String className = name.substring(index + 1);
-						RuleCompletionProposal p = new RuleCompletionProposal(
-								prefix.length(), className, className + "(  )",
-								className.length() + 2);
-						p.setPriority(-1);
-						p.setImage(classIcon);
-						list.add(p);
-					}
-				}
-				Set templates = getDRLEditor().getTemplates();
-				iterator = templates.iterator();
-				while (iterator.hasNext()) {
-					String name = (String) iterator.next();
+			}
+			List classesInPackage = getDRLEditor().getClassesInPackage();
+			iterator = classesInPackage.iterator();
+			while (iterator.hasNext()) {
+				String name = (String) iterator.next();
+				int index = name.lastIndexOf(".");
+				if (index != -1) {
+					String className = name.substring(index + 1);
 					RuleCompletionProposal p = new RuleCompletionProposal(
-							prefix.length(), name, name + "(  )",
-							name.length() + 2);
+							prefix.length(), className, className + "(  )",
+							className.length() + 2);
 					p.setPriority(-1);
-					p.setImage(classIcon);
+					p.setImage(CLASS_ICON);
 					list.add(p);
 				}
-				break;
-			case LocationDeterminator.LOCATION_INSIDE_CONDITION_START:
-				String className = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME);
-				if (className != null) {
-					boolean isTemplate = addFactTemplatePropertyProposals(
-							prefix, className, list);
-					if (!isTemplate) {
-						ClassTypeResolver resolver = new ClassTypeResolver(
-								getDRLEditor().getImports(), ProjectClassLoader
-										.getProjectClassLoader(getEditor()));
-						try {
-							Class clazz = resolver.resolveType(className);
-							if (clazz != null) {
-								Iterator iterator2 = new ClassFieldInspector(
-										clazz).getFieldNames().keySet()
-										.iterator();
-								while (iterator2.hasNext()) {
-									String name = (String) iterator2.next();
-									RuleCompletionProposal p = new RuleCompletionProposal(
-											prefix.length(), name, name + " ");
-									p.setImage(methodIcon);
-									list.add(p);
-								}
+			}
+			Set templates = getDRLEditor().getTemplates();
+			iterator = templates.iterator();
+			while (iterator.hasNext()) {
+				String name = (String) iterator.next();
+				RuleCompletionProposal p = new RuleCompletionProposal(
+						prefix.length(), name, name + "(  )",
+						name.length() + 2);
+				p.setPriority(-1);
+				p.setImage(CLASS_ICON);
+				list.add(p);
+			}
+			break;
+		case LocationDeterminator.LOCATION_LHS_INSIDE_CONDITION_START:
+			String className = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME);
+			if (className != null) {
+				boolean isTemplate = addFactTemplatePropertyProposals(
+						prefix, className, list);
+				if (!isTemplate) {
+					ClassTypeResolver resolver = new ClassTypeResolver(
+							getDRLEditor().getImports(), ProjectClassLoader
+									.getProjectClassLoader(getEditor()));
+					try {
+						Class clazz = resolver.resolveType(className);
+						if (clazz != null) {
+							Iterator iterator2 = new ClassFieldInspector(
+									clazz).getFieldNames().keySet()
+									.iterator();
+							while (iterator2.hasNext()) {
+								String name = (String) iterator2.next();
+								RuleCompletionProposal p = new RuleCompletionProposal(
+										prefix.length(), name, name + " ");
+								p.setImage(METHOD_ICON);
+								list.add(p);
 							}
-						} catch (IOException exc) {
-							// Do nothing
-						} catch (ClassNotFoundException exc) {
-							// Do nothing
 						}
+					} catch (IOException exc) {
+						// Do nothing
+					} catch (ClassNotFoundException exc) {
+						// Do nothing
 					}
 				}
-				break;
-			case LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR:
-				className = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME);
-				String property = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME);
-				String type = getPropertyClass(className, property);
+			}
+			break;
+		case LocationDeterminator.LOCATION_LHS_INSIDE_CONDITION_OPERATOR:
+			className = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME);
+			String property = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME);
+			String type = getPropertyClass(className, property);
 
-				list.add(new RuleCompletionProposal(prefix.length(), "==",
-						"== ", droolsIcon));
-				list.add(new RuleCompletionProposal(prefix.length(), "!=",
-						"!= ", droolsIcon));
-				list.add(new RuleCompletionProposal(prefix.length(), ":", ": ",
-						droolsIcon));
-				list.add(new RuleCompletionProposal(prefix.length(), "->",
-						"-> (  )", 5, droolsIcon));
+			list.add(new RuleCompletionProposal(prefix.length(), "==",
+					"== ", DROOLS_ICON));
+			list.add(new RuleCompletionProposal(prefix.length(), "!=",
+					"!= ", DROOLS_ICON));
+			list.add(new RuleCompletionProposal(prefix.length(), ":", ": ",
+					DROOLS_ICON));
+			list.add(new RuleCompletionProposal(prefix.length(), "->",
+					"-> (  )", 5, DROOLS_ICON));
 
-				if (isComparable(type)) {
-					list.add(new RuleCompletionProposal(prefix.length(), "<",
-							"< ", droolsIcon));
-					list.add(new RuleCompletionProposal(prefix.length(), "<=",
-							"<= ", droolsIcon));
-					list.add(new RuleCompletionProposal(prefix.length(), ">",
-							"> ", droolsIcon));
-					list.add(new RuleCompletionProposal(prefix.length(), ">=",
-							">= ", droolsIcon));
-				}
-				if (type.equals("java.lang.String")) {
-					list.add(new RuleCompletionProposal(prefix.length(),
-							"matches", "matches \"\"", 9, droolsIcon));
-				}
-				if (isSubtypeOf(type, "java.util.Collection")) {
-					list.add(new RuleCompletionProposal(prefix.length(),
-							"contains", "contains ", droolsIcon));
-					list.add(new RuleCompletionProposal(prefix.length(),
-							"excludes", "excludes ", droolsIcon));
-				}
-				break;
-			case LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT:
-				// determine type
-				className = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME);
-				property = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME);
-				String operator = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_OPERATOR);
-				type = getPropertyClass(className, property);
+			if (isComparable(type)) {
+				list.add(new RuleCompletionProposal(prefix.length(), "<",
+						"< ", DROOLS_ICON));
+				list.add(new RuleCompletionProposal(prefix.length(), "<=",
+						"<= ", DROOLS_ICON));
+				list.add(new RuleCompletionProposal(prefix.length(), ">",
+						"> ", DROOLS_ICON));
+				list.add(new RuleCompletionProposal(prefix.length(), ">=",
+						">= ", DROOLS_ICON));
+			}
+			if (type.equals("java.lang.String")) {
+				list.add(new RuleCompletionProposal(prefix.length(),
+						"matches", "matches \"\"", 9, DROOLS_ICON));
+			}
+			if (isSubtypeOf(type, "java.util.Collection")) {
+				list.add(new RuleCompletionProposal(prefix.length(),
+						"contains", "contains ", DROOLS_ICON));
+				list.add(new RuleCompletionProposal(prefix.length(),
+						"excludes", "excludes ", DROOLS_ICON));
+			}
+			break;
+		case LocationDeterminator.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT:
+			// determine type
+			className = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME);
+			property = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME);
+			String operator = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_OPERATOR);
+			type = getPropertyClass(className, property);
 
-				if ("contains".equals(operator) || "excludes".equals(operator)) {
-					type = "java.lang.Object";
-				}
+			if ("contains".equals(operator) || "excludes".equals(operator)) {
+				type = "java.lang.Object";
+			}
 
-				boolean isObject = false;
-				if ("java.lang.Object".equals(type)) {
-					isObject = true;
-				}
+			boolean isObject = false;
+			if ("java.lang.Object".equals(type)) {
+				isObject = true;
+			}
 
-				list.add(new RuleCompletionProposal(prefix.length(), "null",
-						"null ", droolsIcon));
-				if ("boolean".equals(type)) {
-					list.add(new RuleCompletionProposal(prefix.length(),
-							"true", "true ", droolsIcon));
-					list.add(new RuleCompletionProposal(prefix.length(),
-							"false", "false ", droolsIcon));
-				}
-				if (isObject || "java.lang.String".equals(type)) {
-					list.add(new RuleCompletionProposal(prefix.length(),
-							"\"\"", "\"\"", 1, droolsIcon));
-				}
-				if (isObject || "java.util.Date".equals(type)) {
-					list
-							.add(new RuleCompletionProposal(prefix.length(),
-									"\"dd-mmm-yyyy\"", "\"dd-mmm-yyyy\"", 1,
-									droolsIcon));
-				}
-				list.add(new RuleCompletionProposal(prefix.length(), "()",
-						"(  )", 2, droolsIcon));
-				DrlParser parser = new DrlParser();
-				try {
-					PackageDescr descr = parser.parse(backText);
-					List rules = descr.getRules();
-					if (rules != null && rules.size() == 1) {
-						Map result = new HashMap();
-						getRuleParameters(result, ((RuleDescr) rules.get(0))
-								.getLhs().getDescrs());
-						Iterator iterator2 = result.entrySet().iterator();
-						while (iterator2.hasNext()) {
-							Map.Entry entry = (Map.Entry) iterator2.next();
-							String paramName = (String) entry.getKey();
-							String paramType = (String) entry.getValue();
-							if (isSubtypeOf(paramType, type)) {
-								RuleCompletionProposal proposal = new RuleCompletionProposal(
-										prefix.length(), paramName);
-								proposal.setPriority(-1);
-								proposal.setImage(methodIcon);
-								list.add(proposal);
-							}
+			list.add(new RuleCompletionProposal(prefix.length(), "null",
+					"null ", DROOLS_ICON));
+			if ("boolean".equals(type)) {
+				list.add(new RuleCompletionProposal(prefix.length(),
+						"true", "true ", DROOLS_ICON));
+				list.add(new RuleCompletionProposal(prefix.length(),
+						"false", "false ", DROOLS_ICON));
+			}
+			if (isObject || "java.lang.String".equals(type)) {
+				list.add(new RuleCompletionProposal(prefix.length(),
+						"\"\"", "\"\"", 1, DROOLS_ICON));
+			}
+			if (isObject || "java.util.Date".equals(type)) {
+				list
+						.add(new RuleCompletionProposal(prefix.length(),
+								"\"dd-mmm-yyyy\"", "\"dd-mmm-yyyy\"", 1,
+								DROOLS_ICON));
+			}
+			list.add(new RuleCompletionProposal(prefix.length(), "()",
+					"(  )", 2, DROOLS_ICON));
+			DrlParser parser = new DrlParser();
+			try {
+				PackageDescr descr = parser.parse(backText);
+				List rules = descr.getRules();
+				if (rules != null && rules.size() == 1) {
+					Map result = new HashMap();
+					getRuleParameters(result, ((RuleDescr) rules.get(0))
+							.getLhs().getDescrs());
+					Iterator iterator2 = result.entrySet().iterator();
+					while (iterator2.hasNext()) {
+						Map.Entry entry = (Map.Entry) iterator2.next();
+						String paramName = (String) entry.getKey();
+						String paramType = (String) entry.getValue();
+						if (isSubtypeOf(paramType, type)) {
+							RuleCompletionProposal proposal = new RuleCompletionProposal(
+									prefix.length(), paramName);
+							proposal.setPriority(-1);
+							proposal.setImage(METHOD_ICON);
+							list.add(proposal);
 						}
 					}
-				} catch (DroolsParserException exc) {
-					// do nothing
 				}
-				break;
-			case LocationDeterminator.LOCATION_INSIDE_EVAL:
-				String content = (String) location
-						.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT);
-				list.addAll(getJavaCompletionProposals(content, prefix,
-						getRuleParameters(backText)));
-				break;
-			case LocationDeterminator.LOCATION_INSIDE_CONDITION_END:
-				list.add(new RuleCompletionProposal(prefix.length(), "&", "& ",
-						droolsIcon));
-				list.add(new RuleCompletionProposal(prefix.length(), "|", "| ",
-						droolsIcon));
-				list.add(new RuleCompletionProposal(prefix.length(), ",", ", ",
-						droolsIcon));
-				break;
-			case LocationDeterminator.LOCATION_FROM:
-				String fromText = (String) location
-						.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT);
-				int index = fromText.indexOf('.');
-				if (index == -1) {
-					// add accumulate and collect keyword
-					list
-							.add(new RuleCompletionProposal(
-									prefix.length(),
-									"accumulate",
-									"accumulate (  , init (  ), action (  ), result (  ) )",
-									13, droolsIcon));
-					list.add(new RuleCompletionProposal(prefix.length(),
-							"collect", "collect (  )", 10, droolsIcon));
-					// add all functions
-					if ("".equals(fromText)) {
-						List functions = getDRLEditor().getFunctions();
-						iterator = functions.iterator();
-						while (iterator.hasNext()) {
-							String name = (String) iterator.next() + "()";
-							prop = new RuleCompletionProposal(prefix.length(),
-									name, name, name.length() - 1);
-							prop.setPriority(-1);
-							prop.setImage(methodIcon);
-							list.add(prop);
-						}
+			} catch (DroolsParserException exc) {
+				// do nothing
+			}
+			break;
+		case LocationDeterminator.LOCATION_LHS_INSIDE_EVAL:
+			String content = (String) location
+					.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT);
+			list.addAll(getJavaCompletionProposals(content, prefix,
+					getRuleParameters(backText)));
+			break;
+		case LocationDeterminator.LOCATION_LHS_INSIDE_CONDITION_END:
+			list.add(new RuleCompletionProposal(prefix.length(), "&", "& ",
+					DROOLS_ICON));
+			list.add(new RuleCompletionProposal(prefix.length(), "|", "| ",
+					DROOLS_ICON));
+			list.add(new RuleCompletionProposal(prefix.length(), ",", ", ",
+					DROOLS_ICON));
+			break;
+		case LocationDeterminator.LOCATION_LHS_FROM:
+			String fromText = (String) location
+					.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT);
+			int index = fromText.indexOf('.');
+			if (index == -1) {
+				// add accumulate and collect keyword
+				list
+						.add(new RuleCompletionProposal(
+								prefix.length(),
+								"accumulate",
+								"accumulate (  , init (  ), action (  ), result (  ) )",
+								13, DROOLS_ICON));
+				list.add(new RuleCompletionProposal(prefix.length(),
+						"collect", "collect (  )", 10, DROOLS_ICON));
+				// add all functions
+				if ("".equals(fromText)) {
+					List functions = getDRLEditor().getFunctions();
+					iterator = functions.iterator();
+					while (iterator.hasNext()) {
+						String name = (String) iterator.next() + "()";
+						prop = new RuleCompletionProposal(prefix.length(),
+								name, name, name.length() - 1);
+						prop.setPriority(-1);
+						prop.setImage(METHOD_ICON);
+						list.add(prop);
 					}
-					list.addAll(getJavaCompletionProposals(fromText, prefix,
-							getRuleParameters(backText)));
 				}
-				break;
-			case LocationDeterminator.LOCATION_FROM_ACCUMULATE_INIT_INSIDE:
-				content = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
-				list.addAll(getJavaCompletionProposals(content, prefix,
+				list.addAll(getJavaCompletionProposals(fromText, prefix,
 						getRuleParameters(backText)));
-				break;
-			case LocationDeterminator.LOCATION_FROM_ACCUMULATE_ACTION_INSIDE:
-				content = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
-				content += (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
-				list.addAll(getJavaCompletionProposals(content, prefix,
-						getRuleParameters(backText)));
-				break;
-			case LocationDeterminator.LOCATION_FROM_ACCUMULATE_RESULT_INSIDE:
-				content = (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
-				content += (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
-				content += (String) location
-						.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT);
-				list.addAll(getJavaCompletionProposals(content, prefix,
-						getRuleParameters(backText)));
-				break;
 			}
+			break;
+		case LocationDeterminator.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE:
+			content = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
+			list.addAll(getJavaCompletionProposals(content, prefix,
+					getRuleParameters(backText)));
+			break;
+		case LocationDeterminator.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE:
+			content = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
+			content += (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
+			list.addAll(getJavaCompletionProposals(content, prefix,
+					getRuleParameters(backText)));
+			break;
+		case LocationDeterminator.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE:
+			content = (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
+			content += (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
+			content += (String) location
+					.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT);
+			list.addAll(getJavaCompletionProposals(content, prefix,
+					getRuleParameters(backText)));
+			break;
 		}
 	}
 
@@ -498,7 +445,7 @@
 		}
 		return result;
 	}
-
+	
 	private boolean isComparable(String type) {
 		if (type == null) {
 			return false;
@@ -590,34 +537,7 @@
 		return null;
 	}
 
-	private boolean consequence(String backText) {
-		return isKeywordOnLine(backText, "then");
-	}
-
-	private boolean condition(String backText) {
-		return isKeywordOnLine(backText, "when");
-	}
-
-	boolean query(String backText) {
-		return query.matcher(backText).matches();
-	}
-
-	/**
-	 * Check to see if the keyword appears on a line by itself.
-	 */
-	private boolean isKeywordOnLine(String chunk, String keyword) {
-		StringTokenizer st = new StringTokenizer(chunk, "\n\t");
-		while (st.hasMoreTokens()) {
-			if (st.nextToken().trim().equals(keyword)) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	private void addRHSFunctionCompletionProposals(ITextViewer viewer,
-			final List list, final String prefix) throws CoreException,
-			DroolsParserException {
+	private void addRHSFunctionCompletionProposals(List list, String prefix) {
 		Iterator iterator;
 		RuleCompletionProposal prop;
 		List functions = getDRLEditor().getFunctions();
@@ -627,37 +547,35 @@
 			prop = new RuleCompletionProposal(prefix.length(), name,
 					name + ";", name.length() - 1);
 			prop.setPriority(-1);
-			prop.setImage(methodIcon);
+			prop.setImage(METHOD_ICON);
 			list.add(prop);
 		}
 	}
 
-	private void addRHSCompletionProposals(final List list, final String prefix) {
+	private void addRHSKeywordCompletionProposals(
+			List list, String prefix) {
 		RuleCompletionProposal prop = new RuleCompletionProposal(prefix
 				.length(), "modify", "modify();", 7);
-		prop.setImage(droolsIcon);
+		prop.setImage(DROOLS_ICON);
 		list.add(prop);
 		prop = new RuleCompletionProposal(prefix.length(), "retract",
 				"retract();", 8);
-		prop.setImage(droolsIcon);
+		prop.setImage(DROOLS_ICON);
 		list.add(prop);
 		prop = new RuleCompletionProposal(prefix.length(), "assert",
 				"assert();", 7);
-		prop.setImage(droolsIcon);
+		prop.setImage(DROOLS_ICON);
 		list.add(prop);
 		prop = new RuleCompletionProposal(prefix.length(), "assertLogical",
 				"assertLogical();", 14);
-		prop.setImage(droolsIcon);
+		prop.setImage(DROOLS_ICON);
 		list.add(prop);
 	}
 
-	private void addRHSJavaCompletionProposals(List list, String backText,
-			String prefix) {
-		int thenPosition = backText.lastIndexOf("then");
-		String conditions = backText.substring(0, thenPosition);
-		String consequence = backText.substring(thenPosition + 4);
+	private void addRHSJavaCompletionProposals(List list, String prefix, String backText, 
+			String conditions, String consequence) {
 		list.addAll(getJavaCompletionProposals(consequence, prefix,
-				getRuleParameters(conditions)));
+				getRuleParameters(backText)));
 	}
 
 	private void getRuleParameters(Map result, List descrs) {
@@ -721,83 +639,33 @@
 		}
 	}
 
-	private void addRuleHeaderItems(final List list, final String prefix) {
+	private void addRuleHeaderProposals(List list, String prefix, String backText) {
 		list.add(new RuleCompletionProposal(prefix.length(), "salience",
-				"salience ", droolsIcon));
+				"salience ", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "no-loop",
-				"no-loop ", droolsIcon));
+				"no-loop ", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "agenda-group",
-				"agenda-group ", droolsIcon));
+				"agenda-group ", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "duration",
-				"duration ", droolsIcon));
+				"duration ", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "auto-focus",
-				"auto-focus ", droolsIcon));
+				"auto-focus ", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "when", "when"
-				+ System.getProperty("line.separator") + "\t ", droolsIcon));
+				+ System.getProperty("line.separator") + "\t ", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(),
-				"activation-group", "activation-group ", droolsIcon));
+				"activation-group", "activation-group ", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "date-effective",
-				"date-effective \"dd-MMM-yyyy\"", 16, droolsIcon));
+				"date-effective \"dd-MMM-yyyy\"", 16, DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "date-expires",
-				"date-expires \"dd-MMM-yyyy\"", 14, droolsIcon));
+				"date-expires \"dd-MMM-yyyy\"", 14, DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "enabled",
-				"enabled false", droolsIcon));
+				"enabled false", DROOLS_ICON));
 		list.add(new RuleCompletionProposal(prefix.length(), "ruleflow-group",
-				"ruleflow-group \"\"", 16, droolsIcon));
+				"ruleflow-group \"\"", 16, DROOLS_ICON));
         list.add(new RuleCompletionProposal(prefix.length(), "lock-on-active",
-                                            "lock-on-active ", droolsIcon));        
+                "lock-on-active ", DROOLS_ICON));        
 	}
 
-	private void addDSLProposals(final List list, final String prefix,
-			List dslItems) {
-		Iterator iterator = dslItems.iterator();
-		while (iterator.hasNext()) {
-			String consequence = (String) iterator.next();
-			RuleCompletionProposal p = new RuleCompletionProposal(prefix
-					.length(), consequence);
-			p.setImage(dslIcon);
-			list.add(p);
-		}
-	}
-
-	/**
-	 * Lazily get the adapter for DSLs, and cache it with the editor for future
-	 * reference. If it is unable to load a DSL, it will try again next time.
-	 * But once it has found and loaded one, it will keep it until the editor is
-	 * closed.
-	 * 
-	 * This delegates to DSLAdapter to poke around the project to try and load
-	 * the DSL.
-	 */
-	private DSLAdapter getDSLAdapter(ITextViewer viewer) {
-		// TODO: cache DSL adapter in plugin, and reset when dsl file saved
-		// retrieve dsl name always (might have changed) and try retrieving
-		// cached dsl from plugin first
-		// return new DSLAdapter(viewer.getDocument().get(), ((FileEditorInput)
-		// getEditor().getEditorInput()).getFile());
-		DSLAdapter adapter = getDRLEditor().getDSLAdapter();
-		if (adapter == null) {
-			String content = viewer.getDocument().get();
-			adapter = new DSLAdapter(content, ((FileEditorInput) getEditor()
-					.getEditorInput()).getFile());
-			if (adapter.isValid()) {
-				getDRLEditor().setDSLAdapter(adapter);
-			}
-			if (this.dslTree.isEmpty()) {
-				try {
-					Reader dslContents = DSLAdapter.getDSLContent(content,
-						((FileEditorInput) getEditor().getEditorInput()).getFile());
-					if (dslContents != null) {
-						this.dslTree.buildTree(dslContents);
-					}
-				} catch (CoreException e) {
-					DroolsEclipsePlugin.log(e);
-				}
-			}
-		}
-		return adapter;
-	}
-
 	private boolean addFactTemplatePropertyProposals(String prefix,
 			String templateName, List list) {
 		FactTemplateDescr descr = getDRLEditor().getTemplate(templateName);
@@ -810,97 +678,10 @@
 			String fieldName = field.getName();
 			RuleCompletionProposal p = new RuleCompletionProposal(prefix
 					.length(), fieldName, fieldName + " ");
-			p.setImage(methodIcon);
+			p.setImage(METHOD_ICON);
 			list.add(p);
 		}
 		return true;
 	}
 
-	/**
-	 * because of how the backText works, we need to get the last line, so that
-	 * we can pass it to the DSLUtility
-	 * 
-	 * @param backText
-	 * @return
-	 */
-	public String getLastLine(String backText) {
-		BufferedReader breader = new BufferedReader(new StringReader(backText));
-		String last = "";
-		String line = null;
-		try {
-			while ((line = breader.readLine()) != null) {
-				// only if the line has text do we set last to it
-				if (line.length() > 0) {
-					last = line;
-				}
-			}
-		} catch (IOException e) {
-			// TODO need to log this.
-			// I'm leaving this for mic_hat, so he has something to do
-		}
-		// now that all the conditions for a single object are on the same line
-		// we need to check for the left parenthesis
-		if (last.indexOf("(") > -1) {
-			last = last.substring(last.lastIndexOf("(") + 1);
-		}
-		// if the string has a comma "," we get the substring starting from
-		// the index after the last comma
-		if (last.indexOf(",") > -1) {
-			last = last.substring(last.lastIndexOf(",") + 1);
-		}
-		// if the line ends with right parenthesis, we change it to zero length
-		// string
-		if (last.endsWith(")")) {
-			last = "";
-		}
-		return last;
-	}
-
-	/**
-	 * Returns the last line that doesn't start with a dash
-	 * 
-	 * @param backText
-	 * @return
-	 */
-	public String getLastNonDashLine(String backText) {
-		BufferedReader breader = new BufferedReader(new StringReader(backText));
-		String last = "";
-		String line = null;
-		try {
-			while ((line = breader.readLine()) != null) {
-				// there may be blank lines, so we trim first
-				line = line.trim();
-				// only if the line has text do we set last to it
-				if (line.length() > 0 && !line.startsWith("-")) {
-					last = line;
-				}
-			}
-		} catch (IOException e) {
-			// TODO need to log this.
-			// I'm leaving this for mic_hat, so he has something to do
-		}
-		if (last.indexOf("(") > -1 && !last.endsWith(")")) {
-			last = last.substring(0, last.indexOf("("));
-		} else if (last.indexOf("(") > -1 && last.endsWith(")")) {
-			last = "";
-		}
-		return last;
-	}
-
-	/**
-	 * The DSLTree is configurable. It can either return just the child of the
-	 * last token found, or it can traverse the tree and generate all the
-	 * combinations beneath the last matching node. TODO I don't know how to add
-	 * configuration to the editor, so it needs to be hooked up to the
-	 * configuration for the editor later.
-	 * 
-	 * @param last
-	 * @return
-	 */
-	protected List getProposals(String obj, String last) {
-		if (last.length() == 0) {
-			last = " ";
-		}
-		return this.dslTree.getChildrenList(obj, last, false);
-	}
 }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -14,41 +14,40 @@
 /**
  * Break apart the rule source, very very simply.
  * 
- * The job of the partitioner is to identify if the cursor position is in a rule block, or not.
- * When in a rule block, the RuleCompletion processor will scan to work out a finer grain of context
- * (such as if it is in a condition, or consequence block).
+ * The job of the partitioner is to identify if the cursor position
+ * is in a rule block, or not.  Comments are also generated as a
+ * separate partition.
  * 
  * @author Michael Neale
  */
 public class DRLPartionScanner extends RuleBasedPartitionScanner {
 
-    
     public static final String RULE_PART_CONTENT = "__partition_rule_content";
     public static final String RULE_COMMENT = "__partition_multiline_comment";
     
-    
-    public static final String[] LEGAL_CONTENT_TYPES = {IDocument.DEFAULT_CONTENT_TYPE,  RULE_PART_CONTENT, RULE_COMMENT};
-    
-    
+    public static final String[] LEGAL_CONTENT_TYPES = {
+    	IDocument.DEFAULT_CONTENT_TYPE,
+    	RULE_PART_CONTENT,
+    	RULE_COMMENT
+    };
+        
     public DRLPartionScanner() {
-        super();
         initialise();
     }
     
     private void initialise() {
-
-        IToken rulePartition = new Token(RULE_PART_CONTENT);
-        IToken comment = new Token(RULE_COMMENT);
-        
         List rules = new ArrayList();
-        rules.add( new MultiLineRule("/*", "*/", comment, (char) 0, true));
-        rules.add(new MultiLineRule("\nrule", "\nend", rulePartition));
         
+        // rules
+        IToken rulePartition = new Token(RULE_PART_CONTENT);
+        rules.add(new MultiLineRule("\nrule", "\nend", rulePartition));
         //a query is really just a rule for most purposes.
         rules.add(new MultiLineRule("\nquery", "\nend", rulePartition));
+
+        // comments
+        IToken comment = new Token(RULE_COMMENT);
+        rules.add( new MultiLineRule("/*", "*/", comment, (char) 0, true));
         
-        IPredicateRule[] rulez = new IPredicateRule[rules.size()];
-        rules.toArray(rulez);
-        setPredicateRules(rulez);
+        setPredicateRules((IPredicateRule[]) rules.toArray(new IPredicateRule[rules.size()]));
     }
 }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java	2007-05-04 01:27:23 UTC (rev 11663)
@@ -26,25 +26,25 @@
  */
 public class DRLScanner extends RuleBasedScanner {
     
-	private static Color KEYWORD_COLOUR = ColorManager.getInstance().getColor(ColorManager.KEYWORD);
-	private static Color COMMENT_COLOR = ColorManager.getInstance().getColor(ColorManager.SINGLE_LINE_COMMENT);
-    private static Color STRING_COLOR = ColorManager.getInstance().getColor(ColorManager.STRING);
-    private static Color DEFAULT = ColorManager.getInstance().getColor(ColorManager.DEFAULT);
+	private static final Color KEYWORD_COLOR = ColorManager.getInstance().getColor(ColorManager.KEYWORD);
+	private static final Color COMMENT_COLOR = ColorManager.getInstance().getColor(ColorManager.SINGLE_LINE_COMMENT);
+    private static final Color STRING_COLOR = ColorManager.getInstance().getColor(ColorManager.STRING);
+    private static final Color DEFAULT_COLOR = ColorManager.getInstance().getColor(ColorManager.DEFAULT);
     
-    private static String[] fgDroolsKeywords= Keywords.getInstance().getAllDroolsKeywords();
-    private static String[] fgJavaKeywords= Keywords.getInstance().getAllJavaKeywords();
+    private static final String[] DROOLS_KEYWORDS = Keywords.getInstance().getAllDroolsKeywords();
+    private static final String[] JAVA_KEYWORDS = Keywords.getInstance().getAllJavaKeywords();
 
-    private static String[] fgTypes= { "void", "boolean", "char", "byte", "short", "strictfp", "int", "long", "float", "double" }; 
+    private static final String[] TYPES = { "void", "boolean", "char", "byte", "short", "strictfp", "int", "long", "float", "double" }; 
 
-    private static String[] fgConstants= { "false", "true", "null" }; 
+    private static final String[] CONSTANTS = { "false", "true", "null" }; 
     
 
 	public DRLScanner() {
         
-		IToken keyword = new Token(new TextAttribute(KEYWORD_COLOUR, null, SWT.BOLD));
+		IToken keyword = new Token(new TextAttribute(KEYWORD_COLOR, null, SWT.BOLD));
 		IToken comment= new Token(new TextAttribute(COMMENT_COLOR));
 		IToken string = new Token(new TextAttribute(STRING_COLOR));
-		IToken other = new Token(new TextAttribute(DEFAULT));
+		IToken other = new Token(new TextAttribute(DEFAULT_COLOR));
         
         List rules = new ArrayList();
 
@@ -63,14 +63,14 @@
 
         // Add word rule for keywords, types, and constants.
         WordRule wordRule= new WordRule(new RuleWordDetector(), other);
-        for (int i= 0; i < fgDroolsKeywords.length; i++)
-            wordRule.addWord(fgDroolsKeywords[i], keyword);
-        for (int i= 0; i < fgJavaKeywords.length; i++)
-            wordRule.addWord(fgJavaKeywords[i], keyword);
-        for (int i= 0; i < fgTypes.length; i++)
-            wordRule.addWord(fgTypes[i], keyword);
-        for (int i= 0; i < fgConstants.length; i++)
-            wordRule.addWord(fgConstants[i], keyword);
+        for (int i= 0; i < DROOLS_KEYWORDS.length; i++)
+            wordRule.addWord(DROOLS_KEYWORDS[i], keyword);
+        for (int i= 0; i < JAVA_KEYWORDS.length; i++)
+            wordRule.addWord(JAVA_KEYWORDS[i], keyword);
+        for (int i= 0; i < TYPES.length; i++)
+            wordRule.addWord(TYPES[i], keyword);
+        for (int i= 0; i < CONSTANTS.length; i++)
+            wordRule.addWord(CONSTANTS[i], keyword);
         rules.add(wordRule);        
         
         IRule[] result= new IRule[rules.size()];

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/wizard/project/RuleLauncherSample.java.template
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/wizard/project/RuleLauncherSample.java.template	2007-05-04 01:25:21 UTC (rev 11662)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/wizard/project/RuleLauncherSample.java.template	2007-05-04 01:27:23 UTC (rev 11663)
@@ -19,7 +19,7 @@
         	
         	//load up the rulebase
             RuleBase ruleBase = readRule();
-            WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+            WorkingMemory workingMemory = ruleBase.newStatefulSession();
             
             //go !
             Message message = new Message();




More information about the jboss-svn-commits mailing list