Java 类com.vaadin.ui.declarative.DesignAttributeHandler 实例源码

项目:md-stepper    文件:AbstractStepper.java   
@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);
}
项目:Vaadin-SignatureField    文件:SignatureField.java   
@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);
    }
}
项目:calendar-component    文件:Calendar.java   
@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()));
    }
}
项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
@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;
}
项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
@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;
}
项目:context-menu    文件:MenuBar.java   
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;
}
项目:Vaadin-SignatureField    文件:SignatureField.java   
@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);
    }
}