]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphLabelerFactory.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / GraphLabelerFactory.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.graph.impl;\r
13 \r
14 import java.util.Map;\r
15 \r
16 import org.simantics.browsing.ui.BuiltinKeys;\r
17 import org.simantics.browsing.ui.NodeContext;\r
18 import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
19 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;\r
20 import org.simantics.browsing.ui.GraphExplorer.ModificationContext;\r
21 import org.simantics.browsing.ui.content.Labeler;\r
22 import org.simantics.browsing.ui.content.LabelerFactory;\r
23 import org.simantics.browsing.ui.content.Labeler.Modifier;\r
24 import org.simantics.db.ReadGraph;\r
25 import org.simantics.db.Resource;\r
26 import org.simantics.db.exception.DatabaseException;\r
27 \r
28 public abstract class GraphLabelerFactory implements LabelerFactory {\r
29 \r
30     @Override\r
31     public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {\r
32 \r
33         assert(updater != null);\r
34         assert(context != null);\r
35 \r
36         return new LazyGraphLabeler(updater, context, key) {\r
37             @Override\r
38             public Map<String, String> labels(ReadGraph graph) throws DatabaseException {\r
39                 return GraphLabelerFactory.this.labels(graph, (Resource) context.getConstant(BuiltinKeys.INPUT));\r
40             }\r
41 \r
42             @Override\r
43             public int category(ReadGraph graph) throws DatabaseException {\r
44                 return GraphLabelerFactory.this.category(graph, (Resource) context.getConstant(BuiltinKeys.INPUT));\r
45             }\r
46             \r
47             @Override\r
48             public String toString() {\r
49                 return GraphLabelerFactory.this.toString();\r
50             }\r
51             \r
52             @Override\r
53             public Modifier getModifier(ModificationContext modificationContext, String key) {\r
54                 return GraphLabelerFactory.this.getModifier(key);\r
55             }\r
56             \r
57         };\r
58     }\r
59 \r
60     abstract protected Map<String, String> labels(ReadGraph graph, Resource resource) throws DatabaseException;\r
61     \r
62     protected int category(ReadGraph graph, Resource resource) throws DatabaseException {\r
63         return 0;\r
64     }\r
65 \r
66     protected Modifier getModifier(String key) {\r
67         return null;\r
68     }\r
69     \r
70 }\r