1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.widgets.Table; 15 import org.eclipse.swt.widgets.TableItem; 16 import org.eclipse.ui.IPerspectiveDescriptor; 17 import org.eclipse.ui.IPerspectiveListener; 18 import org.eclipse.ui.IWorkbenchPage; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.model.PerspectiveLabelProvider; 21 22 26 public class CyclePerspectiveAction extends CyclePartAction implements 27 IPerspectiveListener { 28 29 private PerspectiveLabelProvider labelProvider = new PerspectiveLabelProvider( 30 false); 31 32 38 public CyclePerspectiveAction(IWorkbenchWindow window, boolean forward) { 39 super(window, forward); 40 window.addPerspectiveListener(this); 41 updateState(); 42 } 43 44 protected void setText() { 45 if (forward) { 47 setText(WorkbenchMessages.CyclePerspectiveAction_next_text); 48 setToolTipText(WorkbenchMessages.CyclePerspectiveAction_next_toolTip); 49 getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(this, 51 IWorkbenchHelpContextIds.CYCLE_PERSPECTIVE_FORWARD_ACTION); 52 setActionDefinitionId("org.eclipse.ui.window.nextPerspective"); } else { 54 setText(WorkbenchMessages.CyclePerspectiveAction_prev_text); 55 setToolTipText(WorkbenchMessages.CyclePerspectiveAction_prev_toolTip); 56 getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(this, 58 IWorkbenchHelpContextIds.CYCLE_PERSPECTIVE_BACKWARD_ACTION); 59 setActionDefinitionId("org.eclipse.ui.window.previousPerspective"); } 61 } 62 63 66 public void dispose() { 67 if (getWorkbenchWindow() == null) { 68 return; 70 } 71 getWorkbenchWindow().removePerspectiveListener(this); 72 labelProvider.dispose(); 73 super.dispose(); 74 } 75 76 79 public void activate(IWorkbenchPage page, Object selection) { 80 if (selection != null) { 81 IPerspectiveDescriptor persp = (IPerspectiveDescriptor) selection; 82 page.setPerspective(persp); 83 } 84 } 85 86 89 public void updateState() { 90 WorkbenchPage page = (WorkbenchPage) getActivePage(); 91 if (page == null) { 92 setEnabled(false); 93 return; 94 } 95 setEnabled(page.getSortedPerspectives().length >= 1); 97 } 98 99 102 protected void addItems(Table table, WorkbenchPage page) { 103 IPerspectiveDescriptor perspectives[] = page.getSortedPerspectives(); 104 for (int i = perspectives.length - 1; i >= 0; i--) { 105 TableItem item = new TableItem(table, SWT.NONE); 106 IPerspectiveDescriptor desc = perspectives[i]; 107 String text = labelProvider.getText(desc); 108 if(text == null) { 109 text = ""; } 111 item.setText(text); 112 item.setImage(labelProvider.getImage(desc)); 113 item.setData(desc); 114 } 115 } 116 117 120 protected String getTableHeader() { 121 return WorkbenchMessages.CyclePerspectiveAction_header; 122 } 123 124 127 public void perspectiveActivated(IWorkbenchPage page, 128 IPerspectiveDescriptor perspective) { 129 updateState(); 130 } 131 132 135 public void perspectiveChanged(IWorkbenchPage page, 136 IPerspectiveDescriptor perspective, String changeId) { 137 } 139 140 } 141 | Popular Tags |