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