Lior Vernia has uploaded a new change for review. Change subject: webadmin: Have minus button on every row in AddRemoveRowWidget ......................................................................
webadmin: Have minus button on every row in AddRemoveRowWidget Modified AddRemoveRowWidget to have a minus button on every entry, including the last one. This to enable removing the last row without adding a new one first. When removing the last row though, a plus button needs to be added to the previous one. Also made sure to add a new ghost entry if the removed entry was the only one (this is equivalent to reseting the entry's value to a ghost value). Some styling changes were required to properly display two buttons per entry, where this couldn't happen before. Change-Id: I6f6af3c5a94f7786a9b1e6191f1c36d3181983cf Bug-Url: https://bugzilla.redhat.com/1065978 Signed-off-by: Lior Vernia <[email protected]> --- M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/AddRemoveRowWidget.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/form/key_value/KeyValueWidget.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.ui.xml M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfilesInstanceTypeEditor.ui.xml M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelEditor.java M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelWidget.ui.xml M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.ui.xml M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfilesEditor.ui.xml 8 files changed, 58 insertions(+), 24 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/26946/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 148dd03..95b839c 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 @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.ListIterator; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.ui.common.CommonApplicationResources; @@ -136,9 +137,11 @@ final V widget = createWidget(value); Pair<T, V> item = new Pair<T, V>(value, widget); items.add(item); - PushButton button = createButton(item, lastItem); - AddRemoveRowPanel entry = new AddRemoveRowPanel(widget, button); + PushButton removeButton = createButton(item, false); + AddRemoveRowPanel entry = + lastItem ? new AddRemoveRowPanel(widget, removeButton, createButton(item, true)) + : new AddRemoveRowPanel(widget, removeButton); contentPanel.add(entry); final boolean ghost = isGhost(value); @@ -152,7 +155,7 @@ T value = event.getValue(); boolean becomingGhost = isGhost(value); if (becomingGhost != wasGhost) { - setButtonEnabled(widget, !becomingGhost); + setButtonsEnabled(widget, !becomingGhost); toggleGhost(value, widget, becomingGhost); wasGhost = becomingGhost; } @@ -181,7 +184,7 @@ @Override public void onClick(ClickEvent event) { - getEntry(widget).swapButton(createButton(item, false)); + getEntry(widget).removeLastButton(); Pair<T, V> item = addGhostEntry(); onAdd(item.getFirst(), item.getSecond()); } @@ -190,8 +193,23 @@ @Override public void onClick(ClickEvent event) { + ListIterator<Pair<T, V>> last = items.listIterator(items.size()); + if (!last.hasPrevious()) { // just a precaution; if there's no item, there should be no button + return; + } + + if (item == last.previous() && last.hasPrevious()) { // add plus button to previous item + Pair<T, V> previousItem = last.previous(); + getEntry(previousItem.getSecond()).appendButton(createButton(previousItem, true)); + } + removeEntry(item); onRemove(value, widget); + + if (items.isEmpty()) { + Pair<T, V> item = addGhostEntry(); + onAdd(item.getFirst(), item.getSecond()); + } } }); @@ -207,18 +225,21 @@ contentPanel.remove(getEntry(widget)); } - protected void setButtonEnabled(V widget, boolean enabled) { - getEntry(widget).setButtonEnabled(enabled); + protected void setButtonsEnabled(V widget, boolean enabled) { + getEntry(widget).setButtonsEnabled(enabled); } private class AddRemoveRowPanel extends FlowPanel { - private PushButton button; + private List<PushButton> buttons = new LinkedList<PushButton>(); - public AddRemoveRowPanel(Widget widget, PushButton button) { + public AddRemoveRowPanel(Widget widget, PushButton... buttons) { append(widget); - append(button); - this.button = button; + this.buttons.clear(); + for (PushButton button : buttons) { + append(button); + this.buttons.add(button); + } } private void append(Widget widget) { @@ -226,14 +247,19 @@ add(widget); } - public void setButtonEnabled(boolean enabled) { - button.setEnabled(enabled); + public void setButtonsEnabled(boolean enabled) { + for (PushButton button : buttons) { + button.setEnabled(enabled); + } } - public void swapButton(PushButton newButton) { - remove(button); - append(newButton); - button = newButton; + public void removeLastButton() { + remove(buttons.remove(buttons.size() - 1)); + } + + public void appendButton(PushButton button) { + buttons.add(button); + append(button); } } diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/form/key_value/KeyValueWidget.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/form/key_value/KeyValueWidget.java index 79d4fbe..9e57018 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/form/key_value/KeyValueWidget.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/form/key_value/KeyValueWidget.java @@ -82,7 +82,7 @@ protected void toggleGhost(KeyValueLineModel value, KeyValueLineWidget widget, boolean becomingGhost) { widget.setEnabled(!becomingGhost && enabled); widget.keyField.setEnabled(enabled); - setButtonEnabled(widget, !becomingGhost && enabled); + setButtonsEnabled(widget, !becomingGhost && enabled); } @Override diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.ui.xml b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.ui.xml index 909a374..c7738e029 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.ui.xml +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfileInstanceTypeEditor.ui.xml @@ -14,10 +14,15 @@ .contentStyle { float: left; } + + .containerStyle { + width: 300px; + margin-right: 20px; + } </ui:style> <g:FlowPanel> - <p:ProfileEditor ui:field="profileEditor" width="300px" /> + <p:ProfileEditor ui:field="profileEditor" addStyleNames="{style.containerStyle}" /> </g:FlowPanel> </ui:UiBinder> diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfilesInstanceTypeEditor.ui.xml b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfilesInstanceTypeEditor.ui.xml index e6ca471..ee9b72d 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfilesInstanceTypeEditor.ui.xml +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/profile/ProfilesInstanceTypeEditor.ui.xml @@ -21,7 +21,7 @@ padding-left: 2px; padding-top: 2px; margin-top: 7px; - margin-left: 50px; + margin-left: 10px; } </ui:style> diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelEditor.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelEditor.java index 8203be4..90a035e 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelEditor.java +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelEditor.java @@ -30,6 +30,7 @@ initWidget(suggestBoxEditor); getElement().getStyle().setMarginTop(5, Unit.PX); getElement().getStyle().setMarginBottom(5, Unit.PX); + getElement().getStyle().setMarginRight(15, Unit.PX); driver.initialize(this); } diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelWidget.ui.xml b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelWidget.ui.xml index a6da61c..f7f91bc 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelWidget.ui.xml +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/host/NicLabelWidget.ui.xml @@ -11,13 +11,12 @@ } .buttonStyle { - margin-right: 7px; width: 9px; height: 10px; padding-left: 2px; padding-top: 2px; margin-top: 11px; - margin-left: 20px; + margin-left: 10px; } .labelStyle { diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.ui.xml b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.ui.xml index 7a70ca6..0e7fffa 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.ui.xml +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfileWidget.ui.xml @@ -31,8 +31,12 @@ width: 185px; margin-left: 20px; } + + .containerStyle { + margin-right: 10px; + } </ui:style> - <g:HorizontalPanel> + <g:HorizontalPanel addStyleNames="{style.containerStyle}"> <e:EntityModelTextBoxOnlyEditor ui:field="nameEditor" /> <g:FlowPanel addStyleNames="{style.publicUsePanel}"> <e:EntityModelCheckBoxEditor ui:field="publicUseEditor" addStyleNames="{style.publicUseElement}"/> diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfilesEditor.ui.xml b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfilesEditor.ui.xml index f7b13e2..12b5961 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfilesEditor.ui.xml +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/widget/vnicProfile/VnicProfilesEditor.ui.xml @@ -9,13 +9,12 @@ } .buttonStyle { - margin-right: 7px; width: 9px; height: 10px; padding-left: 2px; padding-top: 2px; margin-top: 7px; - margin-left: 8px; + margin-left: 10px; } </ui:style> -- To view, visit http://gerrit.ovirt.org/26946 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6f6af3c5a94f7786a9b1e6191f1c36d3181983cf Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
