| 1 4 package org.terracotta.dso.views; 5 6 import org.eclipse.jdt.internal.ui.util.SelectionUtil; 7 import org.eclipse.jface.action.Action; 8 import org.eclipse.jface.viewers.ISelection; 9 import org.eclipse.jface.viewers.ISelectionProvider; 10 import org.eclipse.ui.actions.ActionContext; 11 12 public class HonorTransientAction extends Action { 13 ConfigViewPart fPart; 14 15 HonorTransientAction(ConfigViewPart part) { 16 super("Honor transient", AS_CHECK_BOX); 17 fPart = part; 18 } 19 20 public void run() { 21 fPart.setHonorTransient(isChecked()); 22 } 23 24 public void setContext(ActionContext context) { 25 Object element = SelectionUtil.getSingleElement(getSelection()); 26 27 if(element instanceof IncludeWrapper) { 28 IncludeWrapper wrapper = (IncludeWrapper)element; 29 setChecked(wrapper.getHonorTransient()); 30 } 31 } 32 33 public boolean canActionBeAdded() { 34 Object element = SelectionUtil.getSingleElement(getSelection()); 35 return element instanceof IncludeWrapper; 36 } 37 38 private ISelection getSelection() { 39 ISelectionProvider provider = fPart.getSite().getSelectionProvider(); 40 41 if(provider != null) { 42 return provider.getSelection(); 43 } 44 45 return null; 46 } 47 } 48 | Popular Tags |