1 11 package org.eclipse.debug.internal.ui.views.variables; 12 13 14 import org.eclipse.debug.internal.ui.DebugUIPlugin; 15 import org.eclipse.debug.ui.IDebugView; 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.jface.preference.IPreferenceStore; 18 import org.eclipse.jface.viewers.ISelection; 19 import org.eclipse.jface.viewers.StructuredViewer; 20 import org.eclipse.jface.viewers.Viewer; 21 import org.eclipse.swt.widgets.Event; 22 import org.eclipse.ui.IActionDelegate2; 23 import org.eclipse.ui.IViewActionDelegate; 24 import org.eclipse.ui.IViewPart; 25 26 29 public abstract class VariableViewToggleAction implements IViewActionDelegate, IActionDelegate2 { 30 31 private IViewPart fView; 32 private IAction fAction; 33 34 public VariableViewToggleAction() { 35 super(); 36 } 37 38 41 public void init(IViewPart view) { 42 fView = view; 43 boolean checked = getPreferenceValue(view); 44 fAction.setChecked(checked); 45 run(fAction); 46 } 47 48 51 public void init(IAction action) { 52 fAction = action; 53 } 54 55 58 public void dispose() { 59 } 60 61 64 public void runWithEvent(IAction action, Event event) { 65 run(action); 66 } 67 68 71 public void run(IAction action) { 72 IPreferenceStore store = getPreferenceStore(); 73 String key = getView().getSite().getId() + "." + getPreferenceKey(); store.setValue(key, action.isChecked()); 75 } 76 77 80 public void selectionChanged(IAction action, ISelection selection) { 81 } 82 83 protected IPreferenceStore getPreferenceStore() { 84 return DebugUIPlugin.getDefault().getPreferenceStore(); 85 } 86 87 94 protected boolean getPreferenceValue(IViewPart part) { 95 String baseKey = getPreferenceKey(); 96 String viewKey = part.getSite().getId(); 97 String compositeKey = viewKey + "." + baseKey; IPreferenceStore store = getPreferenceStore(); 99 boolean value = false; 100 if (store.contains(compositeKey)) { 101 value = store.getBoolean(compositeKey); 102 } else { 103 value = store.getBoolean(baseKey); 104 } 105 return value; 106 } 107 108 113 protected abstract String getPreferenceKey(); 114 115 protected IViewPart getView() { 116 return fView; 117 } 118 119 protected StructuredViewer getStructuredViewer() { 120 IDebugView view = (IDebugView)getView().getAdapter(IDebugView.class); 121 if (view != null) { 122 Viewer viewer = view.getViewer(); 123 if (viewer instanceof StructuredViewer) { 124 return (StructuredViewer)viewer; 125 } 126 } 127 return null; 128 } 129 } 130 | Popular Tags |