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.IResource; 21 22 import org.eclipse.jdt.core.IJavaProject; 23 import org.eclipse.jdt.core.IPackageFragmentRoot; 24 import org.eclipse.jdt.core.JavaModelException; 25 26 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 27 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup; 28 29 30 37 public class IncludeOperation extends ClasspathModifierOperation { 38 39 50 public IncludeOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 51 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Include_tooltip, IClasspathInformationProvider.INCLUDE); 52 } 53 54 61 public void run(IProgressMonitor monitor) throws InvocationTargetException { 62 List result= null; 63 fException= null; 64 try { 65 List elements= getSelectedElements(); 66 IJavaProject project= fInformationProvider.getJavaProject(); 67 result= include(elements, project, monitor); 68 } catch (CoreException e) { 69 fException= e; 70 result= null; 71 } 72 super.handleResult(result, monitor); 73 } 74 75 89 public boolean isValid(List elements, int[] types) throws JavaModelException { 90 if (elements.size() == 0) 91 return false; 92 IJavaProject project= fInformationProvider.getJavaProject(); 93 for(int i= 0; i < elements.size(); i++) { 94 Object element= elements.get(i); 95 switch (types[i]) { 96 case DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT: break; case DialogPackageExplorerActionGroup.FOLDER: if (!isValidFolder((IResource)element, project)) return false; break; 98 case DialogPackageExplorerActionGroup.EXCLUDED_FOLDER: break; case DialogPackageExplorerActionGroup.EXCLUDED_FILE: break; case DialogPackageExplorerActionGroup.COMPILATION_UNIT: break; default: return false; } 103 104 } 105 return true; 106 } 107 108 117 private boolean isValidFolder(IResource resource, IJavaProject project) throws JavaModelException { 118 if (project.isOnClasspath(project) && resource.getProjectRelativePath().segmentCount() == 1) { 119 IPackageFragmentRoot root1= ClasspathModifier.getFragmentRoot(resource, project, null); 120 IPackageFragmentRoot root2= ClasspathModifier.getFragmentRoot(project.getResource(), project, null); 121 if (root1 != null && root1.equals(root2)) { 122 return true; 123 } 124 } 125 return false; 126 } 127 128 140 public String getDescription(int type) { 141 if (type == DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT) 142 return NewWizardMessages.PackageExplorerActionGroup_FormText_Include; 143 if (type == DialogPackageExplorerActionGroup.COMPILATION_UNIT) 144 return NewWizardMessages.PackageExplorerActionGroup_FormText_Include; 145 if (type == DialogPackageExplorerActionGroup.FOLDER) 146 return NewWizardMessages.PackageExplorerActionGroup_FormText_Include; 147 if (type == DialogPackageExplorerActionGroup.EXCLUDED_FOLDER) 148 return NewWizardMessages.PackageExplorerActionGroup_FormText_Include; 149 if (type == DialogPackageExplorerActionGroup.EXCLUDED_FILE) 150 return NewWizardMessages.PackageExplorerActionGroup_FormText_Include; 151 return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Include; 152 } 153 } 154 | Popular Tags |