/** * Returns the column corresponding to the specified index. * * @param index Column index. * @return List header at index. */ private Column getColumnByIndex(int index) { for (BaseComponent comp : columns.getChildren()) { if (((Integer) comp.getAttribute(COL_INDEX_ATTR)).intValue() == index) { return (Column) comp; } } return null; }
/** * 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); } } } } }
/** * 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); } } }
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(); }
/** * If the added column is marked as sorted, set it as the sort column. * * @see org.fujion.component.BaseComponent#afterAddChild(org.fujion.component.BaseComponent) */ @Override protected void afterAddChild(BaseComponent child) { super.afterAddChild(child); if (((Column) child).isSortColumn()) { setSortColumn((Column) child); } }
grid.getColumns().getChild(Column.class).sort();
int max = columns == null ? 0 : columns.getChildCount(); String info = patientListItem.getInfo();
@Test public void testForm() throws Exception { BaseComponent root = PageUtil.createPage("web/org/carewebframework/ui/sharedforms/listviewForm.fsp", null).get(0); TestController controller = new TestController(); root.wireController(controller); ElementPlugin dummy = new ElementPlugin(); controller.onLoad(dummy); controller.requestData(); assertEquals(10, controller.model.size()); Grid grid = (Grid) root.findByName("grid"); Rows rows = grid.getRows(); assertEquals(10, rows.getChildCount()); assertEquals("Item #2.3", ((ILabeled) rows.getChildAt(1).getChildAt(2)).getLabel()); assertEquals("Test Title", controller.getCaption()); assertEquals("Header3", ((Column) grid.getColumns().getLastChild()).getLabel()); assertEquals(":1:false;0:33%;1:33%;2:33%", controller.getLayout()); controller.setLayout(":2:true;0:20%;1:30%;2:50%"); assertEquals(":2:true;0:20%;1:30%;2:50%", controller.getLayout()); } }
/** * 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; }
/** * 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(); }