01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.dso.views;
06:
07: import org.eclipse.jdt.internal.ui.util.SelectionUtil;
08: import org.eclipse.jface.action.Action;
09: import org.eclipse.jface.viewers.ISelection;
10: import org.eclipse.jface.viewers.ISelectionProvider;
11: import org.terracotta.dso.TcPlugin;
12:
13: import java.util.List;
14:
15: public class DeleteAction extends Action {
16: private ConfigViewPart fPart;
17:
18: public DeleteAction(ConfigViewPart part) {
19: fPart = part;
20: setText("Delete");
21: setToolTipText("Delete");
22:
23: String iconPath = "images/eclipse/delete_edit.gif";
24: setImageDescriptor(TcPlugin.getImageDescriptor(iconPath));
25: }
26:
27: public boolean canActionBeAdded() {
28: List list = SelectionUtil.toList(getSelection());
29:
30: if (list != null && list.size() > 0) {
31: for (int i = 0; i < list.size(); i++) {
32: Object element = list.get(i);
33:
34: if (element instanceof RootWrapper
35: || element instanceof NamedLockWrapper
36: || element instanceof AutolockWrapper
37: || element instanceof BootClassWrapper
38: || element instanceof TransientFieldWrapper
39: || element instanceof DistributedMethodWrapper
40: || element instanceof IncludeWrapper
41: || element instanceof ExcludeWrapper) {
42: continue;
43: } else {
44: return false;
45: }
46: }
47: }
48:
49: return list != null;
50: }
51:
52: private ISelection getSelection() {
53: ISelectionProvider provider = fPart.getSite()
54: .getSelectionProvider();
55:
56: if (provider != null) {
57: return provider.getSelection();
58: }
59:
60: return null;
61: }
62:
63: public void run() {
64: fPart.removeSelectedItem();
65: }
66: }
|