1 11 package org.eclipse.jdt.internal.ui.refactoring.reorg; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.jface.action.IAction; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 17 import org.eclipse.ui.ISharedImages; 18 import org.eclipse.ui.IWorkbenchSite; 19 import org.eclipse.ui.actions.DeleteResourceAction; 20 import org.eclipse.ui.PlatformUI; 21 22 import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester; 23 import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter; 24 import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils; 25 import org.eclipse.jdt.internal.corext.util.JavaModelUtil; 26 27 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; 30 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 31 32 import org.eclipse.jdt.ui.actions.SelectionDispatchAction; 33 34 35 public class DeleteAction extends SelectionDispatchAction { 36 37 public DeleteAction(IWorkbenchSite site) { 38 super(site); 39 setText(ReorgMessages.DeleteAction_3); 40 setDescription(ReorgMessages.DeleteAction_4); 41 ISharedImages workbenchImages= JavaPlugin.getDefault().getWorkbench().getSharedImages(); 42 setDisabledImageDescriptor(workbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED)); 43 setImageDescriptor(workbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); 44 setHoverImageDescriptor(workbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); 45 46 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.DELETE_ACTION); 47 } 48 49 52 public void selectionChanged(IStructuredSelection selection) { 53 if (ReorgUtils.containsOnlyProjects(selection.toList())) { 54 setEnabled(createWorkbenchAction(selection).isEnabled()); 55 return; 56 } 57 try { 58 setEnabled(RefactoringAvailabilityTester.isDeleteAvailable(selection.toArray())); 59 } catch (CoreException e) { 60 if (JavaModelUtil.isExceptionToBeLogged(e)) 63 JavaPlugin.log(e); 64 setEnabled(false); 65 } 66 } 67 68 private IAction createWorkbenchAction(IStructuredSelection selection) { 69 DeleteResourceAction action= new DeleteResourceAction(getShell()); 70 action.selectionChanged(selection); 71 return action; 72 } 73 74 77 public void run(IStructuredSelection selection) { 78 if (ReorgUtils.containsOnlyProjects(selection.toList())) { 79 createWorkbenchAction(selection).run(); 80 return; 81 } 82 try { 83 RefactoringExecutionStarter.startDeleteRefactoring(selection.toArray(), getShell()); 84 } catch (CoreException e) { 85 ExceptionHandler.handle(e, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringMessages.OpenRefactoringWizardAction_exception); 86 } 87 } 88 } 89 | Popular Tags |