Example usage for org.apache.wicket.extensions.markup.html.repeater.data.table NavigationToolbar NavigationToolbar

List of usage examples for org.apache.wicket.extensions.markup.html.repeater.data.table NavigationToolbar NavigationToolbar

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.markup.html.repeater.data.table NavigationToolbar NavigationToolbar.

Prototype

public NavigationToolbar(final DataTable<?, ?> table) 

Source Link

Document

Constructor

Usage

From source file:com.wt.dms.web.IndexManagerDataTable.java

License:Apache License

/**
 * Constructor// w  ww .j  av a 2 s  . com
 * 
 * @param id
 *            component id
 * @param columns
 *            list of columns
 * @param dataProvider
 *            data provider
 * @param rowsPerPage
 *            number of rows per page
 */
public IndexManagerDataTable(final String id, final List<IColumn<T>> columns,
        final ISortableDataProvider<T> dataProvider, final int rowsPerPage) {
    super(id, columns, dataProvider, rowsPerPage);

    addTopToolbar(new HeadersToolbar(this, dataProvider));
    addBottomToolbar(new NoRecordsToolbar(this));
    /*addTopToolbar(new NavigationToolbar(this));*/
    addBottomToolbar(new NavigationToolbar(this));
}

From source file:de.alpharogroup.wicket.data.provider.examples.datatable.DataTablePanel.java

License:Apache License

public DataTablePanel(final String id) {
    super(id);//  w w  w  . j ava2s  . c  o m

    final SortableFilterPersonDataProvider dataProvider = new SortableFilterPersonDataProvider(
            PersonDatabaseManager.getInstance().getPersons()) {
        private static final long serialVersionUID = 1L;

        @Override
        public List<Person> getData() {
            final List<Person> persons = PersonDatabaseManager.getInstance().getPersons();
            setData(persons);
            return persons;
        }
    };
    dataProvider.setSort("firstname", SortOrder.ASCENDING);

    final List<IColumn<Person, String>> columns = new ArrayList<>();

    columns.add(new AbstractColumn<Person, String>(new Model<>("Actions")) {
        /**
         * The serialVersionUID
         */
        private static final long serialVersionUID = 1L;

        /**
         * {@inheritDoc}
         */
        @Override
        public void populateItem(final Item<ICellPopulator<Person>> cellItem, final String componentId,
                final IModel<Person> model) {
            final ActionPanel<Person> editActionPanel = new ActionPanel<Person>(componentId, model) {

                /**
                 * The serialVersionUID
                 */
                private static final long serialVersionUID = 1L;

                /**
                 * {@inheritDoc}
                 */
                @Override
                protected IModel<String> newActionLinkLabelModel() {
                    return ResourceModelFactory.newResourceModel("global.main.button.edit.label");
                }

                /**
                 * {@inheritDoc}
                 */
                @Override
                protected void onAction(final AjaxRequestTarget target) {
                    DataTablePanel.this.onEdit(target);
                }

            };
            cellItem.add(editActionPanel);
        }
    });

    columns.add(new PropertyColumn<Person, String>(Model.of("First name"), "firstname", "firstname"));
    columns.add(new PropertyColumn<Person, String>(Model.of("Last Name"), "lastname", "lastname") {
        private static final long serialVersionUID = 1L;

        @Override
        public String getCssClass() {
            return "last-name";
        }
    });
    columns.add(new PropertyColumn<Person, String>(Model.of("Date of birth"), "dateOfBirth", "dateOfBirth"));

    final DataTable<Person, String> tableWithFilterForm = new DataTable<>("tableWithFilterForm", columns,
            dataProvider, 10);
    tableWithFilterForm.setOutputMarkupId(true);

    final FilterForm<PersonFilter> filterForm = new FilterForm<>("filterForm", dataProvider);
    filterForm.add(new TextField<>("dateFrom", PropertyModel.of(dataProvider, "filterState.dateFrom")));
    filterForm.add(new TextField<>("dateTo", PropertyModel.of(dataProvider, "filterState.dateTo")));
    add(filterForm);

    final FilterToolbar filterToolbar = new FilterToolbar(tableWithFilterForm, filterForm);
    tableWithFilterForm.addTopToolbar(filterToolbar);
    tableWithFilterForm.addTopToolbar(new NavigationToolbar(tableWithFilterForm));
    tableWithFilterForm.addTopToolbar(new HeadersToolbar<>(tableWithFilterForm, dataProvider));
    filterForm.add(tableWithFilterForm);
}

From source file:net.databinder.components.hib.QueryPanel.java

License:Open Source License

/**
 * Creates a result table for the current query.
 * @return a result table, or an empty label if there is no current query
 *//*  w  w  w  .ja v a 2  s  .com*/
private Component getResultsTable() {
    if (Strings.isEmpty(query.getQuery())) {
        return new Label("results", "");
    } else {
        IDataProvider dataProvider = new IDataProvider() {
            private static final long serialVersionUID = 1L;

            public void detach() {
            }

            public int size() {
                Session sess = Databinder.getHibernateSession();
                Query query = sess.createQuery(getQuery());
                return query.list().size();
            }

            public String getQuery() {
                return QueryPanel.this.query.getQuery();
            }

            public IModel model(Object object) {
                return new BoundCompoundPropertyModel(new HibernateObjectModel(object));
            }

            public Iterator iterator(int first, int count) {
                Session sess = Databinder.getHibernateSession();
                long start = System.nanoTime();
                try {
                    Query q = sess.createQuery(getQuery());
                    q.setFirstResult(first);
                    q.setMaxResults(count);
                    return q.iterate();
                } finally {
                    float nanoTime = ((System.nanoTime() - start) / 1000) / 1000.0f;
                    setExecutionInfo("query executed in " + nanoTime + " ms: " + getQuery());
                }
            }
        };
        IColumn[] columns;
        Session sess = Databinder.getHibernateSession();
        Query q = sess.createQuery(query.getQuery());
        String[] aliases;
        Type[] returnTypes;
        try {
            aliases = q.getReturnAliases();
            returnTypes = q.getReturnTypes();
        } catch (NullPointerException e) { // thrown on updates
            return new Label("results", "");
        }

        if (returnTypes.length != 1) {
            columns = new IColumn[returnTypes.length];
            for (int i = 0; i < returnTypes.length; i++) {
                String alias = aliases == null || aliases.length <= i ? returnTypes[i].getName() : aliases[i];
                final int index = i;
                columns[i] = new AbstractColumn(new Model(alias)) {
                    private static final long serialVersionUID = 1L;

                    public void populateItem(Item cellItem, String componentId, IModel rowModel) {
                        Object[] objects = (Object[]) rowModel.getObject();
                        cellItem.add(new Label(componentId,
                                new Model(objects[index] == null ? "" : objects[index].toString())));
                    }
                };
            }
        } else {
            Type returnType = returnTypes[0];
            if (returnType.isEntityType()) {
                Class clss = returnType.getReturnedClass();
                ClassMetadata metadata = Databinder.getHibernateSessionFactory().getClassMetadata(clss);
                List<IColumn> cols = new ArrayList<IColumn>();
                String idProp = metadata.getIdentifierPropertyName();
                cols.add(new PropertyColumn(new Model(idProp), idProp));
                String[] properties = metadata.getPropertyNames();
                for (String prop : properties) {
                    Type type = metadata.getPropertyType(prop);
                    if (type.isCollectionType()) {
                        // TODO: see if we could provide a link to the collection value
                    } else {
                        cols.add(new PropertyColumn(new Model(prop), prop));
                    }
                }
                columns = (IColumn[]) cols.toArray(new IColumn[cols.size()]);
            } else {
                String alias = aliases == null || aliases.length == 0 ? returnType.getName() : aliases[0];
                columns = new IColumn[] { new AbstractColumn(new Model(alias)) {
                    private static final long serialVersionUID = 1L;

                    public void populateItem(Item cellItem, String componentId, IModel rowModel) {
                        cellItem.add(new Label(componentId, rowModel));
                    }
                } };
            }
        }
        DataTable dataTable = new DataTable("results", columns, dataProvider, 10);

        dataTable.addTopToolbar(new HeadersToolbar(dataTable, null));
        dataTable.addBottomToolbar(new NavigationToolbar(dataTable));
        dataTable.setOutputMarkupId(true);
        return dataTable;
    }
}

From source file:net.fatlenny.datacitation.webapp.pages.DatasetCreationPage.java

License:Apache License

private void initializeDatatable(String selectedFile, String queryString) {
    if (selectedFile == null) {
        add(new Label("datatable", "Error populating data table."));
        return;//from w  w w  .j  a  v  a2 s  .c om
    }

    try {
        TableModel tableModel;
        if (queryString.isEmpty()) {
            tableModel = citationDBService.loadDataset(selectedFile.toString());
        } else {
            String pidIdentifier = UUID.randomUUID().toString();
            PID pid = new DefaultPID.PIDBuilder(pidIdentifier).setName(pidIdentifier).build();

            Revision revision = new DefaultRevision("HEAD");

            Query query = new DefaultQuery.QueryBuilder(pid, queryString, selectedFile, revision).build();

            tableModel = citationDBService.getQueryResult(query);
        }

        revision = tableModel.getMetaData().getRevision().getRevisionId();

        List<IColumn> header = new ArrayList<>();
        List<String> headerData = tableModel.getHeaderData();

        for (int i = 0; i < headerData.size(); i++) {
            header.add(new PropertyColumn<>(new Model<>(headerData.get(i)), String.format("%s", i)));
        }
        List<String[]> rows = tableModel.getRowData();

        ListDataProvider<String[]> dataProvider = new ListDataProvider<>(rows);

        DataTable<String, String> table = new DataTable("datatable", header, dataProvider, 15);
        table.addBottomToolbar(new NavigationToolbar(table));
        table.addTopToolbar(new HeadersToolbar(table, null));
        add(table);
    } catch (CitationDBException e) {
        error(e.getMessage());
        add(new Label("datatable", "Error populating data table."));
    }
}

From source file:net.fatlenny.datacitation.webapp.pages.QueryPage.java

License:Apache License

public QueryPage(final PageParameters parameters) {
    super(parameters);

    StringValue selectedQueryPid = parameters.get(Constants.PID_PARAM);

    add(new BookmarkablePageLink<Void>("home", HomePage.class));

    add(new FeedbackPanel("feedback"));

    if (selectedQueryPid.isEmpty()) {
        error("No query transmitted. Please go back and select a valid query.");
        LOG.error("Parameter 'selectedQueryPid' null or emtpy.");
    }//w  w w.j  av a2 s.c  o m

    Query query = citationDBService.getQueryById(selectedQueryPid.toString());
    TableModel tableModel = citationDBService.getQueryResult(query);

    final TextArea<String> queryString = new TextArea<String>("queryString",
            Model.of(wrapLines(query.getQuery())));
    queryString.setEnabled(false);
    add(queryString);

    List<IColumn> header = new ArrayList<>();
    List<String> headerData = tableModel.getHeaderData();

    for (int i = 0; i < headerData.size(); i++) {
        header.add(new PropertyColumn<>(new Model<>(headerData.get(i)), String.format("%s", i)));
    }

    List<String[]> rows = tableModel.getRowData();

    ListDataProvider<String[]> dataProvider = new ListDataProvider<>(rows);

    DataTable<String, String> table = new DataTable("datatable", header, dataProvider, 15);
    table.addBottomToolbar(new NavigationToolbar(table));
    table.addTopToolbar(new HeadersToolbar(table, null));
    add(table);
}

From source file:org.cast.cwm.admin.EventLog.java

License:Open Source License

public EventLog(final PageParameters params) {
    super(params);
    setPageTitle("Event Log");

    addFilterForm();//from   w w  w.j a v a2s.c o  m

    OrderingCriteriaBuilder builder = makeCriteriaBuilder();
    SortableHibernateProvider<Event> eventsprovider = makeHibernateProvider(builder);
    List<IDataColumn<Event>> columns = makeColumns();
    DataTable<Event, String> table = new DataTable<Event, String>("eventtable", columns, eventsprovider, 30);
    table.addTopToolbar(new HeadersToolbar<String>(table, eventsprovider));
    table.addTopToolbar(new NavigationToolbar(table));
    table.addBottomToolbar(new NavigationToolbar(table));
    table.addBottomToolbar(new NoRecordsToolbar(table, new Model<String>("No events found")));
    add(table);

    CSVDownload<Event> download = new CSVDownload<Event>(columns, eventsprovider);
    add(new ResourceLink<Object>("downloadLink", download));
}

From source file:org.cast.cwm.admin.SessionListPage.java

License:Open Source License

public SessionListPage(final PageParameters parameters) {
    super(parameters);

    setPageTitle("Session List");

    LoginSessionCriteriaBuilder builder = new LoginSessionCriteriaBuilder();
    SortableHibernateProvider<LoginSession> provider = new SortableHibernateProvider<LoginSession>(
            LoginSession.class, builder);
    provider.setWrapWithPropertyModel(false);
    DefaultDataTable<LoginSession, String> table = new DefaultDataTable<LoginSession, String>("sessionList",
            makeColumns(), provider, 25);
    table.addBottomToolbar(new NavigationToolbar(table));
    add(table);//from   w  w  w  .  j a v a2 s  .  c o m
}

From source file:org.cast.cwm.admin.UserContentLogPage.java

License:Open Source License

public UserContentLogPage(PageParameters parameters) {
    super(parameters);

    addFilterForm();//from  www  .  jav  a  2s  .  c o  m

    AuditDataProvider<UserContent, DefaultRevisionEntity> provider = getDataProvider();

    List<IDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>> columns = makeColumns();
    // Annoying to have to make a new List here; DataTable should use <? extends IColumn>.
    ArrayList<IColumn<AuditTriple<UserContent, DefaultRevisionEntity>, String>> colList = new ArrayList<IColumn<AuditTriple<UserContent, DefaultRevisionEntity>, String>>(
            columns);
    DataTable<AuditTriple<UserContent, DefaultRevisionEntity>, String> table = new DataTable<AuditTriple<UserContent, DefaultRevisionEntity>, String>(
            "table", colList, provider, ITEMS_PER_PAGE);

    table.addTopToolbar(new HeadersToolbar<String>(table, provider));
    table.addBottomToolbar(new NavigationToolbar(table));
    table.addBottomToolbar(new NoRecordsToolbar(table, new Model<String>("No revisions found")));
    add(table);

    CSVDownload<AuditTriple<UserContent, DefaultRevisionEntity>> download = new CSVDownload<AuditTriple<UserContent, DefaultRevisionEntity>>(
            columns, provider);
    add(new ResourceLink<Object>("downloadLink", download));

    // Look for a configuration variable with site's URL, called either cwm.url or app.url.
    // If it is set, it is used to make URLs absolute in the downloaded file
    if (Application.get() instanceof CwmApplication) {
        IAppConfiguration config = CwmApplication.get().getConfiguration();
        urlPrefix = config.getString("cwm.url", config.getString("app.url", ""));
    }
}

From source file:org.cast.cwm.admin.UserListPanel.java

License:Open Source License

public UserListPanel(String id) {
    super(id);//from  w ww  .j  a va 2s.com
    ISortableDataProvider<User, String> provider = getDataProvider(getCriteriaBuilder());
    DefaultDataTable<User, String> table = new DefaultDataTable<User, String>("userList", makeColumns(),
            provider, 25);
    table.addBottomToolbar(new NavigationToolbar(table));
    add(table);
}

From source file:org.cdlflex.ui.markup.html.repeater.data.table.DefaultDataTable.java

License:Apache License

/**
 * Constructor./*from   ww  w. j  a va 2  s  .c  o m*/
 *
 * @param id component id
 * @param columns list of columns
 * @param dataProvider data provider
 * @param rowsPerPage number of rows per page
 */
public DefaultDataTable(final String id, final List<? extends IColumn<T, S>> columns,
        final ISortableDataProvider<T, S> dataProvider, final int rowsPerPage) {
    super(id, columns, dataProvider, rowsPerPage);

    addTopToolbar(new NavigationToolbar(this));
    addTopToolbar(new HeadersToolbar<>(this, dataProvider));
    addBottomToolbar(new NoRecordsToolbar(this));
}