]> gerrit.simantics Code Review - simantics/platform.git/blob
d6fae16ccf7e780b42a5bd5db2a8c3d3f7980695
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.simulation.ui.handlers;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.project.IProject;
18 import org.simantics.simulation.ontology.SimulationResource;
19 import org.simantics.simulation.project.IExperimentManager;
20 import org.simantics.ui.DoubleClickEvent;
21 import org.simantics.ui.IDoubleClickAction;
22 import org.simantics.ui.SimanticsUI;
23 import org.simantics.ui.utils.ResourceAdaptionUtils;
24 import org.simantics.utils.ui.action.PriorityAction;
25
26 /**
27  * A double click action handler for the graph explorer browser. Intended for
28  * invocation when an experiment resource is double clicked, which is controlled
29  * from outside of this class.
30  * 
31  * @author Tuukka Lehtonen
32  * 
33  * @see ExperimentActivator
34  */
35 public class ActivateExperimentAction implements IDoubleClickAction {
36
37     @Override
38     public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {
39         ReadGraph g = e.getGraph();
40         final Resource experiment = ResourceAdaptionUtils.toSingleResource(e.getResource());
41         if (experiment == null)
42             return;
43
44         if (g.isInstanceOf(experiment, SimulationResource.getInstance(g).Experiment)) {
45             final IProject project = SimanticsUI.getProject();
46             if (project == null)
47                 return;
48
49             final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
50             if (experimentManager != null) {
51                 e.add(new PriorityAction(PriorityAction.HIGH+10) {
52                     @Override
53                     public void run() {
54                         ExperimentActivator.scheduleActivation(project.getSession(), project, experimentManager, experiment);
55                     }
56                 });
57                 e.consume();
58                 return;
59             } /*else {
60                 ExperimentUtil.activateExperiment(g, experiment);
61             }*/
62
63         }
64     }
65
66 }