1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import org.eclipse.debug.ui.DebugUITools; 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.jface.action.IAction; 16 import org.eclipse.jface.util.IPropertyChangeListener; 17 import org.eclipse.jface.util.PropertyChangeEvent; 18 import org.eclipse.jface.viewers.ISelection; 19 import org.eclipse.swt.widgets.Event; 20 import org.eclipse.ui.IActionDelegate2; 21 import org.eclipse.ui.IViewActionDelegate; 22 import org.eclipse.ui.IViewPart; 23 24 27 abstract public class ToggleViewPaneAction extends Action implements IViewActionDelegate, IActionDelegate2, IPropertyChangeListener { 28 29 MemoryView fView; 30 IAction fAction; 31 32 33 36 public void init(IViewPart view) { 37 if (view instanceof MemoryView) 38 { 39 fView = (MemoryView)view; 40 } 41 } 42 43 46 public void run(IAction action) { 47 48 if (fView == null) 49 return; 50 51 fView.showViewPane(!fView.isViewPaneVisible(getPaneId()), getPaneId()); 52 53 if (fView.isViewPaneVisible(getPaneId())) 54 action.setChecked(true); 55 else 56 action.setChecked(false); 57 58 } 59 60 public void run() { 61 if (fView == null) 62 return; 63 64 fView.showViewPane(!fView.isViewPaneVisible(getPaneId()), getPaneId()); 65 } 66 67 70 public void selectionChanged(IAction action, ISelection selection) { 71 if (fView.isViewPaneVisible(getPaneId())) 72 action.setChecked(true); 73 else 74 action.setChecked(false); 75 } 76 77 public void dispose() { 78 DebugUITools.getPreferenceStore().removePropertyChangeListener(this); 79 } 80 81 public void init(IAction action) { 82 fAction = action; 83 DebugUITools.getPreferenceStore().addPropertyChangeListener(this); 84 } 85 86 public void runWithEvent(IAction action, Event event) { 87 run(action); 88 } 89 90 public void propertyChange(PropertyChangeEvent event) { 91 if (fView != null && fAction != null) 92 { 93 if (fView.isViewPaneVisible(getPaneId())) 94 fAction.setChecked(true); 95 else 96 fAction.setChecked(false); 97 } 98 } 99 100 abstract public String getPaneId(); 101 } 102 | Popular Tags |