Cleanup MaxFieldLength for UI text fields. (#676)

* Cleanup MaxFieldLength for Ui text fields.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Cleanup builder usage.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Code cleanup.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2018-04-27 09:21:22 +02:00
committed by GitHub
parent 63cf4598c2
commit fcc15a0484
23 changed files with 162 additions and 198 deletions

View File

@@ -20,7 +20,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.EmptyStringValidator;
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
@@ -211,20 +210,19 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
private void createRequiredComponents() {
nameTextField = createTextField("textfield.name", UIComponentIdProvider.SOFT_MODULE_NAME);
nameTextField.addValidator(new EmptyStringValidator(i18n));
nameTextField = createTextField("textfield.name", UIComponentIdProvider.SOFT_MODULE_NAME,
SoftwareModule.NAME_MAX_SIZE);
versionTextField = createTextField("textfield.version", UIComponentIdProvider.SOFT_MODULE_VERSION);
versionTextField.addValidator(new EmptyStringValidator(i18n));
versionTextField = createTextField("textfield.version", UIComponentIdProvider.SOFT_MODULE_VERSION,
SoftwareModule.VERSION_MAX_SIZE);
vendorTextField = createTextField("textfield.vendor", UIComponentIdProvider.SOFT_MODULE_VENDOR);
vendorTextField.setRequired(false);
vendorTextField.setNullRepresentation("");
descTextArea = new TextAreaBuilder().caption(i18n.getMessage("textfield.description")).style("text-area-style")
.prompt(i18n.getMessage("textfield.description")).id(UIComponentIdProvider.ADD_SW_MODULE_DESCRIPTION)
vendorTextField = new TextFieldBuilder(SoftwareModule.VENDOR_MAX_SIZE)
.caption(i18n.getMessage("textfield.vendor")).id(UIComponentIdProvider.SOFT_MODULE_VENDOR)
.buildTextComponent();
descTextArea.setNullRepresentation("");
descTextArea = new TextAreaBuilder(SoftwareModule.DESCRIPTION_MAX_SIZE)
.caption(i18n.getMessage("textfield.description")).style("text-area-style")
.id(UIComponentIdProvider.ADD_SW_MODULE_DESCRIPTION).buildTextComponent();
typeComboBox = SPUIComponentProvider.getComboBox(i18n.getMessage("upload.swmodule.type"), "", null, null, true,
null, i18n.getMessage("upload.swmodule.type"));
@@ -234,9 +232,9 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent {
typeComboBox.setImmediate(Boolean.TRUE);
}
private TextField createTextField(final String in18Key, final String id) {
return new TextFieldBuilder().caption(i18n.getMessage(in18Key)).required(true).prompt(i18n.getMessage(in18Key))
.immediate(true).id(id).buildTextComponent();
private TextField createTextField(final String in18Key, final String id, final int maxLength) {
return new TextFieldBuilder(maxLength).caption(i18n.getMessage(in18Key)).required(true, i18n).id(id)
.buildTextComponent();
}
private void populateTypeNameCombo() {

View File

@@ -20,7 +20,6 @@ import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
import org.eclipse.hawkbit.ui.common.EmptyStringValidator;
import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
@@ -101,15 +100,16 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
multiAssign = new LabelBuilder().name(multiAssignStr).buildLabel();
tagName = createTextField("textfield.name", SPUIDefinitions.TYPE_NAME, SPUIDefinitions.NEW_SOFTWARE_TYPE_NAME);
tagName = createTextField("textfield.name", SPUIDefinitions.TYPE_NAME, SPUIDefinitions.NEW_SOFTWARE_TYPE_NAME,
SoftwareModuleType.NAME_MAX_SIZE);
typeKey = createTextField("textfield.key", SPUIDefinitions.TYPE_KEY, SPUIDefinitions.NEW_SOFTWARE_TYPE_KEY);
typeKey = createTextField("textfield.key", SPUIDefinitions.TYPE_KEY, SPUIDefinitions.NEW_SOFTWARE_TYPE_KEY,
SoftwareModuleType.KEY_MAX_SIZE);
tagDesc = new TextAreaBuilder().caption(i18n.getMessage("textfield.description"))
tagDesc = new TextAreaBuilder(SoftwareModuleType.DESCRIPTION_MAX_SIZE)
.caption(i18n.getMessage("textfield.description"))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TYPE_DESC)
.prompt(i18n.getMessage("textfield.description")).immediate(true)
.id(SPUIDefinitions.NEW_SOFTWARE_TYPE_DESC).buildTextComponent();
tagDesc.setNullRepresentation("");
singleMultiOptionGroup();
}
@@ -127,10 +127,10 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout<Softw
return ColorPickerHelper.rgbToColorConverter(ColorPickerConstants.DEFAULT_COLOR);
}
private TextField createTextField(final String in18Key, final String styleName, final String id) {
return new TextFieldBuilder().caption(i18n.getMessage(in18Key))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + styleName).required(true).prompt(i18n.getMessage(in18Key))
.validator(new EmptyStringValidator(i18n)).immediate(true).id(id).buildTextComponent();
private TextField createTextField(final String in18Key, final String styleName, final String id,
final int maxLength) {
return new TextFieldBuilder(maxLength).caption(i18n.getMessage(in18Key))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + styleName).required(true, i18n).id(id).buildTextComponent();
}
@Override

View File

@@ -264,7 +264,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
}
private static TextField createTextField(final String id) {
return new TextFieldBuilder().immediate(true).id(id).buildTextComponent();
return new TextFieldBuilder(64).id(id).buildTextComponent();
}
private void addFileNameLayout(final Item newItem, final String baseSoftwareModuleNameVersion,

View File

@@ -236,10 +236,8 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
}
private TextField createKeyTextField() {
final TextField keyField = new TextFieldBuilder().caption(i18n.getMessage("textfield.key")).required(true)
.prompt(i18n.getMessage("textfield.key")).immediate(true)
.id(UIComponentIdProvider.METADATA_KEY_FIELD_ID).maxLengthAllowed(MetaData.KEY_MAX_SIZE)
.validator(new EmptyStringValidator(i18n)).buildTextComponent();
final TextField keyField = new TextFieldBuilder(MetaData.KEY_MAX_SIZE).caption(i18n.getMessage("textfield.key"))
.required(true, i18n).id(UIComponentIdProvider.METADATA_KEY_FIELD_ID).buildTextComponent();
keyField.addTextChangeListener(this::onKeyChange);
keyField.setTextChangeEventMode(TextChangeEventMode.EAGER);
keyField.setWidth("100%");
@@ -247,11 +245,8 @@ public abstract class AbstractMetadataPopupLayout<E extends NamedVersionedEntity
}
private TextArea createValueTextField() {
valueTextArea = new TextAreaBuilder().caption(i18n.getMessage("textfield.value")).required(true)
.validator(new EmptyStringValidator(i18n)).prompt(i18n.getMessage("textfield.value")).immediate(true)
.id(UIComponentIdProvider.METADATA_VALUE_ID).maxLengthAllowed(MetaData.VALUE_MAX_SIZE)
.buildTextComponent();
valueTextArea.setNullRepresentation("");
valueTextArea = new TextAreaBuilder(MetaData.VALUE_MAX_SIZE).caption(i18n.getMessage("textfield.value"))
.required(true, i18n).id(UIComponentIdProvider.METADATA_VALUE_ID).buildTextComponent();
valueTextArea.setSizeFull();
valueTextArea.setHeight(100, Unit.PERCENTAGE);
valueTextArea.addTextChangeListener(this::onValueChange);

View File

@@ -23,18 +23,6 @@ public class EmptyStringValidator extends StringLengthValidator {
private static final String MESSAGE_KEY = "validator.textfield.min.length";
private static final int TEXT_FIELD_DEFAULT_MAX_LENGTH = 64;
/**
* Constructor for EmptyStringValidator
*
* @param i18n
* {@link VaadinMessageSource}
*/
public EmptyStringValidator(final VaadinMessageSource i18n) {
super(i18n.getMessage(MESSAGE_KEY), 1, TEXT_FIELD_DEFAULT_MAX_LENGTH, false);
}
/**
* Constructor for EmptyStringValidator
*
@@ -44,12 +32,12 @@ public class EmptyStringValidator extends StringLengthValidator {
* max length of the textfield
*/
public EmptyStringValidator(final VaadinMessageSource i18n, final int maxLength) {
super(i18n.getMessage(MESSAGE_KEY), 1, maxLength, false);
super(i18n.getMessage(MESSAGE_KEY, maxLength), 1, maxLength, false);
}
@Override
public boolean isValid(final Object value) {
return super.isValid(value != null ? value.toString().trim() : null);
public boolean isValidValue(final String value) {
return super.isValidValue(value != null ? value.trim() : null);
}
}

View File

@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.ui.common.builder;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.hawkbit.ui.common.EmptyStringValidator;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
import org.springframework.util.StringUtils;
import com.vaadin.data.Validator;
@@ -18,32 +20,40 @@ import com.vaadin.ui.AbstractTextField;
/**
* Abstract Text field builder.
*
*
* @param <T>
* type of the builder
* @param <E>
* the concrete text component
* the text component
*
*/
public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
public abstract class AbstractTextFieldBuilder<T, E extends AbstractTextField> {
private String caption;
private String style;
private String styleName;
private String prompt;
private String id;
private boolean immediate;
private boolean immediate = true;
private boolean required;
private boolean readOnly;
private boolean enabled = true;
private int maxLengthAllowed;
private final int maxLengthAllowed;
private final List<Validator> validators = new LinkedList<>();
protected AbstractTextFieldBuilder(final int maxLengthAllowed) {
this.maxLengthAllowed = maxLengthAllowed;
}
/**
* @param caption
* the caption to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> caption(final String caption) {
public T caption(final String caption) {
this.caption = caption;
return this;
this.prompt = caption;
return (T) this;
}
/**
@@ -51,9 +61,9 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the style to set * @return the builder
* @return the builder
*/
public AbstractTextFieldBuilder<E> style(final String style) {
public T style(final String style) {
this.style = style;
return this;
return (T) this;
}
/**
@@ -61,19 +71,24 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the styleName to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> styleName(final String styleName) {
public T styleName(final String styleName) {
this.styleName = styleName;
return this;
return (T) this;
}
/**
* @param required
* the required to set
* @param i18n
* to translate error message
* @return the builder
*/
public AbstractTextFieldBuilder<E> required(final boolean required) {
public T required(final boolean required, final VaadinMessageSource i18n) {
this.required = required;
return this;
if (required) {
validators.add(new EmptyStringValidator(i18n, maxLengthAllowed));
}
return (T) this;
}
/**
@@ -81,9 +96,9 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the readOnly to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> readOnly(final boolean readOnly) {
public T readOnly(final boolean readOnly) {
this.readOnly = readOnly;
return this;
return (T) this;
}
/**
@@ -91,9 +106,9 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the enabled to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> enabled(final boolean enabled) {
public T enabled(final boolean enabled) {
this.enabled = enabled;
return this;
return (T) this;
}
/**
@@ -101,9 +116,9 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the prompt to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> prompt(final String prompt) {
public T prompt(final String prompt) {
this.prompt = prompt;
return this;
return (T) this;
}
/**
@@ -111,19 +126,9 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the immediate to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> immediate(final boolean immediate) {
public T immediate(final boolean immediate) {
this.immediate = immediate;
return this;
}
/**
* @param maxLengthAllowed
* the maxLengthAllowed to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> maxLengthAllowed(final int maxLengthAllowed) {
this.maxLengthAllowed = maxLengthAllowed;
return this;
return (T) this;
}
/**
@@ -131,9 +136,9 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the id to set
* @return the builder
*/
public AbstractTextFieldBuilder<E> id(final String id) {
public T id(final String id) {
this.id = id;
return this;
return (T) this;
}
/**
@@ -142,9 +147,9 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
* the validator to set for this field
* @return the builder
*/
public AbstractTextFieldBuilder<E> validator(final Validator validator) {
public T validator(final Validator validator) {
validators.add(validator);
return this;
return (T) this;
}
/**
@@ -187,6 +192,8 @@ public abstract class AbstractTextFieldBuilder<E extends AbstractTextField> {
validators.forEach(textComponent::addValidator);
}
textComponent.setNullRepresentation("");
return textComponent;
}

View File

@@ -15,15 +15,16 @@ import com.vaadin.ui.themes.ValoTheme;
* TextArea builder.
*
*/
public class TextAreaBuilder extends AbstractTextFieldBuilder<TextArea> {
private static final int TEXT_AREA_DEFAULT_MAX_LENGTH = 512;
public class TextAreaBuilder extends AbstractTextFieldBuilder<TextAreaBuilder, TextArea> {
/**
* Constructor.
*
* @param maxLengthAllowed
* for the text area
*/
public TextAreaBuilder() {
maxLengthAllowed(TEXT_AREA_DEFAULT_MAX_LENGTH);
public TextAreaBuilder(final int maxLengthAllowed) {
super(maxLengthAllowed);
styleName(ValoTheme.TEXTAREA_SMALL);
}

View File

@@ -18,24 +18,17 @@ import com.vaadin.ui.themes.ValoTheme;
* Textfield builder.
*
*/
public class TextFieldBuilder extends AbstractTextFieldBuilder<TextField> {
/**
* Constructor.
*/
public TextFieldBuilder() {
this(null);
}
public class TextFieldBuilder extends AbstractTextFieldBuilder<TextFieldBuilder, TextField> {
/**
* Constructor.
*
* @param id
* the id
* @param maxLengthAllowed
* as mandatory field
*/
public TextFieldBuilder(final String id) {
public TextFieldBuilder(final int maxLengthAllowed) {
super(maxLengthAllowed);
styleName(ValoTheme.TEXTAREA_TINY);
id(id);
}
/**

View File

@@ -73,7 +73,8 @@ public abstract class AbstractGridHeader extends VerticalLayout {
private void createComponents() {
headerCaptionLayout = getHeaderCaptionLayout();
if (isRollout()) {
searchField = new TextFieldBuilder(getSearchBoxId()).createSearchField(event -> searchBy(event.getText()));
searchField = new TextFieldBuilder(64).id(getSearchBoxId())
.createSearchField(event -> searchBy(event.getText()));
searchResetIcon = createSearchResetIcon();
addButton = createAddButton();
}

View File

@@ -87,7 +87,8 @@ public abstract class AbstractTableHeader extends VerticalLayout {
private void createComponents() {
headerCaption = createHeaderCaption();
searchField = new TextFieldBuilder(getSearchBoxId()).createSearchField(event -> searchBy(event.getText()));
searchField = new TextFieldBuilder(64).id(getSearchBoxId())
.createSearchField(event -> searchBy(event.getText()));
searchResetIcon = createSearchResetIcon();

View File

@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerConstants;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery;
import org.eclipse.hawkbit.ui.common.EmptyStringValidator;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
@@ -124,22 +123,21 @@ public class CreateUpdateDistSetTypeLayout extends CreateUpdateTypeLayout<Distri
super.createRequiredComponents();
tagName = createTextField("textfield.name", SPUIDefinitions.DIST_SET_TYPE_NAME,
SPUIDefinitions.NEW_DISTRIBUTION_TYPE_NAME);
SPUIDefinitions.NEW_DISTRIBUTION_TYPE_NAME, DistributionSetType.NAME_MAX_SIZE);
typeKey = createTextField("textfield.key", SPUIDefinitions.DIST_SET_TYPE_KEY,
SPUIDefinitions.NEW_DISTRIBUTION_TYPE_KEY);
SPUIDefinitions.NEW_DISTRIBUTION_TYPE_KEY, DistributionSetType.KEY_MAX_SIZE);
tagDesc = new TextAreaBuilder().caption(i18n.getMessage("textfield.description"))
tagDesc = new TextAreaBuilder(DistributionSetType.DESCRIPTION_MAX_SIZE)
.caption(i18n.getMessage("textfield.description"))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.DIST_SET_TYPE_DESC)
.prompt(i18n.getMessage("textfield.description")).immediate(true)
.id(SPUIDefinitions.NEW_DISTRIBUTION_TYPE_DESC).buildTextComponent();
tagDesc.setNullRepresentation("");
}
private TextField createTextField(final String in18Key, final String styleName, final String id) {
return new TextFieldBuilder().caption(i18n.getMessage(in18Key))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + styleName).required(true).prompt(i18n.getMessage(in18Key))
.validator(new EmptyStringValidator(i18n)).immediate(true).id(id).buildTextComponent();
private TextField createTextField(final String in18Key, final String styleName, final String id,
final int maxSize) {
return new TextFieldBuilder(maxSize).caption(i18n.getMessage(in18Key))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + styleName).required(true, i18n).id(id).buildTextComponent();
}
@Override

View File

@@ -15,11 +15,11 @@ import java.util.concurrent.Executor;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent;
import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider;
import org.springframework.beans.factory.annotation.Autowired;
@@ -195,12 +195,11 @@ public class AutoCompleteTextFieldComponent extends HorizontalLayout {
}
private TextField createSearchField() {
final TextField textField = new TextFieldBuilder().immediate(true).id(UIComponentIdProvider.CUSTOM_FILTER_QUERY)
.maxLengthAllowed(SPUILabelDefinitions.TARGET_FILTER_QUERY_TEXT_FIELD_LENGTH).buildTextComponent();
final TextField textField = new TextFieldBuilder(TargetFilterQuery.QUERY_MAX_SIZE)
.id(UIComponentIdProvider.CUSTOM_FILTER_QUERY).buildTextComponent();
textField.addStyleName("target-filter-textfield");
textField.setWidth(900.0F, Unit.PIXELS);
textField.setTextChangeEventMode(TextChangeEventMode.EAGER);
textField.setImmediate(true);
textField.setTextChangeTimeout(100);
return textField;
}

View File

@@ -12,6 +12,7 @@ import java.util.Optional;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.ui.SpPermissionChecker;
import org.eclipse.hawkbit.ui.UiProperties;
@@ -201,8 +202,8 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button
}
private TextField createNameTextField() {
final TextField nameField = new TextFieldBuilder().caption(i18n.getMessage("textfield.customfiltername"))
.prompt(i18n.getMessage("textfield.customfiltername")).immediate(true)
final TextField nameField = new TextFieldBuilder(NamedEntity.NAME_MAX_SIZE)
.caption(i18n.getMessage("textfield.customfiltername")).required(true, i18n)
.id(UIComponentIdProvider.CUSTOM_FILTER_ADD_NAME).buildTextComponent();
nameField.setPropertyDataSource(nameLabel);
nameField.addTextChangeListener(this::onFilterNameChange);
@@ -368,8 +369,8 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button
}
private void createTargetFilterQuery() {
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create(entityFactory
.targetFilterQuery().create().name(nameTextField.getValue()).query(queryTextField.getValue()));
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create(entityFactory.targetFilterQuery()
.create().name(nameTextField.getValue()).query(queryTextField.getValue()));
notification.displaySuccess(
i18n.getMessage("message.create.filter.success", new Object[] { targetFilterQuery.getName() }));
eventBus.publish(this, CustomFilterUIEvent.CREATE_TARGET_FILTER_QUERY);

View File

@@ -122,7 +122,8 @@ public class TargetFilterHeader extends VerticalLayout {
}
private TextField createSearchField() {
final TextField campSearchTextField = new TextFieldBuilder(UIComponentIdProvider.TARGET_FILTER_SEARCH_TEXT)
final TextField campSearchTextField = new TextFieldBuilder(64)
.id(UIComponentIdProvider.TARGET_FILTER_SEARCH_TEXT)
.createSearchField(event -> searchBy(event.getText()));
campSearchTextField.setWidth(500.0F, Unit.PIXELS);
return campSearchTextField;

View File

@@ -18,7 +18,6 @@ import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper;
import org.eclipse.hawkbit.ui.colorpicker.ColorPickerLayout;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.EmptyStringValidator;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
@@ -191,18 +190,15 @@ public abstract class AbstractCreateUpdateTagLayout<E extends NamedEntity> exten
colorLabel = new LabelBuilder().name(i18n.getMessage("label.choose.tag.color")).buildLabel();
colorLabel.addStyleName(SPUIDefinitions.COLOR_LABEL_STYLE);
tagName = new TextFieldBuilder().caption(i18n.getMessage("textfield.name"))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TAG_NAME).required(true)
.prompt(i18n.getMessage("textfield.name")).immediate(true).id(SPUIDefinitions.NEW_TARGET_TAG_NAME)
.validator(new EmptyStringValidator(i18n)).buildTextComponent();
tagName = new TextFieldBuilder(NamedEntity.NAME_MAX_SIZE).caption(i18n.getMessage("textfield.name"))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TAG_NAME).required(true, i18n)
.id(SPUIDefinitions.NEW_TARGET_TAG_NAME).buildTextComponent();
tagDesc = new TextAreaBuilder().caption(i18n.getMessage("textfield.description"))
tagDesc = new TextAreaBuilder(NamedEntity.DESCRIPTION_MAX_SIZE)
.caption(i18n.getMessage("textfield.description"))
.styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TAG_DESC)
.prompt(i18n.getMessage("textfield.description")).immediate(true)
.id(SPUIDefinitions.NEW_TARGET_TAG_DESC).buildTextComponent();
tagDesc.setNullRepresentation("");
tagNameComboBox = SPUIComponentProvider.getComboBox(null, "", null, null, false, "",
i18n.getMessage("label.combobox.tag"));
tagNameComboBox.addStyleName(SPUIDefinitions.FILTER_TYPE_COMBO_STYLE);

View File

@@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.model.TenantMetaData;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow;
import org.eclipse.hawkbit.ui.common.CommonDialogWindow.SaveDialogCloseListener;
import org.eclipse.hawkbit.ui.common.DistributionSetTypeBeanQuery;
import org.eclipse.hawkbit.ui.common.EmptyStringValidator;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.common.builder.WindowBuilder;
@@ -222,8 +221,10 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
* Create required UI components.
*/
private void createRequiredComponents() {
distNameTextField = createTextField("textfield.name", UIComponentIdProvider.DIST_ADD_NAME);
distVersionTextField = createTextField("textfield.version", UIComponentIdProvider.DIST_ADD_VERSION);
distNameTextField = createTextField("textfield.name", UIComponentIdProvider.DIST_ADD_NAME,
DistributionSet.NAME_MAX_SIZE);
distVersionTextField = createTextField("textfield.version", UIComponentIdProvider.DIST_ADD_VERSION,
DistributionSet.VERSION_MAX_SIZE);
distsetTypeNameComboBox = SPUIComponentProvider.getComboBox(i18n.getMessage("label.combobox.type"), "", null,
"", false, "", i18n.getMessage("label.combobox.type"));
@@ -231,10 +232,9 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
distsetTypeNameComboBox.setNullSelectionAllowed(false);
distsetTypeNameComboBox.setId(UIComponentIdProvider.DIST_ADD_DISTSETTYPE);
descTextArea = new TextAreaBuilder().caption(i18n.getMessage("textfield.description")).style("text-area-style")
.prompt(i18n.getMessage("textfield.description")).immediate(true)
descTextArea = new TextAreaBuilder(DistributionSet.DESCRIPTION_MAX_SIZE)
.caption(i18n.getMessage("textfield.description")).style("text-area-style")
.id(UIComponentIdProvider.DIST_ADD_DESC).buildTextComponent();
descTextArea.setNullRepresentation("");
reqMigStepCheckbox = SPUIComponentProvider.getCheckBox(i18n.getMessage("checkbox.dist.required.migration.step"),
"dist-checkbox-style", null, false, "");
@@ -242,12 +242,9 @@ public class DistributionAddUpdateWindowLayout extends CustomComponent {
reqMigStepCheckbox.setId(UIComponentIdProvider.DIST_ADD_MIGRATION_CHECK);
}
private TextField createTextField(final String in18Key, final String id) {
final TextField buildTextField = new TextFieldBuilder().caption(i18n.getMessage(in18Key)).required(true)
.validator(new EmptyStringValidator(i18n)).prompt(i18n.getMessage(in18Key)).immediate(true).id(id)
private TextField createTextField(final String in18Key, final String id, final int maxLength) {
return new TextFieldBuilder(maxLength).caption(i18n.getMessage(in18Key)).required(true, i18n).id(id)
.buildTextComponent();
buildTextField.setNullRepresentation("");
return buildTextField;
}
/**

View File

@@ -17,6 +17,7 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
import org.eclipse.hawkbit.repository.exception.InvalidMaintenanceScheduleException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.ui.common.builder.LabelBuilder;
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
@@ -83,9 +84,10 @@ public class MaintenanceWindowLayout extends VerticalLayout {
* Text field to specify the schedule.
*/
private void createMaintenanceScheduleControl() {
schedule = new TextFieldBuilder().id(UIComponentIdProvider.MAINTENANCE_WINDOW_SCHEDULE_ID)
.caption(i18n.getMessage("caption.maintenancewindow.schedule")).immediate(true)
.validator(new CronValidator()).prompt("0 0 3 ? * 6").required(true).buildTextComponent();
schedule = new TextFieldBuilder(Action.MAINTENANCE_SCHEDULE_CRON_LENGTH)
.id(UIComponentIdProvider.MAINTENANCE_WINDOW_SCHEDULE_ID)
.caption(i18n.getMessage("caption.maintenancewindow.schedule")).validator(new CronValidator())
.prompt("0 0 3 ? * 6").required(true, i18n).buildTextComponent();
schedule.addTextChangeListener(new CronTranslationListener());
}
@@ -148,9 +150,10 @@ public class MaintenanceWindowLayout extends VerticalLayout {
* Text field to specify the duration.
*/
private void createMaintenanceDurationControl() {
duration = new TextFieldBuilder().id(UIComponentIdProvider.MAINTENANCE_WINDOW_DURATION_ID)
.caption(i18n.getMessage("caption.maintenancewindow.duration")).immediate(true)
.validator(new DurationValidator()).prompt("hh:mm:ss").required(true).buildTextComponent();
duration = new TextFieldBuilder(Action.MAINTENANCE_WINDOW_DURATION_LENGTH)
.id(UIComponentIdProvider.MAINTENANCE_WINDOW_DURATION_ID)
.caption(i18n.getMessage("caption.maintenancewindow.duration")).validator(new DurationValidator())
.prompt("hh:mm:ss").required(true, i18n).buildTextComponent();
}
/**

View File

@@ -98,21 +98,18 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
}
private void createRequiredComponents() {
controllerIDTextField = createTextField("prompt.target.id", UIComponentIdProvider.TARGET_ADD_CONTROLLER_ID);
controllerIDTextField = new TextFieldBuilder(Target.CONTROLLER_ID_MAX_SIZE)
.caption(i18n.getMessage("prompt.target.id")).required(true, i18n)
.id(UIComponentIdProvider.TARGET_ADD_CONTROLLER_ID).buildTextComponent();
controllerIDTextField
.addValidator(new RegexpValidator("[.\\S]*", i18n.getMessage("message.target.whitespace.check")));
nameTextField = createTextField("textfield.name", UIComponentIdProvider.TARGET_ADD_NAME);
nameTextField = new TextFieldBuilder(Target.NAME_MAX_SIZE).caption(i18n.getMessage("textfield.name"))
.id(UIComponentIdProvider.TARGET_ADD_NAME).buildTextComponent();
nameTextField.setRequired(false);
descTextArea = new TextAreaBuilder().caption(i18n.getMessage("textfield.description")).style("text-area-style")
.prompt(i18n.getMessage("textfield.description")).immediate(true)
descTextArea = new TextAreaBuilder(Target.DESCRIPTION_MAX_SIZE)
.caption(i18n.getMessage("textfield.description")).style("text-area-style")
.id(UIComponentIdProvider.TARGET_ADD_DESC).buildTextComponent();
descTextArea.setNullRepresentation("");
}
private TextField createTextField(final String in18Key, final String id) {
return new TextFieldBuilder().caption(i18n.getMessage(in18Key)).required(true).prompt(i18n.getMessage(in18Key))
.immediate(true).id(id).buildTextComponent();
}
private void buildLayout() {

View File

@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TargetTagManagement;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.ui.SpPermissionChecker;
import org.eclipse.hawkbit.ui.UiProperties;
import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder;
@@ -98,9 +99,9 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
TargetBulkUpdateWindowLayout(final VaadinMessageSource i18n, final TargetManagement targetManagement,
final UIEventBus eventBus, final ManagementUIState managementUIState,
final DeploymentManagement deploymentManagement, final UiProperties uiproperties,
final SpPermissionChecker checker, final UINotification uinotification, final TargetTagManagement tagManagement,
final DistributionSetManagement distributionSetManagement, final EntityFactory entityFactory,
final Executor uiExecutor) {
final SpPermissionChecker checker, final UINotification uinotification,
final TargetTagManagement tagManagement, final DistributionSetManagement distributionSetManagement,
final EntityFactory entityFactory, final Executor uiExecutor) {
this.i18n = i18n;
this.targetManagement = targetManagement;
this.eventBus = eventBus;
@@ -194,10 +195,9 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
}
private TextArea getDescriptionTextArea() {
final TextArea description = new TextAreaBuilder().caption(i18n.getMessage("textfield.description"))
.style("text-area-style").prompt(i18n.getMessage("textfield.description")).immediate(true)
final TextArea description = new TextAreaBuilder(Target.DESCRIPTION_MAX_SIZE)
.caption(i18n.getMessage("textfield.description")).style("text-area-style")
.id(UIComponentIdProvider.BULK_UPLOAD_DESC).buildTextComponent();
description.setNullRepresentation("");
description.setWidth("100%");
return description;
}

View File

@@ -333,7 +333,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
private Long getScheduledStartTime() {
return AutoStartOptionGroupLayout.AutoStartOption.SCHEDULED.equals(getAutoStartOption())
? autoStartOptionGroupLayout.getStartAtDateField().getValue().getTime() : null;
? autoStartOptionGroupLayout.getStartAtDateField().getValue().getTime()
: null;
}
private int getErrorThresholdPercentage(final int amountGroup) {
@@ -486,13 +487,12 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
return new LabelBuilder().name(i18n.getMessage(key)).buildLabel();
}
private TextField createTextField(final String in18Key, final String id) {
return new TextFieldBuilder().prompt(i18n.getMessage(in18Key)).immediate(true).id(id).buildTextComponent();
private TextField createTextField(final String in18Key, final String id, final int maxLength) {
return new TextFieldBuilder(maxLength).prompt(i18n.getMessage(in18Key)).id(id).buildTextComponent();
}
private TextField createIntegerTextField(final String in18Key, final String id) {
final TextField textField = createTextField(in18Key, id);
textField.setNullRepresentation("");
final TextField textField = createTextField(in18Key, id, 32);
textField.setConverter(new StringToIntegerConverter());
textField.setConversionError(i18n.getMessage(MESSAGE_ENTER_NUMBER));
textField.setSizeUndefined();
@@ -615,12 +615,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
}
private static TextArea createTargetFilterQuery() {
final TextArea filterField = new TextAreaBuilder().style("text-area-style")
.id(UIComponentIdProvider.ROLLOUT_TARGET_FILTER_QUERY_FIELD)
.maxLengthAllowed(SPUILabelDefinitions.TARGET_FILTER_QUERY_TEXT_FIELD_LENGTH).buildTextComponent();
final TextArea filterField = new TextAreaBuilder(TargetFilterQuery.QUERY_MAX_SIZE).style("text-area-style")
.id(UIComponentIdProvider.ROLLOUT_TARGET_FILTER_QUERY_FIELD).buildTextComponent();
filterField.setId(UIComponentIdProvider.ROLLOUT_TARGET_FILTER_QUERY_FIELD);
filterField.setNullRepresentation("");
filterField.setEnabled(false);
filterField.setSizeUndefined();
return filterField;
@@ -776,11 +774,9 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
errorThresholdOptionGroup.setValue(ERRORTHRESOLDOPTIONS.PERCENT.getValue());
}
private TextArea createDescription() {
final TextArea descriptionField = new TextAreaBuilder().style("text-area-style")
.prompt(i18n.getMessage("textfield.description")).id(UIComponentIdProvider.ROLLOUT_DESCRIPTION_ID)
.buildTextComponent();
descriptionField.setNullRepresentation("");
private static TextArea createDescription() {
final TextArea descriptionField = new TextAreaBuilder(Rollout.DESCRIPTION_MAX_SIZE).style("text-area-style")
.id(UIComponentIdProvider.ROLLOUT_DESCRIPTION_ID).buildTextComponent();
descriptionField.setSizeUndefined();
return descriptionField;
}
@@ -846,8 +842,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout {
}
private TextField createRolloutNameField() {
final TextField rolloutNameField = createTextField("textfield.name",
UIComponentIdProvider.ROLLOUT_NAME_FIELD_ID);
final TextField rolloutNameField = new TextFieldBuilder(Rollout.NAME_MAX_SIZE)
.prompt(i18n.getMessage("textfield.name")).id(UIComponentIdProvider.ROLLOUT_NAME_FIELD_ID)
.required(true, i18n).buildTextComponent();
rolloutNameField.setSizeUndefined();
return rolloutNameField;
}

View File

@@ -50,7 +50,6 @@ import com.vaadin.data.util.converter.StringToFloatConverter;
import com.vaadin.data.util.converter.StringToIntegerConverter;
import com.vaadin.data.validator.FloatRangeValidator;
import com.vaadin.data.validator.IntegerRangeValidator;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.server.FontAwesome;
import com.vaadin.server.UserError;
import com.vaadin.ui.Button;
@@ -419,19 +418,17 @@ public class DefineGroupsLayout extends GridLayout {
}
private TextField createTextField(final String in18Key, final String id) {
final TextField textField = new TextFieldBuilder().prompt(i18n.getMessage(in18Key)).immediate(true).id(id)
.buildTextComponent();
final TextField textField = new TextFieldBuilder(RolloutGroup.NAME_MAX_SIZE).required(true, i18n)
.prompt(i18n.getMessage(in18Key)).id(id).buildTextComponent();
textField.setSizeUndefined();
textField.addValidator(
new StringLengthValidator(i18n.getMessage("message.rollout.group.name.invalid"), 1, 64, false));
return textField;
}
private TextField createPercentageField(final String in18Key, final String id) {
final TextField textField = new TextFieldBuilder().prompt(i18n.getMessage(in18Key)).immediate(true).id(id)
final TextField textField = new TextFieldBuilder(32).prompt(i18n.getMessage(in18Key)).id(id)
.buildTextComponent();
textField.setWidth(80, Unit.PIXELS);
textField.setNullRepresentation("");
textField.setConverter(new StringToIntegerConverter());
textField.addValidator(this::validateMandatoryPercentage);
return textField;
@@ -474,11 +471,9 @@ public class DefineGroupsLayout extends GridLayout {
}
private TextArea createTargetFilterQuery() {
final TextArea filterField = new TextAreaBuilder().style("text-area-style")
.id(UIComponentIdProvider.ROLLOUT_TARGET_FILTER_QUERY_FIELD)
.maxLengthAllowed(SPUILabelDefinitions.TARGET_FILTER_QUERY_TEXT_FIELD_LENGTH).buildTextComponent();
final TextArea filterField = new TextAreaBuilder(TargetFilterQuery.QUERY_MAX_SIZE).style("text-area-style")
.id(UIComponentIdProvider.ROLLOUT_TARGET_FILTER_QUERY_FIELD).buildTextComponent();
filterField.setNullRepresentation("");
filterField.setEnabled(false);
filterField.setSizeUndefined();
return filterField;

View File

@@ -53,7 +53,7 @@ public class CertificateAuthenticationConfigurationItem extends AbstractBooleanT
"The SSL Issuer iRules.X509 hash, to validate against the controller request certifcate.");
caRootAuthorityLabel.setWidthUndefined();
caRootAuthorityTextField = new TextFieldBuilder().immediate(true).maxLengthAllowed(160).buildTextComponent();
caRootAuthorityTextField = new TextFieldBuilder(160).buildTextComponent();
caRootAuthorityTextField.setWidth("100%");
caRootAuthorityTextField.addTextChangeListener(event -> caRootAuthorityChanged());

View File

@@ -272,11 +272,6 @@ public final class SPUILabelDefinitions {
*/
public static final String STATUS_ICON = "statusIcon";
/**
* Create custom target filter header - query text field length.
*/
public static final int TARGET_FILTER_QUERY_TEXT_FIELD_LENGTH = 1024;
/**
* Status - column property.
*/