]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
4e00ace65dd897f0277ff3ed5fe7fb92084d5a40
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2010 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.actions;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 import org.simantics.project.IProject;\r
18 import org.simantics.simulation.ontology.SimulationResource;\r
19 import org.simantics.simulation.project.IExperimentManager;\r
20 import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator;\r
21 import org.simantics.ui.DoubleClickEvent;\r
22 import org.simantics.ui.IDoubleClickAction;\r
23 import org.simantics.ui.SimanticsUI;\r
24 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
25 import org.simantics.utils.ui.ErrorLogger;\r
26 import org.simantics.utils.ui.action.PriorityAction;\r
27 \r
28 public class ActivateExperimentAction implements IDoubleClickAction {\r
29 \r
30         @Override\r
31         public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {\r
32         ReadGraph g = e.getGraph();\r
33         final Resource experiment = ResourceAdaptionUtils.toSingleResource(e.getResource());\r
34         if (experiment == null)\r
35             return;\r
36 \r
37         if (g.isInstanceOf(experiment, SimulationResource.getInstance(g).Experiment)) {\r
38             final IProject project = SimanticsUI.getProject();\r
39             if (project == null)\r
40                 return;\r
41 \r
42             final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
43             if (experimentManager == null) {\r
44                 ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception());\r
45                 return;\r
46             }\r
47 \r
48             e.add(new PriorityAction(PriorityAction.HIGH+20) {\r
49                 @Override\r
50                 public void run() {\r
51                         SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, experiment);\r
52                 }\r
53             });\r
54             e.consume();\r
55         }\r
56                 \r
57         }\r
58 \r
59 }\r