Search in sources :

Example 1 with FormGroup

use of org.gwtbootstrap3.client.ui.FormGroup in project kura by eclipse.

the class AbstractServicesUi method renderMultiFieldConfigParameter.

protected void renderMultiFieldConfigParameter(GwtConfigParameter mParam) {
    String value;
    String[] values = mParam.getValues();
    boolean isFirstInstance = true;
    FormGroup formGroup = new FormGroup();
    for (int i = 0; i < Math.min(mParam.getCardinality(), 10); i++) {
        // temporary set the param value to the current one in the array
        // use a value from the one passed in if we have it.
        value = null;
        if (values != null && i < values.length) {
            value = values[i];
        }
        mParam.setValue(value);
        renderConfigParameter(mParam, isFirstInstance, formGroup);
        if (isFirstInstance) {
            isFirstInstance = false;
        }
    }
    // restore a null current value
    mParam.setValue(null);
}
Also used : FormGroup(org.gwtbootstrap3.client.ui.FormGroup)

Example 2 with FormGroup

use of org.gwtbootstrap3.client.ui.FormGroup in project kura by eclipse.

the class AbstractServicesUi method renderPasswordField.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void renderPasswordField(final GwtConfigParameter param, boolean isFirstInstance, FormGroup formGroup) {
    this.valid.put(param.getId(), true);
    if (isFirstInstance) {
        FormLabel formLabel = new FormLabel();
        formLabel.setText(param.getName());
        if (param.isRequired()) {
            formLabel.setShowRequiredIndicator(true);
        }
        formLabel.setTitle(param.getId());
        formGroup.add(formLabel);
        InlineHelpBlock ihb = new InlineHelpBlock();
        ihb.setIconType(IconType.EXCLAMATION_TRIANGLE);
        formGroup.add(ihb);
        if (param.getDescription() != null) {
            HelpBlock toolTip = new HelpBlock();
            toolTip.setText(getDescription(param));
            formGroup.add(toolTip);
        }
    }
    final Input input = new Input();
    input.setType(InputType.PASSWORD);
    if (param.getValue() != null) {
        input.setText(param.getValue());
    } else {
        input.setText("");
    }
    if (param.getMin() != null && param.getMin().equals(param.getMax())) {
        input.setReadOnly(true);
        input.setEnabled(false);
    }
    input.setValidateOnBlur(true);
    input.addValidator(new Validator() {

        @Override
        public List<EditorError> validate(Editor editor, Object value) {
            setDirty(true);
            List<EditorError> result = new ArrayList<EditorError>();
            if ((input.getText() == null || "".equals(input.getText().trim())) && param.isRequired()) {
                // null in required field
                result.add(new BasicEditorError(input, input.getText(), MSGS.formRequiredParameter()));
                AbstractServicesUi.this.valid.put(param.getName(), false);
            } else {
                param.setValue(input.getText());
                AbstractServicesUi.this.valid.put(param.getName(), true);
            }
            return result;
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
    formGroup.add(input);
}
Also used : BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) Input(org.gwtbootstrap3.client.ui.Input) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) HelpBlock(org.gwtbootstrap3.client.ui.HelpBlock) BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) EditorError(com.google.gwt.editor.client.EditorError) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) ArrayList(java.util.ArrayList) List(java.util.List) FormLabel(org.gwtbootstrap3.client.ui.FormLabel) Editor(com.google.gwt.editor.client.Editor) Validator(org.gwtbootstrap3.client.ui.form.validator.Validator)

Example 3 with FormGroup

use of org.gwtbootstrap3.client.ui.FormGroup in project kura by eclipse.

the class AbstractServicesUi method renderTextField.

// Field Render based on Type
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void renderTextField(final GwtConfigParameter param, boolean isFirstInstance, final FormGroup formGroup) {
    this.valid.put(param.getId(), true);
    if (isFirstInstance) {
        FormLabel formLabel = new FormLabel();
        formLabel.setText(param.getName());
        if (param.isRequired()) {
            formLabel.setShowRequiredIndicator(true);
        }
        formLabel.setTitle(param.getId());
        formGroup.add(formLabel);
        InlineHelpBlock ihb = new InlineHelpBlock();
        ihb.setIconType(IconType.EXCLAMATION_TRIANGLE);
        formGroup.add(ihb);
        HelpBlock tooltip = new HelpBlock();
        tooltip.setText(getDescription(param));
        formGroup.add(tooltip);
    }
    final TextBoxBase textBox = createTextBox(param);
    String formattedValue = new String();
    // double value as expected
    switch(param.getType()) {
        case LONG:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Long.parseLong(param.getValue()));
            }
            break;
        case DOUBLE:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Double.parseDouble(param.getValue()));
            }
            break;
        case FLOAT:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Float.parseFloat(param.getValue()));
            }
            break;
        case SHORT:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Short.parseShort(param.getValue()));
            }
            break;
        case BYTE:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Byte.parseByte(param.getValue()));
            }
            break;
        case INTEGER:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Integer.parseInt(param.getValue()));
            }
            break;
        default:
            formattedValue = param.getValue();
            break;
    }
    if (param.getValue() != null) {
        textBox.setText(formattedValue);
    } else {
        textBox.setText("");
    }
    if (param.getMin() != null && param.getMin().equals(param.getMax())) {
        textBox.setReadOnly(true);
        textBox.setEnabled(false);
    }
    formGroup.add(textBox);
    textBox.setValidateOnBlur(true);
    textBox.addValidator(new Validator() {

        @Override
        public List<EditorError> validate(Editor editor, Object value) {
            setDirty(true);
            return validateTextBox(param, textBox, formGroup);
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
// textBox.validate();
}
Also used : InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) HelpBlock(org.gwtbootstrap3.client.ui.HelpBlock) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) ArrayList(java.util.ArrayList) List(java.util.List) FormLabel(org.gwtbootstrap3.client.ui.FormLabel) Editor(com.google.gwt.editor.client.Editor) Validator(org.gwtbootstrap3.client.ui.form.validator.Validator) TextBoxBase(org.gwtbootstrap3.client.ui.base.TextBoxBase)

Example 4 with FormGroup

use of org.gwtbootstrap3.client.ui.FormGroup in project kura by eclipse.

the class TextFieldValidator method validate.

public void validate(TextBox textBox, FormGroup formGroup, FieldType fieldType, boolean req) {
    this.type = fieldType;
    this.required = req;
    this.group = formGroup;
    textBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            // value format
            TextBox box = (TextBox) event.getSource();
            if (!box.getText().matches(TextFieldValidator.this.type.getRegex())) {
                TextFieldValidator.this.group.setValidationState(ValidationState.ERROR);
                box.setPlaceholder(TextFieldValidator.this.type.getRegexMessage());
            } else {
                TextFieldValidator.this.group.setValidationState(ValidationState.NONE);
                box.setPlaceholder("");
            }
            // value required
            if (TextFieldValidator.this.required && ("".equals(box.getText().trim()) || box.getText() == null)) {
                TextFieldValidator.this.group.setValidationState(ValidationState.ERROR);
                box.setPlaceholder(TextFieldValidator.this.type.getRequiredMessage());
            } else {
                TextFieldValidator.this.group.setValidationState(ValidationState.NONE);
                box.setPlaceholder("");
            }
        }
    });
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) TextBox(org.gwtbootstrap3.client.ui.TextBox)

Example 5 with FormGroup

use of org.gwtbootstrap3.client.ui.FormGroup in project kura by eclipse.

the class ServicesUi method getUpdatedConfiguration.

private GwtConfigComponent getUpdatedConfiguration() {
    Iterator<Widget> it = this.fields.iterator();
    while (it.hasNext()) {
        Widget w = it.next();
        if (w instanceof FormGroup) {
            FormGroup fg = (FormGroup) w;
            fillUpdatedConfiguration(fg);
        }
    }
    return this.m_configurableComponent;
}
Also used : FormGroup(org.gwtbootstrap3.client.ui.FormGroup) Widget(com.google.gwt.user.client.ui.Widget)

Aggregations

FormGroup (org.gwtbootstrap3.client.ui.FormGroup)5 FormLabel (org.gwtbootstrap3.client.ui.FormLabel)5 ArrayList (java.util.ArrayList)4 HelpBlock (org.gwtbootstrap3.client.ui.HelpBlock)4 InlineHelpBlock (org.gwtbootstrap3.client.ui.InlineHelpBlock)4 GwtConfigParameter (org.eclipse.kura.web.shared.model.GwtConfigParameter)3 Editor (com.google.gwt.editor.client.Editor)2 EditorError (com.google.gwt.editor.client.EditorError)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)2 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)2 Widget (com.google.gwt.user.client.ui.Widget)2 List (java.util.List)2 Input (org.gwtbootstrap3.client.ui.Input)2 ListBox (org.gwtbootstrap3.client.ui.ListBox)2 TextBoxBase (org.gwtbootstrap3.client.ui.base.TextBoxBase)2 BasicEditorError (org.gwtbootstrap3.client.ui.form.error.BasicEditorError)2 Validator (org.gwtbootstrap3.client.ui.form.validator.Validator)2 InlineRadio (org.gwtbootstrap3.client.ui.InlineRadio)1