1 11 12 package org.eclipse.jdt.internal.corext.buildpath; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.resources.IResource; 22 23 import org.eclipse.jdt.core.IJavaProject; 24 import org.eclipse.jdt.core.JavaModelException; 25 26 import org.eclipse.jdt.internal.corext.util.Messages; 27 28 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 29 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup; 30 31 32 39 public class UnexcludeOperation extends ClasspathModifierOperation { 40 41 52 public UnexcludeOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 53 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Unexclude_tooltip, IClasspathInformationProvider.UNEXCLUDE); 54 } 55 56 63 public void run(IProgressMonitor monitor) throws InvocationTargetException { 64 List result= null; 65 fException= null; 66 try { 67 List resources= getSelectedElements(); 68 IJavaProject project= fInformationProvider.getJavaProject(); 69 result= unExclude(resources, project, 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 for(int i= 0; i < elements.size(); i++) { 96 Object element= elements.get(i); 97 switch (types[i]) { 98 case DialogPackageExplorerActionGroup.FOLDER: if (!isValidFolder((IResource)element, project)) return false; break; 99 case DialogPackageExplorerActionGroup.EXCLUDED_FOLDER: if (!isValidExcludedFolder((IResource)element, project)) return false; break; 100 case DialogPackageExplorerActionGroup.EXCLUDED_FILE: if (!isValidExcludedFile((IFile)element, project)) return false; break; 101 default: return false; 102 } 103 } 104 return true; 105 } 106 107 116 private boolean isValidFolder(IResource resource, IJavaProject project) throws JavaModelException { 117 return ClasspathModifier.isExcluded(resource, project); 118 } 119 120 129 private boolean isValidExcludedFolder(IResource resource, IJavaProject project) throws JavaModelException { 130 return ClasspathModifier.isExcluded(resource, project); 131 } 132 133 142 private boolean isValidExcludedFile(IFile file, IJavaProject project) throws JavaModelException { 143 return ClasspathModifier.isExcluded(file, project); 144 } 145 146 158 public String getDescription(int type) { 159 IResource resource= (IResource) getSelectedElements().get(0); 160 String name= escapeSpecialChars(resource.getName()); 161 162 if (type == DialogPackageExplorerActionGroup.FOLDER) 163 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_UnexcludeFolder, name); 164 if (type == DialogPackageExplorerActionGroup.EXCLUDED_FILE) 165 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_UnexcludeFile, name); 166 167 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Unexclude, name); 168 } 169 } 170 | Popular Tags |