]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultLabelDecoratorsProcessor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / DefaultLabelDecoratorsProcessor.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.swt;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17
18 import org.eclipse.swt.SWT;
19 import org.simantics.browsing.ui.BuiltinKeys;
20 import org.simantics.browsing.ui.BuiltinKeys.LabelDecoratorKey;
21 import org.simantics.browsing.ui.NodeContext;
22 import org.simantics.browsing.ui.NodeContext.QueryKey;
23 import org.simantics.browsing.ui.NodeQueryManager;
24 import org.simantics.browsing.ui.common.processors.AbstractNodeQueryProcessor;
25 import org.simantics.browsing.ui.content.LabelDecorator;
26 import org.simantics.browsing.ui.content.LabelDecoratorFactory;
27
28 public class DefaultLabelDecoratorsProcessor extends AbstractNodeQueryProcessor<Collection<LabelDecorator>> {
29
30     @Override
31     public Collection<LabelDecorator> query(NodeQueryManager manager, NodeContext context) {
32         Collection<LabelDecoratorFactory> factories = manager.query(context, BuiltinKeys.SELECTED_LABEL_DECORATOR_FACTORIES);
33         if (factories.isEmpty()) {
34             LabelDecorator truncation = new TreeTruncationDecoratorFactory(SWT.BOLD).create(manager, context);
35             if (truncation != null)
36                 return Collections.singletonList(truncation);
37             return Collections.emptyList();
38         }
39
40         Collection<LabelDecorator> decorators = new ArrayList<LabelDecorator>(factories.size() + 1);
41         for (LabelDecoratorFactory f : factories) {
42             assert f != null;
43             LabelDecorator decorator = manager.query(context, new LabelDecoratorKey(f));
44             if (decorator != null)
45                 decorators.add(decorator);
46         }
47
48         LabelDecorator truncation = new TreeTruncationDecoratorFactory(SWT.BOLD).create(manager, context);
49         if (truncation != null)
50             decorators.add(truncation);
51
52         return decorators;
53     }
54
55     @Override
56     public String toString() {
57         return "LabelDecoratorsProcessor";
58     }
59
60     @Override
61     public QueryKey<Collection<LabelDecorator>> getIdentifier() {
62         return BuiltinKeys.LABEL_DECORATORS;
63     }
64
65 }