KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > reorg > DeleteAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /*
50      * @see SelectionDispatchAction#selectionChanged(IStructuredSelection)
51      */

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             //no ui here - this happens on selection changes
61
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
62
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     /* (non-Javadoc)
75      * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#run(org.eclipse.jface.viewers.IStructuredSelection)
76      */

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