X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled.ui%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fui%2FSTSTestEditorDocumentProvider.java;fp=bundles%2Forg.simantics.tests.modelled.ui%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fui%2FSTSTestEditorDocumentProvider.java;h=ed1633c5e197c2c0a2d4945d05e75fc766808c93;hb=3b5069d0d30e7de27f73d88d5e89d29052291a34;hp=0000000000000000000000000000000000000000;hpb=bf75fd9740858140eac90c18f0bca0aea3893248;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditorDocumentProvider.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditorDocumentProvider.java new file mode 100644 index 000000000..ed1633c5e --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditorDocumentProvider.java @@ -0,0 +1,79 @@ +package org.simantics.tests.modelled.ui; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.simantics.Simantics; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ui.componentTypeEditor.SCLModuleEditorDocumentProvider; +import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew; +import org.simantics.tests.modelled.ontology.TestsResource; +import org.simantics.ui.workbench.ResourceEditorInput; +import org.simantics.utils.logging.TimeLogger; + +public class STSTestEditorDocumentProvider extends SCLModuleEditorDocumentProvider { + + public STSTestEditorDocumentProvider(SCLSourceViewerConfigurationNew sourceViewer) { + super(sourceViewer); + } + + @Override + protected IAnnotationModel createAnnotationModel(Object element) throws CoreException { + return null; + } + + @Override + protected void updateAnnotations() { + } + + @Override + protected IDocument createDocument(Object element) throws CoreException { + ResourceEditorInput input = (ResourceEditorInput)element; + resource = input.getResource(); + try { + return Simantics.getSession().syncRequest(new UniqueRead() { + @Override + public Document perform(ReadGraph graph) throws DatabaseException { + TestsResource TESTS = TestsResource.getInstance(graph); + currentText = graph.getRelatedValue(resource, TESTS.STSTest_definition, Bindings.STRING); + errorHappened = false; + return new Document(currentText != null ? currentText : ""); + } + }); + } catch (DatabaseException e) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + errorHappened = true; + return new Document(sw.toString()); + } + } + + @Override + protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException { + TimeLogger.resetTimeAndLog("STSTestEditorDocumentProvider.doSaveDocument"); + currentText = document.get(); + Simantics.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + TestsResource TESTS = TestsResource.getInstance(graph); + graph.claimLiteral(resource, TESTS.STSTest_definition, currentText, Bindings.STRING); + Layer0Utils.addCommentMetadata(graph, "Saved SCL Module " + graph.getRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING)); + } + }); + } + +}