com.holonplatform.vaadin7.internal.components.builders.AbstractStringFieldBuilder Maven / Gradle / Ivy
/*
* Copyright 2016-2017 Axioma srl.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.holonplatform.vaadin7.internal.components.builders;
import com.holonplatform.core.i18n.Localizable;
import com.holonplatform.core.i18n.LocalizationContext;
import com.holonplatform.vaadin7.components.Input;
import com.holonplatform.vaadin7.components.builders.StringInputBuilder;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.ui.AbstractTextField;
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextArea;
/**
* Builder to create {@link String} type {@link Field}s.
*
* @param Internal field type
*
* @since 5.0.0
*/
public abstract class AbstractStringFieldBuilder
extends AbstractFieldBuilder, I, StringInputBuilder> implements StringInputBuilder {
protected Localizable inputPrompt;
public AbstractStringFieldBuilder(I instance) {
super(instance);
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#maxLength(int)
*/
@Override
public StringInputBuilder maxLength(int maxLength) {
getInstance().setMaxLength(maxLength);
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#inputPrompt(java.lang.String)
*/
@Override
public StringInputBuilder inputPrompt(String inputPrompt) {
getInstance().setInputPrompt(inputPrompt);
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#inputPrompt(java.lang.String,
* java.lang.String, java.lang.Object[])
*/
@Override
public StringInputBuilder inputPrompt(String defaultInputPrompt, String messageCode, Object... arguments) {
this.inputPrompt = Localizable.builder().message(defaultInputPrompt).messageCode(messageCode)
.messageArguments(arguments).build();
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#inputPrompt(com.holonplatform.core.i18n.
* Localizable)
*/
@Override
public StringInputBuilder inputPrompt(Localizable inputPrompt) {
this.inputPrompt = inputPrompt;
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#textChangeEventMode(com.vaadin.ui.
* AbstractTextField.TextChangeEventMode)
*/
@Override
public StringInputBuilder textChangeEventMode(TextChangeEventMode inputEventMode) {
getInstance().setTextChangeEventMode(inputEventMode);
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#textChangeTimeout(int)
*/
@Override
public StringInputBuilder textChangeTimeout(int timeout) {
getInstance().setTextChangeTimeout(timeout);
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#withTextChangeListener(com.vaadin.event.
* FieldEvents.TextChangeListener)
*/
@Override
public StringInputBuilder withTextChangeListener(TextChangeListener listener) {
getInstance().addTextChangeListener(listener);
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#withFocusListener(com.vaadin.event.
* FieldEvents.FocusListener)
*/
@Override
public StringInputBuilder withFocusListener(FocusListener listener) {
getInstance().addFocusListener(listener);
return builder();
}
/*
* (non-Javadoc)
* @see
* com.holonplatform.vaadin.components.builders.TextInputFieldBuilder#withBlurListener(com.vaadin.event.FieldEvents
* .BlurListener)
*/
@Override
public StringInputBuilder withBlurListener(BlurListener listener) {
getInstance().addBlurListener(listener);
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.components.builders.TextFieldBuilder#rows(int)
*/
@Override
public StringInputBuilder rows(int rows) {
if (getInstance() instanceof TextArea) {
((TextArea) getInstance()).setRows(rows);
}
return builder();
}
/*
* (non-Javadoc)
* @see
* com.holonplatform.vaadin.internal.components.builders.AbstractFieldBuilder#localize(com.vaadin.ui.AbstractField)
*/
@Override
protected void localize(I instance) {
super.localize(instance);
if (inputPrompt != null) {
instance.setInputPrompt(LocalizationContext.translate(inputPrompt, true));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy