Fix save and close order for common window dialog. Close the window

after the save action, because after the close action there is no UI
anymore. So an error cannot shown on the UI.

Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
SirWayne
2016-08-19 17:44:23 +02:00
parent 6babfe3603
commit fe113a4bc6
8 changed files with 212 additions and 201 deletions

View File

@@ -50,6 +50,27 @@ import com.vaadin.ui.themes.ValoTheme;
@ViewScope @ViewScope
public class SoftwareModuleAddUpdateWindow extends CustomComponent { public class SoftwareModuleAddUpdateWindow extends CustomComponent {
/**
* @author Dennis Melzer
*
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editSwModule) {
updateSwModule();
} else {
addNewBaseSoftware();
}
}
@Override
public boolean canWindowSaveOrUpdate() {
return editSwModule || !isDuplicate();
}
}
private static final long serialVersionUID = -5217675246477211483L; private static final long serialVersionUID = -5217675246477211483L;
@Autowired @Autowired
@@ -179,28 +200,9 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
setCompositionRoot(formLayout); setCompositionRoot(formLayout);
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(i18n.get("upload.caption.add.new.swmodule")).content(this) .caption(i18n.get("upload.caption.add.new.swmodule")).content(this).layout(formLayout).i18n(i18n)
.layout(formLayout).i18n(i18n) .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
.buildCommonDialogWindow();
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
@Override
public void saveOrUpdate() {
if (editSwModule) {
updateSwModule();
} else {
addNewBaseSoftware();
}
}
@Override
public boolean canWindowClose() {
return editSwModule || !isDuplicate();
}
});
nameTextField.setEnabled(!editSwModule); nameTextField.setEnabled(!editSwModule);
versionTextField.setEnabled(!editSwModule); versionTextField.setEnabled(!editSwModule);
typeComboBox.setEnabled(!editSwModule); typeComboBox.setEnabled(!editSwModule);
@@ -215,11 +217,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null; final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
if (isDuplicate()) {
uiNotifcation.displayValidationError(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
return;
}
final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name, version, final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name, version,
vendor, softwareManagement.findSoftwareModuleTypeByName(type), description); vendor, softwareManagement.findSoftwareModuleTypeByName(type), description);
if (newBaseSoftwareModule != null) { if (newBaseSoftwareModule != null) {
@@ -238,7 +235,13 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class);
final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version, final SoftwareModule swModule = swMgmtService.findSoftwareModuleByNameAndVersion(name, version,
swMgmtService.findSoftwareModuleTypeByName(type)); swMgmtService.findSoftwareModuleTypeByName(type));
return swModule != null;
if (swModule != null) {
uiNotifcation.displayValidationError(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
return true;
}
return false;
} }
/** /**

View File

@@ -65,6 +65,26 @@ import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent;
public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity, M extends MetaData> public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity, M extends MetaData>
extends CustomComponent { extends CustomComponent {
/**
*
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
onSave();
}
@Override
public boolean canWindowSaveOrUpdate() {
return true;
}
@Override
public boolean canWindowClose() {
return false;
}
}
private static final String DELETE_BUTTON = "DELETE_BUTTON"; private static final String DELETE_BUTTON = "DELETE_BUTTON";
private static final long serialVersionUID = -1491218218453167613L; private static final long serialVersionUID = -1491218218453167613L;
@@ -120,20 +140,8 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
metadataWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) metadataWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(getMetadataCaption(nameVersion)).content(this).cancelButtonClickListener(event -> onCancel()) .caption(getMetadataCaption(nameVersion)).content(this).cancelButtonClickListener(event -> onCancel())
.id(SPUIComponentIdProvider.METADATA_POPUP_ID).layout(mainLayout).i18n(i18n).buildCommonDialogWindow(); .id(SPUIComponentIdProvider.METADATA_POPUP_ID).layout(mainLayout).i18n(i18n)
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
metadataWindow.setSaveDialogCloseListener(new SaveDialogCloseListener() {
@Override
public void saveOrUpdate() {
onSave();
}
@Override
public boolean canWindowClose() {
return false;
}
});
metadataWindow.setHeight(550, Unit.PIXELS); metadataWindow.setHeight(550, Unit.PIXELS);
metadataWindow.setWidth(800, Unit.PIXELS); metadataWindow.setWidth(800, Unit.PIXELS);

View File

@@ -8,6 +8,8 @@
*/ */
package org.eclipse.hawkbit.ui.common; package org.eclipse.hawkbit.ui.common;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@@ -63,8 +65,10 @@ import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ValoTheme; import com.vaadin.ui.themes.ValoTheme;
/** /**
*
* Table pop-up-windows including a minimize and close icon in the upper right * Table pop-up-windows including a minimize and close icon in the upper right
* corner and a save and cancel button at the bottom. Is not intended to reuse. * corner and a save and cancel button at the bottom. Is not intended to reuse.
*
*/ */
public class CommonDialogWindow extends Window { public class CommonDialogWindow extends Window {
@@ -107,6 +111,8 @@ public class CommonDialogWindow extends Window {
* the content * the content
* @param helpLink * @param helpLink
* the helpLinks * the helpLinks
* @param closeListener
* the saveDialogCloseListener
* @param cancelButtonClickListener * @param cancelButtonClickListener
* the cancelButtonClickListener * the cancelButtonClickListener
* @param layout * @param layout
@@ -115,10 +121,13 @@ public class CommonDialogWindow extends Window {
* the i18n service * the i18n service
*/ */
public CommonDialogWindow(final String caption, final Component content, final String helpLink, public CommonDialogWindow(final String caption, final Component content, final String helpLink,
final ClickListener cancelButtonClickListener, final AbstractLayout layout, final I18N i18n) { final SaveDialogCloseListener closeListener, final ClickListener cancelButtonClickListener,
final AbstractLayout layout, final I18N i18n) {
checkNotNull(closeListener);
this.caption = caption; this.caption = caption;
this.content = content; this.content = content;
this.helpLink = helpLink; this.helpLink = helpLink;
this.closeListener = closeListener;
this.cancelButtonClickListener = cancelButtonClickListener; this.cancelButtonClickListener = cancelButtonClickListener;
this.orginalValues = new HashMap<>(); this.orginalValues = new HashMap<>();
this.allComponents = getAllComponents(layout); this.allComponents = getAllComponents(layout);
@@ -126,29 +135,24 @@ public class CommonDialogWindow extends Window {
init(); init();
} }
/**
* Sets the close Listener
*
* @param closeListener
*/
public void setSaveDialogCloseListener(final SaveDialogCloseListener closeListener) {
this.closeListener = closeListener;
}
private void onCloseEvent(final ClickEvent clickEvent) { private void onCloseEvent(final ClickEvent clickEvent) {
if (!clickEvent.getButton().equals(saveButton)) { if (!clickEvent.getButton().equals(saveButton)) {
close(); close();
return; return;
} }
if (closeListener == null || closeListener.canWindowClose()) { // check first the can window close before you save the dialog, because
close(); // if you save the dialog first, the entity exist and the duplicate
} // check is failing.
final boolean canWindowClose = closeListener.canWindowClose();
if (closeListener.canWindowSaveOrUpdate()) { if (closeListener.canWindowSaveOrUpdate()) {
closeListener.saveOrUpdate(); closeListener.saveOrUpdate();
} }
if (canWindowClose) {
close();
}
} }
@Override @Override
@@ -547,14 +551,14 @@ public class CommonDialogWindow extends Window {
* *
* @return true/false . * @return true/false .
*/ */
default boolean canWindowSaveOrUpdate() { boolean canWindowSaveOrUpdate();
return true;
}
/** /**
* @return true/false based on the dialog window to be closed or not. * @return true/false based on the dialog window to be closed or not.
*/ */
boolean canWindowClose(); default boolean canWindowClose() {
return canWindowSaveOrUpdate();
}
/** /**
* Saves/Updates * Saves/Updates
@@ -563,4 +567,22 @@ public class CommonDialogWindow extends Window {
void saveOrUpdate(); void saveOrUpdate();
} }
// public abstract class DefaultSaveDialogCloseListener implements
// SaveDialogCloseListener {
//
// private boolean canWindowSaveOrUpdate;
//
// @Override
// public boolean canWindowSaveOrUpdate() {
// return this.canWindowSaveOrUpdate;
// }
//
// @Override
// public boolean canWindowClose() {
// this.canWindowSaveOrUpdate =
// return this.canWindowSaveOrUpdate;
// }
//
// }
} }

View File

@@ -144,23 +144,8 @@ public class WindowBuilder {
* @return the window. * @return the window.
*/ */
public CommonDialogWindow buildCommonDialogWindow() { public CommonDialogWindow buildCommonDialogWindow() {
final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, cancelButtonClickListener, final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, saveDialogCloseListener,
layout, i18n); cancelButtonClickListener, layout, i18n);
window.setSaveDialogCloseListener(saveDialogCloseListener);
decorateWindow(window);
return window;
}
/**
* Build the common dialog window.
*
* @return the window.
*/
public CommonDialogWindow buildConfirmationWindow() {
final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, cancelButtonClickListener,
layout, i18n);
window.setSaveDialogCloseListener(saveDialogCloseListener);
decorateWindow(window); decorateWindow(window);
return window; return window;

View File

@@ -61,6 +61,27 @@ import com.vaadin.ui.themes.ValoTheme;
*/ */
public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> extends CustomComponent public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> extends CustomComponent
implements ColorChangeListener, ColorSelector { implements ColorChangeListener, ColorSelector {
/**
*
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (optiongroup.getValue().equals(createTagStr)) {
createEntity();
} else {
updateEntity(findEntityByName());
}
}
@Override
public boolean canWindowSaveOrUpdate() {
final boolean update = !optiongroup.getValue().equals(createTagStr);
return update || !isDuplicate();
}
}
private static final long serialVersionUID = 4229177824620576456L; private static final long serialVersionUID = 4229177824620576456L;
private static final String TAG_NAME_DYNAMIC_STYLE = "new-tag-name"; private static final String TAG_NAME_DYNAMIC_STYLE = "new-tag-name";
private static final String TAG_DESC_DYNAMIC_STYLE = "new-tag-desc"; private static final String TAG_DESC_DYNAMIC_STYLE = "new-tag-desc";
@@ -462,27 +483,8 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
public CommonDialogWindow getWindow() { public CommonDialogWindow getWindow() {
reset(); reset();
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(getWindowCaption()).content(this) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(getWindowCaption()).content(this)
.cancelButtonClickListener(event -> discard()).layout(mainLayout).i18n(i18n).buildCommonDialogWindow(); .cancelButtonClickListener(event -> discard()).layout(mainLayout).i18n(i18n)
.saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
@Override
public void saveOrUpdate() {
if (optiongroup.getValue().equals(createTagStr)) {
if (!isDuplicate()) {
createEntity();
}
} else {
updateEntity(findEntityByName());
}
}
@Override
public boolean canWindowClose() {
final boolean update = !optiongroup.getValue().equals(createTagStr);
return update || !isDuplicate();
}
});
return window; return window;
} }

View File

@@ -18,7 +18,6 @@ import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.repository.model.TenantMetaData;
@@ -42,8 +41,6 @@ import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.UINotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
@@ -69,8 +66,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
private static final long serialVersionUID = -5602182034230568435L; private static final long serialVersionUID = -5602182034230568435L;
private static final Logger LOG = LoggerFactory.getLogger(DistributionAddUpdateWindowLayout.class);
@Autowired @Autowired
private I18N i18n; private I18N i18n;
@@ -100,6 +95,23 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
private FormLayout formLayout; private FormLayout formLayout;
private final class SaveOnCloseDialogListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editDistribution) {
updateDistribution();
} else {
addNewDistribution();
}
}
@Override
public boolean canWindowSaveOrUpdate() {
return !isDuplicate();
}
}
/** /**
* Initialize Distribution Add and Edit Window. * Initialize Distribution Add and Edit Window.
*/ */
@@ -198,17 +210,12 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
/* identify the changes */ /* identify the changes */
setDistributionValues(currentDS, name, version, distSetTypeName, desc, isMigStepReq); setDistributionValues(currentDS, name, version, distSetTypeName, desc, isMigStepReq);
try { distributionSetManagement.updateDistributionSet(currentDS);
distributionSetManagement.updateDistributionSet(currentDS); notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success",
notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success", new Object[] { currentDS.getName(), currentDS.getVersion() }));
new Object[] { currentDS.getName(), currentDS.getVersion() })); // update table row+details layout
// update table row+details layout eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS));
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.UPDATED_ENTITY, currentDS));
} catch (final EntityAlreadyExistsException entityAlreadyExistsException) {
LOG.error("Update distribution failed {}", entityAlreadyExistsException);
notificationMessage.displayValidationError(
i18n.get("message.distribution.no.update", currentDS.getName() + ":" + currentDS.getVersion()));
}
} }
/** /**
@@ -336,28 +343,8 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
populateDistSetTypeNameCombo(); populateDistSetTypeNameCombo();
populateValuesOfDistribution(editDistId); populateValuesOfDistribution(editDistId);
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.dist")) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.dist"))
.content(this).layout(formLayout).i18n(i18n).buildCommonDialogWindow(); .content(this).layout(formLayout).i18n(i18n).saveDialogCloseListener(new SaveOnCloseDialogListener())
.buildCommonDialogWindow();
window.setSaveDialogCloseListener(new SaveDialogCloseListener() {
@Override
public void saveOrUpdate() {
if (editDistribution) {
updateDistribution();
} else {
addNewDistribution();
}
}
@Override
public boolean canWindowSaveOrUpdate() {
return editDistribution || !isDuplicate();
}
@Override
public boolean canWindowClose() {
return !isDuplicate();
}
});
return window; return window;
} }

View File

@@ -47,6 +47,27 @@ import com.vaadin.ui.Window;
@SpringComponent @SpringComponent
@VaadinSessionScope @VaadinSessionScope
public class TargetAddUpdateWindowLayout extends CustomComponent { public class TargetAddUpdateWindowLayout extends CustomComponent {
/**
*
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editTarget) {
updateTarget();
} else {
addNewTarget();
}
}
@Override
public boolean canWindowSaveOrUpdate() {
return editTarget || !isDuplicate();
}
}
private static final long serialVersionUID = -6659290471705262389L; private static final long serialVersionUID = -6659290471705262389L;
@Autowired @Autowired
@@ -127,9 +148,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
} }
private void addNewTarget() { private void addNewTarget() {
if (isDuplicate()) {
return;
}
final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue()); final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue());
final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue()); final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue());
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
@@ -152,23 +170,8 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
public Window getWindow() { public Window getWindow() {
eventBus.publish(this, DragEvent.HIDE_DROP_HINT); eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.target")) window = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW).caption(i18n.get("caption.add.new.target"))
.content(this).layout(formLayout).i18n(i18n).buildCommonDialogWindow(); .content(this).layout(formLayout).i18n(i18n).saveDialogCloseListener(new SaveOnDialogCloseListener())
window.setSaveDialogCloseListener(new SaveDialogCloseListener() { .buildCommonDialogWindow();
@Override
public void saveOrUpdate() {
if (editTarget) {
updateTarget();
} else {
addNewTarget();
}
}
@Override
public boolean canWindowClose() {
return editTarget || !isDuplicate();
}
});
return window; return window;
} }

View File

@@ -171,27 +171,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
resetComponents(); resetComponents();
final CommonDialogWindow commonDialogWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW) final CommonDialogWindow commonDialogWindow = new WindowBuilder(SPUIDefinitions.CREATE_UPDATE_WINDOW)
.caption(i18n.get("caption.configure.rollout")).content(this).layout(this).i18n(i18n) .caption(i18n.get("caption.configure.rollout")).content(this).layout(this).i18n(i18n)
.helpLink(uiProperties.getLinks().getDocumentation().getRolloutView()).buildCommonDialogWindow(); .helpLink(uiProperties.getLinks().getDocumentation().getRolloutView())
commonDialogWindow.setSaveDialogCloseListener(new SaveDialogCloseListener() { .saveDialogCloseListener(new SaveOnDialogCloseListener()).buildCommonDialogWindow();
@Override
public void saveOrUpdate() {
if (editRolloutEnabled) {
editRollout();
} else {
createRollout();
}
}
@Override
public boolean canWindowClose() {
if (editRolloutEnabled) {
return duplicateCheckForEdit();
}
return duplicateCheck();
}
});
return commonDialogWindow; return commonDialogWindow;
} }
@@ -418,26 +399,26 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
} }
private void editRollout() { private void editRollout() {
if (duplicateCheckForEdit() && rolloutForEdit != null) { if (rolloutForEdit == null) {
rolloutForEdit.setName(rolloutName.getValue()); return;
rolloutForEdit.setDescription(description.getValue());
final DistributionSetIdName distributionSetIdName = (DistributionSetIdName) distributionSet.getValue();
rolloutForEdit.setDistributionSet(
distributionSetManagement.findDistributionSetById(distributionSetIdName.getId()));
rolloutForEdit.setActionType(getActionType());
rolloutForEdit.setForcedTime(getForcedTimeStamp());
final int amountGroup = Integer.parseInt(noOfGroups.getValue());
final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup);
for (final RolloutGroup rolloutGroup : rolloutForEdit.getRolloutGroups()) {
rolloutGroup.setErrorConditionExp(triggerThreshold.getValue());
rolloutGroup.setSuccessConditionExp(String.valueOf(errorThresoldPercent));
}
final Rollout updatedRollout = rolloutManagement.updateRollout(rolloutForEdit);
uiNotification
.displaySuccess(i18n.get("message.update.success", new Object[] { updatedRollout.getName() }));
eventBus.publish(this, RolloutEvent.UPDATE_ROLLOUT);
} }
rolloutForEdit.setName(rolloutName.getValue());
rolloutForEdit.setDescription(description.getValue());
final DistributionSetIdName distributionSetIdName = (DistributionSetIdName) distributionSet.getValue();
rolloutForEdit
.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetIdName.getId()));
rolloutForEdit.setActionType(getActionType());
rolloutForEdit.setForcedTime(getForcedTimeStamp());
final int amountGroup = Integer.parseInt(noOfGroups.getValue());
final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup);
for (final RolloutGroup rolloutGroup : rolloutForEdit.getRolloutGroups()) {
rolloutGroup.setErrorConditionExp(triggerThreshold.getValue());
rolloutGroup.setSuccessConditionExp(String.valueOf(errorThresoldPercent));
}
final Rollout updatedRollout = rolloutManagement.updateRollout(rolloutForEdit);
uiNotification.displaySuccess(i18n.get("message.update.success", new Object[] { updatedRollout.getName() }));
eventBus.publish(this, RolloutEvent.UPDATE_ROLLOUT);
} }
private boolean duplicateCheckForEdit() { private boolean duplicateCheckForEdit() {
@@ -463,11 +444,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
} }
private void createRollout() { private void createRollout() {
if (duplicateCheck()) { final Rollout rolloutToCreate = saveRollout();
final Rollout rolloutToCreate = saveRollout(); uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() }));
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() }));
eventBus.publish(this, RolloutEvent.CREATE_ROLLOUT);
}
} }
private Rollout saveRollout() { private Rollout saveRollout() {
@@ -605,6 +583,29 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
return HawkbitCommonUtil.trimAndNullIfEmpty(rolloutName.getValue()); return HawkbitCommonUtil.trimAndNullIfEmpty(rolloutName.getValue());
} }
/**
*
*/
private final class SaveOnDialogCloseListener implements SaveDialogCloseListener {
@Override
public void saveOrUpdate() {
if (editRolloutEnabled) {
editRollout();
} else {
createRollout();
}
}
@Override
public boolean canWindowSaveOrUpdate() {
if (editRolloutEnabled) {
return duplicateCheckForEdit();
}
return duplicateCheck();
}
}
class ErrorThresoldOptionValidator implements Validator { class ErrorThresoldOptionValidator implements Validator {
private static final long serialVersionUID = 9049939751976326550L; private static final long serialVersionUID = 9049939751976326550L;