--- /dev/null
+/*******************************************************************************\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 org.eclipse.jface.resource.FontDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.event.ontology.EventResource;\r
+import org.simantics.event.view.Constants;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public enum EventDecorationRule implements LabelDecorationRule {\r
+\r
+ INSTANCE;\r
+\r
+ public static EventDecorationRule 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 LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
+ Resource event = (Resource) content;\r
+\r
+ EventResource EVENT = EventResource.getInstance(graph);\r
+\r
+ final boolean milestone = graph.hasStatement(event, EVENT.Milestone);\r
+ final boolean hidden = graph.hasStatement(event, EVENT.Hidden);\r
+ final boolean baseline = graph.hasStatement(event, EVENT.EventLog_HasBaselineEvent_Inverse);\r
+ final boolean returnEvent = graph.hasStatement(event, EVENT.ReturnEvent);\r
+ final boolean returnedEvent = graph.hasStatement(event, EVENT.ReturnedBy);\r
+ if (!milestone && !hidden && !baseline && !returnEvent && !returnedEvent)\r
+ return null;\r
+\r
+ return new LabelDecorator.Stub() {\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <F> F decorateFont(F font, String column, int itemIndex) {\r
+ int style = 0;\r
+ style |= milestone ? SWT.BOLD : 0;\r
+ style |= hidden ? SWT.ITALIC : 0;\r
+ return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;\r
+ }\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <C> C decorateForeground(C color, String column, int itemIndex) {\r
+ if (returnEvent || returnedEvent)\r
+ return (C) Constants.RETURN_EVENT_FG;\r
+ return color;\r
+ }\r
+ @Override\r
+ public <C> C decorateBackground(C color, String column, int itemIndex) {\r
+ return color;\r
+ }\r
+ };\r
+ }\r
+\r
+}\r