Author: ptahchiev
Date: Tue Mar 18 03:39:14 2008
New Revision: 638311

URL: http://svn.apache.org/viewvc?rev=638311&view=rev
Log:
Added the Cactus quickFix feature. See issue #187

Added:
    
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/
    
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/AddCactusClassesCompletionProposal.java
   (with props)
    
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/CactusQuickFixProcessor.java
   (with props)
Modified:
    
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/conf/plugin.xml
    
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactifyActionDelegate.java
    
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactusPlugin.java

Modified: 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/conf/plugin.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/conf/plugin.xml?rev=638311&r1=638310&r2=638311&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/conf/plugin.xml
 (original)
+++ 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/conf/plugin.xml
 Tue Mar 18 03:39:14 2008
@@ -161,6 +161,16 @@
       <extraClasspathEntry
             library="org.apache.cactus.eclipse.runner-1.8.0-SNAPSHOT-src.zip">
       </extraClasspathEntry>
+   </extension>
+   
+   <extension
+         id="org.apache.cactus.runner.quickfix"
+         name="CactusQuickFixProcessor"
+         point="org.eclipse.jdt.ui.quickFixProcessors">
+               <quickFixProcessor
+                   
class="org.apache.cactus.eclipse.quickfix.CactusQuickFixProcessor"
+                   
id="org.apache.cactus.eclipse.quickfix.CactusQuickFixProcessor">
+           </quickFixProcessor>
    </extension>
 
 </plugin>

Added: 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/AddCactusClassesCompletionProposal.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/AddCactusClassesCompletionProposal.java?rev=638311&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/AddCactusClassesCompletionProposal.java
 (added)
+++ 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/AddCactusClassesCompletionProposal.java
 Tue Mar 18 03:39:14 2008
@@ -0,0 +1,91 @@
+/* 
+ * ========================================================================
+ * 
+ * Copyright 2001-2003 The Apache Software Foundation.
+ *
+ * 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.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.eclipse.quickfix;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.cactus.eclipse.runner.ui.CactifyActionDelegate;
+import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+public class AddCactusClassesCompletionProposal  implements 
IJavaCompletionProposal  {
+
+       private final String name;
+       private final String proposalInfo;
+       private final int relevance;
+       private IJavaProject project;
+  
+       public AddCactusClassesCompletionProposal(
+                       String name,
+                       int relevance, 
+                       IJavaProject theWorkingProject) {
+               this.name = name;
+               this.relevance = relevance;
+               this.project = theWorkingProject;
+
+               final StringBuffer buffer = new StringBuffer(80);
+               buffer.append("Cactify this project ...<br>" +
+                                               "Add the Cactus jars to the 
classpath <br/>");
+               this.proposalInfo = buffer.toString();
+       }
+
+       public int getRelevance() {
+               return relevance;
+       }
+
+       public void apply(IDocument document) {
+               CactifyActionDelegate cactifyDelegate = new 
CactifyActionDelegate();
+               cactifyDelegate.setSelectedProject(project);
+               //We add null and empty string because CactifyActionDelegate 
does not need these.
+               cactifyDelegate.run(null);
+       }
+
+       public Point getSelection(IDocument document) {
+               return null;
+       }
+
+       public String getAdditionalProposalInfo() {
+               return proposalInfo;
+       }
+
+       public String getDisplayString() {
+               return name;
+       }
+
+       public Image getImage() {
+               return 
CactusPlugin.getDefault().getImageRegistry().get(CactusPlugin.CACTUS_RUN_IMAGE);
+       }
+
+       public IContextInformation getContextInformation() {
+               return null;
+       }
+  
+       public IJavaCompletionProposal createTypeProposal() {
+               return null;
+       }
+}
+

Propchange: 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/AddCactusClassesCompletionProposal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/CactusQuickFixProcessor.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/CactusQuickFixProcessor.java?rev=638311&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/CactusQuickFixProcessor.java
 (added)
+++ 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/CactusQuickFixProcessor.java
 Tue Mar 18 03:39:14 2008
@@ -0,0 +1,107 @@
+/* 
+ * ========================================================================
+ * 
+ * Copyright 2001-2003 The Apache Software Foundation.
+ *
+ * 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.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.eclipse.quickfix;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.text.java.IInvocationContext;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jdt.ui.text.java.IProblemLocation;
+import org.eclipse.jdt.ui.text.java.IQuickFixProcessor;
+
+public class CactusQuickFixProcessor implements IQuickFixProcessor {
+
+       private static final int IMPORT_NOT_FOUND = 268435846;
+       
+       private static final int IS_CLASSPATH_CORRECT = 16777218;
+       
+       private static final int UNDEFINED_TYPE = 16777218;
+
+       public boolean hasCorrections(final ICompilationUnit unit, final int 
problemId) {
+               if (problemId == 1000) {
+                       return true;
+               }
+               return false;
+       }
+
+       public IJavaCompletionProposal[] getCorrections(
+                       final IInvocationContext context,
+                       final IProblemLocation[] locations) throws 
CoreException {
+               if (locations == null || locations.length == 0) {
+                       return null;
+               }
+               final ArrayList resultingCollections = new ArrayList();
+               for (int i=0;i< locations.length;i++) {
+                       IProblemLocation problemLocation = (IProblemLocation) 
locations[i];
+                       process(context, problemLocation, resultingCollections);
+               }
+               IJavaCompletionProposal[] proposals = new 
IJavaCompletionProposal[resultingCollections.size()];
+    
+               for(int i=0;i<resultingCollections.size();i++) {
+                       proposals[i] = (IJavaCompletionProposal) 
resultingCollections.get(i);
+               }
+               return proposals;
+       }
+
+       private void process(
+                       final IInvocationContext context,
+                       final IProblemLocation problem,
+                       final ArrayList proposals) {
+               if (problem.getProblemId() == 0) { // no proposals for 
none-problem locations
+                       return;
+               }
+               
+           final String source;
+           try {
+             source = context.getCompilationUnit().getSource();
+           }
+           catch (final JavaModelException e) {
+             //ignore
+             return;
+           }
+           final int offset = problem.getOffset();
+           final int length = problem.getLength();
+
+           final String substring = source.substring(offset, offset + length);
+           
+           
+           
+           IJavaProject theWorkingProject = 
context.getCompilationUnit().getJavaProject();
+           
+           boolean cactusProblem = (problem.getProblemId() == IMPORT_NOT_FOUND 
&& substring.startsWith("org.apache.cactus")) ||
+                                                       (problem.getProblemId() 
== IS_CLASSPATH_CORRECT && isCactusPrefixesMatch(substring));
+           
+               if(cactusProblem) {
+                       final String name = "Cactify this project...";
+                       proposals.add(new 
AddCactusClassesCompletionProposal(name, 1, theWorkingProject));
+               }
+       }
+       
+       private boolean isCactusPrefixesMatch(String prefix) {
+               return (prefix.startsWith("ServletTestCase") || 
+                               prefix.startsWith("JspTestCase") || 
+                               prefix.startsWith("EJBTestCase") || 
+                               prefix.startsWith("JettyTestSetup"));
+       }
+}
\ No newline at end of file

Propchange: 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/quickfix/CactusQuickFixProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactifyActionDelegate.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactifyActionDelegate.java?rev=638311&r1=638310&r2=638311&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactifyActionDelegate.java
 (original)
+++ 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactifyActionDelegate.java
 Tue Mar 18 03:39:14 2008
@@ -66,15 +66,15 @@
      */
     public void run(IAction theAction)
     {
-        if (part != null && selectedProject != null)
+        if (selectedProject != null)
         {
             CactusPlugin thePlugin = CactusPlugin.getDefault();
                                File commonLibDir = null;
                                File clientLibDir = null;
 
             try {
-                                       commonLibDir = new 
File(Platform.asLocalURL(thePlugin.getBundle().getEntry("/" 
+CactusPlugin.CACTUS_LIBRARY_PATH +"/" 
+CactusPlugin.CACTUS_COMMON_LIBRARY_PATH)).getPath());
-                                       clientLibDir = new 
File(Platform.asLocalURL(thePlugin.getBundle().getEntry("/" 
+CactusPlugin.CACTUS_LIBRARY_PATH +"/" 
+CactusPlugin.CACTUS_CLIENT_LIBRARY_PATH)).getPath());
+                               commonLibDir = new 
File(Platform.asLocalURL(thePlugin.getBundle().getEntry("/" 
+CactusPlugin.CACTUS_LIBRARY_PATH +"/" 
+CactusPlugin.CACTUS_COMMON_LIBRARY_PATH)).getPath());
+                               clientLibDir = new 
File(Platform.asLocalURL(thePlugin.getBundle().getEntry("/" 
+CactusPlugin.CACTUS_LIBRARY_PATH +"/" 
+CactusPlugin.CACTUS_CLIENT_LIBRARY_PATH)).getPath());
             } catch (Exception ex) {
                CactusPlugin.log(ex);
             }
@@ -200,4 +200,8 @@
         return (IClasspathEntry[]) result.toArray(
             new IClasspathEntry[result.size()]);
     }
+
+       public void setSelectedProject(IJavaProject selectedProject) {
+               this.selectedProject = selectedProject;
+       }
 }

Modified: 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactusPlugin.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactusPlugin.java?rev=638311&r1=638310&r2=638311&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactusPlugin.java
 (original)
+++ 
jakarta/cactus/trunk/integration/eclipse/org.apache.cactus.eclipse.runner/src/main/java/org/apache/cactus/eclipse/runner/ui/CactusPlugin.java
 Tue Mar 18 03:39:14 2008
@@ -21,6 +21,7 @@
 
 import java.io.File;
 import java.io.FilenameFilter;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Vector;
 
@@ -34,6 +35,8 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IWorkbench;
@@ -87,6 +90,8 @@
      * Name of the client libraries folder
      */
     public static final String CACTUS_CLIENT_LIBRARY_PATH = "client";
+
+       public static final String CACTUS_RUN_IMAGE = "cactus.run.image";
     
     
 
@@ -388,5 +393,22 @@
         }
         return (String[]) containers.toArray(new String[containers.size()]);
     }
+    
+    
+    protected ImageRegistry createImageRegistry() {
+           final ImageRegistry registry = super.createImageRegistry();
+           
+               URL url = null;
+               try {
+                       url = new 
URL(CactusPlugin.getDefault().getDescriptor().getInstallURL(),"icons/calaunch.gif");
+               } catch (MalformedURLException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+           //ImageDescriptor imageDescriptor = 
ImageDescriptor.createFromURL(CactusPlugin
+           //    .getDefault().getBundle().getResource("icons/calaunch.gif"));
+           registry.put(CACTUS_RUN_IMAGE, ImageDescriptor.createFromURL(url));
+           return registry;
+       }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to