[jboss-svn-commits] JBL Code SVN: r23926 - in labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse: dsl/editor and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Nov 18 12:00:21 EST 2008


Author: KrisVerlaenen
Date: 2008-11-18 12:00:21 -0500 (Tue, 18 Nov 2008)
New Revision: 23926

Modified:
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DRLInfo.java
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/dsl/editor/DSLEditor.java
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/common/editor/GenericModelEditor.java
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/editor/RuleFlowModelEditor.java
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/editors/RuleEditor.java
   labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/ui/ConstraintValueEditor.java
Log:
JBRULES-1852: Support opening Guvnor resources
 - editor should now also support StringInput

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DRLInfo.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DRLInfo.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DRLInfo.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -31,7 +31,7 @@
 	private DialectCompiletimeRegistry dialectRegistry;
 
 	public DRLInfo(String sourcePathName, PackageDescr packageDescr, List<DroolsError> parserErrors, DialectCompiletimeRegistry dialectRegistry) {
-		if (sourcePathName == null || "".equals(sourcePathName)) {
+		if (sourcePathName == null) {
 			throw new IllegalArgumentException("Invalid sourcePathName " + sourcePathName);
 		}
 		this.sourcePathName = sourcePathName;

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/DroolsEclipsePlugin.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -363,7 +363,8 @@
             ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
             ClassLoader newLoader = DroolsBuilder.class.getClassLoader();
             String level = null;
-            if ( resource.getProject().getNature( "org.eclipse.jdt.core.javanature" ) != null ) {
+            // resource could be null when opening a read-only remote file 
+            if ( resource != null && resource.getProject().getNature( "org.eclipse.jdt.core.javanature" ) != null ) {
                 IJavaProject project = JavaCore.create( resource.getProject() );
                 newLoader = ProjectClassLoader.getProjectClassLoader( project );
                 level = project.getOption( JavaCore.COMPILER_COMPLIANCE,
@@ -381,7 +382,7 @@
                 // first parse the source
                 PackageDescr packageDescr = null;
                 List<DroolsError> parserErrors = null;
-                if ( useCache ) {
+                if ( useCache && resource != null) {
                     DRLInfo cachedDrlInfo = (DRLInfo) parsedRules.get( resource );
                     if ( cachedDrlInfo != null ) {
                         packageDescr = cachedDrlInfo.getPackageDescr();
@@ -400,9 +401,9 @@
                 PackageBuilder builder = new PackageBuilder( builder_configuration );
                 DRLInfo result = null;
                 // compile parsed rules if necessary
-                if ( compile && !parser.hasErrors() ) {
+                if ( compile && !parser.hasErrors()) {
                     // check whether a .package file exists and add it
-                    if ( resource.getParent() != null ) {
+                    if ( resource != null && resource.getParent() != null ) {
                         MyResourceVisitor visitor = new MyResourceVisitor();
                         resource.getParent().accept( visitor,
                                                      IResource.DEPTH_ONE,
@@ -416,23 +417,23 @@
 
                     builder.addPackage( packageDescr );
                                         
-                    result = new DRLInfo( resource.getProjectRelativePath().toString(),
+                    result = new DRLInfo( resource == null ? "" : resource.getProjectRelativePath().toString(),
                                           packageDescr,
                                           parserErrors,
                                           builder.getPackage(),
                                           builder.getErrors().getErrors(),
                                           builder.getPackageRegistry( builder.getDefaultNamespace() ).getDialectCompiletimeRegistry() );
                 } else {
-                    result = new DRLInfo( resource.getProjectRelativePath().toString(),
+                    result = new DRLInfo( resource == null ? "" : resource.getProjectRelativePath().toString(),
                                           packageDescr,
                                           parserErrors,
                                           new PackageRegistry(builder, new Package("")).getDialectCompiletimeRegistry() );
                 }
 
                 // cache result
-                if ( useCache ) {
+                if ( useCache && resource != null) {
                     if ( compile && !parser.hasErrors() ) {
-                        parsedRules.remove( resource );
+                    	parsedRules.remove( resource );
                         compiledRules.put( resource,
                                            result );
                         RuleInfo[] ruleInfos = result.getRuleInfos();

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/dsl/editor/DSLEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/dsl/editor/DSLEditor.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/dsl/editor/DSLEditor.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -42,6 +42,7 @@
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IStorageEditorInput;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.part.EditorPart;
 import org.eclipse.ui.part.FileEditorInput;
@@ -158,14 +159,21 @@
 
     public void init(IEditorSite site,
                      IEditorInput editorInput) throws PartInitException {
-        FileEditorInput input = (FileEditorInput) editorInput;
         setSite( site );
         setInput( editorInput );
-        setVisibleName( input );
+		setVisibleName( editorInput );
 
         try {
-            InputStream stream = input.getFile().getContents();
-            model = new NLGrammarModel();
+            InputStream stream = null;
+        	if (editorInput instanceof FileEditorInput) {
+        		FileEditorInput input = (FileEditorInput) editorInput;
+        		stream = input.getFile().getContents();
+        	} else if (editorInput instanceof IStorageEditorInput) {
+        		IStorageEditorInput input = (IStorageEditorInput) editorInput;
+        		stream = input.getStorage().getContents();
+        	}
+
+        	model = new NLGrammarModel();
             DSLMappingFile file = new DSLMappingFile();
             file.parseAndLoad( new InputStreamReader( stream ) );
             model.addEntries( file.getMapping().getEntries() );
@@ -179,9 +187,9 @@
 
     }
 
-    private void setVisibleName(FileEditorInput input) {
-        setPartName( input.getFile().getName() );
-        setContentDescription( "Editing Domain specific language: [" + input.getFile().getFullPath().toString() + "]" );
+    private void setVisibleName(IEditorInput input) {
+        setPartName( input.getName() );
+        setContentDescription( "Editing Domain specific language: [" + input.getName() + "]" );
     }
 
     public boolean isDirty() {

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/editors/AbstractRuleEditor.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -89,17 +89,19 @@
 	}
 	
 	public void updateFoldingStructure(List positions) {
-		Annotation[] annotations = new Annotation[positions.size()];
-		// this will hold the new annotations along
-		// with their corresponding positions
-		HashMap newAnnotations = new HashMap();
-		for (int i = 0; i < positions.size(); i++) {
-			ProjectionAnnotation annotation = new ProjectionAnnotation();
-			newAnnotations.put(annotation, positions.get(i));
-			annotations[i] = annotation;
+		if (annotationModel != null) {
+			Annotation[] annotations = new Annotation[positions.size()];
+			// this will hold the new annotations along
+			// with their corresponding positions
+			HashMap newAnnotations = new HashMap();
+			for (int i = 0; i < positions.size(); i++) {
+				ProjectionAnnotation annotation = new ProjectionAnnotation();
+				newAnnotations.put(annotation, positions.get(i));
+				annotations[i] = annotation;
+			}
+			annotationModel.modifyAnnotations(oldAnnotations, newAnnotations, null);
+			oldAnnotations = annotations;
 		}
-		annotationModel.modifyAnnotations(oldAnnotations, newAnnotations, null);
-		oldAnnotations = annotations;
 	}
 
 	/** For user triggered content assistance */

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/common/editor/GenericModelEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/common/editor/GenericModelEditor.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/common/editor/GenericModelEditor.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -17,8 +17,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -27,6 +25,7 @@
 import org.drools.eclipse.DroolsEclipsePlugin;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IStorage;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
@@ -66,6 +65,7 @@
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IStorageEditorInput;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.actions.ActionFactory;
 import org.eclipse.ui.actions.WorkspaceModifyOperation;
@@ -275,20 +275,38 @@
 	protected void setInput(IEditorInput input) {
 		super.setInput(input);
 
-		IFile file = getFile();
-		setPartName(file.getName());
-		try {
-			InputStream is = file.getContents(false);
-			createModel(is);
-		} catch (Throwable t) {
-			DroolsEclipsePlugin.log(t);
+		if (input instanceof IFileEditorInput) {
+			IFile file = getFile();
+			if (file != null) {
+				setPartName(file.getName());
+			}
+			try {
+				InputStream is = file.getContents(false);
+				createModel(is);
+			} catch (Throwable t) {
+				DroolsEclipsePlugin.log(t);
+			}
+		} else if (input instanceof IStorageEditorInput) {
+			try {
+				IStorage storage = ((IStorageEditorInput) input).getStorage();
+				setPartName(storage.getName());
+				InputStream is = storage.getContents();
+				createModel(is);
+			} catch (Throwable t) {
+				DroolsEclipsePlugin.log(t);
+			}
 		}
+		
 		if (getGraphicalViewer() != null) {
 			initializeGraphicalViewer();
 		}
 	}
 	
 	public IFile getFile() {
+		IEditorInput input = getEditorInput();
+		if (!(input instanceof IFileEditorInput)) {
+			return null;
+		}
 	    return ((IFileEditorInput) getEditorInput()).getFile();
 	}
 	

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/editor/RuleFlowModelEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/editor/RuleFlowModelEditor.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/editor/RuleFlowModelEditor.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -85,7 +85,9 @@
 
     protected void setInput(IEditorInput input) {
         super.setInput(input);
-        refreshPalette(((IFileEditorInput) input).getFile());
+        if (input instanceof IFileEditorInput) {
+        	refreshPalette(((IFileEditorInput) input).getFile());
+        }
     }
     
     private void refreshPalette(IFile file) {

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/editors/RuleEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/editors/RuleEditor.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/editors/RuleEditor.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -10,16 +10,16 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
-import org.drools.guvnor.server.rules.SuggestionCompletionLoader;
-import org.drools.guvnor.server.util.BRDRLPersistence;
-import org.drools.guvnor.server.util.BRXMLPersistence;
 import org.drools.compiler.DrlParser;
 import org.drools.eclipse.DroolsEclipsePlugin;
 import org.drools.eclipse.dsl.editor.DSLAdapter;
 import org.drools.eclipse.editors.DRLDocumentProvider;
 import org.drools.eclipse.editors.DRLRuleEditor;
 import org.drools.eclipse.util.ProjectClassLoader;
+import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
+import org.drools.guvnor.server.rules.SuggestionCompletionLoader;
+import org.drools.guvnor.server.util.BRDRLPersistence;
+import org.drools.guvnor.server.util.BRXMLPersistence;
 import org.drools.lang.dsl.DSLMappingFile;
 import org.eclipse.core.internal.resources.Container;
 import org.eclipse.core.resources.IFile;
@@ -121,34 +121,29 @@
 
             addPage( drlEditor,
                      xmlEditor.getEditorInput() );
-
-            IPath packagePath = getCurrentDirectoryPath( getEditorInput() ).append( "rule.package" );
-
-            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile( packagePath );
-
-            IJavaProject javaProject = JavaCore.create( file.getProject() );
-
-            ClassLoader classLoader = ProjectClassLoader.getProjectClassLoader( javaProject );
-
-            loader = new SuggestionCompletionLoader( classLoader );
-
-            if ( !file.exists() ) {
-                String defaultHeader = "//This is a package configuration file";
-                defaultHeader += "\n//Add imports, globals etc here which will be used by all the rule assets in this folder.";
-                InputStream is = new ByteArrayInputStream( defaultHeader.getBytes() );
-                try {
-                    file.create( is,
-                                 true,
-                                 null );
-                } catch ( CoreException e ) {
-                    DroolsEclipsePlugin.log( e );
-                }
+            IPath packagePath = getCurrentDirectoryPath( getEditorInput() );
+            if (packagePath != null) {
+            	packagePath = packagePath.append( "rule.package" );
+	            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile( packagePath );
+	            IJavaProject javaProject = JavaCore.create( file.getProject() );
+	            ClassLoader classLoader = ProjectClassLoader.getProjectClassLoader( javaProject );
+	            loader = new SuggestionCompletionLoader( classLoader );
+	            if ( !file.exists() ) {
+	                String defaultHeader = "//This is a package configuration file";
+	                defaultHeader += "\n//Add imports, globals etc here which will be used by all the rule assets in this folder.";
+	                InputStream is = new ByteArrayInputStream( defaultHeader.getBytes() );
+	                try {
+	                    file.create( is,
+	                                 true,
+	                                 null );
+	                } catch ( CoreException e ) {
+	                    DroolsEclipsePlugin.log( e );
+	                }
+	            }
+	            packageEditorInput = new FileEditorInput( file );
             }
-
-            packageEditorInput = new FileEditorInput( file );
-
             reloadCompletionEngine();
-
+	
             setPageText( 1,
                          "BRL Source" );
 
@@ -178,10 +173,21 @@
     }
 
     private IPath getCurrentDirectoryPath(IEditorInput editorInput) {
-        return ((FileEditorInput) editorInput).getFile().getFullPath().removeLastSegments( 1 ).addTrailingSeparator();
+    	if (editorInput instanceof FileEditorInput) {
+    		return ((FileEditorInput) editorInput).getFile().getFullPath().removeLastSegments( 1 ).addTrailingSeparator();
+    	}
+    	return null;
     }
 
     private void reloadCompletionEngine() {
+    	
+    	if (packageEditorInput == null) {
+    		completion = new SuggestionCompletionLoader( null ).getSuggestionEngine( "",
+                new ArrayList(),
+                new ArrayList() );
+    		return;
+    	}
+    	
         try {
 
             // Load all .dsl files from current dir

Modified: labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/ui/ConstraintValueEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/ui/ConstraintValueEditor.java	2008-11-18 15:33:31 UTC (rev 23925)
+++ labs/jbossrules/trunk/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/rulebuilder/ui/ConstraintValueEditor.java	2008-11-18 17:00:21 UTC (rev 23926)
@@ -40,7 +40,7 @@
 		this.toolkit = toolkit;
 		this.modeller = modeller;
 		
-		if (numericType.equals( SuggestionCompletionEngine.TYPE_NUMERIC )) {
+		if (SuggestionCompletionEngine.TYPE_NUMERIC.equals( numericType )) {
             this.numericValue = true;
         }
 		create();




More information about the jboss-svn-commits mailing list