diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index 65310e6d3..25d579717 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; +import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.WindowBuilder; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; @@ -127,10 +128,9 @@ public class SoftwareModuleAddUpdateWindow extends CustomComponent implements Se vendorTextField = createTextField("textfield.vendor", SPUIComponentIdProvider.SOFT_MODULE_VENDOR); vendorTextField.setRequired(false); - descTextArea = SPUIComponentProvider.getTextArea(i18n.get("textfield.description"), "text-area-style", - ValoTheme.TEXTAREA_TINY, false, null, i18n.get("textfield.description"), - SPUILabelDefinitions.TEXT_AREA_MAX_LENGTH); - descTextArea.setId(SPUIComponentIdProvider.ADD_SW_MODULE_DESCRIPTION); + descTextArea = new TextAreaBuilder().caption(i18n.get("textfield.description")).style("text-area-style") + .prompt(i18n.get("textfield.description")).id(SPUIComponentIdProvider.ADD_SW_MODULE_DESCRIPTION) + .buildTextField(); typeComboBox = SPUIComponentProvider.getComboBox(i18n.get("upload.swmodule.type"), "", "", null, null, true, null, i18n.get("upload.swmodule.type")); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index 63f93807a..e1c665751 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -19,8 +19,8 @@ import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareMo import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; +import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; -import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.layouts.CreateUpdateTypeLayout; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -85,11 +85,10 @@ public class CreateUpdateSoftwareTypeLayout extends CreateUpdateTypeLayout { typeKey = createTextField("textfield.key", SPUIDefinitions.NEW_SOFTWARE_TYPE_KEY, SPUIDefinitions.TYPE_KEY); - tagDesc = SPUIComponentProvider.getTextArea(i18n.get("textfield.description"), "", - ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TYPE_DESC, false, "", - i18n.get("textfield.description"), SPUILabelDefinitions.TEXT_AREA_MAX_LENGTH); - tagDesc.setId(SPUIDefinitions.NEW_SOFTWARE_TYPE_DESC); - tagDesc.setImmediate(true); + tagDesc = new TextAreaBuilder().caption(i18n.get("textfield.description")) + .styleName(ValoTheme.TEXTFIELD_TINY + " " + SPUIDefinitions.TYPE_DESC) + .prompt(i18n.get("textfield.description")).immediate(true).id(SPUIDefinitions.NEW_SOFTWARE_TYPE_DESC) + .buildTextField(); tagDesc.setNullRepresentation(""); singleMultiOptionGroup(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java index 8b80dee31..c89dff4b6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.MetaData; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; +import org.eclipse.hawkbit.ui.common.builder.TextAreaBuilder; import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder; import org.eclipse.hawkbit.ui.common.builder.WindowBuilder; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -49,7 +50,6 @@ import com.vaadin.ui.TextField; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; -import com.vaadin.ui.themes.ValoTheme; /** * @@ -217,9 +217,9 @@ public abstract class AbstractMetadataPopupLayout + * the concrete text component + */ +public abstract class AbstractTextFieldBuilder { + + private String caption; + private String style; + private String styleName; + private String prompt; + private String id; + private boolean immediate; + private boolean required; + private int maxLengthAllowed; + + /** + * @param caption + * the caption to set + * @return the builder + */ + public AbstractTextFieldBuilder caption(final String caption) { + this.caption = caption; + return this; + } + + /** + * @param style + * the style to set * @return the builder + * @return the builder + */ + public AbstractTextFieldBuilder style(final String style) { + this.style = style; + return this; + } + + /** + * @param styleName + * the styleName to set + * @return the builder + */ + public AbstractTextFieldBuilder styleName(final String styleName) { + this.styleName = styleName; + return this; + } + + /** + * @param required + * the required to set + * @return the builder + */ + public AbstractTextFieldBuilder required(final boolean required) { + this.required = required; + return this; + } + + /** + * @param prompt + * the prompt to set + * @return the builder + */ + public AbstractTextFieldBuilder prompt(final String prompt) { + this.prompt = prompt; + return this; + } + + /** + * @param immediate + * the immediate to set + * @return the builder + */ + public AbstractTextFieldBuilder immediate(final boolean immediate) { + this.immediate = immediate; + return this; + } + + /** + * @param maxLengthAllowed + * the maxLengthAllowed to set + * @return the builder + */ + public AbstractTextFieldBuilder maxLengthAllowed(final int maxLengthAllowed) { + this.maxLengthAllowed = maxLengthAllowed; + return this; + } + + /** + * @param id + * the id to set + * @return the builder + */ + public AbstractTextFieldBuilder id(final String id) { + this.id = id; + return this; + } + + /** + * Build a textfield + * + * @return textfield + */ + public E buildTextField() { + final E textComponent = createTextComponent(); + + textComponent.setRequired(required); + textComponent.setImmediate(immediate); + + if (StringUtils.isNotEmpty(caption)) { + textComponent.setCaption(caption); + } + + if (StringUtils.isNotEmpty(style)) { + textComponent.setStyleName(style); + } + + if (StringUtils.isNotEmpty(styleName)) { + textComponent.addStyleName(styleName); + } + if (StringUtils.isNotEmpty(prompt)) { + textComponent.setInputPrompt(prompt); + } + + if (maxLengthAllowed > 0) { + textComponent.setMaxLength(maxLengthAllowed); + } + + if (StringUtils.isNotEmpty(id)) { + textComponent.setId(id); + } + + return textComponent; + } + + protected abstract E createTextComponent(); + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/TextAreaBuilder.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/TextAreaBuilder.java new file mode 100644 index 000000000..d75b408d4 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/builder/TextAreaBuilder.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.common.builder; + +import com.vaadin.ui.TextArea; +import com.vaadin.ui.themes.ValoTheme; + +/** + * TextArea builder. + * + */ +public class TextAreaBuilder extends AbstractTextFieldBuilder