Save button is only enabled if validation is successful
Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
@@ -26,7 +26,6 @@ import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
|
||||
@@ -40,7 +39,6 @@ import com.vaadin.ui.FormLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
@@ -184,8 +182,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
setCompositionRoot(formLayout);
|
||||
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("upload.caption.add.new.swmodule"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveOrUpdate(), event -> closeThisWindow(), null,
|
||||
formLayout, i18n);
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveOrUpdate(), null, null, formLayout, i18n);
|
||||
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
|
||||
|
||||
nameTextField.setEnabled(!editSwModule);
|
||||
@@ -202,10 +199,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
|
||||
final String type = typeComboBox.getValue() != null ? typeComboBox.getValue().toString() : null;
|
||||
|
||||
if (!mandatoryCheck(name, version, type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (HawkbitCommonUtil.isDuplicate(name, version, type)) {
|
||||
uiNotifcation.displayValidationError(
|
||||
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
|
||||
@@ -218,8 +211,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
new Object[] { newBaseSoftwareModule.getName() + ":" + newBaseSoftwareModule.getVersion() }));
|
||||
eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.NEW_ENTITY, newBaseSoftwareModule));
|
||||
}
|
||||
// close the window
|
||||
closeThisWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +230,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
|
||||
eventBus.publish(this, new SoftwareModuleEvent(BaseEntityEventType.UPDATED_ENTITY, newSWModule));
|
||||
}
|
||||
closeThisWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,6 +239,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
if (baseSwModuleId == null) {
|
||||
return;
|
||||
}
|
||||
editSwModule = Boolean.TRUE;
|
||||
final SoftwareModule swModle = softwareManagement.findSoftwareModuleById(baseSwModuleId);
|
||||
nameTextField.setValue(swModle.getName());
|
||||
versionTextField.setValue(swModle.getVersion());
|
||||
@@ -262,42 +253,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
typeComboBox.setValue(swModle.getType().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to close window.
|
||||
*/
|
||||
private void closeThisWindow() {
|
||||
window.close();
|
||||
UI.getCurrent().removeWindow(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation check - Mandatory.
|
||||
*
|
||||
* @param name
|
||||
* as String
|
||||
* @param version
|
||||
* as version
|
||||
* @return boolena as flag
|
||||
*/
|
||||
private boolean mandatoryCheck(final String name, final String version, final String type) {
|
||||
boolean isValid = true;
|
||||
if (name == null || version == null || type == null) {
|
||||
if (name == null) {
|
||||
nameTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
}
|
||||
if (version == null) {
|
||||
versionTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
}
|
||||
if (type == null) {
|
||||
typeComboBox.addStyleName(SPUIStyleDefinitions.SP_COMBOFIELD_ERROR);
|
||||
}
|
||||
|
||||
uiNotifcation.displayValidationError(i18n.get("message.mandatory.check"));
|
||||
isValid = false;
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
private void saveOrUpdate() {
|
||||
if (editSwModule) {
|
||||
updateSwModule();
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.vaadin.ui.Button.ClickEvent;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.OptionGroup;
|
||||
import com.vaadin.ui.components.colorpicker.ColorChangeListener;
|
||||
import com.vaadin.ui.components.colorpicker.ColorSelector;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
@@ -45,8 +44,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout
|
||||
implements ColorChangeListener, ColorSelector {
|
||||
public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout {
|
||||
|
||||
private static final long serialVersionUID = -5169398523815919367L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CreateUpdateSoftwareTypeLayout.class);
|
||||
@@ -231,7 +229,6 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout
|
||||
|
||||
newSWType = swTypeManagementService.createSoftwareModuleType(newSWType);
|
||||
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { newSWType.getName() }));
|
||||
closeWindow();
|
||||
eventBus.publish(this,
|
||||
new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE, newSWType));
|
||||
|
||||
@@ -253,7 +250,6 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout
|
||||
existingType.setColour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()));
|
||||
swTypeManagementService.updateSoftwareModuleType(existingType);
|
||||
uiNotification.displaySuccess(i18n.get("message.update.success", new Object[] { existingType.getName() }));
|
||||
closeWindow();
|
||||
eventBus.publish(this,
|
||||
new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.UPDATE_SOFTWARE_MODULE_TYPE, existingType));
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.eclipse.hawkbit.ui.management.targettable.TargetAddUpdateWindowLayout
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroupItemComponent;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -38,6 +39,8 @@ import com.vaadin.data.Container.ItemSetChangeEvent;
|
||||
import com.vaadin.data.Container.ItemSetChangeListener;
|
||||
import com.vaadin.data.Property.ValueChangeEvent;
|
||||
import com.vaadin.data.Property.ValueChangeListener;
|
||||
import com.vaadin.data.Validator;
|
||||
import com.vaadin.data.validator.NullValidator;
|
||||
import com.vaadin.event.FieldEvents.TextChangeEvent;
|
||||
import com.vaadin.event.FieldEvents.TextChangeListener;
|
||||
import com.vaadin.event.FieldEvents.TextChangeNotifier;
|
||||
@@ -64,6 +67,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
public class CommonDialogWindow extends Window implements Serializable {
|
||||
|
||||
@@ -89,6 +93,8 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
|
||||
private final ClickListener cancelButtonClickListener;
|
||||
|
||||
private final ClickListener close = event -> close();
|
||||
|
||||
private final Map<Component, Object> orginalValues;
|
||||
|
||||
private final List<AbstractField<?>> allComponents;
|
||||
@@ -113,7 +119,6 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener,
|
||||
final AbstractLayout layout, final I18N i18n) {
|
||||
checkNotNull(saveButtonClickListener);
|
||||
checkNotNull(cancelButtonClickListener);
|
||||
this.caption = caption;
|
||||
this.content = content;
|
||||
this.helpLink = helpLink;
|
||||
@@ -211,13 +216,11 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
}
|
||||
orginalValues.put(field, value);
|
||||
}
|
||||
|
||||
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(null, null));
|
||||
}
|
||||
|
||||
private final void addListeners() {
|
||||
for (final AbstractField<?> field : allComponents) {
|
||||
|
||||
if (field instanceof TextChangeNotifier) {
|
||||
((TextChangeNotifier) field).addTextChangeListener(new ChangeListener(field));
|
||||
}
|
||||
@@ -229,13 +232,13 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
saveButton.addClickListener(event -> close());
|
||||
cancelButton.addClickListener(event -> close());
|
||||
saveButton.addClickListener(close);
|
||||
cancelButton.addClickListener(close);
|
||||
}
|
||||
|
||||
private boolean isSaveButtonEnabledAfterValueChange(final Component currentChangedComponent,
|
||||
final Object newValue) {
|
||||
return isMandatoyFieldNotEmpty(currentChangedComponent, newValue)
|
||||
return isMandatoryFieldNotEmptyAndValid(currentChangedComponent, newValue)
|
||||
&& isValuesChanged(currentChangedComponent, newValue);
|
||||
}
|
||||
|
||||
@@ -247,7 +250,6 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
if (!isValueEquals(field, orginalValue, currentValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -289,31 +291,45 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMandatoyFieldNotEmpty(final Component currentChangedComponent, final Object newValue) {
|
||||
private boolean isMandatoryFieldNotEmptyAndValid(final Component currentChangedComponent, final Object newValue) {
|
||||
|
||||
boolean valid = true;
|
||||
final List<AbstractField<?>> requiredComponents = allComponents.stream().filter(field -> field.isRequired())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (final AbstractField<?> field : requiredComponents) {
|
||||
Object value = getCurrentVaue(currentChangedComponent, newValue, field);
|
||||
requiredComponents.addAll(allComponents.stream().filter(this::hasNullValidator).collect(Collectors.toList()));
|
||||
|
||||
if (String.class.equals(field.getType())) {
|
||||
value = Strings.emptyToNull((String) value);
|
||||
}
|
||||
|
||||
if (Set.class.equals(field.getType())) {
|
||||
value = emptyToNull((Collection<?>) value);
|
||||
}
|
||||
for (final AbstractField field : requiredComponents) {
|
||||
final Object value = getCurrentVaue(currentChangedComponent, newValue, field);
|
||||
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
// We need to loop through the entire loop for validity testing.
|
||||
// Otherwise the UI will only mark the
|
||||
// first field with errors and then stop. If there are several
|
||||
// fields with errors, this is bad.
|
||||
field.setValue(value);
|
||||
if (!field.isValid()) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
private static Object emptyToNull(final Collection<?> c) {
|
||||
return (c == null || c.isEmpty()) ? null : c;
|
||||
private boolean hasNullValidator(final Component component) {
|
||||
|
||||
if (component instanceof AbstractField<?>) {
|
||||
final AbstractField<?> fieldComponent = (AbstractField<?>) component;
|
||||
for (final Validator validator : fieldComponent.getValidators()) {
|
||||
if (validator instanceof NullValidator) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<AbstractField<?>> getAllComponents(final AbstractLayout abstractLayout) {
|
||||
@@ -329,6 +345,10 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
if (c instanceof AbstractField) {
|
||||
components.add((AbstractField<?>) c);
|
||||
}
|
||||
|
||||
if (c instanceof FlexibleOptionGroupItemComponent) {
|
||||
components.add(((FlexibleOptionGroupItemComponent) c).getOwner());
|
||||
}
|
||||
}
|
||||
return components;
|
||||
}
|
||||
@@ -374,7 +394,9 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
FontAwesome.TIMES, SPUIButtonStyleBorderWithIcon.class);
|
||||
cancelButton.setSizeUndefined();
|
||||
cancelButton.addStyleName("default-color");
|
||||
cancelButton.addClickListener(cancelButtonClickListener);
|
||||
if (cancelButtonClickListener != null) {
|
||||
cancelButton.addClickListener(cancelButtonClickListener);
|
||||
}
|
||||
|
||||
buttonsLayout.addComponent(cancelButton);
|
||||
buttonsLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_LEFT);
|
||||
@@ -419,7 +441,6 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
@Override
|
||||
public void textChange(final TextChangeEvent event) {
|
||||
saveButton.setEnabled(isSaveButtonEnabledAfterValueChange(field, event.getText()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -436,7 +457,6 @@ public class CommonDialogWindow extends Window implements Serializable {
|
||||
saveButton.setEnabled(
|
||||
isSaveButtonEnabledAfterValueChange(table, table.getContainerDataSource().getItemIds()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.distributions.disttype;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -49,8 +48,6 @@ import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Table;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.components.colorpicker.ColorChangeListener;
|
||||
import com.vaadin.ui.components.colorpicker.ColorSelector;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
@@ -58,8 +55,7 @@ import com.vaadin.ui.themes.ValoTheme;
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
implements ColorChangeListener, ColorSelector {
|
||||
public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout {
|
||||
|
||||
private static final long serialVersionUID = -5169398523815877767L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CreateUpdateDistSetTypeLayout.class);
|
||||
@@ -259,9 +255,6 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
for (final Long id : selectedIds) {
|
||||
addTargetTableData(id);
|
||||
}
|
||||
// TODO: Add Table to window
|
||||
// window.updateRequiredFields(selectedTable.getId(),
|
||||
// hasContentChanged());
|
||||
}
|
||||
|
||||
private void removeSMType() {
|
||||
@@ -274,40 +267,9 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
for (final Long id : selectedIds) {
|
||||
addSourceTableData(id);
|
||||
selectedTable.removeItem(id);
|
||||
// window.updateRequiredFields(selectedTable.getId(),
|
||||
// hasContentChanged());
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean hasContentChanged() {
|
||||
|
||||
if (originalSelectedTableContainer == null) {
|
||||
originalSelectedTableContainer = new IndexedContainer();
|
||||
}
|
||||
// is new softwareModule added?
|
||||
for (final Iterator itemIterator = selectedTableContainer.getItemIds().iterator(); itemIterator.hasNext();) {
|
||||
final long itemId = (Long) itemIterator.next();
|
||||
if (!originalSelectedTableContainer.containsId(itemId)) {
|
||||
// window.updateEditedFields(selectedTable.getId(),
|
||||
// Boolean.TRUE);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// is softwareModule removed and at least one softwareModule is selected
|
||||
for (final Iterator itemIterator = originalSelectedTableContainer.getItemIds().iterator(); itemIterator
|
||||
.hasNext();) {
|
||||
final long itemId = (Long) itemIterator.next();
|
||||
if (selectedTableContainer.size() > 0 && !selectedTableContainer.containsId(itemId)) {
|
||||
// window.updateEditedFields(selectedTable.getId(),
|
||||
// Boolean.TRUE);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void getSourceTableData() {
|
||||
|
||||
@@ -402,10 +364,8 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
newDistType.setColour(colorPicked);
|
||||
newDistType = distributionSetManagement.createDistributionSetType(newDistType);
|
||||
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { newDistType.getName() }));
|
||||
closeWindow();
|
||||
eventBus.publish(this,
|
||||
new DistributionSetTypeEvent(DistributionSetTypeEnum.ADD_DIST_SET_TYPE, newDistType));
|
||||
|
||||
} else {
|
||||
uiNotification.displayValidationError(i18n.get("message.error.missing.typenameorkey"));
|
||||
}
|
||||
@@ -445,7 +405,6 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
distributionSetManagement.updateDistributionSetType(updateDistSetType);
|
||||
uiNotification
|
||||
.displaySuccess(i18n.get("message.update.success", new Object[] { updateDistSetType.getName() }));
|
||||
closeWindow();
|
||||
eventBus.publish(this,
|
||||
new DistributionSetTypeEvent(DistributionSetTypeEnum.UPDATE_DIST_SET_TYPE, updateDistSetType));
|
||||
|
||||
@@ -480,18 +439,6 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
return distSetType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColorChangeListener(final ColorChangeListener listener) {
|
||||
|
||||
LOG.info("in side addColorChangeListener() ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColorChangeListener(final ColorChangeListener listener) {
|
||||
|
||||
LOG.info("in side removeColorChangeListener() ");
|
||||
}
|
||||
|
||||
/**
|
||||
* reset the components.
|
||||
*/
|
||||
@@ -515,7 +462,6 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
super.optionValueChanged(event);
|
||||
|
||||
if (updateTypeStr.equals(event.getProperty().getValue())) {
|
||||
// window.updateRequiredFields(selectedTable.getId(), Boolean.TRUE);
|
||||
selectedTable.getContainerDataSource().removeAllItems();
|
||||
getSourceTableData();
|
||||
distTypeSelectLayout.setEnabled(false);
|
||||
@@ -616,6 +562,8 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
sourceTable.removeItem(swModuleType.getId());
|
||||
saveTblitem.getItemProperty(DIST_TYPE_NAME).setValue(swModuleType.getName());
|
||||
saveTblitem.getItemProperty(DIST_TYPE_MANDATORY).setValue(new CheckBox("", mandatory));
|
||||
|
||||
// TODO CHECKBOX
|
||||
final CheckBox mandatoryCheckbox = (CheckBox) selectedTableContainer
|
||||
.getContainerProperty(swModuleType.getId(), DIST_TYPE_MANDATORY).getValue();
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.eclipse.hawkbit.ui.utils.UINotification;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.vaadin.data.Property.ValueChangeEvent;
|
||||
import com.vaadin.data.Property.ValueChangeListener;
|
||||
import com.vaadin.server.Page;
|
||||
@@ -335,7 +334,6 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
colorPickerLayout.setSelectedColor(colorPickerLayout.getDefaultColor());
|
||||
colorPickerLayout.getSelPreview().setColor(colorPickerLayout.getSelectedColor());
|
||||
tagPreviewBtnClicked = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,11 +425,6 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
|
||||
}
|
||||
|
||||
protected void closeWindow() {
|
||||
window.close();
|
||||
UI.getCurrent().removeWindow(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* create option group with Create tag/Update tag based on permissions.
|
||||
*/
|
||||
@@ -463,14 +456,6 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColorChangeListener(final ColorChangeListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColorChangeListener(final ColorChangeListener listener) {
|
||||
}
|
||||
|
||||
public ColorPickerLayout getColorPickerLayout() {
|
||||
return colorPickerLayout;
|
||||
}
|
||||
@@ -554,7 +539,6 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
tagManagement.updateDistributionSetTag((DistributionSetTag) targetObj);
|
||||
}
|
||||
uiNotification.displaySuccess(i18n.get("message.update.success", new Object[] { targetObj.getName() }));
|
||||
closeWindow();
|
||||
} else {
|
||||
uiNotification.displayValidationError(i18n.get("message.tag.update.mandatory"));
|
||||
}
|
||||
@@ -576,27 +560,6 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
getPreviewButtonColor(previewColor);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected Boolean mandatoryValuesPresent() {
|
||||
if (Strings.isNullOrEmpty(tagName.getValue())) {
|
||||
if (optiongroup.getValue().equals(createTagStr)) {
|
||||
displayValidationError(SPUILabelDefinitions.MISSING_TAG_NAME);
|
||||
}
|
||||
if (optiongroup.getValue().equals(updateTagStr)) {
|
||||
if (null == tagNameComboBox.getValue()) {
|
||||
displayValidationError(i18n.get(MESSAGE_ERROR_MISSING_TAGNAME));
|
||||
} else {
|
||||
displayValidationError(SPUILabelDefinitions.MISSING_TAG_NAME);
|
||||
}
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
protected Boolean checkIsDuplicate(final Tag existingTag) {
|
||||
if (existingTag != null) {
|
||||
displayValidationError(i18n.get("message.tag.duplicate.check", new Object[] { existingTag.getName() }));
|
||||
@@ -637,4 +600,16 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
return mainLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColorChangeListener(final ColorChangeListener listener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColorChangeListener(final ColorChangeListener listener) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -179,11 +179,6 @@ public abstract class CreateUpdateTypeLayout extends AbstractCreateUpdateTagLayo
|
||||
createDynamicStyleForComponents(tagName, typeKey, tagDesc, colorPickedPreview);
|
||||
getColorPickerLayout().getColorSelect().setColor(getColorPickerLayout().getSelPreview().getColor());
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// window.checkColorChange(colorPickerLayout.getId(),
|
||||
// colorPickerLayout.getSelectedColor(),
|
||||
// getOriginalSelectedColor());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,6 @@ import com.vaadin.ui.CustomComponent;
|
||||
import com.vaadin.ui.FormLayout;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
@@ -192,7 +191,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
final String distSetTypeName = HawkbitCommonUtil
|
||||
.trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue());
|
||||
|
||||
if (mandatoryCheck(name, version, distSetTypeName) && duplicateCheck(name, version)) {
|
||||
if (duplicateCheck(name, version)) {
|
||||
final DistributionSet currentDS = distributionSetManagement.findDistributionSetByIdWithDetails(editDistId);
|
||||
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
|
||||
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
|
||||
@@ -210,7 +209,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
notificationMessage.displayValidationError(
|
||||
i18n.get("message.distribution.no.update", currentDS.getName() + ":" + currentDS.getVersion()));
|
||||
}
|
||||
closeThisWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +222,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
final String distSetTypeName = HawkbitCommonUtil
|
||||
.trimAndNullIfEmpty((String) distsetTypeNameComboBox.getValue());
|
||||
|
||||
if (mandatoryCheck(name, version, distSetTypeName) && duplicateCheck(name, version)) {
|
||||
if (duplicateCheck(name, version)) {
|
||||
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
|
||||
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
|
||||
DistributionSet newDist = entityFactory.generateDistributionSet();
|
||||
@@ -234,21 +232,11 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
|
||||
notificationMessage.displaySuccess(i18n.get("message.new.dist.save.success",
|
||||
new Object[] { newDist.getName(), newDist.getVersion() }));
|
||||
/* close the window */
|
||||
closeThisWindow();
|
||||
|
||||
eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.NEW_ENTITY, newDist));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close window.
|
||||
*/
|
||||
private void closeThisWindow() {
|
||||
window.close();
|
||||
UI.getCurrent().removeWindow(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Values for Distribution set.
|
||||
*
|
||||
@@ -292,45 +280,6 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mandatory Check.
|
||||
*
|
||||
* @param name
|
||||
* as String
|
||||
* @param version
|
||||
* as String
|
||||
* @param selectedJVM
|
||||
* as String
|
||||
* @param selectedAgentHub
|
||||
* as String
|
||||
* @param selectedOs
|
||||
* as String
|
||||
* @return boolean as flag
|
||||
*/
|
||||
private boolean mandatoryCheck(final String name, final String version, final String distSetTypeName) {
|
||||
|
||||
if (name == null || version == null || distSetTypeName == null) {
|
||||
if (name == null) {
|
||||
distNameTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
}
|
||||
if (version == null) {
|
||||
distVersionTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
}
|
||||
if (distSetTypeName == null) {
|
||||
distsetTypeNameComboBox.addStyleName(SPUIStyleDefinitions.SP_COMBOFIELD_ERROR);
|
||||
}
|
||||
notificationMessage.displayValidationError(i18n.get("message.mandatory.check"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void discardDistribution() {
|
||||
/* Just close this window */
|
||||
closeThisWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all the fields.
|
||||
*/
|
||||
@@ -377,8 +326,7 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
populateDistSetTypeNameCombo();
|
||||
populateValuesOfDistribution(editDistId);
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.dist"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveDistribution(), event -> discardDistribution(),
|
||||
null, formLayout, i18n);
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveDistribution(), null, null, formLayout, i18n);
|
||||
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.management.targettable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
@@ -40,7 +38,6 @@ import com.vaadin.ui.CustomComponent;
|
||||
import com.vaadin.ui.FormLayout;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
@@ -75,10 +72,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
private FormLayout formLayout;
|
||||
private CommonDialogWindow window;
|
||||
|
||||
private String originalTargetName;
|
||||
private String originalTargetDesc;
|
||||
private String originalControllerId;
|
||||
|
||||
/**
|
||||
* Initialize the Add Update Window Component for Target.
|
||||
*/
|
||||
@@ -139,10 +132,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
uINotification.displaySuccess(i18n.get("message.update.success", new Object[] { latestTarget.getName() }));
|
||||
// publishing through event bus
|
||||
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.UPDATED_ENTITY, latestTarget));
|
||||
|
||||
/* close the window */
|
||||
closeThisWindow();
|
||||
/* update details in table */
|
||||
}
|
||||
|
||||
private void saveTargetListner() {
|
||||
@@ -153,13 +142,9 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private void discardTargetListner() {
|
||||
closeThisWindow();
|
||||
}
|
||||
|
||||
private void addNewTarget() {
|
||||
final String newControlllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerIDTextField.getValue());
|
||||
if (mandatoryCheck(newControlllerId) && duplicateCheck(newControlllerId)) {
|
||||
if (duplicateCheck(newControlllerId)) {
|
||||
final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(nameTextField.getValue());
|
||||
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
|
||||
|
||||
@@ -176,27 +161,16 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
|
||||
/* display success msg */
|
||||
uINotification.displaySuccess(i18n.get("message.save.success", new Object[] { newTarget.getName() }));
|
||||
/* close the window */
|
||||
closeThisWindow();
|
||||
}
|
||||
}
|
||||
|
||||
public Window getWindow() {
|
||||
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("caption.add.new.target"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveTargetListner(),
|
||||
event -> discardTargetListner(), null, formLayout, i18n);
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveTargetListner(), null, null, formLayout, i18n);
|
||||
return window;
|
||||
}
|
||||
|
||||
private Map<String, Boolean> getEditedFields() {
|
||||
final Map<String, Boolean> editedFields = new HashMap<>();
|
||||
editedFields.put(controllerIDTextField.getId(), Boolean.FALSE);
|
||||
editedFields.put(nameTextField.getId(), Boolean.FALSE);
|
||||
editedFields.put(descTextArea.getId(), Boolean.FALSE);
|
||||
return editedFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all fields of Target Edit Window.
|
||||
*/
|
||||
@@ -208,17 +182,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
controllerIDTextField.clear();
|
||||
descTextArea.clear();
|
||||
editTarget = Boolean.FALSE;
|
||||
|
||||
originalControllerId = null;
|
||||
originalTargetDesc = null;
|
||||
originalTargetName = null;
|
||||
|
||||
}
|
||||
|
||||
private void closeThisWindow() {
|
||||
editTarget = Boolean.FALSE;
|
||||
window.close();
|
||||
UI.getCurrent().removeWindow(window);
|
||||
}
|
||||
|
||||
private void setTargetValues(final Target target, final String name, final String description) {
|
||||
@@ -226,16 +189,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
target.setDescription(description);
|
||||
}
|
||||
|
||||
private boolean mandatoryCheck(final String newControlllerId) {
|
||||
if (newControlllerId == null) {
|
||||
controllerIDTextField.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR);
|
||||
uINotification.displayValidationError("Mandatory details are missing");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean duplicateCheck(final String newControlllerId) {
|
||||
final Target existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim());
|
||||
if (existingTarget != null) {
|
||||
@@ -261,10 +214,6 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
if (target.getDescription() != null) {
|
||||
descTextArea.setValue(target.getDescription());
|
||||
}
|
||||
|
||||
originalTargetDesc = descTextArea.getValue();
|
||||
originalTargetName = nameTextField.getValue();
|
||||
originalControllerId = controllerIDTextField.getValue();
|
||||
window.addStyleName("target-update-window");
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,6 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa
|
||||
}
|
||||
newTargetTag = tagManagement.createTargetTag(newTargetTag);
|
||||
displaySuccess(newTargetTag.getName());
|
||||
closeWindow();
|
||||
} else {
|
||||
displayValidationError(i18n.get(MESSAGE_ERROR_MISSING_TAGNAME));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
@@ -58,8 +57,9 @@ import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Item;
|
||||
import com.vaadin.data.Property.ValueChangeEvent;
|
||||
import com.vaadin.data.Validator;
|
||||
import com.vaadin.data.util.converter.StringToIntegerConverter;
|
||||
import com.vaadin.data.validator.IntegerRangeValidator;
|
||||
import com.vaadin.data.validator.RegexpValidator;
|
||||
import com.vaadin.data.validator.NullValidator;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
@@ -69,7 +69,6 @@ import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.OptionGroup;
|
||||
import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
@@ -87,8 +86,6 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
|
||||
private static final String MESSAGE_ENTER_NUMBER = "message.enter.number";
|
||||
|
||||
private static final String NUMBER_REGEXP = "[-]?[0-9]*\\.?,?[0-9]+";
|
||||
|
||||
@Autowired
|
||||
private ActionTypeOptionGroupLayout actionTypeOptionGroupLayout;
|
||||
|
||||
@@ -146,6 +143,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
|
||||
private TextArea targetFilterQuery;
|
||||
|
||||
private final NullValidator nullValidator = new NullValidator(null, false);
|
||||
|
||||
/**
|
||||
* Create components and layout.
|
||||
*/
|
||||
@@ -157,10 +156,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
|
||||
public CommonDialogWindow getWindow(final Long rolloutId) {
|
||||
resetComponents();
|
||||
populateData(rolloutId);
|
||||
window = SPUIWindowDecorator.getWindow(i18n.get("caption.configure.rollout"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> onRolloutSave(), event -> onDiscard(),
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> onRolloutSave(), null,
|
||||
uiProperties.getLinks().getDocumentation().getRolloutView(), this, i18n);
|
||||
populateData(rolloutId);
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -207,33 +206,34 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
|
||||
addComponent(getMandatoryLabel("textfield.name"), 0, 0);
|
||||
addComponent(rolloutName, 1, 0);
|
||||
rolloutName.setRequired(true);
|
||||
rolloutName.addValidator(nullValidator);
|
||||
|
||||
addComponent(getMandatoryLabel("prompt.distribution.set"), 0, 1);
|
||||
addComponent(distributionSet, 1, 1);
|
||||
distributionSet.setRequired(true);
|
||||
distributionSet.addValidator(nullValidator);
|
||||
|
||||
addComponent(getMandatoryLabel("prompt.target.filter"), 0, 2);
|
||||
addComponent(targetFilterQueryCombo, 1, 2);
|
||||
targetFilterQueryCombo.setRequired(true);
|
||||
targetFilterQueryCombo.addValidator(nullValidator);
|
||||
targetFilterQuery.removeValidator(nullValidator);
|
||||
|
||||
addComponent(totalTargetsLabel, 2, 2);
|
||||
|
||||
addComponent(getMandatoryLabel("prompt.number.of.groups"), 0, 3);
|
||||
addComponent(noOfGroups, 1, 3);
|
||||
noOfGroups.setRequired(true);
|
||||
noOfGroups.addValidator(nullValidator);
|
||||
|
||||
addComponent(groupSizeLabel, 2, 3);
|
||||
|
||||
addComponent(getMandatoryLabel("prompt.tigger.threshold"), 0, 4);
|
||||
addComponent(triggerThreshold, 1, 4);
|
||||
triggerThreshold.setRequired(true);
|
||||
triggerThreshold.addValidator(nullValidator);
|
||||
|
||||
addComponent(getPercentHintLabel(), 2, 4);
|
||||
|
||||
addComponent(getMandatoryLabel("prompt.error.threshold"), 0, 5);
|
||||
addComponent(errorThreshold, 1, 5);
|
||||
errorThreshold.setRequired(true);
|
||||
errorThreshold.addValidator(nullValidator);
|
||||
addComponent(errorThresholdOptionGroup, 2, 5);
|
||||
|
||||
addComponent(getLabel("textfield.description"), 0, 6);
|
||||
@@ -386,10 +386,6 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
targetFilterQF);
|
||||
}
|
||||
|
||||
private void onDiscard() {
|
||||
closeThisWindow();
|
||||
}
|
||||
|
||||
private void onRolloutSave() {
|
||||
if (editRolloutEnabled) {
|
||||
editRollout();
|
||||
@@ -399,7 +395,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
}
|
||||
|
||||
private void editRollout() {
|
||||
if (mandatoryCheckForEdit() && validateFields() && duplicateCheckForEdit() && null != rolloutForEdit) {
|
||||
if (duplicateCheckForEdit() && rolloutForEdit != null) {
|
||||
rolloutForEdit.setName(rolloutName.getValue());
|
||||
rolloutForEdit.setDescription(description.getValue());
|
||||
final DistributionSetIdName distributionSetIdName = (DistributionSetIdName) distributionSet.getValue();
|
||||
@@ -417,7 +413,6 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
final Rollout updatedRollout = rolloutManagement.updateRollout(rolloutForEdit);
|
||||
uiNotification
|
||||
.displaySuccess(i18n.get("message.update.success", new Object[] { updatedRollout.getName() }));
|
||||
closeThisWindow();
|
||||
eventBus.publish(this, RolloutEvent.UPDATE_ROLLOUT);
|
||||
}
|
||||
}
|
||||
@@ -445,11 +440,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
}
|
||||
|
||||
private void createRollout() {
|
||||
if (mandatoryCheck() && validateFields() && duplicateCheck()) {
|
||||
if (duplicateCheck()) {
|
||||
final Rollout rolloutToCreate = saveRollout();
|
||||
uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { rolloutToCreate.getName() }));
|
||||
eventBus.publish(this, RolloutEvent.CREATE_ROLLOUT);
|
||||
closeThisWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,48 +500,6 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void closeThisWindow() {
|
||||
window.close();
|
||||
UI.getCurrent().removeWindow(window);
|
||||
}
|
||||
|
||||
private boolean mandatoryCheck() {
|
||||
final DistributionSetIdName ds = getDistributionSetSelected();
|
||||
final String targetFilter = (String) targetFilterQueryCombo.getValue();
|
||||
final String triggerThresoldValue = triggerThreshold.getValue();
|
||||
final String errorThresoldValue = errorThreshold.getValue();
|
||||
if (hasNoNameOrTargetFilter(targetFilter) || ds == null
|
||||
|| HawkbitCommonUtil.trimAndNullIfEmpty(noOfGroups.getValue()) == null
|
||||
|| isThresholdValueMissing(triggerThresoldValue, errorThresoldValue)) {
|
||||
uiNotification.displayValidationError(i18n.get("message.mandatory.check"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean mandatoryCheckForEdit() {
|
||||
final DistributionSetIdName ds = getDistributionSetSelected();
|
||||
final String targetFilter = targetFilterQuery.getValue();
|
||||
final String triggerThresoldValue = triggerThreshold.getValue();
|
||||
final String errorThresoldValue = errorThreshold.getValue();
|
||||
if (hasNoNameOrTargetFilter(targetFilter) || ds == null
|
||||
|| HawkbitCommonUtil.trimAndNullIfEmpty(noOfGroups.getValue()) == null
|
||||
|| isThresholdValueMissing(triggerThresoldValue, errorThresoldValue)) {
|
||||
uiNotification.displayValidationError(i18n.get("message.mandatory.check"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasNoNameOrTargetFilter(final String targetFilter) {
|
||||
return getRolloutName() == null || targetFilter == null;
|
||||
}
|
||||
|
||||
private boolean isThresholdValueMissing(final String triggerThresoldValue, final String errorThresoldValue) {
|
||||
return HawkbitCommonUtil.trimAndNullIfEmpty(triggerThresoldValue) == null
|
||||
|| HawkbitCommonUtil.trimAndNullIfEmpty(errorThresoldValue) == null;
|
||||
}
|
||||
|
||||
private boolean duplicateCheck() {
|
||||
if (rolloutManagement.findRolloutByName(getRolloutName()) != null) {
|
||||
uiNotification.displayValidationError(
|
||||
@@ -573,7 +525,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
|
||||
private TextField createErrorThreshold() {
|
||||
final TextField errorField = getTextfield("prompt.error.threshold");
|
||||
errorField.setNullRepresentation("");
|
||||
errorField.addValidator(new ThresholdFieldValidator());
|
||||
errorField.setConverter(new StringToIntegerConverter());
|
||||
errorField.setConversionError(i18n.get(MESSAGE_ENTER_NUMBER));
|
||||
errorField.setId(SPUIComponentIdProvider.ROLLOUT_ERROR_THRESOLD_ID);
|
||||
errorField.setMaxLength(7);
|
||||
errorField.setSizeUndefined();
|
||||
@@ -583,7 +538,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
private TextField createTriggerThreshold() {
|
||||
final TextField thresholdField = getTextfield("prompt.tigger.threshold");
|
||||
thresholdField.setId(SPUIComponentIdProvider.ROLLOUT_TRIGGER_THRESOLD_ID);
|
||||
thresholdField.setNullRepresentation("");
|
||||
thresholdField.addValidator(new ThresholdFieldValidator());
|
||||
thresholdField.setConverter(new StringToIntegerConverter());
|
||||
thresholdField.setConversionError(i18n.get(MESSAGE_ENTER_NUMBER));
|
||||
thresholdField.setSizeUndefined();
|
||||
thresholdField.setMaxLength(3);
|
||||
return thresholdField;
|
||||
@@ -595,12 +553,15 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
noOfGroupsField.addValidator(new GroupNumberValidator());
|
||||
noOfGroupsField.setSizeUndefined();
|
||||
noOfGroupsField.setMaxLength(3);
|
||||
noOfGroupsField.setConverter(new StringToIntegerConverter());
|
||||
noOfGroupsField.setConversionError(i18n.get(MESSAGE_ENTER_NUMBER));
|
||||
noOfGroupsField.addValueChangeListener(this::onGroupNumberChange);
|
||||
noOfGroupsField.setNullRepresentation("");
|
||||
return noOfGroupsField;
|
||||
}
|
||||
|
||||
private void onGroupNumberChange(final ValueChangeEvent event) {
|
||||
if (noOfGroups.isValid() && !Strings.isNullOrEmpty(noOfGroups.getValue())) {
|
||||
if (event.getProperty().getValue() != null && noOfGroups.isValid()) {
|
||||
groupSizeLabel.setValue(getTargetPerGroupMessage(String.valueOf(getGroupSize())));
|
||||
groupSizeLabel.setVisible(true);
|
||||
} else {
|
||||
@@ -643,10 +604,6 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
return HawkbitCommonUtil.trimAndNullIfEmpty(rolloutName.getValue());
|
||||
}
|
||||
|
||||
private DistributionSetIdName getDistributionSetSelected() {
|
||||
return (DistributionSetIdName) distributionSet.getValue();
|
||||
}
|
||||
|
||||
class ErrorThresoldOptionValidator implements Validator {
|
||||
private static final long serialVersionUID = 9049939751976326550L;
|
||||
|
||||
@@ -659,8 +616,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
uiNotification
|
||||
.displayValidationError(i18n.get("message.rollout.noofgroups.or.targetfilter.missing"));
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(value.toString())) {
|
||||
new RegexpValidator(NUMBER_REGEXP, i18n.get(MESSAGE_ENTER_NUMBER)).validate(value);
|
||||
if (value != null) {
|
||||
final int groupSize = getGroupSize();
|
||||
new IntegerRangeValidator(i18n.get(MESSAGE_ROLLOUT_FIELD_VALUE_RANGE, 0, groupSize), 0,
|
||||
groupSize).validate(Integer.valueOf(value.toString()));
|
||||
@@ -670,8 +626,12 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
// suppress the need of preserve original exception, will blow
|
||||
// up the
|
||||
// log and not necessary here
|
||||
catch (@SuppressWarnings("squid:S1166") final InvalidValueException ex) {
|
||||
LOG.error(ex.getMessage());
|
||||
catch (
|
||||
|
||||
@SuppressWarnings("squid:S1166") final InvalidValueException ex) {
|
||||
// we have to throw the exception here, otherwise the UI won't
|
||||
// show the vaadin validation error!
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -686,8 +646,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
@Override
|
||||
public void validate(final Object value) {
|
||||
try {
|
||||
if (StringUtils.isNotBlank(value.toString())) {
|
||||
new RegexpValidator(NUMBER_REGEXP, i18n.get(MESSAGE_ENTER_NUMBER)).validate(value);
|
||||
if (value != null) {
|
||||
new IntegerRangeValidator(i18n.get(MESSAGE_ROLLOUT_FIELD_VALUE_RANGE, 0, 100), 0, 100)
|
||||
.validate(Integer.valueOf(value.toString()));
|
||||
}
|
||||
@@ -696,7 +655,9 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
// up the
|
||||
// log and not necessary here
|
||||
catch (@SuppressWarnings("squid:S1166") final InvalidValueException ex) {
|
||||
LOG.error(ex.getMessage());
|
||||
// we have to throw the exception here, otherwise the UI won't
|
||||
// show the vaadin validation error!
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -707,8 +668,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
@Override
|
||||
public void validate(final Object value) {
|
||||
try {
|
||||
if (StringUtils.isNotBlank(value.toString())) {
|
||||
new RegexpValidator(NUMBER_REGEXP, i18n.get(MESSAGE_ENTER_NUMBER)).validate(value);
|
||||
if (value != null) {
|
||||
new IntegerRangeValidator(i18n.get(MESSAGE_ROLLOUT_FIELD_VALUE_RANGE, 0, 500), 0, 500)
|
||||
.validate(Integer.valueOf(value.toString()));
|
||||
}
|
||||
@@ -717,7 +677,9 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
// up the
|
||||
// log and not necessary here
|
||||
catch (@SuppressWarnings("squid:S1166") final InvalidValueException ex) {
|
||||
LOG.error(ex.getMessage());
|
||||
// we have to throw the exception here, otherwise the UI won't
|
||||
// show the vaadin validation error!
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -749,7 +711,9 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
noOfGroups.setEnabled(false);
|
||||
targetFilterQuery.setValue(rolloutForEdit.getTargetFilterQuery());
|
||||
removeComponent(1, 2);
|
||||
targetFilterQueryCombo.removeValidator(nullValidator);
|
||||
addComponent(targetFilterQuery, 1, 2);
|
||||
targetFilterQuery.addValidator(nullValidator);
|
||||
|
||||
totalTargetsCount = targetManagement.countTargetByTargetFilterQuery(rolloutForEdit.getTargetFilterQuery());
|
||||
totalTargetsLabel.setValue(getTotalTargetMessage());
|
||||
@@ -795,7 +759,7 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
* @param rolloutGroups
|
||||
*/
|
||||
private void setThresholdValues(final List<RolloutGroup> rolloutGroups) {
|
||||
if (null != rolloutGroups && !rolloutGroups.isEmpty()) {
|
||||
if (rolloutGroups != null && !rolloutGroups.isEmpty()) {
|
||||
errorThreshold.setValue(rolloutGroups.get(0).getErrorConditionExp());
|
||||
triggerThreshold.setValue(rolloutGroups.get(0).getSuccessConditionExp());
|
||||
noOfGroups.setValue(String.valueOf(rolloutGroups.size()));
|
||||
|
||||
Reference in New Issue
Block a user