--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.issues.ui;\r
+\r
+import java.util.Collections;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
+import org.simantics.browsing.ui.model.labels.LabelRule;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.issues.common.IssuesOfSeverity;\r
+import org.simantics.issues.ui.ontology.IssueUIResource;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class SeverityFolderLabelRule implements LabelRule {\r
+ \r
+ private final String DESCRIPTION = ColumnKeys.SINGLE;\r
+\r
+ final Resource rule;\r
+ \r
+ public SeverityFolderLabelRule(Resource rule) {\r
+ this.rule = rule;\r
+ }\r
+ \r
+ @Override\r
+ public boolean isCompatible(Class<?> contentType) {\r
+ return contentType.equals(Resource.class);\r
+ }\r
+\r
+ @Override\r
+ public Map<String,String> getLabel(ReadGraph graph, Object content) throws DatabaseException {\r
+ \r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ IssueUIResource UI = IssueUIResource.getInstance(graph);\r
+ Resource project = (Resource)content;\r
+ Resource severity = graph.getSingleObject(rule, UI.IssueBrowseContext_SeverityFolderLabelRule_HasSeverity);\r
+ String severityName = graph.getRelatedValue(severity, L0.HasName, Bindings.STRING);\r
+ Set<Variable> issues = graph.syncRequest(new IssuesOfSeverity(project, severity));\r
+ \r
+ if(issues.size() > 1) {\r
+ return Collections.singletonMap(DESCRIPTION, severityName + "s (" + issues.size() + " items)");\r
+ } else {\r
+ return Collections.singletonMap(DESCRIPTION, severityName + "s (1 item)");\r
+ }\r
+ \r
+ }\r
+ \r
+}\r