Example usage for com.vaadin.ui HorizontalLayout getComponent

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

Introduction

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

Prototype

public Component getComponent(int index) throws IndexOutOfBoundsException 

Source Link

Document

Returns the component at the given position.

Usage

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

License:Apache License

public TextField[] getParameterLayoutTextFields(HorizontalLayout hl) {

    if (hl != null) {
        int n = countParametersInLayout(hl);
        TextField[] tft = new TextField[n];

        /* Get and return the TextField elements in a one-dimensional table */
        for (int i = 0; i < n; i++) {
            tft[i] = (TextField) hl.getComponent(i);
        }//w w w.jav a2 s  .c  o m
        return tft;
    } else {
        return null;
    }
}

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

License:Apache License

/**
 * A helper function to count how many TextFields there are in a parameter
 * layout.//from w  ww.  j av a2 s .c o m
 * 
 * @param hl
 *            {@link HorizontalLayout} corresponding to a parameter layout.
 * @return integer count
 */
private int countParametersInLayout(HorizontalLayout hl) {

    /* How many parameters we have in this layout? */
    int i;
    for (i = 1; i <= hl.getComponentCount(); i++) {
        if (!(hl.getComponent(i - 1) instanceof TextField)) {
            /* Index i does not any more contain a TextField */
            i--;
            break;
        }
    }

    /*
     * Now we know that there are i parameters in total (if someone has not
     * added an extra TextField into the layout once it was constructed).
     */
    return i;
}

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

License:Apache License

/**
 * A function to set parameter values in the element generated by
 * {@link RContainer#getParameterLayout}.
 * //from   www .j a v a 2  s . com
 * @param p
 *            double[] parameter vector
 * @param hl
 *            HorizontalLayout obtained from
 *            {@link RContainer#getParameterLayout}
 */
public void setParameterLayoutValues(double[] p, HorizontalLayout hl) {

    for (int i = 0; i < p.length; i++) {
        ((TextField) hl.getComponent(i)).setValue(Double.toString(p[i]));
    }
}

From source file:fr.amapj.view.engine.popup.formpopup.AbstractFormPopup.java

License:Open Source License

protected <T extends Enum<T>> ComboBox addComboEnumField(String title, String propertyId, T[] enumsToExcludes,
        IValidator... validators) {/*from w w w. ja v  a2  s .  c  o m*/
    HorizontalLayout hl = EnumSearcher.createEnumSearcher(binder, title, propertyId, enumsToExcludes);

    form.addComponent(hl);

    ComboBox box = (ComboBox) hl.getComponent(0);

    validatorManager.add(box, title, propertyId, validators);

    return box;
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadConfirmationWindow.java

License:Open Source License

/**
 * If warning was displayed prior and not displayed currently ,the update
 * other warning labels accordingly.// w w w .  ja v a  2s .c  o m
 *
 * @param itemId
 *            id of row which is deleted/whose file name modified.
 * @param oldSwId
 *            software module id
 * @param oldFileName
 *            file name before modification
 */
private void modifyIconOfSameSwId(final Object itemId, final Long oldSwId, final String oldFileName) {
    for (final Object rowId : tableContainer.getItemIds()) {
        final Item newItem = tableContainer.getItem(rowId);
        final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
        final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
        if (!rowId.equals(itemId) && newBaseSwId.equals(oldSwId) && newFileName.equals(oldFileName)) {
            final HorizontalLayout layout = (HorizontalLayout) newItem.getItemProperty(FILE_NAME_LAYOUT)
                    .getValue();
            final Label warningLabel = (Label) layout.getComponent(1);
            if (warningLabel.isVisible()) {
                warningLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
                warningLabel.setDescription(i18n.getMessage(ALREADY_EXISTS_MSG));
                newItem.getItemProperty(WARNING_ICON).setValue(warningLabel);
                redErrorLabelCount--;
                break;
            }
        }
    }
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadConfirmationWindow.java

License:Open Source License

private void newFileNameIsDuplicate(final Object itemId, final Long currentSwId,
        final String currentChangedText) {
    for (final Object rowId : tableContainer.getItemIds()) {
        final Item currentItem = tableContainer.getItem(itemId);
        final Item newItem = tableContainer.getItem(rowId);
        final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
        final String fileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
        if (!rowId.equals(itemId) && newBaseSwId.equals(currentSwId) && fileName.equals(currentChangedText)) {
            final HorizontalLayout layout = (HorizontalLayout) currentItem.getItemProperty(FILE_NAME_LAYOUT)
                    .getValue();//w  ww .  j a  v a  2s .  c  o m
            final Label iconLabel = (Label) layout.getComponent(1);
            if (!iconLabel.getStyleName().contains(SPUIStyleDefinitions.ERROR_LABEL)) {
                iconLabel.setVisible(true);
                iconLabel.setDescription(i18n.getMessage("message.duplicate.filename"));
                iconLabel.addStyleName(SPUIStyleDefinitions.ERROR_LABEL);
                redErrorLabelCount++;
            }
            break;
        }
    }
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadConfirmationWindow.java

License:Open Source License

private void reValidateOtherFileNamesOfSameBaseSw(final Object itemId, final Long currentSwId,
        final String oldFileName) {
    Label warningLabel = null;//from  w  w w. j  a v a  2 s.  c o m
    Label errorLabel = null;
    int errorLabelCount = 0;
    int duplicateCount = 0;
    for (final Object rowId : tableContainer.getItemIds()) {
        final Item newItem = tableContainer.getItem(rowId);
        final Long newBaseSwId = (Long) newItem.getItemProperty(BASE_SOFTWARE_ID).getValue();
        final String newFileName = (String) newItem.getItemProperty(FILE_NAME).getValue();
        if (!rowId.equals(itemId) && newBaseSwId.equals(currentSwId) && newFileName.equals(oldFileName)) {
            final HorizontalLayout layout = (HorizontalLayout) newItem.getItemProperty(FILE_NAME_LAYOUT)
                    .getValue();
            final Label icon = (Label) layout.getComponent(1);
            duplicateCount++;
            if (icon.isVisible()) {
                if (!icon.getStyleName().contains(SPUIStyleDefinitions.ERROR_LABEL)) {
                    warningLabel = icon;
                    break;
                }
                errorLabel = icon;
                errorLabelCount++;
            }
        }
    }
    hideErrorIcon(warningLabel, errorLabelCount, duplicateCount, errorLabel, oldFileName, currentSwId);
}

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

License:Open Source License

/**
 * Returns with a label based on the edited field.
 * //from   w w  w . j a va 2  s.  c  o  m
 * @param property
 * @return boolean an element switch happened or not
 */
public static boolean switchToLabelFromEditedField(HorizontalLayout parentLayout) {
    Preconditions.checkNotNull(parentLayout, "ParentLayout on DynamicLayout is null");
    Component staticLabelComponent = null, dataComponent = null;
    try {
        staticLabelComponent = parentLayout.getComponent(0);
        dataComponent = parentLayout.getComponent(1);
    } catch (IndexOutOfBoundsException e) {
        LOG.error("This layout should contain only 2 components!");
        return false;
    }
    Property dataProperty = null;
    Label label = null;
    if (dataComponent instanceof TextField) {
        dataProperty = ((TextField) dataComponent).getPropertyDataSource();
        label = new Label(dataProperty);
    } else if (dataComponent instanceof ComboBox) {
        if (((ComboBox) dataComponent).getValue() instanceof String) {
            dataProperty = ((ComboBox) dataComponent).getPropertyDataSource();
            if (dataProperty == null) {
                label = new Label((String) ((ComboBox) dataComponent).getValue());
            } else {
                label = new Label(dataProperty);
            }
        } else if (((ComboBox) dataComponent).getValue() instanceof RigBean) {
            label = new Label(((RigBean) ((ComboBox) dataComponent).getValue()).getComplexId());
        } else if (((ComboBox) dataComponent).getValue() instanceof UserBean) {
            label = new Label(((UserBean) ((ComboBox) dataComponent).getValue()).getComplexId());
        } else if (((ComboBox) dataComponent).getValue() instanceof OrgUnitBean) {
            label = new Label(((OrgUnitBean) ((ComboBox) dataComponent).getValue()).getComplexId());
        } else if (((ComboBox) dataComponent).getValue() instanceof FileFormatBean) {
            label = new Label(((FileFormatBean) ((ComboBox) dataComponent).getValue()).getTitle());
        } else {
            LOG.error("Incorrect data type at the switch to label");
        }
    } else if (dataComponent instanceof Label) {
        label = (Label) dataComponent;
    } else if (dataComponent instanceof CheckBox || dataComponent instanceof VerticalLayout) {
        return true;
    }

    if (label == null) {
        LOG.debug("The wrong dataComponent is " + dataComponent.toString());
        return false;
    }
    label.setWidth(TEXT_WIDTH);
    label.setStyleName(STYLE_ELABS_TEXT_AS_LABEL);
    label.setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    parentLayout.replaceComponent(dataComponent, label);
    parentLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    ((Label) staticLabelComponent).setDescription(USER_DESCR_ON_LABEL_TO_EDIT);
    parentLayout.setDescription(USER_DESCR_ON_HOR_LAYOUT_TO_EDIT);
    return true;
}

From source file:org.escidoc.browser.elabsmodul.views.InstrumentView.java

License:Open Source License

@Override
public void resetLayout() {
    Preconditions.checkNotNull(this.dynamicLayout, "View's dynamiclayout is null.");
    HorizontalLayout tempParentLayout = null;
    for (Iterator<Component> iterator = this.dynamicLayout.getComponentIterator(); iterator.hasNext();) {
        Component component = iterator.next();
        if (component instanceof HorizontalLayout) {
            tempParentLayout = (HorizontalLayout) component;
        } else {/*  w ww . j  a  va  2 s .  c  om*/
            LOG.error("DynamicLayout can contain only HorizontalLayouts as direct child element.");
            break;
        }

        if (tempParentLayout.getComponentCount() != 2) {
            continue;
        }

        if (LabsLayoutHelper.switchToLabelFromEditedField(tempParentLayout)) {
            this.setModifiedComponent(null);
            if (this.dynamicLayout.getComponentIndex(tempParentLayout) == 4) {
                this.instrumentBean
                        .setESyncDaemon((String) ((Label) tempParentLayout.getComponent(1)).getValue());
            }
        } else {
            LOG.error("Label change error, mod .component is not set to null");
        }
    }
}

From source file:org.escidoc.browser.elabsmodul.views.InvestigationView.java

License:Open Source License

@Override
public void resetLayout() {
    Preconditions.checkNotNull(this.dynamicLayout, "View's dynamiclayout is null.");

    HorizontalLayout tempParentLayout = null;
    for (final Iterator<Component> iterator = this.dynamicLayout.getComponentIterator(); iterator.hasNext();) {
        final Component component = iterator.next();
        if (component instanceof HorizontalLayout) {
            tempParentLayout = (HorizontalLayout) component;
        } else {/*from w  ww  .j a  va2 s.com*/
            LOG.error("DynamicLayout can contain only HorizontalLayouts as direct child element.");
            break;
        }

        if (tempParentLayout.getComponentCount() != 2) {
            continue;
        }

        if (LabsLayoutHelper.switchToLabelFromEditedField(tempParentLayout)) {
            this.setModifiedComponent(null);
            if (dynamicLayout.getComponentIndex(tempParentLayout) == 2) {
                investigationBean
                        .setDepositEndpoint((String) ((Label) tempParentLayout.getComponent(1)).getValue());
            }
        }
    }
}