IDEMPIERE-503 Zk: Implement image icon support for window

This commit is contained in:
Heng Sin Low 2012-11-14 10:14:14 +08:00
parent 640888051a
commit 0b06a75a3b
8 changed files with 160 additions and 50 deletions

View File

@ -250,6 +250,18 @@ public class GridWindow implements Serializable
MImage mImage = MImage.get(Env.getCtx(), m_vo.AD_Image_ID); MImage mImage = MImage.get(Env.getCtx(), m_vo.AD_Image_ID);
return mImage.getImage(); return mImage.getImage();
} // getImage } // getImage
/**
* @return MImage
*/
public MImage getMImage()
{
if (m_vo.AD_Image_ID == 0)
return null;
//
MImage mImage = MImage.get(Env.getCtx(), m_vo.AD_Image_ID);
return mImage;
}
/** /**
* Get Window Icon * Get Window Icon

View File

@ -31,6 +31,7 @@ import java.util.logging.Level;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import org.adempiere.base.Core;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.Ini; import org.compiere.util.Ini;
@ -257,6 +258,10 @@ public class MImage extends X_AD_Image
} }
// Get from URL // Get from URL
URL url = getURL(); URL url = getURL();
if (url == null)
{
url = Core.getResourceFinder().getResource(str);
}
if (url == null) if (url == null)
{ {
log.config("No URL"); log.config("No URL");

View File

@ -17,12 +17,16 @@
package org.adempiere.webui.adwindow; package org.adempiere.webui.adwindow;
import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import org.adempiere.webui.desktop.IDesktop; import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.part.AbstractUIPart; import org.adempiere.webui.part.AbstractUIPart;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.compiere.model.MImage;
import org.compiere.model.MQuery; import org.compiere.model.MQuery;
import org.compiere.util.CCache;
import org.zkoss.image.AImage;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
/** /**
@ -42,6 +46,9 @@ public class ADWindow extends AbstractUIPart
private MQuery query; private MQuery query;
private Component windowPanelComponent; private Component windowPanelComponent;
private MImage image;
private static final CCache<Integer, AImage> imageCache = new CCache<Integer, AImage>("WindowImageCache", 5);
public ADWindow(Properties ctx, int adWindowId) public ADWindow(Properties ctx, int adWindowId)
{ {
@ -62,7 +69,9 @@ public class ADWindow extends AbstractUIPart
private void init() private void init()
{ {
windowContent = new ADWindowContent(ctx, windowNo); windowContent = new ADWindowContent(ctx, windowNo, adWindowId);
_title = windowContent.getTitle();
image = windowContent.getImage();
} }
public String getTitle() public String getTitle()
@ -70,14 +79,35 @@ public class ADWindow extends AbstractUIPart
return _title; return _title;
} }
public MImage getMImage()
{
return image;
}
public AImage getAImage() throws IOException {
MImage image = getMImage();
AImage aImage = null;
if (image != null) {
synchronized (imageCache) {
aImage = imageCache.get(image.getAD_Image_ID());
}
if (aImage == null) {
aImage = new AImage(image.getName(), image.getData());
synchronized (imageCache) {
imageCache.put(image.getAD_Image_ID(), aImage);
}
}
}
return aImage;
}
protected Component doCreatePart(Component parent) protected Component doCreatePart(Component parent)
{ {
windowPanelComponent = windowContent.createPart(parent); windowPanelComponent = windowContent.createPart(parent);
windowPanelComponent.setAttribute("ADWindow", this); windowPanelComponent.setAttribute("ADWindow", this);
windowPanelComponent.setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, windowNo); windowPanelComponent.setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, windowNo);
if (windowContent.initPanel(adWindowId, query)) if (windowContent.initPanel(query))
{ {
_title = windowContent.getTitle();
return windowPanelComponent; return windowPanelComponent;
} }
else else

View File

@ -67,9 +67,9 @@ public class ADWindowContent extends AbstractADWindowContent
private Keylistener keyListener; private Keylistener keyListener;
public ADWindowContent(Properties ctx, int windowNo) public ADWindowContent(Properties ctx, int windowNo, int adWindowId)
{ {
super(ctx, windowNo); super(ctx, windowNo, adWindowId);
} }
protected Component doCreatePart(Component parent) protected Component doCreatePart(Component parent)

View File

@ -77,6 +77,7 @@ import org.compiere.model.GridTable;
import org.compiere.model.GridWindow; import org.compiere.model.GridWindow;
import org.compiere.model.GridWindowVO; import org.compiere.model.GridWindowVO;
import org.compiere.model.Lookup; import org.compiere.model.Lookup;
import org.compiere.model.MImage;
import org.compiere.model.MProcess; import org.compiere.model.MProcess;
import org.compiere.model.MQuery; import org.compiere.model.MQuery;
import org.compiere.model.MRecentItem; import org.compiere.model.MRecentItem;
@ -175,15 +176,21 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
protected BreadCrumb breadCrumb; protected BreadCrumb breadCrumb;
private int adWindowId;
private MImage image;
/** /**
* Constructor * Constructor
* @param ctx * @param ctx
* @param windowNo * @param windowNo
* @param adWindowId
*/ */
public AbstractADWindowContent(Properties ctx, int windowNo) public AbstractADWindowContent(Properties ctx, int windowNo, int adWindowId)
{ {
this.ctx = ctx; this.ctx = ctx;
this.curWindowNo = windowNo; this.curWindowNo = windowNo;
this.adWindowId = adWindowId;
initComponents(); initComponents();
} }
@ -224,7 +231,18 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
toolbar.addListener(this); toolbar.addListener(this);
statusBar = new StatusBar(); statusBar = new StatusBar();
}
GridWindowVO gWindowVO = AEnv.getMWindowVO(curWindowNo, adWindowId, 0);
if (gWindowVO == null)
{
throw new ApplicationException(Msg.getMsg(ctx,
"AccessTableNoView")
+ "(No Window Model Info)");
}
gridWindow = new GridWindow(gWindowVO, true);
title = gridWindow.getName();
image = gridWindow.getMImage();
}
/** /**
* @return IADTab * @return IADTab
@ -247,7 +265,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
* @param query * @param query
* @return boolean * @return boolean
*/ */
public boolean initPanel(int adWindowId, MQuery query) public boolean initPanel(MQuery query)
{ {
// This temporary validation code is added to check the reported bug // This temporary validation code is added to check the reported bug
// [ adempiere-ZK Web Client-2832968 ] User context lost? // [ adempiere-ZK Web Client-2832968 ] User context lost?
@ -276,15 +294,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
boolean autoNew = Env.isAutoNew(ctx); boolean autoNew = Env.isAutoNew(ctx);
Env.setAutoNew(ctx, curWindowNo, autoNew); Env.setAutoNew(ctx, curWindowNo, autoNew);
GridWindowVO gWindowVO = AEnv.getMWindowVO(curWindowNo, adWindowId, 0);
if (gWindowVO == null)
{
throw new ApplicationException(Msg.getMsg(ctx,
"AccessTableNoView")
+ "(No Window Model Info)");
}
gridWindow = new GridWindow(gWindowVO, true);
title = gridWindow.getName();
// Set SO/AutoNew for Window // Set SO/AutoNew for Window
Env.setContext(ctx, curWindowNo, "IsSOTrx", gridWindow.isSOTrx()); Env.setContext(ctx, curWindowNo, "IsSOTrx", gridWindow.isSOTrx());
@ -518,8 +528,6 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
} }
}); });
// curTab = gTab;
} }
if (gTab.isSortTab()) if (gTab.isSortTab())
@ -668,6 +676,11 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
{ {
return title; return title;
} }
public MImage getImage()
{
return image;
}
/** /**
* @see ToolbarListener#onDetailRecord() * @see ToolbarListener#onDetailRecord()

View File

@ -269,7 +269,8 @@ public final class AEnv
if (mWindowVO != null) if (mWindowVO != null)
{ {
mWindowVO = mWindowVO.clone(WindowNo); mWindowVO = mWindowVO.clone(WindowNo);
log.info("Cached=" + mWindowVO); if (log.isLoggable(Level.INFO))
log.info("Cached=" + mWindowVO);
} }
} }
} }
@ -280,7 +281,7 @@ public final class AEnv
{ {
log.config("create local"); log.config("create local");
mWindowVO = GridWindowVO.create (Env.getCtx(), WindowNo, AD_Window_ID, AD_Menu_ID); mWindowVO = GridWindowVO.create (Env.getCtx(), WindowNo, AD_Window_ID, AD_Menu_ID);
if (mWindowVO != null) if (mWindowVO != null && Ini.isCacheWindow())
{ {
synchronized (windowCache) synchronized (windowCache)
{ {

View File

@ -13,8 +13,11 @@
*****************************************************************************/ *****************************************************************************/
package org.adempiere.webui.desktop; package org.adempiere.webui.desktop;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import org.adempiere.util.ContextRunnable;
import org.adempiere.webui.adwindow.ADWindow; import org.adempiere.webui.adwindow.ADWindow;
import org.adempiere.webui.apps.ProcessDialog; import org.adempiere.webui.apps.ProcessDialog;
import org.adempiere.webui.apps.wf.WFPanel; import org.adempiere.webui.apps.wf.WFPanel;
@ -24,13 +27,16 @@ import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.panel.ADForm; import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.part.WindowContainer; import org.adempiere.webui.part.WindowContainer;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.util.IServerPushCallback;
import org.adempiere.webui.util.ServerPushTemplate;
import org.adempiere.webui.window.WTask; import org.adempiere.webui.window.WTask;
import org.compiere.Adempiere;
import org.compiere.model.MQuery; import org.compiere.model.MQuery;
import org.compiere.model.MTask; import org.compiere.model.MTask;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.WebDoc; import org.compiere.util.WebDoc;
import org.compiere.wf.MWorkflow; import org.compiere.wf.MWorkflow;
import org.zkoss.image.AImage;
import org.zkoss.util.media.AMedia; import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Iframe; import org.zkoss.zul.Iframe;
@ -44,6 +50,7 @@ import org.zkoss.zul.Tabpanels;
*/ */
public abstract class TabbedDesktop extends AbstractDesktop { public abstract class TabbedDesktop extends AbstractDesktop {
private static final String IN_PROGRESS_IMAGE = "~./zk/img/progress3.gif";
protected WindowContainer windowContainer; protected WindowContainer windowContainer;
public TabbedDesktop() { public TabbedDesktop() {
@ -109,21 +116,12 @@ public abstract class TabbedDesktop extends AbstractDesktop {
/** /**
* *
* @param <T>
* @param windowId * @param windowId
* @return ADWindow * @return ADWindow
*/ */
public ADWindow openWindow(int windowId) { public ADWindow openWindow(int windowId) {
ADWindow adWindow = new ADWindow(Env.getCtx(), windowId); return openWindow(windowId, null);
DesktopTabpanel tabPanel = new DesktopTabpanel();
if (adWindow.createPart(tabPanel) != null) {
preOpenNewTab();
windowContainer.addWindow(tabPanel, adWindow.getTitle(), true);
return adWindow;
} else {
//user cancel
return null;
}
} }
/** /**
@ -133,17 +131,16 @@ public abstract class TabbedDesktop extends AbstractDesktop {
* @return ADWindow * @return ADWindow
*/ */
public ADWindow openWindow(int windowId, MQuery query) { public ADWindow openWindow(int windowId, MQuery query) {
ADWindow adWindow = new ADWindow(Env.getCtx(), windowId, query); final ADWindow adWindow = new ADWindow(Env.getCtx(), windowId, query);
DesktopTabpanel tabPanel = new DesktopTabpanel(); final DesktopTabpanel tabPanel = new DesktopTabpanel();
if (adWindow.createPart(tabPanel) != null) { final Tab tab = windowContainer.addWindow(tabPanel, adWindow.getTitle(), true);
preOpenNewTab(); tab.setImage(IN_PROGRESS_IMAGE);
windowContainer.addWindow(tabPanel, adWindow.getTitle(), true); tab.setClosable(false);
return adWindow; OpenWindowRunnable runnable = new OpenWindowRunnable(adWindow, tab, tabPanel);
} else { Adempiere.getThreadPoolExecutor().schedule(runnable, 100, TimeUnit.MICROSECONDS);
//user cancel
return null; return adWindow;
}
} }
/** /**
@ -220,14 +217,14 @@ public abstract class TabbedDesktop extends AbstractDesktop {
*/ */
public void showZoomWindow(int AD_Window_ID, MQuery query) public void showZoomWindow(int AD_Window_ID, MQuery query)
{ {
ADWindow wnd = new ADWindow(Env.getCtx(), AD_Window_ID, query); final ADWindow wnd = new ADWindow(Env.getCtx(), AD_Window_ID, query);
DesktopTabpanel tabPanel = new DesktopTabpanel(); final DesktopTabpanel tabPanel = new DesktopTabpanel();
if (wnd.createPart(tabPanel) != null) final Tab tab = windowContainer.insertAfter(windowContainer.getSelectedTab(), tabPanel, wnd.getTitle(), true, true);
{ tab.setImage(IN_PROGRESS_IMAGE);
preOpenNewTab(); tab.setClosable(false);
windowContainer.insertAfter(windowContainer.getSelectedTab(), tabPanel, wnd.getTitle(), true, true); OpenWindowRunnable runnable = new OpenWindowRunnable(wnd, tab, tabPanel);
} Adempiere.getThreadPoolExecutor().schedule(runnable, 100, TimeUnit.MICROSECONDS);
} }
/** /**
@ -335,4 +332,45 @@ public abstract class TabbedDesktop extends AbstractDesktop {
protected void preOpenNewTab() protected void preOpenNewTab()
{ {
} }
class OpenWindowRunnable extends ContextRunnable {
private final ADWindow adWindow;
private final Tab tab;
private final DesktopTabpanel tabPanel;
protected OpenWindowRunnable(ADWindow adWindow, Tab tab, DesktopTabpanel tabPanel) {
this.adWindow = adWindow;
this.tab = tab;
this.tabPanel = tabPanel;
}
@Override
protected void doRun() {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
}
ServerPushTemplate template = new ServerPushTemplate(windowContainer.getComponent().getDesktop());
template.executeAsync(new IServerPushCallback() {
@Override
public void updateUI() {
preOpenNewTab();
if (adWindow.createPart(tabPanel) != null ) {
tab.setImage(null);
tab.setClosable(true);
if (adWindow.getMImage() != null) {
try {
AImage aImage = adWindow.getAImage();
tab.setImageContent(aImage);
} catch (IOException e) {
}
}
} else {
tab.onClose();
}
}
});
}
}
} }

View File

@ -31,6 +31,17 @@ 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());
url = WebUIActivator.getBundleContext().getBundle().getEntry(t); url = WebUIActivator.getBundleContext().getBundle().getEntry(t);
if (url == null && t.endsWith(".gif")) {
t = t.replace(".gif", ".png");
url = WebUIActivator.getBundleContext().getBundle().getEntry(t);
}
} else if (url == null && name.startsWith("/org/compiere/images")) {
String t = name.substring("/org/compiere/".length());
url = WebUIActivator.getBundleContext().getBundle().getEntry(t);
if (url == null && t.endsWith(".gif")) {
t = t.replace(".gif", ".png");
url = WebUIActivator.getBundleContext().getBundle().getEntry(t);
}
} }
return url; return url;
} }