X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FcomponentTypeEditor%2FPGraphEditorDocumentProvider.java;h=39152636b0e80aab3d9b18eaa439ce26ca839cf1;hp=69449fd8f0f7c2bdf86acee536af1f86d630240d;hb=aea3e7b117a8398471f10c31844efffc8026f815;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java index 69449fd8f..39152636b 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java @@ -20,12 +20,18 @@ import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.ReadRequest; 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.graph.refactoring.GraphRefactoringUtils; +import org.simantics.graph.representation.PrettyPrintTG; +import org.simantics.graph.representation.TransferableGraph1; import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingUtils; +import org.simantics.modeling.ui.sharedontology.wizard.Constants; import org.simantics.scl.compiler.errors.CompilationError; import org.simantics.scl.compiler.errors.Locations; import org.simantics.ui.workbench.ResourceEditorInput; @@ -48,9 +54,24 @@ public class PGraphEditorDocumentProvider extends AbstractDocumentProvider { @Override public Document perform(ReadGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); - currentText = graph.getRelatedValue(resource, L0.PGraph_definition, Bindings.STRING); - errorHappened = false; - return new Document(currentText != null ? currentText : ""); + if(graph.isInstanceOf(resource, L0.PGraph)) { + currentText = graph.getRelatedValue(resource, L0.PGraph_definition, Bindings.STRING); + errorHappened = false; + return new Document(currentText != null ? currentText : ""); + } else { + Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(resource)); + try { + if(indexRoot != null && graph.isInstanceOf(indexRoot, L0.Ontology)) { + TransferableGraph1 tg = ModelingUtils.exportSharedOntology(graph, indexRoot, null, Constants.SHARED_LIBRARY_FORMAT, Constants.SHARED_LIBRARY_CURRENT_VERSION); + GraphRefactoringUtils.fixOntologyExport(tg); + currentText = PrettyPrintTG.print(tg, false); + errorHappened = false; + } + return new Document(currentText != null ? currentText : ""); + } catch (Exception e) { + throw new DatabaseException("Could not get PGraph from " + resource); + } + } } }); } catch (DatabaseException e) {