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