1 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.IPerspectiveDescriptor; 20 import org.eclipse.ui.commands.ICommandService; 21 import org.eclipse.ui.model.PerspectiveLabelProvider; 22 23 31 public class CyclePerspectiveHandler extends CycleBaseHandler { 32 private PerspectiveLabelProvider labelProvider = new PerspectiveLabelProvider( 33 false); 34 35 38 protected void addItems(Table table, WorkbenchPage page) { 39 IPerspectiveDescriptor perspectives[] = page.getSortedPerspectives(); 40 for (int i = perspectives.length - 1; i >= 0; i--) { 41 TableItem item = new TableItem(table, SWT.NONE); 42 IPerspectiveDescriptor desc = perspectives[i]; 43 String text = labelProvider.getText(desc); 44 if(text == null) { 45 text = ""; } 47 item.setText(text); 48 item.setImage(labelProvider.getImage(desc)); 49 item.setData(desc); 50 } 51 52 } 53 54 57 protected ParameterizedCommand getBackwardCommand() { 58 final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class); 59 final Command command = commandService.getCommand("org.eclipse.ui.window.previousPerspective"); ParameterizedCommand commandBack = new ParameterizedCommand(command, null); 61 return commandBack; 62 } 63 64 67 protected ParameterizedCommand getForwardCommand() { 68 final ICommandService commandService = (ICommandService) window.getWorkbench().getService(ICommandService.class); 69 final Command command = commandService.getCommand("org.eclipse.ui.window.nextPerspective"); ParameterizedCommand commandF = new ParameterizedCommand(command, null); 71 return commandF; 72 } 73 74 77 protected String getTableHeader() { 78 return WorkbenchMessages.CyclePerspectiveAction_header; 79 } 80 81 84 public void dispose() { 85 if (labelProvider!=null) { 86 labelProvider.dispose(); 87 labelProvider = null; 88 } 89 super.dispose(); 90 } 91 } 92 | Popular Tags |