/** * Adds a column to a grid. * * @param grid Grid. * @param label Label for column. * @param width Width for column. * @param sortBy Field for sorting. * @return Newly created column. */ public Column addColumn(Grid grid, String label, String width, String sortBy) { Column column = new Column(); grid.getColumns().addChild(column); column.setLabel(label); column.setWidth(width); column.setSortComparator(sortBy); column.setSortOrder(SortOrder.ASCENDING); return column; }
/** * Sets the sort column state. If set to true, the column is sorted and designated as the * current sort column. * * @param sortColumn If true, this column is sorted and designated as the current sort column. * @param notifyParent If true, update the sort column property of the parent. */ protected void _setSortColumn(boolean sortColumn, boolean notifyParent) { if (propertyChange("sortColumn", this.sortColumn, this.sortColumn = sortColumn, false)) { if (sortColumn) { sort(); } else { updateClient(); } if (notifyParent) { Columns parent = (Columns) getParent(); if (parent != null) { if (sortColumn) { parent.setSortColumn(this); } else if (parent.getSortColumn() == this) { parent.setSortColumn(null); } } } } }
/** * Sort the column according to the sort order property. */ public void sort() { if (!sortColumn) { setSortColumn(true); return; } IListModel<Object> model = sortComparator == null || sortOrder == SortOrder.UNSORTED ? null : getRowsModel(); updateClient(); if (model != null) { @SuppressWarnings("unchecked") Comparator<Object> comparator = sortOrder == SortOrder.NATIVE ? null : (Comparator<Object>) sortComparator; model.sort(comparator, sortOrder != SortOrder.DESCENDING); } }
/** * Transitions the sort order to the next state (depending on the setting of the sort toggle) * and performs the sort. */ public void toggleSort() { int i = sortOrder.ordinal() + 1; int max = sortToggle == SortToggle.TRISTATE ? 3 : 2; setSortOrder(SortOrder.values()[i >= max ? 0 : i]); sort(); }
protected void setup(String title, int sortBy, String... headers) { setCaption(title); dataName = title; String defWidth = (100 / headers.length) + "%"; for (String header : headers) { String[] pcs = StrUtil.split(header, "^", 3); Column lhdr = new Column(pcs[0]); columns.addChild(lhdr); lhdr.setAttribute(SORT_TYPE_ATTR, NumberUtils.toInt(pcs[1])); lhdr.setAttribute(COL_INDEX_ATTR, colCount++); String width = pcs[2]; if (!width.isEmpty()) { if (NumberUtils.isDigits(width) || "min".equals(width)) { //lhdr.setHflex(width); } else { lhdr.setWidth(width); } } else { lhdr.setWidth(defWidth); } } sortColumn = Math.abs(sortBy) - 1; sortAscending = sortBy > 0; doSort(); }
/** * Setter method for Layout property. This property allows an application to control the * position of the splitter bar and ordering of columns. * * @param layout The layout data. */ public void setLayout(String layout) { String[] pcs = StrUtil.split(layout, ";"); if (pcs.length > 0) { String[] spl = StrUtil.split(pcs[0], ":", 3); sortColumn = NumberUtils.toInt(spl[1]); sortAscending = BooleanUtils.toBoolean(spl[2]); } for (int i = 1; i < pcs.length; i++) { String[] col = StrUtil.split(pcs[i], ":", 2); Column lhdr = getColumnByIndex(NumberUtils.toInt(col[0])); if (lhdr != null) { lhdr.setWidth(col[1]); lhdr.setIndex(i - 1); } } doSort(); }
/** * Sets the name of the model property to be used for sorting. * * @param propertyName The name of the model property to be used for sorting. */ @PropertySetter(value = "sortBy", description = "The name of the model property to be used for sorting.") public void setSortComparator(String propertyName) { setSortComparator(new SmartComparator(propertyName)); }
private void doSort() { getColumnByIndex(sortColumn).sort(); }
/** * Getter method for Layout property. Format: * * <pre> * List Pane Size:Sort Column:Sort Direction;Column 0 Index:Column 0 Width;... * </pre> * * @return The layout data. */ public String getLayout() { StringBuilder sb = new StringBuilder(); sb.append(':').append(sortColumn).append(':').append(sortAscending); for (BaseComponent comp : columns.getChildren()) { Column lhdr = (Column) comp; sb.append(';').append(lhdr.getAttribute(COL_INDEX_ATTR)).append(':').append(lhdr.getWidth()); } return sb.toString(); }
@Override public void init(Grid grid) { grid.getRows().getModelAndView(ManifestItem.class).setRenderer(this); addColumn(grid, "Module", "40%", "@implModule").setSortColumn(true); addColumn(grid, "Version", "20%", "@implVersion"); addColumn(grid, "Author", "40%", "@implVendor"); } }
/** * Sets the currently sorted column. * * @param sortColumn The column to sort. */ public void setSortColumn(Column sortColumn) { if (sortColumn != this.sortColumn) { validateIsChild(sortColumn); if (this.sortColumn != null) { this.sortColumn._setSortColumn(false, false); } this.sortColumn = sortColumn; if (sortColumn != null) { sortColumn._setSortColumn(true, false); } } }
/** * Returns the model from the associated grid rows. * * @return The model backing the associated grid rows. May be null. */ private IListModel<Object> getRowsModel() { Grid grid = getAncestor(Grid.class); Rows rows = grid == null ? null : grid.getRows(); return rows == null ? null : rows.getModel(Object.class); }
@Override public void afterInitialized(BaseComponent comp) { super.afterInitialized(comp); window = (Window) comp; title = window.getTitle(); scenario = (Scenario) comp.getAttribute("scenario"); model.addAll(scenario.getResources()); model.sort(resourceComparator, true); colResource.setSortComparator(resourceComparator); IModelAndView<Row, IBaseResource> mv = tblResources.getRows().getModelAndView(IBaseResource.class); mv.setRenderer(resourceRenderer); mv.setModel(model); updateCaption(); }
grid.getColumns().getChild(Column.class).sort();
/** * When set to true, designates this column as the currently sorted column. Note that this * setting is mutually exclusive among columns within the same grid instance. * * @param sortColumn Set to true to sort this column and designate it as the current sort * column. Doing so will set this property to false on all other columns. */ @PropertySetter(value = "sortColumn", defaultValue = "false", description = "True if this is the currently sorted column.") public void setSortColumn(boolean sortColumn) { _setSortColumn(sortColumn, true); }