1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.diagramEditor.handlers;
\r
14 import org.eclipse.core.commands.Command;
\r
15 import org.eclipse.core.commands.ExecutionException;
\r
16 import org.eclipse.core.commands.IParameter;
\r
17 import org.eclipse.core.commands.IParameterValues;
\r
18 import org.eclipse.core.commands.NotEnabledException;
\r
19 import org.eclipse.core.commands.NotHandledException;
\r
20 import org.eclipse.core.commands.ParameterValuesException;
\r
21 import org.eclipse.core.commands.Parameterization;
\r
22 import org.eclipse.core.commands.ParameterizedCommand;
\r
23 import org.eclipse.core.commands.common.NotDefinedException;
\r
24 import org.eclipse.ui.IWorkbench;
\r
25 import org.eclipse.ui.PlatformUI;
\r
26 import org.eclipse.ui.commands.ICommandService;
\r
27 import org.eclipse.ui.handlers.IHandlerService;
\r
30 * @author Tuukka Lehtonen
\r
32 public class CommandUtil {
\r
35 * @param viewIdPart a part of the ID of the view to be shown
\r
36 * @throws ExecutionException any errors occur during command execution or
\r
37 * if several views contain the specified string
\r
39 public static void showView(String viewIdPart) throws ExecutionException {
\r
40 IWorkbench workbench = PlatformUI.getWorkbench();
\r
41 ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
\r
42 IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
\r
43 Command showView = commandService.getCommand("org.eclipse.ui.views.showView");
\r
46 IParameter viewIdParm = showView.getParameter("org.eclipse.ui.views.showView.viewId");
\r
48 // the viewId parameter provides a list of valid values ... if you
\r
49 // knew the id of the problem view, you could skip this step.
\r
50 // This method is supposed to be used in places like the keys
\r
51 // preference page, to allow the user to select values
\r
52 IParameterValues parmValues = viewIdParm.getValues();
\r
53 String viewId = null;
\r
54 for (Object o : parmValues.getParameterValues().values()) {
\r
55 String id = (String) o;
\r
56 if (id.indexOf(viewIdPart) != -1) {
\r
64 Parameterization parm = new Parameterization(viewIdParm, viewId);
\r
65 ParameterizedCommand parmCommand = new ParameterizedCommand(showView, new Parameterization[] { parm });
\r
67 handlerService.executeCommand(parmCommand, null);
\r
68 } catch (ParameterValuesException e) {
\r
69 throw new ExecutionException("could not get parameter values for showView command", e);
\r
70 } catch (NotDefinedException e) {
\r
71 throw new ExecutionException("showView command definition problem", e);
\r
72 } catch (NotEnabledException e) {
\r
73 throw new ExecutionException("showView command not enabled", e);
\r
74 } catch (NotHandledException e) {
\r
75 throw new ExecutionException("no handler for showView command", e);
\r