1 11 12 package org.eclipse.jdt.internal.corext.buildpath; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 21 import org.eclipse.jdt.core.IClasspathEntry; 22 import org.eclipse.jdt.core.IJavaElement; 23 import org.eclipse.jdt.core.IJavaProject; 24 import org.eclipse.jdt.core.IPackageFragmentRoot; 25 import org.eclipse.jdt.core.JavaModelException; 26 27 import org.eclipse.jdt.internal.corext.util.Messages; 28 29 import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; 30 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 31 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup; 32 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IRemoveLinkedFolderQuery; 33 34 41 public class RemoveFromClasspathOperation extends ClasspathModifierOperation { 42 43 54 public RemoveFromClasspathOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 55 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_RemoveFromCP_tooltip, IClasspathInformationProvider.REMOVE_FROM_BP); 56 } 57 58 65 public void run(IProgressMonitor monitor) throws InvocationTargetException { 66 List result= null; 67 fException= null; 68 try { 69 result= removeFromClasspath(fInformationProvider.getRemoveLinkedFolderQuery(), getSelectedElements(), fInformationProvider.getJavaProject(), monitor); 70 } catch (CoreException e) { 71 fException= e; 72 result= null; 73 } 74 super.handleResult(result, monitor); 75 } 76 77 91 public boolean isValid(List elements, int[] types) throws JavaModelException { 92 if (elements.size() == 0) 93 return false; 94 IJavaProject project= fInformationProvider.getJavaProject(); 95 Iterator iterator= elements.iterator(); 96 while (iterator.hasNext()) { 97 Object element= iterator.next(); 98 if (!(element instanceof IPackageFragmentRoot || element instanceof IJavaProject || element instanceof ClassPathContainer)) 99 return false; 100 if (element instanceof IJavaProject) { 101 if (!isSourceFolder(project)) 102 return false; 103 } else if (element instanceof IPackageFragmentRoot) { 104 IClasspathEntry entry= ((IPackageFragmentRoot) element).getRawClasspathEntry(); 105 if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { 106 return false; 107 } 108 } 109 } 110 return true; 111 } 112 113 114 115 127 public String getDescription(int type) { 128 IJavaElement elem= (IJavaElement)getSelectedElements().get(0); 129 String name= escapeSpecialChars(elem.getElementName()); 130 if (type == DialogPackageExplorerActionGroup.JAVA_PROJECT) 131 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ProjectFromBuildpath, name); 132 if (type == DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT_ROOT || type == DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT) 133 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_fromBuildpath, name); 134 return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_FromBuildpath; 135 } 136 } 137 | Popular Tags |