Skip to content

Commit

Permalink
Merge pull request #339 from eclipse/bugfix/Issue330-DualList_should_…
Browse files Browse the repository at this point in the history
…respect_the_initial_last_selection_value

Issue #330 - DualList should respect the initial "last selection" value
  • Loading branch information
lcaron authored Jun 9, 2021
2 parents dd9eed5 + 999e6fa commit 41e3604
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ private static List<DLItem> createItems(final Shell shell) {
list.add(new DLItem("Denmark"));
list.add(new DLItem("Estonia"));
list.add(new DLItem("Finland"));
list.add(new DLItem("France"));
list.add(new DLItem("France").setSelected(true));
list.add(new DLItem("Germany"));
list.add(new DLItem("Greece"));
list.add(new DLItem("Hungary"));
list.add(new DLItem("Hungary").setSelected(true));
list.add(new DLItem("Ireland"));
list.add(new DLItem("Italy"));
list.add(new DLItem("Latvia"));
list.add(new DLItem("Lithuania"));
list.add(new DLItem("Lithuania").setSelected(true));
list.add(new DLItem("Luxembourg"));
list.add(new DLItem("Malta"));
list.add(new DLItem("Netherlands"));
list.add(new DLItem("Poland"));
list.add(new DLItem("Poland").setSelected(true));
list.add(new DLItem("Portugal"));
list.add(new DLItem("Romania"));
list.add(new DLItem("Slovakia"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,21 @@ public LAST_ACTION getLastAction() {

/**
* @param lastAction the last action performed on this DLItem
* @return
*/
public void setLastAction(final LAST_ACTION lastAction) {
public DLItem setLastAction(final LAST_ACTION lastAction) {
this.lastAction = lastAction;
return this;
}

/**
* Change the selection state of this item
*
* @param selection
* @return
*/
public DLItem setSelected(boolean selection) {
this.lastAction = selection ? LAST_ACTION.SELECTION : LAST_ACTION.DESELECTION;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1432,15 +1432,24 @@ public void setItems(final List<DLItem> items) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}

final List<DLItem> temp = new ArrayList<DLItem>();
final List<DLItem> unselectedItems = new ArrayList<DLItem>();
final List<DLItem> selectedItems = new ArrayList<DLItem>();
for (final DLItem item : items) {
if (item == null) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
temp.add(item);
if (item.getLastAction() == LAST_ACTION.SELECTION) {
selectedItems.add(item);
} else {
unselectedItems.add(item);
}
}
this.items.clear();
this.items.addAll(temp);
this.items.addAll(unselectedItems);

this.selection.clear();
this.selection.addAll(selectedItems);

redrawTables();
}

Expand Down

0 comments on commit 41e3604

Please sign in to comment.