Example usage for com.vaadin.ui HorizontalLayout setEnabled

List of usage examples for com.vaadin.ui HorizontalLayout setEnabled

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setEnabled.

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:fi.vtt.RVaadin.RContainer.java

License:Apache License

/**
 * For general description, see/*from  www. j  a v  a2  s  . c om*/
 * {@link RContainer#getParameterLayout(String, String)}.
 * 
 * @param caption
 *            Parameter name
 * @param parName
 *            The numeric vector name (of 1..N elements) in R
 * @param enabled
 *            Is the field enabled by default?
 * @return orizontalLayout element with implicit ValueChangeListeners to
 *         update R
 */
public HorizontalLayout getParameterLayout(String caption, final String parName, final boolean[] enabled) {

    /* The horizontal layout to place the parameters [p1, p2, p3,..., pN] */
    final HorizontalLayout hl = new HorizontalLayout();
    hl.setCaption(caption);
    hl.setSpacing(true);

    /* TextFields serve as the input field for the parameters */
    final TextField[] pFields;

    /* Get the default values for the parameter vector */
    double[] p = getDoubles(parName);

    /*
     * Show the parameter names in the TextField caption, in case that they
     * were defined in R
     */
    boolean namedPars = false;
    String[] names = null;
    if (isTRUE("!is.null(names(" + parName + "))")) {
        namedPars = true;
        names = getStrings("names(" + parName + ")");
    }

    if (p != null) {

        /*
         * Construct TextField(s) for the parameter vector and set the
         * initial values
         */
        pFields = new TextField[p.length];
        for (int i = 0; i < pFields.length; i++) {

            pFields[i] = new TextField();
            pFields[i].setValue(Double.toString(p[i]));

            if (enabled != null) {
                pFields[i].setEnabled(enabled[i]);
            }

            /*
             * Nice default width for a numeric parameter field. This could
             * actually be a parameter for this call.
             */
            pFields[i].setWidth("10ex");

            pFields[i].setImmediate(true);

            /*
             * In case that the parameters are named, show the name before
             * the text field
             */
            if (namedPars) {
                pFields[i].setCaption(names[i]);
            }

            hl.addComponent(pFields[i]);
        }

        /*
         * Set up a listener which can be attached to all the parameter
         * fields
         */

        ValueChangeListener parChanged = new ValueChangeListener() {

            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(ValueChangeEvent event) {

                /* Get the Property which fired the listener */
                TextField tf = ((TextField) event.getProperty());

                /* Find the corresponding parameter index */
                int idx;
                for (idx = 0; idx < pFields.length; idx++) {
                    if (tf == pFields[idx]) {
                        break;
                    }
                }

                /*
                 * Try to update the new value. If it is illegal (cannot be
                 * cast to Double), then stick with the old value and
                 * display it to the user to indicate erroneous input.
                 */

                double newValue;
                try {
                    newValue = Double.valueOf(tf.getValue().toString());

                    /*
                     * Submit the new value to R, remembering that the
                     * indexing is off by one between Java and R
                     */
                    eval(parName + "[" + (idx + 1) + "] <- " + newValue);

                } catch (Exception e) {

                    /*
                     * The parameter was illegal. Do nothing for R, and
                     * display the old value to indicate that the new value
                     * was not eligible.
                     */

                    Double oldPar = getDouble(parName + "[" + (idx + 1) + "]");
                    tf.setValue(Double.toString(oldPar));
                }
            }
        };

        /* Attach this listener to all TextField items */
        for (int i = 0; i < pFields.length; i++) {
            pFields[i].addValueChangeListener(parChanged);
        }

    } else {
        /* The original parameters were not readable as double[] */

        hl.addComponent(new Label("Error reading the parameters"));
        hl.setEnabled(false);
    }

    return hl;
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsLayoutHelper.java

License:Open Source License

public static HorizontalLayout createHorizontalLayoutWithELabsLabelAndLabelData(final String labelTxt,
        Property dataProperty, boolean required) {
    Preconditions.checkNotNull(labelTxt, "Label is null");
    Preconditions.checkNotNull(dataProperty, "DataSource is null");
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSizeUndefined();
    horizontalLayout.setDescription(USER_DESCR_ON_HOR_LAYOUT_TO_EDIT);
    horizontalLayout.setEnabled(true);
    horizontalLayout.setSpacing(true);/*w ww .  j a va 2s.c  o m*/
    horizontalLayout.setHeight(HOR_PANEL_HEIGHT);
    Label label = new Label();
    label.setWidth(LABEL_WIDTH);
    label.setValue(DIV_ALIGN_RIGHT + (required ? ELabsViewContants.REQUIRED_SIGN : "") + labelTxt + DIV_END);
    label.setContentMode(Label.CONTENT_XHTML);
    label.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    Label textLabel = new Label(dataProperty);
    textLabel.setWidth(TEXT_WIDTH);
    textLabel.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    textLabel.setStyleName(STYLE_ELABS_TEXT_AS_LABEL);
    horizontalLayout.setStyleName(STYLE_ELABS_HOR_PANEL);
    horizontalLayout.addComponent(label, 0);
    horizontalLayout.addComponent(textLabel, 1);
    horizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    horizontalLayout.setComponentAlignment(textLabel, Alignment.MIDDLE_RIGHT);
    return horizontalLayout;
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsLayoutHelper.java

License:Open Source License

public static HorizontalLayout createHorizontalLayoutWithELabsLabelAndStaticComboData(final String labelTxt,
        String value, boolean required) {
    Preconditions.checkNotNull(labelTxt, "Label is null");
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSizeUndefined();
    horizontalLayout.setDescription(USER_DESCR_ON_HOR_LAYOUT_TO_EDIT);
    horizontalLayout.setEnabled(true);
    horizontalLayout.setSpacing(true);/*from w w w  . j ava 2  s .  co  m*/
    horizontalLayout.setHeight(HOR_PANEL_HEIGHT);
    Label label = new Label();
    label.setWidth(LABEL_WIDTH);
    label.setValue(DIV_ALIGN_RIGHT + (required ? ELabsViewContants.REQUIRED_SIGN : "") + labelTxt + DIV_END);
    label.setContentMode(Label.CONTENT_XHTML);
    label.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    Label textLabel = new Label(value);
    textLabel.setWidth(TEXT_WIDTH);
    textLabel.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    textLabel.setStyleName(STYLE_ELABS_TEXT_AS_LABEL);
    horizontalLayout.setStyleName(STYLE_ELABS_HOR_PANEL);
    horizontalLayout.addComponent(label, 0);
    horizontalLayout.addComponent(textLabel, 1);
    horizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    horizontalLayout.setComponentAlignment(textLabel, Alignment.MIDDLE_RIGHT);
    return horizontalLayout;
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsLayoutHelper.java

License:Open Source License

public static HorizontalLayout createHorizontalLayoutWithELabsLabelAndLabelComplexData(final String labelTxt,
        String dataTxt, boolean required) {
    Preconditions.checkNotNull(labelTxt, "Label is null");
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSizeUndefined();
    horizontalLayout.setDescription(USER_DESCR_ON_HOR_LAYOUT_TO_EDIT);
    horizontalLayout.setEnabled(true);
    horizontalLayout.setSpacing(true);//from   ww  w. ja  v a  2 s  .  c o m
    horizontalLayout.setHeight(HOR_PANEL_HEIGHT);
    Label label = new Label();
    label.setWidth(LABEL_WIDTH);
    label.setValue(DIV_ALIGN_RIGHT + (required ? ELabsViewContants.REQUIRED_SIGN : "") + labelTxt + DIV_END);
    label.setContentMode(Label.CONTENT_XHTML);
    label.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    Label textLabel = new Label(dataTxt);
    textLabel.setWidth(TEXT_WIDTH);
    textLabel.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    textLabel.setStyleName(STYLE_ELABS_TEXT_AS_LABEL);
    horizontalLayout.setStyleName(STYLE_ELABS_HOR_PANEL);
    horizontalLayout.addComponent(label, 0);
    horizontalLayout.addComponent(textLabel, 1);
    horizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    horizontalLayout.setComponentAlignment(textLabel, Alignment.MIDDLE_RIGHT);
    return horizontalLayout;
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsLayoutHelper.java

License:Open Source License

public static HorizontalLayout createHorizontalLayoutWithELabsLabelAndRelatedDataForRig(final String labelTxt,
        Property dataProperty, RigBean rigBean, final IRigAction controller, LabsRigTableHelper helper,
        boolean required) {
    synchronized (LOCK_1) {
        Preconditions.checkNotNull(labelTxt, "Label is null");
        Preconditions.checkNotNull(dataProperty, "DataSource is null");
        Preconditions.checkNotNull(rigBean, "RigBean is null");
        Preconditions.checkNotNull(helper, "Helper is null");
        Preconditions.checkNotNull(controller, "Controller is null");
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        horizontalLayout.setSizeUndefined();
        horizontalLayout.setEnabled(true);
        horizontalLayout.setSpacing(true);
        horizontalLayout.setStyleName(STYLE_ELABS_HOR_PANEL_FOR_TABLE);
        Label label = new Label();
        label.setWidth(LABEL_WIDTH);/*from  ww w.j ava  2  s. co m*/
        label.setValue(
                DIV_ALIGN_RIGHT + (required ? ELabsViewContants.REQUIRED_SIGN : "") + labelTxt + DIV_END);
        label.setContentMode(Label.CONTENT_XHTML);
        label.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
        label.setStyleName(STYLE_ELABS_HOR_PANEL);
        horizontalLayout.addComponent(label, 0);
        horizontalLayout.addComponent(helper.createTableLayoutForRig(rigBean, controller), 1);
        horizontalLayout.setComponentAlignment(label, Alignment.TOP_LEFT);
        return horizontalLayout;
    }
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsLayoutHelper.java

License:Open Source License

public static HorizontalLayout createHorizontalLayoutWithPublicationDataForStudy(final String labelTxt,
        Property dataProperty, boolean isMotNotResPublication, LabsStudyTableHelper helper, boolean required) {
    synchronized (LOCK_2) {
        Preconditions.checkNotNull(labelTxt, "Label is null");
        Preconditions.checkNotNull(dataProperty, "DataSource is null");
        Preconditions.checkNotNull(helper, "Helper is null");
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        horizontalLayout.setSizeUndefined();
        horizontalLayout.setEnabled(true);
        horizontalLayout.setSpacing(true);
        horizontalLayout.setStyleName(STYLE_ELABS_HOR_PANEL_FOR_TABLE);
        Label label = new Label();
        label.setWidth(LABEL_WIDTH);/*from w  w w .jav  a  2 s .  com*/
        label.setValue(
                DIV_ALIGN_RIGHT + (required ? ELabsViewContants.REQUIRED_SIGN : "") + labelTxt + DIV_END);
        label.setContentMode(Label.CONTENT_XHTML);
        label.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
        label.setStyleName(STYLE_ELABS_HOR_PANEL);
        horizontalLayout.addComponent(label, 0);
        if (isMotNotResPublication) {
            horizontalLayout.addComponent(helper.createTableLayoutForMotPublications(), 1);
        } else {
            horizontalLayout.addComponent(helper.createTableLayoutForResPublications(), 1);
        }
        horizontalLayout.setComponentAlignment(label, Alignment.TOP_LEFT);
        return horizontalLayout;
    }
}

From source file:org.escidoc.browser.elabsmodul.views.helpers.LabsLayoutHelper.java

License:Open Source License

public static HorizontalLayout createHorizontalLayoutWithELabsLabelAndCheckBoxData(final String labelTxt,
        final String checkBoxDescription, Property dataProperty, boolean required) {
    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSizeUndefined();
    horizontalLayout.setDescription(USER_DESCR_ON_HOR_LAYOUT_TO_EDIT);
    horizontalLayout.setEnabled(true);
    horizontalLayout.setSpacing(true);/*from w  w w .  j  a va  2 s  .c o  m*/
    horizontalLayout.setHeight(HOR_PANEL_HEIGHT);
    horizontalLayout.setStyleName(STYLE_ELABS_HOR_PANEL);
    Label label = new Label();
    label.setWidth(LABEL_WIDTH);
    label.setValue(DIV_ALIGN_RIGHT + (required ? ELabsViewContants.REQUIRED_SIGN : "") + labelTxt + DIV_END);
    label.setContentMode(Label.CONTENT_XHTML);
    label.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    final CheckBox checkBox = new CheckBox(checkBoxDescription, dataProperty);
    checkBox.setEnabled(true);
    checkBox.setVisible(true);
    checkBox.setWidth(TEXT_WIDTH);
    checkBox.setStyleName(STYLE_ELABS_TEXT_AS_LABEL);
    checkBox.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    horizontalLayout.addComponent(label, 0);
    horizontalLayout.addComponent(checkBox, 1);
    horizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    horizontalLayout.setComponentAlignment(checkBox, Alignment.MIDDLE_RIGHT);
    return horizontalLayout;
}