--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.proconf.g3d.actions;\r
+\r
+import org.simantics.db.Graph;\r
+import org.simantics.db.GraphRequest;\r
+import org.simantics.db.GraphRequestAdapter;\r
+import org.simantics.db.GraphRequestStatus;\r
+import org.simantics.db.Session;\r
+import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
+\r
+public abstract class ReadAction extends ContextAction {\r
+ boolean sync;\r
+ public ReadAction(ThreeDimensionalEditorBase parent, boolean sync) {\r
+ super(parent);\r
+ this.sync = sync;\r
+ }\r
+\r
+ @Override\r
+ public final void run() {\r
+ Session session = parent.getSession();\r
+ if(!canActivate()) {\r
+ return;\r
+ }\r
+ GraphRequest r = new GraphRequestAdapter() {\r
+ @Override\r
+ public GraphRequestStatus perform(Graph g) throws Exception {\r
+ doChanges(g);\r
+ return GraphRequestStatus.transactionComplete();\r
+ }\r
+ };\r
+ if (sync) {\r
+ session.syncRead(r);\r
+ } else {\r
+ session.asyncRead(r);\r
+ } \r
+ }\r
+ \r
+ public abstract void doChanges(Graph graph) throws Exception;\r
+\r
+ public boolean canActivate() {\r
+ return true;\r
+ }\r
+}\r