01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.views;
05:
06: import org.eclipse.jdt.internal.ui.util.SelectionUtil;
07: import org.eclipse.jface.action.Action;
08: import org.eclipse.jface.viewers.ISelection;
09: import org.eclipse.jface.viewers.ISelectionProvider;
10: import org.eclipse.ui.actions.ActionContext;
11:
12: public class AutoSynchronizedAction extends Action {
13: ConfigViewPart fPart;
14:
15: AutoSynchronizedAction(ConfigViewPart part) {
16: super ("Auto-synchronized", AS_CHECK_BOX);
17: fPart = part;
18: }
19:
20: public void run() {
21: fPart.setAutoSynchronized(isChecked());
22: }
23:
24: public void setContext(ActionContext context) {
25: Object element = SelectionUtil.getSingleElement(getSelection());
26:
27: if (element instanceof AutolockWrapper) {
28: AutolockWrapper wrapper = (AutolockWrapper) element;
29: setChecked(wrapper.getAutoSynchronized());
30: }
31: }
32:
33: public boolean canActionBeAdded() {
34: Object element = SelectionUtil.getSingleElement(getSelection());
35: return element instanceof AutolockWrapper;
36: }
37:
38: private ISelection getSelection() {
39: ISelectionProvider provider = fPart.getSite()
40: .getSelectionProvider();
41: return (provider != null) ? provider.getSelection() : null;
42: }
43: }
|