Example usage for com.vaadin.ui AbstractComponent setCaption

List of usage examples for com.vaadin.ui AbstractComponent setCaption

Introduction

In this page you can find the example usage for com.vaadin.ui AbstractComponent setCaption.

Prototype

@Override
    public void setCaption(String caption) 

Source Link

Usage

From source file:com.coatl.vaadin.abc.ixABCDialogos.java

ixDefinicionDeForma getForma(String forma, String tipo) {
    Stack<AbstractComponent> pila = new Stack();
    Map<String, AbstractComponent> componentes = new HashMap();
    AbstractComponent ultimo = null;/*  w w  w. j a  v a 2s  .  com*/

    String[] cmds = forma.split(" ");

    for (String cmd : cmds) {
        cmd = cmd.trim();
        if (!cmd.equals("")) {
            //System.out.println("CMD> [" + cmd + "]");
            if (cmd.equals("bConfBorrar")) {
                agregar(pila, getbConfBorrar());

            } else if (cmd.equals("bBorrar")) {
                agregar(pila, getbBorrar());

            } else if (cmd.equals("bGuardar")) {
                agregar(pila, getbGuardar());

            } else if (cmd.equals("bCrear")) {
                agregar(pila, getbCrear());
            } else if (cmd.startsWith("H")) {
                HorizontalLayout hl = new HorizontalLayout();
                if (cmd.contains("m")) {
                    hl.setMargin(true);
                }
                agregar(pila, hl);
            } else if (cmd.startsWith("V")) {
                VerticalLayout vl = new VerticalLayout();
                if (cmd.contains("m")) {
                    vl.setMargin(true);
                }
                agregar(pila, vl);
            } else if (cmd.startsWith("F")) {
                FormLayout fl = new FormLayout();
                if (cmd.contains("m")) {
                    fl.setMargin(true);
                }
                agregar(pila, fl);
            } else if (cmd.equals(".")) {
                ultimo = pila.pop();
                //System.out.println("Sacando de pila a " + ultimo);
            } else if (cmd.startsWith("'")) {
                String txt = cmd.substring(1);
                while (txt.contains("~")) {
                    txt = txt.replace("~", " ");
                }
                Label l = new Label(txt);

                agregar(pila, l);
            } else {
                //System.out.println("Buscando columna [" + cmd + "]");
                ixDefinicionDeColumna columna = columnas.get(cmd);
                String claseControl = columna.getClaseControl();
                if (claseControl == null) {
                    claseControl = "com.vaadin.ui.TextField";
                }

                AbstractComponent con = null;

                try {
                    con = (AbstractComponent) this.getClass().getClassLoader().loadClass(claseControl)
                            .newInstance();
                } catch (Exception ex) {
                    System.out.println("ERROR INSTANCIANDO> [" + claseControl + "], " + ex);
                }
                con.setCaption(this.getTituloColumna(cmd));
                if (con != null) {
                    agregar(pila, con);
                    componentes.put(cmd, con);
                }

                if (tipo != null) {
                    if (tipo.toLowerCase().equals("c")) {
                        if (columna.isSoloLecturaCrear() || columna.isSoloLectura()) {
                            con.setReadOnly(true);
                        }
                    }
                    if (tipo.toLowerCase().equals("e") || tipo.toLowerCase().equals("g")) {
                        if (columna.isSoloLecturaGuardar() || columna.isSoloLectura()) {
                            con.setReadOnly(true);
                        }
                    }
                    if (tipo.toLowerCase().equals("b")) {

                        con.setReadOnly(true);
                    }
                }

            }
        }
    }

    while (pila.size() > 0) {
        ultimo = pila.pop();
    }

    ixDefinicionDeForma res = new ixDefinicionDeForma();
    res.setComponente(ultimo);
    res.setComponentes(componentes);

    return res;
}

From source file:com.foc.vaadin.gui.components.tableAndTree.FVColGen_FocProperty.java

License:Apache License

private Object getDisplayObject_ForProperty_Editable(FocObject focObject, FProperty property,
        FVTableColumn column, Object columnId) {
    Object objReturned = null;/*from   w  ww .jav a 2  s .  c o  m*/

    FField field = property != null ? property.getFocField() : null;

    if (field instanceof FImageField) {
        objReturned = (AbstractComponent) getTableTreeDelegate().newGuiComponent(focObject, column, property);
        FVImageField imageField = (FVImageField) objReturned;
        imageField.setWidth("60px");
        imageField.setHeight("50px");
    } else if (field instanceof FCloudStorageField) {
        FCloudStorageProperty csProp = (FCloudStorageProperty) property;
        if (csProp != null) {
            FVImageField imageField = new FVImageField(csProp, column.getAttributes());
            if (imageField.getBufferedImage() == null) {
                Resource resource = imageField.getResourceAndSetIcon();
                if (resource != null) {
                    Button docIcon = new Button();
                    docIcon.setStyleName(Runo.BUTTON_LINK);
                    docIcon.setWidth("-1px");
                    docIcon.setHeight("-1px");
                    docIcon.setIcon(resource);
                    objReturned = docIcon;
                }
            } else {
                Image image = imageField.getEmbedded();
                if (image != null) {
                    int maxWidth = 150;
                    int maxHeight = 150;
                    imageField.resizeImage(image, maxWidth, maxHeight);
                }
                objReturned = imageField;
            }
        }
    } else {
        objReturned = "";
        if (property != null) {
            AbstractComponent abstractComponent = (AbstractComponent) getTableTreeDelegate()
                    .newGuiComponent(focObject, column, property);

            if (abstractComponent != null) {
                objReturned = abstractComponent;
                abstractComponent.addStyleName("editableStyle");

                if (abstractComponent instanceof FVTextField) {
                    // ((FVTextField) abstractComponent).selectAll();
                    /*
                     * ((FVTextField) abstractComponent).addFocusListener(new
                     * FocusListener() { private boolean updating = false; public void
                     * focus(FocusEvent event) { if(!updating){ updating = true;
                     * ((FVTextField) abstractComponent).selectAll(); updating = false;
                     * } } });
                     */
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    if (getFormulaFocusListener() != null) {
                        ((FVTextField) abstractComponent).addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        ((FVTextField) abstractComponent).addFocusListener(getReadOnlyFocusListener(true));
                        ((FVTextField) abstractComponent).addBlurListener(getReadOnlyBlurListener(true));
                    }
                } else if (abstractComponent instanceof FVCheckBox) {
                    abstractComponent.setCaption("");
                } else if (abstractComponent instanceof FVComboBox) {
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    if (getFormulaFocusListener() != null) {
                        ((FVComboBox) abstractComponent).addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        ((FVComboBox) abstractComponent).addFocusListener(getReadOnlyFocusListener(true));
                        ((FVComboBox) abstractComponent).addBlurListener(getReadOnlyBlurListener(true));
                    }

                } else if (abstractComponent instanceof FVObjectPopupView) {
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    FVObjectPopupView popupView = ((FVObjectPopupView) abstractComponent);
                    if (popupView != null && getFormulaFocusListener() != null) {
                        popupView.addPopupVisibilityListener(new PopupVisibilityListener() {

                            @Override
                            public void popupVisibilityChange(PopupVisibilityEvent event) {
                                if (getTableTreeDelegate() != null && event != null
                                        && event.getPopupView() != null
                                        && event.getPopupView() instanceof FVObjectPopupView) {
                                    FVObjectPopupView popupView = (FVObjectPopupView) event.getPopupView();
                                    getTableTreeDelegate().adjustFormulaLayoutForComponent(popupView);
                                }
                            }
                        });
                        //                     popupView.addFocusListener(getFormulaFocusListener());
                    }
                    //                  if(isUseReadOnlyFlag()){
                    //                     popupView.addFocusListener(getReadOnlyFocusListener(true));
                    //                     popupView.addBlurListener(getReadOnlyBlurListener(true));
                    //                  }
                } else if (abstractComponent instanceof FVObjectSelector) {
                    // Adding the focus listener on the component to be used in the
                    // formula layout
                    FVObjectComboBox comboBox = ((FVObjectSelector) abstractComponent).getComboBox();
                    if (comboBox != null && getFormulaFocusListener() != null) {
                        comboBox.addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        comboBox.addFocusListener(getReadOnlyFocusListener(true));
                        comboBox.addBlurListener(getReadOnlyBlurListener(true));
                    }
                } else if (abstractComponent instanceof FVObjectComboBox && getFormulaFocusListener() != null) {
                    FVObjectComboBox comboBox = (FVObjectComboBox) abstractComponent;
                    if (comboBox != null) {
                        comboBox.addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        comboBox.addFocusListener(getReadOnlyFocusListener(true));
                        comboBox.addBlurListener(getReadOnlyBlurListener(true));
                    }
                } else if (abstractComponent instanceof FVMultipleChoiceComboBox
                        && getFormulaFocusListener() != null) {
                    FVMultipleChoiceComboBox comboBox = (FVMultipleChoiceComboBox) abstractComponent;
                    if (comboBox != null) {
                        comboBox.addFocusListener(getFormulaFocusListener());
                    }
                    if (isUseReadOnlyFlag()) {
                        comboBox.addFocusListener(getReadOnlyFocusListener(true));
                        comboBox.addBlurListener(getReadOnlyBlurListener(true));
                    }
                }
                // Setting the column and row Ids of component
                FocXMLGuiComponent focXMLGuiComponent = (FocXMLGuiComponent) abstractComponent;
                FocXMLGuiComponentDelegate focXMLGuiComponentDelegate = focXMLGuiComponent.getDelegate();
                if (focXMLGuiComponentDelegate != null) {
                    focXMLGuiComponentDelegate.setColumnId(columnId);
                    if (focObject != null && focObject.getReference() != null) {
                        focXMLGuiComponentDelegate.setRowId(focObject.getReference().getLong());
                    }
                }
                abstractComponent.setId(column.getDataPath());
                abstractComponent.setWidth("100%");// This was added to get the node
                                                   // name text field in the BKDN
                                                   // tree big enough to enter or see
                                                   // the value
                                                   // If we put 100% in the xml we get a small width extendable. but with
                                                   // this solution we have a fixed minimum width in the xml + the 100%
                                                   // allows us to change the width
                if (isUseReadOnlyFlag()) {
                    abstractComponent.setReadOnly(true);
                }
            }
        }
    }

    if (property != null && property.isInherited()) {
        FProperty inheritedProp = null;
        try {
            inheritedProp = property.getFocField().getInheritedPropertyGetter()
                    .getInheritedProperty(property.getFocObject(), property);
        } catch (Exception e) {
            Globals.logException(e);
        }
        if (inheritedProp != null) {
            objReturned = inheritedProp;
        }
    }
    return objReturned;
}

From source file:de.fzi.fhemapi.view.vaadin.ui.UIHelper.java

License:Apache License

/**
 * Builds an attribute panel. This build a caption on the left side. This should be altered if
 * one would like to change the appearance of the whole UI.
 * @param attributeName the caption of the component
 * @param component a component//from   w  w w.  j a  va  2  s. c o m
 * @return a horizontallayout.
 */
public static HorizontalLayout buildAttributePanel(String attributeName, AbstractComponent component) {
    // common part: create layout
    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setImmediate(false);
    horizontalLayout.setWidth("100.0%");
    horizontalLayout.setHeight("-1px");
    horizontalLayout.setMargin(false);

    horizontalLayout.addComponent(buildRichTextField("<b>" + attributeName + "</b>"));
    horizontalLayout.addComponent(component);
    component.setCaption(attributeName);
    //      component.set

    return horizontalLayout;
}

From source file:pt.ist.vaadinframework.ui.AbstractViewerFactory.java

License:Open Source License

@Override
public Viewer createViewer(Item item, Object propertyId, Component uiContext) {
    Viewer viewer = makeViewer(item, propertyId, uiContext);
    AbstractComponent component = (AbstractComponent) viewer;
    component.setCaption(makeCaption(item, propertyId, uiContext));
    component.setDescription(makeDescription(item, propertyId, uiContext));
    return viewer;
}

From source file:pt.ist.vaadinframework.ui.DefaultViewerFactory.java

License:Open Source License

@Override
public final Viewer createViewer(Item item, Object propertyId, Component uiContext) {
    Viewer viewer = makeViewer(item, propertyId, uiContext);
    AbstractComponent component = (AbstractComponent) viewer;
    component.setDescription(makeDescription(item, propertyId, uiContext));
    component.setCaption(makeCaption(item, propertyId, uiContext));
    return viewer;
}

From source file:uk.co.q3c.v7.i18n.AnnotationI18NInterpreter.java

License:Apache License

private void processComponent(I18NListener listener, Field field) {
    if (field.isAnnotationPresent(I18N.class)) {
        I18N annotation = field.getAnnotation(I18N.class);
        LabelKeys captionKey = annotation.caption();
        DescriptionKeys descriptionKey = annotation.description();
        DescriptionKeys valueKey = annotation.value();

        String captionValue = captionKey.equals(LabelKeys._notdefined_) ? null : captionKey.getValue(locale);
        String descriptionValue = descriptionKey.equals(DescriptionKeys._notdefined_) ? null
                : descriptionKey.getValue(locale);

        field.setAccessible(true);//from ww  w .java  2 s. c om
        try {
            AbstractComponent c = (AbstractComponent) field.get(listener);
            if (captionValue != null) {
                c.setCaption(captionValue);
            }
            if (descriptionValue != null) {
                c.setDescription(descriptionValue);
            }
            c.setLocale(locale);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            log.error("Unable to set I18N caption or description for " + field.getName(), e);
        }

        // These components have a value. Usually I18N would only be used for Label values. If no key is provided
        // the component value is left unchanged
        if (valueKey != null) {
            if (Property.class.isAssignableFrom(field.getType())) {
                try {
                    @SuppressWarnings("unchecked")
                    Property<String> c = (Property<String>) field.get(listener);
                    String valueValue = valueKey.equals(DescriptionKeys._notdefined_) ? null
                            : valueKey.getValue(locale);
                    if (valueValue != null) {
                        c.setValue(valueValue);
                    }
                } catch (Exception e) {
                    log.error("Unable to set I18N value for " + field.getName(), e);

                }
            }
        }

    }

}

From source file:uk.co.q3c.v7.i18n.AnnotationI18NTranslator.java

License:Apache License

private void decodeAnnotation(I18NListener listener, Field field, Annotation annotation,
        Provider<? extends I18NAnnotationReader> provider) {

    // get a reader
    I18NAnnotationReader reader = provider.get();

    // get the keys from the reader
    I18NKey<?> captionKey = reader.caption(annotation);
    I18NKey<?> descriptionKey = reader.description(annotation);
    I18NKey<?> valueKey = reader.value(annotation);

    // check for nulls. Nulls are used for caption and description so that content can be cleared.
    // for value, this is not the case, as it may be a bad idea
    String captionValue = captionKey.isNullKey() ? null : captionKey.getValue(currentLocale.getLocale());
    String descriptionValue = descriptionKey.isNullKey() ? null
            : descriptionKey.getValue(currentLocale.getLocale());

    // set caption and description
    field.setAccessible(true);//from w w  w.  ja  v a 2 s .  c om
    try {
        AbstractComponent c = (AbstractComponent) field.get(listener);
        if (captionValue != null) {
            c.setCaption(captionValue);
        }
        if (descriptionValue != null) {
            c.setDescription(descriptionValue);
        }
        c.setLocale(currentLocale.getLocale());
    } catch (IllegalArgumentException | IllegalAccessException e) {
        log.error("Unable to set I18N caption or description for " + field.getName(), e);
    }

    // These components have a value. Usually I18N would only be used for Label values. If no key is provided
    // the component value is left unchanged
    if (valueKey != null) {
        if (Property.class.isAssignableFrom(field.getType())) {
            try {
                @SuppressWarnings("unchecked")
                Property<String> c = (Property<String>) field.get(listener);
                String valueValue = valueKey.isNullKey() ? null : valueKey.getValue(currentLocale.getLocale());
                if (valueValue != null) {
                    c.setValue(valueValue);
                }
            } catch (Exception e) {
                log.error("Unable to set I18N value for " + field.getName(), e);

            }
        }
    }

    // Table columns need special treatment
    if (Table.class.isAssignableFrom(field.getType())) {
        try {
            Table table = (Table) field.get(listener);
            Object[] columns = table.getVisibleColumns();
            List<String> headers = new ArrayList<>();
            for (Object column : columns) {
                if (column instanceof LabelKey) {
                    LabelKey columnid = (LabelKey) column;
                    String header = columnid.getValue(currentLocale.getLocale());
                    headers.add(header);
                } else {
                    headers.add(column.toString());
                }
            }
            String headerArray[] = headers.toArray(new String[] {});
            table.setColumnHeaders(headerArray);

        } catch (Exception e) {
            log.error("Unable to set I18N table columns headers for " + field.getName(), e);
        }

    }
}

From source file:uk.q3c.krail.core.i18n.DefaultI18NProcessor.java

License:Apache License

/**
 * Applies annotation values to {@code component}
 *
 * @param component        the component to be updated
 * @param annotationValues the annotation values to apply
 * @param annotationInfo   used primarily to identify the Field, and therefore its name
 *//*w ww .  j  ava 2  s  .  c om*/
private void applyAnnotationValues(AbstractComponent component, AnnotationValues annotationValues,
        AnnotationInfo annotationInfo) {
    // set locale first
    Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get()
            : currentLocale.getLocale();
    component.setLocale(locale);

    // set caption, description & value if available
    if (annotationValues.captionKey.isPresent()) {
        component.setCaption(translate.from(annotationValues.captionKey.get(), locale));
    }
    if (annotationValues.descriptionKey.isPresent()) {
        component.setDescription(translate.from(annotationValues.descriptionKey.get(), locale));
    }
    if (annotationValues.valueKey.isPresent()) {
        if (component instanceof HasValue) {
            ((HasValue) component).setValue(translate.from(annotationValues.valueKey.get(), locale));
            return;
        } else {
            log.warn("Field {} has a value annotation but does not implement HasValue.  Annotation ignored",
                    annotationInfo.getField().getName());
        }
    }

}

From source file:uk.q3c.krail.i18n.DefaultI18NProcessor.java

License:Apache License

/**
 * Applies annotation values to {@code component}
 *
 * @param component// w w w.  j  a  v  a2s  . c  om
 *         the component to be updated
 * @param annotationValues
 *         the annotation values to apply
 * @param annotationInfo
 *         used primarily to identify the Field, and therefore its name
 */
private void applyAnnotationValues(AbstractComponent component, AnnotationValues annotationValues,
        AnnotationInfo annotationInfo) {
    // set locale first
    Locale locale = annotationValues.locale.isPresent() ? annotationValues.locale.get()
            : currentLocale.getLocale();
    component.setLocale(locale);

    // set caption, description & value if available
    if (annotationValues.captionKey.isPresent()) {
        component.setCaption(translate.from(annotationValues.captionKey.get(), locale));
    }
    if (annotationValues.descriptionKey.isPresent()) {
        component.setDescription(translate.from(annotationValues.descriptionKey.get(), locale));
    }
    if (annotationValues.valueKey.isPresent()) {
        if (component instanceof Property) {
            //noinspection unchecked
            ((Property) component).setValue(translate.from(annotationValues.valueKey.get(), locale));
        } else {
            log.warn("Field {} has a value annotation but does not implement Property.  Annotation ignored",
                    annotationInfo.getField().getName());
        }
    }

}