Enable save button if all mandatory fields are filled (softwareModule)
Signed-off-by: Melanie Retter <melanie.retter@bosch-si.com>
This commit is contained in:
@@ -9,7 +9,11 @@
|
||||
package org.eclipse.hawkbit.ui.artifacts.smtable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -29,10 +33,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
|
||||
import com.vaadin.data.Property.ValueChangeEvent;
|
||||
import com.vaadin.event.FieldEvents.TextChangeEvent;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.AbstractField;
|
||||
import com.vaadin.ui.ComboBox;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.CustomComponent;
|
||||
import com.vaadin.ui.FormLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
@@ -129,12 +136,14 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
nameTextField = SPUIComponentProvider.getTextField(i18n.get("textfield.name"), "", ValoTheme.TEXTFIELD_TINY,
|
||||
true, null, i18n.get("textfield.name"), true, SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
nameTextField.setId(SPUIComponentIdProvider.SOFT_MODULE_NAME);
|
||||
nameTextField.addTextChangeListener(this::nameTextFieldChanged);
|
||||
|
||||
/* version text field */
|
||||
versionTextField = SPUIComponentProvider.getTextField(i18n.get("textfield.version"), "",
|
||||
ValoTheme.TEXTFIELD_TINY, true, null, i18n.get("textfield.version"), true,
|
||||
SPUILabelDefinitions.TEXT_FIELD_MAX_LENGTH);
|
||||
versionTextField.setId(SPUIComponentIdProvider.SOFT_MODULE_VERSION);
|
||||
versionTextField.addTextChangeListener(this::versionTextFieldChanged);
|
||||
|
||||
/* Vendor text field */
|
||||
vendorTextField = SPUIComponentProvider.getTextField(i18n.get("textfield.vendor"), "", ValoTheme.TEXTFIELD_TINY,
|
||||
@@ -159,15 +168,40 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
typeComboBox.setStyleName(SPUIDefinitions.COMBO_BOX_SPECIFIC_STYLE + " " + ValoTheme.COMBOBOX_TINY);
|
||||
typeComboBox.setNewItemsAllowed(Boolean.FALSE);
|
||||
typeComboBox.setImmediate(Boolean.TRUE);
|
||||
typeComboBox.addValueChangeListener(this::typeComboBoxChanged);
|
||||
|
||||
populateTypeNameCombo();
|
||||
|
||||
resetOldValues();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void nameTextFieldChanged(final TextChangeEvent event) {
|
||||
if (StringUtils.isNotBlank(event.getText())) {
|
||||
window.getRequiredFields().put(nameTextField.getCaption(), Boolean.TRUE);
|
||||
} else {
|
||||
window.getRequiredFields().put(nameTextField.getCaption(), Boolean.FALSE);
|
||||
}
|
||||
window.checkMandatoryFields();
|
||||
}
|
||||
|
||||
private void versionTextFieldChanged(final TextChangeEvent event) {
|
||||
if (StringUtils.isNotBlank(event.getText())) {
|
||||
window.getRequiredFields().put(versionTextField.getCaption(), Boolean.TRUE);
|
||||
} else {
|
||||
window.getRequiredFields().put(versionTextField.getCaption(), Boolean.FALSE);
|
||||
}
|
||||
window.checkMandatoryFields();
|
||||
}
|
||||
|
||||
private void typeComboBoxChanged(final ValueChangeEvent event) {
|
||||
if (event.getProperty().getValue() != null) {
|
||||
window.getRequiredFields().put(typeComboBox.getCaption(), Boolean.TRUE);
|
||||
} else {
|
||||
window.getRequiredFields().put(typeComboBox.getCaption(), Boolean.FALSE);
|
||||
}
|
||||
window.checkMandatoryFields();
|
||||
}
|
||||
|
||||
private void populateTypeNameCombo() {
|
||||
typeComboBox.setContainerDataSource(HawkbitCommonUtil.createLazyQueryContainer(
|
||||
new BeanQueryFactory<SoftwareModuleTypeBeanQuery>(SoftwareModuleTypeBeanQuery.class)));
|
||||
@@ -180,10 +214,6 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
oldVendorValue = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the window content and get an instance of customDialogWindow
|
||||
*
|
||||
*/
|
||||
private void createWindow() {
|
||||
|
||||
final Label madatoryStarLabel = new Label("*");
|
||||
@@ -197,7 +227,7 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
addStyleName("lay-color");
|
||||
|
||||
final FormLayout formLayout = new FormLayout();
|
||||
formLayout.addComponent(mandatoryLabel);
|
||||
// formLayout.addComponent(mandatoryLabel);
|
||||
formLayout.addComponent(typeComboBox);
|
||||
formLayout.addComponent(nameTextField);
|
||||
formLayout.addComponent(versionTextField);
|
||||
@@ -208,11 +238,31 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se
|
||||
|
||||
/* add main layout to the window */
|
||||
window = SPUIComponentProvider.getWindow(i18n.get("upload.caption.add.new.swmodule"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveOrUpdate(), event -> closeThisWindow(), null);
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveOrUpdate(), event -> closeThisWindow(), null,
|
||||
getMandatoryFields(formLayout));
|
||||
window.getButtonsLayout().removeStyleName("actionButtonsMargin");
|
||||
nameTextField.focus();
|
||||
}
|
||||
|
||||
private Map<String, Boolean> getMandatoryFields(final FormLayout formLayout) {
|
||||
final Map<String, Boolean> requiredFields = new HashMap<>();
|
||||
final Iterator<Component> iterate = formLayout.iterator();
|
||||
while (iterate.hasNext()) {
|
||||
final Component c = iterate.next();
|
||||
if (c instanceof AbstractField && ((AbstractField) c).isRequired()) {
|
||||
requiredFields.put(c.getCaption(), null);
|
||||
}
|
||||
// else if (c instanceof TextField && ((TextField) c).isRequired())
|
||||
// {
|
||||
// requiredFields.put(c.getCaption(), null);
|
||||
// } else if (c instanceof TextArea && ((TextArea) c).isRequired())
|
||||
// {
|
||||
// requiredFields.put(c.getCaption(), null);
|
||||
// }
|
||||
}
|
||||
return requiredFields;
|
||||
}
|
||||
|
||||
private void addDescriptionTextChangeListener() {
|
||||
descTextArea.addTextChangeListener(event -> window.setSaveButtonEnabled(hasDescriptionChanged(event)));
|
||||
}
|
||||
|
||||
@@ -112,11 +112,13 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout
|
||||
getFormLayout().addComponent(assignOptiongroup);
|
||||
}
|
||||
|
||||
// TODO MR requiredFields
|
||||
|
||||
@Override
|
||||
public void createWindow() {
|
||||
reset();
|
||||
window = SPUIComponentProvider.getWindow(i18n.get("caption.add.type"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, this::save, this::discard, null);
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, this::save, this::discard, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,29 +10,38 @@ package org.eclipse.hawkbit.ui.common;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
|
||||
import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleBorderWithIcon;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.vaadin.data.Property.ValueChangeListener;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
import com.vaadin.spring.annotation.ViewScope;
|
||||
import com.vaadin.ui.AbstractOrderedLayout;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Button;
|
||||
import com.vaadin.ui.Button.ClickListener;
|
||||
import com.vaadin.ui.Component;
|
||||
import com.vaadin.ui.HorizontalLayout;
|
||||
import com.vaadin.ui.Label;
|
||||
import com.vaadin.ui.Link;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
import com.vaadin.ui.Window;
|
||||
import com.vaadin.ui.themes.ValoTheme;
|
||||
|
||||
/**
|
||||
*
|
||||
* Superclass for pop-up-windows including a minimize and close icon in the
|
||||
* upper right corner and a save and cancel button at the bottom.
|
||||
*
|
||||
*/
|
||||
@SpringComponent
|
||||
@ViewScope
|
||||
public class CommonDialogWindow extends Window {
|
||||
|
||||
private static final long serialVersionUID = -1321949234316858703L;
|
||||
@@ -57,6 +66,11 @@ public class CommonDialogWindow extends Window {
|
||||
|
||||
private final ClickListener cancelButtonClickListener;
|
||||
|
||||
private Map<String, Boolean> requiredFields;
|
||||
|
||||
@Autowired
|
||||
private I18N i18n;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -72,7 +86,8 @@ public class CommonDialogWindow extends Window {
|
||||
* the cancelButtonClickListener
|
||||
*/
|
||||
public CommonDialogWindow(final String caption, final Component content, final String helpLink,
|
||||
final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener) {
|
||||
final ClickListener saveButtonClickListener, final ClickListener cancelButtonClickListener,
|
||||
final Map<String, Boolean> requiredFields) {
|
||||
checkNotNull(saveButtonClickListener);
|
||||
checkNotNull(cancelButtonClickListener);
|
||||
this.caption = caption;
|
||||
@@ -80,10 +95,27 @@ public class CommonDialogWindow extends Window {
|
||||
this.helpLink = helpLink;
|
||||
this.saveButtonClickListener = saveButtonClickListener;
|
||||
this.cancelButtonClickListener = cancelButtonClickListener;
|
||||
this.requiredFields = requiredFields;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the mandatory fields in the pop-up-window content. If all
|
||||
* mandatory fields are filled the save button is enabled. Otherwise the
|
||||
* save button is disabled.
|
||||
*/
|
||||
public void checkMandatoryFields() {
|
||||
|
||||
for (final Map.Entry<String, Boolean> entry : requiredFields.entrySet()) {
|
||||
if (entry.getValue() == null || entry.getValue().equals(Boolean.FALSE)) {
|
||||
saveButton.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
saveButton.setEnabled(true);
|
||||
}
|
||||
|
||||
private final void init() {
|
||||
|
||||
if (content instanceof AbstractOrderedLayout) {
|
||||
@@ -94,6 +126,9 @@ public class CommonDialogWindow extends Window {
|
||||
if (null != content) {
|
||||
mainLayout.addComponent(content);
|
||||
}
|
||||
|
||||
createMandatoryLabel();
|
||||
|
||||
final HorizontalLayout buttonLayout = createActionButtonsLayout();
|
||||
mainLayout.addComponent(buttonLayout);
|
||||
mainLayout.setComponentAlignment(buttonLayout, Alignment.TOP_CENTER);
|
||||
@@ -122,6 +157,17 @@ public class CommonDialogWindow extends Window {
|
||||
return buttonsLayout;
|
||||
}
|
||||
|
||||
private void createMandatoryLabel() {
|
||||
|
||||
if (existsMandatoryFieldsInWindowContent()) {
|
||||
// final Label madatoryLabel = new
|
||||
// Label(i18n.get("label.mandatory.field"));
|
||||
final Label madatoryLabel = new Label("* Mandatory Field");
|
||||
madatoryLabel.addStyleName(SPUIStyleDefinitions.SP_TEXTFIELD_ERROR + " " + ValoTheme.LABEL_TINY);
|
||||
mainLayout.addComponent(madatoryLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void createCancelButton() {
|
||||
cancelButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.CANCEL_BUTTON, "Cancel", "", "", true,
|
||||
FontAwesome.TIMES, SPUIButtonStyleBorderWithIcon.class);
|
||||
@@ -140,11 +186,20 @@ public class CommonDialogWindow extends Window {
|
||||
saveButton.setSizeUndefined();
|
||||
saveButton.addStyleName("default-color");
|
||||
saveButton.addClickListener(saveButtonClickListener);
|
||||
saveButton.setEnabled(!existsMandatoryFieldsInWindowContent());
|
||||
buttonsLayout.addComponent(saveButton);
|
||||
buttonsLayout.setComponentAlignment(saveButton, Alignment.MIDDLE_RIGHT);
|
||||
buttonsLayout.setExpandRatio(saveButton, 1.0F);
|
||||
}
|
||||
|
||||
private boolean existsMandatoryFieldsInWindowContent() {
|
||||
|
||||
if (requiredFields != null && requiredFields.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addHelpLink() {
|
||||
|
||||
if (StringUtils.isEmpty(helpLink)) {
|
||||
@@ -167,4 +222,12 @@ public class CommonDialogWindow extends Window {
|
||||
return buttonsLayout;
|
||||
}
|
||||
|
||||
public Map<String, Boolean> getRequiredFields() {
|
||||
return requiredFields;
|
||||
}
|
||||
|
||||
public void setRequiredFields(final Map<String, Boolean> requiredFields) {
|
||||
this.requiredFields = requiredFields;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -153,9 +153,10 @@ public final class SPUIComponentProvider {
|
||||
*/
|
||||
public static CommonDialogWindow getWindow(final String caption, final String id, final String type,
|
||||
final Component content, final ClickListener saveButtonClickListener,
|
||||
final ClickListener cancelButtonClickListener, final String helpLink) {
|
||||
final ClickListener cancelButtonClickListener, final String helpLink,
|
||||
final Map<String, Boolean> requiredFields) {
|
||||
return SPUIWindowDecorator.getDeocratedWindow(caption, id, type, content, saveButtonClickListener,
|
||||
cancelButtonClickListener, helpLink);
|
||||
cancelButtonClickListener, helpLink, requiredFields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.decorators;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
@@ -44,10 +46,11 @@ public final class SPUIWindowDecorator {
|
||||
*/
|
||||
public static CommonDialogWindow getDeocratedWindow(final String caption, final String id, final String type,
|
||||
final Component content, final ClickListener saveButtonClickListener,
|
||||
final ClickListener cancelButtonClickListener, final String helpLink) {
|
||||
final ClickListener cancelButtonClickListener, final String helpLink,
|
||||
final Map<String, Boolean> requiredFields) {
|
||||
|
||||
final CommonDialogWindow window = new CommonDialogWindow(caption, content, helpLink, saveButtonClickListener,
|
||||
cancelButtonClickListener);
|
||||
cancelButtonClickListener, requiredFields);
|
||||
if (null != id) {
|
||||
window.setId(id);
|
||||
}
|
||||
|
||||
@@ -610,11 +610,12 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout
|
||||
}
|
||||
}
|
||||
|
||||
// TODO MR requiredFields
|
||||
@Override
|
||||
public void createWindow() {
|
||||
reset();
|
||||
window = SPUIComponentProvider.getWindow(i18n.get("caption.add.type"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, this::save, this::discard, null);
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, this::save, this::discard, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -105,10 +105,11 @@ public abstract class AbstractCreateUpdateTagLayout extends CustomComponent
|
||||
protected String tagNameValue;
|
||||
protected String tagDescValue;
|
||||
|
||||
// TODO MR requiredFields
|
||||
protected void createWindow() {
|
||||
reset();
|
||||
setWindow(SPUIComponentProvider.getWindow(i18n.get("caption.add.tag"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, this::save, this::discard, null));
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, this::save, this::discard, null, null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -504,13 +504,14 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO MR requiredFields
|
||||
public CommonDialogWindow getWindow() {
|
||||
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
||||
populateRequiredComponents();
|
||||
resetComponents();
|
||||
addDistributionWindow = SPUIComponentProvider.getWindow(i18n.get("caption.add.new.dist"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveDistribution(), event -> discardDistribution(),
|
||||
null);
|
||||
null, null);
|
||||
addDistributionWindow.getButtonsLayout().removeStyleName("actionButtonsMargin");
|
||||
|
||||
return addDistributionWindow;
|
||||
|
||||
@@ -241,10 +241,11 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO MR requiredFields
|
||||
public Window getWindow() {
|
||||
eventBus.publish(this, DragEvent.HIDE_DROP_HINT);
|
||||
window = SPUIComponentProvider.getWindow(i18n.get("caption.add.new.target"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveTargetListner(), event -> discardTargetListner(), null);
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> saveTargetListner(), event -> discardTargetListner(), null, null);
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
@@ -157,11 +157,12 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
|
||||
buildLayout();
|
||||
}
|
||||
|
||||
// TODO MR requiredFields
|
||||
public CommonDialogWindow getWindow() {
|
||||
|
||||
addUpdateRolloutWindow = SPUIComponentProvider.getWindow(i18n.get("caption.configure.rollout"), null,
|
||||
SPUIDefinitions.CREATE_UPDATE_WINDOW, this, event -> onRolloutSave(), event -> onDiscard(),
|
||||
uiProperties.getLinks().getDocumentation().getRolloutView());
|
||||
uiProperties.getLinks().getDocumentation().getRolloutView(), null);
|
||||
return addUpdateRolloutWindow;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user