KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > views > HonorTransientAction


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc 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 JavaDoc 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