IDEMPIERE-4952 Image icon missing for Notice, Request, Product and Business Partner tab (#869)
- Fix loading of image resource using IResourceFinder interface - Include a one liner minor layout fix for TreeSearchPanel
This commit is contained in:
parent
0c5a0112e1
commit
992ec3c219
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.adempiere.webui.component;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -91,12 +92,14 @@ public class Tab extends org.zkoss.zul.Tab
|
|||
*/
|
||||
public static class DecorateInfo {
|
||||
private String imageKey;
|
||||
private String imageIntenalUrl;
|
||||
private URL imageIntenalUrl;
|
||||
|
||||
public void decorate (LabelImageElement comp){
|
||||
if (imageIntenalUrl != null)
|
||||
comp.setImage(imageIntenalUrl);
|
||||
else if (imageKey != null){
|
||||
if (imageIntenalUrl != null) {
|
||||
Image image = ManageImageCache.instance().getImage(imageIntenalUrl);
|
||||
if (image != null)
|
||||
comp.setImageContent(image);
|
||||
} else if (imageKey != null){
|
||||
Image ico = ManageImageCache.instance().getImage(imageKey);
|
||||
if (ico != null)
|
||||
comp.setImageContent(ico);
|
||||
|
@ -104,15 +107,19 @@ public class Tab extends org.zkoss.zul.Tab
|
|||
}
|
||||
|
||||
public DecorateInfo (MImage imageData){
|
||||
imageIntenalUrl = ManageImageCache.getImageInternalUrl(imageData);
|
||||
if (imageIntenalUrl == null)
|
||||
imageKey = ManageImageCache.instance().loadImage(imageData);
|
||||
if (imageData != null) {
|
||||
imageIntenalUrl = ManageImageCache.getImageInternalUrl(imageData);
|
||||
if (imageIntenalUrl == null)
|
||||
imageKey = ManageImageCache.instance().loadImage(imageData);
|
||||
}
|
||||
}
|
||||
|
||||
public DecorateInfo (String imagePath){
|
||||
imageIntenalUrl = ManageImageCache.getImageInternalUrl(imagePath);
|
||||
if (imageIntenalUrl == null)
|
||||
imageKey = imagePath;
|
||||
if (imagePath != null) {
|
||||
imageIntenalUrl = ManageImageCache.getImageInternalUrl(imagePath);
|
||||
if (imageIntenalUrl == null)
|
||||
imageKey = imagePath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -147,6 +147,7 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
|
|||
protected void init()
|
||||
{
|
||||
layout = new Hlayout();
|
||||
layout.setHflex("1");
|
||||
layout.setValign("middle");
|
||||
lblSearch = new Label();
|
||||
lblSearch.setValue(Msg.getMsg(Env.getCtx(),"TreeSearch").replaceAll("&", "") + ":");
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ManageImageCache {
|
|||
* @param image
|
||||
* @return
|
||||
*/
|
||||
public static String getImageInternalUrl (MImage image){
|
||||
public static URL getImageInternalUrl (MImage image){
|
||||
if (image == null)
|
||||
return null;
|
||||
return getImageInternalUrl(image.getImageURL());
|
||||
|
@ -86,12 +86,12 @@ public class ManageImageCache {
|
|||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static String getImageInternalUrl (String url){
|
||||
public static URL getImageInternalUrl (String url){
|
||||
if (url == null || url.trim().length() == 0 || url.indexOf("://") > 0)
|
||||
return null;
|
||||
|
||||
URL urlRsource = Core.getResourceFinder().getResource(url);
|
||||
return urlRsource == null?null:urlRsource.getPath();
|
||||
return urlRsource;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,6 +156,37 @@ public class ManageImageCache {
|
|||
return aImage;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url
|
||||
* @return {@link Image}
|
||||
*/
|
||||
public Image getImage(URL url) {
|
||||
if (url == null)
|
||||
return null;
|
||||
|
||||
Image image = null;
|
||||
boolean hasCache = false;
|
||||
synchronized (imageCache) {
|
||||
hasCache = imageCache.containsKey(url.toString());
|
||||
if (hasCache)
|
||||
image = imageCache.get(url.toString());
|
||||
}
|
||||
|
||||
|
||||
if (!hasCache) {
|
||||
try {
|
||||
image = new AImage(url);
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
synchronized (imageCache) {
|
||||
imageCache.put(url.toString(), image);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* if MImage contain extend image or binary image data, load it into cache and return key
|
||||
* other return null
|
||||
|
|
|
@ -54,41 +54,12 @@ public class WebUIResourceFinder implements IResourceFinder {
|
|||
}
|
||||
if (url == null && name.startsWith("org/compiere/images")) {
|
||||
String t = name.substring("org/compiere/".length());
|
||||
t = ThemeManager.getThemeResource(t);
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
if (url == null && t.endsWith(".gif")) {
|
||||
t = t.replace(".gif", ".png");
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
}
|
||||
url = findResource(t);
|
||||
} else if (url == null && name.startsWith("/org/compiere/images")) {
|
||||
String t = name.substring("/org/compiere/".length());
|
||||
t = ThemeManager.getThemeResource(t);
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
if (url == null && t.endsWith(".gif")) {
|
||||
t = t.replace(".gif", ".png");
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
}
|
||||
url = findResource(t);
|
||||
} else if (url == null && name.startsWith("images/")) {
|
||||
String t = ThemeManager.getThemeResource(name);
|
||||
if (t.startsWith(ThemeManager.ZK_URL_PREFIX_FOR_CLASSPATH_RESOURCE)) {
|
||||
url = ThemeManager.class.getResource(ThemeManager.toClassPathResourcePath(t));
|
||||
} else {
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
}
|
||||
if (url == null && t.endsWith(".gif")) {
|
||||
t = t.replace(".gif", ".png");
|
||||
if (t.startsWith(ThemeManager.ZK_URL_PREFIX_FOR_CLASSPATH_RESOURCE)) {
|
||||
url = ThemeManager.class.getResource(ThemeManager.toClassPathResourcePath(t));
|
||||
} else {
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
}
|
||||
}
|
||||
url = findResource(name);
|
||||
} else if (url == null && name.endsWith(".gif")) {
|
||||
String t = name.replace(".gif", ".png");
|
||||
e = find(t);
|
||||
|
@ -96,4 +67,26 @@ public class WebUIResourceFinder implements IResourceFinder {
|
|||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private URL findResource(String name) {
|
||||
Enumeration<URL> e;
|
||||
URL url;
|
||||
String t = ThemeManager.getThemeResource(name);
|
||||
if (t.startsWith(ThemeManager.ZK_URL_PREFIX_FOR_CLASSPATH_RESOURCE)) {
|
||||
url = ThemeManager.class.getResource(ThemeManager.toClassPathResourcePath(t));
|
||||
} else {
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
}
|
||||
if (url == null && t.endsWith(".gif")) {
|
||||
t = t.replace(".gif", ".png");
|
||||
if (t.startsWith(ThemeManager.ZK_URL_PREFIX_FOR_CLASSPATH_RESOURCE)) {
|
||||
url = ThemeManager.class.getResource(ThemeManager.toClassPathResourcePath(t));
|
||||
} else {
|
||||
e = find(t);
|
||||
url = e != null && e.hasMoreElements() ? e.nextElement() : null;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue