]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphLabelerFactory.java
Replace System.err and System.out with SLF4J Logging
[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 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public abstract class GraphLabelerFactory implements LabelerFactory {
31
32     @Override
33     public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {
34
35         assert(updater != null);
36         assert(context != null);
37
38         return new LazyGraphLabeler(updater, context, key) {
39             @Override
40             public Map<String, String> labels(ReadGraph graph) throws DatabaseException {
41                 return GraphLabelerFactory.this.labels(graph, (Resource) context.getConstant(BuiltinKeys.INPUT));
42             }
43
44             @Override
45             public int category(ReadGraph graph) throws DatabaseException {
46                 return GraphLabelerFactory.this.category(graph, (Resource) context.getConstant(BuiltinKeys.INPUT));
47             }
48             
49             @Override
50             public String toString() {
51                 return GraphLabelerFactory.this.toString();
52             }
53             
54             @Override
55             public Modifier getModifier(ModificationContext modificationContext, String key) {
56                 return GraphLabelerFactory.this.getModifier(key);
57             }
58
59             @Override
60             public Logger getLogger() {
61                 return LoggerFactory.getLogger(GraphLabelerFactory.class);
62             }
63             
64         };
65     }
66
67     abstract protected Map<String, String> labels(ReadGraph graph, Resource resource) throws DatabaseException;
68     
69     protected int category(ReadGraph graph, Resource resource) throws DatabaseException {
70         return 0;
71     }
72
73     protected Modifier getModifier(String key) {
74         return null;
75     }
76     
77 }