Changeset 7765
- Timestamp:
- Feb 5, 2020, 10:53:21 AM (3 years ago)
- Location:
- trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumn.java
r7764 r7765 4 4 5 5 import net.sf.basedb.core.Annotatable; 6 import net.sf.basedb.core.Annotation;7 6 import net.sf.basedb.core.AnnotationType; 8 7 import net.sf.basedb.core.DbControl; 9 8 import net.sf.basedb.core.Item; 10 9 import net.sf.basedb.core.ItemSubtype; 11 import net.sf.basedb.core. Subtypable;12 import net.sf.basedb.core. Type;10 import net.sf.basedb.core.Metadata; 11 import net.sf.basedb.core.Metadata.PropertyPath; 13 12 import net.sf.basedb.util.AnnotationUtil; 14 import net.sf.basedb.util.Enumeration;15 13 import net.sf.basedb.util.Values; 16 14 import net.sf.basedb.util.filter.Filter; 17 import net.sf.basedb.util.formatter.Formatter;18 15 19 16 /** … … 27 24 @since 3.16 28 25 */ 29 public class ParentItemColumn<I extends Annotatable, V> 30 implements ListColumnAction<I, V>, 31 Filter<Annotatable> 26 public abstract class ParentItemColumn 27 extends AbstractListColumnBean<Annotatable, Object> 32 28 { 33 29 34 30 /** 35 For now, we assume that 'expr' is /ITEMTYPE/subtype-id/#annotationtype-id 31 For now, we assume that 'expr' is /ITEMTYPE/subtype-id/#annotationtype-id or 32 /ITEMTYPE/subtype-id/property 36 33 */ 37 static <I extends Annotatable, V> ParentItemColumn<I, V> create(DbControl dc, String expr)34 public static ParentItemColumn create(DbControl dc, String expr, ParentItemHelper helper) 38 35 { 39 36 String[] tmp = expr.split("/"); 40 37 Item parentType = Item.valueOf(tmp[1]); 41 38 ItemSubtype subtype = ItemSubtype.getById(dc, Values.getInt(tmp[2])); 42 AnnotationType at = AnnotationType.getById(dc, Values.getInt(tmp[3].substring(1)));43 39 44 return new ParentItemColumn<>(expr, subtype, at); 40 ParentItemColumn col = null; 41 if (tmp[3].startsWith("#")) 42 { 43 AnnotationType at = AnnotationType.getById(dc, Values.getInt(tmp[3].substring(1))); 44 col = new ParentItemAnnotationColumn(expr, new SubtypeFilter(subtype), helper, at); 45 col.setTitle(at.getName() + " [A]"); 46 col.setTooltip(subtype.getName() + " › "+at.getName()); 47 col.setValueType(at.getValueType()); 48 } 49 else 50 { 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]); 55 } 56 57 return col; 45 58 } 46 59 47 private String id; 60 private final Filter<Annotatable> filter; 61 protected final ParentItemHelper helper; 48 62 49 private ItemSubtype subtype; 50 private AnnotationType at; 51 52 public ParentItemColumn(String id, ItemSubtype subtype, AnnotationType at) 63 ParentItemColumn(String id, Filter<Annotatable> filter, ParentItemHelper helper) 53 64 { 54 this.id = id; 55 this.subtype = subtype; 56 this.at = at; 65 this.filter = filter; 66 this.helper = helper; 67 setId(id); 68 setProperty(id); 69 setExportable(true); 70 } 71 72 protected Set<Annotatable> getParentItems(DbControl dc, Annotatable item) 73 { 74 return AnnotationUtil.getAllAnnotatableParentItems(dc, item, filter, helper.cache); 57 75 } 58 76 59 @Override60 public String getId()61 {62 return id;63 }64 65 @Override66 public String getClazz()67 {68 return null;69 }70 71 @Override72 public String getStyle()73 {74 return null;75 }76 77 @Override78 public String getTitle()79 {80 return at.getName() + " [A]";81 }82 83 @Override84 public String getTooltip()85 {86 return subtype.getName() + ">"+at.getName();87 }88 89 @Override90 public String getProperty()91 {92 return id;93 }94 95 @Override96 public Type getValueType()97 {98 return at.getValueType();99 }100 101 @Override102 public boolean isSortable()103 {104 return false;105 }106 107 @Override108 public String getSortProperty()109 {110 return null;111 }112 113 @Override114 public boolean isFilterable()115 {116 return false;117 }118 119 @Override120 public String getFilterProperty()121 {122 return null;123 }124 125 @Override126 public boolean isExportable()127 {128 return true;129 }130 131 @Override132 public String getExportProperty()133 {134 return id;135 }136 137 @Override138 public Formatter getExportFormatter()139 {140 return null;141 }142 143 @Override144 public Object getExportValue(DbControl dc, I item)145 {146 return getValue(dc, item);147 }148 149 @Override150 public Enumeration<String, String> getEnumeration()151 {152 return null;153 }154 155 @Override156 public Formatter<? super V> getFormatter()157 {158 return null;159 }160 161 @Override162 public V getValue(DbControl dc, I item)163 {164 165 Set<Annotatable> parents = AnnotationUtil.getAllAnnotatableParentItems(dc, item, this);166 Annotatable p = parents.iterator().next();167 168 if (!p.isAnnotated()) return null;169 if (!p.getAnnotationSet().hasAnnotation(at, Annotation.Source.PRIMARY)) return null;170 return (V)p.getAnnotationSet().getAnnotation(at).getValues();171 }172 173 @Override174 public boolean evaluate(Annotatable item)175 {176 if (item.getType() != subtype.getMainItemType()) return false;177 return subtype.equals(((Subtypable)item).getItemSubtype());178 179 }180 77 181 78 } -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumnActionFactory.java
r7764 r7765 28 28 @since 3.16 29 29 */ 30 public class ParentItemColumnActionFactory <I extends Annotatable, V>31 extends AbstractJspActionFactory<ListColumnAction< I, V>>30 public class ParentItemColumnActionFactory 31 extends AbstractJspActionFactory<ListColumnAction<Annotatable, Object>> 32 32 { 33 33 … … 40 40 */ 41 41 @Override 42 public boolean prepareContext(InvokationContext<? super ListColumnAction< I, V>> context)42 public boolean prepareContext(InvokationContext<? super ListColumnAction<Annotatable, Object>> context) 43 43 { 44 44 JspContext jspContext = (JspContext)context.getClientContext(); … … 60 60 @SuppressWarnings("unchecked") 61 61 @Override 62 public ListColumnAction< I, V>[] getActions(InvokationContext<? super ListColumnAction<I, V>> context)62 public ListColumnAction<Annotatable, Object>[] getActions(InvokationContext<? super ListColumnAction<Annotatable, Object>> context) 63 63 { 64 64 JspContext jspContext = (JspContext)context.getClientContext(); … … 74 74 if (allColumns == null || !allColumns.contains("/")) return null; 75 75 76 List<ListColumnAction<I, V>> actions = new ArrayList<>(); 76 ParentItemHelper helper = new ParentItemHelper(); 77 List<ListColumnAction<Annotatable, Object>> actions = new ArrayList<>(); 77 78 for (String col : allColumns.split(",")) 78 79 { 79 80 if (col.startsWith("/")) 80 81 { 81 ListColumnAction< I, V> action = ParentItemColumn.create(jspContext.getDbControl(), col);82 ListColumnAction<Annotatable, Object> action = ParentItemColumn.create(jspContext.getDbControl(), col, helper); 82 83 if (action != null) actions.add(action); 83 84 }
Note: See TracChangeset
for help on using the changeset viewer.