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