]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/SeverityFolderLabelRule.java
Externalize strings
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / SeverityFolderLabelRule.java
1 /*******************************************************************************
2  * Copyright (c) 2010, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.issues.ui;
13
14 import java.util.Collections;
15 import java.util.Map;
16 import java.util.Set;
17
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;
28
29 public class SeverityFolderLabelRule implements LabelRule {
30         
31     private final String DESCRIPTION = ColumnKeys.SINGLE;
32
33         final Resource rule;
34         
35         public SeverityFolderLabelRule(Resource rule) {
36                 this.rule = rule;
37         }
38     
39     @Override
40     public boolean isCompatible(Class<?> contentType) {
41         return contentType.equals(Resource.class);
42     }
43
44     @Override
45     public Map<String,String> getLabel(ReadGraph graph, Object content) throws DatabaseException {
46         
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));
53         
54         if(issues.size() > 1) {
55                 return Collections.singletonMap(DESCRIPTION, severityName + "s (" + issues.size() + " items)"); //$NON-NLS-1$ //$NON-NLS-2$
56         } else {
57                 return Collections.singletonMap(DESCRIPTION, severityName + "s (1 item)"); //$NON-NLS-1$
58         }
59         
60     }
61     
62 }