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