1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.adapters;
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;
24 * @author Tuukka Lehtonen
26 public class ConnectionRelationStringModifierFactory implements StringModifierFactory {
28 private Resource subject;
30 public ConnectionRelationStringModifierFactory(Resource subject) throws DatabaseException {
31 this.subject = subject;
35 public StringModifier createModifier(ReadGraph graph, Resource relation, Resource property) throws DatabaseException {
36 Layer0 L0 = Layer0.getInstance(graph);
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);