Changeset 7766


Ignore:
Timestamp:
Feb 6, 2020, 9:32:27 AM (22 months ago)
Author:
Nicklas Nordborg
Message:

References #2202: Include information from parent items in list pages

Adding formatter implementations to get nicer formatting both when exporting and in the list page.

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  
    11package net.sf.basedb.clients.web.extensions.list;
    22
    3 import java.util.ArrayList;
    4 import java.util.List;
    53import java.util.Set;
     4import java.util.TreeSet;
    65
    76import net.sf.basedb.core.Annotatable;
     
    1211import net.sf.basedb.util.filter.Filter;
    1312
     13/**
     14  Parent item column that load annotation values from the parent items.
     15  @author nicklas
     16  @since 3.16
     17*/
    1418public class ParentItemAnnotationColumn
    1519  extends ParentItemColumn
     
    2933  public Object getValue(DbControl dc, Annotatable item)
    3034  {
     35    Set<Annotatable> parents = getParentItems(dc, item);
     36    if (parents.size() == 0) return null;
    3137   
    32     Set<Annotatable> parents = getParentItems(dc, item);
    33     List<Object> values = new ArrayList<>();
     38    Set<Object> values = new TreeSet<>();
    3439    for (Annotatable p : parents)
    3540    {
     
    3944      }
    4045    }
    41    
    42     return values;
     46    return values.size() == 0 ? null : values;
    4347  }
    4448
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumn.java

    r7765 r7766  
    33import java.util.Set;
    44
     5import net.sf.basedb.clients.web.formatter.FormatterFactory;
     6import net.sf.basedb.clients.web.formatter.LinkedItemFormatter;
    57import net.sf.basedb.core.Annotatable;
    68import net.sf.basedb.core.AnnotationType;
     
    911import net.sf.basedb.core.ItemSubtype;
    1012import net.sf.basedb.core.Metadata;
     13import net.sf.basedb.core.StringUtil;
    1114import net.sf.basedb.core.Metadata.PropertyPath;
    1215import net.sf.basedb.util.AnnotationUtil;
    1316import net.sf.basedb.util.Values;
    1417import net.sf.basedb.util.filter.Filter;
     18import net.sf.basedb.util.formatter.CollectionFormatter;
     19import net.sf.basedb.util.formatter.NameableFormatter;
     20import net.sf.basedb.util.formatter.ToStringFormatter;
    1521
    1622/**
     
    3743    Item parentType = Item.valueOf(tmp[1]);
    3844    ItemSubtype subtype = ItemSubtype.getById(dc, Values.getInt(tmp[2]));
    39    
     45    Filter<Annotatable> parentFilter = new SubtypeFilter(subtype);
    4046    ParentItemColumn col = null;
    4147    if (tmp[3].startsWith("#"))
    4248    {
    4349      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);
    4551      col.setTitle(at.getName() + " [A]");
    4652      col.setTooltip(subtype.getName() + " › "+at.getName());
    4753      col.setValueType(at.getValueType());
     54      col.setExportFormatter(FormatterFactory.getTypeFormatter(dc.getSessionControl(), at.getValueType()));
     55      col.setFormatter(new CollectionFormatter(col.getExportFormatter()));
    4856    }
    4957    else
    5058    {
    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      }
    5585    }
    5686   
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemPropertyColumn.java

    r7765 r7766  
    11package net.sf.basedb.clients.web.extensions.list;
    22
    3 import java.util.ArrayList;
    4 import java.util.List;
     3import java.util.LinkedHashSet;
    54import java.util.Set;
    65
     
    2524  public Object getValue(DbControl dc, Annotatable item)
    2625  {
    27    
    2826    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<>();
    3030    for (Annotatable p : parents)
    3131    {
    32       values.add(property.getValue(dc, p));
     32      values.add(property == null ? p : property.getValue(dc, p));
    3333    }
    3434   
    35     return values;
     35    return values.size() == 0 ? null : values;
    3636  }
    3737
    38 
    3938}
Note: See TracChangeset for help on using the changeset viewer.