Lior Vernia has uploaded a new change for review. Change subject: webadmin: AddRemoveRowWidget to only add ghost entry if no items ......................................................................
webadmin: AddRemoveRowWidget to only add ghost entry if no items If there are items in the passed collection, then there's no need to add a ghost entry by default, but only have a plus button next to the last entry. Change-Id: I120e9183d739213b3a26227cc8c3b738ee3b54dc Bug-Url: https://bugzilla.redhat.com/1020861 Bug-Url: https://bugzilla.redhat.com/1058205 Signed-off-by: Lior Vernia <lver...@redhat.com> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AddRemoveRowWidget.java 1 file changed, 19 insertions(+), 13 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/19/23819/1 diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AddRemoveRowWidget.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AddRemoveRowWidget.java index a2472e7..148dd03 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AddRemoveRowWidget.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AddRemoveRowWidget.java @@ -1,6 +1,7 @@ package org.ovirt.engine.ui.common.widget; import java.util.Collection; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -88,11 +89,17 @@ return; } - for (T value : modelItems) { - addEntry(value); + if (modelItems.isEmpty()) { + T ghostValue = addGhostEntry().getFirst(); + modelItems.add(ghostValue); + } else { + Iterator<T> i = modelItems.iterator(); + while (i.hasNext()) { + T value = i.next(); + addEntry(value, !i.hasNext()); + } } - T additionalValue = addGhostEntry().getFirst(); - modelItems.add(additionalValue); + } @Override @@ -121,15 +128,15 @@ private Pair<T, V> addGhostEntry() { T value = createGhostValue(); - V widget = addEntry(value); + V widget = addEntry(value, true); return new Pair<T, V>(value, widget); } - private V addEntry(T value) { + private V addEntry(T value, boolean lastItem) { final V widget = createWidget(value); Pair<T, V> item = new Pair<T, V>(value, widget); items.add(item); - PushButton button = createButton(item); + PushButton button = createButton(item, lastItem); AddRemoveRowPanel entry = new AddRemoveRowPanel(widget, button); contentPanel.add(entry); @@ -160,22 +167,21 @@ removeWidget(item.getSecond()); } - private PushButton createButton(final Pair<T, V> item) { + private PushButton createButton(final Pair<T, V> item, boolean plusButton) { final T value = item.getFirst(); final V widget = item.getSecond(); - boolean ghostItem = isGhost(value); final PushButton button = - new PushButton(new Image(ghostItem ? resources.increaseIcon() : resources.decreaseIcon())); + new PushButton(new Image(plusButton ? resources.increaseIcon() : resources.decreaseIcon())); button.addStyleName(style.buttonStyle()); - button.setEnabled(!ghostItem); + button.setEnabled(!isGhost(value)); - button.addClickHandler(ghostItem ? + button.addClickHandler(plusButton ? new ClickHandler() { @Override public void onClick(ClickEvent event) { - getEntry(widget).swapButton(createButton(item)); + getEntry(widget).swapButton(createButton(item, false)); Pair<T, V> item = addGhostEntry(); onAdd(item.getFirst(), item.getSecond()); } -- To view, visit http://gerrit.ovirt.org/23819 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I120e9183d739213b3a26227cc8c3b738ee3b54dc Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <lver...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches