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 org.eclipse.jface.resource.FontDescriptor;
\r
15 import org.eclipse.swt.SWT;
\r
16 import org.simantics.browsing.ui.content.LabelDecorator;
\r
17 import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.exception.DatabaseException;
\r
21 import org.simantics.event.ontology.EventResource;
\r
22 import org.simantics.event.view.Constants;
\r
25 * @author Tuukka Lehtonen
\r
27 public enum EventDecorationRule implements LabelDecorationRule {
\r
31 public static EventDecorationRule get() {
\r
36 public boolean isCompatible(Class<?> contentType) {
\r
37 return contentType.equals(Resource.class);
\r
41 public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
\r
42 Resource event = (Resource) content;
\r
44 EventResource EVENT = EventResource.getInstance(graph);
\r
46 final boolean milestone = graph.hasStatement(event, EVENT.Milestone);
\r
47 final boolean hidden = graph.hasStatement(event, EVENT.Hidden);
\r
48 final boolean baseline = graph.hasStatement(event, EVENT.EventLog_HasBaselineEvent_Inverse);
\r
49 final boolean returnEvent = graph.hasStatement(event, EVENT.ReturnEvent);
\r
50 final boolean returnedEvent = graph.hasStatement(event, EVENT.ReturnedBy);
\r
51 if (!milestone && !hidden && !baseline && !returnEvent && !returnedEvent)
\r
54 return new LabelDecorator.Stub() {
\r
55 @SuppressWarnings("unchecked")
\r
57 public <F> F decorateFont(F font, String column, int itemIndex) {
\r
59 style |= milestone ? SWT.BOLD : 0;
\r
60 style |= hidden ? SWT.ITALIC : 0;
\r
61 return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;
\r
63 @SuppressWarnings("unchecked")
\r
65 public <C> C decorateForeground(C color, String column, int itemIndex) {
\r
66 if (returnEvent || returnedEvent)
\r
67 return (C) Constants.RETURN_EVENT_FG;
\r
71 public <C> C decorateBackground(C color, String column, int itemIndex) {
\r