1 /*******************************************************************************
\r
2 * Copyright (c) 2010 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.sysdyn.ui.elements;
\r
14 import org.simantics.databoard.Bindings;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.Session;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.diagram.synchronization.IModificationQueue;
\r
19 import org.simantics.diagram.synchronization.ISynchronizationContext;
\r
20 import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
\r
21 import org.simantics.diagram.synchronization.graph.RelatedPropertyModification;
\r
22 import org.simantics.diagram.synchronization.graph.ResourceSynchronizer;
\r
23 import org.simantics.g2d.element.ElementHints;
\r
24 import org.simantics.layer0.Layer0;
\r
25 import org.simantics.modeling.ModelingResources;
\r
26 import org.simantics.utils.datastructures.hints.IHintContext.Key;
\r
27 import org.simantics.utils.datastructures.hints.IHintObservable;
\r
30 * @author Tuukka Lehtonen
\r
32 public class ComponentNameSynchronizer extends ResourceSynchronizer {
\r
34 public static final ComponentNameSynchronizer INSTANCE = new ComponentNameSynchronizer();
\r
36 private static final Key[] SYNCHRONIZED_HINTS = {
\r
37 ElementHints.KEY_TEXT
\r
41 public Key[] getSynchronizedHints() {
\r
42 return SYNCHRONIZED_HINTS;
\r
46 public boolean hintChanged(ISynchronizationContext context, IModificationQueue queue, Resource object, IHintObservable sender, Key key, Object oldValue, Object newValue) {
\r
47 if (ElementHints.KEY_TEXT.equals(key)) {
\r
48 Session session = context.get(GraphSynchronizationHints.SESSION);
\r
51 l0 = Layer0.getInstance(session);
\r
52 ModelingResources mr = session.getService(ModelingResources.class);
\r
53 return queue.offer(new RelatedPropertyModification(object, mr.ElementToComponent, l0.HasName, l0.String, newValue, Bindings.STRING), null);
\r
54 } catch (DatabaseException e) {
\r
55 e.printStackTrace();
\r