Здравствуйте. Уже долго пытаюсь добавить дополнительные иконки к своей теме. В проекте предустановлен набор иконок FontAwesome. Но стоит версия 4.4.0. Меня заинтересовали иконки версии 5.0.0. А так же иконки Glyphicon. Как обновить версию я не нашел, поэтому решил создать так называемое расширение на основе FontAwesome 4.4.0. Я нашел набор файлов для Glyphicon *.eot *.svg *.ttf *.woff *.woff2. Добавил в тему по пути Themes -> MyThemes ->fonts -> glyphicons. По пути Themes -> MyThemes ->fonts создал стиль glyphicons.scss
@mixin glyphicons {
@font-face {
font-family: "Glyphicons";
src: url("../glyphicons/glyphicons-halflings-regular.eot");
src: url("../glyphicons/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"),
url("../glyphicons/glyphicons-halflings-regular.woff2") format("woff2"),
url("../glyphicons/glyphicons-halflings-regular.woff") format("woff"),
url("../glyphicons/glyphicons-halflings-regular.ttf") format("truetype"),
url("../glyphicons/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") format("svg");
}
.glyphicons {
position: relative;
top: 1px;
display: inline-block;
font-family: "Glyphicons";
font-style: normal;
font-weight: 400;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
}
и в файле styles.scss импортировал его
@import "fonts/glyphicons";
@include glyphicons;
Далее я создал два класса
Glyphicons
import com.vaadin.server.FontIcon;
import com.vaadin.server.GenericFontIcon;
public enum Glyphicons implements FontIcon {
MY(0XE005);
public static final String FONT_FAMILY = "Glyphicons";
private int codepoint;
Glyphicons(int codepoint) {
this.codepoint = codepoint;
}
@Override
public String getFontFamily() {
return FONT_FAMILY;
}
@Override
public int getCodepoint() {
return codepoint;
}
@Override
public String getHtml() {
return GenericFontIcon.getHtml(FONT_FAMILY, codepoint);
}
@Override
public String getMIMEType() {
throw new UnsupportedOperationException(FontIcon.class.getSimpleName()
+ " should not be used where a MIME type is needed.");
}
public static Glyphicons fromCodepoint(final int codepoint) {
for (Glyphicons f : values()) {
if (f.getCodepoint() == codepoint) {
return f;
}
}
throw new IllegalArgumentException("Codepoint " + codepoint
+ " not found in Glyphicons");
}
}
Код E005 есть в файле *.svg. Я так понимаю по этому коду цепляется иконка из файла.
И создал класс GlyphiconProvider
package ru.mt.ev.web;
import com.haulmont.cuba.web.gui.icons.IconProvider;
import com.vaadin.server.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Order(10)
@Component
public class GlyphiconProvider implements IconProvider {
private final Logger log = LoggerFactory.getLogger(GlyphiconProvider.class);
@Override
public Resource getIconResource(String iconPath) {
Resource resource = null;
iconPath = iconPath.split(":")[1];
try {
resource = ((Resource) Glyphicons.class
.getDeclaredField(iconPath)
.get(null));
} catch (IllegalAccessException | NoSuchFieldException e) {
log.warn("There is no icon with name {} in the FontAwesome icon set", iconPath);
}
return resource;
}
@Override
public boolean canProvide(String iconPath) {
return iconPath.startsWith("glyphicons:");
}
}
В дескрипторе экрана вызываю icon=“glyphicons:MY”
но это не работает.
Перечитал документацию там ровно такой метод описывается. Что я делаю не так? Как можно расширить тему иконками и вызывать их через свойство icon (это одно из обязательных условий задачи, если это возможно)? Возможно есть более простой способ установки шрифтов и иконок FontAwesome и Glyphicon в среде CUBA?