KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > ToggleViewPaneAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
25  * @since 3.1
26  */

27 abstract public class ToggleViewPaneAction extends Action implements IViewActionDelegate, IActionDelegate2, IPropertyChangeListener {
28
29     MemoryView fView;
30     IAction fAction;
31     
32
33     /* (non-Javadoc)
34      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
35      */

36     public void init(IViewPart view) {
37         if (view instanceof MemoryView)
38         {
39             fView = (MemoryView)view;
40         }
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
45      */

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     /* (non-Javadoc)
68      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
69      */

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 JavaDoc getPaneId();
101 }
102
Popular Tags