1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.dialogs.ErrorDialog; 15 import org.eclipse.ui.IPluginContribution; 16 import org.eclipse.ui.IViewPart; 17 import org.eclipse.ui.IViewReference; 18 import org.eclipse.ui.IWorkbenchPage; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.PartInitException; 21 import org.eclipse.ui.internal.registry.ViewDescriptor; 22 import org.eclipse.ui.views.IViewDescriptor; 23 24 27 public class ShowViewAction extends Action implements IPluginContribution { 28 private IWorkbenchWindow window; 29 30 private IViewDescriptor desc; 31 private boolean makeFast = false; 32 33 34 37 protected ShowViewAction(IWorkbenchWindow window, IViewDescriptor desc, boolean makeFast) { 38 super(""); 40 String accel = desc instanceof ViewDescriptor ? ((ViewDescriptor) desc) 42 .getAccelerator() : null; 43 String label = desc.getLabel(); 44 setText(accel == null ? label : label + "@" + accel); setImageDescriptor(desc.getImageDescriptor()); 46 setToolTipText(label); 47 window.getWorkbench().getHelpSystem().setHelp(this, 48 IWorkbenchHelpContextIds.SHOW_VIEW_ACTION); 49 this.window = window; 50 this.desc = desc; 51 this.makeFast = makeFast; 52 } 53 54 57 public void run() { 58 IWorkbenchPage page = window.getActivePage(); 59 if (page != null) { 60 try { 61 if (makeFast) { 62 WorkbenchPage wp = (WorkbenchPage) page; 63 Perspective persp = wp.getActivePerspective(); 64 65 boolean useNewMinMax = Perspective.useNewMinMax(persp); 67 if (useNewMinMax) { 68 IViewReference ref = persp.getViewReference(desc.getId(), null); 69 if (ref == null) 70 return; 71 72 persp.getFastViewManager().addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, true); 73 wp.activate(ref.getPart(true)); 74 75 return; 76 } 77 78 IViewReference ref = wp.findViewReference(desc.getId()); 79 80 if (ref == null) { 81 IViewPart part = page.showView(desc.getId(), null, IWorkbenchPage.VIEW_CREATE); 82 ref = (IViewReference)wp.getReference(part); 83 } 84 85 if (!wp.isFastView(ref) && persp != null) { 86 persp.getFastViewManager().addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, true); 87 } 88 wp.activate(ref.getPart(true)); 89 } else { 90 page.showView(desc.getId()); 91 } 92 } catch (PartInitException e) { 93 ErrorDialog.openError(window.getShell(), WorkbenchMessages.ShowView_errorTitle, 94 e.getMessage(), e.getStatus()); 95 } 96 } 97 } 98 99 104 public String getLocalId() { 105 return desc.getId(); 106 } 107 108 113 public String getPluginId() { 114 return desc instanceof IPluginContribution ? ((IPluginContribution) desc) 115 .getPluginId() 116 : null; 117 } 118 } 119 | Popular Tags |