Example usage for com.vaadin.ui AbstractComponent setReadOnly

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

Introduction

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

Prototype

protected void setReadOnly(boolean readOnly) 

Source Link

Document

Sets the read-only status in the state of this AbstractComponent .

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;/*from  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  w  w .  j a  v 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.escidoc.admintool.view.util.LayoutHelper.java

License:Open Source License

/**
 * @param className/*from   w  w  w.  j  ava 2 s. c  o m*/
 * @param item
 * @param readOnly
 * @param text
 * @param propertyName
 * @return AbstractComponent
 */
public static synchronized AbstractComponent createCheckBoxElement(final String className,
        final POJOItem<?> item, final boolean readOnly, final String text, final String propertyName) {
    final AbstractComponent comp = new CheckBox(text);
    comp.setReadOnly(readOnly);
    ((CheckBox) comp).setWriteThrough(false);
    ((CheckBox) comp).setPropertyDataSource(item.getItemProperty(propertyName));
    List<Field> attachedFields = ATTACHED_FIELD_MAP.get(className);
    if (attachedFields == null) {
        attachedFields = new ArrayList<Field>();
        ATTACHED_FIELD_MAP.put(className, attachedFields);
    }
    attachedFields.add((Field) comp);
    return comp;
}

From source file:nz.co.senanque.vaadinsupport.application.MaduraSessionManager.java

License:Apache License

private void setPermissions(MaduraPropertyWrapper property, AbstractComponent field) {
    PermissionManager permissionmanager = getPermissionManager();
    if (!permissionmanager.hasPermission(property.getWritePermission())) {
        field.setReadOnly(true);
    }//from   w  w  w. j a v  a 2 s  .  c o  m
    if (!permissionmanager.hasPermission(property.getReadPermission())) {
        field.setVisible(false);
    }
}