Changeset 6353


Ignore:
Timestamp:
07/06/15 08:33:16 (9 years ago)
Author:
Twan Goosen
Message:

navigate up tree hierarchy within record page (ajax enabled)

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  
    3333            <div wicket:id="parents">
    3434                <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>
    3637                </div>
    3738                <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  
    3131import org.apache.wicket.behavior.AttributeAppender;
    3232import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxFallbackLink;
     33import org.apache.wicket.extensions.markup.html.repeater.tree.AbstractTree;
    3334import org.apache.wicket.extensions.markup.html.repeater.tree.DefaultNestedTree;
    3435import org.apache.wicket.extensions.markup.html.repeater.util.SortableTreeProvider;
     
    5556     */
    5657    public static final int INITIAL_PARENTS_SHOWN = 5;
    57 
     58   
    5859    @SpringBean
    5960    private SolrDocumentService documentService;
    60 
     61   
    6162    private final IDataProvider<SolrDocument> parentsProvider;
    62 
     63    private final AbstractTree<SolrDocument> tree;
     64    private final IModel<SolrDocument> pageDocumentModel;
     65   
    6366    public HierarchyPanel(String id, IModel<SolrDocument> documentModel) {
    6467        super(id, documentModel);
    65 
     68        pageDocumentModel = documentModel;
     69       
    6670        parentsProvider = new ParentsDataProvider();
    67 
     71       
    6872        add(createParentLinks("parents"));
    69         add(createTree("tree"));
    70     }
    71 
     73       
     74        tree = createTree("tree");
     75        add(tree);
     76       
     77        setOutputMarkupId(true);
     78    }
     79   
    7280    private Component createParentLinks(String id) {
    7381        // data view of (first N) parents and a link to load all in an
     
    7785        // actual view
    7886        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) {
    8290                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           
    85105            @Override
    86106            protected void onConfigure() {
     
    92112        // ajax link to load the entire list, only shown if applicable
    93113        final Link showAllLink = new IndicatingAjaxFallbackLink("showAll") {
    94 
     114           
    95115            @Override
    96116            public void onClick(AjaxRequestTarget target) {
     
    100120                }
    101121            }
    102 
     122           
    103123            @Override
    104124            protected void onConfigure() {
     
    109129        // show how many ndoes can be loaded
    110130        showAllLink.add(new Label("itemCount", new PropertyModel<Integer>(parentsProvider, "size")));
    111 
     131       
    112132        return container
    113133                .add(parentsView)
     
    115135                .setOutputMarkupId(true);
    116136    }
    117 
    118     private Component createTree(String id) {
     137   
     138    private AbstractTree<SolrDocument> createTree(String id) {
    119139        final DefaultNestedTree<SolrDocument> tree = new DefaultNestedTree<SolrDocument>(id, new HierarchyTreeProvider()) {
    120 
     140           
    121141            @Override
    122142            protected Component newContentComponent(String id, final IModel<SolrDocument> node) {
    123143                return new NamedRecordPageLink(id, node) {
    124 
     144                   
    125145                    @Override
    126146                    protected void onConfigure() {
    127                         setEnabled(!node.equals(HierarchyPanel.this.getModel()));
     147                        setEnabled(!node.equals(pageDocumentModel));
    128148                    }
    129149                };
    130150            }
    131 
     151           
    132152        };
    133153        // style of tree depends on presence of parent nodes
    134154        tree.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
    135 
     155           
    136156            @Override
    137157            public String getObject() {
     
    145165        return tree;
    146166    }
    147 
     167   
    148168    @Override
    149169    public void detachModels() {
    150170        super.detachModels();
    151     }
    152 
     171        pageDocumentModel.detach();
     172    }
     173   
    153174    private class HierarchyTreeProvider extends SortableTreeProvider<SolrDocument, Object> {
    154 
     175       
    155176        @Override
    156177        public Iterator<? extends SolrDocument> getRoots() {
    157178            return Iterators.singletonIterator(HierarchyPanel.this.getModel().getObject());
    158179        }
    159 
     180       
    160181        @Override
    161182        public boolean hasChildren(SolrDocument node) {
     
    163184            return (partCount instanceof Number) && ((Number) partCount).intValue() > 0;
    164185        }
    165 
     186       
    166187        @Override
    167188        public Iterator<? extends SolrDocument> getChildren(SolrDocument node) {
    168189            final Collection<Object> parts = node.getFieldValues(FacetConstants.FIELD_HAS_PART);
    169190            return Iterators.transform(parts.iterator(), new Function<Object, SolrDocument>() {
    170 
     191               
    171192                @Override
    172193                public SolrDocument apply(Object input) {
     
    176197            });
    177198        }
    178 
     199       
    179200        @Override
    180201        public IModel<SolrDocument> model(SolrDocument object) {
     
    182203        }
    183204    }
    184 
     205   
    185206    private class ParentsDataProvider implements IDataProvider<SolrDocument> {
    186207
    187208        // used to cache parent count (until detach)
    188209        private Long size = null;
    189 
     210       
    190211        @Override
    191212        public Iterator<? extends SolrDocument> iterator(long first, long count) {
     
    197218                // parents found, convert ID collection into documents list
    198219                return Iterators.transform(parentIds.iterator(), new Function<Object, SolrDocument>() {
    199 
     220                   
    200221                    @Override
    201222                    public SolrDocument apply(Object docId) {
     
    205226            }
    206227        }
    207 
     228       
    208229        @Override
    209230        public long size() {
     
    220241            return size;
    221242        }
    222 
     243       
    223244        @Override
    224245        public IModel<SolrDocument> model(SolrDocument object) {
    225246            return new SolrDocumentModel(object);
    226247        }
    227 
     248       
    228249        @Override
    229250        public void detach() {
     
    231252        }
    232253    }
    233 
     254   
    234255}
  • vlo/trunk/vlo-web-app/src/main/less/eu/clarin/cmdi/vlo/wicket/pages/inc/vlo-record.less

    r6332 r6353  
    278278#recordtree {
    279279    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.