Browse Source

fixed lots of ComboBox bugs + cleaned the code

svn changeset:4054/svn branch:trunk
tags/6.7.0.beta1
Matti Tahvonen 16 years ago
parent
commit
a0b0979d06

+ 29
- 47
src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java View File

@@ -146,8 +146,9 @@ public class IFilterSelect extends Composite implements Paintable,
// nullsel not counted, as requested by user
DOM.setInnerText(status, (totalSuggestions == 0 ? 0 : first)
+ "-"
+ (nullSelectionAllowed && currentPage == 0 ? last - 1
: last) + "/" + matches);
+ ("".equals(lastFilter) && nullSelectionAllowed
&& currentPage == 0 ? last - 1 : last) + "/"
+ matches);
} else {
DOM.setInnerText(status, "");
}
@@ -200,8 +201,8 @@ public class IFilterSelect extends Composite implements Paintable,
.getText().length()
- lastFilter.length());

} else if (!clientSideFiltering && hasNextPage()) {
filterOptions(currentPage + 1);
} else if (hasNextPage()) {
filterOptions(currentPage + 1, lastFilter);
}
}

@@ -218,7 +219,7 @@ public class IFilterSelect extends Composite implements Paintable,
- lastFilter.length());
} else if (index == -1) {
if (currentPage > 0) {
filterOptions(currentPage - 1);
filterOptions(currentPage - 1, lastFilter);
}
} else {
final MenuItem newSelectedItem = (MenuItem) menu.getItems()
@@ -450,9 +451,6 @@ public class IFilterSelect extends Composite implements Paintable,

private FilterSelectSuggestion currentSuggestion;

private boolean clientSideFiltering;

private ArrayList allSuggestions;
private int totalMatches;
private boolean allowNewItem;
private boolean nullSelectionAllowed;
@@ -499,29 +497,19 @@ public class IFilterSelect extends Composite implements Paintable,
}
if (!filter.equals(lastFilter)) {
// we are on subsequent page and text has changed -> reset page
page = 0;
}
if (clientSideFiltering) {
currentSuggestions.clear();
for (final Iterator it = allSuggestions.iterator(); it.hasNext();) {
final FilterSelectSuggestion s = (FilterSelectSuggestion) it
.next();
final String string = s.getDisplayString().toLowerCase();
if (string.startsWith(filter.toLowerCase())) {
currentSuggestions.add(s);
}
if ("".equals(filter)) {
// let server decide
page = -1;
} else {
page = 0;
}
lastFilter = filter;
currentPage = page;
suggestionPopup.showSuggestions(currentSuggestions, page,
currentSuggestions.size());
} else {
filtering = true;
client.updateVariable(paintableId, "filter", filter, false);
client.updateVariable(paintableId, "page", page, true);
lastFilter = filter;
currentPage = page;
}

filtering = true;
client.updateVariable(paintableId, "filter", filter, false);
client.updateVariable(paintableId, "page", page, true);
lastFilter = filter;
currentPage = page;
}

public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
@@ -544,18 +532,14 @@ public class IFilterSelect extends Composite implements Paintable,

nullSelectionAllowed = uidl.hasAttribute("nullselect");

currentPage = uidl.getIntVariable("page");

if (uidl.hasAttribute(ATTR_EMPTYTEXT)) {
// "emptytext" changed from server
emptyText = uidl.getStringAttribute(ATTR_EMPTYTEXT);
}

if (true) {
suggestionPopup.setPagingEnabled(true);
clientSideFiltering = false;
} else {
suggestionPopup.setPagingEnabled(false);
clientSideFiltering = true;
}
suggestionPopup.setPagingEnabled(true);

allowNewItem = uidl.hasAttribute("allownewitem");

@@ -564,20 +548,16 @@ public class IFilterSelect extends Composite implements Paintable,
totalMatches = uidl.getIntAttribute("totalMatches");

String captions = emptyText;
if (clientSideFiltering) {
allSuggestions = new ArrayList();
}

for (final Iterator i = options.getChildIterator(); i.hasNext();) {
final UIDL optionUidl = (UIDL) i.next();
final FilterSelectSuggestion suggestion = new FilterSelectSuggestion(
optionUidl);
currentSuggestions.add(suggestion);
if (clientSideFiltering) {
allSuggestions.add(suggestion);
}
if (!filtering && optionUidl.hasAttribute("selected")) {
tb.setText(suggestion.getReplacementString());
if (optionUidl.hasAttribute("selected")) {
if (!filtering) {
tb.setText(suggestion.getReplacementString());
}
currentSuggestion = suggestion;
}

@@ -632,7 +612,7 @@ public class IFilterSelect extends Composite implements Paintable,
selectedOptionKey = newKey;
client.updateVariable(paintableId, "selected",
new String[] { selectedOptionKey }, immediate);
lastFilter = tb.getText();
// currentPage = -1; // forget the page
}
suggestionPopup.hide();
}
@@ -694,7 +674,8 @@ public class IFilterSelect extends Composite implements Paintable,
break;
} else {
// open popup as from gadget
filterOptions(0, "");
filterOptions(-1, "");
lastFilter = "";
tb.selectAll();
break;
}
@@ -714,7 +695,8 @@ public class IFilterSelect extends Composite implements Paintable,
// Popup's
// auto close feature
if (!suggestionPopup.isJustClosed()) {
filterOptions(0, "");
filterOptions(-1, "");
lastFilter = "";
}
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
tb.setFocus(true);

+ 39
- 31
src/com/itmill/toolkit/ui/Select.java View File

@@ -45,7 +45,7 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
private int columns = 0;

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

private int filteringMode = FILTERINGMODE_STARTSWITH;

@@ -144,6 +144,15 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {

target.startTag("options");

if (currentPage < 0) {
optionRequest = false;
currentPage = 0;
filterstring = "";
}

List options = getFilteredOptions();
options = sanitetizeList(options, needNullSelectOption);

final boolean paintNullSelection = needNullSelectOption
&& (currentPage == 0 && (filterstring == null || filterstring
.equals("")));
@@ -155,8 +164,6 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
target.endTag("so");
}

List options = getFilteredOptions();
options = sanitetizeList(options, needNullSelectOption);
final Iterator i = options.iterator();
// Paints the available selection options from data source

@@ -203,6 +210,8 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
target.addVariable(this, "filter", filterstring);
target.addVariable(this, "page", currentPage);

currentPage = -1; // current page is always set by client

optionRequest = true;
}

@@ -312,35 +321,12 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
* java.util.Map)
*/
public void changeVariables(Object source, Map variables) {
String newFilter;
if ((newFilter = (String) variables.get("filter")) != null) {
// this is a filter request
currentPage = ((Integer) variables.get("page")).intValue();
filterstring = newFilter;
if (filterstring != null) {
filterstring = filterstring.toLowerCase();
}
optionRepaint();
return;
}

// Try to set the property value

// New option entered (and it is allowed)
final String newitem = (String) variables.get("newitem");
if (newitem != null && newitem.length() > 0) {
getNewItemHandler().addNewItem(newitem);
// rebuild list
filterstring = null;
prevfilterstring = null;
}

// Selection change
if (variables.containsKey("selected")) {
final String[] ka = (String[]) variables.get("selected");

// Multiselect mode
if (isMultiSelect()) {
// Multiselect mode

// TODO Optimize by adding repaintNotNeeded whan applicaple

@@ -367,10 +353,8 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
newsel.addAll(s);
setValue(newsel, true);
}
}

// Single select mode
else {
} else {
// Single select mode
if (ka.length == 0) {

// Allows deselection only if the deselected item is visible
@@ -389,6 +373,30 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
}
}
}

String newFilter;
if ((newFilter = (String) variables.get("filter")) != null) {
// this is a filter request
currentPage = ((Integer) variables.get("page")).intValue();
filterstring = newFilter;
if (filterstring != null) {
filterstring = filterstring.toLowerCase();
}
optionRepaint();
return;
}

// Try to set the property value

// New option entered (and it is allowed)
final String newitem = (String) variables.get("newitem");
if (newitem != null && newitem.length() > 0) {
getNewItemHandler().addNewItem(newitem);
// rebuild list
filterstring = null;
prevfilterstring = null;
}

}

public void requestRepaint() {

Loading…
Cancel
Save