ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r608392 - in /ant/ivy/ivyde/trunk: ./ src/java/org/apache/ivyde/eclipse/ src/java/org/apache/ivyde/eclipse/cpcontainer/ src/java/org/apache/ivyde/eclipse/ui/actions/ src/java/org/apache/ivyde/eclipse/ui/views/
Date Thu, 03 Jan 2008 09:36:41 GMT
Author: xavier
Date: Thu Jan  3 01:36:39 2008
New Revision: 608392

URL: http://svn.apache.org/viewvc?rev=608392&view=rev
Log:
FIX: IvyDE is using some internal classes of Eclipse (IVYDE-68) (thanks to Nicolas Lalevée)

Modified:
    ant/ivy/ivyde/trunk/CHANGES.txt
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
    ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java

Modified: ant/ivy/ivyde/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/CHANGES.txt?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/CHANGES.txt (original)
+++ ant/ivy/ivyde/trunk/CHANGES.txt Thu Jan  3 01:36:39 2008
@@ -10,6 +10,7 @@
 - IMPROVE: Support javadoc and sources even in modules where they are not declared (IVYDE-46)
 - IMPROVE: Simplify the resolve process (IVYDE-64) (thanks to Nicolas Lalevée) 
 
+- FIX: IvyDE is using some internal classes of Eclipse (IVYDE-68) (thanks to Nicolas Lalevée)

 - FIX: "Add Ivy library" not working in eclipse 3.3 (IVYDE-57)
 - FIX: Automatic javadoc attachment is not working (IVYDE-55)
 - FIX: On startup IvyIDE can freeze eclipse (IVYDE-63) (thanks to Nicolas Lalevée)

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/IvyPlugin.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/IvyPlugin.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/IvyPlugin.java (original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/IvyPlugin.java Thu Jan  3 01:36:39
2008
@@ -15,7 +15,6 @@
 import java.util.Set;
 
 import org.apache.ivy.Ivy;
-import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
@@ -25,14 +24,16 @@
 import org.apache.ivyde.eclipse.ui.preferences.PreferenceConstants;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.jdt.core.IJavaModel;
 import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.core.JavaModelManager;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.util.IPropertyChangeListener;
@@ -59,9 +60,10 @@
 	//Resource bundle.
 	private ResourceBundle resourceBundle;
     private IvyConsole console;
-    
-	
-	/**
+
+    private IJavaModel javaModel;
+
+    /**
 	 * The constructor.
 	 */
 	public IvyPlugin() {
@@ -93,6 +95,7 @@
                 }
             }
         });
+        javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
         log(IStatus.INFO, "IvyDE plugin started", null); 
 	}
 
@@ -209,7 +212,7 @@
     
 	public static void ivyConfPathChanged() {
         try {
-            IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
+            IJavaProject[] projects = plugin.javaModel.getJavaProjects();
             String defaultConfURL = getIvyconfURL();
             for (int i = 0; i < projects.length; i++) {
                 if (getStrictIvyconfURL(projects[i]) == null) {
@@ -222,7 +225,7 @@
 
     public static void typesChanged(String typesCode) {
         try {
-            IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
+            IJavaProject[] projects = plugin.javaModel.getJavaProjects();
             String defaultConfURL = getIvyconfURL();
             for (int i = 0; i < projects.length; i++) {
                 if ("[inherited]".equals(getTypesString(projects[i], typesCode))) {

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
(original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainer.java
Thu Jan  3 01:36:39 2008
@@ -466,8 +466,8 @@
             }
 
             if (url != null) {
-                result.add(new ClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
url
-                        .toExternalForm()));
+                result.add(JavaCore.newClasspathAttribute(
+                		IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, url.toExternalForm()));
             }
             return (IClasspathAttribute[]) result.toArray(new IClasspathAttribute[result.size()]);
         }

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
(original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathInitializer.java
Thu Jan  3 01:36:39 2008
@@ -1,6 +1,7 @@
 package org.apache.ivyde.eclipse.cpcontainer;
 
 
+import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.apache.ivyde.eclipse.cpcontainer.fragmentinfo.IPackageFragmentExtraInfo;
 import org.eclipse.core.runtime.CoreException;
@@ -89,7 +90,16 @@
             //force refresh of ivy classpath entry in ui thread 
             Display.getDefault().asyncExec(new Runnable() {
                 public void run() {
-                    IvyClasspathUtil.refreshContainer(project);
+                    IvyClasspathContainer ivycp;
+                    try {
+                        ivycp = IvyClasspathUtil.getIvyClassPathContainer(project);
+                    } catch (JavaModelException e) {
+                        Message.error(e.getMessage());
+                        return;
+                    }
+                    if (ivycp != null) {
+                        ivycp.refresh();
+                    }
                 }
             });
 	    }

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
(original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathUtil.java
Thu Jan  3 01:36:39 2008
@@ -2,15 +2,15 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathContainer;
 import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaElement;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.JavaModelException;
@@ -21,94 +21,116 @@
 import org.eclipse.ui.PlatformUI;
 
 public class IvyClasspathUtil {
-	/**
-	 * Adds an IvyDE classpath container to the list of existing classpath entries in the 
-	 * given project.
-	 * 
-	 * @param project 
-	 * 			the project to which the cp container should be added
-	 * @param projectRelativePath 
-	 * 			the path relative to the project of the module descriptor file
-	 * 			to use for the classpath container
-	 * @param confs 
-	 * 			the configurations to use in the classpath container.
-	 */
-	public static void addCPContainer(
-			IJavaProject project, IPath projectRelativePath, String confs) {
-		try {
-			IClasspathEntry newEntry = JavaCore.newContainerEntry(
-					new Path(IvyClasspathContainer.IVY_CLASSPATH_CONTAINER_ID)
-					.append(projectRelativePath)
-					.append(confs));
-			
-			IClasspathEntry[] entries= project.getRawClasspath();
-			
-			List newEntries = new ArrayList(Arrays.asList(entries));
-			newEntries.add(newEntry);
-			entries = (IClasspathEntry[]) newEntries
-					.toArray(new IClasspathEntry[newEntries.size()]);
-			
-			project.setRawClasspath(entries, project.getOutputLocation(), null);
-		} catch (CoreException e) {
-			IvyPlugin.getDefault().log(e);
-		}
-	}
-	
-    public static void refreshContainer() {
+
+    /**
+     * Adds an Ivy classpath container to the list of existing classpath
+     * entries in the given project.
+     * 
+     * @param project
+     *            the project to which the classpath container should be added
+     * @param projectRelativePath
+     *            the path relative to the project of the module descriptor file
+     *            to use for the classpath container
+     * @param confs
+     *            the configurations to use in the classpath container.
+     */
+    public static void addCPContainer(IJavaProject project, IPath projectRelativePath, String
confs) {
+        try {
+            IClasspathEntry newEntry = JavaCore.newContainerEntry(new Path(
+                    IvyClasspathContainer.IVY_CLASSPATH_CONTAINER_ID).append(projectRelativePath).append(confs));
+
+            IClasspathEntry[] entries = project.getRawClasspath();
+
+            List newEntries = new ArrayList(Arrays.asList(entries));
+            newEntries.add(newEntry);
+            entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
+
+            project.setRawClasspath(entries, project.getOutputLocation(), null);
+        } catch (CoreException e) {
+            IvyPlugin.log(e);
+        }
+    }
+
+    /**
+     * Get the current selection in the Java package view
+     * 
+     * @return the selection, <code>null</code> if unsuccessful
+     */
+    public static IStructuredSelection getSelectionInJavaPackageView() {
         IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if(activeWorkbenchWindow != null) {
+        if (activeWorkbenchWindow == null) {
+            return null;
+        }
             ISelection sel = activeWorkbenchWindow.getSelectionService().getSelection();
-            if(!(sel instanceof IStructuredSelection)) {
-            		sel = activeWorkbenchWindow.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer");
-            }
+        IStructuredSelection selection;
+        if (sel instanceof IStructuredSelection) {
+            selection = (IStructuredSelection) sel;
+        } else {
+            sel = activeWorkbenchWindow.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer");
             if (sel instanceof IStructuredSelection) {
-                IStructuredSelection s = (IStructuredSelection)sel;
-                try {
-                    IClasspathContainer fContainer= getClassPathContainer(s.getFirstElement());
-                    if (fContainer instanceof IvyClasspathContainer) {
-                        IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer;
-                        ivycp.refresh();
+                selection = (IStructuredSelection) sel;
+            } else {
+                return null;
+            }
+        } 
+        return selection;
+    }
+
+    /**
+     * Get the Ivy classpath container from the selection in the Java package view
+     * 
+     * @param selection the selection 
+     * @return
+     * @throws JavaModelException
+     */
+    public static IvyClasspathContainer getIvyClasspathContainer(IStructuredSelection selection)
throws JavaModelException {
+        if (selection == null) {
+            return null;
+        }
+        for (Iterator it = selection.iterator(); it.hasNext();) {
+            Object element = it.next();
+            IvyClasspathContainer cp = null;
+            if (element instanceof IvyClasspathContainer) {
+                return (IvyClasspathContainer) element;
+            }
+            if (element instanceof IJavaProject) {
+                return getIvyClassPathContainer((IJavaProject) element);
+            }
+            if (element instanceof IAdaptable) {
+                cp = (IvyClasspathContainer) ((IAdaptable) element).getAdapter(IvyClasspathContainer.class);
+                if (cp == null) {
+                    IJavaProject p = (IJavaProject) ((IAdaptable) element).getAdapter(IJavaProject.class);
+                    if (p != null) {
+                        cp = getIvyClassPathContainer(p);
                     }
-                } catch (JavaModelException e) {
-                    e.printStackTrace();
                 }
             }
+            if (cp != null) {
+                return cp;
+            }
+            if (element instanceof ClassPathContainer) {
+                // we shouldn't check against internal JDT API but there are not adaptable
to useful class
+                return getIvyClassPathContainer(((ClassPathContainer) element).getJavaProject());
+            }
         }
+        return null;
     }
-    public static void refreshContainer(IJavaProject project) {
-	    	IvyClasspathContainer ivycp;
-			try {
-				ivycp = (IvyClasspathContainer)getIvyClassPathContainer(project);
-				if(ivycp != null) {
-					ivycp.refresh();
-				}
-			} catch (JavaModelException e) {
-			}
-    }
-    
-    private static IClasspathContainer getClassPathContainer(Object o) throws JavaModelException
{
-        if (o instanceof ClassPathContainer) {
-            ClassPathContainer cp = (ClassPathContainer) o;
-            IJavaProject project = cp.getJavaProject();
-            return JavaCore.getClasspathContainer(cp.getClasspathEntry().getPath(), project);
-        }
-        if (o instanceof IJavaProject) {
-            return getIvyClassPathContainer((IJavaProject) o);
-        }
-        if (o instanceof IJavaElement) {
-            return getClassPathContainer(((IJavaElement) o).getParent());
+
+    /**
+     * Search the Ivy classpath container within the specified Java project
+     * 
+     * @param javaProject the project to search into
+     * @return the Ivy classpath container if found, otherwise return <code>null</code>
+     * @throws JavaModelException
+     */
+    public static IvyClasspathContainer getIvyClassPathContainer(IJavaProject javaProject)
throws JavaModelException {
+        IClasspathEntry[] cpe = javaProject.getRawClasspath();
+        for (int i = 0; i < cpe.length; i++) {
+            IClasspathEntry entry = cpe[i];
+            if (IvyClasspathContainer.isIvyClasspathContainer(entry.getPath())) {
+                return (IvyClasspathContainer) JavaCore.getClasspathContainer(entry.getPath(),
javaProject);
+            }
         }
         return null;
     }
-    
-	public  static IvyClasspathContainer getIvyClassPathContainer(IJavaProject javaProject)
throws JavaModelException {
-		IClasspathEntry[] cpe = javaProject.getRawClasspath();
-		for (int i = 0; i < cpe.length; i++) {
-		    IClasspathEntry entry = cpe[i];
-		    if (IvyClasspathContainer.isIvyClasspathContainer(entry.getPath())) {
-		        return (IvyClasspathContainer) JavaCore.getClasspathContainer(entry.getPath(),
javaProject);
-		    }
-		}
-		return null;
-	}
 }

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
(original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/cpcontainer/IvydeContainerPage.java
Thu Jan  3 01:36:39 2008
@@ -18,11 +18,12 @@
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator;
 import org.eclipse.jdt.ui.wizards.IClasspathContainerPage;
 import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension;
 import org.eclipse.jdt.ui.wizards.NewElementWizardPage;
@@ -49,6 +50,7 @@
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
 import org.eclipse.ui.model.WorkbenchContentProvider;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 import org.eclipse.ui.views.navigator.ResourceSorter;
@@ -162,9 +164,23 @@
         btn.addSelectionListener(new SelectionAdapter() {
             public void widgetSelected(SelectionEvent e) {
                 ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(Display.getDefault().getActiveShell(),
new WorkbenchLabelProvider(), new WorkbenchContentProvider());
-                Class[] acceptedClasses= new Class[] { IFile.class };
-                TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses,
true);
-                dialog.setValidator(validator);
+                dialog.setValidator(new ISelectionStatusValidator() {
+                    private final IStatus errorStatus = new Status(IStatus.ERROR, IvyPlugin.ID,
0, "", null); //$NON-NLS-1$
+
+                    public IStatus validate(Object[] selection) {
+                        if (selection.length == 0) {
+                            return errorStatus;
+                        }
+                        for (int i = 0; i < selection.length; i++) {
+                            Object o = selection[i];
+                            if (!(o instanceof IFile)) {
+                                return errorStatus;
+                            }
+                        }
+                        return Status.OK_STATUS;
+                    }
+
+                });
                 dialog.setTitle("choose ivy file"); 
                 dialog.setMessage("choose the ivy file to use to resolve dependencies");

                 dialog.setInput(_project.getProject());

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java
(original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/CreateContainerAction.java
Thu Jan  3 01:36:39 2008
@@ -1,30 +1,13 @@
 package org.apache.ivyde.eclipse.ui.actions;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.ivyde.eclipse.IvyPlugin;
-import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier;
-import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
-import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 import org.eclipse.ui.PlatformUI;

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java
(original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/OpenIvyFileAction.java
Thu Jan  3 01:36:39 2008
@@ -6,31 +6,24 @@
  */
 package org.apache.ivyde.eclipse.ui.actions;
 
-import java.io.File;
-
+import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
-import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
 import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.ide.IDE;
-import org.eclipse.ui.internal.WorkbenchPage;
-import org.eclipse.ui.internal.ide.DialogUtil;
-import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
 import org.eclipse.ui.part.FileEditorInput;
 
 
@@ -49,38 +42,43 @@
      * @see IWorkbenchWindowActionDelegate#run
      */
     public void run(IAction action) {
-        ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
-        if (sel instanceof IStructuredSelection) {
-            IStructuredSelection s = (IStructuredSelection)sel;
-            Object o = s.getFirstElement();
-            if (o instanceof ClassPathContainer) {
-                IPath path = ((ClassPathContainer)o).getClasspathEntry().getPath();
-                IJavaProject project = ((ClassPathContainer)o).getJavaProject();
+        IvyClasspathContainer cp;
+        try {
+            cp = IvyClasspathUtil.getIvyClasspathContainer(IvyClasspathUtil.getSelectionInJavaPackageView());
+        } catch (JavaModelException e) {
+            Message.error(e.getMessage());
+            return;
+        }
+        if (cp != null) {
+            IFile file = cp.getIvyFile();
+            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+            if (file != null) {
                 try {
-                    IClasspathContainer fContainer= JavaCore.getClasspathContainer(path,
project);
-                    if (fContainer instanceof IvyClasspathContainer) {
-                        IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer;
-                        
-                        IFile file = ivycp.getIvyFile();
-                        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-                        if (file != null) {
-                            try {
-                                String editorId = "org.apache.ivyde.editors.IvyEditor";
-                                page.openEditor(new FileEditorInput(file), editorId, true);
-                                // only remember the default editor if the open succeeds
-                                IDE.setDefaultEditor(file, editorId);
-                            } catch (PartInitException e) {
-                                DialogUtil.openError(page.getWorkbenchWindow().getShell(),
-                                        IDEWorkbenchMessages.OpenWithMenu_dialogTitle,
-                                        e.getMessage(), e);
-                            }
-                        }
+                    String editorId = "org.apache.ivyde.editors.IvyEditor";
+                    page.openEditor(new FileEditorInput(file), editorId, true);
+                    // only remember the default editor if the open succeeds
+                    IDE.setDefaultEditor(file, editorId);
+                } catch (PartInitException e) {
+                    Shell parent = page.getWorkbenchWindow().getShell();
+                    String title = "Problems Opening Editor";
+                    String message  = e.getMessage();
+                    // Check for a nested CoreException
+                    CoreException nestedException = null;
+                    IStatus status = e.getStatus();
+                    if (status != null && status.getException() instanceof CoreException)
{
+                        nestedException = (CoreException) status.getException();
+                    }
+                    if (nestedException != null) {
+                        // Open an error dialog and include the extra
+                        // status information from the nested CoreException
+                        ErrorDialog.openError(parent, title, message, nestedException
+                                .getStatus());
+                    } else {
+                        // Open a regular error dialog since there is no
+                        // extra information to display
+                        MessageDialog.openError(parent, title, message);
                     }
-                } catch (Exception e) {  
-                    // TODO : log exc
-                    System.err.println(e.getMessage());
                 }
-
             }
         }
     }

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java (original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/RefreshAction.java Thu
Jan  3 01:36:39 2008
@@ -1,20 +1,13 @@
 package org.apache.ivyde.eclipse.ui.actions;
 
+import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.jface.dialogs.MessageDialog;
 
 
 public class RefreshAction implements IWorkbenchWindowActionDelegate {
@@ -32,9 +25,17 @@
 	 * @see IWorkbenchWindowActionDelegate#run
 	 */
 	public void run(IAction action) {
-        IvyClasspathUtil.refreshContainer();
+	    IvyClasspathContainer cp;
+        try {
+            cp = IvyClasspathUtil.getIvyClasspathContainer(IvyClasspathUtil.getSelectionInJavaPackageView());
+        } catch (JavaModelException e) {
+            Message.error(e.getMessage());
+            return;
+        }
+	    if (cp != null) {
+	        cp.refresh();
+	    }
 	}
-
 
 	/**
 	 * Selection in the workbench has been changed. We 

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java (original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAction.java Thu
Jan  3 01:36:39 2008
@@ -1,19 +1,13 @@
 package org.apache.ivyde.eclipse.ui.actions;
 
+import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
 import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.jface.dialogs.MessageDialog;
 
 
 public class ResolveAction implements IWorkbenchWindowActionDelegate {
@@ -31,23 +25,15 @@
 	 * @see IWorkbenchWindowActionDelegate#run
 	 */
 	public void run(IAction action) {
-        ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
-        if (sel instanceof IStructuredSelection) {
-            IStructuredSelection s = (IStructuredSelection)sel;
-            Object o = s.getFirstElement();
-            if (o instanceof ClassPathContainer) {
-                IPath path = ((ClassPathContainer)o).getClasspathEntry().getPath();
-                IJavaProject project = ((ClassPathContainer)o).getJavaProject();
-                try {
-                    IClasspathContainer fContainer= JavaCore.getClasspathContainer(path,
project);
-                    if (fContainer instanceof IvyClasspathContainer) {
-                        IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer;
-                        ivycp.resolve();
-                    }
-                } catch (JavaModelException e) {                    
-                }
-
-            }
+        IvyClasspathContainer cp;
+        try {
+            cp = IvyClasspathUtil.getIvyClasspathContainer(IvyClasspathUtil.getSelectionInJavaPackageView());
+        } catch (JavaModelException e) {
+            Message.error(e.getMessage());
+            return;
+        }
+        if (cp != null) {
+            cp.resolve();
         }
 	}
 

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
(original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/actions/ResolveAllAction.java
Thu Jan  3 01:36:39 2008
@@ -34,7 +34,7 @@
             protected IStatus run(IProgressMonitor monitor) {
                 Collection containers = IvyPlugin.getDefault().getAllContainers();
                 monitor.beginTask("Resolve all dependencies", containers.size());
-                for (Iterator iter = IvyPlugin.getDefault().getAllContainers().iterator();
iter.hasNext();) {
+                for (Iterator iter = containers.iterator(); iter.hasNext();) {
                     if (monitor.isCanceled()) {
                         return Status.CANCEL_STATUS;
                     }

Modified: ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java?rev=608392&r1=608391&r2=608392&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java (original)
+++ ant/ivy/ivyde/trunk/src/java/org/apache/ivyde/eclipse/ui/views/ReportView.java Thu Jan
 3 01:36:39 2008
@@ -4,12 +4,8 @@
 
 import org.apache.ivy.util.Message;
 import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
 import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;
@@ -38,29 +34,24 @@
 
 	public void selectionChanged(IWorkbenchPart part, ISelection sel) {
         if (sel instanceof IStructuredSelection) {
-            IStructuredSelection s = (IStructuredSelection)sel;
-            Object o = s.getFirstElement();
-            if (o instanceof ClassPathContainer) {
-                IPath path = ((ClassPathContainer)o).getClasspathEntry().getPath();
-                IJavaProject project = ((ClassPathContainer)o).getJavaProject();
-                try {
-                    IClasspathContainer fContainer= JavaCore.getClasspathContainer(path,
project);
-                    if (fContainer instanceof IvyClasspathContainer) {
-                    	_browser.setUrl("");
-                        IvyClasspathContainer ivycp = (IvyClasspathContainer)fContainer;
-                        URL report = ivycp.getReportUrl();
-                        if (report != null) {
-                        	if (!_browser.setUrl(report.toExternalForm())) {
-                        		_browser.setUrl("");
-                        		Message.warn("impossible to set report view url to "+report.toExternalForm());
-                        	}
-                        }
+            IvyClasspathContainer ivycp;
+            try {
+                ivycp = IvyClasspathUtil.getIvyClasspathContainer((IStructuredSelection)
sel);
+            } catch (JavaModelException e) {
+                Message.error(e.getMessage());
+                return;
+            }
+            if (ivycp != null) {
+                _browser.setUrl("");
+                URL report = ivycp.getReportUrl();
+                if (report != null) {
+                    if (!_browser.setUrl(report.toExternalForm())) {
+                        _browser.setUrl("");
+                        Message.warn("impossible to set report view url to " + report.toExternalForm());
                     }
-                } catch (JavaModelException e) {                    
                 }
-
             }
         }
-	}
+    }
 
 }



Mime
View raw message