1 11 package org.eclipse.ui.actions; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.swt.events.SelectionEvent; 15 import org.eclipse.swt.widgets.Event; 16 import org.eclipse.ui.IPerspectiveDescriptor; 17 import org.eclipse.ui.IPluginContribution; 18 import org.eclipse.ui.IWorkbenchWindow; 19 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 20 import org.eclipse.ui.internal.util.Util; 21 22 27 public final class OpenPerspectiveAction extends Action implements 28 IPluginContribution { 29 30 35 private final PerspectiveMenu callback; 36 37 41 private final IPerspectiveDescriptor descriptor; 42 43 56 public OpenPerspectiveAction(final IWorkbenchWindow window, 57 final IPerspectiveDescriptor descriptor, 58 final PerspectiveMenu callback) { 59 super(Util.ZERO_LENGTH_STRING); 60 61 this.descriptor = descriptor; 62 this.callback = callback; 63 64 final String label = descriptor.getLabel(); 65 setText(label); 66 setToolTipText(label); 67 setImageDescriptor(descriptor.getImageDescriptor()); 68 69 window.getWorkbench().getHelpSystem().setHelp(this, 70 IWorkbenchHelpContextIds.OPEN_PERSPECTIVE_ACTION); 71 } 72 73 74 77 public final void runWithEvent(final Event event) { 78 callback.run(descriptor, new SelectionEvent(event)); 79 } 80 81 86 public String getLocalId() { 87 return descriptor.getId(); 88 } 89 90 95 public String getPluginId() { 96 return descriptor instanceof IPluginContribution ? ((IPluginContribution) descriptor) 97 .getPluginId() 98 : null; 99 } 100 } 101 | Popular Tags |