]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ConnectionRelationStringModifierFactory.java
Find SCL references in SCLModuleEditor with Ctrl+Shift+G
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / ConnectionRelationStringModifierFactory.java
1 /*******************************************************************************
2  * Copyright (c) 2014 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.adapters;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.db.layer0.adapter.StringModifier;
18 import org.simantics.db.layer0.adapter.StringModifierFactory;
19 import org.simantics.db.layer0.adapter.impl.RelatedEntityNameModifier;
20 import org.simantics.layer0.Layer0;
21 import org.simantics.modeling.ModelingResources;
22
23 /**
24  * @author Tuukka Lehtonen
25  */
26 public class ConnectionRelationStringModifierFactory implements StringModifierFactory {
27
28         private Resource subject;
29
30         public ConnectionRelationStringModifierFactory(Resource subject) throws DatabaseException {
31                 this.subject = subject;
32         }
33
34         @Override
35         public StringModifier createModifier(ReadGraph graph, Resource relation, Resource property) throws DatabaseException {
36                 Layer0 L0 = Layer0.getInstance(graph);
37
38                 // Names require special care in validation and modification.
39                 if (L0.HasName.equals(relation)) {
40                         // Always rename all (configuration and diagram) connection relations 
41                         ModelingResources MOD = ModelingResources.getInstance(graph);
42                         Resource connectionRelation = graph.getPossibleObject(subject, MOD.DiagramConnectionRelationToConnectionRelation);
43                         Resource subject = connectionRelation != null ? connectionRelation : this.subject;
44                         return new RelatedEntityNameModifier(graph, subject, property, MOD.ConnectionRelationToDiagramConnectionRelation);
45                 }
46
47                 return null;
48         }
49
50 }