]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/proconf/g3d/actions/ReadAction.java
7c4cdce87e30f01d274511df2a9520a6a63b2fb9
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / proconf / g3d / actions / ReadAction.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.actions;\r
12 \r
13 import org.simantics.db.Graph;\r
14 import org.simantics.db.GraphRequest;\r
15 import org.simantics.db.GraphRequestAdapter;\r
16 import org.simantics.db.GraphRequestStatus;\r
17 import org.simantics.db.Session;\r
18 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
19 \r
20 public abstract class ReadAction extends ContextAction {\r
21         boolean sync;\r
22         public ReadAction(ThreeDimensionalEditorBase parent, boolean sync) {\r
23                 super(parent);\r
24                 this.sync = sync;\r
25         }\r
26 \r
27         @Override\r
28         public final void run() {\r
29                 Session session = parent.getSession();\r
30                 if(!canActivate()) {\r
31                         return;\r
32                 }\r
33                 GraphRequest r = new GraphRequestAdapter() {\r
34                         @Override\r
35                         public GraphRequestStatus perform(Graph g) throws Exception {\r
36                                 doChanges(g);\r
37                                 return GraphRequestStatus.transactionComplete();\r
38                         }\r
39                 };\r
40                 if (sync) {\r
41                         session.syncRead(r);\r
42                 } else {\r
43                         session.asyncRead(r);\r
44                 } \r
45         }\r
46         \r
47         public abstract void doChanges(Graph graph) throws Exception;\r
48 \r
49         public boolean canActivate() {\r
50                 return true;\r
51         }\r
52 }\r