]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.workbench.search/src/org/simantics/workbench/search/NameAndTypeRow.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.workbench.search / src / org / simantics / workbench / search / NameAndTypeRow.java
1 package org.simantics.workbench.search;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6
7 import org.simantics.databoard.util.URIStringUtils;
8
9 /**
10  * Search Result for Name and Type queries.
11  * 
12  * Implements the functionality of old SearchResult used in Simantics 1.10 and 1.11
13  * 
14  * 
15  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
16  *
17  */
18 public class NameAndTypeRow implements SearchResultRow {
19         
20         public static final List<SearchResultColumn> columns;
21         
22         static {
23                 columns = new ArrayList<SearchResultColumn>();
24                 columns.add(new SearchResultColumn("Name"));
25                 columns.add(new SearchResultColumn("Type"));
26                 columns.add(new SearchResultColumn("Part Of"));
27         }
28         
29         public NamedResource             resource;
30     public NamedResource             parent;
31     public Collection<NamedResource> types;
32     public Collection<NamedResource> principalTypes;
33
34     public NamedResource getResource() {
35         return resource;
36     }
37
38     public NamedResource getParent() {
39         return parent;
40     }
41
42     public Collection<NamedResource> getTypes() {
43         return types;
44     }
45
46     public Collection<NamedResource> getPrincipalTypes() {
47         return principalTypes;
48     }
49     
50     @Override
51     public String getContent(int column) {
52         
53         switch (column) {
54         
55                 case 0:
56                         return "<a class=\"small\" href=\"resource:"+ resource.getResource() +"\"" + (resource.getUri() == null ? "" : " title=\""+URIStringUtils.unescape( resource.getUri() )+"\">")+StringUtil.escape(resource.getName())+"</a>";
57                 case 1:
58                         String s = "";
59                         for (NamedResource type : principalTypes)
60                          s+="<a class=\"small\" href=\"resource:"+ type.getResource() +"\"" + (type.getUri() == null ? "" : " title=\""+URIStringUtils.unescape( type.getUri() )+"\">")+StringUtil.escape(type.getName())+"</a>";
61                         return s;
62                 case 2:
63                         if (parent != null)
64                                 return "<a class=\"small\" href=\"resource:"+ parent.getResource() +"\"" + (parent.getUri() == null ? "" : " title=\""+URIStringUtils.unescape( parent.getUri() )+"\">")+StringUtil.escape(parent.getName())+"</a>";
65                         return "";
66                 default:
67                         return "";
68                 }
69     }
70 }