1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
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.model.imagedecorators;
14 import org.simantics.browsing.ui.BuiltinKeys;
15 import org.simantics.browsing.ui.NodeContext;
16 import org.simantics.browsing.ui.content.ImageDecorator;
17 import org.simantics.browsing.ui.model.InvalidContribution;
18 import org.simantics.browsing.ui.model.nodetypes.NodeType;
19 import org.simantics.browsing.ui.model.tests.Test;
20 import org.simantics.browsing.ui.model.visuals.VisualsContribution;
21 import org.simantics.db.ReadGraph;
22 import org.simantics.db.exception.DatabaseException;
25 * Produces image decorators for nodes of given node type.
26 * @author Hannu Niemistö
28 public class ImageDecorationContribution extends VisualsContribution {
29 ImageDecorationRule imageDecorationRule;
31 public ImageDecorationContribution(NodeType nodeType, Test test, ImageDecorationRule imageDecorationRule, double priority) throws InvalidContribution {
32 super(nodeType, test, priority);
33 if(!imageDecorationRule.isCompatible(
34 nodeType.getContentType()
36 throw new InvalidContribution("Image decoration rule is not compatible with the content type.");
37 this.imageDecorationRule = imageDecorationRule;
41 * Returns an image decorator for the node or null, if contribution is
42 * not suitable for the input.
44 public ImageDecorator getImageDecorator(ReadGraph graph, NodeContext context) {
45 Object content = context.getConstant(BuiltinKeys.INPUT);
47 if(test == null || test.test(graph, content))
48 return imageDecorationRule.getImageDecorator(graph, content);
51 } catch(DatabaseException e) {