1 5 package org.terracotta.dso.views; 6 7 import org.eclipse.jdt.internal.ui.util.SelectionUtil; 8 import org.eclipse.jface.action.Action; 9 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().getSelectionProvider(); 54 55 if(provider != null) { 56 return provider.getSelection(); 57 } 58 59 return null; 60 } 61 62 public void run() { 63 fPart.removeSelectedItem(); 64 } 65 } 66 | Popular Tags |