X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;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=10d7fb21bceccf83a059c64ec79f9b4ce63aaec3;hp=ed1633c5e197c2c0a2d4945d05e75fc766808c93;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 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 index ed1633c5e..10d7fb21b 100644 --- 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 @@ -1,79 +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)); - } - }); - } - -} +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)); + } + }); + } + +}