1 11 package org.eclipse.ui.handlers; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.commands.AbstractHandler; 16 import org.eclipse.core.commands.ExecutionEvent; 17 import org.eclipse.core.commands.ExecutionException; 18 import org.eclipse.jface.window.Window; 19 import org.eclipse.ui.IViewPart; 20 import org.eclipse.ui.IViewReference; 21 import org.eclipse.ui.IWorkbenchPage; 22 import org.eclipse.ui.IWorkbenchWindow; 23 import org.eclipse.ui.PartInitException; 24 import org.eclipse.ui.internal.FastViewBar; 25 import org.eclipse.ui.internal.Perspective; 26 import org.eclipse.ui.internal.WorkbenchMessages; 27 import org.eclipse.ui.internal.WorkbenchPage; 28 import org.eclipse.ui.internal.WorkbenchPlugin; 29 import org.eclipse.ui.internal.dialogs.ShowViewDialog; 30 import org.eclipse.ui.internal.misc.StatusUtil; 31 import org.eclipse.ui.statushandlers.StatusManager; 32 import org.eclipse.ui.views.IViewDescriptor; 33 34 40 public final class ShowViewHandler extends AbstractHandler { 41 42 45 private static final String PARAMETER_NAME_VIEW_ID = "org.eclipse.ui.views.showView.viewId"; private boolean makeFast = false; 47 private static final String PARAMETER_MAKE_FAST = "org.eclipse.ui.views.showView.makeFast"; 49 52 public ShowViewHandler() { 53 } 54 55 63 public ShowViewHandler(boolean makeFast) { 64 this.makeFast = makeFast; 65 } 66 67 public final Object execute(final ExecutionEvent event) 68 throws ExecutionException { 69 IWorkbenchWindow window = HandlerUtil 70 .getActiveWorkbenchWindowChecked(event); 71 final Map parameters = event.getParameters(); 73 final Object value = parameters.get(PARAMETER_NAME_VIEW_ID); 74 makeFast = "true".equals(parameters.get(PARAMETER_MAKE_FAST)); 76 if (value == null) { 77 openOther(window); 78 } else { 79 try { 80 openView((String ) value, window); 81 } catch (PartInitException e) { 82 throw new ExecutionException("Part could not be initialized", e); } 84 } 85 86 return null; 87 } 88 89 92 private final void openOther(final IWorkbenchWindow window) { 93 final IWorkbenchPage page = window.getActivePage(); 94 if (page == null) { 95 return; 96 } 97 98 final ShowViewDialog dialog = new ShowViewDialog(window, 99 WorkbenchPlugin.getDefault().getViewRegistry()); 100 dialog.open(); 101 102 if (dialog.getReturnCode() == Window.CANCEL) { 103 return; 104 } 105 106 final IViewDescriptor[] descriptors = dialog.getSelection(); 107 for (int i = 0; i < descriptors.length; ++i) { 108 try { 109 openView(descriptors[i].getId(), window); 110 } catch (PartInitException e) { 111 StatusUtil.handleStatus(e.getStatus(), 112 WorkbenchMessages.ShowView_errorTitle 113 + ": " + e.getMessage(), StatusManager.SHOW); 115 } 116 } 117 } 118 119 127 private final void openView(final String viewId, 128 final IWorkbenchWindow activeWorkbenchWindow) 129 throws PartInitException { 130 131 final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); 132 if (activePage == null) { 133 return; 134 } 135 136 if (makeFast) { 137 WorkbenchPage wp = (WorkbenchPage) activePage; 138 Perspective persp = wp.getActivePerspective(); 139 140 boolean useNewMinMax = Perspective.useNewMinMax(persp); 142 if (useNewMinMax) { 143 IViewReference ref = persp.getViewReference(viewId, null); 144 if (ref == null) 145 return; 146 147 persp.getFastViewManager().addViewReference(FastViewBar.FASTVIEWBAR_ID, -1, ref, true); 148 wp.activate(ref.getPart(true)); 149 150 return; 151 } 152 153 IViewReference ref = wp.findViewReference(viewId); 154 155 if (ref == null) { 156 IViewPart part = wp.showView(viewId, null, IWorkbenchPage.VIEW_CREATE); 157 ref = (IViewReference)wp.getReference(part); 158 } 159 160 if (!wp.isFastView(ref)) { 161 wp.addFastView(ref); 162 } 163 wp.activate(ref.getPart(true)); 164 } else { 165 activePage.showView(viewId); 166 } 167 168 } 169 } 170 | Popular Tags |