KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > PerspectiveAction


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.ui.IPerspectiveDescriptor;
17 import org.eclipse.ui.IWorkbenchPage;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.actions.ActionFactory;
20
21 /**
22  * Abstract superclass of actions which are enabled iff there is an active perspective
23  * in the window.
24  *
25  * @since 3.1
26  */

27 public abstract class PerspectiveAction extends Action implements ActionFactory.IWorkbenchAction {
28     
29     /**
30      * The workbench window containing this action.
31      */

32     private IWorkbenchWindow workbenchWindow;
33     
34     /**
35      * Tracks perspective activation, to update this action's
36      * enabled state.
37      */

38     private PerspectiveTracker tracker;
39
40     /**
41      * Constructs a new perspective action for the given window.
42      *
43      * @param window the window
44      */

45     protected PerspectiveAction(IWorkbenchWindow window) {
46         Assert.isNotNull(window);
47         this.workbenchWindow = window;
48         tracker = new PerspectiveTracker(window, this);
49     }
50     
51     /**
52      * Returns the window, or <code>null</code> if the action has been disposed.
53      *
54      * @return the window or <code>null</code>
55      */

56     protected IWorkbenchWindow getWindow() {
57         return workbenchWindow;
58     }
59     
60     /* (non-Javadoc)
61      * Method declared on IAction.
62      */

63     public void run() {
64         if (workbenchWindow == null) {
65             // action has been disposed
66
return;
67         }
68         IWorkbenchPage page = workbenchWindow.getActivePage();
69         if (page != null && page.getPerspective() != null) {
70             run(page, page.getPerspective());
71         }
72     }
73     
74     /**
75      * Runs the action, passing the active page and perspective.
76      *
77      * @param page the active page
78      * @param persp the active perspective
79      */

80     protected abstract void run(IWorkbenchPage page, IPerspectiveDescriptor persp);
81
82     /* (non-Javadoc)
83      * Method declared on ActionFactory.IWorkbenchAction.
84      */

85     public void dispose() {
86         if (workbenchWindow == null) {
87             // already disposed
88
return;
89         }
90         tracker.dispose();
91         workbenchWindow = null;
92     }
93
94 }
95
96
Popular Tags