From d4af8b07d51a1e7b1b4eaa828be596b780afd34f Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 18 Feb 2013 12:57:29 +0200 Subject: Count instances instead of windows and also show the counter Change-Id: Ida1d0c9424d09169f3c7f76ebf70dcced5742dad --- .../vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java index ecca98b884..48ccd217ca 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java @@ -18,6 +18,7 @@ package com.vaadin.tests.minitutorials.v7a1; import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.CssLayout; import com.vaadin.ui.TextField; import com.vaadin.ui.UI; @@ -31,13 +32,12 @@ import com.vaadin.ui.UI; */ @PreserveOnRefresh public class CreatingPreserveState extends UI { - private static int windowCounter = 0; + private static int instanceCounter = 0; @Override public void init(VaadinRequest request) { - TextField tf = new TextField("Window #" + (++windowCounter)); + TextField tf = new TextField("Instance #" + (++instanceCounter)); tf.setImmediate(true); - setContent(tf); + setContent(new CssLayout(tf)); } - } -- cgit v1.2.3 From 41e1a013d829f75c0bdadea40ec0b42429e2a581 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Thu, 14 Feb 2013 15:41:45 +0200 Subject: Interim fix for resizing of child component in AbsoluteLayout when child is 100% and layout resized (no-merge) #10427 Change-Id: I497ecc1ac88ef1b3c07d127aff3c157827088e01 --- .../src/com/vaadin/client/ui/VAbsoluteLayout.java | 11 ++++-- .../absolutelayout/AbsoluteLayoutResizing.html | 37 ++++++++++++++++++ .../absolutelayout/AbsoluteLayoutResizing.java | 44 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.html create mode 100644 uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VAbsoluteLayout.java b/client/src/com/vaadin/client/ui/VAbsoluteLayout.java index 92a51f209d..88fbae6e88 100644 --- a/client/src/com/vaadin/client/ui/VAbsoluteLayout.java +++ b/client/src/com/vaadin/client/ui/VAbsoluteLayout.java @@ -326,6 +326,10 @@ public class VAbsoluteLayout extends ComplexPanel { Style wrapperStyle = wrapper.getElement().getStyle(); Style widgetStyle = wrapper.getWidget().getElement().getStyle(); + + // Ensure previous heights do not affect the measures + wrapperStyle.clearHeight(); + if (widgetStyle.getHeight() != null && widgetStyle.getHeight().endsWith("%")) { int h; @@ -343,8 +347,6 @@ public class VAbsoluteLayout extends ComplexPanel { - wrapper.getElement().getOffsetTop(); } wrapperStyle.setHeight(h, Unit.PX); - } else { - wrapperStyle.clearHeight(); } wrapper.updateCaptionPosition(); @@ -380,6 +382,9 @@ public class VAbsoluteLayout extends ComplexPanel { Style wrapperStyle = wrapper.getElement().getStyle(); Style widgetStyle = wrapper.getWidget().getElement().getStyle(); + // Ensure previous heights do not affect the measures + wrapperStyle.clearWidth(); + if (widgetStyle.getWidth() != null && widgetStyle.getWidth().endsWith("%")) { int w; @@ -398,8 +403,6 @@ public class VAbsoluteLayout extends ComplexPanel { - wrapper.getElement().getOffsetLeft(); } wrapperStyle.setWidth(w, Unit.PX); - } else { - wrapperStyle.clearWidth(); } wrapper.updateCaptionPosition(); diff --git a/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.html b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.html new file mode 100644 index 0000000000..01206b317c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.html @@ -0,0 +1,37 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.absolutelayout.AbsoluteLayoutResizing?restartApplication
dragAndDropvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutResizing::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSplitPanelVertical[0]/domChild[0]/domChild[1]/domChild[0]0,294
dragAndDropvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutResizing::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSplitPanelVertical[0]/VSplitPanelHorizontal[0]/domChild[0]/domChild[1]/domChild[0]588,0
screenCaptureresized
+ + diff --git a/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.java b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.java new file mode 100644 index 0000000000..810a583ba5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutResizing.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.absolutelayout; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.AbsoluteLayout; +import com.vaadin.ui.HorizontalSplitPanel; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.VerticalSplitPanel; + +public class AbsoluteLayoutResizing extends TestBase { + + @Override + protected void setup() { + getLayout().setSizeFull(); + + AbsoluteLayout al = new AbsoluteLayout(); + + TextArea ta = new TextArea(); + ta.setValue("When resizing the layout this text area should also get resized"); + ta.setSizeFull(); + al.addComponent(ta, "left: 10px; right: 10px; top: 10px; bottom: 10px;"); + + HorizontalSplitPanel horizPanel = new HorizontalSplitPanel(); + horizPanel.setSizeFull(); + horizPanel.setFirstComponent(al); + + VerticalSplitPanel vertPanel = new VerticalSplitPanel(); + vertPanel.setSizeFull(); + vertPanel.setFirstComponent(horizPanel); + + addComponent(vertPanel); + + } + + @Override + protected String getDescription() { + return "Absolute layout should correctly dynamically resize itself"; + } + + @Override + protected Integer getTicketNumber() { + return 10427; + } + +} -- cgit v1.2.3 From 6949cd8109db726b92e80cffb3286c67ec7abb47 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Fri, 8 Feb 2013 17:20:04 +0200 Subject: Merge of second part of (#10513) to Vaadin 7. Fix for TreeTable's indent handling & width calculations. Conflicts: client/src/com/vaadin/client/ui/table/TableConnector.java Change-Id: I94f0d84ac978045d3b79be6b3726ea6973d30b35 --- client/src/com/vaadin/client/ui/VScrollTable.java | 508 ++++++++++++++++++--- client/src/com/vaadin/client/ui/VTreeTable.java | 38 +- .../com/vaadin/client/ui/table/TableConnector.java | 1 + .../TreeTableExtraScrollBarWithChildren.html | 69 +++ .../TreeTableExtraScrollbarWithChildren.java | 92 ++++ 5 files changed, 626 insertions(+), 82 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollBarWithChildren.html create mode 100644 uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbarWithChildren.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 75d67b82d6..c76dd38d8f 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -1191,6 +1191,39 @@ public class VScrollTable extends FlowPanel implements HasWidgets, return totalRows; } + /** + * Returns the extra space that is given to the header column when column + * width is determined by header text. + * + * @return extra space in pixels + */ + private int getHeaderPadding() { + return scrollBody.getCellExtraWidth(); + } + + /** + * This method exists for the needs of {@link VTreeTable} only. Not part of + * the official API, extend at your own risk. May be removed or + * replaced in the future. + * + * @return index of TreeTable's hierarchy column, or -1 if not applicable + */ + protected int getHierarchyColumnIndex() { + return -1; + } + + /** + * For internal use only. May be removed or replaced in the future. + */ + public void updateMaxIndent() { + int oldIndent = scrollBody.getMaxIndent(); + scrollBody.calculateMaxIndent(); + if (oldIndent != scrollBody.getMaxIndent()) { + // indent updated, headers might need adjusting + triggerLazyColumnAdjustment(true); + } + } + /** For internal use only. May be removed or replaced in the future. */ public void focusRowFromBody() { if (selectedRowKeys.size() == 1) { @@ -1382,6 +1415,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * amount of rows in data set */ public void updateBody(UIDL uidl, int firstRow, int reqRows) { + int oldIndent = scrollBody.getMaxIndent(); if (uidl == null || reqRows < 1) { // container is empty, remove possibly existing rows if (firstRow <= 0) { @@ -1399,6 +1433,11 @@ public class VScrollTable extends FlowPanel implements HasWidgets, scrollBody.renderRows(uidl, firstRow, reqRows); discardRowsOutsideCacheWindow(); + scrollBody.calculateMaxIndent(); + if (oldIndent != scrollBody.getMaxIndent()) { + // indent updated, headers might need adjusting + headerChangedDuringUpdate = true; + } } /** For internal use only. May be removed or replaced in the future. */ @@ -1591,31 +1630,55 @@ public class VScrollTable extends FlowPanel implements HasWidgets, return tHead.getHeaderCell(index).getColKey(); } - private void setColWidth(int colIndex, int w, boolean isDefinedWidth) { + /** + * Note: not part of the official API, extend at your own risk. May be + * removed or replaced in the future. + * + * Sets the indicated column's width for headers and scrollBody alike. + * + * @param colIndex + * index of the modified column + * @param w + * new width (may be subject to modifications if doesn't meet + * minimum requirements) + * @param isDefinedWidth + * disables expand ratio if set true + */ + protected void setColWidth(int colIndex, int w, boolean isDefinedWidth) { final HeaderCell hcell = tHead.getHeaderCell(colIndex); // Make sure that the column grows to accommodate the sort indicator if // necessary. - if (w < hcell.getMinWidth()) { - w = hcell.getMinWidth(); + // get min width with no indent or padding + int minWidth = hcell.getMinWidth(false, false); + if (w < minWidth) { + w = minWidth; } - // Set header column width + // Set header column width WITHOUT INDENT hcell.setWidth(w, isDefinedWidth); + // Set footer column width likewise + FooterCell fcell = tFoot.getFooterCell(colIndex); + fcell.setWidth(w, isDefinedWidth); + // Ensure indicators have been taken into account tHead.resizeCaptionContainer(hcell); + // Make sure that the body column grows to accommodate the indent if + // necessary. + // get min width with indent, no padding + minWidth = hcell.getMinWidth(true, false); + if (w < minWidth) { + w = minWidth; + } + // Set body column width scrollBody.setColWidth(colIndex, w); - - // Set footer column width - FooterCell fcell = tFoot.getFooterCell(colIndex); - fcell.setWidth(w, isDefinedWidth); } private int getColWidth(String colKey) { - return tHead.getHeaderCell(colKey).getWidth(); + return tHead.getHeaderCell(colKey).getWidthWithIndent(); } /** @@ -1813,22 +1876,37 @@ public class VScrollTable extends FlowPanel implements HasWidgets, tHead.enableBrowserIntelligence(); tFoot.enableBrowserIntelligence(); + int hierarchyColumnIndent = scrollBody != null ? scrollBody + .getMaxIndent() : 0; + HeaderCell hierarchyHeaderWithExpandRatio = null; + // first loop: collect natural widths while (headCells.hasNext()) { final HeaderCell hCell = (HeaderCell) headCells.next(); final FooterCell fCell = (FooterCell) footCells.next(); + boolean needsIndent = hierarchyColumnIndent > 0 + && hCell.isHierarchyColumn(); int w = hCell.getWidth(); if (hCell.isDefinedWidth()) { // server has defined column width explicitly + if (needsIndent && w < hierarchyColumnIndent) { + // hierarchy indent overrides explicitly set width + w = hierarchyColumnIndent; + } totalExplicitColumnsWidths += w; } else { if (hCell.getExpandRatio() > 0) { expandRatioDivider += hCell.getExpandRatio(); w = 0; + if (needsIndent && w < hierarchyColumnIndent) { + hierarchyHeaderWithExpandRatio = hCell; + // don't add to widths here, because will be included in + // the expand ratio space if there's enough of it + } } else { // get and store greater of header width and column width, - // and - // store it as a minimumn natural col width + // and store it as a minimum natural column width (these + // already contain the indent if any) int headerWidth = hCell.getNaturalColumnWidth(i); int footerWidth = fCell.getNaturalColumnWidth(i); w = headerWidth > footerWidth ? headerWidth : footerWidth; @@ -1840,6 +1918,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, total += w; i++; } + if (hierarchyHeaderWithExpandRatio != null) { + total += hierarchyColumnIndent; + } tHead.disableBrowserIntelligence(); tFoot.disableBrowserIntelligence(); @@ -1871,13 +1952,24 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (availW > total) { // natural size is smaller than available space - final int extraSpace = availW - total; + int extraSpace = availW - total; + if (hierarchyHeaderWithExpandRatio != null) { + /* + * add the indent's space back to ensure each column gets an + * even share according to the expand ratios (note: if the + * allocated space isn't enough for the hierarchy column it + * shall be treated like a defined width column and the indent + * space gets removed from the extra space again) + */ + extraSpace += hierarchyColumnIndent; + } final int totalWidthR = total - totalExplicitColumnsWidths; int checksum = 0; if (extraSpace == 1) { // We cannot divide one single pixel so we give it the first // undefined column + // no need to worry about indent here headCells = tHead.iterator(); i = 0; checksum = availW; @@ -1891,6 +1983,22 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } } else if (expandRatioDivider > 0) { + boolean setIndentToHierarchyHeader = false; + if (hierarchyHeaderWithExpandRatio != null) { + // ensure first that the hierarchyColumn gets at least the + // space allocated for indent + final int newSpace = Math + .round((extraSpace * (hierarchyHeaderWithExpandRatio + .getExpandRatio() / expandRatioDivider))); + if (newSpace < hierarchyColumnIndent) { + // not enough space for indent, remove indent from the + // extraSpace again and handle hierarchy column's header + // separately + setIndentToHierarchyHeader = true; + extraSpace -= hierarchyColumnIndent; + } + } + // visible columns have some active expand ratios, excess // space is divided according to them headCells = tHead.iterator(); @@ -1899,9 +2007,17 @@ public class VScrollTable extends FlowPanel implements HasWidgets, HeaderCell hCell = (HeaderCell) headCells.next(); if (hCell.getExpandRatio() > 0) { int w = widths[i]; - final int newSpace = Math.round((extraSpace * (hCell - .getExpandRatio() / expandRatioDivider))); - w += newSpace; + if (setIndentToHierarchyHeader + && hierarchyHeaderWithExpandRatio.equals(hCell)) { + // hierarchy column's header is no longer part of + // the expansion divide and only gets indent + w += hierarchyColumnIndent; + } else { + final int newSpace = Math + .round((extraSpace * (hCell + .getExpandRatio() / expandRatioDivider))); + w += newSpace; + } widths[i] = w; } checksum += widths[i]; @@ -1911,6 +2027,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // no expand ratios defined, we will share extra space // relatively to "natural widths" among those without // explicit width + // no need to worry about indent here, it's already included headCells = tHead.iterator(); i = 0; while (headCells.hasNext()) { @@ -1946,7 +2063,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } } else { - // bodys size will be more than available and scrollbar will appear + // body's size will be more than available and scrollbar will appear } // last loop: set possibly modified values or reset if new tBody @@ -2046,8 +2163,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } /** - * Note, this method is not official api although declared as protected. - * Extend at you own risk. + * Note: this method is not part of official API although declared as + * protected. Extend at your own risk. * * @return true if content area will have scrollbars visible. */ @@ -2430,6 +2547,16 @@ public class VScrollTable extends FlowPanel implements HasWidgets, expandRatio = 0; } + /** + * Sets width to the header cell. This width should not include any + * possible indent modifications that are present in + * {@link VScrollTableBody#getMaxIndent()}. + * + * @param w + * required width of the cell sans indentations + * @param ensureDefinedWidth + * disables expand ratio if required + */ public void setWidth(int w, boolean ensureDefinedWidth) { if (ensureDefinedWidth) { definedWidth = true; @@ -2453,15 +2580,23 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * unless TD width is not explicitly set. */ if (scrollBody != null) { - int tdWidth = width + scrollBody.getCellExtraWidth(); + int maxIndent = scrollBody.getMaxIndent(); + if (w < maxIndent && isHierarchyColumn()) { + w = maxIndent; + } + int tdWidth = w + scrollBody.getCellExtraWidth(); setWidth(tdWidth + "px"); } else { Scheduler.get().scheduleDeferred(new Command() { @Override public void execute() { - int tdWidth = width - + scrollBody.getCellExtraWidth(); + int maxIndent = scrollBody.getMaxIndent(); + int tdWidth = width; + if (tdWidth < maxIndent && isHierarchyColumn()) { + tdWidth = maxIndent; + } + tdWidth += scrollBody.getCellExtraWidth(); setWidth(tdWidth + "px"); } }); @@ -2484,10 +2619,45 @@ public class VScrollTable extends FlowPanel implements HasWidgets, return definedWidth && width >= 0; } + /** + * This method exists for the needs of {@link VTreeTable} only. + * + * Returns the pixels width of the header cell. This includes the + * indent, if applicable. + * + * @return The width in pixels + */ + protected int getWidthWithIndent() { + if (scrollBody != null && isHierarchyColumn()) { + int maxIndent = scrollBody.getMaxIndent(); + if (maxIndent > width) { + return maxIndent; + } + } + return width; + } + + /** + * Returns the pixels width of the header cell. + * + * @return The width in pixels + */ public int getWidth() { return width; } + /** + * This method exists for the needs of {@link VTreeTable} only. + * + * @return true if this is hierarcyColumn's header cell, + * false otherwise + */ + private boolean isHierarchyColumn() { + int hierarchyColumnIndex = getHierarchyColumnIndex(); + return hierarchyColumnIndex >= 0 + && tHead.visibleCells.indexOf(this) == hierarchyColumnIndex; + } + public void setText(String headerText) { DOM.setInnerHTML(captionContainer, headerText); } @@ -2742,7 +2912,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, DOM.setCapture(getElement()); dragStartX = DOM.eventGetClientX(event); colIndex = getColIndexByKey(cid); - originalWidth = getWidth(); + originalWidth = getWidthWithIndent(); DOM.eventPreventDefault(event); break; case Event.ONMOUSEUP: @@ -2774,8 +2944,11 @@ public class VScrollTable extends FlowPanel implements HasWidgets, tHead.disableAutoColumnWidthCalculation(this); int newWidth = originalWidth + deltaX; - if (newWidth < getMinWidth()) { - newWidth = getMinWidth(); + // get min width with indent, no padding + int minWidth = getMinWidth(true, false); + if (newWidth < minWidth) { + // already includes indent if any + newWidth = minWidth; } setColWidth(colIndex, newWidth, true); triggerLazyColumnAdjustment(false); @@ -2787,12 +2960,37 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } } - public int getMinWidth() { - int cellExtraWidth = 0; + /** + * Returns the smallest possible cell width in pixels. + * + * @param includeIndent + * - width should include hierarchy column indent if + * applicable (VTreeTable only) + * @param includeCellExtraWidth + * - width should include paddings etc. + * @return + */ + private int getMinWidth(boolean includeIndent, + boolean includeCellExtraWidth) { + int minWidth = sortIndicator.getOffsetWidth(); if (scrollBody != null) { - cellExtraWidth += scrollBody.getCellExtraWidth(); + // check the need for indent before adding paddings etc. + if (includeIndent && isHierarchyColumn()) { + int maxIndent = scrollBody.getMaxIndent(); + if (minWidth < maxIndent) { + minWidth = maxIndent; + } + } + if (includeCellExtraWidth) { + minWidth += scrollBody.getCellExtraWidth(); + } } - return cellExtraWidth + sortIndicator.getOffsetWidth(); + return minWidth; + } + + public int getMinWidth() { + // get min width with padding, no indent + return getMinWidth(false, true); } public String getCaption() { @@ -2823,16 +3021,20 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * @return */ public int getNaturalColumnWidth(int columnIndex) { + final int iw = columnIndex == getHierarchyColumnIndex() ? scrollBody + .getMaxIndent() : 0; if (isDefinedWidth()) { + if (iw > width) { + return iw; + } return width; } else { if (naturalWidth < 0) { // This is recently revealed column. Try to detect a proper - // value (greater of header and data - // cols) + // value (greater of header and data columns) int hw = captionContainer.getOffsetWidth() - + scrollBody.getCellExtraWidth(); + + getHeaderPadding(); if (BrowserInfo.get().isGecko()) { hw += sortIndicator.getOffsetWidth(); } @@ -2848,7 +3050,13 @@ public class VScrollTable extends FlowPanel implements HasWidgets, final int cw = scrollBody.getColWidth(columnIndex); naturalWidth = (hw > cw ? hw : cw); } - return naturalWidth; + if (iw > naturalWidth) { + // indent is temporary value, naturalWidth shouldn't be + // updated + return iw; + } else { + return naturalWidth; + } } } @@ -2945,32 +3153,49 @@ public class VScrollTable extends FlowPanel implements HasWidgets, public void resizeCaptionContainer(HeaderCell cell) { HeaderCell lastcell = getHeaderCell(visibleCells.size() - 1); + int columnSelectorOffset = columnSelector.getOffsetWidth(); - // Measure column widths - int columnTotalWidth = 0; - for (Widget w : visibleCells) { - columnTotalWidth += w.getOffsetWidth(); - } - - if (cell == lastcell - && columnSelector.getOffsetWidth() > 0 - && columnTotalWidth >= div.getOffsetWidth() - - columnSelector.getOffsetWidth() + if (cell == lastcell && columnSelectorOffset > 0 && !hasVerticalScrollbar()) { - // Ensure column caption is visible when placed under the column - // selector widget by shifting and resizing the caption. - int offset = 0; - int diff = div.getOffsetWidth() - columnTotalWidth; - if (diff < columnSelector.getOffsetWidth() && diff > 0) { - // If the difference is less than the column selectors width - // then just offset by the - // difference - offset = columnSelector.getOffsetWidth() - diff; + + // Measure column widths + int columnTotalWidth = 0; + for (Widget w : visibleCells) { + int cellExtraWidth = w.getOffsetWidth(); + if (scrollBody != null + && visibleCells.indexOf(w) == getHierarchyColumnIndex() + && cellExtraWidth < scrollBody.getMaxIndent()) { + // indent must be taken into consideration even if it + // hasn't been applied yet + columnTotalWidth += scrollBody.getMaxIndent(); + } else { + columnTotalWidth += cellExtraWidth; + } + } + + int divOffset = div.getOffsetWidth(); + if (columnTotalWidth >= divOffset - columnSelectorOffset) { + /* + * Ensure column caption is visible when placed under the + * column selector widget by shifting and resizing the + * caption. + */ + int offset = 0; + int diff = divOffset - columnTotalWidth; + if (diff < columnSelectorOffset && diff > 0) { + /* + * If the difference is less than the column selectors + * width then just offset by the difference + */ + offset = columnSelectorOffset - diff; + } else { + // Else offset by the whole column selector + offset = columnSelectorOffset; + } + lastcell.resizeCaptionContainer(offset); } else { - // Else offset by the whole column selector - offset = columnSelector.getOffsetWidth(); + cell.resizeCaptionContainer(0); } - lastcell.resizeCaptionContainer(offset); } else { cell.resizeCaptionContainer(0); } @@ -3033,10 +3258,14 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // Make sure to accomodate for the sort indicator if // necessary. int width = Integer.parseInt(widthStr); - if (width < c.getMinWidth()) { - width = c.getMinWidth(); + int widthWithoutAddedIndent = width; + + // get min width with indent, no padding + int minWidth = c.getMinWidth(true, false); + if (width < minWidth) { + width = minWidth; } - if (width != c.getWidth() && scrollBody != null) { + if (scrollBody != null && width != c.getWidthWithIndent()) { // Do a more thorough update if a column is resized from // the server *after* the header has been properly // initialized @@ -3052,7 +3281,13 @@ public class VScrollTable extends FlowPanel implements HasWidgets, }); refreshContentWidths = true; } else { - c.setWidth(width, true); + // get min width with no indent or padding + minWidth = c.getMinWidth(false, false); + if (widthWithoutAddedIndent < minWidth) { + widthWithoutAddedIndent = minWidth; + } + // save min width without indent + c.setWidth(widthWithoutAddedIndent, true); } } else if (recalcWidths) { c.setUndefinedWidth(); @@ -3507,12 +3742,14 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } /** - * Sets the width of the cell + * Sets the width of the cell. This width should not include any + * possible indent modifications that are present in + * {@link VScrollTableBody#getMaxIndent()}. * * @param w * The width of the cell * @param ensureDefinedWidth - * Ensures the the given width is not recalculated + * Ensures that the given width is not recalculated */ public void setWidth(int w, boolean ensureDefinedWidth) { @@ -3549,7 +3786,13 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * unless TD width is not explicitly set. */ if (scrollBody != null) { - int tdWidth = width + scrollBody.getCellExtraWidth() + int maxIndent = scrollBody.getMaxIndent(); + if (w < maxIndent + && tFoot.visibleCells.indexOf(this) == getHierarchyColumnIndex()) { + // ensure there's room for the indent + w = maxIndent; + } + int tdWidth = w + scrollBody.getCellExtraWidth() - borderWidths; setWidth(Math.max(tdWidth, 0) + "px"); } else { @@ -3557,8 +3800,14 @@ public class VScrollTable extends FlowPanel implements HasWidgets, @Override public void execute() { - int tdWidth = width - + scrollBody.getCellExtraWidth() + int tdWidth = width; + int maxIndent = scrollBody.getMaxIndent(); + if (tdWidth < maxIndent + && tFoot.visibleCells.indexOf(this) == getHierarchyColumnIndex()) { + // ensure there's room for the indent + tdWidth = maxIndent; + } + tdWidth += scrollBody.getCellExtraWidth() - borderWidths; setWidth(Math.max(tdWidth, 0) + "px"); } @@ -3571,6 +3820,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * Sets the width to undefined */ public void setUndefinedWidth() { + definedWidth = false; setWidth(-1, false); } @@ -3585,7 +3835,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } /** - * Returns the pixels width of the footer cell + * Returns the pixels width of the footer cell. * * @return The width in pixels */ @@ -3699,7 +3949,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * @return */ public int getNaturalColumnWidth(int columnIndex) { + final int iw = columnIndex == getHierarchyColumnIndex() ? scrollBody + .getMaxIndent() : 0; if (isDefinedWidth()) { + if (iw > width) { + return iw; + } return width; } else { if (naturalWidth < 0) { @@ -3708,7 +3963,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // cols) final int hw = ((Element) getElement().getLastChild()) - .getOffsetWidth() + scrollBody.getCellExtraWidth(); + .getOffsetWidth() + getHeaderPadding(); if (columnIndex < 0) { columnIndex = 0; for (Iterator it = tHead.iterator(); it @@ -3721,7 +3976,11 @@ public class VScrollTable extends FlowPanel implements HasWidgets, final int cw = scrollBody.getColWidth(columnIndex); naturalWidth = (hw > cw ? hw : cw); } - return naturalWidth; + if (iw > naturalWidth) { + return iw; + } else { + return naturalWidth; + } } } @@ -4627,6 +4886,28 @@ public class VScrollTable extends FlowPanel implements HasWidgets, return cellExtraWidth; } + /** + * This method exists for the needs of {@link VTreeTable} only. May be + * removed or replaced in the future.

Returns the maximum + * indent of the hierarcyColumn, if applicable. + * + * @see {@link VScrollTable#getHierarchyColumnIndex()} + * + * @return maximum indent in pixels + */ + protected int getMaxIndent() { + return 0; + } + + /** + * This method exists for the needs of {@link VTreeTable} only. May be + * removed or replaced in the future.

Calculates the maximum + * indent of the hierarcyColumn, if applicable. + */ + protected void calculateMaxIndent() { + // NOP + } + private void detectExtrawidth() { NodeList rows = tBodyElement.getRows(); if (rows.getLength() == 0) { @@ -4806,8 +5087,23 @@ public class VScrollTable extends FlowPanel implements HasWidgets, protected void setCellWidth(int cellIx, int width) { final Element cell = DOM.getChild(getElement(), cellIx); - cell.getFirstChildElement().getStyle() - .setPropertyPx("width", width); + Style wrapperStyle = cell.getFirstChildElement().getStyle(); + int wrapperWidth = width; + if (BrowserInfo.get().isWebkit() + || BrowserInfo.get().isOpera10()) { + /* + * Some versions of Webkit and Opera ignore the width + * definition of zero width table cells. Instead, use 1px + * and compensate with a negative margin. + */ + if (width == 0) { + wrapperWidth = 1; + wrapperStyle.setMarginRight(-1, Unit.PX); + } else { + wrapperStyle.clearMarginRight(); + } + } + wrapperStyle.setPropertyPx("width", wrapperWidth); cell.getStyle().setPropertyPx("width", width); } @@ -5866,7 +6162,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, @Override public void execute() { if (showRowHeaders) { - setCellWidth(0, tHead.getHeaderCell(0).getWidth()); + setCellWidth(0, tHead.getHeaderCell(0) + .getWidthWithIndent()); calcAndSetSpanWidthOnCell(1); } else { calcAndSetSpanWidthOnCell(0); @@ -6100,14 +6397,35 @@ public class VScrollTable extends FlowPanel implements HasWidgets, int totalExplicitColumnsWidths = 0; float expandRatioDivider = 0; int colIndex = 0; + + int hierarchyColumnIndent = scrollBody.getMaxIndent(); + int hierarchyColumnIndex = getHierarchyColumnIndex(); + HeaderCell hierarchyHeaderInNeedOfFurtherHandling = null; + while (headCells.hasNext()) { final HeaderCell hCell = (HeaderCell) headCells.next(); + boolean hasIndent = hierarchyColumnIndent > 0 + && hCell.isHierarchyColumn(); if (hCell.isDefinedWidth()) { - totalExplicitColumnsWidths += hCell.getWidth(); - usedMinimumWidth += hCell.getWidth(); + // get width without indent to find out whether adjustments + // are needed (requires special handling further ahead) + int w = hCell.getWidth(); + if (hasIndent && w < hierarchyColumnIndent) { + // enforce indent if necessary + w = hierarchyColumnIndent; + hierarchyHeaderInNeedOfFurtherHandling = hCell; + } + totalExplicitColumnsWidths += w; + usedMinimumWidth += w; } else { - usedMinimumWidth += hCell.getNaturalColumnWidth(colIndex); + // natural width already includes indent if any + int naturalColumnWidth = hCell + .getNaturalColumnWidth(colIndex); + usedMinimumWidth += naturalColumnWidth; expandRatioDivider += hCell.getExpandRatio(); + if (hasIndent) { + hierarchyHeaderInNeedOfFurtherHandling = hCell; + } } colIndex++; } @@ -6152,6 +6470,28 @@ public class VScrollTable extends FlowPanel implements HasWidgets, int totalUndefinedNaturalWidths = usedMinimumWidth - totalExplicitColumnsWidths; + if (hierarchyHeaderInNeedOfFurtherHandling != null + && !hierarchyHeaderInNeedOfFurtherHandling.isDefinedWidth()) { + // ensure the cell gets enough space for the indent + int w = hierarchyHeaderInNeedOfFurtherHandling + .getNaturalColumnWidth(hierarchyColumnIndex); + int newSpace = Math.round(w + (float) extraSpace * (float) w + / totalUndefinedNaturalWidths); + if (newSpace >= hierarchyColumnIndent) { + // no special handling required + hierarchyHeaderInNeedOfFurtherHandling = null; + } else { + // treat as a defined width column of indent's width + totalExplicitColumnsWidths += hierarchyColumnIndent; + usedMinimumWidth -= w - hierarchyColumnIndent; + totalUndefinedNaturalWidths = usedMinimumWidth + - totalExplicitColumnsWidths; + expandRatioDivider += hierarchyHeaderInNeedOfFurtherHandling + .getExpandRatio(); + extraSpace = Math.max(availW - usedMinimumWidth, 0); + } + } + // we have some space that can be divided optimally HeaderCell hCell; colIndex = 0; @@ -6167,7 +6507,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets, newSpace = Math.round((w + extraSpace * hCell.getExpandRatio() / expandRatioDivider)); } else { - if (totalUndefinedNaturalWidths != 0) { + if (hierarchyHeaderInNeedOfFurtherHandling == hCell) { + // still exists, so needs exactly the indent's width + newSpace = hierarchyColumnIndent; + } else if (totalUndefinedNaturalWidths != 0) { // divide relatively to natural column widths newSpace = Math.round(w + (float) extraSpace * (float) w / totalUndefinedNaturalWidths); @@ -6177,8 +6520,21 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } checksum += newSpace; setColWidth(colIndex, newSpace, false); + } else { - checksum += hCell.getWidth(); + if (hierarchyHeaderInNeedOfFurtherHandling == hCell) { + // defined with enforced into indent width + checksum += hierarchyColumnIndent; + setColWidth(colIndex, hierarchyColumnIndent, false); + } else { + int cellWidth = hCell.getWidthWithIndent(); + checksum += cellWidth; + if (hCell.isHierarchyColumn()) { + // update in case the indent has changed + // (not detectable earlier) + setColWidth(colIndex, cellWidth, true); + } + } } colIndex++; } @@ -6194,8 +6550,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, while (headCells.hasNext()) { HeaderCell hc = (HeaderCell) headCells.next(); if (!hc.isDefinedWidth()) { - setColWidth(colIndex, - hc.getWidth() + availW - checksum, false); + setColWidth(colIndex, hc.getWidthWithIndent() + availW + - checksum, false); break; } colIndex++; diff --git a/client/src/com/vaadin/client/ui/VTreeTable.java b/client/src/com/vaadin/client/ui/VTreeTable.java index f65198865c..097b9c7ab2 100644 --- a/client/src/com/vaadin/client/ui/VTreeTable.java +++ b/client/src/com/vaadin/client/ui/VTreeTable.java @@ -122,8 +122,14 @@ public class VTreeTable extends VScrollTable { } } + @Override + protected int getHierarchyColumnIndex() { + return colIndexOfHierarchy + (showRowHeaders ? 1 : 0); + } + public class VTreeTableScrollBody extends VScrollTable.VScrollTableBody { private int indentWidth = -1; + private int maxIndent = 0; VTreeTableScrollBody() { super(); @@ -232,6 +238,11 @@ public class VTreeTable extends VScrollTable { treeSpacer.getParentElement().getStyle() .setPaddingLeft(getIndent(), Unit.PX); treeSpacer.getStyle().setWidth(getIndent(), Unit.PX); + int colWidth = getColWidth(getHierarchyColumnIndex()); + if (colWidth > 0 && getIndent() > colWidth) { + VTreeTable.this.setColWidth(getHierarchyColumnIndex(), + getIndent(), false); + } } } @@ -277,16 +288,12 @@ public class VTreeTable extends VScrollTable { // hierarchy column int indent = getIndent(); if (indent != -1) { - width = Math.max(width - getIndent(), 0); + width = Math.max(width - indent, 0); } } super.setCellWidth(cellIx, width); } - private int getHierarchyColumnIndex() { - return colIndexOfHierarchy + (showRowHeaders ? 1 : 0); - } - private int getIndent() { return (depth + 1) * getIndentWidth(); } @@ -323,7 +330,8 @@ public class VTreeTable extends VScrollTable { @Override public void execute() { if (showRowHeaders) { - setCellWidth(0, tHead.getHeaderCell(0).getWidth()); + setCellWidth(0, tHead.getHeaderCell(0) + .getWidthWithIndent()); calcAndSetSpanWidthOnCell(1); } else { calcAndSetSpanWidthOnCell(0); @@ -421,6 +429,22 @@ public class VTreeTable extends VScrollTable { return indentWidth; } + @Override + protected int getMaxIndent() { + return maxIndent; + } + + @Override + protected void calculateMaxIndent() { + int maxIndent = 0; + Iterator iterator = iterator(); + while (iterator.hasNext()) { + VTreeTableRow next = (VTreeTableRow) iterator.next(); + maxIndent = Math.max(maxIndent, next.getIndent()); + } + this.maxIndent = maxIndent; + } + private void detectIndent(VTreeTableRow vTreeTableRow) { indentWidth = vTreeTableRow.treeSpacer.getOffsetWidth(); if (indentWidth == 0) { @@ -432,6 +456,7 @@ public class VTreeTable extends VScrollTable { VTreeTableRow next = (VTreeTableRow) iterator.next(); next.setIndent(); } + calculateMaxIndent(); } protected void unlinkRowsAnimatedAndUpdateCacheWhenFinished( @@ -471,6 +496,7 @@ public class VTreeTable extends VScrollTable { RowExpandAnimation anim = new RowExpandAnimation(insertedRows); anim.run(150); } + scrollBody.calculateMaxIndent(); return insertedRows; } diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index c967642059..fc31cdf8ea 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -176,6 +176,7 @@ public class TableConnector extends AbstractHasComponentsConnector implements // amount of rows) getWidget().scrollBody.setLastRendered(getWidget().scrollBody .getLastRendered()); + getWidget().updateMaxIndent(); } else { getWidget().postponeSanityCheckForLastRendered = false; UIDL rowData = uidl.getChildByTagName("rows"); diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollBarWithChildren.html b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollBarWithChildren.html new file mode 100644 index 0000000000..611e7a5994 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollBarWithChildren.html @@ -0,0 +1,69 @@ + + + + + + +TreeTableExtraScrollbar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TreeTableExtraScrollbar
open/run/com.vaadin.tests.components.treetable.TreeTableExtraScrollbarWithChildren?restartApplication
mouseClickbutton
pause300
screenCaptureexpanded
mouseClickbutton
pause300
screenCapturecollapsed
open/run/com.vaadin.tests.components.treetable.TreeTableExtraScrollbarWithChildren
pause300
screenCapturerefreshed
+ + diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbarWithChildren.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbarWithChildren.java new file mode 100644 index 0000000000..cad33e242f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbarWithChildren.java @@ -0,0 +1,92 @@ +package com.vaadin.tests.components.treetable; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Table; +import com.vaadin.ui.TreeTable; + +public class TreeTableExtraScrollbarWithChildren extends TestBase { + + @Override + protected String getDescription() { + return "Arrow calculation should not cause a horizontal scrollbar" + + " if there is enough space for the final contents."; + } + + @Override + protected Integer getTicketNumber() { + return 10513; + } + + @Override + protected void setup() { + HorizontalLayout layout = new HorizontalLayout(); + layout.setWidth("300px"); + layout.setHeight("300px"); + + final TreeTable table = new TreeTable(); + table.setSizeFull(); + + table.addGeneratedColumn("parameterId", new HierarchyColumnGenerator()); + table.addGeneratedColumn("wordingTextId", new TypeColumnGenerator()); + table.addGeneratedColumn("parameterTypeId", new TypeColumnGenerator()); + + table.setColumnWidth("parameterId", 26); + + table.addItem(new TestObject("name 1", "value 1")); + table.addItem(new TestObject("name 2", "value 2")); + table.addItem(new TestObject("name 3", "value 3")); + table.addItem(new TestObject("name 4", "value 4")); + table.addItem(new TestObject("name 5", "value 5")); + final TestObject parent = new TestObject("name 6", "value 6"); + table.addItem(parent); + table.setFooterVisible(true); + for (int i = 1; i <= 10; ++i) { + TestObject child = new TestObject("name 6-" + i, "value 6-" + i); + table.addItem(child); + table.setParent(child, parent); + } + table.setVisibleColumns(new Object[] { "wordingTextId", "parameterId", + "parameterTypeId" }); + table.setColumnHeaders(new String[] { "", "", "" }); + table.setHierarchyColumn("parameterId"); + + layout.addComponent(table); + + Button button = new Button("Toggle"); + button.setId("button"); + button.addClickListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + table.setCollapsed(parent, !table.isCollapsed(parent)); + Notification.show("collapsed: " + table.isCollapsed(parent)); + } + }); + + addComponent(layout); + addComponent(button); + } + + private class HierarchyColumnGenerator implements Table.ColumnGenerator { + public Object generateCell(Table table, Object itemId, Object columnId) { + Label label = new Label("this should be mostly hidden"); + label.setSizeUndefined(); + return label; + } + } + + private class TypeColumnGenerator implements Table.ColumnGenerator { + public Object generateCell(Table table, Object itemId, Object columnId) { + if (itemId instanceof TestObject) { + return new Label(((TestObject) itemId).getValue()); + } + return null; + } + } + +} -- cgit v1.2.3 From c4a0bc318ec9c6b41d652e7020ee39784cc1eb10 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Mon, 11 Feb 2013 17:04:15 +0200 Subject: Properly pass the AbstractField internal value to shared state in Slider and ProgressIndicator (#10921) * In case of a null value, 0 is stored to shared state. This is consistent with how CheckBox is already implemented. * This somewhat hacky solution should be replaced with a better one once AbstractField itself is migrated. See #11064. Change-Id: I2b313af8491a6deccdc7a509dcd1b718482cdcd4 --- server/src/com/vaadin/ui/CheckBox.java | 7 +++ server/src/com/vaadin/ui/ProgressIndicator.java | 15 ++++++ server/src/com/vaadin/ui/Slider.java | 16 ++++++ .../slider/SliderValueFromDataSource.html | 32 ++++++++++++ .../slider/SliderValueFromDataSource.java | 59 ++++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html create mode 100644 uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java (limited to 'uitest/src/com') diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 22b90b224f..0ace0a4f26 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -110,6 +110,13 @@ public class CheckBox extends AbstractField { return (CheckBoxState) super.getState(); } + /* + * Overridden to keep the shared state in sync with the AbstractField + * internal value. Should be removed once AbstractField is refactored to use + * shared state. + * + * See tickets #10921 and #11064. + */ @Override protected void setInternalValue(Boolean newValue) { super.setInternalValue(newValue); diff --git a/server/src/com/vaadin/ui/ProgressIndicator.java b/server/src/com/vaadin/ui/ProgressIndicator.java index 96c2d2814a..c481aa1e8f 100644 --- a/server/src/com/vaadin/ui/ProgressIndicator.java +++ b/server/src/com/vaadin/ui/ProgressIndicator.java @@ -157,4 +157,19 @@ public class ProgressIndicator extends AbstractField implements return getState().pollingInterval; } + /* + * Overridden to keep the shared state in sync with the AbstractField + * internal value. Should be removed once AbstractField is refactored to use + * shared state. + * + * See tickets #10921 and #11064. + */ + @Override + protected void setInternalValue(Float newValue) { + super.setInternalValue(newValue); + if (newValue == null) { + newValue = 0.0f; + } + getState().state = newValue; + } } diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java index 2bf05f895c..e63fdc5e10 100644 --- a/server/src/com/vaadin/ui/Slider.java +++ b/server/src/com/vaadin/ui/Slider.java @@ -263,6 +263,22 @@ public class Slider extends AbstractField { getState().value = newFieldValue; } + /* + * Overridden to keep the shared state in sync with the AbstractField + * internal value. Should be removed once AbstractField is refactored to use + * shared state. + * + * See tickets #10921 and #11064. + */ + @Override + protected void setInternalValue(Double newValue) { + super.setInternalValue(newValue); + if (newValue == null) { + newValue = 0.0; + } + getState().value = newValue; + } + /** * Thrown when the value of the slider is about to be set to a value that is * outside the valid range of the slider. diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html new file mode 100644 index 0000000000..8b5a7067e4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html @@ -0,0 +1,32 @@ + + + + + + +SliderValueFromDataSource + + + + + + + + + + + + + + + + + + + + + + +
SliderValueFromDataSource
open/run/SliderValueFromDataSource?restartApplication
assertAttributevaadin=runSliderValueFromDataSource::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VProgressIndicator[0]/domChild[0]/domChild[0]@styleregex:.*(width|WIDTH): 50%.*
assertAttributevaadin=runSliderValueFromDataSource::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]@styleregex:.*(margin-left|MARGIN-LEFT): 94px.*
+ + diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java new file mode 100644 index 0000000000..141dc5baf4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.slider; + +import com.vaadin.data.Item; +import com.vaadin.data.util.BeanItem; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ProgressIndicator; +import com.vaadin.ui.Slider; + +public class SliderValueFromDataSource extends AbstractTestUI { + + public static class TestBean { + + private double doubleValue = 10.0; + private float floatValue = 0.5f; + + public double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(double doubleValue) { + this.doubleValue = doubleValue; + } + + public float getFloatValue() { + return floatValue; + } + + public void setFloatValue(float floatValue) { + this.floatValue = floatValue; + } + } + + @Override + protected void setup(VaadinRequest request) { + Item item = new BeanItem(new TestBean()); + + Slider slider = new Slider(0, 20); + slider.setWidth("200px"); + slider.setPropertyDataSource(item.getItemProperty("doubleValue")); + addComponent(slider); + + ProgressIndicator pi = new ProgressIndicator(); + pi.setPollingInterval(60 * 1000); + pi.setWidth("200px"); + pi.setPropertyDataSource(item.getItemProperty("floatValue")); + addComponent(pi); + } + + @Override + protected String getTestDescription() { + return "Slider and ProgressIndicator do not properly pass a value from data source to the client"; + } + + @Override + protected Integer getTicketNumber() { + return 10921; + } +} -- cgit v1.2.3 From 9af9a2d1e6dcd6546d181deb6f4537d6d2a4f595 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 18 Feb 2013 19:38:28 +0200 Subject: Fixed NPE when TextField value is null (#11021) Ticket: 11021 Change-Id: If3b99333a116e6191ba3f563738e456a07173ab4 --- .../client/ui/textfield/TextFieldConnector.java | 6 ++- .../TextFieldWithDataSourceAndInputPrompt.html | 31 +++++++++++ .../TextFieldWithDataSourceAndInputPrompt.java | 63 ++++++++++++++++++++++ 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.html create mode 100644 uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java index 922e8d4a32..e2ede121b6 100644 --- a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java +++ b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java @@ -77,8 +77,10 @@ public class TextFieldConnector extends AbstractFieldConnector implements } getWidget().setColumns(getState().columns); - final String text = getState().text; - + String text = getState().text; + if (text == null) { + text = ""; + } /* * We skip the text content update if field has been repainted, but text * has not been changed. Additional sanity check verifies there is no diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.html b/uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.html new file mode 100644 index 0000000000..cf08d8923d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.html @@ -0,0 +1,31 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.textfield.TextFieldWithDataSourceAndInputPrompt?restartApplication
assertValuevaadin=runcomvaadintestscomponentstextfieldTextFieldWithDataSourceAndInputPrompt::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VTextField[0]Me is input prompt
assertValuevaadin=runcomvaadintestscomponentstextfieldTextFieldWithDataSourceAndInputPrompt::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VTextField[0]Me is input prompt
+ + diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.java b/uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.java new file mode 100644 index 0000000000..881aa11fbb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldWithDataSourceAndInputPrompt.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.textfield; + +import com.vaadin.data.util.BeanItem; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.TextField; + +public class TextFieldWithDataSourceAndInputPrompt extends AbstractTestUI { + public static class Pojo { + private String string; + + public String getString() { + return string; + } + + public void setString(String string) { + this.string = string; + } + } + + @Override + protected void setup(VaadinRequest request) { + TextField textField = new TextField("TextField with null value"); + textField.setInputPrompt("Me is input prompt"); + textField.setNullRepresentation(null); + textField.setValue(null); + addComponent(textField); + + TextField textField2 = new TextField( + "TextField with null data source value"); + textField2.setInputPrompt("Me is input prompt"); + textField2.setNullRepresentation(null); + BeanItem beanItem = new BeanItem(new Pojo()); + textField2.setPropertyDataSource(beanItem.getItemProperty("string")); + addComponent(textField2); + } + + @Override + protected String getTestDescription() { + return "Input prompt should be shown when data source provides null"; + } + + @Override + protected Integer getTicketNumber() { + return 11021; + } + +} -- cgit v1.2.3 From 9da1979af798324cbe1eea2b6adde0886774f73b Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 19 Feb 2013 11:04:55 +0200 Subject: Properly detach old connectors for repaintAll response (#11067) Change-Id: I6491a9b30ea4c0e4ff141497b9bd78e5d1c4c98c --- .../com/vaadin/client/ApplicationConnection.java | 36 ++++++++++++++++--- .../tests/debug/HierarchyAfterAnalyzeLayouts.html | 37 ++++++++++++++++++++ .../tests/debug/HierarchyAfterAnalyzeLayouts.java | 40 ++++++++++++++++++++++ 3 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.html create mode 100644 uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 3157bd0685..8ecc90bdd5 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -1395,15 +1395,12 @@ public class ApplicationConnection { Profiler.leave("Handling locales"); Profiler.enter("Handling meta information"); - boolean repaintAll = false; ValueMap meta = null; if (json.containsKey("meta")) { VConsole.log(" * Handling meta information"); meta = json.getValueMap("meta"); if (meta.containsKey("repaintAll")) { - repaintAll = true; - uIConnector.getWidget().clear(); - getConnectorMap().clear(); + prepareRepaintAll(); if (meta.containsKey("invalidLayouts")) { validatingLayouts = true; } @@ -1532,6 +1529,37 @@ public class ApplicationConnection { } + /** + * Properly clean up any old stuff to ensure everything is properly + * reinitialized. + */ + private void prepareRepaintAll() { + String uiConnectorId = uIConnector.getConnectorId(); + if (uiConnectorId == null) { + // Nothing to clear yet + return; + } + + // Create fake server response that says that the uiConnector + // has no children + JSONObject fakeHierarchy = new JSONObject(); + fakeHierarchy.put(uiConnectorId, new JSONArray()); + JSONObject fakeJson = new JSONObject(); + fakeJson.put("hierarchy", fakeHierarchy); + ValueMap fakeValueMap = fakeJson.getJavaScriptObject().cast(); + + // Update hierarchy based on the fake response + ConnectorHierarchyUpdateResult connectorHierarchyUpdateResult = updateConnectorHierarchy(fakeValueMap); + + // Send hierarchy events based on the fake update + sendHierarchyChangeEvents(connectorHierarchyUpdateResult.events); + + // Unregister all the old connectors that have now been removed + unregisterRemovedConnectors(); + + getLayoutManager().cleanMeasuredSizes(); + } + private void updateCaptions( Collection pendingStateChangeEvents, Collection parentChanged) { diff --git a/uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.html b/uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.html new file mode 100644 index 0000000000..03d8f34651 --- /dev/null +++ b/uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.html @@ -0,0 +1,37 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.debug.HierarchyAfterAnalyzeLayouts?restartApplication&debug
mouseClickvaadin=runcomvaadintestsdebugHierarchyAfterAnalyzeLayouts::Root/VDebugConsole[0]/FlowPanel[0]/HorizontalPanel[0]/domChild[0]/domChild[0]/domChild[3]/domChild[0]18,9
assertTextPresentLayouts analyzed on server, total top level problems: 0
assertElementPresentvaadin=runcomvaadintestsdebugHierarchyAfterAnalyzeLayouts::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]
+ + diff --git a/uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.java b/uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.java new file mode 100644 index 0000000000..6f55e050c0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/debug/HierarchyAfterAnalyzeLayouts.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.debug; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; + +public class HierarchyAfterAnalyzeLayouts extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent(new Label("This is a label")); + } + + @Override + protected String getTestDescription() { + return "The connector hierarchy should be in order after clicking AL in the debug console"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(11067); + } + +} -- cgit v1.2.3 From 2788b5192330a8ac8169571b592be33972c3b016 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Wed, 20 Feb 2013 09:44:43 +0200 Subject: Merge of (#9940) to Vaadin 7 Change-Id: Ie2e53c8cdba20c8265fa04e35e9469b39b21d43e --- client/src/com/vaadin/client/ui/VTextField.java | 15 +++---- .../TextFieldMaxLengthRemovedFromDOM.html | 51 ++++++++++++++++++++++ .../TextFieldMaxLengthRemovedFromDOM.java | 37 ++++++++++++++++ 3 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html create mode 100644 uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java (limited to 'uitest/src/com') diff --git a/client/src/com/vaadin/client/ui/VTextField.java b/client/src/com/vaadin/client/ui/VTextField.java index 1229eda093..0fbed0dd90 100644 --- a/client/src/com/vaadin/client/ui/VTextField.java +++ b/client/src/com/vaadin/client/ui/VTextField.java @@ -272,19 +272,16 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, /** For internal use only. May be removed or replaced in the future. */ public void setMaxLength(int newMaxLength) { - if (newMaxLength >= 0 && newMaxLength != maxLength) { - maxLength = newMaxLength; - updateMaxLength(maxLength); - } else if (maxLength != -1) { - maxLength = -1; - updateMaxLength(maxLength); + if (newMaxLength == maxLength) { + return; } - + maxLength = newMaxLength; + updateMaxLength(maxLength); } /** - * This method is reponsible for updating the DOM or otherwise ensuring that - * the given max length is enforced. Called when the max length for the + * This method is responsible for updating the DOM or otherwise ensuring + * that the given max length is enforced. Called when the max length for the * field has changed. * * @param maxLength diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html new file mode 100644 index 0000000000..45c7e0f2c8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html @@ -0,0 +1,51 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.textfield.TextFieldMaxLengthRemovedFromDOM?restartApplication
assertAttributevaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]@maxlength11
mouseClickvaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]118,13
assertAttributevaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]@maxlength11
typevaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]hello
mouseClickvaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/domChild[0]/domChild[1]172,60
assertAttributevaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTextField[0]@maxlength11
+ + diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java new file mode 100644 index 0000000000..61993de107 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.components.textfield; + +import com.vaadin.event.FieldEvents; +import com.vaadin.event.FieldEvents.FocusEvent; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.TextField; + +public class TextFieldMaxLengthRemovedFromDOM extends TestBase { + + @Override + protected void setup() { + final TextField tf = new TextField(); + tf.setMaxLength(11); + tf.setRequired(true); + tf.setImmediate(true); + addComponent(tf); + + tf.addListener(new FieldEvents.FocusListener() { + + public void focus(FocusEvent event) { + // Resetting Max length should not remove maxlength attribute + tf.setMaxLength(11); + } + }); + } + + @Override + protected String getDescription() { + return "Maxlength attribute should not dissappear from the DOM when I focus the text field."; + } + + @Override + protected Integer getTicketNumber() { + return 9940; + } + +} -- cgit v1.2.3 From 092edcce873b5c88790025c95777909c2445b076 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Wed, 20 Feb 2013 12:43:22 +0200 Subject: Updated merged 6.8 test to work with 7.0 Change-Id: I5e44183af9431ba34fb0ecaa353e6b65c2aaeace --- .../tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html | 2 +- .../tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html index 45c7e0f2c8..3086b66dfa 100644 --- a/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.html @@ -38,7 +38,7 @@ mouseClick - vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/domChild[0]/domChild[1] + vaadin=runcomvaadintestscomponentstextfieldTextFieldMaxLengthRemovedFromDOM::/VVerticalLayout[0]/domChild[0] 172,60 diff --git a/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java index 61993de107..28ff20c174 100644 --- a/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java +++ b/uitest/src/com/vaadin/tests/components/textfield/TextFieldMaxLengthRemovedFromDOM.java @@ -15,7 +15,7 @@ public class TextFieldMaxLengthRemovedFromDOM extends TestBase { tf.setImmediate(true); addComponent(tf); - tf.addListener(new FieldEvents.FocusListener() { + tf.addFocusListener(new FieldEvents.FocusListener() { public void focus(FocusEvent event) { // Resetting Max length should not remove maxlength attribute -- cgit v1.2.3