KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.ui.internal;
12
13 import org.eclipse.ui.IWorkbenchPage;
14 import org.eclipse.ui.IWorkbenchPartReference;
15 import org.eclipse.ui.IWorkbenchWindow;
16
17 /**
18  * Toggles the maximize/restore state of the active part, if there is one.
19  */

20 public class MaximizePartAction extends PageEventAction {
21
22     /**
23      * Creates a MaximizePartAction.
24      *
25      * @param window the window
26      */

27     public MaximizePartAction(IWorkbenchWindow window) {
28         super(WorkbenchMessages.MaximizePartAction_text, window);
29         setToolTipText(WorkbenchMessages.MaximizePartAction_toolTip);
30         // @issue missing action id
31
updateState();
32         window.getWorkbench().getHelpSystem().setHelp(this,
33                 IWorkbenchHelpContextIds.MAXIMIZE_PART_ACTION);
34         setActionDefinitionId("org.eclipse.ui.window.maximizePart"); //$NON-NLS-1$
35
}
36
37     /* (non-Javadoc)
38      * Method declared on PageEventAction.
39      */

40     public void pageActivated(IWorkbenchPage page) {
41         super.pageActivated(page);
42         updateState();
43     }
44
45     /* (non-Javadoc)
46      * Method declared on PageEventAction.
47      */

48     public void pageClosed(IWorkbenchPage page) {
49         super.pageClosed(page);
50         updateState();
51     }
52
53     /* (non-Javadoc)
54      * Method declared on IAction.
55      */

56     public void run() {
57         if (getWorkbenchWindow() == null) {
58             // action has been dispose
59
return;
60         }
61
62         IWorkbenchPage page = getActivePage();
63         if (page != null) {
64             if (page instanceof WorkbenchPage) {
65                 IWorkbenchPartReference partRef = page.getActivePartReference();
66
67                 if (partRef != null) {
68                     ((WorkbenchPage) page).toggleZoom(partRef);
69                 }
70             }
71         }
72     }
73
74     /**
75      * Updates the enabled state.
76      */

77     private void updateState() {
78         setEnabled(getActivePage() != null);
79     }
80 }
81
Popular Tags