1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 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.event.view.contribution;
\r
14 import java.awt.Color;
\r
15 import java.util.Map;
\r
17 import org.eclipse.jface.resource.ImageDescriptor;
\r
18 import org.simantics.browsing.ui.model.images.ImageRule;
\r
19 import org.simantics.db.ReadGraph;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.exception.DatabaseException;
\r
22 import org.simantics.event.Activator;
\r
23 import org.simantics.event.ontology.EventResource;
\r
24 import org.simantics.event.view.Constants;
\r
25 import org.simantics.utils.datastructures.ArrayMap;
\r
26 import org.simantics.utils.ui.BundleUtils;
\r
27 import org.simantics.utils.ui.gfx.AlphaAdjustmentImageDescriptor;
\r
28 import org.simantics.utils.ui.gfx.CompositionImageDescriptor;
\r
29 import org.simantics.utils.ui.gfx.TextImageDescriptor;
\r
32 * @author Tuukka Lehtonen
\r
34 public enum EventImageRule implements ImageRule {
\r
38 public static EventImageRule get() {
\r
43 public boolean isCompatible(Class<?> contentType) {
\r
44 return contentType.equals(Resource.class);
\r
48 public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
\r
49 Resource event = (Resource) content;
\r
51 EventResource EVENT = EventResource.getInstance(graph);
\r
53 ImageDescriptor eventIcon = null;
\r
54 ImageDescriptor milestoneIcon = null;
\r
55 ImageDescriptor returnIcon = null;
\r
57 // Icon derived from event type
\r
58 Resource eventType = graph.getPossibleObject(event, EVENT.Event_type);
\r
59 if (eventType != null) {
\r
60 eventIcon = graph.syncRequest(new EventTypeImageDescriptorRequest(eventType));
\r
63 // Milestone Diamond Icon
\r
64 if (graph.hasStatement(event, EVENT.Milestone)) {
\r
65 String label = graph.getPossibleRelatedValue(event, EVENT.Event_milestoneLabel);
\r
66 if (label == null) label = "?";
\r
68 boolean isBasetime = graph.hasStatement(event, EVENT.EventLog_HasBaselineEvent_Inverse);
\r
69 ImageDescriptor diamond = isBasetime ? Activator.DIAMOND2_ICON : Activator.DIAMOND_ICON;
\r
70 int color = isBasetime ? 0 : Color.ORANGE.getRGB();
\r
71 ImageDescriptor number = new TextImageDescriptor(label, 16, 16, "Tahoma", 8, 0, color);
\r
72 milestoneIcon = CompositionImageDescriptor.compose( diamond, number );
\r
75 if (!graph.hasStatement(event, EVENT.NoReturn)) {
\r
76 if (graph.hasStatement(event, EVENT.ReturnedBy)) {
\r
77 returnIcon = BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/tick.png");
\r
78 } else if (graph.hasStatement(event, EVENT.ReturnEvent)) {
\r
79 returnIcon = BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_undo.png");
\r
81 returnIcon = BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/cross.png");
\r
85 boolean hidden = graph.hasStatement(event, EVENT.Hidden);
\r
87 eventIcon = fade(eventIcon, hidden);
\r
88 milestoneIcon = fade(milestoneIcon, hidden);
\r
89 returnIcon = fade(returnIcon, hidden);
\r
91 return ArrayMap.make(Constants.COLUMN_KEYS, new ImageDescriptor[] {
\r
106 private static ImageDescriptor fade(ImageDescriptor desc, boolean doIt) {
\r
107 return desc != null && doIt ? AlphaAdjustmentImageDescriptor.adjustAlpha(desc, 128) : desc;
\r