]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
8c7e6fbf46b27d31f46e9bae730671281dae253a
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2012 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.browser.actions;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.WriteGraph;\r
17 import org.simantics.db.common.request.WriteRequest;\r
18 import org.simantics.db.exception.DatabaseException;\r
19 import org.simantics.sysdyn.SysdynResource;\r
20 import org.simantics.ui.DoubleClickEvent;\r
21 import org.simantics.ui.IDoubleClickAction;\r
22 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
23 \r
24 /**\r
25  * Activates a result dataset to be shown in charts and other result visualizations\r
26  * \r
27  * @author Teemu Lempinen\r
28  *\r
29  */\r
30 public class ActivateResultDatasetAction implements IDoubleClickAction {\r
31 \r
32     @Override\r
33     public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {\r
34         final Resource result = ResourceAdaptionUtils.toSingleResource(e.getResource());\r
35         if (result == null)\r
36             return;\r
37 \r
38         ReadGraph graph = e.getGraph();\r
39 \r
40         if(graph.isInstanceOf(result, SysdynResource.getInstance(graph).Result)) {\r
41 \r
42             graph.getSession().asyncRequest(new WriteRequest() {\r
43 \r
44                 @Override\r
45                 public void perform(WriteGraph graph) throws DatabaseException {\r
46                     SysdynResource sr = SysdynResource.getInstance(graph);\r
47                     if(graph.isInstanceOf(result, sr.Result)) {\r
48                         if (graph.hasStatement(result, sr.Result_showResult)) {\r
49                             graph.denyStatement(result, sr.Result_showResult, result);\r
50                         } else {\r
51                             graph.claim(result, sr.Result_showResult, result);\r
52                         }\r
53                     }                \r
54                 }\r
55             });\r
56         }\r
57 \r
58     }\r
59 \r
60 }\r