Changeset 7766
- Timestamp:
- Feb 6, 2020, 9:32:27 AM (3 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemAnnotationColumn.java
r7765 r7766 1 1 package net.sf.basedb.clients.web.extensions.list; 2 2 3 import java.util.ArrayList;4 import java.util.List;5 3 import java.util.Set; 4 import java.util.TreeSet; 6 5 7 6 import net.sf.basedb.core.Annotatable; … … 12 11 import net.sf.basedb.util.filter.Filter; 13 12 13 /** 14 Parent item column that load annotation values from the parent items. 15 @author nicklas 16 @since 3.16 17 */ 14 18 public class ParentItemAnnotationColumn 15 19 extends ParentItemColumn … … 29 33 public Object getValue(DbControl dc, Annotatable item) 30 34 { 35 Set<Annotatable> parents = getParentItems(dc, item); 36 if (parents.size() == 0) return null; 31 37 32 Set<Annotatable> parents = getParentItems(dc, item); 33 List<Object> values = new ArrayList<>(); 38 Set<Object> values = new TreeSet<>(); 34 39 for (Annotatable p : parents) 35 40 { … … 39 44 } 40 45 } 41 42 return values; 46 return values.size() == 0 ? null : values; 43 47 } 44 48 -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumn.java
r7765 r7766 3 3 import java.util.Set; 4 4 5 import net.sf.basedb.clients.web.formatter.FormatterFactory; 6 import net.sf.basedb.clients.web.formatter.LinkedItemFormatter; 5 7 import net.sf.basedb.core.Annotatable; 6 8 import net.sf.basedb.core.AnnotationType; … … 9 11 import net.sf.basedb.core.ItemSubtype; 10 12 import net.sf.basedb.core.Metadata; 13 import net.sf.basedb.core.StringUtil; 11 14 import net.sf.basedb.core.Metadata.PropertyPath; 12 15 import net.sf.basedb.util.AnnotationUtil; 13 16 import net.sf.basedb.util.Values; 14 17 import net.sf.basedb.util.filter.Filter; 18 import net.sf.basedb.util.formatter.CollectionFormatter; 19 import net.sf.basedb.util.formatter.NameableFormatter; 20 import net.sf.basedb.util.formatter.ToStringFormatter; 15 21 16 22 /** … … 37 43 Item parentType = Item.valueOf(tmp[1]); 38 44 ItemSubtype subtype = ItemSubtype.getById(dc, Values.getInt(tmp[2])); 39 45 Filter<Annotatable> parentFilter = new SubtypeFilter(subtype); 40 46 ParentItemColumn col = null; 41 47 if (tmp[3].startsWith("#")) 42 48 { 43 49 AnnotationType at = AnnotationType.getById(dc, Values.getInt(tmp[3].substring(1))); 44 col = new ParentItemAnnotationColumn(expr, new SubtypeFilter(subtype), helper, at);50 col = new ParentItemAnnotationColumn(expr, parentFilter, helper, at); 45 51 col.setTitle(at.getName() + " [A]"); 46 52 col.setTooltip(subtype.getName() + " › "+at.getName()); 47 53 col.setValueType(at.getValueType()); 54 col.setExportFormatter(FormatterFactory.getTypeFormatter(dc.getSessionControl(), at.getValueType())); 55 col.setFormatter(new CollectionFormatter(col.getExportFormatter())); 48 56 } 49 57 else 50 58 { 51 Metadata m = Metadata.getInstance(parentType.getItemClass()); 52 PropertyPath property = m.getPropertyPath(tmp[3], false); 53 col = new ParentItemPropertyColumn(expr, new SubtypeFilter(subtype), helper, property); 54 col.setTitle(subtype.getName()+"."+tmp[3]); 59 String path = tmp[3]; 60 PropertyPath property = null; 61 if (!".".equals(path)) // special case '.' is equal to the "parent" item 62 { 63 Metadata m = Metadata.getInstance(parentType.getItemClass()); 64 property = m.getPropertyPath(path, false); 65 col = new ParentItemPropertyColumn(expr, parentFilter, helper, property); 66 col.setTitle(subtype.getName()+"."+path); 67 col.setTooltip(subtype.getName() + " › "+path); 68 } 69 else 70 { 71 col = new ParentItemPropertyColumn(expr, parentFilter, helper, null); 72 col.setTitle(subtype.getName()); 73 col.setTooltip(subtype.getName()); 74 } 75 if (property == null || property.getHibernateType().isEntityType()) 76 { 77 col.setExportFormatter(new NameableFormatter()); 78 col.setFormatter(new CollectionFormatter(new LinkedItemFormatter())); 79 } 80 else 81 { 82 col.setExportFormatter(new ToStringFormatter<>()); 83 col.setFormatter(new CollectionFormatter(col.getExportFormatter())); 84 } 55 85 } 56 86 -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemPropertyColumn.java
r7765 r7766 1 1 package net.sf.basedb.clients.web.extensions.list; 2 2 3 import java.util.ArrayList; 4 import java.util.List; 3 import java.util.LinkedHashSet; 5 4 import java.util.Set; 6 5 … … 25 24 public Object getValue(DbControl dc, Annotatable item) 26 25 { 27 28 26 Set<Annotatable> parents = getParentItems(dc, item); 29 List<Object> values = new ArrayList<>(); 27 if (parents.size() == 0) return null; 28 29 Set<Object> values = new LinkedHashSet<>(); 30 30 for (Annotatable p : parents) 31 31 { 32 values.add(property .getValue(dc, p));32 values.add(property == null ? p : property.getValue(dc, p)); 33 33 } 34 34 35 return values ;35 return values.size() == 0 ? null : values; 36 36 } 37 37 38 39 38 }
Note: See TracChangeset
for help on using the changeset viewer.