1 /*******************************************************************************
\r
2 * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.issues.ui;
\r
14 import java.util.Collections;
\r
15 import java.util.Map;
\r
16 import java.util.Set;
\r
18 import org.simantics.browsing.ui.common.ColumnKeys;
\r
19 import org.simantics.browsing.ui.model.labels.LabelRule;
\r
20 import org.simantics.databoard.Bindings;
\r
21 import org.simantics.db.ReadGraph;
\r
22 import org.simantics.db.Resource;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.db.layer0.variable.Variable;
\r
25 import org.simantics.issues.common.IssuesOfSeverity;
\r
26 import org.simantics.issues.ui.ontology.IssueUIResource;
\r
27 import org.simantics.layer0.Layer0;
\r
29 public class SeverityFolderLabelRule implements LabelRule {
\r
31 private final String DESCRIPTION = ColumnKeys.SINGLE;
\r
33 final Resource rule;
\r
35 public SeverityFolderLabelRule(Resource rule) {
\r
40 public boolean isCompatible(Class<?> contentType) {
\r
41 return contentType.equals(Resource.class);
\r
45 public Map<String,String> getLabel(ReadGraph graph, Object content) throws DatabaseException {
\r
47 Layer0 L0 = Layer0.getInstance(graph);
\r
48 IssueUIResource UI = IssueUIResource.getInstance(graph);
\r
49 Resource project = (Resource)content;
\r
50 Resource severity = graph.getSingleObject(rule, UI.IssueBrowseContext_SeverityFolderLabelRule_HasSeverity);
\r
51 String severityName = graph.getRelatedValue(severity, L0.HasName, Bindings.STRING);
\r
52 Set<Variable> issues = graph.syncRequest(new IssuesOfSeverity(project, severity));
\r
54 if(issues.size() > 1) {
\r
55 return Collections.singletonMap(DESCRIPTION, severityName + "s (" + issues.size() + " items)");
\r
57 return Collections.singletonMap(DESCRIPTION, severityName + "s (1 item)");
\r