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.IWorkbenchPartReference;
19: import org.eclipse.ui.commands.ICommandService;
20:
21: /**
22: * This handler is used to switch between parts using the keyboard.
23: * <p>
24: * Replacement for CyclePartAction
25: * </p>
26: *
27: * @since 3.3
28: *
29: */
30: public class CycleViewHandler 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: IWorkbenchPartReference refs[] = page.getSortedParts();
38: boolean includeEditor = true;
39:
40: for (int i = refs.length - 1; i >= 0; i--) {
41: if (refs[i] instanceof IEditorReference) {
42: if (includeEditor) {
43: IEditorReference activeEditor = (IEditorReference) refs[i];
44: TableItem item = new TableItem(table, SWT.NONE);
45: item
46: .setText(WorkbenchMessages.CyclePartAction_editor);
47: item.setImage(activeEditor.getTitleImage());
48: item.setData(activeEditor);
49: includeEditor = false;
50: }
51: } else {
52: TableItem item = new TableItem(table, SWT.NONE);
53: item.setText(refs[i].getTitle());
54: item.setImage(refs[i].getTitleImage());
55: item.setData(refs[i]);
56: }
57: }
58: }
59:
60: /* (non-Javadoc)
61: * @see org.eclipse.ui.internal.CycleBaseHandler#getBackwardCommand()
62: */
63: protected ParameterizedCommand getBackwardCommand() {
64: // TODO Auto-generated method stub
65: final ICommandService commandService = (ICommandService) window
66: .getWorkbench().getService(ICommandService.class);
67: final Command command = commandService
68: .getCommand("org.eclipse.ui.window.previousView"); //$NON-NLS-1$
69: ParameterizedCommand commandBack = new ParameterizedCommand(
70: command, null);
71: return commandBack;
72: }
73:
74: /* (non-Javadoc)
75: * @see org.eclipse.ui.internal.CycleBaseHandler#getForwardCommand()
76: */
77: protected ParameterizedCommand getForwardCommand() {
78: // TODO Auto-generated method stub
79: final ICommandService commandService = (ICommandService) window
80: .getWorkbench().getService(ICommandService.class);
81: final Command command = commandService
82: .getCommand("org.eclipse.ui.window.nextView"); //$NON-NLS-1$
83: ParameterizedCommand commandF = new ParameterizedCommand(
84: command, null);
85: return commandF;
86: }
87:
88: /* (non-Javadoc)
89: * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader()
90: */
91: protected String getTableHeader() {
92: // TODO Auto-generated method stub
93: return WorkbenchMessages.CyclePartAction_header;
94: }
95:
96: }
|