1 11 package org.eclipse.jdt.internal.corext.buildpath; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.IProgressMonitor; 19 20 import org.eclipse.core.resources.IResource; 21 22 import org.eclipse.jface.viewers.StructuredSelection; 23 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.newsourcepage.DialogPackageExplorerActionGroup; 29 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.CreateLocalSourceFolderAction; 30 31 public class CreateFolderOperation extends ClasspathModifierOperation { 32 33 private final IClasspathModifierListener fListener; 34 private final IClasspathInformationProvider fCPInformationProvider; 35 36 47 public CreateFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 48 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_AddLibCP_tooltip, IClasspathInformationProvider.CREATE_FOLDER); 49 fListener= listener; 50 fCPInformationProvider= informationProvider; 51 } 52 53 56 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 57 CreateLocalSourceFolderAction action= new CreateLocalSourceFolderAction(); 58 action.selectionChanged(new StructuredSelection(fCPInformationProvider.getJavaProject())); 59 action.run(); 60 IPackageFragmentRoot createdElement= (IPackageFragmentRoot)action.getCreatedElement(); 61 if (createdElement == null) { 62 return; 64 } 65 try { 66 IResource correspondingResource= createdElement.getCorrespondingResource(); 67 List result= new ArrayList (); 68 result.add(correspondingResource); 69 if (fListener != null) { 70 List entries= action.getCPListElements(); 71 fListener.classpathEntryChanged(entries); 72 } 73 fCPInformationProvider.handleResult(result, null, IClasspathInformationProvider.CREATE_FOLDER); 74 } catch (JavaModelException e) { 75 if (monitor == null) { 76 fCPInformationProvider.handleResult(Collections.EMPTY_LIST, e, IClasspathInformationProvider.CREATE_FOLDER); 77 } else { 78 throw new InvocationTargetException (e); 79 } 80 } 81 } 82 83 86 public boolean isValid(List elements, int[] types) throws JavaModelException { 87 return types.length == 1 && types[0] == DialogPackageExplorerActionGroup.JAVA_PROJECT; 88 } 89 90 93 public String getDescription(int type) { 94 return NewWizardMessages.PackageExplorerActionGroup_FormText_createNewSourceFolder; 95 } 96 } 97 | Popular Tags |