]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/contributor/labeler/ContextColumnFinalLabelerContributorImpl.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 / contributor / labeler / ContextColumnFinalLabelerContributorImpl.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.contributor.labeler;
13
14 import java.util.Map;
15
16 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
17 import org.simantics.browsing.ui.NodeContext;
18 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
19 import org.simantics.browsing.ui.Tester;
20 import org.simantics.browsing.ui.content.Contributor;
21 import org.simantics.browsing.ui.content.Labeler;
22 import org.simantics.browsing.ui.content.Labeler.Modifier;
23 import org.simantics.browsing.ui.content.LabelerFactory;
24 import org.simantics.browsing.ui.graph.impl.contribution.FinalLabelerContributionImpl;
25 import org.simantics.db.ReadGraph;
26 import org.simantics.db.UndoContext;
27 import org.simantics.db.exception.DatabaseException;
28
29 abstract public class ContextColumnFinalLabelerContributorImpl implements Contributor<LabelerFactory> {
30
31     abstract public Map<String, String> getLabel(ReadGraph graph, NodeContext input) throws DatabaseException;
32
33     public int getCategory(ReadGraph graph, NodeContext input) throws DatabaseException {
34         return 0;
35     }
36
37     public Modifier getModifier(ReadGraph graph, NodeContext input, String columnKey) throws DatabaseException {
38         return null;
39     }
40
41     final private Class<?> clazz;
42
43     @Override
44     public Tester getNodeContextTester() {
45         return null;
46     }
47
48     public ContextColumnFinalLabelerContributorImpl() {
49         clazz = Object.class;
50     }
51
52     public ContextColumnFinalLabelerContributorImpl(Class<?> clazz) {
53         this.clazz = clazz;
54     }
55
56     @Override
57     public LabelerFactory getFactory() {
58
59         return new LabelerFactory() {
60
61             @Override
62             public Labeler create(final PrimitiveQueryUpdater updater, NodeContext context, final LabelerKey key) {
63
64                 return new FinalLabelerContributionImpl(updater, context, key) {
65
66                     @Override
67                     public Map<String, String> labels(ReadGraph graph, NodeContext context) throws DatabaseException {
68
69                         return ContextColumnFinalLabelerContributorImpl.this.getLabel(graph, context);
70
71                     }
72
73
74                     @Override
75                     public Modifier getModifier(ReadGraph graph, UndoContext undoContext, NodeContext context, String columnKey) throws DatabaseException {
76
77                         return ContextColumnFinalLabelerContributorImpl.this.getModifier(graph, context, columnKey);
78
79                     }
80
81                     @Override
82                     public int category(ReadGraph graph, NodeContext context) throws DatabaseException {
83
84                         return ContextColumnFinalLabelerContributorImpl.this.getCategory(graph, context);
85
86                     }
87
88                     @Override
89                     public String toString() {
90                         return ContextColumnFinalLabelerContributorImpl.this.toString();
91                     }
92
93                 };
94
95             }
96
97         };
98
99     }
100
101     @Override
102     public Class<?> getInputClass() {
103         return clazz;
104     }
105
106 }