1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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.modeling.typicals.rules;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.modeling.ModelingResources;
19 import org.simantics.modeling.typicals.ITypicalSynchronizationRule;
20 import org.simantics.modeling.typicals.TypicalInfo;
21 import org.simantics.modeling.typicals.TypicalUtil;
22 import org.simantics.scl.runtime.function.Function4;
25 * Re-evaluates the name of the typical instance component corresponding to the
26 * specified element. If the template name is not parameterized or the evaluated
27 * name already matches the instance component name, the rule does nothing.
28 * Otherwise it resets the instance component name.
30 * @author Tuukka Lehtonen
32 public enum NameRule implements ITypicalSynchronizationRule {
36 public static NameRule getInstance() {
41 public boolean synchronize(WriteGraph graph, Resource templateElement, Resource instanceElement, TypicalInfo info) throws DatabaseException {
43 Function4<ReadGraph, Resource, Resource, String, String> namingFunction = info.bean.getAux(AuxKeys.KEY_TYPICAL_NAMING_FUNCTION);
44 if (namingFunction == null)
47 ModelingResources MOD = ModelingResources.getInstance(graph);
48 Resource instanceComponent = graph.getPossibleObject(instanceElement, MOD.ElementToComponent);
49 if (instanceComponent == null)
52 boolean result = TypicalUtil.applyTypicalModuleName(graph, instanceComponent, namingFunction, null);
53 if(result) info.messageLog.add("\t\t\tname");