1 /*******************************************************************************
2 * Copyright (c) 2007, 2017 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
12 *******************************************************************************/
13 package org.simantics.issues.ui;
15 import java.util.Collections;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.simantics.browsing.ui.common.ColumnKeys;
20 import org.simantics.browsing.ui.model.images.ImageRule;
21 import org.simantics.db.ReadGraph;
22 import org.simantics.db.Resource;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.layer0.variable.Variable;
25 import org.simantics.issues.ontology.IssueResource;
26 import org.simantics.silk.SilkResources;
29 * @author Tuukka Lehtonen
31 public class IssueImageRule implements ImageRule {
33 private final String DESCRIPTION = ColumnKeys.SINGLE;
35 private final ImageDescriptor tick;
36 private final ImageDescriptor fatal;
37 private final ImageDescriptor error;
38 private final ImageDescriptor warning;
39 private final ImageDescriptor info;
40 private final ImageDescriptor note;
41 private final ImageDescriptor help;
43 public IssueImageRule(ReadGraph graph) throws DatabaseException {
44 SilkResources SILK = SilkResources.getInstance(graph);
45 tick = graph.adapt(SILK.tick, ImageDescriptor.class);
46 fatal = graph.adapt(SILK.bomb, ImageDescriptor.class);
47 error = graph.adapt(SILK.exclamation, ImageDescriptor.class);
48 warning = graph.adapt(SILK.error, ImageDescriptor.class);
49 info = graph.adapt(SILK.information, ImageDescriptor.class);
50 note = graph.adapt(SILK.note, ImageDescriptor.class);
51 help = graph.adapt(SILK.help, ImageDescriptor.class);
55 public boolean isCompatible(Class<?> contentType) {
56 return contentType.equals(Variable.class);
60 public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
61 Variable issue = (Variable) content;
62 String severity = issue.getPossiblePropertyValue(graph, "severity");
64 return Collections.emptyMap();
65 boolean resolved = isResolved(graph, issue);
66 return Collections.singletonMap(DESCRIPTION, resolved ? tick : toImageDescriptor(severity));
69 public boolean isResolved(ReadGraph graph, Variable issue) throws DatabaseException {
70 Resource issueResource = issue.getPossibleRepresents(graph);
71 if (issueResource != null)
72 return graph.hasStatement(issueResource, IssueResource.getInstance(graph).Resolved);
74 Boolean resolved = issue.getPossiblePropertyValue(graph, "resolved");
75 return Boolean.TRUE.equals(resolved);
78 private ImageDescriptor toImageDescriptor(String severity) {
80 case "Fatal": return fatal;
81 case "Error": return error;
82 case "Warning": return warning;
83 case "Info": return info;
84 case "Note": return note;