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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.swt;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
16 import java.util.Collections;
\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
28 public class DefaultLabelDecoratorsProcessor extends AbstractNodeQueryProcessor<Collection<LabelDecorator>> {
\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
40 Collection<LabelDecorator> decorators = new ArrayList<LabelDecorator>(factories.size() + 1);
\r
41 for (LabelDecoratorFactory f : factories) {
\r
43 LabelDecorator decorator = manager.query(context, new LabelDecoratorKey(f));
\r
44 if (decorator != null)
\r
45 decorators.add(decorator);
\r
48 LabelDecorator truncation = new TreeTruncationDecoratorFactory(SWT.BOLD).create(manager, context);
\r
49 if (truncation != null)
\r
50 decorators.add(truncation);
\r
56 public String toString() {
\r
57 return "LabelDecoratorsProcessor";
\r
61 public QueryKey<Collection<LabelDecorator>> getIdentifier() {
\r
62 return BuiltinKeys.LABEL_DECORATORS;
\r