1 /*******************************************************************************
\r
2 * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
\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.model.images;
\r
14 import java.util.Map;
\r
16 import org.eclipse.jface.resource.ImageDescriptor;
\r
17 import org.simantics.browsing.ui.BuiltinKeys;
\r
18 import org.simantics.browsing.ui.NodeContext;
\r
19 import org.simantics.browsing.ui.model.InvalidContribution;
\r
20 import org.simantics.browsing.ui.model.nodetypes.NodeType;
\r
21 import org.simantics.browsing.ui.model.tests.Test;
\r
22 import org.simantics.browsing.ui.model.visuals.VisualsContribution;
\r
23 import org.simantics.db.ReadGraph;
\r
24 import org.simantics.db.exception.DatabaseException;
\r
27 * Produces images for nodes of given node type.
\r
28 * @author Hannu Niemistö
\r
30 public class ImageContribution extends VisualsContribution {
\r
31 ImageRule imageRule;
\r
33 public ImageContribution(NodeType nodeType, Test test, ImageRule imageRule, double priority) throws InvalidContribution {
\r
34 super(nodeType, test, priority);
\r
35 if(!imageRule.isCompatible(
\r
36 nodeType.getContentType()
\r
38 throw new InvalidContribution("image rule is not compatible with the content type.");
\r
39 this.imageRule = imageRule;
\r
43 * Returns a image for the node or null, if contribution is
\r
44 * not suitable for the input.
\r
46 public Map<String, ImageDescriptor> getImage(ReadGraph graph, NodeContext context) {
\r
47 Object content = context.getConstant(BuiltinKeys.INPUT);
\r
49 if(test == null || test.test(graph, content))
\r
50 return imageRule.getImage(graph, content);
\r
53 } catch(DatabaseException e) {
\r