01: /*******************************************************************************
02: * Copyright (c) 2003, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.ui.IWorkbenchPage;
13: import org.eclipse.ui.IWorkbenchPartReference;
14: import org.eclipse.ui.IWorkbenchWindow;
15:
16: /**
17: * Toggles the maximize/restore state of the active part, if there is one.
18: */
19: public class MaximizePartAction extends PageEventAction {
20:
21: /**
22: * Creates a MaximizePartAction.
23: *
24: * @param window the window
25: */
26: public MaximizePartAction(IWorkbenchWindow window) {
27: super (WorkbenchMessages.MaximizePartAction_text, window);
28: setToolTipText(WorkbenchMessages.MaximizePartAction_toolTip);
29: // @issue missing action id
30: updateState();
31: window.getWorkbench().getHelpSystem().setHelp(this ,
32: IWorkbenchHelpContextIds.MAXIMIZE_PART_ACTION);
33: setActionDefinitionId("org.eclipse.ui.window.maximizePart"); //$NON-NLS-1$
34: }
35:
36: /* (non-Javadoc)
37: * Method declared on PageEventAction.
38: */
39: public void pageActivated(IWorkbenchPage page) {
40: super .pageActivated(page);
41: updateState();
42: }
43:
44: /* (non-Javadoc)
45: * Method declared on PageEventAction.
46: */
47: public void pageClosed(IWorkbenchPage page) {
48: super .pageClosed(page);
49: updateState();
50: }
51:
52: /* (non-Javadoc)
53: * Method declared on IAction.
54: */
55: public void run() {
56: if (getWorkbenchWindow() == null) {
57: // action has been dispose
58: return;
59: }
60:
61: IWorkbenchPage page = getActivePage();
62: if (page != null) {
63: if (page instanceof WorkbenchPage) {
64: IWorkbenchPartReference partRef = page
65: .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: }
|