]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptSource.java
Support for SCL script database storage, editing and execution
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / scl / scriptEditor / SCLScriptSource.java
diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptSource.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/SCLScriptSource.java
new file mode 100644 (file)
index 0000000..87c74b7
--- /dev/null
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.ui.scl.scriptEditor;
+
+import org.simantics.Simantics;
+import org.simantics.db.exception.DatabaseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.31.0
+ */
+class SCLScriptSource {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(SCLScriptSource.class);
+
+    private String scriptURI;
+    private String scriptText;
+
+    public SCLScriptSource(String scriptURI, String scriptText) {
+        this.scriptURI = scriptURI;
+        this.scriptText = scriptText;
+    }
+
+    public void update(String newSourceText) {
+        try {
+            Simantics.getSession().syncRequest(new WriteSCLScriptDefinition(scriptURI, newSourceText));
+        } catch (DatabaseException e) {
+            LOGGER.error("Failed to write SCL script source from " + scriptURI, e);
+        }
+    }
+
+    public boolean isUpdateable() {
+        return true;
+    }
+
+    public String getSourceText() {
+        return scriptText;
+    }
+
+    public String getScriptURI() {
+        return scriptURI;
+    }
+
+}
\ No newline at end of file