List of usage examples for com.vaadin.ui Label isReadOnly
protected boolean isReadOnly()
From source file:nz.co.senanque.vaadinsupport.application.MaduraSessionManager.java
License:Apache License
/** * Check all the other fields to ensure they are still valid * this includes any buttons that were registered because they * get disabled if there are errors on the relevant form or * if the requiredness is incomplete./* w w w. j a va 2 s. co m*/ * * @param field */ public void updateOtherFields(AbstractField field) { PermissionManager permissionmanager = getPermissionManager(); Collection<AbstractField> fields = getFields(); Collection<Label> labels = getLabels(); for (Label fieldx : labels) { com.vaadin.data.Property p = fieldx.getPropertyDataSource(); if (p != null && p instanceof LabelProperty) { fieldx.requestRepaint(); } } for (AbstractField fieldx : fields) { if (fieldx.equals(field)) continue; if ((fieldx instanceof Button) && !(fieldx instanceof CheckBox)) { com.vaadin.data.Property p = fieldx.getPropertyDataSource(); if (p != null && p instanceof ButtonProperty) { ((ButtonProperty) p).getPainter().paint((Button) fieldx); fieldx.requestRepaint(); } continue; } if (fieldx instanceof MenuItemWrapper) { MenuItemPainter menuItemPainter = ((MenuItemWrapper) fieldx).getMenuItemPainter(); MenuItem menuItem = (MenuItem) fieldx.getData(); if (menuItemPainter != null) { menuItemPainter.paint(menuItem); fieldx.requestRepaint(); } continue; } MaduraPropertyWrapper property = null; try { property = (MaduraPropertyWrapper) fieldx.getPropertyDataSource(); } catch (Exception e) { // ignore property = null; } if (property != null) { if (logger.isDebugEnabled()) { logger.debug("evaluating field: {}", property.getName()); if (fieldx.isEnabled() != property.isEnabled()) { logger.debug("Enabled: {} {}", fieldx.isEnabled(), property.isEnabled()); } if (fieldx.isReadOnly() != property.isReadOnly()) { logger.debug("ReadOnly: {} {}", fieldx.isReadOnly(), property.isReadOnly()); } if (fieldx.isRequired() != property.isRequired()) { logger.debug("Required: {} {}", fieldx.isRequired(), property.isRequired()); } if (fieldx.isVisible() != property.isVisible()) { logger.debug("Visible: {} {}", fieldx.isVisible(), property.isVisible()); } } fieldx.setEnabled(property.isEnabled()); fieldx.setReadOnly(property.isReadOnly()); fieldx.setRequired(property.isRequired()); fieldx.setVisible(property.isVisible()); // Permissions trump rules if (!permissionmanager.hasPermission(property.getReadPermission())) { fieldx.setVisible(false); } if (!permissionmanager.hasPermission(property.getWritePermission())) { fieldx.setEnabled(false); } if (fieldx instanceof AbstractSelect) { AbstractSelect select = (AbstractSelect) fieldx; List<ChoiceBase> availableList = new ArrayList<ChoiceBase>(); for (ChoiceBase v : property.getAvailableValues()) { availableList.add(v); } logger.debug("{} availableList {}", property.getName(), availableList); Collection<?> itemIds = select.getItemIds(); List<Object> killList = new ArrayList<Object>(); for (Object itemId : itemIds) { if (availableList.contains(itemId)) continue; killList.add(itemId); } for (Object kill : killList) { select.removeItem(kill); } for (ChoiceBase cb : availableList) { select.addItem(cb); } logger.debug("Select {} value \"{}\", updated to {}", new Object[] { property.getName(), select.getValue(), select.getItemIds() }); } } fieldx.requestRepaint(); } }