@Override protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) { String result = super.formatPropertyValue(rowId, colId, property); return StringEscapeUtils.escapeHtml4(result); }
@Override public Resource getItemIcon(Object itemId) { if (iconProvider != null) { return iconProvider.apply(itemId); } return super.getItemIcon(itemId); }
/** * This method is made public in order to be able to delegate the call to * tree tables' {@link HierarchicalStrategy} instead of the actual container * which can be very slow. */ @Override public int indexOfId(Object itemId) { return super.indexOfId(itemId); }
private void toggleChildVisibility(Object itemId, boolean forceFullRefresh) { getContainerStrategy().toggleChildVisibility(itemId); // ensure that page still has first item in page, DON'T clear the // caches. setCurrentPageFirstItemIndex(getCurrentPageFirstItemIndex(), false); if (isCollapsed(itemId)) { fireCollapseEvent(itemId); } else { fireExpandEvent(itemId); } if (containerSupportsPartialUpdates && !forceFullRefresh) { markAsDirty(); } else { // For containers that do not send item set change events, always do // full repaint instead of partial row update. refreshRowCache(); } }
/** * Sets the Item specified by given identifier as collapsed or expanded. If * the Item is collapsed, its children are not displayed to the user. * * @param itemId * the identifier of the Item * @param collapsed * true if the Item should be collapsed, false if expanded */ public void setCollapsed(Object itemId, boolean collapsed) { if (isCollapsed(itemId) != collapsed) { if (null == toggledItemId && !isRowCacheInvalidated() && getVisibleItemIds().contains(itemId)) { // optimization: partial refresh if only one item is // collapsed/expanded toggledItemId = itemId; toggleChildVisibility(itemId, false); } else { // make sure a full refresh takes place - otherwise neither // partial nor full repaint of table content is performed toggledItemId = null; toggleChildVisibility(itemId, true); } } }
@Override public void changeVariables(Object source, Map<String, Object> variables) { super.changeVariables(source, variables); if (variables.containsKey("toggleCollapsed")) { String object = (String) variables.get("toggleCollapsed"); Object itemId = itemIdMapper.get(object); toggledItemId = itemId; toggleChildVisibility(itemId, false); if (variables.containsKey("selectCollapsed")) { // ensure collapsed is selected unless opened with selection // head if (isSelectable()) { select(itemId); } } } else if (variables.containsKey("focusParent")) { String key = (String) variables.get("focusParent"); Object refId = itemIdMapper.get(key); Object itemId = getParent(refId); focusParent(itemId); } }
/** * Simulates receiving a focusParent event from the client, via #changeVariables */ private static void focusParent(TreeTable treeTable, Object rowKey) { treeTable.changeVariables(treeTable, ImmutableMap.of("focusParent", rowKey)); } }
@Test public void collapseNodeWithSelectedChildUnselectsChild() throws Exception { // GIVEN same initial state tree.setCollapsed(ROOT_0, false); treeView.select(Lists.newArrayList(ROOT_0, NODE_121)); // WHEN tree.setCollapsed(ROOT_0, true); // THEN assertThat(tree.isCollapsed(ROOT_0), is(true)); assertThat(tree.isSelected(ROOT_0), is(true)); assertThat(tree.isSelected(NODE_121), is(false)); }
@Override protected void paintRowIcon(PaintTarget target, Object[][] cells, int indexInRowbuffer) throws PaintException { // always paint if present (in parent only if row headers visible) if (getRowHeaderMode() == ROW_HEADER_MODE_HIDDEN) { Resource itemIcon = getItemIcon( cells[CELL_ITEMID][indexInRowbuffer]); if (itemIcon != null) { target.addAttribute("icon", itemIcon); } } else if (cells[CELL_ICON][indexInRowbuffer] != null) { target.addAttribute("icon", (Resource) cells[CELL_ICON][indexInRowbuffer]); } }
@Override public void setContainerDataSource(Container newDataSource) { super.setContainerDataSource(newDataSource); }
@Override public void paintContent(PaintTarget target) throws PaintException { if (beforePaintListener != null) { beforePaintListener.run(); } super.paintContent(target); }
@Override protected Element writeItem(Element tbody, Object itemId, DesignContext context) { Element tr = super.writeItem(tbody, itemId, context); DesignAttributeHandler.writeAttribute("collapsed", tr.attributes(), isCollapsed(itemId), true, boolean.class, context); return tr; }
@Override protected Object readItem(Element tr, Set<String> selected, DesignContext context) { Object itemId = super.readItem(tr, selected, context); if (tr.hasAttr("collapsed")) { boolean collapsed = DesignAttributeHandler .readAttribute("collapsed", tr.attributes(), boolean.class); setCollapsed(itemId, collapsed); } return itemId; }
@Test public void valueListenerDoesntPropagateNullInSelection() throws Exception { // GIVEN/WHEN // listener will be called 3 times: // 1. with ROOT_0 (but we don't care, it's just for producing 2.) // 2. via #focusParent, triggering the set containing null // 3. we select ROOT_0 again and expect single selection (not multiple with null + ROOT_O) produceTableValueContainingNull(tree); tree.select(ROOT_0); ArgumentCaptor<Set> itemsCaptor = ArgumentCaptor.forClass(Set.class); verify(listener, times(3)).onItemSelection(itemsCaptor.capture()); verifyNoMoreInteractions(listener); // THEN (2) Set<Object> items = itemsCaptor.getAllValues().get(1); assertThat(items, not(hasItem(nullValue()))); // THEN (3) items = itemsCaptor.getAllValues().get(2); assertThat(items, allOf(hasSize(1), contains(ROOT_0))); }
@Override protected boolean changeVariables(Map<String, Object> variables) { boolean clientNeedsContentRefresh = super.changeVariables(variables); if (variables.containsKey("resetsortorder")) { resetSortOrder(); markAsDirty(); } if (specificVariablesHandler != null) { clientNeedsContentRefresh = specificVariablesHandler.handleSpecificVariables(variables) || clientNeedsContentRefresh; } return clientNeedsContentRefresh; }
@Override public void setContainerDataSource(Container newDataSource, Collection<?> visibleIds) { super.setContainerDataSource(newDataSource, visibleIds); resetFilters(); }
@Override public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); /* Add filter components to UIDL */ target.startTag(FilterTableConnector.TAG_FILTERS); target.addAttribute(FilterTableConnector.ATTRIBUTE_FILTERS_VISIBLE, filtersVisible); target.addAttribute(FilterTableConnector.ATTRIBUTE_FORCE_RENDER, reRenderFilterFields); reRenderFilterFields = false; for (Object key : getColumnIdToFilterMap().keySet()) { /* Make sure parent is set properly */ if (columnIdToFilterMap.get(key) != null && columnIdToFilterMap.get(key).getParent() == null) { continue; } /* Paint the filter field */ target.startTag(FilterTableConnector.TAG_FILTER_COMPONENT + _columnIdMap.key(key)); target.addAttribute(FilterTableConnector.ATTRIBUTE_COLUMN_ID, _columnIdMap.key(key)); Component c = getColumnIdToFilterMap().get(key); LegacyPaint.paint(c, target); target.endTag(FilterTableConnector.TAG_FILTER_COMPONENT + _columnIdMap.key(key)); } target.endTag(FilterTableConnector.TAG_FILTERS); String[] headerStylenames = getColumnHeaderStylenamesForPaint(); if (headerStylenames != null) { target.addAttribute(FilterTableConnector.ATTRIBUTE_COLUMN_HEADER_STYLE_NAMES, headerStylenames); } }
@Test public void selectExpandsTreeToNodeButNotNodeItself() throws Exception { // GIVEN // initial state assertThat(tree.isCollapsed(ROOT_0), is(true)); assertThat(tree.isCollapsed(NODE_1), is(true)); assertThat(tree.isCollapsed(NODE_12), is(true)); assertThat(tree.isCollapsed(NODE_121), is(true)); // WHEN treeView.select(Lists.newArrayList(NODE_12)); // THEN assertThat(tree.isCollapsed(ROOT_0), is(false)); assertThat(tree.isCollapsed(NODE_1), is(false)); assertThat(tree.isCollapsed(NODE_12), is(true)); }
@Override public void changeVariables(Object source, Map<String, Object> variables) { super.changeVariables(source, variables); if (variables.containsKey("selectAll")) { boolean selectAll = (Boolean) variables.get("selectAll"); if (selectAll) { Collection<?> ids = getItemIds(); for (final Object id : ids) { select(id); } } else { setValue(null); } } if (variables.containsKey("toggleSelection")) { boolean selected = (Boolean) variables.get("toggleSelection"); String key = String.valueOf(variables.get("toggledRowId")); final Object id = itemIdMapper.get(key); if (selected) { select(id); } else { unselect(id); } } }