01: /*******************************************************************************
02: * Copyright (c) 2000, 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.IPerspectiveDescriptor;
13: import org.eclipse.ui.IPerspectiveListener;
14: import org.eclipse.ui.IWorkbenchPage;
15: import org.eclipse.ui.IWorkbenchWindow;
16:
17: /**
18: * Hides or shows the editor area within the current
19: * perspective of the workbench page.
20: */
21: public class ToggleEditorsVisibilityAction extends PerspectiveAction
22: implements IPerspectiveListener {
23:
24: /* (non-Javadoc)
25: * Method declared on IPerspectiveListener
26: */
27: public void perspectiveActivated(IWorkbenchPage page,
28: IPerspectiveDescriptor perspective) {
29: if (page.isEditorAreaVisible()) {
30: setText(WorkbenchMessages.ToggleEditor_hideEditors);
31: } else {
32: setText(WorkbenchMessages.ToggleEditor_showEditors);
33: }
34: }
35:
36: /* (non-Javadoc)
37: * Method declared on IPerspectiveListener
38: */
39: public void perspectiveChanged(IWorkbenchPage page,
40: IPerspectiveDescriptor perspective, String changeId) {
41: if (changeId == IWorkbenchPage.CHANGE_RESET
42: || changeId == IWorkbenchPage.CHANGE_EDITOR_AREA_HIDE
43: || changeId == IWorkbenchPage.CHANGE_EDITOR_AREA_SHOW) {
44: if (page.isEditorAreaVisible()) {
45: setText(WorkbenchMessages.ToggleEditor_hideEditors);
46: } else {
47: setText(WorkbenchMessages.ToggleEditor_showEditors);
48: }
49: }
50: }
51:
52: /**
53: * Creates a new <code>ToggleEditorsVisibilityAction</code>
54: *
55: * @param window the window
56: */
57: public ToggleEditorsVisibilityAction(IWorkbenchWindow window) {
58: super (window);
59: setText(WorkbenchMessages.ToggleEditor_hideEditors);
60: setActionDefinitionId("org.eclipse.ui.window.hideShowEditors"); //$NON-NLS-1$
61: // @issue missing action id
62: setToolTipText(WorkbenchMessages.ToggleEditor_toolTip);
63: window
64: .getWorkbench()
65: .getHelpSystem()
66: .setHelp(
67: this ,
68: IWorkbenchHelpContextIds.TOGGLE_EDITORS_VISIBILITY_ACTION);
69: window.addPerspectiveListener(this );
70: }
71:
72: /* (non-Javadoc)
73: * Method declared on PerspectiveAction.
74: */
75: protected void run(IWorkbenchPage page, IPerspectiveDescriptor persp) {
76: boolean visible = page.isEditorAreaVisible();
77: if (visible) {
78: page.setEditorAreaVisible(false);
79: setText(WorkbenchMessages.ToggleEditor_showEditors);
80: } else {
81: page.setEditorAreaVisible(true);
82: setText(WorkbenchMessages.ToggleEditor_hideEditors);
83: }
84: }
85:
86: /* (non-Javadoc)
87: * Method declared on ActionFactory.IWorkbenchAction.
88: */
89: public void dispose() {
90: if (getWindow() != null) {
91: getWindow().removePerspectiveListener(this);
92: }
93: super.dispose();
94: }
95:
96: }
|