private ToolbarButton(ToolbarButtonBuilder builder) { FontIcon icon = builder.icon; if (icon != null) { contentFA = icon.getHtml(); if (builder.iconText != null) { contentFA += builder.iconText; } } contentDefault = builder.iconFallback; if (builder.customTranslation) { aria = builder.aria; } else { // get buildin translations aria = builder.toolbarBuilder.getOptionsBuilder().getTranslation(builder.aria); } name = builder.name; action = builder.action; if (action == null) { action = name; } tagNames = builder.tagNames; style = builder.style; useQueryState = builder.useQueryState; classList = builder.classList; attrs = builder.attrs; }
@Override public String convertToPresentation(FontIcon value, Class<? extends String> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { if (value != null) { return value.getHtml(); } return null; }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Optional<Converter<?, ?>> getDefaultPropertyConverter(final P property) { Converter<?, ?> converter = null; Class<?> type = getPropertyColumnType(property); // FontIcons if (type != null && FontIcon.class.isAssignableFrom(type)) { converter = new FontIconPresentationConverter(); } else { // Use default property presentation converter if (Property.class.isAssignableFrom(property.getClass())) { converter = new PropertyPresentationConverter<>((Property) property); } } return Optional.ofNullable(converter); }
/** * Get the default {@link Renderer} for given <code>property</code>. * @param property Property * @return The default {@link Renderer}, if available */ protected Optional<Renderer<?>> getDefaultPropertyRenderer(P property) { Class<?> type = getPropertyColumnType(property); // Images if (type != null && (ExternalResource.class.isAssignableFrom(type) || ThemeResource.class.isAssignableFrom(type))) { return Optional.of(new ImageRenderer()); } if (type != null && FontIcon.class.isAssignableFrom(type)) { return Optional.of(new HtmlRenderer("")); } return Optional.empty(); }
public void setIcon(Resource source) { if (source == null) { this.icon.setVisible(false); } else { this.icon.setVisible(true); this.icon.removeAllComponents(); if (source instanceof FontIcon) { this.icon.addComponent(new Label(((FontIcon) source).getHtml(), ContentMode.HTML)); } else { this.icon.addComponent(new Image(null, source)); } } }
@Override public void setIcon(Resource icon) { if (icon != null && !(icon instanceof FontIcon)) { throw new IllegalArgumentException("Only FontIcons are allowed"); } this.icon = (FontIcon) icon; markAsDirty(); }
@Override public String convertToPresentation(FontIcon value, ValueContext context) { if (value != null) { return value.getHtml(); } return null; }
@SuppressWarnings("unchecked") @Override protected Optional<ValueProvider<?, ?>> getDefaultPropertyPresenter(Property property) { if (property != null) { if (Component.class.isAssignableFrom(property.getType())) { return Optional.empty(); } if (FontIcon.class.isAssignableFrom(property.getType())) { return Optional.of(v -> ((FontIcon) v).getHtml()); } return Optional.of(v -> property.present(v)); } return super.getDefaultPropertyPresenter(property); }
@Override protected Optional<Renderer<?>> getDefaultPropertyRenderer(Property property) { if (Component.class.isAssignableFrom(property.getType())) { return Optional.of(new ComponentRenderer()); } if (FontIcon.class.isAssignableFrom(property.getType())) { return Optional.of(new HtmlRenderer("")); } if (ExternalResource.class.isAssignableFrom(property.getType()) || ThemeResource.class.isAssignableFrom(property.getType())) { return Optional.of(new ImageRenderer()); } return super.getDefaultPropertyRenderer(property); }
@Override public String convertToPresentation(FontIcon value, ValueContext context) { if (value == null) { return null; } return value.getHtml(); }
public static FontIcon getFileIconByMime(final String mimeType) { // TODO: Move to map if (!isNullOrEmpty(mimeType)) { if (mimeType.startsWith("image/")) return Fontello.FILE_IMAGE; else if (mimeType.equals("application/pdf")) return Fontello.FILE_PDF; else if (mimeType.equals("application/vnd.ms-excel") || mimeType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) return Fontello.FILE_EXCEL; else if (mimeType.equals("application/msword") || mimeType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) return Fontello.FILE_WORD; else if (mimeType.equals("application/vnd.ms-powerpoint") || mimeType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) return Fontello.FILE_POWERPOINT; else if (mimeType.equals("application/zip") || mimeType.equals("application/x-rar-compressed") || mimeType.equals("application/x-gzip")) return Fontello.FILE_ARCHIVE; else if (mimeType.startsWith("audio/")) return Fontello.FILE_AUDIO; else if (mimeType.startsWith("video/")) return Fontello.FILE_VIDEO; } return Fontello.FILE_CODE; }
@Override public Class<FontIcon> getModelType() { return FontIcon.class; }
@Override public FontIcon convertToModel(String value, Class<? extends FontIcon> targetType, Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException { return null; }
/** * Construct a new label with the given caption, description and icon. * * @param caption * The caption to show * @param description * The description to show * @param icon * The icon to show */ public StepLabel(String caption, String description, FontIcon icon) { active = false; nexted = false; skipped = false; editable = false; clickable = false; iconLabel = new Label(); iconLabel.setWidthUndefined(); iconLabel.setContentMode(ContentMode.HTML); iconLabel.addStyleName(STYLE_STEP_ICON); captionLabel = new Label(); captionLabel.setWidth(100, Unit.PERCENTAGE); captionLabel.addStyleName(STYLE_STEP_CAPTION); descriptionLabel = new Label(); descriptionLabel.setWidth(100, Unit.PERCENTAGE); descriptionLabel.addStyleName(ValoTheme.LABEL_LIGHT); descriptionLabel.addStyleName(ValoTheme.LABEL_SMALL); descriptionLabel.addStyleName(STYLE_STEP_DESCRIPTION); captionWrapper = new VerticalLayout(); captionWrapper.setSpacing(false); captionWrapper.setMargin(false); captionWrapper.setSizeFull(); captionWrapper.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); captionWrapper.addComponent(captionLabel); captionWrapper.addComponent(descriptionLabel); rootLayout = new HorizontalLayout(); rootLayout.setSpacing(false); rootLayout.setMargin(false); rootLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); rootLayout.setWidth(100, Unit.PERCENTAGE); rootLayout.addComponent(iconLabel); rootLayout.addComponent(captionWrapper); rootLayout.setExpandRatio(captionWrapper, 1); setCompositionRoot(rootLayout); addStyleName(STYLE_ROOT_LAYOUT); setIcon(icon); setCaption(caption); setDescription(description); setIconNexted(DEFAULT_ICON_NEXTED); setIconSkipped(DEFAULT_ICON_SKIPPED); setIconEditable(DEFAULT_ICON_EDITABLE); setIconError(DEFAULT_ICON_ERROR); }
@Override public FontIcon getIcon() { return icon; }
@Override public String getMIMEType() { throw new UnsupportedOperationException(FontIcon.class.getSimpleName() + " should not be used where a MIME type is needed."); }
@Override public Result<FontIcon> convertToModel(String value, ValueContext context) { return null; }
@GridColumn(translationKey = "", defaultOrder = 0) public FontIcon getIcon() { return VaadinIcons.VAADIN_H; }
@Override public Result<FontIcon> convertToModel(String value, ValueContext context) { throw new UnsupportedOperationException("Conversion is not supported from HTML to FontIcon"); }
@Override public Converter<String, FontIcon> getConverter() { return converter; }
public BooleanRepresentation(Boolean value, FontIcon icon, String caption) { this.value = value; this.icon = icon; this.caption = caption; }
public FontIcon getIcon() { return icon; }
Gender(FontIcon icon) { this.icon = icon; }
public void setToggleDownIcon(FontIcon toggleDownIcon) { getState().setToggleDownHtml(toggleDownIcon.getHtml()); }
public void setToggleUpIcon(FontIcon toggleUpIcon) { getState().setToggleUpHtml(toggleUpIcon.getHtml()); }
public FontIcon getClosedIcon() { return closedIcon; }
public DisclosurePanel setClosedIcon(FontIcon closedIcon) { this.closedIcon = closedIcon; return setOpen(isOpen()); }
public FontIcon getOpenIcon() { return openIcon; }
public DisclosurePanel setOpenIcon(FontIcon openIcon) { this.openIcon = openIcon; return setOpen(isOpen()); }
public MetaFieldBuilder withCaptionAndIcon(FontIcon icon, String caption) { captionHtml = icon.getHtml() + " " + StringUtils.trim(caption, 20, true); return this; }
/** * Get the icon for the label that is shown if it is <code><b>NEXTED</b></code>. * * @return The icon that is shown */ public FontIcon getIconNexted() { return iconNexted; }
/** * Set the icon that is shown if it is <code><b>NEXTED</b></code>. * * @param iconNexted * The icon to be shown */ public void setIconNexted(FontIcon iconNexted) { Objects.requireNonNull(iconNexted, "icon may not be null"); this.iconNexted = iconNexted; }
/** * Get the icon that is shown if it is <code><b>SKIPPED</b></code>. * * @return The icon that is shown */ public FontIcon getIconSkipped() { return iconSkipped; }
/** * Set the icon that is shown if it is <code><b>SKIPPED</b></code>. * * @param iconSkipped * The icon to be shown */ public void setIconSkipped(FontIcon iconSkipped) { Objects.requireNonNull(iconSkipped, "icon may not be null"); this.iconSkipped = iconSkipped; }
/** * Get the icon for the label that is shown if it is <code><b>EDITABLE</b></code>. * * @return The icon that is shown */ public FontIcon getIconEditable() { return iconEditable; }
/** * Set the icon that is shown if it is <code><b>EDITABLE</b></code>. * * @param iconEditable * The icon to be shown */ public void setIconEditable(FontIcon iconEditable) { Objects.requireNonNull(iconEditable, "icon may not be null"); this.iconEditable = iconEditable; }
/** * Get the icon for the label that is shown if it is <code><b>ERRONEOUS</b></code>. * * @return The icon that is shown */ public FontIcon getIconError() { return iconError; }
/** * Set the icon that is shown if it is <code><b>ERRONEOUS</b></code>. * * @param iconError * The icon to be shown */ public void setIconError(FontIcon iconError) { Objects.requireNonNull(iconError, "icon may not be null"); this.iconError = iconError; }