Added Set End Time command and handler as an alternate stepping mode
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / e4 / WorkbenchUtil.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.simulation.ui.handlers.e4;
13
14 import org.eclipse.e4.ui.model.application.MApplication;
15 import org.eclipse.e4.ui.model.application.ui.menu.MItem;
16 import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
17 import org.eclipse.e4.ui.model.application.ui.menu.MToolItem;
18 import org.eclipse.e4.ui.workbench.modeling.EModelService;
19
20 /**
21  * @author Tuukka Lehtonen
22  * @since 1.39.0
23  */
24 class WorkbenchUtil {
25
26     public static boolean setMenuItemSelected(EModelService modelService, MApplication application, String toolItemId, String menuItemId, boolean selected) {
27         MToolItem toolItem = (MToolItem) modelService.find(toolItemId, application);
28         if (toolItem != null) {
29             MMenu menu = toolItem.getMenu();
30             if (menu != null) {
31                 MItem menuItem = (MItem) modelService.find(menuItemId, menu);
32                 if (menuItem != null) {
33                     menuItem.setSelected(selected);
34                     return true;
35                 }
36             }
37         }
38         return false;
39     }
40
41 }