Example usage for org.apache.wicket.markup.repeater IItemReuseStrategy IItemReuseStrategy

List of usage examples for org.apache.wicket.markup.repeater IItemReuseStrategy IItemReuseStrategy

Introduction

In this page you can find the example usage for org.apache.wicket.markup.repeater IItemReuseStrategy IItemReuseStrategy.

Prototype

IItemReuseStrategy

Source Link

Usage

From source file:org.efaps.ui.wicket.components.tree.SubElement.java

License:Apache License

/**
 * @param _wicketId wicket id for this component
 * @param _tree Nested tree element//from w w  w  . j  a v a  2s  . co m
 * @param _model model for this component
 */
public SubElement(final String _wicketId, final NestedTree<UIStructurBrowser> _tree,
        final IModel<UIStructurBrowser> _model) {
    super(_wicketId, _model);

    if (_tree == null) {
        throw new IllegalArgumentException("argument [tree] cannot be null");
    }
    this.tree = _tree;

    final RefreshingView<UIStructurBrowser> branches = new RefreshingView<UIStructurBrowser>("branches") {

        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<IModel<UIStructurBrowser>> getItemModels() {
            return new ModelIterator();
        }

        @Override
        protected Item<UIStructurBrowser> newItem(final String _wicketId, final int _index,
                final IModel<UIStructurBrowser> _model) {
            return newBranchItem(_wicketId, _index, _model);
        }

        @Override
        protected void populateItem(final Item<UIStructurBrowser> _item) {
            try {
                populateBranch(_item);
            } catch (final EFapsException e) {
                SubElement.LOG.error("EFapsException", e);
            }
        }
    };
    branches.setItemReuseStrategy(new IItemReuseStrategy() {

        private static final long serialVersionUID = 1L;

        @Override
        public <S> Iterator<Item<S>> getItems(final IItemFactory<S> _factory,
                final Iterator<IModel<S>> _newModels, final Iterator<Item<S>> _existingItems) {
            return SubElement.this.tree.getItemReuseStrategy().getItems(_factory, _newModels, _existingItems);
        }
    });
    add(branches);
}

From source file:wickettree.nested.Subtree.java

License:Apache License

/**
 * Create a subtree for the children of the node contained in the given
 * model or the root nodes if the model contains <code>null</code>.
 * // ww  w .  j  a  v a  2 s .  c om
 * @param id
 *            component id
 * @param tree
 *            the containing tree
 * @param model
 */
public Subtree(String id, final NestedTree<T> tree, final IModel<T> model) {
    super(id, model);

    if (tree == null) {
        throw new IllegalArgumentException("argument [tree] cannot be null");
    }
    this.tree = tree;

    RefreshingView<T> branches = new RefreshingView<T>("branches") {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<IModel<T>> getItemModels() {
            return new ModelIterator();
        }

        @Override
        protected Item<T> newItem(String id, int index, IModel<T> model) {
            return newBranchItem(id, index, model);
        }

        @Override
        protected void populateItem(Item<T> item) {
            IModel<T> model = item.getModel();

            Component node = tree.newNodeComponent("node", model);
            item.add(node);

            item.add(tree.newSubtree("subtree", model));
        }
    };
    branches.setItemReuseStrategy(new IItemReuseStrategy() {
        private static final long serialVersionUID = 1L;

        public <S> Iterator<Item<S>> getItems(IItemFactory<S> factory, Iterator<IModel<S>> newModels,
                Iterator<Item<S>> existingItems) {
            return tree.getItemReuseStrategy().getItems(factory, newModels, existingItems);
        }
    });
    add(branches);
}

From source file:wickettree.TableTree.java

License:Apache License

/**
 * Constructor//from   w w  w .j a  v a 2s.c  o m
 * 
 * @param id
 *            component id
 * @param columns
 *            list of column definitions
 * @param provider
 *            provider of the tree
 * @param itemsPerPage
 *            number of rows per page
 * @param state
 *            state of nodes
 */
public TableTree(String id, List<IColumn<T>> columns, ITreeProvider<T> provider, int itemsPerPage,
        IModel<Set<T>> state) {
    super(id, provider, state);

    if (columns == null || columns.isEmpty()) {
        throw new IllegalArgumentException("Argument `columns` cannot be null or empty");
    }
    for (IColumn<T> column : columns) {
        if (column instanceof ITreeColumn<?>) {
            ((ITreeColumn<T>) column).setTree(this);
        }
    }
    this.columns = columns;

    WebMarkupContainer body = newBodyContainer("body");
    add(body);

    datagrid = new DataGridView<T>("rows", columns, newDataProvider(provider)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Item<ICellPopulator<T>> newCellItem(String id, int index, IModel<ICellPopulator<T>> model) {
            Item<ICellPopulator<T>> item = TableTree.this.newCellItem(id, index, model);

            final IColumn<?> column = TableTree.this.columns.get(index);
            if (column instanceof IStyledColumn<?>) {
                item.add(new AttributeAppender("class", Model.of(((IStyledColumn<?>) column).getCssClass()),
                        " "));
            }

            return item;
        }

        @Override
        protected Item<T> newRowItem(String id, int index, IModel<T> model) {
            Item<T> item = TableTree.this.newRowItem(id, index, model);

            // @see #updateNode(T, AjaxRequestTarget)
            item.setOutputMarkupId(true);

            return item;
        }
    };
    datagrid.setItemsPerPage(itemsPerPage);
    datagrid.setItemReuseStrategy(new IItemReuseStrategy() {
        private static final long serialVersionUID = 1L;

        public <S> Iterator<Item<S>> getItems(IItemFactory<S> factory, Iterator<IModel<S>> newModels,
                Iterator<Item<S>> existingItems) {
            return TableTree.this.getItemReuseStrategy().getItems(factory, newModels, existingItems);
        }
    });
    body.add(datagrid);

    topToolbars = new ToolbarsContainer("topToolbars");
    bottomToolbars = new ToolbarsContainer("bottomToolbars");
    add(topToolbars);
    add(bottomToolbars);
}