]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagStringModifierFactory.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / flag / FlagStringModifierFactory.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.flag;
13
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.layer0.Layer0;
20
21 /**
22  * Makes sure that two things apply:
23  * <ol>
24  * <li>If a flag is joined with another flag, both flags must have the same label property</li>
25  * <li>A flag's label is unique within its own diagram</li>
26  * </ol> 
27  * @author Tuukka Lehtonen
28  */
29 public final class FlagStringModifierFactory implements StringModifierFactory {
30
31     private Resource subject;
32
33     public FlagStringModifierFactory(ReadGraph graph, Resource subject) throws DatabaseException {
34         this.subject = subject;
35     }
36
37     @Override
38     public StringModifier createModifier(ReadGraph graph, Resource relation, Resource property) throws DatabaseException {
39 //        System.out.println(NameUtils.getSafeName(graph, subject));
40 //        System.out.println(NameUtils.getSafeName(graph, relation));
41 //        System.out.println(NameUtils.getSafeName(graph, property));
42         Layer0 L0 = Layer0.getInstance(graph);
43         if (L0.HasLabel.equals(relation)) {
44             return new FlagLabelModifier(graph, subject, relation, property);
45         }
46         return null;
47     }
48
49 }