]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.event/src/org/simantics/event/view/contribution/EventDecorationRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / view / contribution / EventDecorationRule.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.event.view.contribution;
13
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;
23
24 /**
25  * @author Tuukka Lehtonen
26  */
27 public enum EventDecorationRule implements LabelDecorationRule {
28
29     INSTANCE;
30
31     public static EventDecorationRule get() {
32         return INSTANCE;
33     }
34
35     @Override
36     public boolean isCompatible(Class<?> contentType) {
37         return contentType.equals(Resource.class);
38     }
39
40     @Override
41     public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
42         Resource event = (Resource) content;
43
44         EventResource EVENT = EventResource.getInstance(graph);
45
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)
52             return null;
53
54         return new LabelDecorator.Stub() {
55             @SuppressWarnings("unchecked")
56             @Override
57             public <F> F decorateFont(F font, String column, int itemIndex) {
58                 int style = 0;
59                 style |= milestone ? SWT.BOLD : 0;
60                 style |= hidden ? SWT.ITALIC : 0;
61                 return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;
62             }
63             @SuppressWarnings("unchecked")
64             @Override
65             public <C> C decorateForeground(C color, String column, int itemIndex) {
66                 if (returnEvent || returnedEvent)
67                     return (C) Constants.RETURN_EVENT_FG;
68                 return color;
69             }
70             @Override
71             public <C> C decorateBackground(C color, String column, int itemIndex) {
72                 return color;
73             }
74         };
75     }
76
77 }