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

项目: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);
}
项目:calendar-component    文件:Calendar.java   
@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());
    }
}
项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
@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;
}
项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
@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;
}
项目:context-menu    文件:MenuBar.java   
@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, "");
    }
}
项目:context-menu    文件:MenuBar.java   
@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));
}
项目: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);
    }
}
项目:md-stepper    文件:AbstractStepper.java   
@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);
  }
}
项目: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);
    }
}
项目:md-stepper    文件:Step.java   
@Override
public void readDesign(Element design, DesignContext designContext) {
  new StepDesignHandler(design, designContext).readDesign();
}
项目:md-stepper    文件:Step.java   
@Override
public void writeDesign(Element design, DesignContext designContext) {
  new StepDesignHandler(design, designContext).writeDesign();
}
项目:md-stepper    文件:Step.java   
private StepDesignHandler(Element design, DesignContext designContext) {
  this.design = design;
  this.designContext = designContext;
}
项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
@Override
protected void readItems(final Element design, final DesignContext context) {
    setStyleGenerator(new DeclarativeStyleGenerator<>(getStyleGenerator()));
    super.readItems(design, context);
}
项目:vaadin-combobox-multiselect    文件:ComboBoxMultiselect.java   
@Override
protected void readItems(final Element design, final DesignContext context) {
    setStyleGenerator(new DeclarativeStyleGenerator<>(getStyleGenerator()));
    super.readItems(design, context);
}