]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultLabelDecoratorsProcessor.java
Merge remote-tracking branch 'origin/svn' commit 'ccc1271c9d6657fb9dcf4cf3cb115fa0c8c...
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / DefaultLabelDecoratorsProcessor.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.swt;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.Collections;\r
17 \r
18 import org.eclipse.swt.SWT;\r
19 import org.simantics.browsing.ui.BuiltinKeys;\r
20 import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;\r
21 import org.simantics.browsing.ui.NodeContext;\r
22 import org.simantics.browsing.ui.NodeContext.QueryKey;\r
23 import org.simantics.browsing.ui.NodeQueryManager;\r
24 import org.simantics.browsing.ui.common.processors.AbstractNodeQueryProcessor;\r
25 import org.simantics.browsing.ui.content.LabelDecorator;\r
26 import org.simantics.browsing.ui.content.LabelDecoratorFactory;\r
27 \r
28 public class DefaultLabelDecoratorsProcessor extends AbstractNodeQueryProcessor<Collection<LabelDecorator>> {\r
29 \r
30     @Override\r
31     public Collection<LabelDecorator> query(NodeQueryManager manager, NodeContext context) {\r
32         Collection<LabelDecoratorFactory> factories = manager.query(context, BuiltinKeys.SELECTED_LABEL_DECORATOR_FACTORIES);\r
33         if (factories.isEmpty()) {\r
34             LabelDecorator truncation = new TreeTruncationDecoratorFactory(SWT.BOLD).create(manager, context);\r
35             if (truncation != null)\r
36                 return Collections.singletonList(truncation);\r
37             return Collections.emptyList();\r
38         }\r
39 \r
40         Collection<LabelDecorator> decorators = new ArrayList<LabelDecorator>(factories.size() + 1);\r
41         for (LabelDecoratorFactory f : factories) {\r
42             assert f != null;\r
43             LabelDecorator decorator = manager.query(context, new LabelDecoratorKey(f));\r
44             if (decorator != null)\r
45                 decorators.add(decorator);\r
46         }\r
47 \r
48         LabelDecorator truncation = new TreeTruncationDecoratorFactory(SWT.BOLD).create(manager, context);\r
49         if (truncation != null)\r
50             decorators.add(truncation);\r
51 \r
52         return decorators;\r
53     }\r
54 \r
55     @Override\r
56     public String toString() {\r
57         return "LabelDecoratorsProcessor";\r
58     }\r
59 \r
60     @Override\r
61     public QueryKey<Collection<LabelDecorator>> getIdentifier() {\r
62         return BuiltinKeys.LABEL_DECORATORS;\r
63     }\r
64 \r
65 }\r