IDEMPIERE-1044 Load testing. Fixed memory leak.

This commit is contained in:
Heng Sin Low 2013-06-13 19:54:27 +08:00
parent 73a562b73c
commit b55c3ca70f
13 changed files with 329 additions and 133 deletions

View File

@ -17,6 +17,7 @@
package org.adempiere.webui;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -53,6 +54,7 @@ import org.zkoss.web.Attributes;
import org.zkoss.web.servlet.Servlets;
import org.zkoss.zk.au.out.AuScript;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.Session;
@ -238,10 +240,14 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
keyListener.setCtrlKeys("@a@c@d@e@f@h@n@o@p@r@s@t@z@x@#left@#right@#up@#down@#home@#end#enter^u@u");
keyListener.setAutoBlur(false);
IDesktop d = (IDesktop) currSess.getAttribute(APPLICATION_DESKTOP_KEY);
@SuppressWarnings("unchecked")
WeakReference<IDesktop> desktopRef = (WeakReference<IDesktop>) currSess.getAttribute(APPLICATION_DESKTOP_KEY);
IDesktop d = desktopRef != null ? desktopRef.get() : null;
if (d != null && d instanceof IDesktop)
{
ExecutionCarryOver eco = (ExecutionCarryOver) currSess.getAttribute(EXECUTION_CARRYOVER_SESSION_KEY);
@SuppressWarnings("unchecked")
WeakReference<ExecutionCarryOver> ecoRef = (WeakReference<ExecutionCarryOver>) currSess.getAttribute(EXECUTION_CARRYOVER_SESSION_KEY);;
ExecutionCarryOver eco = ecoRef != null ? ecoRef.get() : null;
if (eco != null) {
//try restore
try {
@ -299,11 +305,11 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
}
appDesktop.setPage(this.getPage());
Clients.response(new AuScript("$('.slimScroll .z-anchorlayout-body').slimScroll({height: '100%',railVisible: true, alwaysVisible: false});"));
currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, current);
currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, new WeakReference<ExecutionCarryOver>(current));
}
currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
ctx.put(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(this.getPage().getDesktop()));
ctx.put(ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(this.getPage().getDesktop()));
ClientInfo sessionClientInfo = (ClientInfo) currSess.getAttribute(CLIENT_INFO);
if (sessionClientInfo != null) {
clientInfo = sessionClientInfo;
@ -329,11 +335,11 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
createDesktop();
appDesktop.setClientInfo(clientInfo);
appDesktop.createPart(this.getPage());
currSess.setAttribute(APPLICATION_DESKTOP_KEY, appDesktop);
currSess.setAttribute(APPLICATION_DESKTOP_KEY, new WeakReference<IDesktop>(appDesktop));
ExecutionCarryOver eco = new ExecutionCarryOver(this.getPage().getDesktop());
currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, eco);
currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
ctx.put(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, new WeakReference<ExecutionCarryOver>(eco));
currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(this.getPage().getDesktop()));
ctx.put(ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(this.getPage().getDesktop()));
}
//ensure server push is on

View File

@ -21,6 +21,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.PreparedStatement;
@ -811,8 +812,13 @@ public final class AEnv
*/
public static Desktop getDesktop() {
boolean inUIThread = Executions.getCurrent() != null;
return inUIThread ? Executions.getCurrent().getDesktop()
: (Desktop) Env.getCtx().get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY);
if (inUIThread) {
return Executions.getCurrent().getDesktop();
} else {
@SuppressWarnings("unchecked")
WeakReference<Desktop> ref = (WeakReference<Desktop>) Env.getCtx().get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY);
return ref != null ? ref.get() : null;
}
}
/**

View File

@ -6,6 +6,7 @@ import static org.compiere.model.SystemIDs.PROCESS_M_INOUT_GENERATE;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.ref.WeakReference;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -347,7 +348,7 @@ public class ProcessDialog extends Window implements EventListener<Event>, IProc
Properties context = ServerContext.getCurrentInstance();
if (context.get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY) == null) {
Desktop desktop = this.getDesktop();
context.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, desktop);
context.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(desktop));
}
processDialogRunnable = new ProcessDialogRunnable();

View File

@ -17,6 +17,7 @@
package org.adempiere.webui.apps;
import java.io.File;
import java.lang.ref.WeakReference;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -382,7 +383,7 @@ public class ProcessModalDialog extends Window implements EventListener<Event>,
Properties context = ServerContext.getCurrentInstance();
if (context.get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY) == null) {
Desktop desktop = this.getDesktop();
context.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, desktop);
context.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(desktop));
}
processDialogRunnable = new ProcessDialogRunnable();

View File

@ -13,6 +13,7 @@
*****************************************************************************/
package org.adempiere.webui.dashboard;
import java.lang.ref.WeakReference;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
@ -56,6 +57,7 @@ import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.DesktopCleanup;
import org.zkoss.zul.Label;
import org.zkoss.zul.impl.LabelImageElement;
@ -84,8 +86,9 @@ public class DPCalendar extends DashboardPanel implements EventListener<Event>,
private EventWindow eventWin;
private Properties ctx;
private Desktop desktop;
private WeakReference<Desktop> desktop;
private ArrayList<ADCalendarEvent> events;
private DesktopCleanup listener;
private static RequestEventHandler eventHandler;
private static TopicSubscriber subscriber;
@ -126,6 +129,13 @@ public class DPCalendar extends DashboardPanel implements EventListener<Event>,
calendars.addEventListener("onEventEdit", this);
createStaticListeners();
listener = new DesktopCleanup() {
@Override
public void cleanup(Desktop desktop) throws Exception {
DPCalendar.this.cleanup();
}
};
}
private synchronized void createStaticListeners() {
@ -348,7 +358,17 @@ public class DPCalendar extends DashboardPanel implements EventListener<Event>,
public void refresh(ServerPushTemplate template) {
refreshModel();
template.executeAsync(this);
desktop = getDesktop();
if (desktop != null && desktop.get() != null) {
if (desktop.get() != getDesktop()) {
desktop.get().removeListener(listener);
desktop = new WeakReference<Desktop>(getDesktop());
desktop.get().addListener(listener);
}
} else {
desktop = new WeakReference<Desktop>(getDesktop());
desktop.get().addListener(listener);
}
}
@Override
@ -405,8 +425,8 @@ public class DPCalendar extends DashboardPanel implements EventListener<Event>,
if (clientId.equals(AD_Client_ID) && !"0".equals(AD_User_ID)) {
if (salesRepId.equals(AD_User_ID) || userId.equals(AD_User_ID) || createdBy.equals(AD_User_ID)) {
try {
if (desktop != null && desktop.isAlive()) {
ServerPushTemplate template = new ServerPushTemplate(desktop);
if (desktop != null && desktop.get() != null && desktop.get().isAlive()) {
ServerPushTemplate template = new ServerPushTemplate(desktop.get());
refresh(template);
} else {
EventManager.getInstance().unregister(this);
@ -424,13 +444,24 @@ public class DPCalendar extends DashboardPanel implements EventListener<Event>,
super.onPageAttached(newpage, oldpage);
if (newpage != null) {
EventManager.getInstance().register(ON_REQUEST_CHANGED_TOPIC, this);
desktop = getDesktop();
if (desktop != null && desktop.get() != null) {
desktop.get().removeListener(listener);
}
desktop = new WeakReference<Desktop>(getDesktop());
desktop.get().addListener(listener);
}
}
@Override
public void onPageDetached(Page page) {
super.onPageDetached(page);
cleanup();
}
/**
*
*/
protected void cleanup() {
EventManager.getInstance().unregister(this);
desktop = null;
}

View File

@ -13,6 +13,7 @@
*****************************************************************************/
package org.adempiere.webui.dashboard;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Properties;
@ -39,6 +40,7 @@ import org.zkoss.zk.ui.event.DropEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.DesktopCleanup;
import org.zkoss.zul.A;
import org.zkoss.zul.Box;
import org.zkoss.zul.Image;
@ -71,7 +73,9 @@ public class DPRecentItems extends DashboardPanel implements EventListener<Event
private Properties ctx;
private Desktop desktop;
private WeakReference<Desktop> desktop;
private DesktopCleanup listener;
public DPRecentItems()
{
@ -109,6 +113,18 @@ public class DPRecentItems extends DashboardPanel implements EventListener<Event
img.addEventListener(Events.ON_DROP, this);
//
createTopicSubscriber();
listener = new DesktopCleanup() {
@Override
public void cleanup(Desktop desktop) throws Exception {
DPRecentItems.this.cleanup();
}
};
}
protected void cleanup() {
EventManager.getInstance().unregister(this);
desktop = null;
}
private static synchronized void createTopicSubscriber() {
@ -256,7 +272,21 @@ public class DPRecentItems extends DashboardPanel implements EventListener<Event
public void updateUI() {
refresh();
bxRecentItems.invalidate();
desktop = getDesktop();
updateDesktopReference();
}
/**
*
*/
protected void updateDesktopReference() {
if ((desktop == null || desktop.get() == null) || (desktop.get() != null && desktop.get() != getDesktop())) {
if (desktop != null && desktop.get() != null)
desktop.get().removeListener(listener);
desktop = new WeakReference<Desktop>(getDesktop());
desktop.get().addListener(listener);
}
}
@Override
@ -267,8 +297,8 @@ public class DPRecentItems extends DashboardPanel implements EventListener<Event
int id = ((Number)property).intValue();
if (id == AD_User_ID) {
try {
if (desktop != null && desktop.isAlive()) {
ServerPushTemplate template = new ServerPushTemplate(desktop);
if (desktop != null && desktop.get() != null && desktop.get().isAlive()) {
ServerPushTemplate template = new ServerPushTemplate(desktop.get());
refresh(template);
}
} catch (Exception e) {
@ -284,15 +314,14 @@ public class DPRecentItems extends DashboardPanel implements EventListener<Event
super.onPageAttached(newpage, oldpage);
if (newpage != null) {
EventManager.getInstance().register(MRecentItem.ON_RECENT_ITEM_CHANGED_TOPIC, this);
desktop = getDesktop();
updateDesktopReference();
}
}
@Override
public void onPageDetached(Page page) {
super.onPageDetached(page);
EventManager.getInstance().unregister(this);
desktop = null;
cleanup();
}
static class TopicSubscriber implements ITopicSubscriber<Integer> {

View File

@ -14,6 +14,7 @@
package org.adempiere.webui.dashboard;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@ -26,6 +27,7 @@ import org.compiere.util.CLogger;
import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.DesktopCleanup;
/**
*
@ -38,10 +40,12 @@ public class DashboardRunnable implements Runnable, Serializable
private static final long serialVersionUID = 5995227773511788894L;
private Desktop desktop;
private WeakReference<Desktop> desktop;
private List<DashboardPanel> dashboardPanels;
private Locale locale;
private DesktopCleanup listener;
@SuppressWarnings("unused")
private static final CLogger logger = CLogger.getCLogger(DashboardRunnable.class);
@ -51,25 +55,43 @@ public class DashboardRunnable implements Runnable, Serializable
* @param appDesktop adempiere desktop interface
*/
public DashboardRunnable(Desktop desktop) {
this.desktop = desktop;
this.desktop = new WeakReference<Desktop>(desktop);
dashboardPanels = new ArrayList<DashboardPanel>();
locale = Locales.getCurrent();
listener = new DesktopCleanup() {
@Override
public void cleanup(Desktop desktop) throws Exception {
DashboardRunnable.this.cleanup();
}
};
this.desktop.get().addListener(listener);
}
protected void cleanup() {
dashboardPanels = null;
if (desktop != null && desktop.get() != null)
desktop.get().removeListener(listener);
desktop = null;
}
public DashboardRunnable(DashboardRunnable tmp, Desktop desktop) {
this(desktop);
this.dashboardPanels = tmp.dashboardPanels;
tmp.cleanup();
}
public void run()
{
Locales.setThreadLocal(locale);
try {
refreshDashboard(true);
} catch (Exception e) {
// logger.log(Level.INFO, e.getLocalizedMessage(), (e.getCause() != null ? e.getCause() : e));
throw new RuntimeException(e);
{
if (dashboardPanels != null && desktop != null && desktop.get() != null)
{
Locales.setThreadLocal(locale);
try {
refreshDashboard(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@ -79,7 +101,7 @@ public class DashboardRunnable implements Runnable, Serializable
public void refreshDashboard(boolean pooling)
{
ServerPushTemplate template = new ServerPushTemplate(desktop);
ServerPushTemplate template = new ServerPushTemplate(desktop.get());
//set thread local context if not in event thread
Properties ctx = null;
boolean isEventThread = Events.inEventListener();
@ -122,7 +144,8 @@ public class DashboardRunnable implements Runnable, Serializable
* @param dashboardPanel
*/
public void add(DashboardPanel dashboardPanel) {
dashboardPanels.add(dashboardPanel);
if (dashboardPanels != null)
dashboardPanels.add(dashboardPanel);
}
/**

View File

@ -384,12 +384,12 @@ public class DashboardController implements EventListener<Event> {
{
dashboardRunnable.refreshDashboard(false);
// default Update every one minutes
int interval = MSysConfig.getIntValue(MSysConfig.ZK_DASHBOARD_REFRESH_INTERVAL, 60000);
dashboardFuture = Adempiere.getThreadPoolExecutor().scheduleWithFixedDelay(dashboardRunnable, interval, interval, TimeUnit.MILLISECONDS);
}
// default Update every one minutes
int interval = MSysConfig.getIntValue(MSysConfig.ZK_DASHBOARD_REFRESH_INTERVAL, 60000);
dashboardFuture = Adempiere.getThreadPoolExecutor().scheduleWithFixedDelay(dashboardRunnable, interval, interval, TimeUnit.MILLISECONDS);
}
}
public void onEvent(Event event) throws Exception {
Component comp = event.getTarget();
String eventName = event.getName();
@ -598,8 +598,9 @@ public class DashboardController implements EventListener<Event> {
public void onSetPage(Page page, Desktop desktop) {
if (dashboardFuture != null && !dashboardFuture.isDone()) {
dashboardFuture.cancel(true);
DashboardRunnable tmp = dashboardRunnable;
Adempiere.getThreadPoolExecutor().remove((Runnable) dashboardFuture);
DashboardRunnable tmp = dashboardRunnable;
dashboardRunnable = new DashboardRunnable(tmp, desktop);
// default Update every one minutes
int interval = MSysConfig.getIntValue(MSysConfig.ZK_DASHBOARD_REFRESH_INTERVAL, 60000);
@ -613,7 +614,14 @@ public class DashboardController implements EventListener<Event> {
public void onLogOut() {
if (dashboardFuture != null && !dashboardFuture.isDone()) {
dashboardFuture.cancel(true);
Adempiere.getThreadPoolExecutor().remove((Runnable) dashboardFuture);
dashboardFuture = null;
}
if (dashboardRunnable != null) {
dashboardRunnable = null;
}
dashboardLayout.detach();
dashboardLayout = null;
}
public void addDashboardPanel(DashboardPanel dashboardPanel) {

View File

@ -108,8 +108,6 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
@SuppressWarnings("unused")
private static final CLogger logger = CLogger.getCLogger(DefaultDesktop.class);
private Center windowArea;
private Borderlayout layout;
private int noOfNotice;
@ -124,12 +122,9 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
private DashboardController dashboardController, sideController;
private BroadcastMessageWindow messageWindow;
private BroadcastMessageWindow testMessageWindow;
private HeaderPanel pnlHead;
private Desktop m_desktop = null;
private TimeoutPanel panel = null;
private HelpController helpController;
@ -217,7 +212,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
helpController.render(e, this);
windowArea = layout.getCenter();
Center windowArea = layout.getCenter();
windowContainer.createPart(windowArea);
@ -229,7 +224,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
busyDialog.setShadow(false);
homeTab.appendChild(busyDialog);
messageWindow = new BroadcastMessageWindow(pnlHead);
BroadcastMessageWindow messageWindow = new BroadcastMessageWindow(pnlHead);
BroadcastMsgUtil.showPendingMessage(Env.getAD_User_ID(Env.getCtx()), messageWindow);
if (!layout.getDesktop().isServerPushEnabled())
@ -422,11 +417,18 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
unbindEventManager();
if (dashboardController != null) {
dashboardController.onLogOut();
dashboardController = null;
}
if (sideController != null) {
sideController.onLogOut();
sideController = null;
}
layout.detach();
layout = null;
pnlHead = null;
max = null;
m_desktop = null;
}
public void updateUI() {
@ -499,8 +501,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
.toString(Env.getContextAsInt(Env.getCtx(),
"AD_Session_ID"));
if (currSession.equals(msg.getTarget())) {
if (testMessageWindow == null)
testMessageWindow = new BroadcastMessageWindow(
BroadcastMessageWindow testMessageWindow = new BroadcastMessageWindow(
pnlHead);
testMessageWindow.appendMessage(mbMessage, true);
testMessageWindow = null;
@ -512,8 +513,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
Env.getCtx(), msg.getIntData());
if (mbMessage.isValidUserforMessage()) {
if (messageWindow == null)
messageWindow = new BroadcastMessageWindow(
BroadcastMessageWindow messageWindow = new BroadcastMessageWindow(
pnlHead);
messageWindow.appendMessage(mbMessage, false);
}
@ -522,12 +522,8 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
currSession = Integer.toString(Env.getContextAsInt(
Env.getCtx(), "AD_Session_ID"));
System.out.println("Current Session" + currSession);
if (currSession.equalsIgnoreCase(msg.getTarget())) {
if (panel == null) {
panel = new TimeoutPanel(pnlHead,
msg.getIntData());
}
new TimeoutPanel(pnlHead, msg.getIntData());
}
break;
@ -536,10 +532,7 @@ public class DefaultDesktop extends TabbedDesktop implements MenuListener, Seria
currSession = WebUtil.getServerName();
if (currSession.equalsIgnoreCase(msg.getTarget())) {
if (panel == null) {
panel = new TimeoutPanel(pnlHead,
msg.getIntData());
}
new TimeoutPanel(pnlHead, msg.getIntData());
}
}

View File

@ -53,11 +53,13 @@ import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.NamePair;
import org.compiere.util.ValueNamePair;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.DesktopCleanup;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Menuitem;
@ -656,18 +658,37 @@ ContextMenuListener, IZoomableEditor
*/
private static final long serialVersionUID = 4540856986889452983L;
protected WTableDirEditor editor;
private DesktopCleanup listener = null;
@Override
public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage);
if (editor.tableCacheListener == null) {
editor.createCacheListener();
if (listener == null) {
listener = new DesktopCleanup() {
@Override
public void cleanup(Desktop desktop) throws Exception {
EditorCombobox.this.cleanup();
}
};
newpage.getDesktop().addListener(listener);
}
}
}
@Override
public void onPageDetached(Page page) {
super.onPageDetached(page);
if (listener != null && page.getDesktop() != null)
page.getDesktop().removeListener(listener);
cleanup();
}
/**
*
*/
protected void cleanup() {
if (editor.tableCacheListener != null) {
CacheMgt.get().unregister(editor.tableCacheListener);
editor.tableCacheListener = null;

View File

@ -33,8 +33,10 @@ import org.compiere.model.MTreeNode;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.EventQueue;
import org.zkoss.zk.ui.event.EventQueues;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.A;
@ -65,57 +67,14 @@ public abstract class AbstractMenuPanel extends Panel implements EventListener<E
private Properties ctx;
private Tree menuTree;
private EventListener<Event> listener;
public AbstractMenuPanel(Component parent)
{
if (parent != null)
this.setParent(parent);
init();
EventQueues.lookup(MENU_ITEM_SELECTED_QUEUE, EventQueues.DESKTOP, true).subscribe(new EventListener<Event>() {
public void onEvent(Event event) throws Exception {
if (event.getName() == Events.ON_SELECT)
{
Treeitem selectedItem = (Treeitem) event.getData();
if (selectedItem != null)
{
Object value = selectedItem.getValue();
if (value != null)
{
if (menuTree.getSelectedItem() != null && menuTree.getSelectedItem().getValue() != null && menuTree.getSelectedItem().getValue().equals(value))
return;
Collection<Treeitem> items = menuTree.getItems();
for (Treeitem item : items)
{
if (item != null && item.getValue() != null && item.getValue().equals(value))
{
TreeSearchPanel.select(item);
return;
}
}
}
else
{
String label = selectedItem.getLabel();
if (menuTree.getSelectedItem() != null && menuTree.getSelectedItem().getLabel() != null && menuTree.getSelectedItem().getLabel().equals(label))
return;
Collection<Treeitem> items = menuTree.getItems();
for (Treeitem item : items)
{
if (item != null && item.getLabel() != null && item.getLabel().equals(label))
{
TreeSearchPanel.select(item);
return;
}
}
}
}
}
}
});
init();
}
protected void init() {
@ -350,4 +309,75 @@ public abstract class AbstractMenuPanel extends Panel implements EventListener<E
{
return ctx;
}
/* (non-Javadoc)
* @see org.zkoss.zk.ui.AbstractComponent#onPageDetached(org.zkoss.zk.ui.Page)
*/
@Override
public void onPageDetached(Page page) {
super.onPageDetached(page);
if (listener != null) {
try {
EventQueue<Event> queue = EventQueues.lookup(MENU_ITEM_SELECTED_QUEUE, EventQueues.DESKTOP, true);
if (queue != null)
queue.unsubscribe(listener);
} finally {
listener = null;
}
}
}
@Override
public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage);
if (listener == null) {
listener = new EventListener<Event>() {
public void onEvent(Event event) throws Exception {
if (event.getName() == Events.ON_SELECT)
{
Treeitem selectedItem = (Treeitem) event.getData();
if (selectedItem != null)
{
Object value = selectedItem.getValue();
if (value != null)
{
if (menuTree.getSelectedItem() != null && menuTree.getSelectedItem().getValue() != null && menuTree.getSelectedItem().getValue().equals(value))
return;
Collection<Treeitem> items = menuTree.getItems();
for (Treeitem item : items)
{
if (item != null && item.getValue() != null && item.getValue().equals(value))
{
TreeSearchPanel.select(item);
return;
}
}
}
else
{
String label = selectedItem.getLabel();
if (menuTree.getSelectedItem() != null && menuTree.getSelectedItem().getLabel() != null && menuTree.getSelectedItem().getLabel().equals(label))
return;
Collection<Treeitem> items = menuTree.getItems();
for (Treeitem item : items)
{
if (item != null && item.getLabel() != null && item.getLabel().equals(label))
{
TreeSearchPanel.select(item);
return;
}
}
}
}
}
}
};
}
EventQueues.lookup(MENU_ITEM_SELECTED_QUEUE, EventQueues.DESKTOP, true).subscribe(listener);
}
}

View File

@ -15,8 +15,10 @@
package org.adempiere.webui.panel;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.EventQueue;
import org.zkoss.zk.ui.event.EventQueues;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Checkbox;
@ -35,6 +37,8 @@ public class MenuSearchPanel extends AbstractMenuPanel
private static final long serialVersionUID = 5308522340852904168L;
protected MenuTreeSearchPanel pnlSearch;
private EventListener<Event> listener;
public MenuSearchPanel(Component parent)
{
@ -45,26 +49,7 @@ public class MenuSearchPanel extends AbstractMenuPanel
protected void init()
{
super.init();
pnlSearch.initialise();
EventQueues.lookup(MenuTreeFilterPanel.MENU_TREE_FILTER_CHECKED_QUEUE, EventQueues.DESKTOP, true).subscribe(new EventListener<Event>() {
public void onEvent(Event event) throws Exception {
if (event.getName() == Events.ON_CHECK)
{
Checkbox chk = (Checkbox) event.getData();
if (chk != null)
{
if ("flatView".equals(chk.getId()))
MenuTreeFilterPanel.toggleFlatView(getMenuTree(), chk);
else
MenuTreeFilterPanel.toggle(getMenuTree(), chk);
if (pnlSearch != null)
pnlSearch.refreshSearchList();
getMenuTree().invalidate();
}
}
}
});
pnlSearch.initialise();
}
protected void initComponents()
@ -83,4 +68,50 @@ public class MenuSearchPanel extends AbstractMenuPanel
pnlSearch.setSclass("menu-search-panel");
toolbar.appendChild(pnlSearch);
}
/* (non-Javadoc)
* @see org.zkoss.zk.ui.AbstractComponent#onPageDetached(org.zkoss.zk.ui.Page)
*/
@Override
public void onPageDetached(Page page) {
super.onPageDetached(page);
if (listener != null) {
try {
EventQueue<Event> queue = EventQueues.lookup(MenuTreeFilterPanel.MENU_TREE_FILTER_CHECKED_QUEUE, EventQueues.DESKTOP, true);
if (queue != null)
queue.unsubscribe(listener);
} finally {
listener = null;
}
}
}
@Override
public void onPageAttached(Page newpage, Page oldpage) {
super.onPageAttached(newpage, oldpage);
if (listener == null) {
listener = new EventListener<Event>() {
public void onEvent(Event event) throws Exception {
if (event.getName() == Events.ON_CHECK)
{
Checkbox chk = (Checkbox) event.getData();
if (chk != null)
{
if ("flatView".equals(chk.getId()))
MenuTreeFilterPanel.toggleFlatView(getMenuTree(), chk);
else
MenuTreeFilterPanel.toggle(getMenuTree(), chk);
if (pnlSearch != null)
pnlSearch.refreshSearchList();
getMenuTree().invalidate();
}
}
}
};
}
EventQueues.lookup(MenuTreeFilterPanel.MENU_TREE_FILTER_CHECKED_QUEUE, EventQueues.DESKTOP, true).subscribe(listener);
}
}

View File

@ -17,6 +17,7 @@
package org.adempiere.webui.session;
import java.lang.ref.WeakReference;
import java.util.Properties;
import org.adempiere.webui.AdempiereWebUI;
@ -53,8 +54,17 @@ public class SessionManager
private static Session getSession()
{
Execution execution = Executions.getCurrent();
Desktop desktop = execution != null ? execution.getDesktop()
: (Desktop) Env.getCtx().get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY);
Desktop desktop = null;
if (execution != null)
{
desktop = execution.getDesktop();
}
else
{
@SuppressWarnings("unchecked")
WeakReference<Desktop> ref = (WeakReference<Desktop>) Env.getCtx().get(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY);
desktop = ref != null ? ref.get() : null;
}
return desktop != null ? desktop.getSession() : null;
}
@ -62,7 +72,7 @@ public class SessionManager
{
Session session = getSession();
if (session != null)
session.setAttribute(SESSION_APPLICATION, app);
session.setAttribute(SESSION_APPLICATION, new WeakReference<IWebClient>(app));
}
public static IDesktop getAppDesktop()
@ -74,7 +84,13 @@ public class SessionManager
public static IWebClient getSessionApplication()
{
Session session = getSession();
IWebClient app = session != null ? (IWebClient)session.getAttribute(SESSION_APPLICATION) : null;
IWebClient app = null;
if (session != null)
{
@SuppressWarnings("unchecked")
WeakReference<IWebClient> wref = (WeakReference<IWebClient>) session.getAttribute(SESSION_APPLICATION);
app = wref != null ? wref.get() : null;
}
return app;
}