@Override public String put(String key, String value) { String dataKey = dataKey(key); String oldValue = attributes.hasKey(dataKey) ? attributes.get(dataKey) : null; attributes.put(dataKey, value); return oldValue; }
/** * Read the alignment from the given child component attributes. * * @since 7.6.4 * @param attr * the child component attributes * @return the component alignment */ public static Alignment readAlignment(Attributes attr) { int bitMask = 0; if (attr.hasKey(":middle")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER; } else if (attr.hasKey(":bottom")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_BOTTOM; } else { bitMask += AlignmentInfo.Bits.ALIGNMENT_TOP; } if (attr.hasKey(":center")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER; } else if (attr.hasKey(":right")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_RIGHT; } else { bitMask += AlignmentInfo.Bits.ALIGNMENT_LEFT; } return new Alignment(bitMask); }
/** * Reads the size of this component from the given design attributes. If the * attributes do not contain relevant size information, defaults is * consulted. * * @param attributes * the design attributes */ private void readSize(Attributes attributes) { // read width if (attributes.hasKey("width-auto") || attributes.hasKey("size-auto")) { this.setWidth(null); } else if (attributes.hasKey("width-full") || attributes.hasKey("size-full")) { this.setWidth("100%"); } else if (attributes.hasKey("width")) { this.setWidth(attributes.get("width")); } // read height if (attributes.hasKey("height-auto") || attributes.hasKey("size-auto")) { this.setHeight(null); } else if (attributes.hasKey("height-full") || attributes.hasKey("size-full")) { this.setHeight("100%"); } else if (attributes.hasKey("height")) { this.setHeight(attributes.get("height")); } }
if (startTag.attributes.hasKey("action")) { Element form = tb.getFormElement(); form.attr("action", startTag.attributes.get("action")); tb.processStartTag("label"); String prompt = startTag.attributes.hasKey("prompt") ? startTag.attributes.get("prompt") : "This is a searchable index. Enter search keywords: ";
@Override public void readDesign(Element design, DesignContext designContext) { // process default attributes super.readDesign(design, designContext); // handle children for (Element childComponent : design.children()) { Attributes attr = childComponent.attributes(); Component newChild = designContext.readDesign(childComponent); StringBuilder css = new StringBuilder(); if (attr.hasKey(ATTR_TOP)) { css.append("top:").append(attr.get(ATTR_TOP)).append(';'); } if (attr.hasKey(ATTR_RIGHT)) { css.append("right:").append(attr.get(ATTR_RIGHT)).append(';'); } if (attr.hasKey(ATTR_BOTTOM)) { css.append("bottom:").append(attr.get(ATTR_BOTTOM)).append(';'); } if (attr.hasKey(ATTR_LEFT)) { css.append("left:").append(attr.get(ATTR_LEFT)).append(';'); } if (attr.hasKey(ATTR_Z_INDEX)) { css.append("z-index:").append(attr.get(ATTR_Z_INDEX)) .append(';'); } addComponent(newChild, css.toString()); } }
@Override public void readDesign(Element design, DesignContext context) { super.readDesign(design, context); Attributes attr = design.attributes(); if (attr.hasKey("vertical")) { setOrientation(SliderOrientation.VERTICAL); } if (attr.hasKey("value")) { Double newFieldValue = DesignAttributeHandler.readAttribute("value", attr, Double.class); setValue(newFieldValue); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); if (attr.hasKey("value")) { String text = DesignAttributeHandler.readAttribute("value", attr, String.class); doSetValue(text); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); if (attr.hasKey("maxlength")) { setMaxLength(DesignAttributeHandler.readAttribute("maxlength", attr, Integer.class)); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); if (attr.hasKey("value")) { doSetValue(DesignAttributeHandler.readAttribute("value", attr, String.class)); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); if (attr.hasKey("readonly")) { setReadOnly(DesignAttributeHandler.readAttribute("readonly", attr, Boolean.class)); } }
@Override protected void doReadDesign(Element design, DesignContext context) { super.doReadDesign(design, context); Attributes attrs = design.attributes(); if (attrs.hasKey("hierarchy-column")) { setHierarchyColumn(DesignAttributeHandler .readAttribute("hierarchy-column", attrs, String.class)); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attrs = design.attributes(); if (attrs.hasKey("selection-mode")) { setSelectionMode(DesignAttributeHandler.readAttribute( "selection-mode", attrs, SelectionMode.class)); } if (attrs.hasKey("content-mode")) { setContentMode(DesignAttributeHandler.readAttribute("content-mode", attrs, ContentMode.class)); } readItems(design.children()); }
@Override protected void doReadDesign(Element design, DesignContext context) { Attributes attrs = design.attributes(); if (design.hasAttr(DECLARATIVE_DATA_ITEM_TYPE)) { String itemType = design.attr(DECLARATIVE_DATA_ITEM_TYPE); setBeanType(itemType); } if (attrs.hasKey("selection-mode")) { setSelectionMode(DesignAttributeHandler.readAttribute( "selection-mode", attrs, SelectionMode.class)); } Attributes attr = design.attributes(); if (attr.hasKey("selection-allowed")) { setReadOnly(DesignAttributeHandler .readAttribute("selection-allowed", attr, Boolean.class)); } if (attrs.hasKey("rows")) { setHeightByRows(DesignAttributeHandler.readAttribute("rows", attrs, double.class)); } readStructure(design, context); // Read frozen columns after columns are read. if (attrs.hasKey("frozen-columns")) { setFrozenColumnCount(DesignAttributeHandler .readAttribute("frozen-columns", attrs, int.class)); } }
/** * Reads the given attribute from a set of attributes. * * @param attribute * the attribute key * @param attributes * the set of attributes to read from * @param outputType * the output type for the attribute * @return the attribute value or null */ public static <T> T readAttribute(String attribute, Attributes attributes, Class<T> outputType) { if (!getFormatter().canConvert(outputType)) { throw new IllegalArgumentException( "output type: " + outputType.getName() + " not supported"); } if (!attributes.hasKey(attribute)) { return null; } else { try { String value = attributes.get(attribute); return getFormatter().parse(value, outputType); } catch (Exception e) { throw new DesignException( "Failed to read attribute " + attribute, e); } } }
@Override public void readDesign(Element design, DesignContext designContext) { // process default attributes super.readDesign(design, designContext); setMargin(readMargin(design, getMargin(), designContext)); // handle children for (Element childComponent : design.children()) { Attributes attr = childComponent.attributes(); Component newChild = designContext.readDesign(childComponent); addComponent(newChild); // handle alignment setComponentAlignment(newChild, DesignAttributeHandler.readAlignment(attr)); // handle expand ratio if (attr.hasKey(":expand")) { String value = attr.get(":expand"); if (!value.isEmpty()) { try { float ratio = Float.valueOf(value); setExpandRatio(newChild, ratio); } catch (NumberFormatException nfe) { getLogger() .info("Failed to parse expand ratio " + value); } } else { setExpandRatio(newChild, 1.0f); } } } }
if (attributes.hasKey(LOCAL_ID_ATTRIBUTE)) { String localId = attributes.get(LOCAL_ID_ATTRIBUTE); boolean mappingExists = setComponentLocalId(component, localId);
/** * Reads the listing specific state from the given design. * <p> * This method is separated from {@link #readDesign(Element, DesignContext)} * to be overridable in subclasses that need to replace this, but still must * be able to call {@code super.readDesign(...)}. * * @see #doWriteDesign(Element, DesignContext) * * @param design * The element to obtain the state from * @param context * The DesignContext instance used for parsing the design */ protected void doReadDesign(Element design, DesignContext context) { Attributes attr = design.attributes(); if (attr.hasKey("readonly")) { setReadOnly(DesignAttributeHandler.readAttribute("readonly", attr, Boolean.class)); } setItemCaptionGenerator( new DeclarativeCaptionGenerator<>(getItemCaptionGenerator())); setItemIconGenerator( new DeclarativeIconGenerator<>(getItemIconGenerator())); readItems(design, context); }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); String content; // plain-text (default is html) Boolean plain = DesignAttributeHandler .readAttribute(DESIGN_ATTR_PLAIN_TEXT, attr, Boolean.class); if (plain == null || !plain) { setCaptionAsHtml(true); content = design.html(); } else { // content is not intended to be interpreted as HTML, // so html entities need to be decoded content = DesignFormatter.decodeFromTextNode(design.html()); } setCaption(content); if (attr.hasKey("icon-alt")) { setIconAlternateText(DesignAttributeHandler .readAttribute("icon-alt", attr, String.class)); } // click-shortcut removeClickShortcut(); ShortcutAction action = DesignAttributeHandler .readAttribute("click-shortcut", attr, ShortcutAction.class); if (action != null) { setClickShortcut(action.getKeyCode(), action.getModifiers()); } }