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.issues.ui.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.databoard.Bindings;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.variable.Variable;
23 import org.simantics.issues.ontology.IssueResource;
26 * @author Tuukka Lehtonen
28 public enum IssueLabelDecorationRule implements LabelDecorationRule {
32 public static IssueLabelDecorationRule get() {
37 public boolean isCompatible(Class<?> contentType) {
38 return contentType.equals(Variable.class);
42 public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
43 Variable issue = (Variable) content;
45 boolean hidden = false;
47 boolean resolved = false;
49 Resource issueR = issue.getPossibleRepresents(graph);
51 IssueResource ISSUE = IssueResource.getInstance(graph);
52 hidden = graph.hasStatement(issueR, ISSUE.Hidden);
53 user = graph.hasStatement(issueR, ISSUE.UserIssue);
54 resolved = graph.hasStatement(issueR, ISSUE.Resolved);
56 hidden = Boolean.TRUE.equals(issue.getPossiblePropertyValue(graph, "hidden", Bindings.BOOLEAN));
59 int index = (hidden ? 1 : 0) + (user ? 2 : 0) + (resolved ? 4 : 0);
60 return DECORATORS[index];
63 private static final Decorator[] DECORATORS = {
65 new Decorator(true, false, false),
66 new Decorator(false, true, false),
67 new Decorator(true, true, false),
68 new Decorator(false, false, true),
69 new Decorator(true, false, true),
70 new Decorator(false, true, true),
71 new Decorator(true, true, true),
74 private static class Decorator extends LabelDecorator.Stub {
75 private boolean hidden;
77 private boolean resolved;
79 public Decorator(boolean hidden, boolean user, boolean resolved) {
82 this.resolved = resolved;
85 @SuppressWarnings("unchecked")
87 public <F> F decorateFont(F font, String column, int itemIndex) {
89 style |= resolved ? SWT.ITALIC : 0;
90 //style |= hidden ? SWT.BOLD : 0;
91 return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;
93 @SuppressWarnings("unchecked")
95 public <C> C decorateForeground(C color, String column, int itemIndex) {
97 return (C) Constants.HIDDEN_FG;
100 @SuppressWarnings("unchecked")
102 public <C> C decorateBackground(C color, String column, int itemIndex) {
104 return (C) Constants.USER_BG;