[jboss-svn-commits] JBL Code SVN: r15432 - labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Sep 28 09:28:46 EDT 2007


Author: KrisVerlaenen
Date: 2007-09-28 09:28:46 -0400 (Fri, 28 Sep 2007)
New Revision: 15432

Added:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ImportCompletionProcessor.java
Modified:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java
Log:
JIRA-1217: RuleFlow Editor -> Constraint Editor -> Imports Editor context help
 - Code completion for imports added

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ImportCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ImportCompletionProcessor.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/ImportCompletionProcessor.java	2007-09-28 13:28:46 UTC (rev 15432)
@@ -0,0 +1,124 @@
+package org.drools.eclipse.flow.ruleflow.view.property.constraint;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.editors.completion.CompletionUtil;
+import org.drools.eclipse.editors.completion.DefaultCompletionProcessor;
+import org.drools.eclipse.editors.completion.RuleCompletionProposal;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Completion for ruleflow constraints. 
+ * 
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">Kris Verlaenen</a>
+ */
+public class ImportCompletionProcessor extends DefaultCompletionProcessor {
+
+	public ImportCompletionProcessor() {
+		super(null);
+	}
+	
+	public IEditorPart getEditor() {
+		IWorkbench workbench = PlatformUI.getWorkbench();
+		if (workbench != null) { 
+			IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+			if (workbenchWindow != null) {
+				IWorkbenchPage workbenchPage = workbenchWindow.getActivePage(); 
+				if (workbenchPage != null) {
+					return workbenchPage.getActiveEditor();
+				}
+			}
+		}
+		return null;
+	}
+
+    protected List getCompletionProposals(ITextViewer viewer,
+            int documentOffset) {
+		try {
+			IDocument doc = viewer.getDocument();
+			String backText = readBackwards(documentOffset, doc);
+
+			String prefix = CompletionUtil.stripLastWord(backText);
+
+			List props = null;
+			Matcher matcher = IMPORT_PATTERN.matcher(backText);
+			if (matcher.matches()) {
+				String classNameStart = backText.substring(backText
+						.lastIndexOf("import") + 7);
+				props = getAllClassProposals(classNameStart, documentOffset,
+						prefix);
+			} else {
+				props = getPossibleProposals(viewer, documentOffset, backText, prefix);
+			}
+			return props;
+		} catch (Throwable t) {
+			DroolsEclipsePlugin.log(t);
+		}
+		return null;
+	}
+
+    
+    public List getImports() {
+    	return Collections.EMPTY_LIST;
+    }
+    
+    public List getGlobals() {
+    	return Collections.EMPTY_LIST;
+    }
+    
+    protected IJavaProject getCurrentJavaProject() {
+    	IEditorPart editor = getEditor();
+    	if (editor != null && editor.getEditorInput() instanceof IFileEditorInput) {
+			IFile file = ((IFileEditorInput) editor.getEditorInput()).getFile();
+	    	try {
+	    		if (file.getProject().getNature("org.eclipse.jdt.core.javanature") != null) {
+	    			return JavaCore.create(file.getProject());
+	    		}
+	    	} catch (CoreException e) {
+	    		// do nothing
+	    	}
+		}
+    	return null;
+    }
+    
+    protected List getPossibleProposals(ITextViewer viewer,
+            int documentOffset,
+            String backText,
+            final String prefix) {
+		List list = new ArrayList();
+		list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "import", "import "));
+		DefaultCompletionProcessor.filterProposalsOnPrefix(prefix, list);
+		return list;
+	}
+}

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java	2007-09-28 13:28:29 UTC (rev 15431)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/constraint/RuleFlowImportsDialog.java	2007-09-28 13:28:46 UTC (rev 15432)
@@ -22,15 +22,22 @@
 import java.util.regex.Pattern;
 
 import org.drools.eclipse.editors.DRLSourceViewerConfig;
+import org.drools.eclipse.editors.scanners.DRLPartionScanner;
 import org.drools.ruleflow.core.RuleFlowProcess;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.text.Document;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
 import org.eclipse.jface.text.contentassist.IContentAssistant;
 import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.rules.FastPartitioner;
 import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jface.text.source.SourceViewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -78,11 +85,31 @@
 				return null;
 			}
 			public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
-				return null;
+				ContentAssistant assistant = new ContentAssistant();
+				IContentAssistProcessor completionProcessor = new ImportCompletionProcessor();
+				assistant.setContentAssistProcessor(
+					completionProcessor, IDocument.DEFAULT_CONTENT_TYPE);
+				assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
+				return assistant;
 			}
 		});
 		IDocument document = new Document(getProcessImports());
 		importsViewer.setDocument(document);
+		IDocumentPartitioner partitioner =
+            new FastPartitioner(
+                new DRLPartionScanner(),
+                DRLPartionScanner.LEGAL_CONTENT_TYPES);
+        partitioner.connect(document);
+        document.setDocumentPartitioner(partitioner);
+        importsViewer.getControl().addKeyListener(new KeyListener() {
+			public void keyPressed(KeyEvent e) {
+				if (e.character == ' ' && e.stateMask == SWT.CTRL) {
+					importsViewer.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
+				}
+			}
+			public void keyReleased(KeyEvent e) {
+			}
+        });
 		return importsViewer.getControl();
 	}
 	




More information about the jboss-svn-commits mailing list