1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.event.view.contribution;
14 import org.eclipse.jface.resource.FontDescriptor;
15 import org.eclipse.swt.SWT;
16 import org.simantics.browsing.ui.content.LabelDecorator;
17 import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.event.ontology.EventResource;
22 import org.simantics.event.view.Constants;
25 * @author Tuukka Lehtonen
27 public enum EventDecorationRule implements LabelDecorationRule {
31 public static EventDecorationRule get() {
36 public boolean isCompatible(Class<?> contentType) {
37 return contentType.equals(Resource.class);
41 public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
42 Resource event = (Resource) content;
44 EventResource EVENT = EventResource.getInstance(graph);
46 final boolean milestone = graph.hasStatement(event, EVENT.Milestone);
47 final boolean hidden = graph.hasStatement(event, EVENT.Hidden);
48 final boolean baseline = graph.hasStatement(event, EVENT.EventLog_HasBaselineEvent_Inverse);
49 final boolean returnEvent = graph.hasStatement(event, EVENT.ReturnEvent);
50 final boolean returnedEvent = graph.hasStatement(event, EVENT.ReturnedBy);
51 if (!milestone && !hidden && !baseline && !returnEvent && !returnedEvent)
54 return new LabelDecorator.Stub() {
55 @SuppressWarnings("unchecked")
57 public <F> F decorateFont(F font, String column, int itemIndex) {
59 style |= milestone ? SWT.BOLD : 0;
60 style |= hidden ? SWT.ITALIC : 0;
61 return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;
63 @SuppressWarnings("unchecked")
65 public <C> C decorateForeground(C color, String column, int itemIndex) {
66 if (returnEvent || returnedEvent)
67 return (C) Constants.RETURN_EVENT_FG;
71 public <C> C decorateBackground(C color, String column, int itemIndex) {