mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
PL-8470 Icon repository - use icons by names in components (some renaming)
This commit is contained in:
parent
b87218bcce
commit
f485747bc4
@ -518,7 +518,7 @@ public abstract class DesktopAbstractComponent<C extends JComponent>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ public class DesktopButton extends DesktopAbstractComponent<JButton> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
String iconPath = AppBeans.get(Icons.class)
|
||||
.get(icon);
|
||||
setIcon(iconPath);
|
||||
|
@ -213,7 +213,7 @@ public class DesktopFileMultiUploadField extends DesktopAbstractUploadComponent<
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
String iconPath = AppBeans.get(Icons.class)
|
||||
.get(icon);
|
||||
setIcon(iconPath);
|
||||
|
@ -86,7 +86,7 @@ public class DesktopLink extends DesktopAbstractComponent<JXHyperlink> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
String iconPath = AppBeans.get(Icons.class)
|
||||
.get(icon);
|
||||
setIcon(iconPath);
|
||||
|
@ -305,7 +305,7 @@ public class DesktopPopupButton extends DesktopAbstractActionsHolderComponent<JB
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
String iconPath = AppBeans.get(Icons.class)
|
||||
.get(icon);
|
||||
setIcon(iconPath);
|
||||
@ -522,7 +522,7 @@ public class DesktopPopupButton extends DesktopAbstractActionsHolderComponent<JB
|
||||
|
||||
// just stub
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -755,7 +755,7 @@ public class DesktopTabSheet extends DesktopAbstractComponent<JTabbedPane>
|
||||
|
||||
// just stub
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -754,7 +754,7 @@ public class DesktopTokenList extends DesktopAbstractField<JPanel> implements To
|
||||
return "";
|
||||
}
|
||||
});
|
||||
openButton.setIconByName(CubaIcon.PICKERFIELD_OPEN);
|
||||
openButton.setIconFromSet(CubaIcon.PICKERFIELD_OPEN);
|
||||
composition.add(openButton);
|
||||
openButton.setVisible(false);
|
||||
|
||||
|
@ -1518,7 +1518,7 @@ public class DesktopWindow implements Window, Component.Disposable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
this.icon = icons.get(icon);
|
||||
}
|
||||
|
||||
|
@ -50,4 +50,4 @@ cuba.creditsConfig=cuba-credits.xml
|
||||
|
||||
cuba.passwordEncryptionModule=cuba_Sha1EncryptionModule
|
||||
|
||||
cuba.icons.iconSets = com.haulmont.cuba.gui.icons.CubaIcon
|
||||
cuba.iconsConfig = com.haulmont.cuba.gui.icons.CubaIcon
|
@ -118,7 +118,7 @@
|
||||
<property name="cuba.rest.reuseRefreshToken" value="true"/>
|
||||
<property name="cuba.rest.allowedOrigins" value="*"/>
|
||||
<property name="cuba.rest.maxUploadSize" value="20971520"/>
|
||||
<property name="cuba.icons.iconSets" value="com.haulmont.cuba.gui.icons.CubaIcon"/>
|
||||
<property name="cuba.iconsConfig" value="com.haulmont.cuba.gui.icons.CubaIcon"/>
|
||||
</module>
|
||||
|
||||
<module name="web-toolkit" dependsOn="web">
|
||||
@ -166,6 +166,6 @@
|
||||
|
||||
<property name="cuba.useLocalServiceInvocation" value="false"/>
|
||||
<property name="cuba.themeConfig" value="nimbus-theme.properties"/>
|
||||
<property name="cuba.icons.iconSets" value="com.haulmont.cuba.gui.icons.CubaIcon"/>
|
||||
<property name="cuba.iconsConfig" value="com.haulmont.cuba.gui.icons.CubaIcon"/>
|
||||
</module>
|
||||
</app-component>
|
@ -237,8 +237,8 @@ public class AbstractFrame implements Frame, Frame.Wrapper, Component.Wrapper, C
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
frame.setIconByName(icon);
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
frame.setIconFromSet(icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -318,8 +318,8 @@ public class AbstractWindow extends AbstractFrame
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
frame.setIconByName(icon);
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
frame.setIconFromSet(icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -837,15 +837,20 @@ public interface Component {
|
||||
* Component having an icon.
|
||||
*/
|
||||
interface HasIcon {
|
||||
/**
|
||||
* Get icon source: "font-icon:ADD", "icons/myicon.png", "theme://createIcon", etc.
|
||||
*/
|
||||
String getIcon();
|
||||
|
||||
/**
|
||||
* Set an icon by its source: "font-icon:ADD", "icons/myicon.png", "theme://createIcon", etc.
|
||||
*/
|
||||
void setIcon(String icon);
|
||||
|
||||
/**
|
||||
* Sets the given <code>icon</code> to the component.
|
||||
*
|
||||
* @param icon {@link Icons.Icon} instance
|
||||
* Set an icon from an icon set.
|
||||
*/
|
||||
void setIconByName(Icons.Icon icon);
|
||||
void setIconFromSet(Icons.Icon icon);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +67,7 @@ public class DateInIntervalComponent {
|
||||
layout.add(textField);
|
||||
|
||||
Button openEditorBtn = componentsFactory.createComponent(Button.class);
|
||||
openEditorBtn.setIconByName(CubaIcon.PICKERFIELD_LOOKUP);
|
||||
openEditorBtn.setIconFromSet(CubaIcon.PICKERFIELD_LOOKUP);
|
||||
openEditorBtn.setStyleName("c-dateintervaleditor-button");
|
||||
openEditorBtn.setCaption("");
|
||||
openEditorBtn.setAction(new AbstractAction("openEditor") {
|
||||
@ -95,7 +95,7 @@ public class DateInIntervalComponent {
|
||||
layout.add(openEditorBtn);
|
||||
|
||||
Button clearBtn = componentsFactory.createComponent(Button.class);
|
||||
clearBtn.setIconByName(CubaIcon.PICKERFIELD_CLEAR);
|
||||
clearBtn.setIconFromSet(CubaIcon.PICKERFIELD_CLEAR);
|
||||
clearBtn.setStyleName("c-dateintervaleditor-button");
|
||||
clearBtn.setCaption("");
|
||||
clearBtn.setAction(new AbstractAction("clear") {
|
||||
|
@ -89,7 +89,7 @@ public class ListEditorDelegateImpl implements ListEditorDelegate {
|
||||
displayValuesField.setStyleName("c-listeditor-text");
|
||||
displayValuesField.setEditable(false);
|
||||
Button openEditorBtn = componentsFactory.createComponent(Button.class);
|
||||
openEditorBtn.setIconByName(CubaIcon.PICKERFIELD_LOOKUP);
|
||||
openEditorBtn.setIconFromSet(CubaIcon.PICKERFIELD_LOOKUP);
|
||||
openEditorBtn.setStyleName("c-listeditor-button");
|
||||
openEditorBtn.setCaption("");
|
||||
openEditorBtn.setAction(new AbstractAction("openEditor") {
|
||||
@ -321,7 +321,7 @@ public class ListEditorDelegateImpl implements ListEditorDelegate {
|
||||
|
||||
protected void addClearBtn() {
|
||||
clearBtn = componentsFactory.createComponent(Button.class);
|
||||
clearBtn.setIconByName(CubaIcon.PICKERFIELD_CLEAR);
|
||||
clearBtn.setIconFromSet(CubaIcon.PICKERFIELD_CLEAR);
|
||||
clearBtn.setStyleName("c-listeditor-button");
|
||||
clearBtn.setCaption("");
|
||||
clearBtn.setAction(new BaseAction("clear")
|
||||
|
@ -564,14 +564,14 @@ public enum CubaIcon implements Icons.Icon {
|
||||
YOUTUBE_PLAY("font-icon:YOUTUBE_PLAY"),
|
||||
YOUTUBE_SQUARE("font-icon:YOUTUBE_SQUARE");
|
||||
|
||||
protected String id;
|
||||
protected String source;
|
||||
|
||||
CubaIcon(String id) {
|
||||
this.id = id;
|
||||
CubaIcon(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return id;
|
||||
public String source() {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
@ -19,55 +19,53 @@ package com.haulmont.cuba.gui.icons;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A bean that gives an ability to set icons from icon sets - {@link Icon} inheritors.
|
||||
* <p>
|
||||
* It automatically resolves icons from icon sets that override the default icon set - {@link CubaIcon} or icons that
|
||||
* are overridden for a current theme in {@code theme-name-theme.properties} (e.g. halo-theme.properties) file.
|
||||
* A bean that resolves icon sources for icon sets defined for the project.
|
||||
* <p>
|
||||
* Examples:
|
||||
* <pre><code>
|
||||
* <pre>
|
||||
* excelButton.setIcon(icons.get(CubaIcon.EXCEL_ACTION));
|
||||
*
|
||||
* helpButton.setIcon(icons.get(CubaIcon.INFO));
|
||||
* </code></pre>
|
||||
* </pre>
|
||||
*
|
||||
* @see Icon
|
||||
*/
|
||||
public interface Icons {
|
||||
String NAME = "cuba_Icons";
|
||||
|
||||
/**
|
||||
* Returns icon path for the given {@link Icon} instance that can be used to set this icon to components.
|
||||
* For the given {@link Icon} instance, returns the icon source that can be used to set this icon to components.
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre><code>
|
||||
* <pre>
|
||||
* createButton.setIcon(icons.get(CubaIcon.CREATE));
|
||||
* </code></pre>
|
||||
* </pre>
|
||||
*
|
||||
* @param icon {@link Icons.Icon} instance
|
||||
* @return actual icon path
|
||||
* @return icon source (see {@link Icon#source()})
|
||||
*/
|
||||
String get(@Nullable Icon icon);
|
||||
|
||||
/**
|
||||
* Returns icon path for the given {@code iconName} that can be used to set this icon to components.
|
||||
* For the given {@link Icon#name()}, returns the icon source that can be used to set this icon to components.
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre><code>
|
||||
* <pre>
|
||||
* importButton.setIcon(icons.get("IMPORT"));
|
||||
* </code></pre>
|
||||
* </pre>
|
||||
*
|
||||
* @param iconName icon name that contains only uppercase letters and underscores
|
||||
* @return icon full string path
|
||||
* @return icon source (see {@link Icon#source()})
|
||||
*/
|
||||
String get(@Nullable String iconName);
|
||||
|
||||
/**
|
||||
* Marker interface for special enumerations - icon sets.
|
||||
* Interface for enumerations that represent icon sets.
|
||||
*/
|
||||
interface Icon {
|
||||
/**
|
||||
* @return icon source: "font-icon:ADD", "theme://createIcon", etc
|
||||
*/
|
||||
String id();
|
||||
String source();
|
||||
|
||||
/**
|
||||
* @return icon name: "ADD", "CREATE", etc
|
||||
|
@ -55,7 +55,7 @@ public class IconsImpl implements Icons {
|
||||
protected volatile boolean initialized;
|
||||
|
||||
public void init() {
|
||||
String iconSetsProp = AppContext.getProperty("cuba.icons.iconSets");
|
||||
String iconSetsProp = AppContext.getProperty("cuba.iconsConfig");
|
||||
if (StringUtils.isEmpty(iconSetsProp))
|
||||
return;
|
||||
|
||||
@ -138,16 +138,16 @@ public class IconsImpl implements Icons {
|
||||
}
|
||||
|
||||
protected static String resolveIcon(String iconName) {
|
||||
String iconPath = null;
|
||||
String iconSource = null;
|
||||
|
||||
for (Class<? extends Icon> iconSet : iconSets) {
|
||||
try {
|
||||
Object obj = iconSet.getDeclaredField(iconName).get(null);
|
||||
iconPath = ((Icon) obj).id();
|
||||
iconSource = ((Icon) obj).source();
|
||||
} catch (IllegalAccessException | NoSuchFieldException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return iconPath;
|
||||
return iconSource;
|
||||
}
|
||||
}
|
@ -1404,7 +1404,7 @@ public class WebWindow implements Window, Component.Wrapper,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
setIcon(icons.get(icon));
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ public abstract class WebAbstractComponent<T extends com.vaadin.ui.AbstractCompo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
String iconName = AppBeans.get(Icons.class)
|
||||
.get(icon);
|
||||
setIcon(iconName);
|
||||
|
@ -250,7 +250,7 @@ public class WebAccordion extends WebAbstractComponent<CubaAccordion> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
String iconPath = AppBeans.get(Icons.class)
|
||||
.get(icon);
|
||||
setIcon(iconPath);
|
||||
|
@ -264,7 +264,7 @@ public class WebTabSheet extends WebAbstractComponent<CubaTabSheet> implements T
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIconByName(Icons.Icon icon) {
|
||||
public void setIconFromSet(Icons.Icon icon) {
|
||||
String iconPath = AppBeans.get(Icons.class)
|
||||
.get(icon);
|
||||
setIcon(iconPath);
|
||||
|
@ -98,4 +98,4 @@ cuba.rest.allowedOrigins=*
|
||||
# Maximum size of the file that may be uploaded with REST API in bytes
|
||||
cuba.rest.maxUploadSize=20971520
|
||||
|
||||
cuba.icons.iconSets = com.haulmont.cuba.gui.icons.CubaIcon
|
||||
cuba.iconsConfig = com.haulmont.cuba.gui.icons.CubaIcon
|
Loading…
Reference in New Issue
Block a user