]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/scl/scriptEditor/WriteSCLScriptDefinition.java
Better support for customisation of scene graph provider
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / scl / scriptEditor / WriteSCLScriptDefinition.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.databoard.Bindings;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.WriteRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.layer0.Layer0;
20
21 /**
22  * @author Tuukka Lehtonen
23  * @since 1.31.0
24  */
25 public class WriteSCLScriptDefinition extends WriteRequest {
26
27     private final String scriptURI;
28     private final String definition;
29
30     public WriteSCLScriptDefinition(String scriptURI, String sourceText) {
31         this.scriptURI = scriptURI;
32         this.definition = sourceText;
33     }
34
35     @Override
36     public void perform(WriteGraph graph) throws DatabaseException {
37         Resource moduleResource = graph.getPossibleResource(scriptURI);
38         if (moduleResource == null)
39             return;
40         Layer0 L0 = Layer0.getInstance(graph);
41         if (!graph.isInstanceOf(moduleResource, L0.SCLScript))
42             return;
43         graph.claimLiteral(moduleResource, L0.SCLScript_definition, definition, Bindings.STRING);
44     }
45
46 }