]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/IssueImageRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / IssueImageRule.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;
13
14 import java.util.Collections;
15 import java.util.Map;
16
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.simantics.browsing.ui.common.ColumnKeys;
19 import org.simantics.browsing.ui.model.images.ImageRule;
20 import org.simantics.db.ReadGraph;
21 import org.simantics.db.Resource;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.layer0.variable.Variable;
24 import org.simantics.issues.ontology.IssueResource;
25 import org.simantics.silk.SilkResources;
26
27 /**
28  * @author Tuukka Lehtonen
29  */
30 public class IssueImageRule implements ImageRule {
31
32     private final String DESCRIPTION = ColumnKeys.SINGLE;
33
34     @Override
35     public boolean isCompatible(Class<?> contentType) {
36         return contentType.equals(Variable.class);
37     }
38
39     @Override
40     public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
41
42         Variable issue = (Variable)content;
43
44         IssueResource ISSUE = IssueResource.getInstance(graph);
45         SilkResources SILK = SilkResources.getInstance(graph);
46         String severity = issue.getPropertyValue(graph, "severity");
47
48         // TODO: now to do this with variables?
49         Resource issueResource = issue.getPossibleRepresents(graph);
50         boolean resolved = issueResource != null ? graph.hasStatement(issueResource, ISSUE.Resolved) : false;
51         if (resolved)
52             return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.tick, ImageDescriptor.class));
53
54         if("Fatal".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.bomb, ImageDescriptor.class));
55         else if("Error".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.exclamation, ImageDescriptor.class));
56         else if("Warning".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.error, ImageDescriptor.class));
57         else if("Info".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.information, ImageDescriptor.class));
58         else if("Note".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.note, ImageDescriptor.class));
59         else return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.help, ImageDescriptor.class));
60
61     }
62
63 }