KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.ui.internal;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.widgets.Table;
15 import org.eclipse.swt.widgets.TableItem;
16 import org.eclipse.ui.IEditorReference;
17 import org.eclipse.ui.IWorkbenchWindow;
18
19 /**
20  * This is the implementation for both NextEditorAction and PrevEditorAction.
21  */

22 public class CycleEditorAction extends CyclePartAction {
23
24     /**
25      * Creates a CycleEditorAction.
26      * @param window the window
27      * @param forward whether the editors will be cycled forward
28      */

29     public CycleEditorAction(IWorkbenchWindow window, boolean forward) {
30         super(window, forward);
31         updateState();
32     }
33
34     protected void setText() {
35         // TBD: Remove text and tooltip when this becomes an invisible action.
36
if (forward) {
37             setText(WorkbenchMessages.CycleEditorAction_next_text);
38             setToolTipText(WorkbenchMessages.CycleEditorAction_next_toolTip);
39             // @issue missing action ids
40
getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(this,
41                     IWorkbenchHelpContextIds.CYCLE_EDITOR_FORWARD_ACTION);
42             setActionDefinitionId("org.eclipse.ui.window.nextEditor"); //$NON-NLS-1$
43
} else {
44             setText(WorkbenchMessages.CycleEditorAction_prev_text);
45             setToolTipText(WorkbenchMessages.CycleEditorAction_prev_toolTip);
46             // @issue missing action ids
47
getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(this,
48                     IWorkbenchHelpContextIds.CYCLE_EDITOR_BACKWARD_ACTION);
49             setActionDefinitionId("org.eclipse.ui.window.previousEditor"); //$NON-NLS-1$
50
}
51     }
52
53     /**
54      * Updates the enabled state.
55      */

56     public void updateState() {
57         WorkbenchPage page = (WorkbenchPage) getActivePage();
58         if (page == null) {
59             setEnabled(false);
60             return;
61         }
62         // enable iff there is at least one other editor to switch to
63
setEnabled(page.getSortedEditors().length >= 1);
64     }
65
66     /**
67      * Add all views to the dialog in the activation order
68      */

69     protected void addItems(Table table, WorkbenchPage page) {
70         IEditorReference refs[] = page.getSortedEditors();
71         for (int i = refs.length - 1; i >= 0; i--) {
72             TableItem item = null;
73             item = new TableItem(table, SWT.NONE);
74             if (refs[i].isDirty()) {
75                 item.setText("*" + refs[i].getTitle()); //$NON-NLS-1$
76
} else {
77                 item.setText(refs[i].getTitle());
78             }
79             item.setImage(refs[i].getTitleImage());
80             item.setData(refs[i]);
81         }
82     }
83
84     /**
85      * Returns the string which will be shown in the table header.
86      */

87     protected String JavaDoc getTableHeader() {
88         return WorkbenchMessages.CycleEditorAction_header;
89     }
90 }
91
Popular Tags