X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.issues.ui%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fui%2FSeverityFolderLabelRule.java;fp=bundles%2Forg.simantics.issues.ui%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fui%2FSeverityFolderLabelRule.java;h=62b2371082bb097bd72005307e774ed8477124a1;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/SeverityFolderLabelRule.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/SeverityFolderLabelRule.java new file mode 100644 index 000000000..62b237108 --- /dev/null +++ b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/SeverityFolderLabelRule.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2010, 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 java.util.Set; + +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.model.labels.LabelRule; +import org.simantics.databoard.Bindings; +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.common.IssuesOfSeverity; +import org.simantics.issues.ui.ontology.IssueUIResource; +import org.simantics.layer0.Layer0; + +public class SeverityFolderLabelRule implements LabelRule { + + private final String DESCRIPTION = ColumnKeys.SINGLE; + + final Resource rule; + + public SeverityFolderLabelRule(Resource rule) { + this.rule = rule; + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + IssueUIResource UI = IssueUIResource.getInstance(graph); + Resource project = (Resource)content; + Resource severity = graph.getSingleObject(rule, UI.IssueBrowseContext_SeverityFolderLabelRule_HasSeverity); + String severityName = graph.getRelatedValue(severity, L0.HasName, Bindings.STRING); + Set issues = graph.syncRequest(new IssuesOfSeverity(project, severity)); + + if(issues.size() > 1) { + return Collections.singletonMap(DESCRIPTION, severityName + "s (" + issues.size() + " items)"); + } else { + return Collections.singletonMap(DESCRIPTION, severityName + "s (1 item)"); + } + + } + +}