1 11 12 package org.eclipse.jdt.internal.corext.buildpath; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.ArrayList ; 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.ui.wizards.NewWizardMessages; 28 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement; 29 import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElementAttribute; 30 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IOutputLocationQuery; 31 32 37 public class EditOutputFolderOperation extends ClasspathModifierOperation { 38 39 private boolean fShowOutputFolders; 40 51 public EditOutputFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 52 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_EditOutput_tooltip, IClasspathInformationProvider.EDIT_OUTPUT); 53 fShowOutputFolders= false; 54 } 55 56 64 public void run(IProgressMonitor monitor) throws InvocationTargetException { 65 Object result= null; 66 fException= null; 67 try { 68 Object selection= getSelectedElements().get(0); 69 IJavaProject project= fInformationProvider.getJavaProject(); 70 CPListElement selElement; 71 if (selection instanceof IJavaElement) { 72 IJavaElement javaElement= (IJavaElement)selection; 73 IClasspathEntry entry= ClasspathModifier.getClasspathEntryFor(javaElement.getPath(), project, IClasspathEntry.CPE_SOURCE); 74 selElement= CPListElement.createFromExisting(entry, project); 75 } else { 76 selElement= ((CPListElementAttribute)selection).getParent(); 77 } 78 IOutputLocationQuery query= fInformationProvider.getOutputLocationQuery(); 79 result= editOutputFolder(selElement, project, query, monitor); 80 } catch (CoreException e) { 81 fException= e; 82 result= null; 83 } 84 List resultList= new ArrayList (); 85 if (result != null) 86 resultList.add(result); 87 super.handleResult(resultList, monitor); 88 } 89 90 104 public void showOutputFolders(boolean show) { 105 fShowOutputFolders= show; 106 } 107 108 122 public boolean isValid(List elements, int[] types) throws JavaModelException { 123 if (elements.size() != 1 || !fShowOutputFolders) 124 return false; 125 IJavaProject project= fInformationProvider.getJavaProject(); 126 Object element= elements.get(0); 127 128 if (element instanceof IJavaProject) { 129 if (!isSourceFolder(project)) 130 return false; 131 } else if (element instanceof IPackageFragmentRoot) { 132 return ((IPackageFragmentRoot)element).getKind() == IPackageFragmentRoot.K_SOURCE; 133 } 134 return element instanceof CPListElementAttribute; 135 } 136 137 147 public String getDescription(int type) { 148 return NewWizardMessages.PackageExplorerActionGroup_FormText_EditOutputFolder; 149 } 150 } 151 | Popular Tags |