r2734 - trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean
Author: tchemit Date: 2013-10-04 09:07:21 +0200 (Fri, 04 Oct 2013) New Revision: 2734 Url: http://nuiton.org/projects/jaxx/repository/revisions/2734 Log: fixes #2867: [BeanComboBox] Add methods to add and remove multiple items (improve performance) Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBoxHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBox.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBoxHandler.java Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx 2013-10-02 23:23:38 UTC (rev 2733) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBox.jaxx 2013-10-04 07:07:21 UTC (rev 2734) @@ -120,8 +120,12 @@ public void addItem(O item) { handler.addItem(item); } +public void addItems(Iterable<O> items) { handler.addItems(items); } + public void removeItem(O item) { handler.removeItem(item); } +public void removeItems(Iterable<O> items) { handler.removeItems(items); } + ]]> </script> <row> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBoxHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBoxHandler.java 2013-10-02 23:23:38 UTC (rev 2733) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanComboBoxHandler.java 2013-10-04 07:07:21 UTC (rev 2734) @@ -48,6 +48,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.Method; +import java.util.Collections; import java.util.List; /** @@ -202,7 +203,7 @@ /** * @return {@code true} if there is no data in comboBox, - * {@code false} otherwise. + * {@code false} otherwise. * @since 2.5.9 */ public boolean isEmpty() { @@ -211,57 +212,99 @@ } /** - * Add the given item into the comboBox. + * Add the given items into the comboBox. * <p/> * <strong>Note:</strong> The item will be inserted at his correct following * the selected ordering. * - * @param item item to add in comboBox. - * @since 2.5.9 + * @param items items to add in comboBox. + * @since 2.5.28 */ - public void addItem(O item) { + public void addItems(Iterable<O> items) { List<O> data = ui.getData(); + boolean wasEmpty = CollectionUtils.isEmpty(data); - data.add(item); + for (O item : items) { + data.add(item); + } + updateUI(ui.getIndex(), ui.isReverseSort()); fireEmpty(wasEmpty); } /** - * Remove the given item from the comboBox model. + * Remove the given items from the comboBox model. * <p/> - * <strong>Note:</strong> If this item was selected, then selection will - * be cleared. + * <strong>Note:</strong> If this item was selected, then selection will be + * cleared. * - * @param item the item to remove from the comboBox model - * @since 2.5.9 + * @param items items to remove from the comboBox model + * @since 2.5.28 */ - public void removeItem(O item) { + public void removeItems(Iterable<O> items) { List<O> data = ui.getData(); - boolean remove = data.remove(item); + boolean needUpdate = false; + for (O item : items) { + boolean remove = data.remove(item); - if (remove) { + if (remove) { - // item was found in data + // item was found in data - Object selectedItem = ui.getSelectedItem(); - if (item == selectedItem) { + Object selectedItem = ui.getSelectedItem(); + if (item == selectedItem) { - // item was selected item, reset selected item then - ui.setSelectedItem(null); + // item was selected item, reset selected item then + ui.setSelectedItem(null); + } + + needUpdate = true; + } + } + if (needUpdate) { + updateUI(ui.getIndex(), ui.isReverseSort()); fireEmpty(false); } + } /** + * Add the given item into the comboBox. + * <p/> + * <strong>Note:</strong> The item will be inserted at his correct following + * the selected ordering. + * + * @param item item to add in comboBox. + * @since 2.5.9 + */ + public void addItem(O item) { + + addItems(Collections.singleton(item)); + } + + /** + * Remove the given item from the comboBox model. + * <p/> + * <strong>Note:</strong> If this item was selected, then selection will be + * cleared. + * + * @param item the item to remove from the comboBox model + * @since 2.5.9 + */ + public void removeItem(O item) { + + removeItems(Collections.singleton(item)); + } + + /** * Sort data of the model. * * @since 2.5.10 Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBox.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBox.jaxx 2013-10-02 23:23:38 UTC (rev 2733) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBox.jaxx 2013-10-04 07:07:21 UTC (rev 2734) @@ -122,8 +122,12 @@ public void addItem(O item) { handler.addItem(item); } +public void addItems(Iterable<O> items) { handler.addItems(items); } + public void removeItem(O item) { handler.removeItem(item); } +public void removeItems(Iterable<O> items) { handler.removeItems(items); } + public void reset() { handler.reset(); } ]]> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBoxHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBoxHandler.java 2013-10-02 23:23:38 UTC (rev 2733) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/bean/BeanFilterableComboBoxHandler.java 2013-10-04 07:07:21 UTC (rev 2734) @@ -57,6 +57,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.Method; +import java.util.Collections; import java.util.List; /** @@ -270,7 +271,7 @@ /** * @return {@code true} if there is no data in comboBox, {@code false} - * otherwise. + * otherwise. */ public boolean isEmpty() { boolean result = CollectionUtils.isEmpty(ui.getData()); @@ -278,54 +279,97 @@ } /** - * Add the given item into the comboBox. + * Add the given items into the comboBox. * <p/> * <strong>Note:</strong> The item will be inserted at his correct following * the selected ordering. * - * @param item item to add in comboBox. + * @param items items to add in comboBox. + * @since 2.5.28 */ - public void addItem(O item) { + public void addItems(Iterable<O> items) { List<O> data = ui.getData(); + boolean wasEmpty = CollectionUtils.isEmpty(data); - data.add(item); + for (O item : items) { + data.add(item); + } + updateUI(ui.getIndex(), ui.isReverseSort()); fireEmpty(wasEmpty); } /** - * Remove the given item from the comboBox model. + * Remove the given items from the comboBox model. * <p/> * <strong>Note:</strong> If this item was selected, then selection will be * cleared. * - * @param item the item to remove from the comboBox model + * @param items items to remove from the comboBox model + * @since 2.5.28 */ - public void removeItem(O item) { + public void removeItems(Iterable<O> items) { List<O> data = ui.getData(); - boolean remove = data.remove(item); + boolean needUpdate = false; + for (O item : items) { + boolean remove = data.remove(item); - if (remove) { + if (remove) { - // item was found in data + // item was found in data - Object selectedItem = ui.getSelectedItem(); - if (item == selectedItem) { + Object selectedItem = ui.getSelectedItem(); + if (item == selectedItem) { - // item was selected item, reset selected item then - ui.setSelectedItem(null); + // item was selected item, reset selected item then + ui.setSelectedItem(null); + } + + needUpdate = true; } + } + if (needUpdate) { + updateUI(ui.getIndex(), ui.isReverseSort()); fireEmpty(false); } + } + /** + * Add the given item into the comboBox. + * <p/> + * <strong>Note:</strong> The item will be inserted at his correct following + * the selected ordering. + * + * @param item item to add in comboBox. + * @since 2.5.9 + */ + public void addItem(O item) { + + addItems(Collections.singleton(item)); + } + + /** + * Remove the given item from the comboBox model. + * <p/> + * <strong>Note:</strong> If this item was selected, then selection will be + * cleared. + * + * @param item the item to remove from the comboBox model + * @since 2.5.9 + */ + public void removeItem(O item) { + + removeItems(Collections.singleton(item)); + } + /** Sort data of the model. */ public void sortData() {
participants (1)
-
tchemit@users.nuiton.org