List of usage examples for com.vaadin.ui.declarative DesignAttributeHandler readAttribute
public static <T> T readAttribute(String attribute, Attributes attributes, Class<T> outputType)
From source file:com.haulmont.cuba.web.widgets.addons.contextmenu.MenuBar.java
License:Apache License
protected MenuItem readMenuElement(Element menuElement, MenuItem parent) { Resource icon = null;/*from w ww . j a v a 2 s. c o m*/ if (menuElement.hasAttr("icon")) { icon = DesignAttributeHandler.getFormatter().parse(menuElement.attr("icon"), Resource.class); } String caption = ""; List<Element> subMenus = new ArrayList<Element>(); for (Node node : menuElement.childNodes()) { if (node instanceof Element && ((Element) node).tagName().equals("menu")) { subMenus.add((Element) node); } else { caption += node.toString(); } } MenuItemImpl menu = new MenuItemImpl(parent, caption.trim(), icon, null); Attributes attr = menuElement.attributes(); if (menuElement.hasAttr("icon")) { menu.setIcon(DesignAttributeHandler.readAttribute("icon", attr, Resource.class)); } if (menuElement.hasAttr("disabled")) { menu.setEnabled(!DesignAttributeHandler.readAttribute("disabled", attr, boolean.class)); } if (menuElement.hasAttr("visible")) { menu.setVisible(DesignAttributeHandler.readAttribute("visible", attr, boolean.class)); } if (menuElement.hasAttr("separator")) { menu.setSeparator(DesignAttributeHandler.readAttribute("separator", attr, boolean.class)); } if (menuElement.hasAttr("checkable")) { menu.setCheckable(DesignAttributeHandler.readAttribute("checkable", attr, boolean.class)); } if (menuElement.hasAttr("checked")) { menu.setChecked(DesignAttributeHandler.readAttribute("checked", attr, boolean.class)); } if (menuElement.hasAttr("description")) { menu.setDescription(DesignAttributeHandler.readAttribute("description", attr, String.class)); } if (menuElement.hasAttr("style-name")) { menu.setStyleName(DesignAttributeHandler.readAttribute("style-name", attr, String.class)); } if (!subMenus.isEmpty()) { menu.setChildren(new ArrayList<MenuItem>()); } for (Element subMenu : subMenus) { MenuItem newItem = readMenuElement(subMenu, menu); menu.getChildren().add(newItem); } return menu; }
From source file:eu.maxschuster.vaadin.colorpickerfield.AbstractColorPickerField.java
License:Apache License
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attributes = design.attributes(); // see com.vaadin.ui.AbstractColorPicker#readDesign() if (attributes.hasKey("color")) { // Ignore the # character String hexColor = DesignAttributeHandler.readAttribute("color", attributes, String.class).substring(1); setValue(new Color(Integer.parseInt(hexColor, 16))); }/*from w ww . j a va2 s . com*/ if (attributes.hasKey("position")) { String[] position = attributes.get("position").split(","); setPosition(Integer.parseInt(position[0]), Integer.parseInt(position[1])); } if (attributes.hasKey("popup-style")) { setPopupStyle( AbstractColorPicker.PopupStyle.valueOf("POPUP_" + attributes.get("popup-style").toUpperCase())); } }