Example usage for com.vaadin.server PaintTarget addAttribute

List of usage examples for com.vaadin.server PaintTarget addAttribute

Introduction

In this page you can find the example usage for com.vaadin.server PaintTarget addAttribute.

Prototype

public void addAttribute(String string, Object[] keys);

Source Link

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.CubaTreeTable.java

License:Apache License

@Override
protected void paintAdditionalData(PaintTarget target) throws PaintException {
    if (reqFirstRowToPaint == -1 && items instanceof AggregationContainer && isAggregatable()
            && !((AggregationContainer) items).getAggregationPropertyIds().isEmpty() && isShowTotalAggregation()
            && Table.AggregationStyle.TOP.equals(getAggregationStyle())) {
        paintAggregationRow(target, ((AggregationContainer) items).aggregate(new Context(items.getItemIds())));
    }//from  w  w  w . j  av  a 2s .  c o  m

    // paint cuba-ids

    AppUI current = AppUI.getCurrent();
    if (current != null && current.isTestMode()) {
        ArrayList<String> visibleColOrder = new ArrayList<>();
        for (Object columnId : visibleColumns) {
            if (!isColumnCollapsed(columnId)) {
                visibleColOrder.add(columnId.toString());
            }
        }
        target.addAttribute("colcubaids", visibleColOrder.toArray());
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.CubaTwinColSelect.java

License:Apache License

@Override
protected void paintItem(PaintTarget target, Object itemId) throws PaintException {
    super.paintItem(target, itemId);

    if (styleGenerator != null) {
        String style = styleGenerator.generateStyle(this, itemId, isSelected(itemId));
        if (!StringUtils.isEmpty(style)) {
            target.addAttribute("style", style);
        }//from   www .  j  a v a 2 s  . c o m
    }
}

From source file:com.haulmont.cuba.web.toolkit.ui.CubaWidgetsTree.java

License:Apache License

@Override
protected void paintItem(PaintTarget target, Object itemId, LinkedList<String> selectedKeys,
        LinkedList<String> expandedKeys) throws PaintException {
    super.paintItem(target, itemId, selectedKeys, expandedKeys);

    if (itemIds.indexOf(itemId) >= 0) {
        target.addAttribute("widgetIndex", itemIds.indexOf(itemId));
    }/*from www. j ava2  s .c  o  m*/
}

From source file:com.haulmont.cuba.web.widgets.addons.contextmenu.MenuBar.java

License:Apache License

/** Paint (serialise) the component for the client. */
@Override/*  w ww .  j a v a 2 s  .c  o  m*/
public void paintContent(PaintTarget target) throws PaintException {
    target.addAttribute(MenuBarConstants.OPEN_ROOT_MENU_ON_HOWER, openRootOnHover);

    if (isHtmlContentAllowed()) {
        target.addAttribute(MenuBarConstants.HTML_CONTENT_ALLOWED, true);
    }

    target.startTag("options");

    if (getWidth() > -1) {
        target.startTag("moreItem");
        target.addAttribute("text", moreItem.getText());
        if (moreItem.getIcon() != null) {
            target.addAttribute("icon", moreItem.getIcon());
        }
        target.endTag("moreItem");
    }

    target.endTag("options");
    target.startTag("items");

    // This generates the tree from the contents of the menu
    for (MenuItem item : getItems()) {
        paintItem(target, item);
    }

    target.endTag("items");
}

From source file:com.haulmont.cuba.web.widgets.addons.contextmenu.MenuBar.java

License:Apache License

private void paintItem(PaintTarget target, MenuItem item) throws PaintException {
    if (!item.isVisible()) {
        return;//ww  w.  j a va 2 s. co  m
    }

    target.startTag("item");

    target.addAttribute("id", item.getId());

    if (item.getStyleName() != null) {
        target.addAttribute(MenuBarConstants.ATTRIBUTE_ITEM_STYLE, item.getStyleName());
    }

    if (item.isSeparator()) {
        target.addAttribute("separator", true);
    } else {
        target.addAttribute("text", item.getText());

        Command command = item.getCommand();
        if (command != null) {
            target.addAttribute("command", true);
        }

        Resource icon = item.getIcon();
        if (icon != null) {
            target.addAttribute(MenuBarConstants.ATTRIBUTE_ITEM_ICON, icon);
        }

        if (!item.isEnabled()) {
            target.addAttribute(MenuBarConstants.ATTRIBUTE_ITEM_DISABLED, true);
        }

        String description = item.getDescription();
        if (description != null && description.length() > 0) {
            target.addAttribute(MenuBarConstants.ATTRIBUTE_ITEM_DESCRIPTION, description);
        }
        if (item.isCheckable()) {
            // if the "checked" attribute is present (either true or false),
            // the item is checkable
            target.addAttribute(MenuBarConstants.ATTRIBUTE_CHECKED, item.isChecked());
        }
        if (item.hasChildren()) {
            for (MenuItem child : item.getChildren()) {
                paintItem(target, child);
            }
        }

    }

    target.endTag("item");
}

From source file:com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.java

License:Apache License

/**
 * {@inheritDoc}/*from w ww.  j  a v  a 2 s . c  om*/
 * 
 */
public void paintContent(PaintTarget target) throws PaintException {

    if (dropHandler != null && isEnabled()) {
        dropHandler.getAcceptCriterion().paint(target);
    }

    // Drop ratios
    target.addAttribute(Constants.ATTRIBUTE_HORIZONTAL_DROP_RATIO, getState().cellLeftRightDropRatio);

    // Drag mode
    if (isEnabled()) {
        target.addAttribute(Constants.DRAGMODE_ATTRIBUTE, getState().ddState.dragMode.ordinal());
    } else {
        target.addAttribute(Constants.DRAGMODE_ATTRIBUTE, LayoutDragMode.NONE.ordinal());
    }

    // Haulmont API. The constant was extracted into a separate class
    // Shims
    target.addAttribute(SharedConstants.SHIM_ATTRIBUTE, getState().ddState.iframeShims);
}

From source file:com.haulmont.cuba.web.widgets.CubaGroupTable.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*from   ww w.  j  av  a  2 s.  c  o m*/
protected void paintRowAttributes(PaintTarget target, Object itemId) throws PaintException {
    super.paintRowAttributes(target, itemId);

    boolean hasAggregation = items instanceof AggregationContainer && isAggregatable()
            && !((AggregationContainer) items).getAggregationPropertyIds().isEmpty();

    boolean hasGroups = hasGroups();
    if (hasGroups) {
        if (isGroup(itemId)) {
            target.addAttribute("colKey", _columnIdMap().key(getGroupProperty(itemId)));
            target.addAttribute("groupKey", groupIdMap.key(itemId));

            if (isExpanded(itemId)) {
                target.addAttribute("expanded", true);
            }

            Object propertyValue = getGroupPropertyValue(itemId);
            String formattedValue = formatGroupPropertyValue(itemId, propertyValue);
            target.addAttribute("groupCaption", formattedValue);

            if (hasAggregation) {
                paintGroupAggregation(target, itemId,
                        ((AggregationContainer) items).aggregate(new GroupAggregationContext(this, itemId)));
            }
        }
    }
}

From source file:com.haulmont.cuba.web.widgets.CubaGroupTable.java

License:Apache License

protected void paintGroupAggregation(PaintTarget target, Object groupId, Map<Object, Object> aggregations)
        throws PaintException {
    boolean paintGroupProperty = false;

    Collection groupProperties = getGroupProperties();
    Object groupProperty = getGroupProperty(groupId);

    for (Object columnId : _visibleColumns()) {
        if (columnId == null || isColumnCollapsed(columnId)) {
            continue;
        }//w w w.j a  v  a2  s.  co m

        if (groupProperties.contains(columnId) && !paintGroupProperty) {
            if (columnId.equals(groupProperty)) {
                paintGroupProperty = true;
            }
            continue;
        }

        if (getCellStyleGenerator() != null) {
            String cellStyle = getCellStyleGenerator().getStyle(this, null, columnId);
            if (cellStyle != null && !cellStyle.isEmpty()) {
                target.addAttribute("style-" + _columnIdMap().key(columnId), cellStyle + "-ag");
            }
        }

        String value = (String) aggregations.get(columnId);
        if (value != null) {
            target.addText(value);
        } else {
            target.addText("");
        }
    }
}

From source file:com.haulmont.cuba.web.widgets.CubaTable.java

License:Apache License

@Override
protected void paintAdditionalData(PaintTarget target) throws PaintException {
    if (reqFirstRowToPaint == -1) {
        boolean hasAggregation = items instanceof AggregationContainer && isAggregatable()
                && !((AggregationContainer) items).getAggregationPropertyIds().isEmpty();

        if (hasAggregation && isShowTotalAggregation() && AggregationStyle.TOP.equals(getAggregationStyle())) {
            Context context = new Context(getAggregationItemIds());
            paintAggregationRow(target, ((AggregationContainer) items).aggregate(context));
        }/*from  w ww .j  av a2  s .c om*/
    }

    // paint cuba-ids

    if (getCubaId() != null) {
        List<String> visibleColOrder = new ArrayList<>();
        for (Object columnId : _visibleColumns()) {
            if (!isColumnCollapsed(columnId)) {
                visibleColOrder.add(columnId.toString());
            }
        }
        target.addAttribute("colcubaids", visibleColOrder.toArray());
    }
}

From source file:com.haulmont.cuba.web.widgets.CubaTable.java

License:Apache License

protected void paintAggregationRow(PaintTarget target, Map<Object, Object> aggregations) throws PaintException {
    target.startTag("arow");
    for (final Object columnId : _visibleColumns()) {
        if (columnId == null || isColumnCollapsed(columnId)) {
            continue;
        }//from  ww w . j  a  va2  s  . c  om

        if (getCellStyleGenerator() != null) {
            String cellStyle = getCellStyleGenerator().getStyle(this, null, columnId);
            if (cellStyle != null && !cellStyle.equals("")) {
                target.addAttribute("style-" + _columnIdMap().key(columnId), cellStyle + "-ag");
            }
        }

        String value = (String) aggregations.get(columnId);
        target.addText(value);
    }
    target.endTag("arow");
}