KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2007 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
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.core.commands.Command;
15 import org.eclipse.core.commands.ParameterizedCommand;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.Table;
18 import org.eclipse.swt.widgets.TableItem;
19 import org.eclipse.ui.IEditorReference;
20 import org.eclipse.ui.commands.ICommandService;
21
22 /**
23  * This is the handler for NextEditor and PrevEditor commands.
24  * <p>
25  * Replacement for CycleEditorAction
26  * </p>
27  *
28  * @since 3.3
29  */

30 public class CycleEditorHandler extends CycleBaseHandler {
31
32     /* (non-Javadoc)
33      * @see org.eclipse.ui.internal.CycleBaseHandler#addItems(org.eclipse.swt.widgets.Table, org.eclipse.ui.internal.WorkbenchPage)
34      */

35     protected void addItems(Table table, WorkbenchPage page) {
36         // TODO Auto-generated method stub
37
IEditorReference refs[] = page.getSortedEditors();
38         for (int i = refs.length - 1; i >= 0; i--) {
39             TableItem item = null;
40             item = new TableItem(table, SWT.NONE);
41             if (refs[i].isDirty()) {
42                 item.setText("*" + refs[i].getTitle()); //$NON-NLS-1$
43
} else {
44                 item.setText(refs[i].getTitle());
45             }
46             item.setImage(refs[i].getTitleImage());
47             item.setData(refs[i]);
48         }
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.ui.internal.CycleBaseHandler#getBackwardCommand()
53      */

54     protected ParameterizedCommand getBackwardCommand() {
55         final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class);
56         final Command command = commandService.getCommand("org.eclipse.ui.window.previousEditor"); //$NON-NLS-1$
57
ParameterizedCommand commandBack = new ParameterizedCommand(command, null);
58         return commandBack;
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.ui.internal.CycleBaseHandler#getForwardCommand()
63      */

64     protected ParameterizedCommand getForwardCommand() {
65         final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class);
66         final Command command = commandService.getCommand("org.eclipse.ui.window.nextEditor"); //$NON-NLS-1$
67
ParameterizedCommand commandF = new ParameterizedCommand(command, null);
68         return commandF;
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader()
73      */

74     protected String JavaDoc getTableHeader() {
75         // TODO Auto-generated method stub
76
return WorkbenchMessages.CycleEditorAction_header;
77     }
78
79 }
80
Popular Tags