X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.issues.ui%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fui%2Fcontribution%2FIssueImageDecorationRule.java;h=edc6268e31001fde5beb6b1d019ef46a8032d1cc;hp=0c5ff15aa081d304328444d5b902411906a45112;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/contribution/IssueImageDecorationRule.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/contribution/IssueImageDecorationRule.java index 0c5ff15aa..edc6268e3 100644 --- a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/contribution/IssueImageDecorationRule.java +++ b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/contribution/IssueImageDecorationRule.java @@ -1,106 +1,106 @@ -/******************************************************************************* - * 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.contribution; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IDecoration; -import org.simantics.browsing.ui.content.ImageDecorator; -import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationRule; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.issues.Severity; -import org.simantics.issues.common.MaxIssueSeverityRecursive; -import org.simantics.issues.ontology.IssueResource; -import org.simantics.issues.ui.internal.Activator; -import org.simantics.layer0.Layer0; -import org.simantics.utils.ui.gfx.DecorationOverlayIcon; - -/** - * @author Tuukka Lehtonen - */ -public class IssueImageDecorationRule implements ImageDecorationRule { - - Set typesToSearch; - - /** - * @param graph - * @param typesToSearch URIs of types to recurse into while searching for - * issues - * @throws DatabaseException - */ - public IssueImageDecorationRule(ReadGraph graph, String typeToSearch) throws DatabaseException { - this(graph, new String[] { typeToSearch }); - } - - /** - * @param graph - * @param typesToSearch URIs of types to recurse into while searching for - * issues - * @throws DatabaseException - */ - public IssueImageDecorationRule(ReadGraph graph, String type1, String type2) throws DatabaseException { - this(graph, new String[] { type1, type2}); - } - - /** - * @param graph - * @param typesToSearch URIs of types to recurse into while searching for - * issues - * @throws DatabaseException - */ - public IssueImageDecorationRule(ReadGraph graph, String... typesToSearch) throws DatabaseException { - this.typesToSearch = new HashSet(typesToSearch.length); - for (String uri : typesToSearch) - this.typesToSearch.add(graph.getResource(uri)); - } - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public ImageDecorator getImageDecorator(ReadGraph graph, Object content) throws DatabaseException { - Resource r = (Resource) content; - - // Make sure IssueResource service is initialized. - Layer0 L0 = Layer0.getInstance(graph); - IssueResource.getInstance(graph); - - //Severity maxSeverity = graph.syncRequest(new MaxIssueSeveritySingle(r)); - //System.out.println("calculate maxSeverity(" + NameUtils.getSafeName(graph, r, true) + ")"); - Severity maxSeverity = graph.syncRequest(new MaxIssueSeverityRecursive(r, L0.ConsistsOf, typesToSearch)); - //System.out.println("maxSeverity(" + NameUtils.getSafeName(graph, r, true) + "): " + maxSeverity); - if (maxSeverity == null) - return null; - - final Severity severity = maxSeverity; - return new ImageDecorator() { - @SuppressWarnings("unchecked") - @Override - public Image decorateImage(Image image, String column, int itemIndex) { - return (Image) getDecoration((ImageDescriptor) image, severity); - } - }; - } - - private ImageDescriptor getDecoration(ImageDescriptor original, Severity severity) { - ImageDescriptor img = Activator.getDefault().getImageRegistry().getDescriptor(severity.toString()); - return (original == null || original.getImageData() == null) ? img - : new DecorationOverlayIcon(original, img, IDecoration.BOTTOM_LEFT); - } - -} +/******************************************************************************* + * 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.contribution; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IDecoration; +import org.simantics.browsing.ui.content.ImageDecorator; +import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.issues.Severity; +import org.simantics.issues.common.MaxIssueSeverityRecursive; +import org.simantics.issues.ontology.IssueResource; +import org.simantics.issues.ui.internal.Activator; +import org.simantics.layer0.Layer0; +import org.simantics.utils.ui.gfx.DecorationOverlayIcon; + +/** + * @author Tuukka Lehtonen + */ +public class IssueImageDecorationRule implements ImageDecorationRule { + + Set typesToSearch; + + /** + * @param graph + * @param typesToSearch URIs of types to recurse into while searching for + * issues + * @throws DatabaseException + */ + public IssueImageDecorationRule(ReadGraph graph, String typeToSearch) throws DatabaseException { + this(graph, new String[] { typeToSearch }); + } + + /** + * @param graph + * @param typesToSearch URIs of types to recurse into while searching for + * issues + * @throws DatabaseException + */ + public IssueImageDecorationRule(ReadGraph graph, String type1, String type2) throws DatabaseException { + this(graph, new String[] { type1, type2}); + } + + /** + * @param graph + * @param typesToSearch URIs of types to recurse into while searching for + * issues + * @throws DatabaseException + */ + public IssueImageDecorationRule(ReadGraph graph, String... typesToSearch) throws DatabaseException { + this.typesToSearch = new HashSet(typesToSearch.length); + for (String uri : typesToSearch) + this.typesToSearch.add(graph.getResource(uri)); + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public ImageDecorator getImageDecorator(ReadGraph graph, Object content) throws DatabaseException { + Resource r = (Resource) content; + + // Make sure IssueResource service is initialized. + Layer0 L0 = Layer0.getInstance(graph); + IssueResource.getInstance(graph); + + //Severity maxSeverity = graph.syncRequest(new MaxIssueSeveritySingle(r)); + //System.out.println("calculate maxSeverity(" + NameUtils.getSafeName(graph, r, true) + ")"); + Severity maxSeverity = graph.syncRequest(new MaxIssueSeverityRecursive(r, L0.ConsistsOf, typesToSearch)); + //System.out.println("maxSeverity(" + NameUtils.getSafeName(graph, r, true) + "): " + maxSeverity); + if (maxSeverity == null) + return null; + + final Severity severity = maxSeverity; + return new ImageDecorator() { + @SuppressWarnings("unchecked") + @Override + public Image decorateImage(Image image, String column, int itemIndex) { + return (Image) getDecoration((ImageDescriptor) image, severity); + } + }; + } + + private ImageDescriptor getDecoration(ImageDescriptor original, Severity severity) { + ImageDescriptor img = Activator.getDefault().getImageRegistry().getDescriptor(severity.toString()); + return (original == null || original.getImageData() == null) ? img + : new DecorationOverlayIcon(original, img, IDecoration.BOTTOM_LEFT); + } + +}