Example usage for org.apache.wicket.markup.repeater.data DataView DataView

List of usage examples for org.apache.wicket.markup.repeater.data DataView DataView

Introduction

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

Prototype

protected DataView(String id, IDataProvider<T> dataProvider) 

Source Link

Usage

From source file:com.romeikat.datamessie.core.view.ui.panel.CrawlingsOverviewPanel.java

License:Open Source License

private void initialize() {
    setOutputMarkupId(true);/*from  ww  w .j  a v  a2 s  .  c  om*/

    // Crawlings list
    crawlingsOverviewDataProvider = new CrawlingsOverviewDataProvider(dfsModel, crawlingDao, sessionFactory);
    crawlingsOverviewList = new DataView<CrawlingOverviewDto>("crawlingsOverviewList",
            crawlingsOverviewDataProvider) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<CrawlingOverviewDto> item) {
            final IModel<CrawlingOverviewDto> crawlingModel = item.getModel();
            final CrawlingOverviewDto crawling = item.getModelObject();
            final boolean crawlingInProgress = crawling.getCompleted() == null;
            // Started
            final Label startedLabel = new Label("startedLabel",
                    new PropertyModel<LocalDateTime>(crawlingModel, "started"));
            item.add(startedLabel);
            // Duration
            final Label durationLabel = new Label("durationLabel",
                    new PropertyModel<Duration>(crawlingModel, "duration"));
            durationLabel.setVisible(!crawlingInProgress);
            item.add(durationLabel);
            // Ongoing
            final String ongoingText = "ongoing";
            final Label ongoingLabel = new Label("ongoingLabel", ongoingText);
            ongoingLabel.setVisible(crawlingInProgress);
            item.add(ongoingLabel);
        }
    };
    crawlingsOverviewList.setItemsPerPage(CRAWLINGS_PER_PAGE);
    add(crawlingsOverviewList);

    // Crawlings navigator
    crawlingsOverviewNavigator = new AjaxPagingNavigator("crawlingsOverviewNavigator", crawlingsOverviewList) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onConfigure() {
            super.onConfigure();
            final long pageCount = getPageable().getPageCount();
            setVisible(pageCount > 1);
        }
    };
    crawlingsOverviewNavigator.setOutputMarkupId(true);
    add(crawlingsOverviewNavigator);

    // Number of crawlings
    final IModel<String> numberOfCrawlingsLabelModel = new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            final long numberOfCrawlings = crawlingsOverviewDataProvider.size();
            final String suffix = numberOfCrawlings == 1 ? " crawling" : " crawlings";
            final String numberOfCrawlingsString = stringUtil.formatAsInteger(numberOfCrawlings) + suffix;
            return numberOfCrawlingsString;
        }
    };
    final Label numberOfCrawlingsLabel = new Label("numberOfCrawlingsLabel", numberOfCrawlingsLabelModel);
    add(numberOfCrawlingsLabel);
}

From source file:com.romeikat.datamessie.core.view.ui.panel.DocumentsOverviewPanel.java

License:Open Source License

private void initialize() {
    setOutputMarkupId(true);/*ww w . j  ava 2 s  .c  o m*/

    // Documents list
    documentsOverviewDataProvider = new DocumentsOverviewDataProvider(dfsModel, documentDao, sessionFactory);
    documentsOverviewList = new DataView<DocumentOverviewDto>("documentsOverviewList",
            documentsOverviewDataProvider) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<DocumentOverviewDto> item) {
            final IModel<DocumentOverviewDto> documentModel = item.getModel();
            final DocumentOverviewDto document = item.getModelObject();
            // Published
            final Label publishedLabel = new Label("publishedLabel",
                    new PropertyModel<LocalDateTime>(documentModel, "published"));
            item.add(publishedLabel);
            // Link to source
            final PageParameters sourcePageParameters = ((AbstractAuthenticatedPage) getPage())
                    .createProjectPageParameters();
            sourcePageParameters.set("id", document.getSourceId());
            final Label sourceNameLabel = new Label("sourceNameLabel",
                    new PropertyModel<String>(documentModel, "sourceName"));
            final Link<SourcePage> sourceLink = new BookmarkablePageLink<SourcePage>("sourceLink",
                    SourcePage.class, sourcePageParameters);
            sourceLink.add(sourceNameLabel);
            item.add(sourceLink);
            // Link to document
            final PageParameters pageParameters = ((AbstractAuthenticatedPage) getPage())
                    .createProjectPageParameters();
            pageParameters.set("id", document.getId());
            final Label documentTitleLabel = new Label("documentTitleLabel",
                    new PropertyModel<String>(documentModel, "title"));
            final Link<DocumentPage> documentLink = new BookmarkablePageLink<DocumentPage>("documentLink",
                    DocumentPage.class, pageParameters);
            documentLink.add(documentTitleLabel);
            item.add(documentLink);
        }
    };
    documentsOverviewList.setItemsPerPage(DOCUMENTS_PER_PAGE);
    add(documentsOverviewList);

    // Documents navigator
    documentsOverviewNavigator = new AjaxPagingNavigator("documentsOverviewNavigator", documentsOverviewList) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onConfigure() {
            super.onConfigure();
            final long pageCount = getPageable().getPageCount();
            setVisible(pageCount > 1);
        }
    };
    documentsOverviewNavigator.setOutputMarkupId(true);
    add(documentsOverviewNavigator);

    // Number of documents
    final IModel<String> numberOfDocumentsLabelModel = new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            final long numberOfDocuments = documentsOverviewDataProvider.size();
            final String suffix = numberOfDocuments == 1 ? " document" : " documents";
            final String numberOfDocumentsString = stringUtil.formatAsInteger(numberOfDocuments) + suffix;
            return numberOfDocumentsString;
        }
    };
    final Label numberOfDocumentsLabel = new Label("numberOfDocumentsLabel", numberOfDocumentsLabelModel);
    add(numberOfDocumentsLabel);
}

From source file:com.romeikat.datamessie.core.view.ui.panel.SourcesOverviewPanel.java

License:Open Source License

private void initialize() {
    setOutputMarkupId(true);//ww  w  .ja  v a2  s .c o m

    // Sources list
    sourcesOverviewDataProvider = new SourcesOverviewDataProvider(dfsModel, sourceDao, sessionFactory);
    sourcesOverviewList = new DataView<SourceOverviewDto>("sourcesOverviewList", sourcesOverviewDataProvider) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final Item<SourceOverviewDto> item) {
            final IModel<SourceOverviewDto> sourceModel = item.getModel();
            final SourceOverviewDto source = item.getModelObject();
            // Link to source
            final PageParameters sourcePageParameters = ((AbstractAuthenticatedPage) getPage())
                    .createProjectPageParameters();
            sourcePageParameters.set("id", source.getId());
            final Label nameLabel = new Label("name", new PropertyModel<String>(sourceModel, "name"));
            final Link<SourcePage> sourceLink = new BookmarkablePageLink<SourcePage>("sourceLink",
                    SourcePage.class, sourcePageParameters);
            sourceLink.add(nameLabel);
            item.add(sourceLink);
            // Language
            final Label languageLabel = new Label("language",
                    new PropertyModel<String>(sourceModel, "language"));
            item.add(languageLabel);
            // Types
            final SourceTypeChoice typesChoice = new SourceTypeChoice("types",
                    new PropertyModel<Collection<SourceTypeDto>>(sourceModel, "types")).setWidth(300);
            typesChoice.add(new ModelUpdatingBehavior() {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(final AjaxRequestTarget target) {
                    final Collection<SourceTypeDto> newSelection = typesChoice.getModelObject();
                    final HibernateSessionProvider sessionProvider = new HibernateSessionProvider(
                            sessionFactory);
                    new ExecuteWithTransaction(sessionProvider.getStatelessSession()) {
                        @Override
                        protected void execute(final StatelessSession statelessSession) {
                            sourceService.setSourceTypes(statelessSession, source.getId(), newSelection);
                        }
                    }.execute();
                    sessionProvider.closeStatelessSession();
                }
            });
            item.add(typesChoice);
            // Visibility
            final CheckBox visibleCheckBox = new CheckBox("visible",
                    new PropertyModel<Boolean>(sourceModel, "visible"));
            // Updating behavior to save visibility immediately on change
            visibleCheckBox.add(new ModelUpdatingBehavior() {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(final AjaxRequestTarget target) {
                    final Boolean newSelection = visibleCheckBox.getModelObject();
                    final HibernateSessionProvider sessionProvider = new HibernateSessionProvider(
                            sessionFactory);
                    new ExecuteWithTransaction(sessionProvider.getStatelessSession()) {
                        @Override
                        protected void execute(final StatelessSession statelessSession) {
                            sourceService.setVisible(statelessSession, source.getId(), newSelection);
                        }
                    }.execute();
                    sessionProvider.closeStatelessSession();
                }
            });
            item.add(visibleCheckBox);
            // Number of rules
            final Label numberOfRulesLabel = new Label("numberOfRules",
                    source.getNumberOfRedirectingRules() + "/" + source.getNumberOfTagSelectingRules());
            item.add(numberOfRulesLabel);
        }
    };
    sourcesOverviewList.setItemsPerPage(SOURCES_PER_PAGE);
    add(sourcesOverviewList);

    // Sources navigator
    sourcesOverviewNavigator = new AjaxPagingNavigator("sourcesOverviewNavigator", sourcesOverviewList) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onConfigure() {
            super.onConfigure();
            final long pageCount = getPageable().getPageCount();
            setVisible(pageCount > 1);
        }
    };
    sourcesOverviewNavigator.setOutputMarkupId(true);
    add(sourcesOverviewNavigator);

    // Number of sources
    final IModel<String> numberOfSourcesLabelModel = new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            final long numberOfSources = sourcesOverviewDataProvider.size();
            final String suffix = numberOfSources == 1 ? " source" : " sources";
            final String numberOfSourcesString = stringUtil.formatAsInteger(numberOfSources) + suffix;
            return numberOfSourcesString;
        }
    };
    final Label numberOfSourcesLabel = new Label("numberOfSourcesLabel", numberOfSourcesLabelModel);
    add(numberOfSourcesLabel);
}

From source file:com.socialsite.course.answer.AnswersPanel.java

License:Open Source License

public AnswersPanel(final String id, final IModel<Question> model) {
    super(id, model);
    // allow other panels to update this panel using ajax
    setOutputMarkupId(true);//from  w w  w .  ja v a2  s  .  co  m
    final Question question = model.getObject();
    add(answersContainer = new WebMarkupContainer("answerscontainer"));
    answersContainer.setOutputMarkupId(true);

    // TODO add the answers and other things
    final DataView<Answer> answerView = new DataView<Answer>("answers",
            new AnswerDataProvider(question.getId())) {

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

        @Override
        protected void populateItem(final Item<Answer> item) {
            item.add(new AnswerPanel("answer", item.getModel(), answersContainer));
        }
    };
    answersContainer.add(answerView);
}

From source file:com.socialsite.course.comment.CommentsPanel.java

License:Open Source License

public CommentsPanel(final String id, final IModel<Answer> model) {
    super(id, model);
    // allow other panels to update this panel using ajax
    setOutputMarkupId(true);//from w  w w.  ja  va  2  s . com
    final Answer answer = model.getObject();
    final DataView<Comment> commentView = new DataView<Comment>("comments",
            new CommentDataProvider(answer.getId())) {

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

        @Override
        protected void populateItem(final Item<Comment> item) {
            item.add(new CommentPanel("comment", item.getModel()));
        }
    };
    add(commentView);
}

From source file:com.socialsite.message.MessagePanel.java

License:Open Source License

/**
 * constructor/*from  w ww .  j ava 2  s.  c  o  m*/
 * 
 * @param id
 *            id
 */
public MessagePanel(final String id) {
    super(id);

    // container
    add(messageContainer = new WebMarkupContainer("container"));
    messageContainer.setOutputMarkupId(true);

    final MessageDataProvider MessageDataProvider = new MessageDataProvider(
            SocialSiteSession.get().getUserId());

    final DataView<Message> friendRequestDataView = new DataView<Message>("messagelist", MessageDataProvider) {

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

        @Override
        protected void populateItem(final Item<Message> item) {

            final Message message = item.getModelObject();
            if (message instanceof FriendRequestMsg) {
                item.add(new FriendRequestMsgPanel("message", (FriendRequestMsg) message, messageContainer));
            } else if (message instanceof InfoMsg) {
                item.add(
                        new InfoMsgPanel("message", new Model<InfoMsg>(((InfoMsg) message)), messageContainer));
            } else if (message instanceof CourseJoinedMsg) {
                item.add(new CourseJoinedMsgPanel("message",
                        new Model<CourseJoinedMsg>((CourseJoinedMsg) message), messageContainer));
            } else if (message instanceof StaffRequestMsg) {
                item.add(new StaffRequestMsgPanel("message",
                        new Model<StaffRequestMsg>((StaffRequestMsg) message), messageContainer));
            } else if (message instanceof CourseNoteMsg) {
                item.add(new CourseNoteMsgPanel("message", new Model<CourseNoteMsg>((CourseNoteMsg) message),
                        messageContainer));
            } else if (message instanceof QuestionInfoMsg) {
                item.add(new QuestionInfoMsgPanel("message",
                        new Model<QuestionInfoMsg>((QuestionInfoMsg) message), messageContainer));
            } else {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, message.getClass().getName());
            }
        }
    };

    messageContainer.add(friendRequestDataView);

}

From source file:com.tysanclan.site.projectewok.components.BugListPanel.java

License:Open Source License

public BugListPanel(String id, String title, BugFilter filter) {
    super(id);/*www  .j a  va2  s .c o  m*/

    add(new Label("title", title));

    DataView<Bug> bugView = new DataView<Bug>("bugs", FilterDataProvider.of(filter, bugDAO)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(Item<Bug> item) {
            Bug bug = item.getModelObject();

            Link<Bug> link = new Link<Bug>("link", ModelMaker.wrap(bug)) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick() {
                    BugListPanel.this.onClick(getModelObject());
                }
            };

            link.add(new Label("title", bug.getTitle()).setRenderBodyOnly(true));

            item.add(link);
            item.add(new DateLabel("lastUpdate",
                    bug.getUpdated() != null ? bug.getUpdated() : bug.getReported()));
            if (bug.getReporter() != null) {
                item.add(new MemberListItem("reportedBy", bug.getReporter()));
            } else {
                item.add(new BBCodePanel("reportedBy", "[i]Someone not logged in[/i]"));
            }
            if (bug.getAssignedTo() != null) {
                item.add(new MemberListItem("assignedTo", bug.getAssignedTo()));
            } else {
                item.add(new BBCodePanel("assignedTo", "[i]Nobody[/i]"));
            }
            item.add(new Label("status", new Model<BugStatus>(bug.getStatus())));

        }
    };
    bugView.setItemsPerPage(10);

    add(new PagingNavigator("paging", bugView));
    add(bugView);
}

From source file:com.tysanclan.site.projectewok.components.ForumOverviewPanel.java

License:Open Source License

/**
 * @param id Component ID//w w  w . ja va2 s . co m
 */
public ForumOverviewPanel(String id) {
    super(id);

    DataView<ForumCategory> cats = new DataView<ForumCategory>("categories",
            ForumDataProvider.of(forumCategoryDAO)) {
        private static final long serialVersionUID = 1L;

        @SpringBean
        private ForumDAO forumDAO;

        @Override
        protected void populateItem(Item<ForumCategory> item) {
            ForumCategory cat = item.getModelObject();
            String catName = cat.getName();

            TysanSession session = TysanSession.get();
            User user = session != null ? session.getUser() : null;

            boolean active = user == null || !user.isCollapseForums();

            if (!active) {
                for (Forum f : cat.getForums()) {
                    if (f.isInteractive()) {
                        active = true;
                        break;
                    }
                }
            }

            item.add(new WebMarkupContainer("unread").setVisible(session != null && session.getUser() != null));

            Label label = new Label("cattitle", catName);

            item.add(label);

            DataView<Forum> forums = new DataView<Forum>("forums", ForumDataProvider.of(cat, forumDAO)) {
                private static final long serialVersionUID = 1L;

                @SpringBean
                private ForumThreadDAO forumThreadDAO;

                @Override
                protected void populateItem(Item<Forum> innerItem) {
                    final Forum forum = innerItem.getModelObject();

                    innerItem.add(new AutoForumLink("forumlink", forum));
                    innerItem.add(new Label("forumdescription", new Model<String>(forum.getDescription())));
                    innerItem.add(new Label("total",
                            new Model<Long>(ForumDataProvider.of(forum, forumThreadDAO).size())));

                    TysanSession sess = TysanSession.get();
                    User u = sess != null ? sess.getUser() : null;

                    int unreadCount = u != null ? forumService.getForumUnreadCount(u, forum) : 0;

                    innerItem.add(new Label("unread", new Model<Integer>(unreadCount))
                            .setVisible(sess != null && sess.getUser() != null));

                    StringBuilder modList = new StringBuilder();
                    for (User mod : forum.getModerators()) {
                        if (modList.length() > 0) {
                            modList.append(", ");
                        }

                        modList.append(mod.getUsername());
                    }

                    if (forum.getModerators().isEmpty()) {
                        modList.append("-");
                    }

                    innerItem.add(new Label("moderators", modList.toString()));
                }

            };

            item.add(forums);

        }
    };

    add(cats);

    Link<Void> markAsReadLink = new Link<Void>("markasread") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            TysanSession session = (TysanSession) TysanSession.get();

            if (session != null && session.getUser() != null) {
                forumService.clearUnreadPosts(session.getUser());
            }

        }

    };

    markAsReadLink.add(new ContextImage("icon", "images/icons/eye.png"));

    TysanSession session = (TysanSession) TysanSession.get();
    User user = null;

    if (session != null) {
        user = session.getUser();
    }

    markAsReadLink.setVisible(user != null);

    add(markAsReadLink);
}

From source file:com.tysanclan.site.projectewok.pages.ForumThreadPage.java

License:Open Source License

protected void initComponents(ForumThread thread, final int pageId, final boolean publicView) {
    TysanSession sess = TysanSession.get();

    Forum forum = thread.getForum();//from ww  w .jav  a 2  s .  com

    if (!forumService.canView(getUser(), forum)) {
        throw new RestartResponseAtInterceptPageException(AccessDeniedPage.class);
    }

    boolean memberLoggedIn = sess != null;

    setPageTitle(thread.getTitle());
    threadModel = ModelMaker.wrap(thread);

    initJoinComponents(thread, pageId);

    Link<ForumThread> replyLink = new Link<ForumThread>("replylink") {
        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.markup.html.link.Link#onClick()
         */
        @Override
        public void onClick() {
            setResponsePage(new ReplyPage(threadModel.getObject(), pageId));

        }
    };

    WebMarkupContainer branchnote = new WebMarkupContainer("branchnote");
    if (thread.getBranchFrom() != null) {
        branchnote.add(new AutoThreadLink("source", thread.getBranchFrom()));
    } else {
        branchnote.add(new WebMarkupContainer("source"));
    }
    add(branchnote);
    branchnote.setVisible(thread.getBranchFrom() != null);

    ForumThreadModeratorPanel modPanel = new ForumThreadModeratorPanel("moderatorToolbox", thread);

    User currentUser = getUser();
    boolean moderator = forumService.isModerator(currentUser, thread.getForum());

    modPanel.setVisible(moderator);

    add(modPanel);

    add(replyLink);

    long parentPageIndex = determineParentPageIndex(thread);

    add(new AutoForumLink("returnlink", thread.getForum(), "Return to forum", parentPageIndex));
    add(new AutoForumLink("returnlink2", thread.getForum(), "Return to forum", parentPageIndex));

    Event event = eventDAO.getEventByThread(thread);
    if (event == null) {
        add(new WebMarkupContainer("event").setVisible(false));
    } else {
        add(new ForumEventPanel("event", event, getUser()));
    }

    Trial trial = trialDAO.getTrialByThread(thread);
    if (trial == null) {
        add(new WebMarkupContainer("trial").setVisible(false));
    } else {
        add(new TrialPanel("trial", trial, getUser()));
    }

    DataView<ForumPost> postView = new DataView<ForumPost>("posts",
            ForumDataProvider.of(thread, forumPostDAO)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(Item<ForumPost> item) {
            final ForumPost fp = item.getModelObject();

            item.add(new PostPanel("postpanel", fp));
        }

    };

    postView.setItemsPerPage(ForumThread.POSTS_PER_PAGE);
    postView.setCurrentPage(pageId - 1);

    add(postView);

    add(new PagingNavigator("topnavigation", postView));
    add(new PagingNavigator("bottomnavigation", postView));

    replyLink.setVisible(memberLoggedIn && !thread.isLocked()
            && forumService.canReply(getUser(), thread.getForum()) && mayReplyToTrial(trial, getUser()));

}

From source file:com.tysanclan.site.projectewok.pages.member.admin.StewardManageBugMastersPage.java

License:Open Source License

public StewardManageBugMastersPage() {
    super("Bug Managers");

    if (!getUser().equals(roleService.getSteward()))
        throw new RestartResponseAtInterceptPageException(AccessDeniedPage.class);

    add(new DataView<User>("current", FilterDataProvider.of(getFilter(true, true), userDAO)) {
        private static final long serialVersionUID = 1L;

        @Override//  ww w. j a  va2s.  c  om
        protected void populateItem(Item<User> item) {
            User user = item.getModelObject();

            item.add(new MemberListItem("user", user));
            item.add(new IconLink.Builder("images/icons/delete.png", new DeleteResponder(user))
                    .newInstance("delete"));

        }

    });

    final DropDownChoice<User> userChoice = new DropDownChoice<User>("user", ModelMaker.wrap((User) null),
            ModelMaker.wrapChoices(userDAO.findByFilter(getFilter(false, false))), new User.Renderer());

    Form<User> addMasterForm = new Form<User>("addMasterForm") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            tracker.grantBugRights(userChoice.getModelObject());

            setResponsePage(new StewardManageBugMastersPage());

        }
    };

    addMasterForm.add(userChoice);

    add(addMasterForm);

}