]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/VariablePropertyLabelRule.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / VariablePropertyLabelRule.java
1 package org.simantics.selectionview;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.simantics.browsing.ui.model.labels.LabelRule;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.db.layer0.variable.Variables;
12
13 public class VariablePropertyLabelRule implements LabelRule {
14         
15     @Override
16     public boolean isCompatible(Class<?> contentType) {
17         return contentType.equals(Variable.class);
18     }
19
20     @Override
21     public Map<String, String> getLabel(ReadGraph graph, Object content)
22             throws DatabaseException {
23         
24         Variable variable = (Variable)content;
25         
26         Map<String, String> result = new HashMap<String, String>();
27         
28         for(Variable property : variable.getProperties(graph)) {
29                 String column = property.getPossiblePropertyValue(graph, Variables.DISPLAY_COLUMN);
30                 if(column != null) {
31                         String value = property.getPossibleValue(graph, Bindings.STRING);
32                         if (value != null)
33                                 result.put(column, value);
34                 }
35         }
36         
37                 return result;
38                 
39     }
40
41 }