private DataView<LdapUser> newGroupMembersListView(LdapGroup group) { List<LdapUser> users; try { users = group.getMembers(); } catch (NamingException e) { logger.warn(e.getMessage(), e); users = new ArrayList<>(0); } DataView<LdapUser> members = new DataView<LdapUser>("membersList", new LdapGroupUsersProvider(users)) { @Override protected void populateItem(Item<LdapUser> item) { LdapUser user = item.getModelObject(); WebMarkupContainer container = new WebMarkupContainer("member"); ExternalLink mail = new ExternalLink( "mail", Model.of("mailto:" + user.getMail()), new PropertyModel(user, "mail")); Label userName = new Label("username", new PropertyModel(user, "userName")); final String fullName = user.getFullName(); Label fullNameLabel = new Label("fullname", Model.of(fullName)); fullNameLabel.setVisible(fullName != null); container.add(mail); container.add(userName); container.add(fullNameLabel); item.add(container); } }; members.setOutputMarkupId(true); return members; }
public void testLoad() { tester.assertRenderedPage(WorkspacePage.class); tester.assertNoErrorMessage(); DataView dv = (DataView) tester.getComponentFromLastRenderedPage("table:listContainer:items"); assertEquals(dv.size(), getCatalog().getWorkspaces().size()); WorkspaceInfo ws = (WorkspaceInfo) dv.getDataProvider().iterator(0, 1).next(); assertEquals("cdf", ws.getName()); }
/** * Sets the table into pageable/non pageable mode. The default is pageable, in non pageable mode * both pagers will be hidden and the number of items per page is set to the DataView default * (Integer.MAX_VALUE) * * @param pageable */ public void setPageable(boolean pageable) { if (!pageable) { navigatorTop.setVisible(false); navigatorBottom.setVisible(false); dataView.setItemsPerPage(Integer.MAX_VALUE); selection = new boolean[getDataProvider().getItems().size()]; } else { navigatorTop.setVisible(true); navigatorBottom.setVisible(true); dataView.setItemsPerPage(DEFAULT_ITEMS_PER_PAGE); selection = new boolean[DEFAULT_ITEMS_PER_PAGE]; } }
@SuppressWarnings("unchecked") public SessionBrowserPage(PageParameters pageParameters) { add(new Label("title", getTitle())); IDataProvider provider = new AbstractListDataProvider<Session>() { public IModel<Session> model(Session o) { return new CompoundPropertyModel<Session>(new LoadableSession(o)); } @Override public List<Session> load() { return _sessionManager.getSessions(); } }; DataView dataView = new DataView("sessions", provider) { @Override protected void populateItem(final Item item) { Session session = (Session) item.getModelObject(); item.add(new AorLink("aorLink", session.getProfile().getUri())); item.add(new Label("barred", String.valueOf(session.getProfile().isBarred()))); item.add(new Label("sessionCase")); item.add(new Label("currentIfc")); item.add( new AttributeModifier( "class", true, new AbstractReadOnlyModel<String>() { @Override public String getObject() { return (item.getIndex() % 2 == 1) ? "even" : "odd"; } })); } }; dataView.setItemsPerPage(getItemByPage()); add(dataView); }
/** * Parses the keywords and sets them into the data provider, forces update of the components that * need to as a result of the different filtering */ private void updateFilter(AjaxRequestTarget target, String flatKeywords) { if ("".equals(flatKeywords)) { dataProvider.setKeywords(null); filter.setModelObject(""); dataView.setCurrentPage(0); } else { String[] keywords = flatKeywords.split("\\s+"); dataProvider.setKeywords(keywords); dataView.setCurrentPage(0); } pagerDelegate.updateMatched(); navigatorTop.updateMatched(); navigatorBottom.updateMatched(); setSelection(false); target.addComponent(listContainer); target.addComponent(navigatorTop); target.addComponent(navigatorBottom); }
/** * Method createShareDataView that shown a list of shared {@link Album}s. * * @return DataView<{@link Album}> the data view with the list of {@link Album}. */ private DataView<Album> createShareDataView() { List<Album> list = albumService.getAlbumsSharedWith(((MySession) Session.get()).getuId(), user.getEmail()); DataView<Album> dataView = new DataView<Album>("pageable", new ListDataProvider<Album>(list)) { public void populateItem(final Item<Album> item) { final Album album = item.getModelObject(); PageParameters pars = new PageParameters(); pars.add("user", user.getEmail()); pars.add("album", album.getName()); BookmarkablePageLink<Void> bp = new BookmarkablePageLink<Void>("link", SharedFiles.class, pars); bp.add(new Label("name", album.getName())); item.add(bp); } }; dataView.setItemsPerPage(ITEMS_PER_PAGE); return dataView; }
/** Selects a single item by object. */ public void selectObject(T object) { int i = 0; for (Iterator it = dataView.iterator(); it.hasNext(); ) { Item item = (Item) it.next(); if (object.equals(item.getModelObject())) { selection[i] = true; return; } i++; } }
/** * Returns the items that have been selected by the user * * @return */ public List<T> getSelection() { List<T> result = new ArrayList<T>(); int i = 0; for (Iterator it = dataView.iterator(); it.hasNext(); ) { Item item = (Item) it.next(); if (selection[i]) { result.add((T) item.getModelObject()); } i++; } return result; }
/** * Method createDataView. * * @return DataView<String> */ private DataView<String> createDataView() { final HashSet<String> set = new HashSet<String>(); final List<ShareInformationAlbums> list = new ArrayList<ShareInformationAlbums>( shareInformationService.getUserShares(((MySession) Session.get()).getuId())); for (ShareInformationAlbums aList : list) { set.add(aList.getAlbum().getUser().getEmail()); } final List<String> list1 = new ArrayList<String>(set); DataView<String> dataView = new DataView<String>("pageable", new ListDataProvider<String>(list1)) { public void populateItem(final Item<String> item) { final String email = item.getModelObject(); PageParameters pars = new PageParameters(); pars.add("user", email); BookmarkablePageLink<Void> bp = new BookmarkablePageLink<Void>("albums", SharedAlbums.class, pars); bp.add(new Label("email", email)); item.add(bp); } }; dataView.setItemsPerPage(ITEMS_PER_PAGE); return dataView; }
@Test public void testBasicTable() throws Exception { tester.startPage( new FormTestPage( new ComponentBuilder() { public Component buildComponent(String id) { return new IntegerTable(id, false); } })); tester.assertComponent("form:panel", IntegerTable.class); // check the contents are as expected String firstLabelPath = "form:panel:listContainer:items:1:itemProperties:0:component"; tester.assertComponent(firstLabelPath, Label.class); assertEquals( new Integer(0), tester.getComponentFromLastRenderedPage(firstLabelPath).getDefaultModelObject()); // check we actually rendered 10 rows DataView dv = (DataView) tester.getComponentFromLastRenderedPage("form:panel:listContainer:items"); assertEquals(10, dv.size()); }
@Override protected WebMarkupContainer initialiseSearchResults() { searchResultsPanel = new SearchResultListPanel( "searchResults", arkContextMarkup, containerForm, arkCrudContainerVO); searchResultsPanel.setOutputMarkupId(true); affectionProvider = new ArkDataProvider<AffectionVO, IArkDiseaseService>(iArkDiseaseService) { private static final long serialVersionUID = 1L; public int size() { int count = service.getAffectionCount(containerForm.getModelObject()); return count; } public Iterator<? extends AffectionVO> iterator(int first, int count) { List<AffectionVO> affectionVOs = service.searchPageableAffections(containerForm.getModelObject(), first, count); return affectionVOs.iterator(); } }; affectionProvider.setModel(this.cpModel); dataView = searchResultsPanel.buildDataView(affectionProvider); dataView.setItemsPerPage(iArkCommonService.getRowsPerPage()); AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", dataView) { private static final long serialVersionUID = 1L; @Override protected void onAjaxEvent(AjaxRequestTarget target) { target.add(searchResultsPanel); } }; resultsWmc.add(pageNavigator); resultsWmc.add(dataView); searchResultsPanel.add(resultsWmc); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultsPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
private void initCustomFieldDataListPanel() { cfdProvider.setCriteriaModel( new PropertyModel<CustomFieldDisplay>(cpModel, "customFieldGroup")); List<CustomField> selectedList = iPhenotypicService.getCustomFieldsLinkedToCustomFieldGroup( getModelObject().getCustomFieldGroup()); Boolean disableEditButton = false; if (getModelObject().getCustomFieldGroup().getPublished()) { for (CustomField customField : selectedList) { if (customField.getCustomFieldHasData()) { disableEditButton = true; break; } } } CustomFieldDisplayListPanel cfdListPanel = new CustomFieldDisplayListPanel( "cfdListPanel", feedBackPanel, arkCrudContainerVO, disableEditButton); cfdListPanel.setOutputMarkupId(true); cfdListPanel.initialisePanel(); dataView = cfdListPanel.buildDataView(cfdProvider); dataView.setItemsPerPage(iArkCommonService.getRowsPerPage()); AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("cfDisplayNavigator", dataView) { private static final long serialVersionUID = 1L; @Override protected void onAjaxEvent(AjaxRequestTarget target) { target.add(arkCrudContainerVO.getWmcForCustomFieldDisplayListPanel()); } }; cfdListPanel.addOrReplace(pageNavigator); cfdListPanel.addOrReplace(dataView); arkCrudContainerVO.getWmcForCustomFieldDisplayListPanel().addOrReplace(cfdListPanel); }
public CommitDiffPage(PageParameters params) { super(params); Repository r = getRepository(); final RevCommit commit = getCommit(); final List<String> parents = new ArrayList<String>(); if (commit.getParentCount() > 0) { for (RevCommit parent : commit.getParents()) { parents.add(parent.name()); } } // commit page links if (parents.size() == 0) { add(new Label("parentLink", getString("gb.none"))); } else { add( new LinkPanel( "parentLink", null, parents.get(0).substring(0, 8), CommitDiffPage.class, newCommitParameter(parents.get(0)))); } add( new BookmarkablePageLink<Void>( "patchLink", PatchPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); add( new BookmarkablePageLink<Void>( "commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId))); add(new CommitHeaderPanel("commitHeader", repositoryName, commit)); final List<String> imageExtensions = app().settings().getStrings(Keys.web.imageExtensions); final ImageDiffHandler handler = new ImageDiffHandler( this, repositoryName, parents.isEmpty() ? null : parents.get(0), commit.getName(), imageExtensions); final DiffOutput diff = DiffUtils.getCommitDiff(r, commit, DiffOutputType.HTML, handler); if (handler.getImgDiffCount() > 0) { addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs } // add commit diffstat int insertions = 0; int deletions = 0; for (PathChangeModel pcm : diff.stat.paths) { insertions += pcm.insertions; deletions += pcm.deletions; } add(new DiffStatPanel("diffStat", insertions, deletions)); addFullText("fullMessage", commit.getFullMessage()); // git notes List<GitNote> notes = JGitUtils.getNotesOnCommit(r, commit); ListDataProvider<GitNote> notesDp = new ListDataProvider<GitNote>(notes); DataView<GitNote> notesView = new DataView<GitNote>("notes", notesDp) { private static final long serialVersionUID = 1L; @Override public void populateItem(final Item<GitNote> item) { GitNote entry = item.getModelObject(); item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef))); item.add( createPersonPanel( "authorName", entry.notesRef.getAuthorIdent(), Constants.SearchType.AUTHOR)); item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent())); item.add( WicketUtils.createTimestampLabel( "authorDate", entry.notesRef.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils())); item.add( new Label( "noteContent", bugtraqProcessor() .processPlainCommitMessage( getRepository(), repositoryName, entry.content)) .setEscapeModelStrings(false)); } }; add(notesView.setVisible(notes.size() > 0)); // changed paths list add(new CommitLegendPanel("commitLegend", diff.stat.paths)); ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(diff.stat.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); item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true)); boolean hasSubmodule = false; String submodulePath = null; if (entry.isTree()) { // tree item.add( new LinkPanel( "pathName", null, entry.path, TreePage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))); } else if (entry.isSubmodule()) { // submodule String submoduleId = entry.objectId; SubmoduleModel submodule = getSubmodule(entry.path); submodulePath = submodule.gitblitPath; hasSubmodule = submodule.hasSubmodule; // add relative link item.add( new LinkPanel( "pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#n" + entry.objectId)); } else { // add relative link item.add(new LinkPanel("pathName", "list", entry.path, "#n" + entry.objectId)); } // quick links if (entry.isSubmodule()) { item.add(new ExternalLink("raw", "").setEnabled(false)); // submodule item.add(new ExternalLink("patch", "").setEnabled(false)); item.add( new BookmarkablePageLink<Void>( "view", CommitPage.class, WicketUtils.newObjectParameter(submodulePath, entry.objectId)) .setEnabled(hasSubmodule)); item.add(new ExternalLink("blame", "").setEnabled(false)); item.add( new BookmarkablePageLink<Void>( "history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)) .setEnabled(!entry.changeType.equals(ChangeType.ADD))); } else { // tree or blob item.add( new BookmarkablePageLink<Void>( "patch", PatchPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)) .setEnabled( !entry.changeType.equals(ChangeType.ADD) && !entry.changeType.equals(ChangeType.DELETE))); item.add( new BookmarkablePageLink<Void>( "view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)) .setEnabled(!entry.changeType.equals(ChangeType.DELETE))); String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, entry.commitId, entry.path); item.add( new ExternalLink("raw", rawUrl) .setEnabled(!entry.changeType.equals(ChangeType.DELETE))); item.add( new BookmarkablePageLink<Void>( "blame", BlamePage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)) .setEnabled( !entry.changeType.equals(ChangeType.ADD) && !entry.changeType.equals(ChangeType.DELETE))); item.add( new BookmarkablePageLink<Void>( "history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)) .setEnabled(!entry.changeType.equals(ChangeType.ADD))); } WicketUtils.setAlternatingBackground(item, counter); counter++; } }; add(pathsView); add(new Label("diffText", diff.content).setEscapeModelStrings(false)); }
@Override protected void onInitialize(EmptyPlugin plugin, AbstractPluginBean pluginBean) { PageParameters params = getPageRequestParameters(); if (params.isEmpty()) { setVisible(false); setResponsePage(ClassifiersPage.class); return; } final String classifierType = params.get(ClassifiersPanel.PARAM_CLASSIFIER_TYPE).toString(); String parentClassifierItem = null; if (params.get(ClassifierConstants.PARENT_ITEM) != null) { parentClassifierItem = params.get(ClassifierConstants.PARENT_ITEM).toString(); } // Add data container final DecoratedPagingNavigatorContainer<ClassifierItem> dataContainer = new DecoratedPagingNavigatorContainer<ClassifierItem>( "container", getCurrentRedirectLink()); add(dataContainer); // Add data view final DataView<ClassifierItem> classifierDataView = new DataView<ClassifierItem>( "item-list", new ClassifierDataProvider(classifierType, parentClassifierItem)) { private static final long serialVersionUID = 1L; @Override protected void populateItem(Item<ClassifierItem> item) { ClassifierItem classifierItem = item.getModelObject(); // Add link PageParameters pageParameters = new PageParameters(); pageParameters.set(ClassifiersPanel.PARAM_CLASSIFIER_TYPE, classifierType); pageParameters.add(ClassifierConstants.PARENT_ITEM, classifierItem.getCode()); BookmarkablePageLink<Void> link = new BookmarkablePageLink<Void>( "link-item", ClassifiersItemPage.class, pageParameters); item.add(link); link.add(new Label("code", new Model<String>(classifierItem.getCode()))); // Add name item.add(new Label("name", new Model<String>(classifierItem.getName()))); } }; dataContainer.addAbstractPageableView(classifierDataView); dataContainer.setVisible(true); classifierDataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); // Create modal window to create new classifier final ModalWindow addNewClassifierModalWindow = new CustomModalWindow("modal-new-item", "title") { private static final long serialVersionUID = 1L; @Override protected void addComponentsToRefresh(java.util.List<Component> components) { components.add(dataContainer); }; }; addNewClassifierModalWindow.setContent( new NewClassifierItemPanel<ClassifierItem, Classifier>( addNewClassifierModalWindow, params)); add(addNewClassifierModalWindow); // add create new classifier link add( new AjaxLink<Void>("link-add-new-item") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { addNewClassifierModalWindow.show(target); } }); }
private void createExchangeRateDataView( final WebMarkupContainer updateExchangerateContainer, final WebMarkupContainer addExchangerateContainer) { dataProvider = new ExchangeRateDataProvider(WICKET_ID_fromCurrency, this); exchangeRateList = new ArrayList<ExchangeRate>(); final DataView<ExchangeRate> dataView = new DataView<ExchangeRate>(WICKET_ID_pageable, dataProvider) { @Override protected void onBeforeRender() { try { dataProvider.loadExchangeRates(forceReload); forceReload = false; refreshTotalItemCount(); // reset rowIndex rowIndex = 1; } catch (DataProviderLoadException dple) { LOG.error("# An error occurred while loading exchange rates", dple); error(getLocalizer().getString("exchangerate.load.error", this)); } if (dataProvider.size() > 0) { setVisible(true); } else { setVisible(false); } refreshTotalItemCount(); super.onBeforeRender(); } private void refreshTotalItemCount() { totalItemString = Integer.toString(dataProvider.size()); int total = getItemCount(); if (total > 0) { startIndex = getCurrentPage() * getItemsPerPage() + 1; endIndex = startIndex + getItemsPerPage() - 1; if (endIndex > total) endIndex = total; } else { startIndex = 0; endIndex = 0; } } @Override protected void populateItem(final Item<ExchangeRate> item) { final ExchangeRate entry = item.getModelObject(); exchangeRateList.add(entry); item.add(new Label(WICKET_ID_fromCurrency, entry.getFromCurrency())); item.add(new Label(WICKET_ID_toCurrency, entry.getToCurrency())); item.add(new Label(WICKET_ID_ratio, entry.getFromAmount() + ":" + entry.getToAmount())); NumberFormat format = NumberFormat.getInstance(getMobiliserWebSession().getLocale()); item.add(new Label(WICKET_ID_rate, format.format(entry.getRate()))); Link<ExchangeRate> editLink = new Link<ExchangeRate>(WICKET_ID_editAction, item.getModel()) { @Override public void onClick() { ExchangeRate entry = (ExchangeRate) getModelObject(); setExchangeRate(entry); setStrToAmount(String.valueOf(entry.getToAmount())); setStrFromAmount(String.valueOf(entry.getFromAmount())); NumberFormat format = NumberFormat.getInstance(getMobiliserWebSession().getLocale()); setStrRate(format.format(entry.getRate())); updateExchangerateContainer.setVisible(true); addExchangerateContainer.setVisible(false); } }; PrivilegedBehavior disableEdit = new PrivilegedBehavior(this.getWebPage(), Constants.PRIV_FOREX_WRITE); disableEdit.setMissingPrivilegeHidesComponent(false); editLink.add(disableEdit); item.add(editLink); Link<ExchangeRate> removeLink = new Link<ExchangeRate>(WICKET_ID_removeAction, item.getModel()) { @Override public void onClick() { ExchangeRate entry = (ExchangeRate) getModelObject(); deleteExchangeRate( entry, addExchangerateContainer, updateExchangerateContainer); } }; PrivilegedBehavior disableRemove = new PrivilegedBehavior(this.getWebPage(), Constants.PRIV_FOREX_WRITE); disableRemove.setMissingPrivilegeHidesComponent(false); removeLink.add(disableRemove); if (removeLink.isEnabled()) { removeLink.add( new SimpleAttributeModifier( "onclick", "return confirm('" + getLocalizer().getString("exchangerate.remove.confirm", this) + "');")); } item.add(removeLink); } }; dataView.setItemsPerPage(10); addOrReplace(dataView); addOrReplace( new OrderByBorder(WICKET_ID_orderByfromCurrency, WICKET_ID_fromCurrency, dataProvider) { @Override protected void onSortChanged() { // For some reasons the dataView can be null when the page is // loading // and the sort is clicked (clicking the name header), so handle // it if (dataView != null) { dataView.setCurrentPage(0); } } }); addOrReplace( new MultiLineLabel( WICKET_ID_noItemsMsg, getLocalizer().getString("exchangerate.noItemsMsg", this) + "\n" + getLocalizer().getString("exchangerate.addExchangeRateHelp", this)) { @Override public boolean isVisible() { if (dataView.getItemCount() > 0) { return false; } else { return super.isVisible(); } } }); // Navigator example: << < 1 2 > >> addOrReplace(new CustomPagingNavigator(WICKET_ID_navigator, dataView)); addOrReplace( new Label(WICKET_ID_totalItems, new PropertyModel<String>(this, "totalItemString"))); addOrReplace(new Label(WICKET_ID_startIndex, new PropertyModel(this, "startIndex"))); addOrReplace(new Label(WICKET_ID_endIndex, new PropertyModel(this, "endIndex"))); }
public OverviewPage(PageParameters params) { super(params); int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5); Repository r = getRepository(); final RepositoryModel model = getRepositoryModel(); UserModel user = GitBlitWebSession.get().getUser(); if (user == null) { user = UserModel.ANONYMOUS; } List<Metric> metrics = null; Metric metricsTotal = null; if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) { metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r); metricsTotal = metrics.remove(0); } addSyndicationDiscoveryLink(); // repository description add(new Label("repositoryDescription", getRepositoryModel().description)); // owner links final List<String> owners = new ArrayList<String>(getRepositoryModel().owners); ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners); DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) { private static final long serialVersionUID = 1L; int counter = 0; public void populateItem(final Item<String> item) { String ownername = item.getModelObject(); UserModel ownerModel = GitBlit.self().getUserModel(ownername); if (ownerModel != null) { item.add( new LinkPanel( "owner", null, ownerModel.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(ownerModel.username)) .setRenderBodyOnly(true)); } else { Label owner = new Label("owner", ownername); WicketUtils.setCssStyle(owner, "text-decoration: line-through;"); WicketUtils.setHtmlTooltip( owner, MessageFormat.format(getString("gb.failedToFindAccount"), ownername)); item.add(owner); } counter++; item.add(new Label("comma", ",").setVisible(counter < owners.size())); item.setRenderBodyOnly(true); } }; ownersView.setRenderBodyOnly(true); add(ownersView); add( WicketUtils.createTimestampLabel( "repositoryLastChange", JGitUtils.getLastChange(r).when, getTimeZone(), getTimeUtils())); add(new Label("repositorySize", model.size)); if (metricsTotal == null) { add(new Label("branchStats", "")); } else { add( new Label( "branchStats", MessageFormat.format( getString("gb.branchStats"), metricsTotal.count, metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration)))); } add( new BookmarkablePageLink<Void>( "metrics", MetricsPage.class, WicketUtils.newRepositoryParameter(repositoryName))); add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model)); int reflogCount = GitBlit.getInteger(Keys.web.overviewReflogCount, 5); ReflogPanel reflog = new ReflogPanel("reflogPanel", getRepositoryModel(), r, reflogCount, 0); add(reflog); add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty()); add( new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false) .hideIfEmpty()); // Display an activity line graph insertActivityGraph(metrics); }
private void createServerListDataView() { dataProvider = new ServerListDataProvider(WICKET_ID_hostname, this); final DataView<ServerBean> dataView = new DataView<ServerBean>(WICKET_ID_pageable, dataProvider) { private static final long serialVersionUID = 1L; @Override protected void onBeforeRender() { try { dataProvider.loadAllServers(); refreshTotalItemCount(); } catch (DataProviderLoadException dple) { LOG.error("An error occured while loading customer serverList list", dple); error(getLocalizer().getString("serverList.load.error", this)); } refreshTotalItemCount(); super.onBeforeRender(); } @Override protected void populateItem(final Item<ServerBean> item) { final ServerBean entry = item.getModelObject(); // run ping to set server status handlePingAction(entry); Image serverIcon = new Image("serverIcon"); serverIcon.add( new AttributeModifier( "src", true, new AbstractReadOnlyModel() { private static final long serialVersionUID = 1L; @Override public final Object getObject() { if (isSelected(entry)) { return "images/icons/server_original_color_112x92.png"; } else { return "images/icons/server_original_greyscale_112x92.png"; } } })); serverIcon.setOutputMarkupId(true); item.add(serverIcon); Image statusIcon = new Image("statusIcon"); statusIcon.add( new AttributeModifier( "src", true, new AbstractReadOnlyModel() { private static final long serialVersionUID = 1L; @Override public final Object getObject() { if (entry.pingOk()) { return "images/icons/status-up-48px.png"; } else { return "images/icons/status-important-48px.png"; } } })); statusIcon.setOutputMarkupId(true); item.add(statusIcon); item.add(new Label(WICKET_ID_hostname, entry.getHostname())); item.add(new Label(WICKET_ID_port, String.valueOf(entry.getPort()))); // Ping Action Link<ServerBean> pingLink = new Link<ServerBean>(WICKET_ID_pingAction, item.getModel()) { @Override public void onClick() { ServerBean entry = (ServerBean) getModelObject(); handlePingAction(entry); if (entry.pingOk()) { setInfo( getLocalizer().getString("serverList.ping.success", this) + entry.getHostname() + ":" + entry.getPort()); } else { setError( getLocalizer().getString("serverList.ping.error", this) + entry.getHostname() + ":" + entry.getPort()); } } }; item.add(pingLink); // Select Action Link selectLink = new Link<ServerBean>(WICKET_ID_selectAction, item.getModel()) { @Override public void onClick() { ServerBean entry = (ServerBean) getModelObject(); handlePingAction(entry); if (!entry.pingOk()) { setError(getLocalizer().getString("serverList.select.error.notonline", this)); } else { handleSelectAction(entry); } } }; item.add(selectLink); // Remove Action Link removeLink = new Link<ServerBean>(WICKET_ID_removeAction, item.getModel()) { @Override public void onClick() { ServerBean entry = (ServerBean) getModelObject(); handleRemoveAction(entry); } }; removeLink.add( new SimpleAttributeModifier( "onclick", "return confirm('" + getLocalizer().getString("serverList.remove.confirm", this) + "');")); item.add(removeLink); // set items in even/odd rows to different css style classes item.add( new AttributeModifier( Constants.CSS_KEYWARD_CLASS, true, new AbstractReadOnlyModel<String>() { @Override public String getObject() { return (item.getIndex() % 2 == 1) ? Constants.CSS_STYLE_ODD : Constants.CSS_STYLE_EVEN; } })); } @Override public boolean isVisible() { if (getItemCount() > 0) { return true; } else { return super.isVisible(); } } private void refreshTotalItemCount() { totalItemString = new Integer(dataProvider.size()).toString(); int total = dataProvider.size(); if (total > 0) { startIndex = getCurrentPage() * getItemsPerPage() + 1; endIndex = startIndex + getItemsPerPage() - 1; if (endIndex > total) { endIndex = total; } } else { startIndex = 0; endIndex = 0; } } }; dataView.setOutputMarkupPlaceholderTag(true); dataView.setItemsPerPage(10); form.addOrReplace(dataView); form.addOrReplace( new MultiLineLabel( WICKET_ID_noItemsMsg, getLocalizer().getString("serverList.table.noItemsMsg", this) + "\n" + getLocalizer().getString("serverList.table.addServerBeanHelp", this)) { @Override public boolean isVisible() { if (dataView.getItemCount() > 0) { return false; } else { return super.isVisible(); } } }); // Navigator example: << < 1 2 > >> form.addOrReplace(new CustomPagingNavigator(WICKET_ID_navigator, dataView)); form.addOrReplace( new Label(WICKET_ID_totalItems, new PropertyModel<String>(this, "totalItemString"))); form.addOrReplace(new Label(WICKET_ID_startIndex, new PropertyModel(this, "startIndex"))); form.addOrReplace(new Label(WICKET_ID_endIndex, new PropertyModel(this, "endIndex"))); return; }
private void createJobListDataView(Form form) { dataProvider = new JobDataProvider(WICKET_ID_handlerName, this); jobList = new ArrayList<Job>(); final Long customerId = getMobiliserWebSession().getLoggedInCustomer().getCustomerId(); form.add( new Button("addJob") { private static final long serialVersionUID = 1L; @Override public void onSubmit() { setResponsePage(new JobAddPage(null, thisPage)); }; }); final DataView<Job> dataView = new DataView<Job>(WICKET_ID_pageable, dataProvider) { @Override protected void onBeforeRender() { try { dataProvider.loadJobs(); refreshTotalItemCount(); } catch (DataProviderLoadException dple) { LOG.error("# An error occurred while loading job and family list", dple); error(getLocalizer().getString("jobList.load.error", this)); } refreshTotalItemCount(); super.onBeforeRender(); } @Override protected void populateItem(final Item<Job> item) { final Job entry = item.getModelObject(); jobList.add(entry); item.add(new Label(WICKET_ID_handlerName, entry.getHandlerName())); item.add(new Label(WICKET_ID_implementationUrl, entry.getImplementationUrl())); item.add(new Label(WICKET_ID_schedule, entry.getSchedule())); // Edit Action Link<Job> editLink = new Link<Job>(WICKET_ID_editAction, item.getModel()) { @Override public void onClick() { Job entry = (Job) getModelObject(); editJob(entry); } }; item.add(editLink); // Send Money Action Link removeLink = new Link<Job>(WICKET_ID_removeAction, item.getModel()) { @Override public void onClick() { Job entry = (Job) getModelObject(); removeJob(entry); } }; removeLink.add( new SimpleAttributeModifier( "onclick", "return confirm('" + getLocalizer().getString("jobList.remove.confirm", this) + "');")); item.add(removeLink); // set items in even/odd rows to different css style classes item.add( new AttributeModifier( Constants.CSS_KEYWARD_CLASS, true, new AbstractReadOnlyModel<String>() { @Override public String getObject() { return (item.getIndex() % 2 == 1) ? Constants.CSS_STYLE_ODD : Constants.CSS_STYLE_EVEN; } })); } private void refreshTotalItemCount() { totalItemString = new Integer(dataProvider.size()).toString(); int total = getItemCount(); if (total > 0) { startIndex = getCurrentPage() * getItemsPerPage() + 1; endIndex = startIndex + getItemsPerPage() - 1; if (endIndex > total) endIndex = total; } else { startIndex = 0; endIndex = 0; } } }; dataView.setItemsPerPage(10); form.add(dataView); form.add( new MultiLineLabel( WICKET_ID_noItemsMsg, getLocalizer().getString("jobList.noItemsMsg", this) + "\n" + getLocalizer().getString("jobList.addJobHelp", this)) { @Override public boolean isVisible() { if (dataView.getItemCount() > 0) { return false; } else { return super.isVisible(); } } }); // Navigator example: << < 1 2 > >> form.add(new CustomPagingNavigator(WICKET_ID_navigator, dataView)); form.add(new Label(WICKET_ID_totalItems, new PropertyModel<String>(this, "totalItemString"))); form.add(new Label(WICKET_ID_startIndex, new PropertyModel(this, "startIndex"))); form.add(new Label(WICKET_ID_endIndex, new PropertyModel(this, "endIndex"))); }
/** * Sets the item reuse strategy for the table. Should be {@link ReuseIfModelsEqualStrategy} if * you're building an editable table, {@link DefaultItemReuseStrategy} otherwise */ public void setItemReuseStrategy(IItemReuseStrategy strategy) { dataView.setItemReuseStrategy(strategy); }
private void createAttachmentsListDataView( WebMarkupContainer attachmentContainer, final Form form) { WebMarkupContainer msgAttachmentsContainer = new WebMarkupContainer("msgAttachmentsContainer"); dataProvider = new MessageAttachmentDataProvider(WICKET_ID_name, basePage); msgAttachmentList = new ArrayList<MessageAttachment>(); final DataView<MessageAttachment> dataView = new DataView<MessageAttachment>(WICKET_ID_pageable, dataProvider) { @Override protected void onBeforeRender() { try { if (!isCreateMode) dataProvider.loadMsgAttachmentsList(message.getId(), forceReload); forceReload = false; refreshTotalItemCount(); // reset rowIndex rowIndex = 1; } catch (DataProviderLoadException dple) { LOG.error("# An error occurred while loading friends and family list", dple); error(getLocalizer().getString("msgAttachments.load.error", this)); } refreshTotalItemCount(); super.onBeforeRender(); } @Override protected void populateItem(final Item<MessageAttachment> item) { final MessageAttachment entry = item.getModelObject(); msgAttachmentList.add(entry); // Select box AjaxCheckBox selectedCheckBox = new AjaxCheckBoxImpl(WICKET_ID_selected, new Model(isSelected(entry)), entry); selectedCheckBox.setOutputMarkupId(true); selectedCheckBox.setMarkupId(WICKET_ID_selected + rowIndex++); item.add(selectedCheckBox); item.add(new Label(WICKET_ID_name, entry.getName())); // set items in even/odd rows to different css style classes item.add( new AttributeModifier( Constants.CSS_KEYWARD_CLASS, true, new AbstractReadOnlyModel<String>() { @Override public String getObject() { return (item.getIndex() % 2 == 1) ? Constants.CSS_STYLE_ODD : Constants.CSS_STYLE_EVEN; } })); } private void refreshTotalItemCount() { totalItemString = new Integer(dataProvider.size()).toString(); int total = getItemCount(); if (total > 0) { startIndex = getCurrentPage() * getItemsPerPage() + 1; endIndex = startIndex + getItemsPerPage() - 1; if (endIndex > total) endIndex = total; } else { startIndex = 0; endIndex = 0; } } class AjaxCheckBoxImpl extends AjaxCheckBox { private final MessageAttachment entry; public AjaxCheckBoxImpl(String id, IModel<Boolean> model, MessageAttachment entry) { super(id, model); this.entry = entry; } @Override public boolean isEnabled() { return true; } @Override protected void onComponentTag(final ComponentTag tag) { super.onComponentTag(tag); if (getModelObject()) { tag.put("checked", "checked"); } } @Override protected void onUpdate(AjaxRequestTarget target) { boolean checkBoxSelected = getModelObject(); if (checkBoxSelected) { LOG.info("Added {} to deletion list", entry.getId()); selectedAttachments.add(entry); } else { LOG.info("Removed {} from deletion list", entry.getId()); selectedAttachments.remove(entry); } } } }; dataView.setItemsPerPage(10); msgAttachmentsContainer.add(dataView); msgAttachmentsContainer.add( new OrderByBorder(WICKET_ID_orderByName, WICKET_ID_name, dataProvider) { @Override protected void onSortChanged() { // For some reasons the dataView can be null when the page is // loading // and the sort is clicked (clicking the name header), so handle // it if (dataView != null) { dataView.setCurrentPage(0); } } }); Button removeButton = new Button("removeAttachment") { private static final long serialVersionUID = 1L; @Override public void onSubmit() { handleRemove(); createAttachmentContainer(form); }; @Override public boolean isVisible() { if (dataView.getItemCount() > 0) { return super.isVisible(); } else { return false; } } }.setDefaultFormProcessing(false); removeButton.add( new SimpleAttributeModifier( "onclick", "return confirm('" + getLocalizer().getString("msgAttachments.remove.confirm", this) + "');")); msgAttachmentsContainer.add(removeButton); msgAttachmentsContainer.add( new MultiLineLabel( WICKET_ID_noItemsMsg, getLocalizer().getString("msgAttachments.noItemsMsg", this) + "\n" + getLocalizer().getString("msgAttachments.addMsgAttachmentsHelp", this)) { @Override public boolean isVisible() { if (dataView.getItemCount() > 0) { return false; } else { return super.isVisible(); } } }); // Navigator example: << < 1 2 > >> msgAttachmentsContainer.add(new CustomPagingNavigator(WICKET_ID_navigator, dataView)); msgAttachmentsContainer.add( new Label(WICKET_ID_totalItems, new PropertyModel<String>(this, "totalItemString"))); msgAttachmentsContainer.add( new Label(WICKET_ID_startIndex, new PropertyModel(this, "startIndex"))); msgAttachmentsContainer.add(new Label(WICKET_ID_endIndex, new PropertyModel(this, "endIndex"))); attachmentContainer.addOrReplace(msgAttachmentsContainer); }
public MenusPage(sf.file.Menus menu) { super("File | Menus"); init(); getMenus(menu.getMenuname()); add(new MenusFilter("menusfilter", this)); final DataView<Menus> dataView = new DataView<Menus>("pageable", new ListDataProvider(list)) { /** */ private static final long serialVersionUID = 1L; public void populateItem(final Item item) { final Menus _hj = (Menus) item.getModelObject(); item.add(new Label("no", String.valueOf(_hj.getNo()))); item.add(new Label("menuname", _hj.getMenuname())); item.add(new Label("recstatus", _hj.getRecstatus())); item.add( new AjaxLink<Menus>("select") { /** */ private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { // TODO Auto-generated method stub Menus header = (Menus) getParent().getDefaultModelObject(); PanelAction.actionType = 2; setResponsePage(new MenusInput(header)); } }); item.add( AttributeModifier.replace( "class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { return (item.getIndex() % 2 == 1) ? "even" : "odd"; } })); } }; dataView.setItemsPerPage(8); add(dataView); add(new PagingNavigator("navigator", dataView)); final FeedbackPanel feedback = new FeedbackPanel("feedback"); add(feedback); newmenu = new Link("newmenu") { /** */ private static final long serialVersionUID = 1L; @Override public void onClick() { // TODO Auto-generated method stub // setResponsePage(ModalKursHarianPage.class, new PageParameters()); setResponsePage(MenusInput.class); } }; add(newmenu); app = this; }
private void setup(PageParameters params) { setupPage("", ""); // default values ArrayList<String> repositories = new ArrayList<String>(); String query = ""; 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); } if (params.containsKey("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>(params != null && params.containsKey("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)); 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)); }
/** * Number of visible items per page, should the default {@link #DEFAULT_ITEMS_PER_PAGE} not * satisfy the programmer needs. Calling this will wipe out the selection * * @param items */ public void setItemsPerPage(int items) { dataView.setItemsPerPage(items); selection = new boolean[items]; }
public UsersPanel(String wicketId, final boolean showAdmin) { super(wicketId); Fragment adminLinks = new Fragment("adminPanel", "adminLinks", this); adminLinks.add(new BookmarkablePageLink<Void>("newUser", EditUserPage.class)); add(adminLinks.setVisible(showAdmin)); final List<UserModel> users = app().users().getAllUsers(); DataView<UserModel> usersView = new DataView<UserModel>("userRow", new ListDataProvider<UserModel>(users)) { private static final long serialVersionUID = 1L; private int counter; @Override protected void onBeforeRender() { super.onBeforeRender(); counter = 0; } @Override public void populateItem(final Item<UserModel> item) { final UserModel entry = item.getModelObject(); LinkPanel editLink = new LinkPanel( "username", "list", entry.username, EditUserPage.class, WicketUtils.newUsernameParameter(entry.username)); WicketUtils.setHtmlTooltip( editLink, getString("gb.edit") + " " + entry.getDisplayName()); item.add(editLink); if (StringUtils.isEmpty(entry.displayName)) { item.add(new Label("displayName").setVisible(false)); } else { editLink = new LinkPanel( "displayName", "list", entry.getDisplayName(), EditUserPage.class, WicketUtils.newUsernameParameter(entry.username)); WicketUtils.setHtmlTooltip( editLink, getString("gb.edit") + " " + entry.getDisplayName()); item.add(editLink); } if (StringUtils.isEmpty(entry.emailAddress)) { item.add(new Label("emailAddress").setVisible(false)); } else { editLink = new LinkPanel( "emailAddress", "list", entry.emailAddress, EditUserPage.class, WicketUtils.newUsernameParameter(entry.username)); WicketUtils.setHtmlTooltip( editLink, getString("gb.edit") + " " + entry.getDisplayName()); item.add(editLink); } item.add( new Label( "accountType", entry.accountType.name() + (entry.canAdmin() ? ", admin" : ""))); item.add(new Label("teams", entry.teams.size() > 0 ? ("" + entry.teams.size()) : "")); item.add( new Label( "repositories", entry.permissions.size() > 0 ? ("" + entry.permissions.size()) : "")); Fragment userLinks = new Fragment("userLinks", "userAdminLinks", this); userLinks.add( new BookmarkablePageLink<Void>( "editUser", EditUserPage.class, WicketUtils.newUsernameParameter(entry.username))); Link<Void> deleteLink = new Link<Void>("deleteUser") { private static final long serialVersionUID = 1L; @Override public void onClick() { if (app().users().deleteUser(entry.username)) { users.remove(entry); info(MessageFormat.format(getString("gb.userDeleted"), entry.username)); } else { error(MessageFormat.format(getString("gb.deleteUserFailed"), entry.username)); } } }; deleteLink.add( new JavascriptEventConfirmation( "onclick", MessageFormat.format(getString("gb.deleteUser"), entry.username))); userLinks.add(deleteLink); item.add(userLinks); WicketUtils.setAlternatingBackground(item, counter); counter++; } }; add(usersView.setVisible(showAdmin)); }
/** Sets back to the first page, clears the selection and */ public void reset() { dataView.setCurrentPage(0); clearSelection(); dataProvider.setSort(null); }
/** Builds a new table panel */ public GeoServerTablePanel( final String id, final GeoServerDataProvider<T> dataProvider, final boolean selectable) { super(id); this.dataProvider = dataProvider; // prepare the selection array selection = new boolean[DEFAULT_ITEMS_PER_PAGE]; // layer container used for ajax-y udpates of the table listContainer = new WebMarkupContainer("listContainer"); // build the filter form filterForm = new Form("filterForm") { @Override public void renderHead(IHeaderResponse response) { if (isRootForm()) return; // in subforms (on dialogs) the forms onsubmit doesn;t forward to the submit links // onclick, so we manually do it outselves String markupId = filterForm.getMarkupId(); String js = "if (Wicket.Browser.isSafari() || Wicket.Browser.isIE()) {" + "n = document.getElementById('" + markupId + "'); " + "while (n.nodeName.toLowerCase() != 'form') { n = n.parentElement; }; " + "n.setAttribute('onsubmit', \"return document.getElementById('" + hiddenSubmit.getMarkupId() + "').onclick();\");" + "}"; response.renderOnLoadJavascript(js); } }; filterForm.setOutputMarkupId(true); add(filterForm); filterForm.add(filter = new TextField("filter", new Model())); filter.add( new SimpleAttributeModifier( "title", String.valueOf(new ResourceModel("GeoServerTablePanel.search", "Search").getObject()))); filterForm.add(hiddenSubmit = hiddenSubmit()); filterForm.setDefaultButton(hiddenSubmit); // setup the table listContainer.setOutputMarkupId(true); add(listContainer); dataView = new DataView("items", dataProvider) { @Override protected void populateItem(Item item) { final IModel itemModel = item.getModel(); // odd/even style item.add( new SimpleAttributeModifier("class", item.getIndex() % 2 == 0 ? "even" : "odd")); // add row selector (visible only if selection is active) WebMarkupContainer cnt = new WebMarkupContainer("selectItemContainer"); cnt.add(selectOneCheckbox(item)); cnt.setVisible(selectable); item.add(cnt); // create one component per viewable property ListView items = new ListView("itemProperties", dataProvider.getVisibleProperties()) { @Override protected void populateItem(ListItem item) { Property<T> property = (Property<T>) item.getModelObject(); Component component = getComponentForProperty("component", itemModel, property); if (component == null) { // show a plain label if the the subclass did not create any component component = new Label("component", property.getModel(itemModel)); } else if (!"component".equals(component.getId())) { // add some checks for the id, the error message // that wicket returns in case of mismatch is not // that helpful throw new IllegalArgumentException( "getComponentForProperty asked " + "to build a component " + "with id = 'component' " + "for property '" + property.getName() + "', but got '" + component.getId() + "' instead"); } item.add(component); onPopulateItem(property, item); } }; items.setReuseItems(true); item.add(items); } }; dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); listContainer.add(dataView); // add select all checkbox WebMarkupContainer cnt = new WebMarkupContainer("selectAllContainer"); cnt.add(selectAll = selectAllCheckbox()); cnt.setVisible(selectable); listContainer.add(cnt); // add the sorting links listContainer.add( new ListView("sortableLinks", dataProvider.getVisibleProperties()) { @Override protected void populateItem(ListItem item) { Property<T> property = (Property<T>) item.getModelObject(); // build a sortable link if the property is sortable, a label otherwise IModel titleModel = getPropertyTitle(property); if (sortable && property.getComparator() != null) { Fragment f = new Fragment("header", "sortableHeader", item); AjaxLink link = sortLink(dataProvider, item); link.add(new Label("label", titleModel)); f.add(link); item.add(f); } else { item.add(new Label("header", titleModel)); } } }); // add the paging navigator and set the items per page dataView.setItemsPerPage(DEFAULT_ITEMS_PER_PAGE); pagerDelegate = new PagerDelegate(); filterForm.add(navigatorTop = new Pager("navigatorTop")); navigatorTop.setOutputMarkupId(true); add(navigatorBottom = new Pager("navigatorBottom")); navigatorBottom.setOutputMarkupId(true); }