com.vaadin.server.Resource Java Examples

The following examples show how to use com.vaadin.server.Resource. 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: WebSearchPickerField.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected Resource generateOptionIcon(V item) {
    if (optionIconProvider == null) {
        return null;
    }

    String resourceId;
    try {
        resourceId = optionIconProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebLookupField.class)
                .warn("Error invoking OptionIconProvider getItemIcon method", e);
        return null;
    }

    return iconResolver.getIconResource(resourceId);
}
 
Example #2
Source File: WebPickerField.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected Resource generateOptionIcon(V item) {
    if (iconProvider == null) {
        return null;
    }

    String resourceId;
    try {
        resourceId = iconProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebPickerField.class)
                .warn("Error invoking optionIconProvider apply method", e);
        return null;
    }

    return getIconResource(resourceId);
}
 
Example #3
Source File: DemoUI.java    From sidemenu-addon with Apache License 2.0 6 votes vote down vote up
private void setUser(String name, Resource icon) {
	sideMenu.setUserName(name);
	sideMenu.setUserIcon(icon);

	sideMenu.clearUserMenu();
       sideMenu.addUserMenuItem("Settings", VaadinIcons.WRENCH, () -> Notification.show("Showing settings", Type.TRAY_NOTIFICATION));
       sideMenu.addUserMenuItem("Sign out", () -> Notification.show("Logging out..", Type.TRAY_NOTIFICATION));

	sideMenu.addUserMenuItem("Hide logo", () -> {
		if (!logoVisible) {
			sideMenu.setMenuCaption(menuCaption, logo);
		} else {
			sideMenu.setMenuCaption(menuCaption);
		}
		logoVisible = !logoVisible;
	});
}
 
Example #4
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 #5
Source File: WebPopupButton.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void setPopupButtonIcon(Button button, String icon) {
    if (!StringUtils.isEmpty(icon)) {
        Resource iconResource = getIconResource(icon);
        button.setIcon(iconResource);
    } else {
        button.setIcon(null);
    }
}
 
Example #6
Source File: WebSearchPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Resource generateOptionImage(V item) {
    com.haulmont.cuba.gui.components.Resource resource;
    try {
        resource = optionImageProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebLookupField.class)
                .warn("Error invoking OptionImageProvider apply method", e);
        return null;
    }

    return resource != null && ((WebResource) resource).hasSource()
            ? ((WebResource) resource).getResource()
            : null;
}
 
Example #7
Source File: WebPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void setPickerButtonIcon(CubaButton button, String icon) {
    if (!StringUtils.isEmpty(icon)) {
        Resource iconResource = getIconResource(icon);
        button.setIcon(iconResource);
    } else {
        button.setIcon(null);
    }
}
 
Example #8
Source File: WebSearchPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void setOptionImageProvider(Function<? super V, com.haulmont.cuba.gui.components.Resource> optionImageProvider) {
    if (this.optionImageProvider != optionImageProvider) {
        this.optionImageProvider = optionImageProvider;

        if (optionImageProvider != null) {
            getComponent().setItemIconGenerator(this::generateOptionImage);
        } else {
            getComponent().setItemIconGenerator(NULL_ITEM_ICON_GENERATOR);
        }
    }
}
 
Example #9
Source File: WebLink.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public String getUrl() {
    Resource resource = component.getResource();
    if (resource instanceof ExternalResource)
        return ((ExternalResource) resource).getURL();

    return null;
}
 
Example #10
Source File: WebTree.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Resource getItemIcon(E item) {
    if (item == null) {
        return null;
    }

    String resourceUrl = this.iconProvider.apply(item);
    return iconResolver.getIconResource(resourceUrl);
}
 
Example #11
Source File: WebRadioButtonGroup.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Resource generateOptionIcon(V item) {
    String resourceId;
    try {
        resourceId = optionIconProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebRadioButtonGroup.class)
                .warn("Error invoking optionIconProvider apply method", e);
        return null;
    }

    return iconResolver.getIconResource(resourceId);
}
 
Example #12
Source File: WebButton.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setIcon(String icon) {
    this.icon = icon;

    // -icon style is added automatically on the client-side of CubaButton
    if (StringUtils.isNotEmpty(icon)) {
        Resource iconResource = getIconResource(icon);
        component.setIcon(iconResource);
    } else {
        component.setIcon(null);
    }
}
 
Example #13
Source File: CubaSideMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
public void setIcon(Resource icon) {
    if (this.icon != icon) {
        Resource oldIcon = this.icon;
        this.icon = icon;
        propertyChangeSupport.firePropertyChange(MENU_ITEM_ICON, oldIcon, icon);
    }
}
 
Example #14
Source File: IconResolverImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Resource getIconResource(String iconPath) {
    if (StringUtils.isEmpty(iconPath)) {
        return null;
    }

    String themeIcon = getThemeIcon(processPath(iconPath));
    if (StringUtils.isNotEmpty(themeIcon)) {
        return getResource(themeIcon);
    }

    return getResource(iconPath);
}
 
Example #15
Source File: ClassPathIconProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Resource getIconResource(String iconPath) {
    Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty");

    String icon = iconPath.substring(CLASSPATH_PREFIX.length());
    return new ClassResource(icon);
}
 
Example #16
Source File: ThemeIconProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Resource getIconResource(String iconPath) {
    Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty");

    String icon = iconPath.substring(THEME_PREFIX.length());
    return new ThemeResource(icon);
}
 
Example #17
Source File: FileIconProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Resource getIconResource(String iconPath) {
    Preconditions.checkNotEmptyString(iconPath, "Icon path should not be empty");

    String icon = iconPath.substring(FILE_PREFIX.length());
    File iconFile = new File(icon);
    if (!iconFile.exists()) {
        throw new IllegalArgumentException("Icon file does not exist: " + icon);
    }

    return new FileResource(iconFile);
}
 
Example #18
Source File: WebAccordion.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setIcon(String icon) {
    this.icon = icon;
    if (!StringUtils.isEmpty(icon)) {
        Resource iconResource = AppBeans.get(IconResolver.class)
                .getIconResource(this.icon);
        getVaadinTab().setIcon(iconResource);
    } else {
        getVaadinTab().setIcon(null);
    }
}
 
Example #19
Source File: WebAbstractComponent.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setIcon(String icon) {
    this.icon = icon;

    if (StringUtils.isNotEmpty(icon)) {
        Resource iconResource = getIconResource(icon);
        getComposition().setIcon(iconResource);
        getComposition().addStyleName(ICON_STYLE);
    } else {
        getComposition().setIcon(null);
        getComposition().removeStyleName(ICON_STYLE);
    }
}
 
Example #20
Source File: WebAbstractActionsHolderComponent.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void setContextMenuButtonIcon(CubaButton button, String icon) {
    if (!StringUtils.isEmpty(icon)) {
        Resource iconResource = getIconResource(icon);
        button.setIcon(iconResource);
    } else {
        button.setIcon(null);
    }
}
 
Example #21
Source File: WebFileUploadField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setClearButtonIcon(String icon) {
    if (icon != null) {
        IconResolver iconResolver = beanLocator.get(IconResolver.NAME);
        Resource iconResource = iconResolver.getIconResource(icon);
        component.setClearButtonIcon(iconResource);
    } else {
        component.setClearButtonIcon(null);
    }
}
 
Example #22
Source File: WebCheckBoxGroup.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Resource generateOptionIcon(V item) {
    String resourceId;
    try {
        resourceId = optionIconProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebCheckBoxGroup.class)
                .warn("Error invoking optionIconProvider apply method", e);
        return null;
    }

    return iconResolver.getIconResource(resourceId);
}
 
Example #23
Source File: WebTabSheet.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setIcon(String icon) {
    this.icon = icon;
    if (!StringUtils.isEmpty(icon)) {
        Resource iconResource = AppBeans.get(IconResolver.class) // todo replace
                .getIconResource(this.icon);
        getVaadinTab().setIcon(iconResource);
    } else {
        getVaadinTab().setIcon(null);
    }
}
 
Example #24
Source File: WebLookupPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Resource generateOptionImage(V item) {
    com.haulmont.cuba.gui.components.Resource resource;
    try {
        resource = optionImageProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebLookupField.class)
                .warn("Error invoking OptionImageProvider apply method", e);
        return null;
    }

    return resource != null && ((WebResource) resource).hasSource()
            ? ((WebResource) resource).getResource()
            : null;
}
 
Example #25
Source File: WebFoldersPane.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Resource getFolderIcon(AbstractSearchFolder item) {
    String resourceId;
    try {
        resourceId = iconProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebFoldersPane.class)
                .warn("Error invoking iconProvider apply method", e);
        return null;
    }
    return getIconResource(resourceId);
}
 
Example #26
Source File: WebAppMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setIcon(String icon) {
    this.icon = icon;

    if (icon != null) {
        Resource iconResource = AppBeans.get(IconResolver.class)
                .getIconResource(this.icon);
        delegateItem.setIcon(iconResource);
    } else {
        delegateItem.setIcon(null);
    }
}
 
Example #27
Source File: WebLookupPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void setOptionImageProvider(Function<? super V, com.haulmont.cuba.gui.components.Resource> optionImageProvider) {
    if (this.optionImageProvider != optionImageProvider) {
        this.optionImageProvider = optionImageProvider;

        if (optionImageProvider != null) {
            getComponent().setItemIconGenerator(this::generateOptionImage);
        } else {
            getComponent().setItemIconGenerator(NULL_ITEM_ICON_GENERATOR);
        }
    }
}
 
Example #28
Source File: WebLookupPickerField.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Resource generateOptionIcon(V item) {
    String resourceId;
    try {
        resourceId = optionIconProvider.apply(item);
    } catch (Exception e) {
        LoggerFactory.getLogger(WebLookupPickerField.class)
                .warn("Error invoking optionIconProvider apply method", e);
        return null;
    }

    return iconResolver.getIconResource(resourceId);
}
 
Example #29
Source File: WebIconRenderer.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public ValueProvider<Icons.Icon, Resource> getPresentationValueProvider() {
    return (ValueProvider<Icons.Icon, Resource>) icon -> {
        String iconName = icons.get(icon);
        return iconResolver.getIconResource(iconName);
    };
}
 
Example #30
Source File: WebLookupField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void setOptionImageProvider(Function<? super V, com.haulmont.cuba.gui.components.Resource> optionImageProvider) {
    if (this.optionImageProvider != optionImageProvider) {
        this.optionImageProvider = optionImageProvider;

        if (optionImageProvider != null) {
            component.setItemIconGenerator(this::generateOptionImage);
        } else {
            component.setItemIconGenerator(NULL_ITEM_ICON_GENERATOR);
        }
    }
}