1 package org.simantics.modeling.ui.actions;
3 import org.simantics.db.Resource;
4 import org.simantics.db.WriteGraph;
5 import org.simantics.db.common.request.WriteRequest;
6 import org.simantics.db.common.utils.NameUtils;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.adapter.ActionFactory;
9 import org.simantics.document.DocumentResource;
10 import org.simantics.layer0.Layer0;
11 import org.simantics.ui.SimanticsUI;
13 public class NewDocument implements ActionFactory {
16 public Runnable create(Object target) {
17 if(!(target instanceof Resource))
19 final Resource model = (Resource)target;
20 return new Runnable() {
24 SimanticsUI.getSession().asyncRequest(new WriteRequest() {
26 public void perform(WriteGraph graph) throws DatabaseException {
27 graph.markUndoPoint();
29 Layer0 L0 = Layer0.getInstance(graph);
30 DocumentResource DOC = DocumentResource.getInstance(graph);
32 String name = NameUtils.findFreshEscapedName(graph, "Document", model, L0.ConsistsOf);
34 // Create DOC.WikiDocument instance
35 Resource wikiDocument = graph.newResource();
36 graph.claim(wikiDocument, L0.InstanceOf, DOC.WikiDocument);
37 graph.claim(wikiDocument, L0.PartOf, model);
38 graph.claimLiteral(wikiDocument, L0.HasName, name);
40 // Bind an empty document scene graph to the new :DOC.WikiDocument
41 Resource documentType = graph.getSingleObject(DOC.WikiDocument_WikiDocumentBinding, DOC.DocumentTypeBinding_HasDocumentType);
42 Resource document = graph.newResource();
43 graph.claim(document, L0.InstanceOf, null, DOC.ScenegraphDocument);
44 graph.claimLiteral(document, L0.HasName, "Documentation");
45 graph.claim(wikiDocument, DOC.HasDocumentation, document);
46 graph.claim(document, L0.PartOf, wikiDocument);
48 Resource scenegraph = graph.newResource();
49 graph.claim(scenegraph, L0.InstanceOf, null, documentType);
50 graph.claimLiteral(scenegraph, L0.HasName, "Scenegraph");
51 graph.claim(scenegraph, L0.PartOf, document);
52 graph.claim(document, DOC.ScenegraphDocument_scenegraph, scenegraph);