KickJava   Java API By Example, From Geeks To Geeks.

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


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.IWorkbenchPartReference;
21 import org.eclipse.ui.commands.ICommandService;
22
23 /**
24  * This handler is used to switch between parts using the keyboard.
25  * <p>
26  * Replacement for CyclePartAction
27  * </p>
28  *
29  * @since 3.3
30  *
31  */

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

37     protected void addItems(Table table, WorkbenchPage page) {
38         // TODO Auto-generated method stub
39
IWorkbenchPartReference refs[] = page.getSortedParts();
40         boolean includeEditor = true;
41
42         for (int i = refs.length - 1; i >= 0; i--) {
43             if (refs[i] instanceof IEditorReference) {
44                 if (includeEditor) {
45                     IEditorReference activeEditor = (IEditorReference) refs[i];
46                     TableItem item = new TableItem(table, SWT.NONE);
47                     item.setText(WorkbenchMessages.CyclePartAction_editor);
48                     item.setImage(activeEditor.getTitleImage());
49                     item.setData(activeEditor);
50                     includeEditor = false;
51                 }
52             } else {
53                 TableItem item = new TableItem(table, SWT.NONE);
54                 item.setText(refs[i].getTitle());
55                 item.setImage(refs[i].getTitleImage());
56                 item.setData(refs[i]);
57             }
58         }
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.ui.internal.CycleBaseHandler#getBackwardCommand()
63      */

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

75     protected ParameterizedCommand getForwardCommand() {
76         // TODO Auto-generated method stub
77
final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class);
78         final Command command = commandService.getCommand("org.eclipse.ui.window.nextView"); //$NON-NLS-1$
79
ParameterizedCommand commandF = new ParameterizedCommand(command, null);
80         return commandF;
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader()
85      */

86     protected String JavaDoc getTableHeader() {
87         // TODO Auto-generated method stub
88
return WorkbenchMessages.CyclePartAction_header;
89     }
90
91 }
92
Popular Tags