1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.typicals.rules;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.WriteGraph;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.modeling.ModelingResources;
\r
19 import org.simantics.modeling.typicals.ITypicalSynchronizationRule;
\r
20 import org.simantics.modeling.typicals.TypicalInfo;
\r
21 import org.simantics.modeling.typicals.TypicalUtil;
\r
22 import org.simantics.scl.runtime.function.Function4;
\r
25 * Re-evaluates the name of the typical instance component corresponding to the
\r
26 * specified element. If the template name is not parameterized or the evaluated
\r
27 * name already matches the instance component name, the rule does nothing.
\r
28 * Otherwise it resets the instance component name.
\r
30 * @author Tuukka Lehtonen
\r
32 public enum NameRule implements ITypicalSynchronizationRule {
\r
36 public static NameRule getInstance() {
\r
41 public boolean synchronize(WriteGraph graph, Resource templateElement, Resource instanceElement, TypicalInfo info) throws DatabaseException {
\r
43 Function4<ReadGraph, Resource, Resource, String, String> namingFunction = info.bean.getAux(AuxKeys.KEY_TYPICAL_NAMING_FUNCTION);
\r
44 if (namingFunction == null)
\r
47 ModelingResources MOD = ModelingResources.getInstance(graph);
\r
48 Resource instanceComponent = graph.getPossibleObject(instanceElement, MOD.ElementToComponent);
\r
49 if (instanceComponent == null)
\r
52 boolean result = TypicalUtil.applyTypicalModuleName(graph, instanceComponent, namingFunction, null);
\r
53 if(result) info.messageLog.add("\t\t\tname");
\r