]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************
2  * Copyright (c) 2017 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.scl.scriptEditor;
13
14 import org.simantics.Simantics;
15 import org.simantics.db.exception.DatabaseException;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * @author Tuukka Lehtonen
21  * @since 1.31.0
22  */
23 class SCLScriptSource {
24
25     private static final Logger LOGGER = LoggerFactory.getLogger(SCLScriptSource.class);
26
27     private String scriptURI;
28     private String scriptText;
29
30     public SCLScriptSource(String scriptURI, String scriptText) {
31         this.scriptURI = scriptURI;
32         this.scriptText = scriptText;
33     }
34
35     public void update(String newSourceText) {
36         try {
37             Simantics.getSession().syncRequest(new WriteSCLScriptDefinition(scriptURI, newSourceText));
38         } catch (DatabaseException e) {
39             LOGGER.error("Failed to write SCL script source from " + scriptURI, e);
40         }
41     }
42
43     public boolean isUpdateable() {
44         return true;
45     }
46
47     public String getSourceText() {
48         return scriptText;
49     }
50
51     public String getScriptURI() {
52         return scriptURI;
53     }
54
55 }