List of usage examples for org.apache.wicket.markup.repeater ReuseIfModelsEqualStrategy getInstance
public static IItemReuseStrategy getInstance()
From source file:com.aplombee.QuickReuseIfModelsEqualStrategy.java
License:Apache License
/** * @see org.apache.wicket.markup.repeater.IItemReuseStrategy#getItems(org.apache.wicket.markup.repeater.IItemFactory, * java.util.Iterator, java.util.Iterator) */// w w w . j a v a 2s.c o m @Override public <T> Iterator<Item<T>> getItems(IItemFactory<T> factory, Iterator<IModel<T>> newModels, Iterator<Item<T>> existingItems) { return ReuseIfModelsEqualStrategy.getInstance().getItems(factory, newModels, existingItems); }
From source file:de.alpharogroup.wicket.components.listview.DataViewPanel.java
License:Apache License
/** * Factory method for create a new {@link DataView}. This method is invoked in the constructor * from the derived classes and can be overridden so users can provide their own version of a * new {@link DataView}.//w ww . j a v a 2s .c om * * @param id * the id * @param dataProvider * the data provider * @return the new {@link DataView} */ protected DataView<T> newDataView(final String id, final IDataProvider<T> dataProvider) { final DataView<T> dataView = new DataView<T>(id, dataProvider) { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ @Override protected void populateItem(final Item<T> item) { item.add(newListComponent("item", item)); } }; dataView.setItemsPerPage(newItemsPerPage()); dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); return dataView; }
From source file:de.alpharogroup.wicket.components.listview.RefreshingViewPanel.java
License:Apache License
/** * Factory method for creating a new {@link RefreshingView}. This method is invoked in the * constructor from the derived classes and can be overridden so users can provide their own * version of the new {@link RefreshingView}. * * @param id//from ww w.j a va 2s. c o m * the id * @param model * the model * @return the new {@link RefreshingView}. */ protected RefreshingView<T> newRefreshingView(final String id, final IModel<List<T>> model) { final RefreshingView<T> listView = new RefreshingView<T>(id, model) { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ @Override protected Iterator<IModel<T>> getItemModels() { return new ModelIteratorAdapter<T>(getModelObject().iterator()) { /** * {@inheritDoc} */ @Override protected IModel<T> model(final T object) { return Model.of(object); } }; } /** * {@inheritDoc} */ @Override protected Item<T> newItem(final String id, final int index, final IModel<T> model) { return RefreshingViewPanel.this.newItem(id, index, model); } /** * {@inheritDoc} */ @Override protected void populateItem(final Item<T> item) { item.add(newListComponent("item", item)); } }; listView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); return listView; }
From source file:de.alpharogroup.wicket.data.provider.examples.refreshingview.RefreshingViewPanel.java
License:Apache License
public RefreshingViewPanel(final String id, final IModel<?> model) { super(id, model); form = new Form<Person>("form"); add(form);//w ww. ja va 2 s . c om // create a repeater that will display the list of contacts. final RefreshingView<Person> refreshingView = new RefreshingView<Person>("simple") { /** * The serialVersionUID. */ private static final long serialVersionUID = 1L; @Override protected Iterator<IModel<Person>> getItemModels() { // for simplicity we only show the first 10 contacts // SortParam<String> sort = new SortParam<String>("firstname", // true); final Iterator<Person> contacts = PersonDatabaseManager.getInstance().getPersons().iterator(); // the iterator returns contact objects, but we need it to // return models, we use this handy adapter class to perform // on-the-fly conversion. return new ModelIteratorAdapter<Person>(contacts) { @Override protected IModel<Person> model(final Person object) { return new CompoundPropertyModel<Person>(object); } }; } @Override protected Item<Person> newItem(final String id, final int index, final IModel<Person> model) { // this item sets markup class attribute to either 'odd' or // 'even' for decoration return new OddEvenItem<Person>(id, index, model); } @Override protected void populateItem(final Item<Person> item) { // populate the row of the repeater final IModel<Person> contact = item.getModel(); item.add(new ActionPanel("actions", contact)); item.add(new TextField<String>("firstname")); item.add(new TextField<String>("lastname")); } }; // because we are in a form we need to preserve state of the component // hierarchy (because it might contain things like form errors that // would be lost if the hierarchy for each item was recreated every // request by default), so we use an item reuse strategy. refreshingView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); form.add(refreshingView); }
From source file:eu.uqasar.web.pages.admin.meta.MetaDataEditPanel.java
License:Apache License
public MetaDataEditPanel(String id, Class<T> clazz, S service, final StyledFeedbackPanel feedbackPanel) { super(id);//from w ww.j a va 2 s . c om this.clazz = clazz; this.service = service; metaData = MetaData.newInstance(clazz); add(new Label("head.type.add", MetaData.getLabelForNew(this.clazz))); Form<Void> form = new InputValidationForm<>("form"); nameField = new TextField<>("name", new PropertyModel<String>(metaData, "name")); InputBeanValidationBorder<String> nameValidationBorder = new OnEventInputBeanValidationBorder<>( "nameValidationBorder", nameField, MetaData.getLabelModelForNew(this.clazz), HtmlEvent.ONBLUR); form.add(nameValidationBorder); AjaxSubmitLink addObject = new AjaxSubmitLink("add") { @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); target.add(form); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { addNewMetaData(target, form); } }; nameValidationBorder.add(addObject); add(form); existingListForm = new InputValidationForm<>("form.existing"); existingListForm.add(new Label("head.type.existing", MetaData.getLabelForExisting(this.clazz))); existingList = getListing(); existingList.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); existingListForm.add(checkGroup = newCheckGroup()); final WebMarkupContainer existingItemsContainer = new WebMarkupContainer("dataContainer"); existingItemsContainer.add(new Label("table.head.type", MetaData.getLabel(this.clazz))); checkGroup.add(existingItemsContainer.setOutputMarkupId(true)); CheckGroupSelector checkGroupSelector = new CheckGroupSelector("dataGroupSelector", checkGroup); existingItemsContainer.add(checkGroupSelector); existingItemsContainer.add(existingList); existingItemsContainer.add(deleteSelectedButton = newDeleteSelectedButton(checkGroup)); existingItemsContainer.add(new IndicatingAjaxButton("update") { @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); target.add(existingItemsContainer); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { updateExistingMetaData(target, form); Effects.replaceWithFading(target, existingItemsContainer); } }); add(existingListForm); add(deleteConfirmationModal = newDeleteConfirmationModal()); }
From source file:guru.mmp.application.web.template.pages.CodeAdministrationPage.java
License:Apache License
/** * Constructs a new <code>CodeAdministrationPage</code>. * * @param previousPage the previous page * @param codeCategoryId the Universally Unique Identifier (UUID) used to uniquely identify the * code category the codes are associated with * @param codeCategoryName the name of the code category *//*from w ww . ja va2 s . com*/ CodeAdministrationPage(PageReference previousPage, UUID codeCategoryId, String codeCategoryName) { super("Codes", codeCategoryName); try { /* * The table container, which allows the table and its associated navigator to be updated * using AJAX. */ WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer"); tableContainer.setOutputMarkupId(true); add(tableContainer); // The dialog used to confirm the removal of a code RemoveDialog removeDialog = new RemoveDialog(tableContainer); add(removeDialog); // The "addLink" link Link<Void> addLink = new Link<Void>("addLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { AddCodePage page = new AddCodePage(getPageReference(), codeCategoryId); setResponsePage(page); } }; tableContainer.add(addLink); // The "backLink" link Link<Void> backLink = new Link<Void>("backLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { setResponsePage(previousPage.getPage()); } }; tableContainer.add(backLink); // The code data view CodeDataProvider dataProvider = new CodeDataProvider(codeCategoryId); DataView<Code> dataView = new DataView<Code>("code", dataProvider) { private static final long serialVersionUID = 1000000; @Override protected void populateItem(Item<Code> item) { Code code = item.getModelObject(); String name = StringUtil.truncate(code.getName(), 25); String value = StringUtil.truncate(code.getValue(), 30); item.add(new Label("name", Model.of(name))); item.add(new Label("value", Model.of(value))); // The "updateLink" link Link<Void> updateLink = new Link<Void>("updateLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { UpdateCodePage page = new UpdateCodePage(getPageReference(), item.getModel()); setResponsePage(page); } }; item.add(updateLink); // The "removeLink" link AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") { private static final long serialVersionUID = 1000000; @Override public void onClick(AjaxRequestTarget target) { removeDialog.show(target, item.getModel()); } }; item.add(removeLink); } }; dataView.setItemsPerPage(10); dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); tableContainer.add(dataView); tableContainer.add(new PagingNavigator("navigator", dataView)); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the CodeAdministrationPage", e); } }
From source file:guru.mmp.application.web.template.pages.CodeCategoryAdministrationPage.java
License:Apache License
/** * Constructs a new <code>CodeCategoryAdministrationPage</code>. *///ww w .ja v a 2 s. c om public CodeCategoryAdministrationPage() { super("Code Categories"); try { /* * The table container, which allows the table and its associated navigator to be updated * using AJAX. */ WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer"); tableContainer.setOutputMarkupId(true); add(tableContainer); // The dialog used to confirm the removal of a code category RemoveDialog removeDialog = new RemoveDialog(tableContainer); add(removeDialog); // The "addLink" used to add a new code category Link<Void> addLink = new Link<Void>("addLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { setResponsePage(new AddCodeCategoryPage(getPageReference())); } }; tableContainer.add(addLink); // The code category data view CodeCategoryDataProvider dataProvider = new CodeCategoryDataProvider(false); DataView<CodeCategory> dataView = new DataView<CodeCategory>("codeCategory", dataProvider) { private static final long serialVersionUID = 1000000; @Override protected void populateItem(Item<CodeCategory> item) { item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name"))); item.add(new Label("categoryType", new PropertyModel<String>(item.getModel(), "categoryType.name"))); // The "updateLink" link Link<Void> updateLink = new Link<Void>("updateLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { UpdateCodeCategoryPage page = new UpdateCodeCategoryPage(getPageReference(), item.getModel()); setResponsePage(page); } }; item.add(updateLink); // The "removeLink" link AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") { private static final long serialVersionUID = 1000000; @Override public void onClick(AjaxRequestTarget target) { removeDialog.show(target, item.getModel()); } }; item.add(removeLink); // The "codeAdministrationLink" link Link<Void> codeAdministrationLink = new Link<Void>("codeAdministrationLink") { private static final long serialVersionUID = 1000000; @Override public boolean isVisible() { return item.getModelObject().getCategoryType() == CodeCategoryType.LOCAL_STANDARD; } @Override public void onClick() { CodeCategory codeCategory = item.getModelObject(); UUID codeCategoryId = codeCategory.getId(); String codeCategoryName = codeCategory.getName(); setResponsePage(new CodeAdministrationPage(getPageReference(), codeCategoryId, codeCategoryName)); } }; item.add(codeAdministrationLink); } }; dataView.setItemsPerPage(10); dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); tableContainer.add(dataView); tableContainer.add(new PagingNavigator("navigator", dataView)); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the CodeCategoryAdministrationPage", e); } }
From source file:guru.mmp.application.web.template.pages.ConfigurationAdministrationPage.java
License:Apache License
/** * Constructs a new <code>ConfigurationAdministrationPage</code>. *///from w w w . j a v a 2 s. co m public ConfigurationAdministrationPage() { super("Configuration"); try { /* * The table container, which allows the table and its associated navigator to be updated * using AJAX. */ WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer"); tableContainer.setOutputMarkupId(true); add(tableContainer); // The dialog used to confirm the removal of a configuration value RemoveDialog removeDialog = new RemoveDialog(tableContainer); add(removeDialog); // The "addLink" used to add a new configuration value Link<Void> addLink = new Link<Void>("addLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { setResponsePage(new AddConfigurationValuePage(getPageReference())); } }; tableContainer.add(addLink); FilteredConfigurationValueDataProvider dataProvider = new FilteredConfigurationValueDataProvider(); // The "filterForm" form Form<Void> filterForm = new Form<>("filterForm"); filterForm.setMarkupId("filterForm"); filterForm.setOutputMarkupId(true); // The "filter" field TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter")); filterForm.add(filterField); // The "filterButton" button Button filterButton = new Button("filterButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { } }; filterButton.setDefaultFormProcessing(true); filterForm.add(filterButton); // The "resetButton" button Button resetButton = new Button("resetButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { dataProvider.setFilter(""); } }; filterForm.add(resetButton); tableContainer.add(filterForm); // The configuration value data view DataView<ConfigurationValue> dataView = new DataView<ConfigurationValue>("configurationValue", dataProvider) { private static final long serialVersionUID = 1000000; @Override protected void populateItem(Item<ConfigurationValue> item) { item.add(new Label("key", new PropertyModel<String>(item.getModel(), "key"))); item.add(new Label("value", new PropertyModel<String>(item.getModel(), "value"))); // The "updateLink" link Link<Void> updateLink = new Link<Void>("updateLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { UpdateConfigurationValuePage page = new UpdateConfigurationValuePage(getPageReference(), item.getModel()); setResponsePage(page); } }; item.add(updateLink); // The "removeLink" link AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") { private static final long serialVersionUID = 1000000; @Override public void onClick(AjaxRequestTarget target) { ConfigurationValue configuration = item.getModelObject(); if (configuration != null) { removeDialog.show(target, configuration); } else { target.add(tableContainer); } } }; item.add(removeLink); } }; dataView.setItemsPerPage(10); dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); tableContainer.add(dataView); tableContainer.add(new PagingNavigator("navigator", dataView)); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the ConfigurationAdministrationPage", e); } }
From source file:guru.mmp.application.web.template.pages.GroupAdministrationPage.java
License:Apache License
/** * Constructs a new <code>GroupAdministrationPage</code>. *//*from w w w .j a v a 2s . co m*/ public GroupAdministrationPage() { super("Groups"); try { /* * Retrieve the list of user directories for the organisation the currently logged on user * is associated with and default to the first user directory. */ List<UserDirectory> userDirectories = getUserDirectories(); userDirectory = userDirectories.get(0); /* * The table container, which allows the table and its associated navigator to be updated * using AJAX. */ WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer"); tableContainer.setOutputMarkupId(true); add(tableContainer); // The dialog used to confirm the removal of a group RemoveDialog removeDialog = new RemoveDialog(tableContainer); add(removeDialog); // The "addLink" link Link<Void> addLink = new Link<Void>("addLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { AddGroupPage page = new AddGroupPage(getPageReference(), userDirectory.getId()); setResponsePage(page); } }; tableContainer.add(addLink); GroupDataProvider dataProvider = new GroupDataProvider(userDirectory.getId()); // The "userDirectoryDropdownMenu" dropdown button DropdownMenu<UserDirectory> userDirectoryDropdownMenu = new DropdownMenu<UserDirectory>( "userDirectoryDropdownMenu", new PropertyModel<>(this, "userDirectory"), userDirectories, "fa fa-users") { @Override protected String getDisplayValue(UserDirectory menuItem) { return menuItem.getName(); } @Override protected void onMenuItemSelected(AjaxRequestTarget target, UserDirectory menuItem) { dataProvider.setUserDirectoryId(userDirectory.getId()); if (target != null) { target.add(tableContainer); } } }; userDirectoryDropdownMenu.setVisible(userDirectories.size() > 1); tableContainer.add(userDirectoryDropdownMenu); // The group data view DataView<Group> dataView = new DataView<Group>("group", dataProvider) { private static final long serialVersionUID = 1000000; @Override protected void populateItem(Item<Group> item) { item.add(new Label("groupName", new PropertyModel<String>(item.getModel(), "groupName"))); item.add(new Label("description", new PropertyModel<String>(item.getModel(), "description"))); // The "updateLink" link Link<Void> updateLink = new Link<Void>("updateLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { UpdateGroupPage page = new UpdateGroupPage(getPageReference(), item.getModel()); setResponsePage(page); } }; item.add(updateLink); // The "removeLink" link AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") { private static final long serialVersionUID = 1000000; @Override public void onClick(AjaxRequestTarget target) { Group group = item.getModelObject(); if (group != null) { removeDialog.show(target, group); } else { target.add(tableContainer); } } }; item.add(removeLink); } }; dataView.setItemsPerPage(10); dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); tableContainer.add(dataView); tableContainer.add(new PagingNavigator("navigator", dataView)); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the GroupAdministrationPage", e); } }
From source file:guru.mmp.application.web.template.pages.JobAdministrationPage.java
License:Apache License
/** * Constructs a new <code>JobAdministrationPage</code>. *//*w w w.j a v a2 s . co m*/ public JobAdministrationPage() { super("Scheduler"); try { /* * The table container, which allows the table and its associated navigator to be updated * using AJAX. */ WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer"); tableContainer.setOutputMarkupId(true); add(tableContainer); // The dialog used to confirm the removal of a job RemoveDialog removeDialog = new RemoveDialog(tableContainer); add(removeDialog); // The "addLink" used to add a new job Link<Void> addLink = new Link<Void>("addLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { AddJobPage page = new AddJobPage(getPageReference()); setResponsePage(page); } }; tableContainer.add(addLink); FilteredJobDataProvider dataProvider = new FilteredJobDataProvider(); // The "filterForm" form Form<Void> filterForm = new Form<>("filterForm"); filterForm.setMarkupId("filterForm"); filterForm.setOutputMarkupId(true); // The "filter" field TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter")); filterForm.add(filterField); // The "filterButton" button Button filterButton = new Button("filterButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { } }; filterButton.setDefaultFormProcessing(true); filterForm.add(filterButton); // The "resetButton" button Button resetButton = new Button("resetButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { dataProvider.setFilter(""); } }; filterForm.add(resetButton); tableContainer.add(filterForm); // The job data view DataView<Job> dataView = new DataView<Job>("job", dataProvider) { private static final long serialVersionUID = 1000000; @Override protected void populateItem(Item<Job> item) { item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name"))); item.add(new Label("jobClass", new PropertyModel<String>(item.getModel(), "jobClass"))); item.add(DateLabel.forDatePattern("nextExecution", new PropertyModel<>(item.getModel(), "nextExecution"), "YYYY-MM-dd hh:mm a")); // The "parametersLink" link Link<Void> parametersLink = new Link<Void>("parametersLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { // Job job = item.getModelObject(); // JobParametersPage page = new JobParametersPage(getPageReference(), job.getId()); // // setResponsePage(page); } }; item.add(parametersLink); // The "updateLink" link Link<Void> updateLink = new Link<Void>("updateLink") { private static final long serialVersionUID = 1000000; @Override public void onClick() { UpdateJobPage page = new UpdateJobPage(getPageReference(), item.getModel()); setResponsePage(page); } }; item.add(updateLink); // The "removeLink" link AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") { private static final long serialVersionUID = 1000000; @Override public void onClick(AjaxRequestTarget target) { Job job = item.getModelObject(); if (job != null) { removeDialog.show(target, job); } else { target.add(tableContainer); } } }; item.add(removeLink); } }; dataView.setItemsPerPage(10); dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); tableContainer.add(dataView); tableContainer.add(new PagingNavigator("navigator", dataView)); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the JobAdministrationPage", e); } }