]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/FlagSynchronizer.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / FlagSynchronizer.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.synchronization.graph;
13
14 import org.simantics.db.Resource;
15 import org.simantics.diagram.synchronization.IModificationQueue;
16 import org.simantics.diagram.synchronization.ISynchronizationContext;
17 import org.simantics.g2d.elementclass.FlagClass;
18 import org.simantics.utils.datastructures.hints.IHintObservable;
19 import org.simantics.utils.datastructures.hints.IHintContext.Key;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public class FlagSynchronizer extends ResourceSynchronizer {
25
26     public static final FlagSynchronizer INSTANCE = new FlagSynchronizer();
27
28     protected static final Key[] SYNCHRONIZED_HINTS = {
29         FlagClass.KEY_FLAG_TYPE,
30     };
31
32     @Override
33     public Key[] getSynchronizedHints() {
34         return SYNCHRONIZED_HINTS;
35     }
36
37     @Override
38     public boolean hintChanged(ISynchronizationContext context, IModificationQueue queue, Resource object, IHintObservable sender, Key key, Object oldValue, Object newValue) {
39         BasicResources br = context.get(GraphSynchronizationHints.BASIC_RESOURCES);
40         if (FlagClass.KEY_FLAG_TYPE.equals(key)) {
41             FlagClass.Type type = (FlagClass.Type) newValue;
42             return queue.offer(new EnumerationModification(object, br.DIA.HasFlagType, DiagramGraphUtil.toFlagTypeResource(br.DIA, type)));
43         }
44
45         return super.hintChanged(context, sender, key, oldValue, newValue);
46     }
47
48 }