+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.event.view.contribution;\r
+\r
+import java.awt.Color;\r
+import java.util.Map;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.model.images.ImageRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.event.Activator;\r
+import org.simantics.event.ontology.EventResource;\r
+import org.simantics.event.view.Constants;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+import org.simantics.utils.ui.BundleUtils;\r
+import org.simantics.utils.ui.gfx.AlphaAdjustmentImageDescriptor;\r
+import org.simantics.utils.ui.gfx.CompositionImageDescriptor;\r
+import org.simantics.utils.ui.gfx.TextImageDescriptor;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public enum EventImageRule implements ImageRule {\r
+\r
+ INSTANCE;\r
+\r
+ public static EventImageRule get() {\r
+ return INSTANCE;\r
+ }\r
+\r
+ @Override\r
+ public boolean isCompatible(Class<?> contentType) {\r
+ return contentType.equals(Resource.class);\r
+ }\r
+\r
+ @Override\r
+ public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {\r
+ Resource event = (Resource) content;\r
+\r
+ EventResource EVENT = EventResource.getInstance(graph);\r
+\r
+ ImageDescriptor eventIcon = null;\r
+ ImageDescriptor milestoneIcon = null;\r
+ ImageDescriptor returnIcon = null;\r
+\r
+ // Icon derived from event type\r
+ Resource eventType = graph.getPossibleObject(event, EVENT.Event_type);\r
+ if (eventType != null) {\r
+ eventIcon = graph.syncRequest(new EventTypeImageDescriptorRequest(eventType));\r
+ }\r
+\r
+ // Milestone Diamond Icon\r
+ if (graph.hasStatement(event, EVENT.Milestone)) {\r
+ String label = graph.getPossibleRelatedValue(event, EVENT.Event_milestoneLabel);\r
+ if (label == null) label = "?";\r
+\r
+ boolean isBasetime = graph.hasStatement(event, EVENT.EventLog_HasBaselineEvent_Inverse);\r
+ ImageDescriptor diamond = isBasetime ? Activator.DIAMOND2_ICON : Activator.DIAMOND_ICON;\r
+ int color = isBasetime ? 0 : Color.ORANGE.getRGB();\r
+ ImageDescriptor number = new TextImageDescriptor(label, 16, 16, "Tahoma", 8, 0, color);\r
+ milestoneIcon = CompositionImageDescriptor.compose( diamond, number );\r
+ }\r
+\r
+ if (!graph.hasStatement(event, EVENT.NoReturn)) {\r
+ if (graph.hasStatement(event, EVENT.ReturnedBy)) {\r
+ returnIcon = BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/tick.png");\r
+ } else if (graph.hasStatement(event, EVENT.ReturnEvent)) {\r
+ returnIcon = BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_undo.png");\r
+ } else {\r
+ returnIcon = BundleUtils.getImageDescriptorFromPlugin("com.famfamfam.silk", "icons/cross.png");\r
+ }\r
+ }\r
+\r
+ boolean hidden = graph.hasStatement(event, EVENT.Hidden);\r
+\r
+ eventIcon = fade(eventIcon, hidden);\r
+ milestoneIcon = fade(milestoneIcon, hidden);\r
+ returnIcon = fade(returnIcon, hidden);\r
+\r
+ return ArrayMap.make(Constants.COLUMN_KEYS, new ImageDescriptor[] {\r
+ null,\r
+ null,\r
+ null,\r
+ milestoneIcon,\r
+ eventIcon,\r
+ returnIcon,\r
+ null,\r
+ null,\r
+ null,\r
+ null,\r
+ null\r
+ });\r
+ }\r
+\r
+ private static ImageDescriptor fade(ImageDescriptor desc, boolean doIt) {\r
+ return desc != null && doIt ? AlphaAdjustmentImageDescriptor.adjustAlpha(desc, 128) : desc;\r
+ }\r
+\r
+}\r