1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.graph.impl.contributor.labeler;
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.LabelerContributionImpl;
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;
31 abstract public class ContextLabelerContributorImpl implements Contributor<LabelerFactory> {
33 abstract public String getLabel(ReadGraph graph, NodeContext input) throws DatabaseException;
35 public int getCategory(ReadGraph graph, NodeContext input) throws DatabaseException {
39 public Modifier getModifier(ReadGraph graph, NodeContext input, String columnKey) throws DatabaseException {
43 final private Class<?> clazz;
46 public Tester getNodeContextTester() {
50 public ContextLabelerContributorImpl() {
54 public ContextLabelerContributorImpl(Class<?> clazz) {
59 public LabelerFactory getFactory() {
61 return new LabelerFactory() {
64 public Labeler create(final PrimitiveQueryUpdater updater, NodeContext context, final LabelerKey key) {
66 return new LabelerContributionImpl(updater, context, key) {
69 public Map<String, String> labels(ReadGraph graph, NodeContext context) throws DatabaseException {
71 String value = ContextLabelerContributorImpl.this.getLabel(graph, context);
73 return new ArrayMap<String, String>(ColumnKeys.KEYS_SINGLE,
74 new String[] { value });
79 public Modifier getModifier(ReadGraph graph, UndoContext undoContext, NodeContext context, String columnKey) throws DatabaseException {
81 return ContextLabelerContributorImpl.this.getModifier(graph, context, columnKey);
86 public int category(ReadGraph graph, NodeContext context) throws DatabaseException {
88 return ContextLabelerContributorImpl.this.getCategory(graph, context);
93 public String toString() {
94 return ContextLabelerContributorImpl.this.toString();
106 public Class<?> getInputClass() {