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.swt;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
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;
28 public class DefaultLabelDecoratorsProcessor extends AbstractNodeQueryProcessor<Collection<LabelDecorator>> {
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();
40 Collection<LabelDecorator> decorators = new ArrayList<LabelDecorator>(factories.size() + 1);
41 for (LabelDecoratorFactory f : factories) {
43 LabelDecorator decorator = manager.query(context, new LabelDecoratorKey(f));
44 if (decorator != null)
45 decorators.add(decorator);
48 LabelDecorator truncation = new TreeTruncationDecoratorFactory(SWT.BOLD).create(manager, context);
49 if (truncation != null)
50 decorators.add(truncation);
56 public String toString() {
57 return "LabelDecoratorsProcessor";
61 public QueryKey<Collection<LabelDecorator>> getIdentifier() {
62 return BuiltinKeys.LABEL_DECORATORS;