Lior Vernia has uploaded a new change for review. Change subject: webadmin: Add common MAC pool widget ......................................................................
webadmin: Add common MAC pool widget Add models and views to hold MAC pool logic in common with per-DC MAC pools and shared MAC pools (configurable on the system level). Change-Id: Ife55cf7c5e005912639c087565c3c5c3faddd93d Signed-off-by: Lior Vernia <[email protected]> --- A frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolModel.java A frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacRangeModel.java M frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java A frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.java A frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.ui.xml A frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.java A frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.ui.xml A frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.java A frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.ui.xml 9 files changed, 372 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/90/27790/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolModel.java new file mode 100644 index 0000000..e217014 --- /dev/null +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacPoolModel.java @@ -0,0 +1,75 @@ +package org.ovirt.engine.ui.uicommonweb.models.macpool; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.MacPool; +import org.ovirt.engine.core.common.businessentities.MacRange; +import org.ovirt.engine.ui.uicommonweb.models.EntityModel; +import org.ovirt.engine.ui.uicommonweb.models.ListModel; +import org.ovirt.engine.ui.uicompat.Event; +import org.ovirt.engine.ui.uicompat.EventArgs; +import org.ovirt.engine.ui.uicompat.IEventListener; + +public class MacPoolModel extends EntityModel<MacPool> { + + private final EntityModel<Boolean> allowDuplicates = new EntityModel<Boolean>(); + private final ListModel<MacRangeModel> macRanges = new ListModel<MacRangeModel>(); + + public EntityModel<Boolean> getAllowDuplicates() { + return allowDuplicates; + } + + public ListModel<MacRangeModel> getMacRanges() { + return macRanges; + } + + public MacPoolModel() { + getEntityChangedEvent().addListener(new IEventListener() { + + @Override + public void eventRaised(Event ev, Object sender, EventArgs args) { + init(); + } + }); + setEntity(new MacPool()); + } + + private void init() { + allowDuplicates.setEntity(getEntity().isAllowDuplicateMacAddresses()); + List<MacRangeModel> rangeModels = new ArrayList<MacRangeModel>(); + for (MacRange range : getEntity().getRanges()) { + rangeModels.add(new MacRangeModel(range)); + } + Collections.sort(rangeModels, new Comparator<MacRangeModel>() { + + @Override + public int compare(MacRangeModel range1, MacRangeModel range2) { + return range1.getLeftBound().getEntity().compareTo(range2.getRightBound().getEntity()); + } + }); + macRanges.setItems(rangeModels); + } + + public MacPool flush() { + getEntity().setAllowDuplicateMacAddresses(allowDuplicates.getEntity()); + getEntity().getRanges().clear(); + for (MacRangeModel rangeModel : macRanges.getItems()) { + getEntity().getRanges().add(rangeModel.flush()); + } + return getEntity(); + } + + public boolean validate() { + boolean valid = true; + for (MacRangeModel range : macRanges.getItems()) { + range.validate(); + valid &= range.getIsValid(); + } + setIsValid(valid); + return valid; + } + +} diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacRangeModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacRangeModel.java new file mode 100644 index 0000000..950534c --- /dev/null +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/macpool/MacRangeModel.java @@ -0,0 +1,69 @@ +package org.ovirt.engine.ui.uicommonweb.models.macpool; + +import org.ovirt.engine.core.common.businessentities.MacRange; +import org.ovirt.engine.ui.uicommonweb.models.EntityModel; +import org.ovirt.engine.ui.uicommonweb.models.Model; +import org.ovirt.engine.ui.uicommonweb.validation.IValidation; +import org.ovirt.engine.ui.uicommonweb.validation.MacAddressValidation; +import org.ovirt.engine.ui.uicommonweb.validation.ValidationResult; +import org.ovirt.engine.ui.uicompat.ConstantsManager; + +public class MacRangeModel extends Model { + + private final MacRange macRange; + + private final EntityModel<String> leftBound = new EntityModel<String>(); + private final EntityModel<String> rightBound = new EntityModel<String>(); + + public EntityModel<String> getLeftBound() { + return leftBound; + } + + public EntityModel<String> getRightBound() { + return rightBound; + } + + public MacRangeModel() { + this(new MacRange()); + } + + public MacRangeModel(MacRange macRange) { + this.macRange = macRange; + init(); + } + + private void init() { + leftBound.setEntity(macRange.getMacFrom() == null ? "" : macRange.getMacFrom()); //$NON-NLS-1$ + rightBound.setEntity(macRange.getMacTo() == null ? "" : macRange.getMacTo()); //$NON-NLS-1$ + } + + public MacRange flush() { + macRange.setMacFrom(leftBound.getEntity()); + macRange.setMacTo(rightBound.getEntity()); + return macRange; + } + + public boolean validate() { + leftBound.validateEntity(new IValidation[] { new MacAddressValidation() }); + rightBound.validateEntity(new IValidation[] { new MacAddressValidation() }); + if (leftBound.getIsValid() && rightBound.getIsValid()) { + rightBound.validateEntity(new IValidation[] { new IValidation() { + + @Override + public ValidationResult validate(Object value) { + ValidationResult res = new ValidationResult(); + if (((String) value).compareToIgnoreCase(leftBound.getEntity()) < 0) { + res.setSuccess(false); + res.getReasons().add(ConstantsManager.getInstance() + .getConstants() + .invalidMacRangeRightBound()); + } + return res; + } + }}); + } + setIsValid(leftBound.getIsValid() && rightBound.getIsValid()); + return getIsValid(); + } + +} diff --git a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java index 10e02e6..a13a222 100644 --- a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java +++ b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java @@ -865,6 +865,9 @@ @DefaultStringValue("Invalid MAC address") String invalidMacAddressMsg(); + @DefaultStringValue("The right bound of the MAC address range must not be smaller than its left bound.") + String invalidMacRangeRightBound(); + @DefaultStringValue("Note: Local Storage is already configured for this Host. The Host belongs to") String noteLocalStorageAlreadyConfiguredForThisHostMsg(); diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.java new file mode 100644 index 0000000..64c897c --- /dev/null +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.java @@ -0,0 +1,60 @@ +package org.ovirt.engine.ui.webadmin.section.main.view.popup.macpool; + +import org.ovirt.engine.ui.common.idhandler.ElementIdHandler; +import org.ovirt.engine.ui.common.idhandler.WithElementId; +import org.ovirt.engine.ui.common.widget.Align; +import org.ovirt.engine.ui.common.widget.editor.generic.EntityModelCheckBoxEditor; +import org.ovirt.engine.ui.common.widget.uicommon.popup.AbstractModelBoundPopupWidget; +import org.ovirt.engine.ui.uicommonweb.models.macpool.MacPoolModel; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.editor.client.SimpleBeanEditorDriver; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.FlowPanel; + +public class MacPoolWidget extends AbstractModelBoundPopupWidget<MacPoolModel> { + + interface Driver extends SimpleBeanEditorDriver<MacPoolModel, MacPoolWidget> { + } + + private final Driver driver = GWT.create(Driver.class); + + interface WidgetUiBinder extends UiBinder<FlowPanel, MacPoolWidget> { + WidgetUiBinder uiBinder = GWT.create(WidgetUiBinder.class); + } + + interface WidgetIdHandler extends ElementIdHandler<MacPoolWidget> { + WidgetIdHandler idHandler = GWT.create(WidgetIdHandler.class); + } + + @UiField(provided = true) + @Path(value = "allowDuplicates.entity") + @WithElementId + public EntityModelCheckBoxEditor allowDuplicates; + + @UiField + @Ignore + @WithElementId + public MacRangeWidget macRanges; + + public MacPoolWidget() { + allowDuplicates = new EntityModelCheckBoxEditor(Align.RIGHT); + initWidget(WidgetUiBinder.uiBinder.createAndBindUi(this)); + WidgetIdHandler.idHandler.generateAndSetIds(this); + driver.initialize(this); + } + + @Override + public void edit(MacPoolModel model) { + driver.edit(model); + macRanges.edit(model.getMacRanges()); + } + + @Override + public MacPoolModel flush() { + macRanges.flush(); + return driver.flush(); + } + +} diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.ui.xml b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.ui.xml new file mode 100644 index 0000000..4e62431 --- /dev/null +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacPoolWidget.ui.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> +<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" + xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:ge="urn:import:org.ovirt.engine.ui.common.widget.editor.generic" + xmlns:d="urn:import:org.ovirt.engine.ui.webadmin.section.main.view.popup.datacenter"> + + <ui:style> + .macRangeStyle { + max-height: 100px; + } + </ui:style> + + <g:FlowPanel> + <ge:EntityModelCheckBoxEditor ui:field="allowDuplicates" /> + <d:MacRangeWidget ui:field="macRanges" addStyleNames="{style.macRangeStyle}" /> + </g:FlowPanel> + +</ui:UiBinder> \ No newline at end of file diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.java new file mode 100644 index 0000000..95e912b --- /dev/null +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.java @@ -0,0 +1,77 @@ +package org.ovirt.engine.ui.webadmin.section.main.view.popup.macpool; + +import org.ovirt.engine.ui.common.idhandler.ElementIdHandler; +import org.ovirt.engine.ui.common.idhandler.WithElementId; +import org.ovirt.engine.ui.common.widget.editor.generic.StringEntityModelTextBoxEditor; +import org.ovirt.engine.ui.common.widget.uicommon.popup.AbstractModelBoundPopupWidget; +import org.ovirt.engine.ui.uicommonweb.models.macpool.MacRangeModel; +import org.ovirt.engine.ui.uicompat.Event; +import org.ovirt.engine.ui.uicompat.EventArgs; +import org.ovirt.engine.ui.uicompat.IEventListener; + +import com.google.gwt.core.shared.GWT; +import com.google.gwt.editor.client.SimpleBeanEditorDriver; +import com.google.gwt.event.logical.shared.HasValueChangeHandlers; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.FlowPanel; + +public class MacRangeEditor extends AbstractModelBoundPopupWidget<MacRangeModel> implements HasValueChangeHandlers<MacRangeModel> { + + public interface Driver extends SimpleBeanEditorDriver<MacRangeModel, MacRangeEditor> { + } + + private final Driver driver = GWT.create(Driver.class); + + interface WidgetUiBinder extends UiBinder<FlowPanel, MacRangeEditor> { + WidgetUiBinder uiBinder = GWT.create(WidgetUiBinder.class); + } + + interface WidgetIdHandler extends ElementIdHandler<MacRangeEditor> { + WidgetIdHandler idHandler = GWT.create(WidgetIdHandler.class); + } + + @UiField + @Path(value = "leftBound.entity") + @WithElementId + StringEntityModelTextBoxEditor leftBound; + + @UiField + @Path(value = "rightBound.entity") + @WithElementId + StringEntityModelTextBoxEditor rightBound; + + public MacRangeEditor() { + initWidget(WidgetUiBinder.uiBinder.createAndBindUi(this)); + WidgetIdHandler.idHandler.generateAndSetIds(this); + driver.initialize(this); + } + + @Override + public void edit(final MacRangeModel model) { + driver.edit(model); + IEventListener textChangedListener = new IEventListener() { + + @Override + public void eventRaised(Event ev, Object sender, EventArgs args) { + ValueChangeEvent.fire(MacRangeEditor.this, model); + } + }; + model.getLeftBound().getEntityChangedEvent().addListener(textChangedListener); + model.getRightBound().getEntityChangedEvent().addListener(textChangedListener); + } + + @Override + public MacRangeModel flush() { + return driver.flush(); + } + + @Override + public HandlerRegistration addValueChangeHandler(ValueChangeHandler<MacRangeModel> handler) { + return addHandler(handler, ValueChangeEvent.getType()); + } + +} diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.ui.xml b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.ui.xml new file mode 100644 index 0000000..69e138a --- /dev/null +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeEditor.ui.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> +<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" + xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:ge="urn:import:org.ovirt.engine.ui.common.widget.editor.generic"> + + <ui:style> + .boxStyle { + float: left; + width: 50%; + } + </ui:style> + + <g:FlowPanel> + <ge:StringEntityModelTextBoxEditor ui:field="leftBound" addStyleNames="{style.boxStyle}" /> + <ge:StringEntityModelTextBoxEditor ui:field="rightBound" addStyleNames="{style.boxStyle}" /> + </g:FlowPanel> + +</ui:UiBinder> \ No newline at end of file diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.java new file mode 100644 index 0000000..e66e71e --- /dev/null +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.java @@ -0,0 +1,31 @@ +package org.ovirt.engine.ui.webadmin.section.main.view.popup.macpool; + +import org.ovirt.engine.ui.common.widget.AddRemoveRowWidget; +import org.ovirt.engine.ui.uicommonweb.models.ListModel; +import org.ovirt.engine.ui.uicommonweb.models.macpool.MacRangeModel; + +public class MacRangeWidget extends AddRemoveRowWidget<ListModel<MacRangeModel>, MacRangeModel, MacRangeEditor> { + + @Override + protected MacRangeEditor createWidget(MacRangeModel value) { + MacRangeEditor widget = new MacRangeEditor(); + widget.edit(value); + return widget; + } + + @Override + protected MacRangeModel createGhostValue() { + return new MacRangeModel(); + } + + @Override + protected boolean isGhost(MacRangeModel value) { + return value.getLeftBound().getEntity().isEmpty() || value.getRightBound().getEntity().isEmpty(); + } + + @Override + protected void toggleGhost(MacRangeModel value, MacRangeEditor widget, boolean becomingGhost) { + // do nothing, widget looks the same when it's a ghost widget + } + +} diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.ui.xml b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.ui.xml new file mode 100644 index 0000000..c7702b818 --- /dev/null +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/macpool/MacRangeWidget.ui.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> +<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui"> + + <ui:style type="org.ovirt.engine.ui.common.widget.AddRemoveRowWidget.WidgetStyle"> + .buttonStyle { + margin-right: 7px; + width: 9px; + height: 10px; + padding-left: 2px; + padding-top: 2px; + margin-top: 11px; + margin-left: 20px; + } + </ui:style> + + <g:ScrollPanel> + <g:FlowPanel ui:field="contentPanel" /> + </g:ScrollPanel> + +</ui:UiBinder> \ No newline at end of file -- To view, visit http://gerrit.ovirt.org/27790 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ife55cf7c5e005912639c087565c3c5c3faddd93d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
