X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.issues.ui%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fui%2FIssueImageRule.java;h=c845ed08235cdafc51909803c72035277907c194;hb=236aa4e765e0acd6e31cbc42dd9df9c2c23677e2;hp=d92a9ade0cb6916a70dcf66c77dd85dedfeed26d;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/IssueImageRule.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/IssueImageRule.java index d92a9ade0..c845ed082 100644 --- a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/IssueImageRule.java +++ b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/IssueImageRule.java @@ -1,63 +1,89 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.issues.ui; - -import java.util.Collections; -import java.util.Map; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.simantics.browsing.ui.common.ColumnKeys; -import org.simantics.browsing.ui.model.images.ImageRule; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.issues.ontology.IssueResource; -import org.simantics.silk.SilkResources; - -/** - * @author Tuukka Lehtonen - */ -public class IssueImageRule implements ImageRule { - - private final String DESCRIPTION = ColumnKeys.SINGLE; - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Variable.class); - } - - @Override - public Map getImage(ReadGraph graph, Object content) throws DatabaseException { - - Variable issue = (Variable)content; - - IssueResource ISSUE = IssueResource.getInstance(graph); - SilkResources SILK = SilkResources.getInstance(graph); - String severity = issue.getPropertyValue(graph, "severity"); - - // TODO: now to do this with variables? - Resource issueResource = issue.getPossibleRepresents(graph); - boolean resolved = issueResource != null ? graph.hasStatement(issueResource, ISSUE.Resolved) : false; - if (resolved) - return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.tick, ImageDescriptor.class)); - - if("Fatal".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.bomb, ImageDescriptor.class)); - else if("Error".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.exclamation, ImageDescriptor.class)); - else if("Warning".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.error, ImageDescriptor.class)); - else if("Info".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.information, ImageDescriptor.class)); - else if("Note".equals(severity)) return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.note, ImageDescriptor.class)); - else return Collections.singletonMap(DESCRIPTION, graph.adapt(SILK.help, ImageDescriptor.class)); - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2017 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - #6948 + *******************************************************************************/ +package org.simantics.issues.ui; + +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.images.ImageRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.issues.ontology.IssueResource; +import org.simantics.silk.SilkResources; + +/** + * @author Tuukka Lehtonen + */ +public class IssueImageRule implements ImageRule { + + private final String DESCRIPTION = ColumnKeys.SINGLE; + + private final ImageDescriptor tick; + private final ImageDescriptor fatal; + private final ImageDescriptor error; + private final ImageDescriptor warning; + private final ImageDescriptor info; + private final ImageDescriptor note; + private final ImageDescriptor help; + + public IssueImageRule(ReadGraph graph) throws DatabaseException { + SilkResources SILK = SilkResources.getInstance(graph); + tick = graph.adapt(SILK.tick, ImageDescriptor.class); + fatal = graph.adapt(SILK.bomb, ImageDescriptor.class); + error = graph.adapt(SILK.exclamation, ImageDescriptor.class); + warning = graph.adapt(SILK.error, ImageDescriptor.class); + info = graph.adapt(SILK.information, ImageDescriptor.class); + note = graph.adapt(SILK.note, ImageDescriptor.class); + help = graph.adapt(SILK.help, ImageDescriptor.class); + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Variable.class); + } + + @Override + public Map getImage(ReadGraph graph, Object content) throws DatabaseException { + Variable issue = (Variable) content; + String severity = issue.getPossiblePropertyValue(graph, "severity"); //$NON-NLS-1$ + if (severity == null) + return Collections.emptyMap(); + boolean resolved = isResolved(graph, issue); + return Collections.singletonMap(DESCRIPTION, resolved ? tick : toImageDescriptor(severity)); + } + + public boolean isResolved(ReadGraph graph, Variable issue) throws DatabaseException { + Resource issueResource = issue.getPossibleRepresents(graph); + if (issueResource != null) + return graph.hasStatement(issueResource, IssueResource.getInstance(graph).Resolved); + + Boolean resolved = issue.getPossiblePropertyValue(graph, "resolved"); //$NON-NLS-1$ + return Boolean.TRUE.equals(resolved); + } + + private ImageDescriptor toImageDescriptor(String severity) { + switch (severity) { + case "Fatal": return fatal; //$NON-NLS-1$ + case "Error": return error; //$NON-NLS-1$ + case "Warning": return warning; //$NON-NLS-1$ + case "Info": return info; //$NON-NLS-1$ + case "Note": return note; //$NON-NLS-1$ + default: return help; + } + } + +}