]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
e984ef152865a5a6273e618410cd916c8fe123bb
[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.layer0.Layer0;\r
18 import org.simantics.operation.Layer0X;\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 import org.simantics.utils.ui.action.PriorityAction;\r
24 \r
25 public class ConsumeUnnecessaryEntersAction implements IDoubleClickAction {\r
26 \r
27         @Override\r
28         public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {\r
29         ReadGraph g = e.getGraph();\r
30         Layer0 l0 = Layer0.getInstance(g);\r
31         Layer0X L0X = Layer0X.getInstance(g);\r
32         final Resource resource = ResourceAdaptionUtils.toSingleResource(e.getResource());\r
33         if(resource == null)\r
34                 return;\r
35                 SysdynResource sr = SysdynResource.getInstance(g);\r
36                 \r
37                 if(g.isInstanceOf(resource, sr.SysdynModel) || g.isInstanceOf(resource, sr.Variable)) {\r
38                         consume(e);\r
39                 } else if(g.hasStatement(resource, L0X.Represents)){\r
40                         Resource represents = g.getSingleObject(resource, L0X.Represents);      \r
41                         if (g.isInstanceOf(represents, sr.Variable)) {\r
42                                 consume(e);\r
43                         }\r
44                 }\r
45         }\r
46         \r
47         private void consume(DoubleClickEvent e) {\r
48         e.add(new PriorityAction(PriorityAction.HIGH) {\r
49             @Override\r
50             public void run() {\r
51                 \r
52             }\r
53         });\r
54                 e.consume();\r
55         }\r
56 \r
57 }\r