]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/contribution/IssueLabelDecorationRule.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / contribution / IssueLabelDecorationRule.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.issues.ui.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.issues.ontology.IssueResource;\r
22 \r
23 /**\r
24  * @author Tuukka Lehtonen\r
25  */\r
26 public enum IssueLabelDecorationRule implements LabelDecorationRule {\r
27 \r
28     INSTANCE;\r
29 \r
30     public static IssueLabelDecorationRule get() {\r
31         return INSTANCE;\r
32     }\r
33 \r
34     @Override\r
35     public boolean isCompatible(Class<?> contentType) {\r
36         return contentType.equals(Resource.class);\r
37     }\r
38 \r
39     @Override\r
40     public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {\r
41         Resource issue = (Resource) content;\r
42 \r
43         final boolean hidden = graph.hasStatement(issue, IssueResource.getInstance(graph).Hidden);\r
44         final boolean user = graph.hasStatement(issue, IssueResource.getInstance(graph).UserIssue);\r
45         final boolean resolved = graph.hasStatement(issue, IssueResource.getInstance(graph).Resolved);\r
46         if (!hidden && !user && !resolved)\r
47             return null;\r
48 \r
49         return new LabelDecorator.Stub() {\r
50             @SuppressWarnings("unchecked")\r
51             @Override\r
52             public <F> F decorateFont(F font, String column, int itemIndex) {\r
53                 int style = 0;\r
54                 style |= resolved ? SWT.ITALIC : 0;\r
55                 return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;\r
56             }\r
57             @SuppressWarnings("unchecked")\r
58             @Override\r
59             public <C> C decorateForeground(C color, String column, int itemIndex) {\r
60                 if (hidden)\r
61                     return (C) Constants.HIDDEN_FG;\r
62                 return color;\r
63             }\r
64             @SuppressWarnings("unchecked")\r
65             @Override\r
66             public <C> C decorateBackground(C color, String column, int itemIndex) {\r
67                 if (user)\r
68                     return (C) Constants.USER_BG;\r
69                 return color;\r
70             }\r
71         };\r
72     }\r
73 \r
74 }\r