PL-8470 Icon repository - use icons by names in components (some renaming)

This commit is contained in:
Konstantin Krivopustov 2017-12-21 11:47:11 +04:00
parent b87218bcce
commit f485747bc4
23 changed files with 58 additions and 55 deletions

View File

@ -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
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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") {

View File

@ -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")

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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));
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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