]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphLabelerFactory.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / GraphLabelerFactory.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.browsing.ui.graph.impl;
13
14 import java.util.Map;
15
16 import org.simantics.browsing.ui.BuiltinKeys;
17 import org.simantics.browsing.ui.NodeContext;
18 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
19 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
20 import org.simantics.browsing.ui.GraphExplorer.ModificationContext;
21 import org.simantics.browsing.ui.content.Labeler;
22 import org.simantics.browsing.ui.content.LabelerFactory;
23 import org.simantics.browsing.ui.content.Labeler.Modifier;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.Resource;
26 import org.simantics.db.exception.DatabaseException;
27
28 public abstract class GraphLabelerFactory implements LabelerFactory {
29
30     @Override
31     public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {
32
33         assert(updater != null);
34         assert(context != null);
35
36         return new LazyGraphLabeler(updater, context, key) {
37             @Override
38             public Map<String, String> labels(ReadGraph graph) throws DatabaseException {
39                 return GraphLabelerFactory.this.labels(graph, (Resource) context.getConstant(BuiltinKeys.INPUT));
40             }
41
42             @Override
43             public int category(ReadGraph graph) throws DatabaseException {
44                 return GraphLabelerFactory.this.category(graph, (Resource) context.getConstant(BuiltinKeys.INPUT));
45             }
46             
47             @Override
48             public String toString() {
49                 return GraphLabelerFactory.this.toString();
50             }
51             
52             @Override
53             public Modifier getModifier(ModificationContext modificationContext, String key) {
54                 return GraphLabelerFactory.this.getModifier(key);
55             }
56             
57         };
58     }
59
60     abstract protected Map<String, String> labels(ReadGraph graph, Resource resource) throws DatabaseException;
61     
62     protected int category(ReadGraph graph, Resource resource) throws DatabaseException {
63         return 0;
64     }
65
66     protected Modifier getModifier(String key) {
67         return null;
68     }
69     
70 }