List of usage examples for org.apache.wicket.extensions.markup.html.repeater.data.table DataTable DataTable
public DataTable(final String id, final List<? extends IColumn<T, S>> columns, final IDataProvider<T> dataProvider, final long rowsPerPage)
From source file:au.org.theark.study.web.component.global.subject.SubjectContainerPanel.java
License:Open Source License
@SuppressWarnings("unchecked") protected WebMarkupContainer initialiseSearchResults(AbstractDetailModalWindow modalWindow, final String gender, final List<RelationshipVo> relatives) { searchResultsPanel = new SearchResultListPanel("searchResults", arkContextMarkup, containerForm, arkCrudContainerVO, studyNameMarkup, studyLogoMarkup, mainTabs); searchResultsPanel.setOutputMarkupId(true); if (sessionStudyId != null) { LinkSubjectStudy linkSubjectStudy = new LinkSubjectStudy(); linkSubjectStudy.setStudy(study); //containerForm.getModelObject().setLinkSubjectStudy(linkSubjectStudy); }//from w w w . j a v a 2s .c o m // Data providor to paginate resultList subjectProvider = new ArkDataProvider<SubjectVO, IArkCommonService>(iArkCommonService) { private static final long serialVersionUID = 1L; private GenderType genderType; { Collection<GenderType> genderTypes = service.getGenderTypes(); for (GenderType type : genderTypes) { if (gender.equalsIgnoreCase(type.getName())) { this.genderType = type; break; } } } public int size() { String subjectUID = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SUBJECTUID); model.getObject().getRelativeUIDs().add(subjectUID); //TODO comment this block to check inbred relatives for (RelationshipVo relationshipVo : relatives) { model.getObject().getRelativeUIDs().add(relationshipVo.getIndividualId()); } model.getObject().getLinkSubjectStudy().getPerson().setGenderType(genderType); return (int) service.getStudySubjectCount(model.getObject()); } public Iterator<SubjectVO> iterator(int first, int count) { List<SubjectVO> listSubjects = new ArrayList<SubjectVO>(); if (isActionPermitted()) { model.getObject().getLinkSubjectStudy().getPerson().setGenderType(genderType); String subjectUID = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SUBJECTUID); model.getObject().getRelativeUIDs().add(subjectUID); //TODO comment this block to check inbred relatives for (RelationshipVo relationshipVo : relatives) { model.getObject().getRelativeUIDs().add(relationshipVo.getIndividualId()); } listSubjects = iArkCommonService.searchPageableSubjects(model.getObject(), first, count); } return listSubjects.iterator(); } }; subjectProvider.setModel(this.cpModel); dataView = searchResultsPanel.buildDataView(subjectProvider, modalWindow, relatives, feedBackPanel); dataView.setItemsPerPage( iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()); AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", dataView) { private static final long serialVersionUID = 1L; @Override protected void onAjaxEvent(AjaxRequestTarget target) { target.add(searchResultsPanel); } }; resultsWmc.add(pageNavigator); List<IColumn<SubjectVO>> columns = new ArrayList<IColumn<SubjectVO>>(); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("SubjectUID"), "subjectUID")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Study"), "linkSubjectStudy.study.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Full Name"), "subjectFullName")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Last Name History"), "linkSubjectStudy.person.descriptiveLastNameHistory")); columns.add(new ExportableDateColumn<SubjectVO>(Model.of("Date Of Birth"), "linkSubjectStudy.person.dateOfBirth", au.org.theark.core.Constants.DD_MM_YYYY)); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Vital Status"), "linkSubjectStudy.person.vitalStatus.name")); columns.add( new ExportableTextColumn<SubjectVO>(Model.of("Gender"), "linkSubjectStudy.person.genderType.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Subject Status"), "linkSubjectStudy.subjectStatus.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Consent Status"), "linkSubjectStudy.consentStatus.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Other IDs"), "linkSubjectStudy.person.descriptiveOtherIDs")); DataTable table = new DataTable("datatable", columns, dataView.getDataProvider(), iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()); List<String> headers = new ArrayList<String>(0); headers.add("SubjectUID"); headers.add("Study"); headers.add("Full Name"); headers.add("Last Name History"); headers.add("Date of Birth"); headers.add("Vital Status"); headers.add("Gender"); headers.add("Subject Status"); headers.add("Consent Status"); headers.add("Other IDs"); String filename = "subjects"; RepeatingView toolbars = new RepeatingView("toolbars"); ExportToolbar<String> exportToolBar = new ExportToolbar<String>(table, headers, filename); toolbars.add(new Component[] { exportToolBar }); resultsWmc.add(toolbars); resultsWmc.add(dataView); searchResultsPanel.add(resultsWmc); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultsPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.study.web.component.subject.SubjectContainerPanel.java
License:Open Source License
@SuppressWarnings("unchecked") protected WebMarkupContainer initialiseSearchResults() { searchResultsPanel = new SearchResultListPanel("searchResults", arkContextMarkup, containerForm, arkCrudContainerVO, studyNameMarkup, studyLogoMarkup); if (sessionStudyId != null) { LinkSubjectStudy linkSubjectStudy = new LinkSubjectStudy(); linkSubjectStudy.setStudy(study); // containerForm.getModelObject().setLinkSubjectStudy(linkSubjectStudy); }/*from w ww. j a v a2 s . com*/ // Data providor to paginate resultList subjectProvider = new ArkDataProvider<SubjectVO, IArkCommonService>(iArkCommonService) { private static final long serialVersionUID = 1L; public int size() { return (int) service.getStudySubjectCount(model.getObject()); } public Iterator<SubjectVO> iterator(int first, int count) { List<SubjectVO> listSubjects = new ArrayList<SubjectVO>(); if (isActionPermitted()) { listSubjects = iArkCommonService.searchPageableSubjects(model.getObject(), first, count); } return listSubjects.iterator(); } }; TextField<OtherID> txtFld = ((TextField<OtherID>) containerForm .get("searchContainer:searchComponentPanel:searchForm:otherID")); String otherIDSearch = txtFld != null ? txtFld.getValue() : null; if (otherIDSearch != null) { OtherID o; o = new OtherID(); o.setOtherID(otherIDSearch); // List<OtherID> otherIDs = new ArrayList<OtherID>(); // otherIDs.add(o); cpModel.getObject().getLinkSubjectStudy().getPerson().getOtherIDs().clear();//setOtherIDs(otherIDs); cpModel.getObject().getLinkSubjectStudy().getPerson().getOtherIDs().add(o); } subjectProvider.setModel(this.cpModel); dataView = searchResultsPanel.buildDataView(subjectProvider); dataView.setItemsPerPage( iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()); PagingNavigator pageNavigator = new PagingNavigator("navigator", dataView); resultsWmc.add(pageNavigator); List<IColumn<SubjectVO>> columns = new ArrayList<IColumn<SubjectVO>>(); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("SubjectUID"), "subjectUID")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Full Name"), "subjectFullName")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Preferred Name"), "linkSubjectStudy.person.preferredName")); columns.add(new ExportableDateColumn<SubjectVO>(Model.of("Date Of Birth"), "linkSubjectStudy.person.dateOfBirth", au.org.theark.core.Constants.DD_MM_YYYY)); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Vital Status"), "linkSubjectStudy.person.vitalStatus.name")); columns.add( new ExportableTextColumn<SubjectVO>(Model.of("Gender"), "linkSubjectStudy.person.genderType.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Subject Status"), "linkSubjectStudy.subjectStatus.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Consent Status"), "linkSubjectStudy.consentStatus.name")); DataTable table = new DataTable("datatable", columns, dataView.getDataProvider(), iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()); List<String> headers = new ArrayList<String>(0); headers.add("SubjectUID"); headers.add("Full Name"); headers.add("Preferred Name"); headers.add("Date of Birth"); headers.add("Vital Status"); headers.add("Gender"); headers.add("Subject Status"); headers.add("Consent Status"); String filename = study.getName() + "_subjects"; RepeatingView toolbars = new RepeatingView("toolbars"); ExportToolbar<String> exportToolBar = new ExportToolbar<String>(table, headers, filename); toolbars.add(new Component[] { exportToolBar }); resultsWmc.add(toolbars); resultsWmc.add(dataView); searchResultsPanel.add(resultsWmc); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultsPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:au.org.theark.study.web.component.subject.SubjectContainerPanel.java
License:Open Source License
@SuppressWarnings("unchecked") protected WebMarkupContainer initialiseSearchResults(AbstractDetailModalWindow modalWindow, final String gender, final List<RelationshipVo> relatives) { searchResultsPanel = new SearchResultListPanel("searchResults", arkContextMarkup, containerForm, arkCrudContainerVO, studyNameMarkup, studyLogoMarkup); searchResultsPanel.setOutputMarkupId(true); if (sessionStudyId != null) { LinkSubjectStudy linkSubjectStudy = new LinkSubjectStudy(); linkSubjectStudy.setStudy(study); // containerForm.getModelObject().setLinkSubjectStudy(linkSubjectStudy); }/*from w w w.ja va 2 s .c om*/ // Data providor to paginate resultList subjectProvider = new ArkDataProvider<SubjectVO, IArkCommonService>(iArkCommonService) { private static final long serialVersionUID = 1L; private GenderType genderType; { Collection<GenderType> genderTypes = service.getGenderTypes(); for (GenderType type : genderTypes) { if (gender.equalsIgnoreCase(type.getName())) { this.genderType = type; break; } } } public int size() { String subjectUID = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SUBJECTUID); model.getObject().getRelativeUIDs().add(subjectUID); // TODO comment this block to check inbred relatives Boolean inbreedAllowed = (Boolean) SecurityUtils.getSubject().getSession() .getAttribute(Constants.INBREED_ALLOWED); if (BooleanUtils.isNotTrue(inbreedAllowed)) { for (RelationshipVo relationshipVo : relatives) { model.getObject().getRelativeUIDs().add(relationshipVo.getIndividualId()); } } else { List<RelationshipVo> childRelatives = iStudyService.getSubjectChildren(subjectUID, sessionStudyId); for (RelationshipVo relationshipVo : childRelatives) { model.getObject().getRelativeUIDs().add(relationshipVo.getIndividualId()); } } model.getObject().getLinkSubjectStudy().getPerson().setGenderType(genderType); return (int) service.getStudySubjectCount(model.getObject()); } public Iterator<SubjectVO> iterator(int first, int count) { List<SubjectVO> listSubjects = new ArrayList<SubjectVO>(); if (isActionPermitted()) { model.getObject().getLinkSubjectStudy().getPerson().setGenderType(genderType); String subjectUID = (String) SecurityUtils.getSubject().getSession() .getAttribute(au.org.theark.core.Constants.SUBJECTUID); model.getObject().getRelativeUIDs().add(subjectUID); // TODO comment this block to check inbred relatives Boolean inbreedAllowed = (Boolean) SecurityUtils.getSubject().getSession() .getAttribute(Constants.INBREED_ALLOWED); if (BooleanUtils.isNotTrue(inbreedAllowed)) { for (RelationshipVo relationshipVo : relatives) { model.getObject().getRelativeUIDs().add(relationshipVo.getIndividualId()); } } else { List<RelationshipVo> childRelatives = iStudyService.getSubjectChildren(subjectUID, sessionStudyId); for (RelationshipVo relationshipVo : childRelatives) { model.getObject().getRelativeUIDs().add(relationshipVo.getIndividualId()); } } listSubjects = iArkCommonService.searchPageableSubjects(model.getObject(), first, count); } return listSubjects.iterator(); } }; subjectProvider.setModel(this.cpModel); dataView = searchResultsPanel.buildDataView(subjectProvider, modalWindow, relatives, feedBackPanel); dataView.setItemsPerPage( iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()); AjaxPagingNavigator pageNavigator = new AjaxPagingNavigator("navigator", dataView) { private static final long serialVersionUID = 1L; @Override protected void onAjaxEvent(AjaxRequestTarget target) { target.add(searchResultsPanel); } }; resultsWmc.add(pageNavigator); List<IColumn<SubjectVO>> columns = new ArrayList<IColumn<SubjectVO>>(); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("SubjectUID"), "subjectUID")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Full Name"), "subjectFullName")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Preferred Name"), "linkSubjectStudy.person.preferredName")); columns.add(new ExportableDateColumn<SubjectVO>(Model.of("Date Of Birth"), "linkSubjectStudy.person.dateOfBirth", au.org.theark.core.Constants.DD_MM_YYYY)); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Vital Status"), "linkSubjectStudy.person.vitalStatus.name")); columns.add( new ExportableTextColumn<SubjectVO>(Model.of("Gender"), "linkSubjectStudy.person.genderType.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Subject Status"), "linkSubjectStudy.subjectStatus.name")); columns.add(new ExportableTextColumn<SubjectVO>(Model.of("Consent Status"), "linkSubjectStudy.consentStatus.name")); DataTable table = new DataTable("datatable", columns, dataView.getDataProvider(), iArkCommonService.getUserConfig(au.org.theark.core.Constants.CONFIG_ROWS_PER_PAGE).getIntValue()); List<String> headers = new ArrayList<String>(0); headers.add("SubjectUID"); headers.add("Full Name"); headers.add("Preferred Name"); headers.add("Date of Birth"); headers.add("Vital Status"); headers.add("Gender"); headers.add("Subject Status"); headers.add("Consent Status"); String filename = study.getName() + "_subjects"; RepeatingView toolbars = new RepeatingView("toolbars"); ExportToolbar<String> exportToolBar = new ExportToolbar<String>(table, headers, filename); toolbars.add(new Component[] { exportToolBar }); resultsWmc.add(toolbars); resultsWmc.add(dataView); searchResultsPanel.add(resultsWmc); arkCrudContainerVO.getSearchResultPanelContainer().add(searchResultsPanel); return arkCrudContainerVO.getSearchResultPanelContainer(); }
From source file:com.doculibre.constellio.wicket.panels.admin.crud.DataPanel.java
License:Open Source License
public DataPanel(String id, int rowsPerPage) { super(id);/* w w w . j a va 2 s . c om*/ List<IColumn> columns = getColumns(); SortableListModel<T> sortableListModel = getSortableListModel(); SortableDataProvider dataProvider = new SortableListDataProvider(sortableListModel); dataTable = new DataTable("dataTable", columns.toArray(new IColumn[0]), dataProvider, rowsPerPage); add(dataTable); dataTable.setOutputMarkupId(true); dataTable.setVersioned(false); dataTable.addTopToolbar(new AjaxFallbackHeadersToolbar(dataTable, dataProvider) { @Override protected WebMarkupContainer newSortableHeader(String borderId, String property, ISortStateLocator locator) { WebMarkupContainer sortableHeader = super.newSortableHeader(borderId, property, locator); sortableHeader.add(new SimpleAttributeModifier("scope", "col")); return sortableHeader; } }); dataTable.addBottomToolbar(new AjaxNavigationToolbar(dataTable) { @Override protected PagingNavigator newPagingNavigator(String navigatorId, DataTable table) { return new AutoHidePagingNavigator(navigatorId, table); } }); dataTable.addBottomToolbar(new NoRecordsToolbar(dataTable)); dataTable.setItemReuseStrategy(new ReuseIfModelsEqualStrategy()); }
From source file:com.locke.tricks.u.U.java
License:Apache License
@SuppressWarnings("unchecked") public U() {/* www . j a v a2 s . c o m*/ final IColumn<Utility>[] columns = new IColumn[2]; columns[0] = new PropertyColumn<Utility>(new Model<String>("Code"), "code", "code"); columns[1] = new PropertyColumn<Utility>(new Model<String>("Output"), "output", "output"); final DataTable<Utility> dataTable = new DataTable<Utility>("utilities", columns, this.utilitiesDataProvider, Integer.MAX_VALUE); dataTable.addTopToolbar(new HeadersToolbar(dataTable, new ISortStateLocator() { private ISortState sortState = new SingleSortState(); public ISortState getSortState() { return this.sortState; } public void setSortState(final ISortState state) { this.sortState = state; } })); add(dataTable); this.utilities.add(new Utility("Time.now().toString()") { @Override public String getOutput() { return Time.now().toString(); } }); this.utilities.add(new Utility("Duration.ONE_WEEK.toString()") { @Override public String getOutput() { return Duration.ONE_WEEK.toString(); } }); this.utilities.add(new Utility("Duration.ONE_WEEK.add(Duration.ONE_DAY).toString()") { @Override public String getOutput() { return Duration.ONE_WEEK.add(Duration.ONE_DAY).toString(); } }); this.utilities.add(new Utility("Time.now().add(Duration.ONE_WEEK).toString()") { @Override public String getOutput() { return Time.now().add(Duration.ONE_WEEK).toString(); } }); this.utilities.add(new Utility("Bytes.valueOf(\"512K\") + Bytes.megabytes(1.3)") { @Override public String getOutput() { return Bytes.bytes(Bytes.valueOf("512K").bytes() + Bytes.megabytes(1.3).bytes()).toString(); } }); this.utilities.add(new Utility("Parsing \'13 + 13\' using MetaPattern") { @Override public String getOutput() { final IntegerGroup a = new IntegerGroup(MetaPattern.DIGITS); final IntegerGroup b = new IntegerGroup(MetaPattern.DIGITS); final MetaPattern sum = new MetaPattern(new MetaPattern[] { a, MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.PLUS, MetaPattern.OPTIONAL_WHITESPACE, b }); final Matcher matcher = sum.matcher("13 + 13"); if (matcher.matches()) { return Integer.toString(a.getInt(matcher) + b.getInt(matcher)); } return "Failed to match."; } }); }
From source file:de.alpharogroup.wicket.data.provider.examples.datatable.DataTablePanel.java
License:Apache License
public DataTablePanel(final String id) { super(id);//from www.j ava2 s . c o m final SortableFilterPersonDataProvider dataProvider = new SortableFilterPersonDataProvider( PersonDatabaseManager.getInstance().getPersons()) { private static final long serialVersionUID = 1L; @Override public List<Person> getData() { final List<Person> persons = PersonDatabaseManager.getInstance().getPersons(); setData(persons); return persons; } }; dataProvider.setSort("firstname", SortOrder.ASCENDING); final List<IColumn<Person, String>> columns = new ArrayList<>(); columns.add(new AbstractColumn<Person, String>(new Model<>("Actions")) { /** * The serialVersionUID */ private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ @Override public void populateItem(final Item<ICellPopulator<Person>> cellItem, final String componentId, final IModel<Person> model) { final ActionPanel<Person> editActionPanel = new ActionPanel<Person>(componentId, model) { /** * The serialVersionUID */ private static final long serialVersionUID = 1L; /** * {@inheritDoc} */ @Override protected IModel<String> newActionLinkLabelModel() { return ResourceModelFactory.newResourceModel("global.main.button.edit.label"); } /** * {@inheritDoc} */ @Override protected void onAction(final AjaxRequestTarget target) { DataTablePanel.this.onEdit(target); } }; cellItem.add(editActionPanel); } }); columns.add(new PropertyColumn<Person, String>(Model.of("First name"), "firstname", "firstname")); columns.add(new PropertyColumn<Person, String>(Model.of("Last Name"), "lastname", "lastname") { private static final long serialVersionUID = 1L; @Override public String getCssClass() { return "last-name"; } }); columns.add(new PropertyColumn<Person, String>(Model.of("Date of birth"), "dateOfBirth", "dateOfBirth")); final DataTable<Person, String> tableWithFilterForm = new DataTable<>("tableWithFilterForm", columns, dataProvider, 10); tableWithFilterForm.setOutputMarkupId(true); final FilterForm<PersonFilter> filterForm = new FilterForm<>("filterForm", dataProvider); filterForm.add(new TextField<>("dateFrom", PropertyModel.of(dataProvider, "filterState.dateFrom"))); filterForm.add(new TextField<>("dateTo", PropertyModel.of(dataProvider, "filterState.dateTo"))); add(filterForm); final FilterToolbar filterToolbar = new FilterToolbar(tableWithFilterForm, filterForm); tableWithFilterForm.addTopToolbar(filterToolbar); tableWithFilterForm.addTopToolbar(new NavigationToolbar(tableWithFilterForm)); tableWithFilterForm.addTopToolbar(new HeadersToolbar<>(tableWithFilterForm, dataProvider)); filterForm.add(tableWithFilterForm); }
From source file:dk.teachus.frontend.components.list.ListPanel.java
License:Apache License
private DataTable<T> createDataTable(List<IColumn<T>> columns, ISortableDataProvider<T> dataProvider, FilterForm<T> form, TeachUsFilter<T> filterStateLocator) { DataTable<T> dataTable = new DataTable<T>("table", columns, dataProvider, 40); if (form != null && filterStateLocator != null) { dataTable.addTopToolbar(new FilterSubmitToolbar(dataTable, filterStateLocator)); dataTable.addTopToolbar(new FilterToolbar(dataTable, form, filterStateLocator)); }/*from w w w . j a v a 2 s. com*/ dataTable.addTopToolbar(new AjaxFallbackHeadersToolbar(dataTable, dataProvider)); dataTable.addTopToolbar(createNavigationToolbar(dataTable)); dataTable.addBottomToolbar(createNavigationToolbar(dataTable)); return dataTable; }
From source file:net.databinder.components.hib.QueryPanel.java
License:Open Source License
/** * Creates a result table for the current query. * @return a result table, or an empty label if there is no current query *///from w ww. j a v a2 s. co m private Component getResultsTable() { if (Strings.isEmpty(query.getQuery())) { return new Label("results", ""); } else { IDataProvider dataProvider = new IDataProvider() { private static final long serialVersionUID = 1L; public void detach() { } public int size() { Session sess = Databinder.getHibernateSession(); Query query = sess.createQuery(getQuery()); return query.list().size(); } public String getQuery() { return QueryPanel.this.query.getQuery(); } public IModel model(Object object) { return new BoundCompoundPropertyModel(new HibernateObjectModel(object)); } public Iterator iterator(int first, int count) { Session sess = Databinder.getHibernateSession(); long start = System.nanoTime(); try { Query q = sess.createQuery(getQuery()); q.setFirstResult(first); q.setMaxResults(count); return q.iterate(); } finally { float nanoTime = ((System.nanoTime() - start) / 1000) / 1000.0f; setExecutionInfo("query executed in " + nanoTime + " ms: " + getQuery()); } } }; IColumn[] columns; Session sess = Databinder.getHibernateSession(); Query q = sess.createQuery(query.getQuery()); String[] aliases; Type[] returnTypes; try { aliases = q.getReturnAliases(); returnTypes = q.getReturnTypes(); } catch (NullPointerException e) { // thrown on updates return new Label("results", ""); } if (returnTypes.length != 1) { columns = new IColumn[returnTypes.length]; for (int i = 0; i < returnTypes.length; i++) { String alias = aliases == null || aliases.length <= i ? returnTypes[i].getName() : aliases[i]; final int index = i; columns[i] = new AbstractColumn(new Model(alias)) { private static final long serialVersionUID = 1L; public void populateItem(Item cellItem, String componentId, IModel rowModel) { Object[] objects = (Object[]) rowModel.getObject(); cellItem.add(new Label(componentId, new Model(objects[index] == null ? "" : objects[index].toString()))); } }; } } else { Type returnType = returnTypes[0]; if (returnType.isEntityType()) { Class clss = returnType.getReturnedClass(); ClassMetadata metadata = Databinder.getHibernateSessionFactory().getClassMetadata(clss); List<IColumn> cols = new ArrayList<IColumn>(); String idProp = metadata.getIdentifierPropertyName(); cols.add(new PropertyColumn(new Model(idProp), idProp)); String[] properties = metadata.getPropertyNames(); for (String prop : properties) { Type type = metadata.getPropertyType(prop); if (type.isCollectionType()) { // TODO: see if we could provide a link to the collection value } else { cols.add(new PropertyColumn(new Model(prop), prop)); } } columns = (IColumn[]) cols.toArray(new IColumn[cols.size()]); } else { String alias = aliases == null || aliases.length == 0 ? returnType.getName() : aliases[0]; columns = new IColumn[] { new AbstractColumn(new Model(alias)) { private static final long serialVersionUID = 1L; public void populateItem(Item cellItem, String componentId, IModel rowModel) { cellItem.add(new Label(componentId, rowModel)); } } }; } } DataTable dataTable = new DataTable("results", columns, dataProvider, 10); dataTable.addTopToolbar(new HeadersToolbar(dataTable, null)); dataTable.addBottomToolbar(new NavigationToolbar(dataTable)); dataTable.setOutputMarkupId(true); return dataTable; } }
From source file:net.fatlenny.datacitation.webapp.pages.DatasetCreationPage.java
License:Apache License
private void initializeDatatable(String selectedFile, String queryString) { if (selectedFile == null) { add(new Label("datatable", "Error populating data table.")); return;//w w w . j a va 2s. c o m } try { TableModel tableModel; if (queryString.isEmpty()) { tableModel = citationDBService.loadDataset(selectedFile.toString()); } else { String pidIdentifier = UUID.randomUUID().toString(); PID pid = new DefaultPID.PIDBuilder(pidIdentifier).setName(pidIdentifier).build(); Revision revision = new DefaultRevision("HEAD"); Query query = new DefaultQuery.QueryBuilder(pid, queryString, selectedFile, revision).build(); tableModel = citationDBService.getQueryResult(query); } revision = tableModel.getMetaData().getRevision().getRevisionId(); List<IColumn> header = new ArrayList<>(); List<String> headerData = tableModel.getHeaderData(); for (int i = 0; i < headerData.size(); i++) { header.add(new PropertyColumn<>(new Model<>(headerData.get(i)), String.format("%s", i))); } List<String[]> rows = tableModel.getRowData(); ListDataProvider<String[]> dataProvider = new ListDataProvider<>(rows); DataTable<String, String> table = new DataTable("datatable", header, dataProvider, 15); table.addBottomToolbar(new NavigationToolbar(table)); table.addTopToolbar(new HeadersToolbar(table, null)); add(table); } catch (CitationDBException e) { error(e.getMessage()); add(new Label("datatable", "Error populating data table.")); } }
From source file:net.fatlenny.datacitation.webapp.pages.QueryPage.java
License:Apache License
public QueryPage(final PageParameters parameters) { super(parameters); StringValue selectedQueryPid = parameters.get(Constants.PID_PARAM); add(new BookmarkablePageLink<Void>("home", HomePage.class)); add(new FeedbackPanel("feedback")); if (selectedQueryPid.isEmpty()) { error("No query transmitted. Please go back and select a valid query."); LOG.error("Parameter 'selectedQueryPid' null or emtpy."); }//from ww w . j av a2 s.c o m Query query = citationDBService.getQueryById(selectedQueryPid.toString()); TableModel tableModel = citationDBService.getQueryResult(query); final TextArea<String> queryString = new TextArea<String>("queryString", Model.of(wrapLines(query.getQuery()))); queryString.setEnabled(false); add(queryString); List<IColumn> header = new ArrayList<>(); List<String> headerData = tableModel.getHeaderData(); for (int i = 0; i < headerData.size(); i++) { header.add(new PropertyColumn<>(new Model<>(headerData.get(i)), String.format("%s", i))); } List<String[]> rows = tableModel.getRowData(); ListDataProvider<String[]> dataProvider = new ListDataProvider<>(rows); DataTable<String, String> table = new DataTable("datatable", header, dataProvider, 15); table.addBottomToolbar(new NavigationToolbar(table)); table.addTopToolbar(new HeadersToolbar(table, null)); add(table); }