1 11 package org.eclipse.jdt.internal.ui.refactoring.reorg; 12 13 import java.util.List ; 14 15 import org.eclipse.core.resources.IResource; 16 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 19 import org.eclipse.ui.IWorkbenchSite; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.actions.CopyProjectAction; 22 23 import org.eclipse.jdt.core.IJavaElement; 24 import org.eclipse.jdt.core.JavaModelException; 25 26 import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester; 27 import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter; 28 import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils; 29 import org.eclipse.jdt.internal.corext.util.JavaModelUtil; 30 31 import org.eclipse.jdt.ui.actions.SelectionDispatchAction; 32 33 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 34 import org.eclipse.jdt.internal.ui.JavaPlugin; 35 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; 36 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 37 38 39 public class ReorgCopyAction extends SelectionDispatchAction { 40 41 public ReorgCopyAction(IWorkbenchSite site) { 42 super(site); 43 setText(ReorgMessages.ReorgCopyAction_3); 44 setDescription(ReorgMessages.ReorgCopyAction_4); 45 46 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.COPY_ACTION); 47 } 48 49 public void selectionChanged(IStructuredSelection selection) { 50 if (!selection.isEmpty()) { 51 if (ReorgUtils.containsOnlyProjects(selection.toList())) { 52 setEnabled(createWorkbenchAction(selection).isEnabled()); 53 return; 54 } 55 try { 56 List elements= selection.toList(); 57 IResource[] resources= ReorgUtils.getResources(elements); 58 IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements); 59 if (elements.size() != resources.length + javaElements.length) 60 setEnabled(false); 61 else 62 setEnabled(RefactoringAvailabilityTester.isCopyAvailable(resources, javaElements)); 63 } catch (JavaModelException e) { 64 if (JavaModelUtil.isExceptionToBeLogged(e)) 67 JavaPlugin.log(e); 68 setEnabled(false); 69 } 70 } else 71 setEnabled(false); 72 } 73 74 private CopyProjectAction createWorkbenchAction(IStructuredSelection selection) { 75 CopyProjectAction action= new CopyProjectAction(getShell()); 76 action.selectionChanged(selection); 77 return action; 78 } 79 80 public void run(IStructuredSelection selection) { 81 if (ReorgUtils.containsOnlyProjects(selection.toList())){ 82 createWorkbenchAction(selection).run(); 83 return; 84 } 85 try { 86 List elements= selection.toList(); 87 IResource[] resources= ReorgUtils.getResources(elements); 88 IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements); 89 if (RefactoringAvailabilityTester.isCopyAvailable(resources, javaElements)) 90 RefactoringExecutionStarter.startCopyRefactoring(resources, javaElements, getShell()); 91 } catch (JavaModelException e) { 92 ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); 93 } 94 } 95 } 96 | Popular Tags |