Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #281 from crevete/master
Browse files Browse the repository at this point in the history
Added method "getSelectedItem(s)" for standard and multiple select.
  • Loading branch information
crevete committed Feb 21, 2016
2 parents 7c68fa5 + 1fc23f1 commit 8bf6b2c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MultipleSelect() {
public final boolean isMultiple() {
return true;
}

/**
* When set to <code>true</code>, adds two buttons to the top of
* the drop-down menu (<b>Select All</b> & <b>Deselect All</b>).<br>
Expand Down Expand Up @@ -148,10 +148,10 @@ public List<String> getValue() {
}
return result;
}
return getAllSelectedValues();
return getSelectedValues();
}

private List<String> getAllSelectedValues() {
private List<String> getSelectedValues() {
final List<String> allSelected = new ArrayList<>(0);
for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
Option opt = entry.getValue();
Expand All @@ -178,6 +178,22 @@ protected void setSelectedValue(List<String> value) {
}
}

/**
* Returns the selected items list. If no item is selected, this method
* returns an empty list.
*
* @return the selected items list
*/
public List<Option> getSelectedItems() {
final List<Option> items = new ArrayList<>(0);
for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
Option opt = entry.getValue();
if (opt.isSelected())
items.add(opt);
}
return items;
}

/**
* Select all items in a multi-select.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ protected void setSelectedValue(String value) {
}
}

/**
* Returns the selected item or <code>null</code> if no item is selected.
*
* @return the selected items list
*/
public Option getSelectedItem() {
for (Entry<OptionElement, Option> entry : itemMap.entrySet()) {
Option opt = entry.getValue();
if (opt.isSelected())
return opt;
}
return null;
}

private native String getValue(Element e) /*-{
return $wnd.jQuery(e).selectpicker('val');
}-*/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,6 @@ public void setShowMenuArrow(final boolean showMenuArrow) {
}
}

// public boolean isShowMenuArrow() {
// return StyleHelper.containsStyle(getStyleName(), SelectStyles.SHOW_MENU_ARROW);
// }

@Override
public LeafValueEditor<T> asEditor() {
if (editor == null) {
Expand Down Expand Up @@ -655,11 +651,11 @@ public int getItemCount() {
}

/**
* Returns the selected item list.
* Returns the item list.
*
* @return the selected item list
* @return the item list
*/
public List<Option> getSelectedItems() {
public List<Option> getItems() {
List<Option> selectedItems = new ArrayList<>(0);
NodeList<OptionElement> items = selectElement.getOptions();
for (int i = 0; i < items.getLength(); i++) {
Expand Down

0 comments on commit 8bf6b2c

Please sign in to comment.