]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/processors/DefaultLabelerFactoriesProcessor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / processors / DefaultLabelerFactoriesProcessor.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.common.processors;
13
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.Map;
17
18 import org.simantics.browsing.ui.BuiltinKeys;
19 import org.simantics.browsing.ui.NodeContext;
20 import org.simantics.browsing.ui.NodeQueryManager;
21 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
22 import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;
23 import org.simantics.browsing.ui.GraphExplorer.ModificationContext;
24 import org.simantics.browsing.ui.NodeContext.QueryKey;
25 import org.simantics.browsing.ui.content.Labeler;
26 import org.simantics.browsing.ui.content.LabelerFactory;
27
28 public class DefaultLabelerFactoriesProcessor extends AbstractNodeQueryProcessor<Collection<LabelerFactory>> {
29
30     int koss;
31
32     @Override
33     public QueryKey<Collection<LabelerFactory>> getIdentifier() {
34         return BuiltinKeys.LABELER_FACTORIES;
35     }
36
37     @Override
38     public Collection<LabelerFactory> query(NodeQueryManager manager, NodeContext context) {
39         return Collections.singleton((LabelerFactory) new LabelerFactory() {
40             @Override
41             public Labeler create(PrimitiveQueryUpdater updater, final NodeContext context, LabelerKey key) {
42
43                 if (++koss % 1000 == 0)
44                     System.out.println("Produced " + koss + " labels");
45
46                 return new Labeler() {
47                     @Override
48                     public Map<String, String> getLabels() {
49                         return Collections.singletonMap("single", context.getConstant(BuiltinKeys.INPUT).toString());
50                     }
51                     @Override
52                     public Map<String, String> getRuntimeLabels() {
53                         return Collections.emptyMap();
54                     }
55                     @Override
56                     public int getCategory() {
57                         return 0;
58                     }
59                     @Override
60                     public Modifier getModifier(ModificationContext modificationContext, String key) {
61                         return null;
62                     }
63                     @Override
64                     public void setListener(LabelerListener listener) {
65                         // Intentionally blank, cannot implement listening.
66                     }
67                 };
68             }
69         });
70     }
71
72     @Override
73     public String toString() {
74         return "LabelerFactoriesProcessor";
75     }
76
77 }