@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); for (Element child : design.children()) { Component childComponent = designContext.readDesign(child); if (!(childComponent instanceof Step)) { throw new IllegalArgumentException("Only implementations of " + Step.class.getName() + " are allowed as children of " + getClass().getName()); } stepIterator.add(((Step) childComponent)); } boolean linear = false; Attributes attributes = design.attributes(); if (attributes.hasKey(DESIGN_ATTRIBUTE_LINEAR)) { linear = DesignAttributeHandler.getFormatter() .parse(design.attr(DESIGN_ATTRIBUTE_LINEAR), Boolean.class); } stepIterator.setLinear(linear); }
@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); if (currentTimeFormat != null) { design.attr("time-format", currentTimeFormat == TimeFormat.Format12H ? "12h" : "24h"); } if (startDate != null) { design.attr("start-date", DATE_FORMAT.format(getStartDate())); } if (endDate != null) { design.attr("end-date", DATE_FORMAT.format(getEndDate())); } if (!getZoneId().equals(ZoneId.systemDefault())) { design.attr("time-zone", getZoneId().getId()); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected T readItem(final Element child, final Set<T> selected, final DesignContext context) { final T item = super.readItem(child, selected, context); if (child.hasAttr("style")) { final StyleGenerator<T> styleGenerator = getStyleGenerator(); if (styleGenerator instanceof DeclarativeStyleGenerator) { ((DeclarativeStyleGenerator) styleGenerator).setStyle(item, child.attr("style")); } else { throw new IllegalStateException(String.format("Don't know how " + "to set style using current style generator '%s'", styleGenerator.getClass() .getName())); } } return item; }
@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); for (MenuItem item : getItems()) { design.appendChild(createMenuElement(item, designContext)); } // in many cases there seems to be an empty more menu item if (getMoreMenuItem() != null && !getMoreMenuItem().getText().isEmpty()) { Element moreMenu = createMenuElement(getMoreMenuItem(), designContext); moreMenu.attr("more", ""); design.appendChild(moreMenu); } if (!isHtmlContentAllowed()) { design.attr(DESIGN_ATTR_PLAIN_TEXT, ""); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); for (Element itemElement : design.children()) { if (itemElement.tagName().equals("menu")) { MenuItem menuItem = readMenuElement(itemElement, null); if (itemElement.hasAttr("more")) { setMoreMenuItem(menuItem); } else { getItems().add(menuItem); } } } setHtmlContentAllowed(!design.hasAttr(DESIGN_ATTR_PLAIN_TEXT)); }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); if (attr.hasKey("mime-type")) { MimeType mimeType = null; String mimeTypeString = DesignAttributeHandler.getFormatter().parse( attr.get("mime-type"), String.class); try { mimeType = MimeType.valueOfMimeType(mimeTypeString); } catch (IllegalArgumentException e) { Logger.getLogger(SignatureField.class.getName()).info( "Unsupported MIME-Type found when reading from design : " .concat(mimeTypeString)); } setMimeType(mimeType); } }
@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); design.attr(DESIGN_ATTRIBUTE_LINEAR, stepIterator.isLinear()); List<Step> steps = stepIterator.getSteps(); for (Step step : steps) { Element childElement = designContext.createElement(step); design.appendChild(childElement); } }
@Override public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); Attributes attr = design.attributes(); if (design.hasAttr("time-zone")) { setZoneId(ZoneId.of(DesignAttributeHandler.readAttribute("end-date", attr, String.class))); } if (design.hasAttr("time-format")) { setTimeFormat(TimeFormat.valueOf( "Format" + design.attr("time-format").toUpperCase())); } if (design.hasAttr("start-date")) { setStartDate( ZonedDateTime.ofInstant(DesignAttributeHandler.readAttribute("start-date", attr, Date.class) .toInstant(), getZoneId())); } if (design.hasAttr("end-date")) { setEndDate( ZonedDateTime.ofInstant(DesignAttributeHandler.readAttribute("end-date", attr, Date.class) .toInstant(), getZoneId())); } }
@Override protected Element writeItem(final Element design, final T item, final DesignContext context) { final Element element = design.appendElement("option"); final String caption = getItemCaptionGenerator().apply(item); if (caption != null) { element.html(DesignFormatter.encodeForTextNode(caption)); } else { element.html(DesignFormatter.encodeForTextNode(item.toString())); } element.attr("item", item.toString()); final Resource icon = getItemIconGenerator().apply(item); if (icon != null) { DesignAttributeHandler.writeAttribute("icon", element.attributes(), icon, null, Resource.class, context); } final String style = getStyleGenerator().apply(item); if (style != null) { element.attr("style", style); } if (isSelected(item)) { element.attr("selected", ""); } return element; }
protected Element createMenuElement(MenuItem item, DesignContext designContext) { Element menuElement = new Element(Tag.valueOf("menu"), ""); // Defaults MenuItem def = new MenuItemImpl("", null, null); Attributes attr = menuElement.attributes(); DesignAttributeHandler.writeAttribute("icon", attr, item.getIcon(), def.getIcon(), Resource.class, designContext); DesignAttributeHandler.writeAttribute("disabled", attr, !item.isEnabled(), !def.isEnabled(), boolean.class, designContext); DesignAttributeHandler.writeAttribute("visible", attr, item.isVisible(), def.isVisible(), boolean.class, designContext); DesignAttributeHandler.writeAttribute("separator", attr, item.isSeparator(), def.isSeparator(), boolean.class, designContext); DesignAttributeHandler.writeAttribute("checkable", attr, item.isCheckable(), def.isCheckable(), boolean.class, designContext); DesignAttributeHandler.writeAttribute("checked", attr, item.isChecked(), def.isChecked(), boolean.class, designContext); DesignAttributeHandler.writeAttribute("description", attr, item.getDescription(), def.getDescription(), String.class, designContext); DesignAttributeHandler.writeAttribute("style-name", attr, item.getStyleName(), def.getStyleName(), String.class, designContext); menuElement.append(item.getText()); if (item.hasChildren()) { for (MenuItem subMenu : item.getChildren()) { menuElement .appendChild(createMenuElement(subMenu, designContext)); } } return menuElement; }
@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); Attributes attr = design.attributes(); SignatureField def = designContext.getDefaultInstance(this); MimeType mimeType = getMimeType(); if (mimeType != null) { String mimeTypeDef = null; if (def.getMimeType() != null) { mimeTypeDef = getMimeType().getMimeType(); } DesignAttributeHandler.writeAttribute("mime-type", attr, mimeType.getMimeType(), mimeTypeDef, String.class, designContext); } }
@Override public void readDesign(Element design, DesignContext designContext) { new StepDesignHandler(design, designContext).readDesign(); }
@Override public void writeDesign(Element design, DesignContext designContext) { new StepDesignHandler(design, designContext).writeDesign(); }
private StepDesignHandler(Element design, DesignContext designContext) { this.design = design; this.designContext = designContext; }
@Override protected void readItems(final Element design, final DesignContext context) { setStyleGenerator(new DeclarativeStyleGenerator<>(getStyleGenerator())); super.readItems(design, context); }