com.vaadin.server.ResourceReference Java Examples

The following examples show how to use com.vaadin.server.ResourceReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the ComboBoxMultiselect with default settings and register client to server RPC implementation.
 */
private void init() {
    registerRpc(this.rpc);
    registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));

    addDataGenerator((final T data, final JsonObject jsonObject) -> {
        String caption = getItemCaptionGenerator().apply(data);
        if (caption == null) {
            caption = "";
        }
        jsonObject.put(DataCommunicatorConstants.NAME, caption);
        final String style = this.itemStyleGenerator.apply(data);
        if (style != null) {
            jsonObject.put(ComboBoxMultiselectConstants.STYLE, style);
        }
        final Resource icon = getItemIconGenerator().apply(data);
        if (icon != null) {
            final String iconUrl = ResourceReference.create(icon, ComboBoxMultiselect.this, null)
                    .getURL();
            jsonObject.put(ComboBoxMultiselectConstants.ICON, iconUrl);
        }
    });
}
 
Example #2
Source File: ComboBoxMultiselect.java    From vaadin-combobox-multiselect with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the ComboBoxMultiselect with default settings and register client to server RPC implementation.
 */
private void init() {
    registerRpc(this.rpc);
    registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));

    addDataGenerator((final T data, final JsonObject jsonObject) -> {
        String caption = getItemCaptionGenerator().apply(data);
        if (caption == null) {
            caption = "";
        }
        jsonObject.put(DataCommunicatorConstants.NAME, caption);
        final String style = this.itemStyleGenerator.apply(data);
        if (style != null) {
            jsonObject.put(ComboBoxMultiselectConstants.STYLE, style);
        }
        final Resource icon = getItemIconGenerator().apply(data);
        if (icon != null) {
            final String iconUrl = ResourceReference.create(icon, ComboBoxMultiselect.this, null)
                    .getURL();
            jsonObject.put(ComboBoxMultiselectConstants.ICON, iconUrl);
        }
    });
}
 
Example #3
Source File: ContextMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
private List<ContextMenuItemState> convertItemsToState(List<MenuItem> items,
                                                       Map<Integer, MenuItem> itemRegistry) {
    if (items == null || items.size() == 0) {
        return null;
    }

    List<ContextMenuItemState> stateItems = new ArrayList<>(items.size());

    for (MenuItem item : items) {
        ContextMenuItemState menuItemState = new ContextMenuItemState();

        if (!item.isVisible()) {
            continue;
        }

        menuItemState.id = item.getId();
        menuItemState.text = item.getText();
        menuItemState.checkable = item.isCheckable();
        menuItemState.command = item.getCommand() != null;
        menuItemState.checked = item.isChecked();
        menuItemState.description = item.getDescription();
        menuItemState.descriptionContentMode = item
                .getDescriptionContentMode();
        menuItemState.enabled = item.isEnabled();
        menuItemState.separator = item.isSeparator();
        menuItemState.icon = ResourceReference.create(item.getIcon(), this,
                "");
        menuItemState.styleName = item.getStyleName();

        menuItemState.childItems = convertItemsToState(item.getChildren(),
                itemRegistry);

        stateItems.add(menuItemState);
        itemRegistry.put(item.getId(), item);
    }

    return stateItems;
}
 
Example #4
Source File: CubaIconRenderer.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public JsonValue encode(Resource value) {
    ResourceReference resourceReference = ResourceReference.create(value, this, ComponentConstants.ICON_RESOURCE);
    return super.encode(resourceReference, URLReference.class);
}
 
Example #5
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
private List<ContextMenuItemState> convertItemsToState(List<MenuItem> items,
        Map<Integer, MenuItem> itemRegistry) {
    if (items == null || items.size() == 0) {
        return null;
    }

    List<ContextMenuItemState> stateItems = new ArrayList<>(items.size());

    for (MenuItem item : items) {
        ContextMenuItemState menuItemState = new ContextMenuItemState();

        if (!item.isVisible()) {
            continue;
        }

        menuItemState.id = item.getId();
        menuItemState.text = item.getText();
        menuItemState.checkable = item.isCheckable();
        menuItemState.command = item.getCommand() != null;
        menuItemState.checked = item.isChecked();
        menuItemState.description = item.getDescription();
        menuItemState.descriptionContentMode = item
                .getDescriptionContentMode();
        menuItemState.enabled = item.isEnabled();
        menuItemState.separator = item.isSeparator();
        String key= item.getIcon()!= null ?
                String.valueOf(item.getIcon().hashCode())
                : "icon";
        ResourceReference resourceReference = ResourceReference.create(item.getIcon(), this, key);
        if (item.getIcon()!=null && (item.getIcon() instanceof ConnectorResource)) {
            super.getState().resources.put(key,resourceReference);
        }
        menuItemState.icon = resourceReference;
        menuItemState.styleName = item.getStyleName();

        menuItemState.childItems = convertItemsToState(item.getChildren(),
                itemRegistry);

        stateItems.add(menuItemState);
        itemRegistry.put(item.getId(), item);
    }

    return stateItems;
}