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.IJavaElement; 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 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.OutputFolderQuery; 31 32 33 40 public class AddSelectedSourceFolderOperation extends ClasspathModifierOperation { 41 42 53 public AddSelectedSourceFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 54 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_AddSelSFToCP_tooltip, IClasspathInformationProvider.ADD_SEL_SF_TO_BP); 55 } 56 57 65 public void run(IProgressMonitor monitor) throws InvocationTargetException { 66 List result= null; 67 fException= null; 68 try { 69 List elements= getSelectedElements(); 70 IJavaProject project= fInformationProvider.getJavaProject(); 71 OutputFolderQuery query= fInformationProvider.getOutputFolderQuery(); 72 result= addToClasspath(elements, project, query, monitor); 73 } catch (CoreException e) { 74 fException= e; 75 result= null; 76 } 77 super.handleResult(result, monitor); 78 } 79 80 94 public boolean isValid(List elements, int[] types) throws JavaModelException { 95 if (elements.size() == 0) 96 return false; 97 for (int i= 0; i < elements.size(); i++) { 98 Object object= elements.get(i); 99 switch (types[i]) { 100 case DialogPackageExplorerActionGroup.JAVA_PROJECT: if (isSourceFolder((IJavaProject) object)) return false; break; 101 case DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT: break; case DialogPackageExplorerActionGroup.INCLUDED_FOLDER: break; case DialogPackageExplorerActionGroup.FOLDER: break; case DialogPackageExplorerActionGroup.EXCLUDED_FOLDER: break; default: return false; } 107 108 } 109 return true; 110 } 111 112 124 public String getDescription(int type) { 125 Object obj= getSelectedElements().get(0); 126 if (obj instanceof IJavaElement) { 127 String name= escapeSpecialChars(((IJavaElement) obj).getElementName()); 128 if (type == DialogPackageExplorerActionGroup.JAVA_PROJECT) 129 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ProjectToBuildpath, name); 130 if (type == DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT) 131 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_PackageToBuildpath, name); 132 if (type == DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT) 133 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_PackageToBuildpath, name); 134 } else if (obj instanceof IResource) { 135 String name= escapeSpecialChars(((IResource) obj).getName()); 136 if (type == DialogPackageExplorerActionGroup.FOLDER) 137 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_FolderToBuildpath, name); 138 if (type == DialogPackageExplorerActionGroup.EXCLUDED_FOLDER) 139 return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_FolderToBuildpath, name); 140 } 141 return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_toBuildpath; 142 } 143 } 144 | Popular Tags |