Changeset 6353
- Timestamp:
- 07/06/15 08:33:16 (9 years ago)
- Location:
- vlo/trunk/vlo-web-app/src/main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/trunk/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/record/HierarchyPanel.html
r6346 r6353 33 33 <div wicket:id="parents"> 34 34 <div class="tree-parent" wicket:id="parentsList"> 35 <a wicket:id="link">[link]</a> 35 <a class="parent-up" wicket:id="up" title="Move up in hierarchy"><span>[up]</span></a> 36 <wicket:container wicket:id="link">[link]</wicket:container> 36 37 </div> 37 38 <a wicket:id="showAll">Show all... (<span wicket:id="itemCount">999</span>)</a> -
vlo/trunk/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/record/HierarchyPanel.java
r6348 r6353 31 31 import org.apache.wicket.behavior.AttributeAppender; 32 32 import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxFallbackLink; 33 import org.apache.wicket.extensions.markup.html.repeater.tree.AbstractTree; 33 34 import org.apache.wicket.extensions.markup.html.repeater.tree.DefaultNestedTree; 34 35 import org.apache.wicket.extensions.markup.html.repeater.util.SortableTreeProvider; … … 55 56 */ 56 57 public static final int INITIAL_PARENTS_SHOWN = 5; 57 58 58 59 @SpringBean 59 60 private SolrDocumentService documentService; 60 61 61 62 private final IDataProvider<SolrDocument> parentsProvider; 62 63 private final AbstractTree<SolrDocument> tree; 64 private final IModel<SolrDocument> pageDocumentModel; 65 63 66 public HierarchyPanel(String id, IModel<SolrDocument> documentModel) { 64 67 super(id, documentModel); 65 68 pageDocumentModel = documentModel; 69 66 70 parentsProvider = new ParentsDataProvider(); 67 71 68 72 add(createParentLinks("parents")); 69 add(createTree("tree")); 70 } 71 73 74 tree = createTree("tree"); 75 add(tree); 76 77 setOutputMarkupId(true); 78 } 79 72 80 private Component createParentLinks(String id) { 73 81 // data view of (first N) parents and a link to load all in an … … 77 85 // actual view 78 86 final DataView<SolrDocument> parentsView = new DataView<SolrDocument>("parentsList", parentsProvider, INITIAL_PARENTS_SHOWN) { 79 80 @Override 81 protected void populateItem( Item<SolrDocument> item) {87 88 @Override 89 protected void populateItem(final Item<SolrDocument> item) { 82 90 item.add(new NamedRecordPageLink("link", item.getModel())); 83 } 84 91 item.add(new IndicatingAjaxFallbackLink("up") { 92 93 @Override 94 public void onClick(AjaxRequestTarget target) { 95 // tree root up one level, expand root for traceability by user 96 HierarchyPanel.this.setModel(item.getModel()); 97 tree.expand(item.getModelObject()); 98 if (target != null) { 99 target.add(HierarchyPanel.this); 100 } 101 } 102 }); 103 } 104 85 105 @Override 86 106 protected void onConfigure() { … … 92 112 // ajax link to load the entire list, only shown if applicable 93 113 final Link showAllLink = new IndicatingAjaxFallbackLink("showAll") { 94 114 95 115 @Override 96 116 public void onClick(AjaxRequestTarget target) { … … 100 120 } 101 121 } 102 122 103 123 @Override 104 124 protected void onConfigure() { … … 109 129 // show how many ndoes can be loaded 110 130 showAllLink.add(new Label("itemCount", new PropertyModel<Integer>(parentsProvider, "size"))); 111 131 112 132 return container 113 133 .add(parentsView) … … 115 135 .setOutputMarkupId(true); 116 136 } 117 118 private ComponentcreateTree(String id) {137 138 private AbstractTree<SolrDocument> createTree(String id) { 119 139 final DefaultNestedTree<SolrDocument> tree = new DefaultNestedTree<SolrDocument>(id, new HierarchyTreeProvider()) { 120 140 121 141 @Override 122 142 protected Component newContentComponent(String id, final IModel<SolrDocument> node) { 123 143 return new NamedRecordPageLink(id, node) { 124 144 125 145 @Override 126 146 protected void onConfigure() { 127 setEnabled(!node.equals( HierarchyPanel.this.getModel()));147 setEnabled(!node.equals(pageDocumentModel)); 128 148 } 129 149 }; 130 150 } 131 151 132 152 }; 133 153 // style of tree depends on presence of parent nodes 134 154 tree.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() { 135 155 136 156 @Override 137 157 public String getObject() { … … 145 165 return tree; 146 166 } 147 167 148 168 @Override 149 169 public void detachModels() { 150 170 super.detachModels(); 151 } 152 171 pageDocumentModel.detach(); 172 } 173 153 174 private class HierarchyTreeProvider extends SortableTreeProvider<SolrDocument, Object> { 154 175 155 176 @Override 156 177 public Iterator<? extends SolrDocument> getRoots() { 157 178 return Iterators.singletonIterator(HierarchyPanel.this.getModel().getObject()); 158 179 } 159 180 160 181 @Override 161 182 public boolean hasChildren(SolrDocument node) { … … 163 184 return (partCount instanceof Number) && ((Number) partCount).intValue() > 0; 164 185 } 165 186 166 187 @Override 167 188 public Iterator<? extends SolrDocument> getChildren(SolrDocument node) { 168 189 final Collection<Object> parts = node.getFieldValues(FacetConstants.FIELD_HAS_PART); 169 190 return Iterators.transform(parts.iterator(), new Function<Object, SolrDocument>() { 170 191 171 192 @Override 172 193 public SolrDocument apply(Object input) { … … 176 197 }); 177 198 } 178 199 179 200 @Override 180 201 public IModel<SolrDocument> model(SolrDocument object) { … … 182 203 } 183 204 } 184 205 185 206 private class ParentsDataProvider implements IDataProvider<SolrDocument> { 186 207 187 208 // used to cache parent count (until detach) 188 209 private Long size = null; 189 210 190 211 @Override 191 212 public Iterator<? extends SolrDocument> iterator(long first, long count) { … … 197 218 // parents found, convert ID collection into documents list 198 219 return Iterators.transform(parentIds.iterator(), new Function<Object, SolrDocument>() { 199 220 200 221 @Override 201 222 public SolrDocument apply(Object docId) { … … 205 226 } 206 227 } 207 228 208 229 @Override 209 230 public long size() { … … 220 241 return size; 221 242 } 222 243 223 244 @Override 224 245 public IModel<SolrDocument> model(SolrDocument object) { 225 246 return new SolrDocumentModel(object); 226 247 } 227 248 228 249 @Override 229 250 public void detach() { … … 231 252 } 232 253 } 233 254 234 255 } -
vlo/trunk/vlo-web-app/src/main/less/eu/clarin/cmdi/vlo/wicket/pages/inc/vlo-record.less
r6332 r6353 278 278 #recordtree { 279 279 padding-bottom: 1em; 280 } 281 282 #recordtree #thisrecord { 283 list-style-type: circle; 284 font-weight: bold; 285 } 286 287 #recordtree .tree-parent { 288 padding-left: 16px; 289 background-image: url('up-3-filled-64.png'); /* icon from icons8.com */ 290 background-repeat: no-repeat; 291 background-size: 12px; 292 background-position: top left; 293 294 min-height: 12px; 295 padding-bottom: 2px; 296 } 297 298 #recordtree .tree-parent a { 299 color: black; 300 } 301 302 #recordtree #tree.has-parent { 303 padding-left: 18px; 304 } 305 306 #recordtree .tree-branch { 307 clear: both; 308 } 309 310 #recordtree .tree-branch a { 311 312 } 280 281 282 #thisrecord { 283 list-style-type: circle; 284 font-weight: bold; 285 } 286 287 .tree-parent a.parent-up { 288 display: inline-block; 289 width: 16px; 290 background-image: url('up-3-filled-64.png'); /* icon from icons8.com */ 291 background-repeat: no-repeat; 292 background-size: 12px; 293 background-position: top left; 294 295 min-height: 12px; 296 padding-bottom: 2px; 297 298 vertical-align: top; 299 300 &:hover { 301 background-color: #ccc; 302 text-decoration: none; 303 } 304 305 span { 306 display: none; 307 } 308 } 309 310 .tree-parent, .tree-branch content { 311 a { 312 color: black; 313 314 &:hover { 315 text-decoration: underline; 316 } 317 } 318 } 319 320 #tree.has-parent { 321 padding-left: 18px; 322 } 323 324 .tree-branch { 325 clear: both; 326 } 327 } 328
Note: See TracChangeset
for help on using the changeset viewer.