Search in sources :

Example 11 with DataView

use of org.apache.wicket.markup.repeater.data.DataView in project gitblit by gitblit.

the class LuceneSearchPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // default values
    ArrayList<String> repositories = new ArrayList<String>();
    String query = "";
    boolean allRepos = false;
    int page = 1;
    int pageSize = app().settings().getInteger(Keys.web.itemsPerPage, 50);
    // display user-accessible selections
    UserModel user = GitBlitWebSession.get().getUser();
    List<String> availableRepositories = new ArrayList<String>();
    for (RepositoryModel model : app().repositories().getRepositoryModels(user)) {
        if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {
            availableRepositories.add(model.name);
        }
    }
    if (params != null) {
        String repository = WicketUtils.getRepositoryName(params);
        if (!StringUtils.isEmpty(repository)) {
            repositories.add(repository);
        }
        page = WicketUtils.getPage(params);
        if (params.containsKey("repositories")) {
            String value = params.getString("repositories", "");
            List<String> list = StringUtils.getStringsFromValue(value);
            repositories.addAll(list);
        }
        allRepos = params.getAsBoolean("allrepos", false);
        if (allRepos) {
            repositories.addAll(availableRepositories);
        }
        if (params.containsKey("query")) {
            query = params.getString("query", "");
        } else {
            String value = WicketUtils.getSearchString(params);
            String type = WicketUtils.getSearchType(params);
            com.gitblit.Constants.SearchType searchType = com.gitblit.Constants.SearchType.forName(type);
            if (!StringUtils.isEmpty(value)) {
                if (searchType == SearchType.COMMIT) {
                    query = "type:" + searchType.name().toLowerCase() + " AND \"" + value + "\"";
                } else {
                    query = searchType.name().toLowerCase() + ":\"" + value + "\"";
                }
            }
        }
    }
    boolean luceneEnabled = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
    if (luceneEnabled) {
        if (availableRepositories.size() == 0) {
            info(getString("gb.noIndexedRepositoriesWarning"));
        }
    } else {
        error(getString("gb.luceneDisabled"));
    }
    // enforce user-accessible repository selections
    Set<String> uniqueRepositories = new LinkedHashSet<String>();
    for (String selectedRepository : repositories) {
        if (availableRepositories.contains(selectedRepository)) {
            uniqueRepositories.add(selectedRepository);
        }
    }
    ArrayList<String> searchRepositories = new ArrayList<String>(uniqueRepositories);
    // search form
    final Model<String> queryModel = new Model<String>(query);
    final Model<ArrayList<String>> repositoriesModel = new Model<ArrayList<String>>(searchRepositories);
    final Model<Boolean> allreposModel = new Model<Boolean>(allRepos);
    SessionlessForm<Void> form = new SessionlessForm<Void>("searchForm", getClass()) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit() {
            String q = queryModel.getObject();
            if (StringUtils.isEmpty(q)) {
                error(getString("gb.undefinedQueryWarning"));
                return;
            }
            if (repositoriesModel.getObject().size() == 0 && !allreposModel.getObject()) {
                error(getString("gb.noSelectedRepositoriesWarning"));
                return;
            }
            PageParameters params = new PageParameters();
            params.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
            params.put("query", queryModel.getObject());
            params.put("allrepos", allreposModel.getObject());
            LuceneSearchPage page = new LuceneSearchPage(params);
            setResponsePage(page);
        }
    };
    ListMultipleChoice<String> selections = new ListMultipleChoice<String>("repositories", repositoriesModel, availableRepositories, new StringChoiceRenderer());
    selections.setMaxRows(8);
    form.add(selections.setEnabled(luceneEnabled));
    form.add(new TextField<String>("query", queryModel).setEnabled(luceneEnabled));
    form.add(new CheckBox("allrepos", allreposModel));
    form.add(new ExternalLink("querySyntax", LUCENE_QUERY_SYNTAX_LINK));
    add(form.setEnabled(luceneEnabled));
    // execute search
    final List<SearchResult> results = new ArrayList<SearchResult>();
    if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
        results.addAll(app().repositories().search(query, page, pageSize, searchRepositories));
    }
    // results header
    if (results.size() == 0) {
        if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
            add(new Label("resultsHeader", query).setRenderBodyOnly(true));
            add(new Label("resultsCount", getString("gb.noHits")).setRenderBodyOnly(true));
        } else {
            add(new Label("resultsHeader").setVisible(false));
            add(new Label("resultsCount").setVisible(false));
        }
    } else {
        add(new Label("resultsHeader", query).setRenderBodyOnly(true));
        add(new Label("resultsCount", MessageFormat.format(getString("gb.queryResults"), results.get(0).hitId, results.get(results.size() - 1).hitId, results.get(0).totalHits)).setRenderBodyOnly(true));
    }
    // search results view
    ListDataProvider<SearchResult> resultsDp = new ListDataProvider<SearchResult>(results);
    final DataView<SearchResult> resultsView = new DataView<SearchResult>("searchResults", resultsDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<SearchResult> item) {
            final SearchResult sr = item.getModelObject();
            switch(sr.type) {
                case commit:
                    {
                        Label icon = WicketUtils.newIcon("type", "icon-refresh");
                        WicketUtils.setHtmlTooltip(icon, "commit");
                        item.add(icon);
                        item.add(new LinkPanel("summary", null, sr.summary, CommitPage.class, WicketUtils.newObjectParameter(sr.repository, sr.commitId)));
                        // show tags
                        Fragment fragment = new Fragment("tags", "tagsPanel", LuceneSearchPage.this);
                        List<String> tags = sr.tags;
                        if (tags == null) {
                            tags = new ArrayList<String>();
                        }
                        ListDataProvider<String> tagsDp = new ListDataProvider<String>(tags);
                        final DataView<String> tagsView = new DataView<String>("tag", tagsDp) {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void populateItem(final Item<String> item) {
                                String tag = item.getModelObject();
                                Component c = new LinkPanel("tagLink", null, tag, TagPage.class, WicketUtils.newObjectParameter(sr.repository, Constants.R_TAGS + tag));
                                WicketUtils.setCssClass(c, "tagRef");
                                item.add(c);
                            }
                        };
                        fragment.add(tagsView);
                        item.add(fragment);
                        break;
                    }
                case blob:
                    {
                        Label icon = WicketUtils.newIcon("type", "icon-file");
                        WicketUtils.setHtmlTooltip(icon, "blob");
                        item.add(icon);
                        item.add(new LinkPanel("summary", null, sr.path, BlobPage.class, WicketUtils.newPathParameter(sr.repository, sr.branch, sr.path)));
                        item.add(new Label("tags").setVisible(false));
                        break;
                    }
            }
            item.add(new Label("fragment", sr.fragment).setEscapeModelStrings(false).setVisible(!StringUtils.isEmpty(sr.fragment)));
            item.add(new LinkPanel("repository", null, sr.repository, SummaryPage.class, WicketUtils.newRepositoryParameter(sr.repository)));
            if (StringUtils.isEmpty(sr.branch)) {
                item.add(new Label("branch", "null"));
            } else {
                item.add(new LinkPanel("branch", "branch", StringUtils.getRelativePath(Constants.R_HEADS, sr.branch), LogPage.class, WicketUtils.newObjectParameter(sr.repository, sr.branch)));
            }
            item.add(new Label("author", sr.author));
            item.add(WicketUtils.createDatestampLabel("date", sr.date, getTimeZone(), getTimeUtils()));
        }
    };
    add(resultsView.setVisible(results.size() > 0));
    PageParameters pagerParams = new PageParameters();
    pagerParams.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
    pagerParams.put("query", queryModel.getObject());
    boolean showPager = false;
    int totalPages = 0;
    if (results.size() > 0) {
        totalPages = (results.get(0).totalHits / pageSize) + (results.get(0).totalHits % pageSize > 0 ? 1 : 0);
        showPager = results.get(0).totalHits > pageSize;
    }
    add(new PagerPanel("topPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
    add(new PagerPanel("bottomPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) SearchType(com.gitblit.Constants.SearchType) Fragment(org.apache.wicket.markup.html.panel.Fragment) ListMultipleChoice(org.apache.wicket.markup.html.form.ListMultipleChoice) Item(org.apache.wicket.markup.repeater.Item) SessionlessForm(com.gitblit.wicket.SessionlessForm) TextField(org.apache.wicket.markup.html.form.TextField) ArrayList(java.util.ArrayList) List(java.util.List) PageParameters(org.apache.wicket.PageParameters) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) StringChoiceRenderer(com.gitblit.wicket.StringChoiceRenderer) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) RepositoryModel(com.gitblit.models.RepositoryModel) PagerPanel(com.gitblit.wicket.panels.PagerPanel) LinkPanel(com.gitblit.wicket.panels.LinkPanel) UserModel(com.gitblit.models.UserModel) Component(org.apache.wicket.Component) Constants(org.eclipse.jgit.lib.Constants) SearchResult(com.gitblit.models.SearchResult) DataView(org.apache.wicket.markup.repeater.data.DataView) RepositoryModel(com.gitblit.models.RepositoryModel) Model(org.apache.wicket.model.Model) UserModel(com.gitblit.models.UserModel)

Example 12 with DataView

use of org.apache.wicket.markup.repeater.data.DataView in project gitblit by gitblit.

the class MyTicketsPage method buildPager.

protected void buildPager(final String query, final String milestone, final String[] states, final String assignedTo, final String sort, final boolean desc, final String repositoryId, final int page, int pageSize, int count, int total) {
    boolean showNav = total > (2 * pageSize);
    boolean allowPrev = page > 1;
    boolean allowNext = (pageSize * (page - 1) + count) < total;
    add(new BookmarkablePageLink<Void>("prevLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page - 1)).setEnabled(allowPrev).setVisible(showNav));
    add(new BookmarkablePageLink<Void>("nextLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page + 1)).setEnabled(allowNext).setVisible(showNav));
    if (total <= pageSize) {
        add(new Label("pageLink").setVisible(false));
        return;
    }
    // determine page numbers to display
    int pages = count == 0 ? 0 : ((total / pageSize) + (total % pageSize == 0 ? 0 : 1));
    // preferred number of pagelinks
    int segments = 5;
    if (pages < segments) {
        // not enough data for preferred number of page links
        segments = pages;
    }
    int minpage = Math.min(Math.max(1, page - 2), pages - (segments - 1));
    int maxpage = Math.min(pages, minpage + (segments - 1));
    List<Integer> sequence = new ArrayList<Integer>();
    for (int i = minpage; i <= maxpage; i++) {
        sequence.add(i);
    }
    ListDataProvider<Integer> pagesDp = new ListDataProvider<Integer>(sequence);
    DataView<Integer> pagesView = new DataView<Integer>("pageLink", pagesDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<Integer> item) {
            final Integer i = item.getModelObject();
            LinkPanel link = new LinkPanel("page", null, "" + i, MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, i));
            link.setRenderBodyOnly(true);
            if (i == page) {
                WicketUtils.setCssClass(item, "active");
            }
            item.add(link);
        }
    };
    add(pagesView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item)

Example 13 with DataView

use of org.apache.wicket.markup.repeater.data.DataView in project gitblit by gitblit.

the class ProjectsPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        add(new Label("projectsPanel"));
        return;
    }
    List<ProjectModel> projects = getProjects(params);
    Collections.sort(projects);
    ListDataProvider<ProjectModel> dp = new ListDataProvider<ProjectModel>(projects);
    DataView<ProjectModel> dataView = new DataView<ProjectModel>("project", dp) {

        private static final long serialVersionUID = 1L;

        int counter;

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            counter = 0;
        }

        @Override
        public void populateItem(final Item<ProjectModel> item) {
            final ProjectModel entry = item.getModelObject();
            PageParameters pp = WicketUtils.newProjectParameter(entry.name);
            item.add(new LinkPanel("projectTitle", "list", entry.getDisplayName(), ProjectPage.class, pp));
            item.add(new LinkPanel("projectDescription", "list", entry.description, ProjectPage.class, pp));
            item.add(new Label("repositoryCount", entry.repositories.size() + " " + (entry.repositories.size() == 1 ? getString("gb.repository") : getString("gb.repositories"))));
            String lastChange;
            if (entry.lastChange.getTime() == 0) {
                lastChange = "--";
            } else {
                lastChange = getTimeUtils().timeAgo(entry.lastChange);
            }
            Label lastChangeLabel = new Label("projectLastChange", lastChange);
            item.add(lastChangeLabel);
            WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
        }
    };
    add(dataView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) PageParameters(org.apache.wicket.PageParameters) LinkPanel(com.gitblit.wicket.panels.LinkPanel) DataView(org.apache.wicket.markup.repeater.data.DataView) ParameterMenuItem(com.gitblit.models.Menu.ParameterMenuItem) Item(org.apache.wicket.markup.repeater.Item) ProjectModel(com.gitblit.models.ProjectModel)

Example 14 with DataView

use of org.apache.wicket.markup.repeater.data.DataView in project gitblit by gitblit.

the class TicketPage method createPatchsetPanel.

protected Fragment createPatchsetPanel(String wicketId, RepositoryModel repository, UserModel user) {
    final Patchset currentPatchset = ticket.getCurrentPatchset();
    List<Patchset> patchsets = new ArrayList<Patchset>(ticket.getPatchsetRevisions(currentPatchset.number));
    patchsets.remove(currentPatchset);
    Collections.reverse(patchsets);
    Fragment panel = new Fragment(wicketId, "collapsiblePatchsetFragment", this);
    // patchset header
    String ps = "<b>" + currentPatchset.number + "</b>";
    if (currentPatchset.rev == 1) {
        panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetN"), ps)).setEscapeModelStrings(false));
    } else {
        String rev = "<b>" + currentPatchset.rev + "</b>";
        panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetNRevisionN"), ps, rev)).setEscapeModelStrings(false));
    }
    panel.add(new LinkPanel("patchId", null, "rev " + currentPatchset.rev, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, currentPatchset.tip), true));
    // compare menu
    panel.add(new LinkPanel("compareMergeBase", null, getString("gb.compareToMergeBase"), ComparePage.class, WicketUtils.newRangeParameter(repositoryName, currentPatchset.base, currentPatchset.tip), true));
    ListDataProvider<Patchset> compareMenuDp = new ListDataProvider<Patchset>(patchsets);
    DataView<Patchset> compareMenu = new DataView<Patchset>("comparePatch", compareMenuDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<Patchset> item) {
            Patchset patchset = item.getModelObject();
            LinkPanel link = new LinkPanel("compareLink", null, MessageFormat.format(getString("gb.compareToN"), patchset.number + "-" + patchset.rev), ComparePage.class, WicketUtils.newRangeParameter(getRepositoryModel().name, patchset.tip, currentPatchset.tip), true);
            item.add(link);
        }
    };
    panel.add(compareMenu);
    // reviews
    List<Change> reviews = ticket.getReviews(currentPatchset);
    ListDataProvider<Change> reviewsDp = new ListDataProvider<Change>(reviews);
    DataView<Change> reviewsView = new DataView<Change>("reviews", reviewsDp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<Change> item) {
            Change change = item.getModelObject();
            final String username = change.author;
            UserModel user = app().users().getUserModel(username);
            if (user == null) {
                item.add(new Label("reviewer", username));
            } else {
                item.add(new LinkPanel("reviewer", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(username)));
            }
            // indicate review score
            Review review = change.review;
            Label scoreLabel = new Label("score");
            String scoreClass = getScoreClass(review.score);
            String tooltip = getScoreDescription(review.score);
            WicketUtils.setCssClass(scoreLabel, scoreClass);
            if (!StringUtils.isEmpty(tooltip)) {
                WicketUtils.setHtmlTooltip(scoreLabel, tooltip);
            }
            item.add(scoreLabel);
        }
    };
    panel.add(reviewsView);
    if (ticket.isOpen() && user.canReviewPatchset(repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
        // can only review open tickets
        Review myReview = null;
        for (Change change : ticket.getReviews(currentPatchset)) {
            if (change.author.equals(user.username)) {
                myReview = change.review;
            }
        }
        // user can review, add review controls
        Fragment reviewControls = new Fragment("reviewControls", "reviewControlsFragment", this);
        // show "approve" button if no review OR not current score
        if (user.canApprovePatchset(repository) && (myReview == null || Score.approved != myReview.score)) {
            reviewControls.add(createReviewLink("approveLink", Score.approved));
        } else {
            reviewControls.add(new Label("approveLink").setVisible(false));
        }
        // show "looks good" button if no review OR not current score
        if (myReview == null || Score.looks_good != myReview.score) {
            reviewControls.add(createReviewLink("looksGoodLink", Score.looks_good));
        } else {
            reviewControls.add(new Label("looksGoodLink").setVisible(false));
        }
        // show "needs improvement" button if no review OR not current score
        if (myReview == null || Score.needs_improvement != myReview.score) {
            reviewControls.add(createReviewLink("needsImprovementLink", Score.needs_improvement));
        } else {
            reviewControls.add(new Label("needsImprovementLink").setVisible(false));
        }
        // show "veto" button if no review OR not current score
        if (user.canVetoPatchset(repository) && (myReview == null || Score.vetoed != myReview.score)) {
            reviewControls.add(createReviewLink("vetoLink", Score.vetoed));
        } else {
            reviewControls.add(new Label("vetoLink").setVisible(false));
        }
        panel.add(reviewControls);
    } else {
        // user can not review
        panel.add(new Label("reviewControls").setVisible(false));
    }
    String insertions = MessageFormat.format("<span style=\"color:darkGreen;font-weight:bold;\">+{0}</span>", ticket.insertions);
    String deletions = MessageFormat.format("<span style=\"color:darkRed;font-weight:bold;\">-{0}</span>", ticket.deletions);
    panel.add(new Label("patchsetStat", MessageFormat.format(StringUtils.escapeForHtml(getString("gb.diffStat"), false), insertions, deletions)).setEscapeModelStrings(false));
    // changed paths list
    List<PathChangeModel> paths = JGitUtils.getFilesInRange(getRepository(), currentPatchset.base, currentPatchset.tip);
    ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
    DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {

        private static final long serialVersionUID = 1L;

        int counter;

        @Override
        public void populateItem(final Item<PathChangeModel> item) {
            final PathChangeModel entry = item.getModelObject();
            Label changeType = new Label("changeType", "");
            WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
            setChangeTypeTooltip(changeType, entry.changeType);
            item.add(changeType);
            boolean hasSubmodule = false;
            String submodulePath = null;
            if (entry.isTree()) {
                // tree
                item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path), true));
                item.add(new Label("diffStat").setVisible(false));
            } else if (entry.isSubmodule()) {
                // submodule
                String submoduleId = entry.objectId;
                SubmoduleModel submodule = getSubmodule(entry.path);
                submodulePath = submodule.gitblitPath;
                hasSubmodule = submodule.hasSubmodule;
                item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), TreePage.class, WicketUtils.newPathParameter(submodulePath, submoduleId, ""), true).setEnabled(hasSubmodule));
                item.add(new Label("diffStat").setVisible(false));
            } else {
                // blob
                String displayPath = entry.path;
                String path = entry.path;
                if (entry.isSymlink()) {
                    RevCommit commit = JGitUtils.getCommit(getRepository(), PatchsetCommand.getTicketBranch(ticket.number));
                    path = JGitUtils.getStringContent(getRepository(), commit.getTree(), path);
                    displayPath = entry.path + " -> " + path;
                }
                if (entry.changeType.equals(ChangeType.ADD)) {
                    // add show view
                    item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
                } else if (entry.changeType.equals(ChangeType.DELETE)) {
                    // delete, show label
                    item.add(new Label("pathName", displayPath));
                } else {
                    // mod, show diff
                    item.add(new LinkPanel("pathName", "list", displayPath, BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
                }
                item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
            }
            // quick links
            if (entry.isSubmodule()) {
                // submodule
                item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD)));
                item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
            } else {
                // tree or blob
                item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newBlobDiffParameter(repositoryName, currentPatchset.base, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD) && !entry.changeType.equals(ChangeType.DELETE)));
                item.add(setNewTarget(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
            }
            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
        }
    };
    panel.add(pathsView);
    addPtCheckoutInstructions(user, repository, panel);
    addGitCheckoutInstructions(user, repository, panel);
    return panel;
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) TicketLabel(com.gitblit.tickets.TicketLabel) Patchset(com.gitblit.models.TicketModel.Patchset) Review(com.gitblit.models.TicketModel.Review) Fragment(org.apache.wicket.markup.html.panel.Fragment) LinkPanel(com.gitblit.wicket.panels.LinkPanel) UserModel(com.gitblit.models.UserModel) Item(org.apache.wicket.markup.repeater.Item) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffStatPanel(com.gitblit.wicket.panels.DiffStatPanel) PathChangeModel(com.gitblit.models.PathModel.PathChangeModel) SubmoduleModel(com.gitblit.models.SubmoduleModel) Change(com.gitblit.models.TicketModel.Change) BookmarkablePageLink(org.apache.wicket.markup.html.link.BookmarkablePageLink) DataView(org.apache.wicket.markup.repeater.data.DataView)

Example 15 with DataView

use of org.apache.wicket.markup.repeater.data.DataView in project midpoint by Evolveum.

the class CapabilityStep method initLayout.

protected void initLayout() {
    final ListDataProvider<CapabilityDto<CapabilityType>> capabilityProvider = new ListDataProvider<>(this, new PropertyModel<List<CapabilityDto<CapabilityType>>>(dtoModel, CapabilityStepDto.F_CAPABILITIES));
    WebMarkupContainer tableBody = new WebMarkupContainer(ID_CAPABILITY_TABLE);
    tableBody.setOutputMarkupId(true);
    add(tableBody);
    WebMarkupContainer configBody = new WebMarkupContainer(ID_CAPABILITY_CONFIG);
    configBody.setOutputMarkupId(true);
    add(configBody);
    DataView<CapabilityDto<CapabilityType>> capabilityDataView = new DataView<CapabilityDto<CapabilityType>>(ID_CAPABILITY_ROW, capabilityProvider) {

        @Override
        protected void populateItem(final Item<CapabilityDto<CapabilityType>> capabilityRow) {
            final CapabilityDto<CapabilityType> dto = capabilityRow.getModelObject();
            AjaxLink name = new AjaxLink(ID_CAPABILITY_LINK) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    editCapabilityPerformed(target, dto);
                }
            };
            Label label = new Label(ID_CAPABILITY_NAME, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    String rv = dto.getDisplayName();
                    if (Boolean.FALSE.equals(dto.getCapability().isEnabled())) {
                        rv += " " + getString("CapabilityStep.disabled");
                    }
                    return rv;
                }
            });
            name.add(label);
            capabilityRow.add(name);
            Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
            if (dto.getTooltipKey() != null) {
                tooltipLabel.add(new AttributeAppender("data-original-title", getString(dto.getTooltipKey())));
                tooltipLabel.add(new InfoTooltipBehavior());
            } else {
                tooltipLabel.setVisible(false);
            }
            tooltipLabel.setOutputMarkupId(true);
            tooltipLabel.setOutputMarkupPlaceholderTag(true);
            name.add(tooltipLabel);
            AjaxLink deleteLink = new AjaxLink(ID_CAPABILITY_DELETE) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteCapabilityPerformed(target, dto);
                }
            };
            deleteLink.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    return !dto.isAmongNativeCapabilities() && !parentPage.isReadOnly();
                }
            });
            name.add(deleteLink);
            capabilityRow.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return isSelected(capabilityRow.getModelObject()) ? "success" : null;
                }
            }));
        }
    };
    tableBody.add(capabilityDataView);
    AjaxLink addLink = new AjaxLink(ID_CAPABILITY_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addCapabilityPerformed(target);
        }
    };
    parentPage.addEditingVisibleBehavior(addLink);
    add(addLink);
    ModalWindow dialog = new AddCapabilityDialog(DIALOG_SELECT_CAPABILITY, dtoModel) {

        @Override
        protected void addPerformed(AjaxRequestTarget target) {
            addCapabilitiesPerformed(target, getSelectedData());
        }
    };
    add(dialog);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Aggregations

Label (org.apache.wicket.markup.html.basic.Label)15 Item (org.apache.wicket.markup.repeater.Item)15 DataView (org.apache.wicket.markup.repeater.data.DataView)15 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)11 ArrayList (java.util.ArrayList)7 LinkPanel (com.gitblit.wicket.panels.LinkPanel)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)5 Fragment (org.apache.wicket.markup.html.panel.Fragment)5 ListDataProvider (com.evolveum.midpoint.web.component.util.ListDataProvider)4 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)4 UserModel (com.gitblit.models.UserModel)4 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)4 NavigatorPanel (com.evolveum.midpoint.web.component.data.paging.NavigatorPanel)3 TicketLabel (com.gitblit.tickets.TicketLabel)3 Component (org.apache.wicket.Component)3 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)3 ParameterMenuItem (com.gitblit.models.Menu.ParameterMenuItem)2 RepositoryModel (com.gitblit.models.RepositoryModel)2 RepositoryUrl (com.gitblit.models.RepositoryUrl)2