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:
hengsin 2021-09-10 15:58:57 +08:00 committed by GitHub
parent 0c5a0112e1
commit 992ec3c219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 45 deletions

View File

@ -17,6 +17,7 @@
package org.adempiere.webui.component; package org.adempiere.webui.component;
import java.net.URL;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -91,12 +92,14 @@ public class Tab extends org.zkoss.zul.Tab
*/ */
public static class DecorateInfo { public static class DecorateInfo {
private String imageKey; private String imageKey;
private String imageIntenalUrl; private URL imageIntenalUrl;
public void decorate (LabelImageElement comp){ public void decorate (LabelImageElement comp){
if (imageIntenalUrl != null) if (imageIntenalUrl != null) {
comp.setImage(imageIntenalUrl); Image image = ManageImageCache.instance().getImage(imageIntenalUrl);
else if (imageKey != null){ if (image != null)
comp.setImageContent(image);
} else if (imageKey != null){
Image ico = ManageImageCache.instance().getImage(imageKey); Image ico = ManageImageCache.instance().getImage(imageKey);
if (ico != null) if (ico != null)
comp.setImageContent(ico); comp.setImageContent(ico);
@ -104,15 +107,19 @@ public class Tab extends org.zkoss.zul.Tab
} }
public DecorateInfo (MImage imageData){ public DecorateInfo (MImage imageData){
imageIntenalUrl = ManageImageCache.getImageInternalUrl(imageData); if (imageData != null) {
if (imageIntenalUrl == null) imageIntenalUrl = ManageImageCache.getImageInternalUrl(imageData);
imageKey = ManageImageCache.instance().loadImage(imageData); if (imageIntenalUrl == null)
imageKey = ManageImageCache.instance().loadImage(imageData);
}
} }
public DecorateInfo (String imagePath){ public DecorateInfo (String imagePath){
imageIntenalUrl = ManageImageCache.getImageInternalUrl(imagePath); if (imagePath != null) {
if (imageIntenalUrl == null) imageIntenalUrl = ManageImageCache.getImageInternalUrl(imagePath);
imageKey = imagePath; if (imageIntenalUrl == null)
imageKey = imagePath;
}
} }
/** /**

View File

@ -147,6 +147,7 @@ public class TreeSearchPanel extends Panel implements EventListener<Event>, Tree
protected void init() protected void init()
{ {
layout = new Hlayout(); layout = new Hlayout();
layout.setHflex("1");
layout.setValign("middle"); layout.setValign("middle");
lblSearch = new Label(); lblSearch = new Label();
lblSearch.setValue(Msg.getMsg(Env.getCtx(),"TreeSearch").replaceAll("&", "") + ":"); lblSearch.setValue(Msg.getMsg(Env.getCtx(),"TreeSearch").replaceAll("&", "") + ":");

View File

@ -75,7 +75,7 @@ public class ManageImageCache {
* @param image * @param image
* @return * @return
*/ */
public static String getImageInternalUrl (MImage image){ public static URL getImageInternalUrl (MImage image){
if (image == null) if (image == null)
return null; return null;
return getImageInternalUrl(image.getImageURL()); return getImageInternalUrl(image.getImageURL());
@ -86,12 +86,12 @@ public class ManageImageCache {
* @param url * @param url
* @return * @return
*/ */
public static String getImageInternalUrl (String url){ public static URL getImageInternalUrl (String url){
if (url == null || url.trim().length() == 0 || url.indexOf("://") > 0) if (url == null || url.trim().length() == 0 || url.indexOf("://") > 0)
return null; return null;
URL urlRsource = Core.getResourceFinder().getResource(url); URL urlRsource = Core.getResourceFinder().getResource(url);
return urlRsource == null?null:urlRsource.getPath(); return urlRsource;
} }
/** /**
@ -156,6 +156,37 @@ public class ManageImageCache {
return aImage; 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 * if MImage contain extend image or binary image data, load it into cache and return key
* other return null * other return null

View File

@ -54,41 +54,12 @@ public class WebUIResourceFinder implements IResourceFinder {
} }
if (url == null && name.startsWith("org/compiere/images")) { if (url == null && name.startsWith("org/compiere/images")) {
String t = name.substring("org/compiere/".length()); String t = name.substring("org/compiere/".length());
t = ThemeManager.getThemeResource(t); url = findResource(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;
}
} else if (url == null && name.startsWith("/org/compiere/images")) { } else if (url == null && name.startsWith("/org/compiere/images")) {
String t = name.substring("/org/compiere/".length()); String t = name.substring("/org/compiere/".length());
t = ThemeManager.getThemeResource(t); url = findResource(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;
}
} else if (url == null && name.startsWith("images/")) { } else if (url == null && name.startsWith("images/")) {
String t = ThemeManager.getThemeResource(name); url = findResource(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;
}
}
} else if (url == null && name.endsWith(".gif")) { } else if (url == null && name.endsWith(".gif")) {
String t = name.replace(".gif", ".png"); String t = name.replace(".gif", ".png");
e = find(t); e = find(t);
@ -96,4 +67,26 @@ public class WebUIResourceFinder implements IResourceFinder {
} }
return url; 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;
}
} }