Browse Source

Move ComboBox pageLength to state (#19929)

Use shared state for the page length and update related tests.
This change also removes an unused widget field.

Change-Id: Id8719661121a9570be40028da09e32f27bec82b5
feature/eventbus
Henri Sara 8 years ago
parent
commit
12e0a20d6f

+ 0
- 3
client/src/main/java/com/vaadin/client/ui/VFilterSelect.java View File

/** For internal use only. May be removed or replaced in the future. */ /** For internal use only. May be removed or replaced in the future. */
public ComboBoxConnector connector; public ComboBoxConnector connector;


/** For internal use only. May be removed or replaced in the future. */
public String paintableId;

/** For internal use only. May be removed or replaced in the future. */ /** For internal use only. May be removed or replaced in the future. */
public int currentPage; public int currentPage;



+ 2
- 3
client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java View File

getWidget().inputPrompt = ""; getWidget().inputPrompt = "";
} }


getWidget().pageLength = getState().pageLength;

Profiler.leave("ComboBoxConnector.onStateChanged update content"); Profiler.leave("ComboBoxConnector.onStateChanged update content");
} }


*/ */
@Override @Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// Save details
getWidget().paintableId = uidl.getId();

if (!isRealUpdate(uidl)) { if (!isRealUpdate(uidl)) {
return; return;
} }

+ 9
- 22
server/src/main/java/com/vaadin/ui/ComboBox.java View File

} }
}; };


/**
* Holds value of property pageLength. 0 disables paging.
*/
protected int pageLength = 10;

// Current page when the user is 'paging' trough options // Current page when the user is 'paging' trough options
private int currentPage = -1; private int currentPage = -1;


// clear caption change listeners // clear caption change listeners
getCaptionChangeListener().clear(); getCaptionChangeListener().clear();


// The tab ordering number
if (getTabIndex() != 0) {
target.addAttribute("tabindex", getTabIndex());
}

// If the field is modified, but not committed, set modified // If the field is modified, but not committed, set modified
// attribute // attribute
if (isModified()) { if (isModified()) {
String[] selectedKeys = new String[(getValue() == null String[] selectedKeys = new String[(getValue() == null
&& getNullSelectionItemId() == null ? 0 : 1)]; && getNullSelectionItemId() == null ? 0 : 1)];


target.addAttribute("pagelength", pageLength);

if (suggestionPopupWidth != null) { if (suggestionPopupWidth != null) {
target.addAttribute("suggestionPopupWidth", target.addAttribute("suggestionPopupWidth",
suggestionPopupWidth); suggestionPopupWidth);
protected List<?> getOptionsWithFilter(boolean needNullSelectOption) { protected List<?> getOptionsWithFilter(boolean needNullSelectOption) {
Container container = getContainerDataSource(); Container container = getContainerDataSource();


if (pageLength == 0 && !isFilteringNeeded()) {
if (getPageLength() == 0 && !isFilteringNeeded()) {
// no paging or filtering: return all items // no paging or filtering: return all items
filteredSize = container.size(); filteredSize = container.size();
assert filteredSize >= 0; assert filteredSize >= 0;
*/ */
private List<?> sanitetizeList(List<?> options, boolean needNullSelectOption) { private List<?> sanitetizeList(List<?> options, boolean needNullSelectOption) {


if (pageLength != 0 && options.size() > pageLength) {
if (getPageLength() != 0 && options.size() > getPageLength()) {


int indexToEnsureInView = -1; int indexToEnsureInView = -1;


int size) { int size) {
// Not all options are visible, find out which ones are on the // Not all options are visible, find out which ones are on the
// current "page". // current "page".
int first = currentPage * pageLength;
int first = currentPage * getPageLength();
if (needNullSelectOption && currentPage > 0) { if (needNullSelectOption && currentPage > 0) {
first--; first--;
} }
private int getLastItemIndexOnCurrentPage(boolean needNullSelectOption, private int getLastItemIndexOnCurrentPage(boolean needNullSelectOption,
int size, int first) { int size, int first) {
// page length usable for non-null items // page length usable for non-null items
int effectivePageLength = pageLength
int effectivePageLength = getPageLength()
- (needNullSelectOption && (currentPage == 0) ? 1 : 0); - (needNullSelectOption && (currentPage == 0) ? 1 : 0);
return Math.min(size - 1, first + effectivePageLength - 1); return Math.min(size - 1, first + effectivePageLength - 1);
} }
int indexToEnsureInView, int size) { int indexToEnsureInView, int size) {
if (indexToEnsureInView != -1) { if (indexToEnsureInView != -1) {
int newPage = (indexToEnsureInView + (needNullSelectOption ? 1 : 0)) int newPage = (indexToEnsureInView + (needNullSelectOption ? 1 : 0))
/ pageLength;
/ getPageLength();
page = newPage; page = newPage;
} }
// adjust the current page if beyond the end of the list // adjust the current page if beyond the end of the list
if (page * pageLength > size) {
page = (size + (needNullSelectOption ? 1 : 0)) / pageLength;
if (page * getPageLength() > size) {
page = (size + (needNullSelectOption ? 1 : 0)) / getPageLength();
} }
return page; return page;
} }
* @return the pageLength * @return the pageLength
*/ */
public int getPageLength() { public int getPageLength() {
return pageLength;
return getState(false).pageLength;
} }


/** /**
* the pageLength to set * the pageLength to set
*/ */
public void setPageLength(int pageLength) { public void setPageLength(int pageLength) {
this.pageLength = pageLength;
markAsDirty();
getState().pageLength = pageLength;
} }


/** /**

+ 4
- 0
shared/src/main/java/com/vaadin/shared/ui/combobox/ComboBoxState.java View File

*/ */
public String inputPrompt = null; public String inputPrompt = null;


/**
* Number of items to show per page or 0 to disable paging.
*/
public int pageLength = 10;
} }

+ 1
- 1
uitest/src/main/java/com/vaadin/tests/components/combobox/Comboboxes.java View File

public class PageLength0ComboBox extends ComboBox { public class PageLength0ComboBox extends ComboBox {
public PageLength0ComboBox() { public PageLength0ComboBox() {
super(); super();
pageLength = 0;
setPageLength(0);
} }
} }



+ 1
- 1
uitest/src/main/java/com/vaadin/tests/layouts/MovingComponentsWhileOldParentInvisible.java View File



ComboBox componentContainerSelect = new ComboBox("Container") { ComboBox componentContainerSelect = new ComboBox("Container") {
{ {
pageLength = 0;
setPageLength(0);
} }
}; };
componentContainerSelect.setId("componentContainerSelect"); componentContainerSelect.setId("componentContainerSelect");

Loading…
Cancel
Save