01: /*******************************************************************************
02: * Copyright (c) 2007 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.core.commands.Command;
13: import org.eclipse.core.commands.ParameterizedCommand;
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.widgets.Table;
16: import org.eclipse.swt.widgets.TableItem;
17: import org.eclipse.ui.IEditorReference;
18: import org.eclipse.ui.commands.ICommandService;
19:
20: /**
21: * This is the handler for NextEditor and PrevEditor commands.
22: * <p>
23: * Replacement for CycleEditorAction
24: * </p>
25: *
26: * @since 3.3
27: */
28: public class CycleEditorHandler extends CycleBaseHandler {
29:
30: /* (non-Javadoc)
31: * @see org.eclipse.ui.internal.CycleBaseHandler#addItems(org.eclipse.swt.widgets.Table, org.eclipse.ui.internal.WorkbenchPage)
32: */
33: protected void addItems(Table table, WorkbenchPage page) {
34: // TODO Auto-generated method stub
35: IEditorReference refs[] = page.getSortedEditors();
36: for (int i = refs.length - 1; i >= 0; i--) {
37: TableItem item = null;
38: item = new TableItem(table, SWT.NONE);
39: if (refs[i].isDirty()) {
40: item.setText("*" + refs[i].getTitle()); //$NON-NLS-1$
41: } else {
42: item.setText(refs[i].getTitle());
43: }
44: item.setImage(refs[i].getTitleImage());
45: item.setData(refs[i]);
46: }
47: }
48:
49: /* (non-Javadoc)
50: * @see org.eclipse.ui.internal.CycleBaseHandler#getBackwardCommand()
51: */
52: protected ParameterizedCommand getBackwardCommand() {
53: final ICommandService commandService = (ICommandService) window
54: .getWorkbench().getService(ICommandService.class);
55: final Command command = commandService
56: .getCommand("org.eclipse.ui.window.previousEditor"); //$NON-NLS-1$
57: ParameterizedCommand commandBack = new ParameterizedCommand(
58: command, null);
59: return commandBack;
60: }
61:
62: /* (non-Javadoc)
63: * @see org.eclipse.ui.internal.CycleBaseHandler#getForwardCommand()
64: */
65: protected ParameterizedCommand getForwardCommand() {
66: final ICommandService commandService = (ICommandService) window
67: .getWorkbench().getService(ICommandService.class);
68: final Command command = commandService
69: .getCommand("org.eclipse.ui.window.nextEditor"); //$NON-NLS-1$
70: ParameterizedCommand commandF = new ParameterizedCommand(
71: command, null);
72: return commandF;
73: }
74:
75: /* (non-Javadoc)
76: * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader()
77: */
78: protected String getTableHeader() {
79: // TODO Auto-generated method stub
80: return WorkbenchMessages.CycleEditorAction_header;
81: }
82:
83: }
|