Changeset 7768
- Timestamp:
- Feb 7, 2020, 11:17:23 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemAnnotationColumn.java
r7767 r7768 22 22 private final Filter<AnnotationSnapshot> atFilter; 23 23 24 ParentItemAnnotationColumn( String id, Filter<Annotatable> filter, ParentItemHelper helper, AnnotationType at)24 ParentItemAnnotationColumn(int index, String id, Filter<Annotatable> filter, ParentItemHelper helper, AnnotationType at) 25 25 { 26 super(i d, filter, helper);26 super(index, id, filter, helper); 27 27 this.at = at; 28 28 this.atFilter = new AnnotationTypeFilter(at); -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumn.java
r7767 r7768 38 38 */ 39 39 @SuppressWarnings({ "unchecked", "rawtypes" }) 40 public static ParentItemColumn create(DbControl dc, String expr, ParentItemHelper helper)40 public static ParentItemColumn create(DbControl dc, int index, String expr, ParentItemHelper helper) 41 41 { 42 42 ParentItemColumn col = null; … … 50 50 { 51 51 AnnotationType at = AnnotationType.getById(dc, Values.getInt(tmp[3].substring(1))); 52 col = new ParentItemAnnotationColumn( expr, parentFilter, helper, at);52 col = new ParentItemAnnotationColumn(index, expr, parentFilter, helper, at); 53 53 col.setTitle(at.getName() + " [A]"); 54 54 col.setTooltip(subtype.getName() + " › "+at.getName()); 55 55 col.setValueType(at.getValueType()); 56 56 col.setExportFormatter(FormatterFactory.getTypeFormatter(dc.getSessionControl(), at.getValueType())); 57 col.setFormatter(new CollectionFormatter(col.getExportFormatter()));57 if (!helper.lazy) col.setFormatter(new CollectionFormatter(col.getExportFormatter())); 58 58 } 59 59 else … … 65 65 Metadata m = Metadata.getInstance(parentType.getItemClass()); 66 66 property = m.getPropertyPath(path, false); 67 col = new ParentItemPropertyColumn( expr, parentFilter, helper, property);67 col = new ParentItemPropertyColumn(index, expr, parentFilter, helper, property); 68 68 col.setTitle(subtype.getName()+"."+path); 69 69 col.setTooltip(subtype.getName() + " › "+path); … … 71 71 else 72 72 { 73 col = new ParentItemPropertyColumn( expr, parentFilter, helper, null);73 col = new ParentItemPropertyColumn(index, expr, parentFilter, helper, null); 74 74 col.setTitle(subtype.getName()); 75 75 col.setTooltip(subtype.getName()); … … 78 78 { 79 79 col.setExportFormatter(new NameableFormatter()); 80 col.setFormatter(new CollectionFormatter(new LinkedItemFormatter()));80 if (!helper.lazy) col.setFormatter(new CollectionFormatter(new LinkedItemFormatter())); 81 81 } 82 82 else 83 83 { 84 84 col.setExportFormatter(new ToStringFormatter<>()); 85 col.setFormatter(new CollectionFormatter(col.getExportFormatter()));85 if (!helper.lazy) col.setFormatter(new CollectionFormatter(col.getExportFormatter())); 86 86 } 87 87 } … … 93 93 } 94 94 95 private final int index; 95 96 private final Filter<Annotatable> filter; 96 97 private final ParentItemHelper helper; 97 98 98 ParentItemColumn( String id, Filter<Annotatable> filter, ParentItemHelper helper)99 ParentItemColumn(int index, String id, Filter<Annotatable> filter, ParentItemHelper helper) 99 100 { 101 this.index = index; 100 102 this.filter = filter; 101 103 this.helper = helper; … … 115 117 public final Object getValue(DbControl dc, Annotatable item) 116 118 { 119 if (helper.lazy) return getProxyTag(item); 117 120 item = helper.recycle(dc, item); 118 121 return getValue(helper, item); 119 122 } 120 123 124 /** 125 Generate a proxy tag that is returned instead of actual data. A 126 JavaScript in 'lazy-parent-items.js' will scan the table and 127 inject the actual data in batches. 128 */ 129 private String getProxyTag(Annotatable item) 130 { 131 StringBuilder sb = new StringBuilder(); 132 sb.append("<div"); 133 sb.append(" class=\"lazy-parent not-loaded\""); 134 sb.append(" id=\"lazy-parent-").append(index).append("-").append(item.getId()).append("\""); 135 sb.append(" data-item-id=\"").append(item.getId()).append("\""); 136 sb.append(" data-index=\"").append(index).append("\""); 137 sb.append("></div>"); 138 return sb.toString(); 139 } 140 141 /** 142 We finalize this implementation to make sure that the helper 143 implementation always get a chance to re-cycle transactions. 144 Subclasses should implement {@link #getValue(ParentItemHelper, Annotatable)} 145 to return the requested value from the item and use the 146 DbControl from {@link ParentItemHelper#dc}. 147 */ 148 @Override 149 public final Object getExportValue(DbControl dc, Annotatable item) 150 { 151 item = helper.recycle(dc, item); 152 return getValue(helper, item); 153 } 154 155 121 156 /** 122 157 Alternate implementation for loading data. -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemColumnActionFactory.java
r7767 r7768 55 55 if (allColumns == null || !allColumns.contains("/")) return false; 56 56 57 jspContext.addScript(jspContext.getRoot() + "/include/scripts/lazy-parent-items.js"); 57 58 return super.prepareContext(context); 58 59 } … … 75 76 if (allColumns == null || !allColumns.contains("/")) return null; 76 77 78 79 boolean lazy = !Boolean.FALSE.equals(jspContext.getAttribute("lazy-loading")); 77 80 DbControl dc = jspContext.getDbControl(); 78 ParentItemHelper helper = new ParentItemHelper(sc );81 ParentItemHelper helper = new ParentItemHelper(sc, lazy); 79 82 List<ListColumnAction<Annotatable, Object>> actions = new ArrayList<>(); 80 83 for (String col : allColumns.split(",")) … … 82 85 if (col.startsWith("/")) 83 86 { 84 ListColumnAction<Annotatable, Object> action = ParentItemColumn.create(dc, col, helper);87 ListColumnAction<Annotatable, Object> action = ParentItemColumn.create(dc, actions.size(), col, helper); 85 88 if (action != null) actions.add(action); 86 89 } -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemHelper.java
r7767 r7768 24 24 25 25 final SessionControl sc; 26 final boolean lazy; 26 27 // Use the snapshot manager for efficient loading of annotations 27 28 final SnapshotManager manager; … … 32 33 DbControl dc; 33 34 34 ParentItemHelper(SessionControl sc )35 ParentItemHelper(SessionControl sc, boolean lazy) 35 36 { 36 37 this.sc = sc; 38 this.lazy = lazy; 37 39 this.manager = new SnapshotManager(); 38 40 this.cache = AnnotationUtil.createCache(); -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/list/ParentItemPropertyColumn.java
r7767 r7768 22 22 private final PropertyPath<? super Annotatable, ?> property; 23 23 24 ParentItemPropertyColumn( String id, Filter<Annotatable> filter, ParentItemHelper helper, PropertyPath<? super Annotatable, ?> property)24 ParentItemPropertyColumn(int index, String id, Filter<Annotatable> filter, ParentItemHelper helper, PropertyPath<? super Annotatable, ?> property) 25 25 { 26 super(i d, filter, helper);26 super(index, id, filter, helper); 27 27 this.property = property; 28 28 } -
trunk/www/include/styles/table.css
r7604 r7768 377 377 } 378 378 379 379 .lazy-parent.not-loaded 380 { 381 outline: 1px dotted #A0A0A0; 382 margin: 0 1em; 383 height: 3px; 384 } 385 386
Note: See TracChangeset
for help on using the changeset viewer.