Fix for the dialog window must not close after save if duplicate exists.

Signed-off-by: Gaurav <gaurav.sahay@in.bosch.com>
This commit is contained in:
Gaurav
2016-08-15 15:38:08 +02:00
parent d89b6993d4
commit 75905472c8
6 changed files with 42 additions and 5 deletions

View File

@@ -202,9 +202,11 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
if (HawkbitCommonUtil.isDuplicate(name, version, type)) { if (HawkbitCommonUtil.isDuplicate(name, version, type)) {
uiNotifcation.displayValidationError( uiNotifcation.displayValidationError(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version })); i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
window.setIsDuplicate(Boolean.TRUE);
} else { } else {
final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name, final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name,
version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description); version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description);
window.setIsDuplicate(Boolean.FALSE);
if (newBaseSoftwareModule != null) { if (newBaseSoftwareModule != null) {
/* display success message */ /* display success message */
uiNotifcation.displaySuccess(i18n.get("message.save.success", uiNotifcation.displaySuccess(i18n.get("message.save.success",

View File

@@ -101,6 +101,8 @@ public class CommonDialogWindow extends Window implements Serializable {
private final List<AbstractField<?>> allComponents; private final List<AbstractField<?>> allComponents;
private final I18N i18n; private final I18N i18n;
private boolean isDuplicate;
/** /**
* Constructor. * Constructor.
@@ -137,11 +139,15 @@ public class CommonDialogWindow extends Window implements Serializable {
@Override @Override
public void close() { public void close() {
super.close(); if(!isDuplicate){
orginalValues.clear(); super.close();
removeListeners(); orginalValues.clear();
allComponents.clear(); removeListeners();
this.saveButton.setEnabled(false); allComponents.clear();
this.saveButton.setEnabled(false);
}else{
isDuplicate = Boolean.FALSE;
}
} }
private void removeListeners() { private void removeListeners() {
@@ -523,4 +529,22 @@ public class CommonDialogWindow extends Window implements Serializable {
public void setCancelButtonEnabled(final boolean enabled) { public void setCancelButtonEnabled(final boolean enabled) {
cancelButton.setEnabled(enabled); cancelButton.setEnabled(enabled);
} }
/**
* Boolean.TRUE/Boolean.FALSE based on the entity saved in the window already exists.
* @return isDuplicate
*/
public boolean getIsDuplicate() {
return isDuplicate;
}
/**
* Sets Boolean.TRUE/Boolean.FALSE based on the entity saved in the window already exists.
* @param isDuplicate
*/
public void setIsDuplicate(final boolean isDuplicate) {
this.isDuplicate = isDuplicate;
}
} }

View File

@@ -563,8 +563,10 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
protected Boolean checkIsDuplicate(final Tag existingTag) { protected Boolean checkIsDuplicate(final Tag existingTag) {
if (existingTag != null) { if (existingTag != null) {
displayValidationError(i18n.get("message.tag.duplicate.check", new Object[] { existingTag.getName() })); displayValidationError(i18n.get("message.tag.duplicate.check", new Object[] { existingTag.getName() }));
window.setIsDuplicate(Boolean.TRUE);
return Boolean.TRUE; return Boolean.TRUE;
} }
window.setIsDuplicate(Boolean.FALSE);
return Boolean.FALSE; return Boolean.FALSE;
} }

View File

@@ -260,8 +260,10 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
if (existingType != null) { if (existingType != null) {
uiNotification.displayValidationError( uiNotification.displayValidationError(
i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() })); i18n.get("message.tag.duplicate.check", new Object[] { existingType.getName() }));
window.setIsDuplicate(Boolean.TRUE);
return Boolean.TRUE; return Boolean.TRUE;
} }
window.setIsDuplicate(Boolean.FALSE);
return Boolean.FALSE; return Boolean.FALSE;
} }
@@ -271,13 +273,16 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
if (existingType instanceof DistributionSetType) { if (existingType instanceof DistributionSetType) {
uiNotification.displayValidationError(i18n.get("message.type.key.duplicate.check", uiNotification.displayValidationError(i18n.get("message.type.key.duplicate.check",
new Object[] { ((DistributionSetType) existingType).getKey() })); new Object[] { ((DistributionSetType) existingType).getKey() }));
window.setIsDuplicate(Boolean.TRUE);
return Boolean.TRUE; return Boolean.TRUE;
} else if (existingType instanceof SoftwareModuleType) { } else if (existingType instanceof SoftwareModuleType) {
uiNotification.displayValidationError(i18n.get("message.type.key.swmodule.duplicate.check", uiNotification.displayValidationError(i18n.get("message.type.key.swmodule.duplicate.check",
new Object[] { ((SoftwareModuleType) existingType).getKey() })); new Object[] { ((SoftwareModuleType) existingType).getKey() }));
window.setIsDuplicate(Boolean.TRUE);
return Boolean.TRUE; return Boolean.TRUE;
} }
} }
window.setIsDuplicate(Boolean.FALSE);
return Boolean.FALSE; return Boolean.FALSE;
} }

View File

@@ -273,9 +273,11 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
distVersionTextField.addStyleName("v-textfield-error"); distVersionTextField.addStyleName("v-textfield-error");
notificationMessage.displayValidationError( notificationMessage.displayValidationError(
i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() })); i18n.get("message.duplicate.dist", new Object[] { existingDs.getName(), existingDs.getVersion() }));
window.setIsDuplicate(Boolean.TRUE);
return false; return false;
} else { } else {
window.setIsDuplicate(Boolean.FALSE);
return true; return true;
} }
} }

View File

@@ -201,8 +201,10 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
if (existingTarget != null) { if (existingTarget != null) {
uINotification.displayValidationError( uINotification.displayValidationError(
i18n.get("message.target.duplicate.check", new Object[] { newControlllerId })); i18n.get("message.target.duplicate.check", new Object[] { newControlllerId }));
window.setIsDuplicate(Boolean.TRUE);
return false; return false;
} else { } else {
window.setIsDuplicate(Boolean.FALSE);
return true; return true;
} }
} }