]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/NewSymbolGroupRequest.java
Symbol code style into platform
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / NewSymbolGroupRequest.java
1 package org.simantics.modeling;
2
3 import org.simantics.db.Resource;
4 import org.simantics.db.WriteGraph;
5 import org.simantics.db.common.request.WriteResultRequest;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.diagram.stubs.DiagramResource;
8 import org.simantics.layer0.Layer0;
9
10 public class NewSymbolGroupRequest extends WriteResultRequest<Resource> {
11     String name;
12     Resource model;
13     Resource symbolGroup;
14
15     public NewSymbolGroupRequest(String name, Resource model) {
16         this.name = name;
17         this.model = model;
18     }
19
20     @Override
21     public Resource perform(WriteGraph graph) throws DatabaseException {
22         return createNewSymbolGroup(graph, model, name);
23     }
24     
25     public static Resource createNewSymbolGroup(WriteGraph graph, Resource model, String name) throws DatabaseException {
26         Layer0 L0 = Layer0.getInstance(graph);
27         DiagramResource DIA = DiagramResource.getInstance(graph);
28
29         // Symbol group
30         Resource symbolGroup = graph.newResource();
31         graph.claim(symbolGroup, L0.PartOf, model);    
32         graph.claim(symbolGroup, L0.InstanceOf, DIA.SymbolReferenceLibrary);
33
34         // Name
35         graph.claimLiteral(symbolGroup, L0.HasName, name);
36         return symbolGroup;
37     }
38 }