KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.IPerspectiveDescriptor;
14 import org.eclipse.ui.IPerspectiveListener;
15 import org.eclipse.ui.IWorkbenchPage;
16 import org.eclipse.ui.IWorkbenchWindow;
17
18 /**
19  * Hides or shows the editor area within the current
20  * perspective of the workbench page.
21  */

22 public class ToggleEditorsVisibilityAction extends PerspectiveAction implements
23         IPerspectiveListener {
24
25     /* (non-Javadoc)
26      * Method declared on IPerspectiveListener
27      */

28     public void perspectiveActivated(IWorkbenchPage page,
29             IPerspectiveDescriptor perspective) {
30         if (page.isEditorAreaVisible()) {
31             setText(WorkbenchMessages.ToggleEditor_hideEditors);
32         } else {
33             setText(WorkbenchMessages.ToggleEditor_showEditors);
34         }
35     }
36
37     /* (non-Javadoc)
38      * Method declared on IPerspectiveListener
39      */

40     public void perspectiveChanged(IWorkbenchPage page,
41             IPerspectiveDescriptor perspective, String JavaDoc changeId) {
42         if (changeId == IWorkbenchPage.CHANGE_RESET
43                 || changeId == IWorkbenchPage.CHANGE_EDITOR_AREA_HIDE
44                 || changeId == IWorkbenchPage.CHANGE_EDITOR_AREA_SHOW) {
45             if (page.isEditorAreaVisible()) {
46                 setText(WorkbenchMessages.ToggleEditor_hideEditors);
47             } else {
48                 setText(WorkbenchMessages.ToggleEditor_showEditors);
49             }
50         }
51     }
52
53     /**
54      * Creates a new <code>ToggleEditorsVisibilityAction</code>
55      *
56      * @param window the window
57      */

58     public ToggleEditorsVisibilityAction(IWorkbenchWindow window) {
59         super(window);
60         setText(WorkbenchMessages.ToggleEditor_hideEditors);
61         setActionDefinitionId("org.eclipse.ui.window.hideShowEditors"); //$NON-NLS-1$
62
// @issue missing action id
63
setToolTipText(WorkbenchMessages.ToggleEditor_toolTip);
64         window.getWorkbench().getHelpSystem().setHelp(this,
65                 IWorkbenchHelpContextIds.TOGGLE_EDITORS_VISIBILITY_ACTION);
66         window.addPerspectiveListener(this);
67     }
68
69     /* (non-Javadoc)
70      * Method declared on PerspectiveAction.
71      */

72     protected void run(IWorkbenchPage page, IPerspectiveDescriptor persp) {
73         boolean visible = page.isEditorAreaVisible();
74         if (visible) {
75             page.setEditorAreaVisible(false);
76             setText(WorkbenchMessages.ToggleEditor_showEditors);
77         } else {
78             page.setEditorAreaVisible(true);
79             setText(WorkbenchMessages.ToggleEditor_hideEditors);
80         }
81     }
82
83     /* (non-Javadoc)
84      * Method declared on ActionFactory.IWorkbenchAction.
85      */

86     public void dispose() {
87         if (getWindow() != null) {
88             getWindow().removePerspectiveListener(this);
89         }
90         super.dispose();
91     }
92
93 }
94
Popular Tags