]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.event/src/org/simantics/event/view/contribution/EventDecorationRule.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / view / contribution / EventDecorationRule.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.event.view.contribution;\r
13 \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
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public enum EventDecorationRule implements LabelDecorationRule {\r
28 \r
29     INSTANCE;\r
30 \r
31     public static EventDecorationRule get() {\r
32         return INSTANCE;\r
33     }\r
34 \r
35     @Override\r
36     public boolean isCompatible(Class<?> contentType) {\r
37         return contentType.equals(Resource.class);\r
38     }\r
39 \r
40     @Override\r
41     public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
42         Resource event = (Resource) content;\r
43 \r
44         EventResource EVENT = EventResource.getInstance(graph);\r
45 \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
52             return null;\r
53 \r
54         return new LabelDecorator.Stub() {\r
55             @SuppressWarnings("unchecked")\r
56             @Override\r
57             public <F> F decorateFont(F font, String column, int itemIndex) {\r
58                 int style = 0;\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
62             }\r
63             @SuppressWarnings("unchecked")\r
64             @Override\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
68                 return color;\r
69             }\r
70             @Override\r
71             public <C> C decorateBackground(C color, String column, int itemIndex) {\r
72                 return color;\r
73             }\r
74         };\r
75     }\r
76 \r
77 }\r