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.IJavaProject; 25 import org.eclipse.jdt.core.IPackageFragmentRoot; 26 import org.eclipse.jdt.core.JavaModelException; 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.ILinkToQuery; 31 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.GenerateBuildPathActionGroup.CreateLinkedSourceFolderAction; 32 33 38 public class LinkedSourceFolderOperation extends ClasspathModifierOperation { 39 40 private IClasspathModifierListener fListener; 41 private IClasspathInformationProvider fCPInformationProvider; 42 43 54 public LinkedSourceFolderOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 55 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Link_tooltip, IClasspathInformationProvider.CREATE_LINK); 56 fListener= listener; 57 fCPInformationProvider= informationProvider; 58 } 59 60 68 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 69 CreateLinkedSourceFolderAction action= new CreateLinkedSourceFolderAction(); 70 action.selectionChanged(new StructuredSelection(fCPInformationProvider.getJavaProject())); 71 action.run(); 72 IPackageFragmentRoot createdElement= (IPackageFragmentRoot)action.getCreatedElement(); 73 if (createdElement == null) { 74 return; 76 } 77 try { 78 IResource correspondingResource= createdElement.getCorrespondingResource(); 79 List result= new ArrayList (); 80 result.add(correspondingResource); 81 if (fListener != null) { 82 List entries= action.getCPListElements(); 83 fListener.classpathEntryChanged(entries); 84 } 85 fCPInformationProvider.handleResult(result, null, IClasspathInformationProvider.CREATE_LINK); 86 } catch (JavaModelException e) { 87 if (monitor == null) { 88 fCPInformationProvider.handleResult(Collections.EMPTY_LIST, e, IClasspathInformationProvider.CREATE_LINK); 89 } else { 90 throw new InvocationTargetException (e); 91 } 92 } 93 } 94 95 108 public boolean isValid(List elements, int[] types) throws JavaModelException { 109 return types.length == 1 && types[0] == DialogPackageExplorerActionGroup.JAVA_PROJECT; 110 } 111 112 119 public String getDescription(int type) { 120 return NewWizardMessages.PackageExplorerActionGroup_FormText_createLinkedFolder; 121 } 122 123 } 124 | Popular Tags |