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

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

Introduction

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

Prototype

public DataTable(final String id, final List<? extends IColumn<T, S>> columns,
        final IDataProvider<T> dataProvider, final long rowsPerPage) 

Source Link

Document

Constructor

Usage

From source file:org.projectforge.web.wicket.AbstractEditPage.java

License:Open Source License

@SuppressWarnings({ "serial", "unchecked" })
protected void init(O data) {
    final StringBuffer buf = new StringBuffer();
    buf.append("function showDeleteQuestionDialog() {\n").append("  return window.confirm('");
    if (getBaseDao().isHistorizable() == true) {
        buf.append(getString("question.markAsDeletedQuestion"));
    } else {/*  w w  w  . j a  v  a2 s .  c  o  m*/
        buf.append(getString("question.deleteQuestion"));
    }
    buf.append("');\n}\n");
    body.add(new Label("showDeleteQuestionDialog", buf.toString()).setEscapeModelStrings(false));
    final Integer id = WicketUtils.getAsInteger(getPageParameters(), PARAMETER_KEY_ID);
    if (data == null) {
        if (id != null) {
            data = getBaseDao().getById(id);
        }
        if (data == null) {
            data = (O) WicketUtils.getAsObject(getPageParameters(), PARAMETER_KEY_DATA_PRESET,
                    getBaseDao().newInstance().getClass());
            if (data == null) {
                data = getBaseDao().newInstance();
            }
        }
    }
    form = newEditForm(this, data);

    body.add(form);
    form.init();
    if (form.isNew() == true) {
        showHistory = false;
        showModificationTimes = false;
    }
    body.add(new Label("tabTitle", getTitle()).setRenderBodyOnly(true));
    final List<IColumn<DisplayHistoryEntry, String>> columns = new ArrayList<IColumn<DisplayHistoryEntry, String>>();
    final CellItemListener<DisplayHistoryEntry> cellItemListener = new CellItemListener<DisplayHistoryEntry>() {
        public void populateItem(final Item<ICellPopulator<DisplayHistoryEntry>> item, final String componentId,
                final IModel<DisplayHistoryEntry> rowModel) {
            // Later a link should show the history entry as popup.
            item.add(AttributeModifier.append("class", new Model<String>("notrlink")));
        }
    };
    final DatePropertyColumn<DisplayHistoryEntry> timestampColumn = new DatePropertyColumn<DisplayHistoryEntry>(
            dateTimeFormatter, getString("timestamp"), null, "timestamp", cellItemListener);
    timestampColumn.setDatePattern(DateFormats.getFormatString(DateFormatType.TIMESTAMP_SHORT_MINUTES));
    columns.add(timestampColumn);
    columns.add(new UserPropertyColumn<DisplayHistoryEntry>(getString("user"), null, "user", cellItemListener)
            .withUserFormatter(userFormatter));
    columns.add(new CellItemListenerPropertyColumn<DisplayHistoryEntry>(getString("history.entryType"), null,
            "entryType", cellItemListener));
    columns.add(new CellItemListenerPropertyColumn<DisplayHistoryEntry>(getString("history.propertyName"), null,
            "propertyName", cellItemListener));
    columns.add(new CellItemListenerPropertyColumn<DisplayHistoryEntry>(getString("history.newValue"), null,
            "newValue", cellItemListener) {
        @Override
        public void populateItem(final Item<ICellPopulator<DisplayHistoryEntry>> item, final String componentId,
                final IModel<DisplayHistoryEntry> rowModel) {
            final DisplayHistoryEntry historyEntry = rowModel.getObject();
            item.add(new DiffTextPanel(componentId, Model.of(historyEntry.getNewValue()),
                    Model.of(historyEntry.getOldValue())));
            cellItemListener.populateItem(item, componentId, rowModel);
        }
    });
    final IDataProvider<DisplayHistoryEntry> dataProvider = new ListDataProvider<DisplayHistoryEntry>(
            getHistory());
    final DataTable<DisplayHistoryEntry, String> dataTable = new DataTable<DisplayHistoryEntry, String>(
            "historyTable", columns, dataProvider, 100) {
        @Override
        protected Item<DisplayHistoryEntry> newRowItem(final String id, final int index,
                final IModel<DisplayHistoryEntry> model) {
            return new OddEvenItem<DisplayHistoryEntry>(id, index, model);
        }

        @Override
        public boolean isVisible() {
            return showHistory;
        }
    };
    final HeadersToolbar<String> headersToolbar = new HeadersToolbar<String>(dataTable, null);
    dataTable.addTopToolbar(headersToolbar);
    body.add(dataTable);
    final Label timeOfCreationLabel = new Label("timeOfCreation",
            dateTimeFormatter.getFormattedDateTime(data.getCreated()));
    timeOfCreationLabel.setRenderBodyOnly(true);
    body.add(timeOfCreationLabel);
    final Label timeOfLastUpdateLabel = new Label("timeOfLastUpdate",
            dateTimeFormatter.getFormattedDateTime(data.getLastUpdate()));
    timeOfLastUpdateLabel.setRenderBodyOnly(true);
    body.add(timeOfLastUpdateLabel);
    onPreEdit();
    evaluateInitialPageParameters(getPageParameters());
    this.editPageSupport = new EditPageSupport<O, D>(this, getBaseDao());
}

From source file:org.ujorm.wicket.component.grid.UjoDataProvider.java

License:Apache License

/** Create AJAX-based DataTable */
public <S> DataTable<T, S> createDataTable(final String id, final int rowsPerPage) {
    final DataTable<T, S> result = new DataTable<T, S>(id, (List) columns, this, rowsPerPage) {
        @Override/*w  w w  .j a  v a 2  s  . co m*/
        protected Item<T> newRowItem(final String id, final int index, final IModel<T> model) {
            return new OddEvenItem<T>(id, index, model);
        }
    };

    result.addTopToolbar(new AjaxNavigationToolbar(result));
    result.addTopToolbar(new HeadersToolbar(result, this));
    result.addBottomToolbar(new NoRecordsToolbar(result));
    result.setOutputMarkupId(true);
    return result;
}

From source file:org.wicketstuff.console.templates.ScriptTemplateSelectionTablePanel.java

License:Apache License

private void init(final IDataProvider<ScriptTemplate> dataProvider, final int rowsPerPage) {
    table = new DataTable<ScriptTemplate, Void>("table", createColumns(), dataProvider, rowsPerPage);
    add(table);//from   w  w w.j a  v a  2  s.co  m
}

From source file:org.wintersleep.usermgmt.wicket.UserListPage.java

License:Apache License

public UserListPage() {
    super();//from  www  . j a  va  2s .co m

    List<IColumn<User, String>> columns = new ArrayList<>();
    columns.add(new FilteredAbstractColumn<User, String>(new Model<>("Actions")) {

        public void populateItem(Item<ICellPopulator<User>> cellItem, String componentId,
                final IModel<User> model) {
            cellItem.add(new ActionsPanel(componentId,
                    new PageSourceLink<>("showLink", UserEditPage.class, model), new IPageLink() {
                        public Page getPage() {
                            return new UserEditPage(UserListPage.this,
                                    (HibernateObjectModel<Long, User>) model);
                        }

                        public Class<UserEditPage> getPageIdentity() {
                            return UserEditPage.class;
                        }
                    }, new IPageLink() {
                        public Page getPage() {
                            User user = model.getObject();
                            return new DeletePage<>(UserListPage.this, model, "User: " + user.getFullName());
                        }

                        public Class<DeletePage> getPageIdentity() {
                            return DeletePage.class;
                        }
                    }));
        }

        public Component getFilter(String componentId, FilterForm<?> form) {
            return new GoAndClearAndNewFilter(componentId, form) {
                public Page createNewPage() {
                    return new UserEditPage(UserListPage.this,
                            new HibernateObjectModel<Long, User>(new User(WicketHibernateUtil.EMPTY_STRING)));
                }
            };
        }
    });
    columns.add(new TextFilteredPropertyColumn<User, User, String>(new Model<>("Login"), "login", "login"));
    columns.add(
            new TextFilteredPropertyColumn<User, User, String>(new Model<>("Name"), "fullName", "fullName"));
    /*
        // custom column to enable countries be be in the list and labeled correctly
        new MyChoiceFilteredPropertyColumn(new Model("Birth country"), "country.name", "country.name", "country", "name", countries),
        new MyChoiceFilteredPropertyColumn(new Model("Birth city"), "birthCity.name", "birthCity.name", "birthCity", "name", cities),
        new PropertyColumn(new Model("Final game"), "finalGame", "finalGame")
    */

    UserFilter filter = new UserFilter();
    final FilterForm<UserFilterState> filterForm = new FilterForm<>("form", filter);
    CriteriaSorter sorter = new CriteriaSorter();
    HibernateProvider<Long, User> provider = new HibernateProvider<>(User.class, filter, sorter);
    DataTable<User, String> table = new DataTable<User, String>("table", columns, provider, 25) {
        protected Item<User> newRowItem(String id, int index, IModel<User> model) {
            return new OddEvenItem<>(id, index, model);
        }
    };
    table.addTopToolbar(new NavigationToolbar(table));
    table.addTopToolbar(new HeadersToolbar<>(table, sorter));
    table.addTopToolbar(new FilterToolbar(table, filterForm, filter));

    add(filterForm.add(table));
}

From source file:org.wintersleep.usermgmt.wicket.UserProfileListPage.java

License:Apache License

public UserProfileListPage() {
    super();/*from   w w  w.j  a v a2 s.c o m*/

    UserProfileFilter filter = new UserProfileFilter();
    final FilterForm<UserProfileFilterState> form = new FilterForm<>("form", filter);

    List<IColumn<UserProfile, String>> columns = new ArrayList<>();
    columns.add(new FilteredAbstractColumn<UserProfile, String>(new Model<>("Actions")) {

        public void populateItem(Item<ICellPopulator<UserProfile>> cellItem, String componentId,
                final IModel<UserProfile> model) {
            cellItem.add(new ActionsPanel(componentId,
                    new PageSourceLink<>("showLink", UserProfileEditPage.class, model), new IPageLink() {
                        public Page getPage() {
                            return new UserProfileEditPage(UserProfileListPage.this, model);
                        }

                        public Class<UserProfileEditPage> getPageIdentity() {
                            return UserProfileEditPage.class;
                        }
                    }, new IPageLink() {
                        public Page getPage() {
                            UserProfile userProfile = model.getObject();
                            return new DeletePage<>(UserProfileListPage.this, model,
                                    "User Profile: " + userProfile.getName());
                        }

                        public Class<DeletePage> getPageIdentity() {
                            return DeletePage.class;
                        }
                    }));
        }

        public Component getFilter(String componentId, FilterForm form) {
            return new GoAndClearAndNewFilter(componentId, form) {
                public Page createNewPage() {
                    return new UserProfileEditPage(UserProfileListPage.this,
                            new HibernateObjectModel<Long, UserProfile>(
                                    new UserProfile(WicketHibernateUtil.EMPTY_STRING)));
                }
            };
        }
    });
    columns.add(new TextFilteredPropertyColumn<UserProfile, UserProfile, String>(new Model<>("Name"), "name",
            "name"));
    //new MyChoiceFilteredPropertyColumn(new Model("Role"), "role.name", "role.name", "role", "name", roles),
    /*
    new MyChoiceFilteredPropertyColumn(new Model("Birth city"), "birthCity.name", "birthCity.name", "birthCity", "name", cities),
    new PropertyColumn(new Model("Final game"), "finalGame", "finalGame")
    */
    CriteriaSorter sorter = new CriteriaSorter();
    HibernateProvider<Long, UserProfile> provider = new HibernateProvider<>(UserProfile.class, filter, sorter);
    DataTable<UserProfile, String> table = new DataTable<UserProfile, String>("table", columns, provider, 25) {
        protected Item<UserProfile> newRowItem(String id, int index, IModel<UserProfile> model) {
            return new OddEvenItem<>(id, index, model);
        }
    };
    table.addTopToolbar(new NavigationToolbar(table));
    table.addTopToolbar(new HeadersToolbar<>(table, sorter));
    table.addTopToolbar(new FilterToolbar(table, form, filter));
    add(form.add(table));
}

From source file:sk.lazyman.gizmo.component.data.TablePanel.java

License:Apache License

private void initLayout(List<IColumn<T, String>> columns, ISortableDataProvider provider, int rowsPerPage) {
    DataTable<T, String> table = new DataTable<>(ID_TABLE, columns, provider, rowsPerPage);

    table.setOutputMarkupId(true);/*w w  w. ja v a2s. c o  m*/

    TableHeadersToolbar headers = new TableHeadersToolbar(table, provider);
    headers.setOutputMarkupId(true);
    table.addTopToolbar(headers);

    CountToolbar count = new CountToolbar(table);
    addVisibleBehaviour(count, showCount);
    table.addBottomToolbar(count);

    add(table);

    NavigatorPanel nb2 = new NavigatorPanel(ID_PAGING, table, true);
    addVisibleBehaviour(nb2, showPaging);
    add(nb2);

    setItemsPerPage(rowsPerPage);
}