Browse Source

Select: null selections without nullselectionItemId

svn changeset:2655/svn branch:trunk
tags/6.7.0.beta1
Matti Tahvonen 16 years ago
parent
commit
44601df882

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

@@ -125,7 +125,6 @@ public class IFilterSelect extends Composite implements Paintable,
setPrevButtonActive(first > 1);
setNextButtonActive(last < totalSuggestions);
setPopupPositionAndShow(this);

}

private void setNextButtonActive(boolean b) {
@@ -274,7 +273,7 @@ public class IFilterSelect extends Composite implements Paintable,

private static final String CLASSNAME = "i-filterselect";

public static final int PAGELENTH = 15;
public static final int PAGELENTH = 10;

private final FlowPanel panel = new FlowPanel();

@@ -311,6 +310,7 @@ public class IFilterSelect extends Composite implements Paintable,
private ArrayList allSuggestions;
private int totalMatches;
private boolean allowNewItem;
private boolean nullSelectionAllowed;

public IFilterSelect() {
selectedItemIcon.setVisible(false);
@@ -376,10 +376,9 @@ public class IFilterSelect extends Composite implements Paintable,
if (client.updateComponent(this, uidl, true))
return;

if (uidl.hasAttribute("immediate"))
immediate = true;
else
immediate = false;
immediate = uidl.hasAttribute("immediate");
nullSelectionAllowed = uidl.hasAttribute("nullselect");

if (true) {
this.suggestionPopup.setPagingEnabled(true);
@@ -447,7 +446,14 @@ public class IFilterSelect extends Composite implements Paintable,

public void onSuggestionSelected(FilterSelectSuggestion suggestion) {
currentSuggestion = suggestion;
String newKey = String.valueOf(suggestion.getOptionKey());
String newKey;
if(suggestion.key.equals("")) {
// "nullselection"
newKey = "";
} else {
// normal selection
newKey = String.valueOf(suggestion.getOptionKey());
}
tb.setText(suggestion.getReplacementString());
setSelectedItemIcon(suggestion.getIconUri());
if (!newKey.equals(selectedOptionKey)) {

+ 27
- 4
src/com/itmill/toolkit/ui/Select.java View File

@@ -65,7 +65,7 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
/**
* Holds value of property pageLength. 0 disables paging.
*/
protected int pageLength = 15;
protected int pageLength = 10;

// current page when the user is 'paging' trough options
private int currentPage;
@@ -132,8 +132,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
if (isNewItemsAllowed()) {
target.addAttribute("allownewitem", true);
}

boolean needNullSelectOption = false;
if (isNullSelectionAllowed()) {
target.addAttribute("nullselect", true);
needNullSelectOption = getNullSelectionItemId() == null;
}

// Constructs selected keys array
@@ -173,10 +176,29 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
* target.addAttribute("totalMatches", this.optionFilter
* .getMatchCount()); } else { i = getItemIds().iterator(); }
*/
target.startTag("options");

boolean paintNullSelection = needNullSelectOption
&& (currentPage == 0 && (filterstring == null
|| filterstring.equals("") || filterstring.equals("-")));

if (paintNullSelection) {
target.startTag("so");
target.addAttribute("caption", "-");
target.addAttribute("key", "");
target.endTag("so");
}

List options = getFilteredOptions();
if (options.size() > this.pageLength) {
int first = this.currentPage * this.pageLength;
int last = first + this.pageLength;
if(needNullSelectOption) {
if(currentPage > 0) {
first--;
}
last--;
}
if (options.size() < last) {
last = options.size();
}
@@ -185,7 +207,6 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
Iterator i = options.iterator();
// Paints the available selection options from data source

target.startTag("options");
while (i.hasNext()) {

// Gets the option attribute values
@@ -212,9 +233,11 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering {
}
target.endTag("options");

target.addAttribute("totalitems", size());
target.addAttribute("totalitems", size()
+ (needNullSelectOption ? 1 : 0));
if (this.filteredOptions != null) {
target.addAttribute("totalMatches", this.filteredOptions.size());
target.addAttribute("totalMatches", this.filteredOptions.size()
+ (needNullSelectOption ? 1 : 0));
}

// Paint variables

Loading…
Cancel
Save