1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.structural.ui.adapters;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.utils.CommonDBUtils;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.adapter.Template;
22 import org.simantics.diagram.stubs.DiagramResource;
23 import org.simantics.layer0.Layer0;
24 import org.simantics.modeling.ModelingResources;
25 import org.simantics.operation.Layer0X;
27 public class DiagramTemplate implements Template {
31 public DiagramTemplate(Resource template) {
32 this.template = template;
36 public void apply(WriteGraph g, Map<String, Object> parameters)
37 throws DatabaseException {
38 Layer0 l0 = Layer0.getInstance(g);
39 Layer0X L0X = Layer0X.getInstance(g);
40 DiagramResource DIA = DiagramResource.getInstance(g);
41 ModelingResources mr = ModelingResources.getInstance(g);
43 Resource composite = (Resource)parameters.get("");
44 CommonDBUtils.selectClusterSet(g, composite);
46 Resource diagramType = g.getSingleObject(template, mr.HasDiagramType);
48 Resource diagram = (Resource)parameters.get("diagram");
49 if (diagram == null) {
50 diagram = g.newResource();
51 parameters.put("diagram", diagram);
57 // Resource descriptionType = g.getPossibleObject(template, mr.HasDefaultDocumentType);
58 // if(descriptionType != null) {
59 // DocumentResource DOC = DocumentResource.getInstance(g);
60 // Resource description = g.newResource();
61 // g.claim(description, l0.InstanceOf, null, descriptionType);
62 // g.claimLiteral(description, l0.HasName, "Description");
63 // g.claim(description, l0.PartOf, composite);
64 // g.claim(composite, DOC.HasDocument, description);
67 g.claim(diagram, l0.InstanceOf, null, diagramType);
68 g.claim(diagram, l0.SubrelationOf, null, l0.HasNext);
69 g.claim(diagram, mr.DiagramToComposite, composite);
70 Resource diagramInv = g.newResource();
71 g.claim(diagramInv, l0.InverseOf, diagram);
72 g.claim(diagramInv, l0.SubrelationOf, null, l0.HasPrevious);
73 g.claim(diagram, diagram, diagramInv, diagram);
74 Resource mapping = g.newResource();
75 g.claim(diagram, L0X.HasTrigger, mapping);
77 Resource mappingType = g.getPossibleObject(template, mr.DiagramTemplate_HasMappingType);
78 if(mappingType != null) {
79 g.claim(mapping, l0.InstanceOf, mappingType);
82 String name = (String) parameters.get("name");
85 g.claimLiteral(diagram, l0.HasName, name, Bindings.STRING);
87 // Make diagram part of a dummy container entity attached to the parent
88 // composite if it's not already part of something.
89 if (!g.hasStatement(diagram, l0.PartOf)) {
90 Resource container = g.newResource();
91 g.claim(container, l0.InstanceOf, null, DIA.DiagramContainer);
92 g.addLiteral(container, l0.HasName, l0.NameOf, l0.String, "__CONTAINER__", Bindings.STRING);
93 g.claim(container, l0.ConsistsOf, diagram);
94 g.claim(composite, l0.ConsistsOf, container);