Merged trekglobal/idempiere/release-2.0 into release-2.0

This commit is contained in:
Carlos Ruiz 2013-11-20 08:44:52 -05:00
commit 540a7c71c4
5 changed files with 140 additions and 168 deletions

View File

@ -560,11 +560,35 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
if (cssPrefix != null) if (cssPrefix != null)
table.setClass(cssPrefix + "-table"); table.setClass(cssPrefix + "-table");
// //
//
table.setNeedClosingTag(false);
PrintWriter w = new PrintWriter(writer);
if (onlyTable)
table.output(w);
else
{
XhtmlDocument doc = new XhtmlDocument();
doc.getHtml().setNeedClosingTag(false);
doc.getBody().setNeedClosingTag(false);
doc.appendBody(table);
if (extension != null && extension.getStyleURL() != null)
{
link l = new link(extension.getStyleURL(), "stylesheet", "text/css");
doc.appendHead(l);
}
if (extension != null && extension.getScriptURL() != null)
{
script jslink = new script();
jslink.setLanguage("javascript");
jslink.setSrc(extension.getScriptURL());
doc.appendHead(jslink);
}
doc.output(w);
}
// for all rows (-1 = header row) // for all rows (-1 = header row)
for (int row = -1; row < m_printData.getRowCount(); row++) for (int row = -1; row < m_printData.getRowCount(); row++)
{ {
tr tr = new tr(); tr tr = new tr();
table.addElement(tr);
if (row != -1) if (row != -1)
{ {
m_printData.setRowIndex(row); m_printData.setRowIndex(row);
@ -693,29 +717,15 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
} }
} // printed } // printed
} // for all columns } // for all columns
tr.output(w);
} // for all rows } // for all rows
// w.println();
PrintWriter w = new PrintWriter(writer); w.println("</table>");
if (onlyTable) if (!onlyTable)
table.output(w);
else
{ {
XhtmlDocument doc = new XhtmlDocument(); w.println("</body>");
doc.appendBody(table); w.println("</html>");
if (extension != null && extension.getStyleURL() != null)
{
link l = new link(extension.getStyleURL(), "stylesheet", "text/css");
doc.appendHead(l);
}
if (extension != null && extension.getScriptURL() != null)
{
script jslink = new script();
jslink.setLanguage("javascript");
jslink.setSrc(extension.getScriptURL());
doc.appendHead(jslink);
}
doc.output(w);
} }
w.flush(); w.flush();
w.close(); w.close();

View File

@ -18,8 +18,6 @@
package org.adempiere.webui; package org.adempiere.webui;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -53,23 +51,15 @@ import org.zkforge.keylistener.Keylistener;
import org.zkoss.web.Attributes; import org.zkoss.web.Attributes;
import org.zkoss.web.servlet.Servlets; import org.zkoss.web.servlet.Servlets;
import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.au.out.AuScript;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.Session; import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.UiException;
import org.zkoss.zk.ui.event.ClientInfoEvent; import org.zkoss.zk.ui.event.ClientInfoEvent;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.impl.ExecutionCarryOver;
import org.zkoss.zk.ui.sys.DesktopCache; import org.zkoss.zk.ui.sys.DesktopCache;
import org.zkoss.zk.ui.sys.DesktopCtrl;
import org.zkoss.zk.ui.sys.ExecutionCtrl;
import org.zkoss.zk.ui.sys.ExecutionsCtrl;
import org.zkoss.zk.ui.sys.SessionCtrl; import org.zkoss.zk.ui.sys.SessionCtrl;
import org.zkoss.zk.ui.sys.Visualizer;
import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Window; import org.zkoss.zul.Window;
@ -100,8 +90,6 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
private WLogin loginDesktop; private WLogin loginDesktop;
private IDesktop appDesktop;
private ClientInfo clientInfo = new ClientInfo(); private ClientInfo clientInfo = new ClientInfo();
private String langSession; private String langSession;
@ -243,107 +231,15 @@ 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.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); keyListener.setAutoBlur(false);
@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)
{
@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 {
appDesktop = (IDesktop) d;
ExecutionCarryOver current = new ExecutionCarryOver(this.getPage().getDesktop());
ExecutionCtrl ctrl = ExecutionsCtrl.getCurrentCtrl();
Visualizer vi = ctrl.getVisualizer();
eco.carryOver();
Collection<Component> rootComponents = new ArrayList<Component>();
try {
ctrl = ExecutionsCtrl.getCurrentCtrl();
((DesktopCtrl)Executions.getCurrent().getDesktop()).setVisualizer(vi);
//detach root component from old page
Page page = appDesktop.getComponent().getPage();
if (page.getDesktop() != null) {
Collection<Component> collection = page.getRoots();
for(Component comp : collection) {
try {
comp.detach();
if (!(comp instanceof Keylistener) && !(comp instanceof AdempiereWebUI)) {
rootComponents.add(comp);
}
} catch (Exception e) {
e.printStackTrace();
}
}
appDesktop.getComponent().detach();
DesktopCache desktopCache = ((SessionCtrl)currSess).getDesktopCache();
if (desktopCache != null)
desktopCache.removeDesktop(Executions.getCurrent().getDesktop());
} else {
appDesktop = null;
}
} catch (Exception e) {
e.printStackTrace();
appDesktop = null;
} finally {
eco.cleanup();
current.carryOver();
}
if (appDesktop != null) {
//re-attach root components
for (Component component : rootComponents) {
try {
component.setPage(this.getPage());
} catch (UiException e) {
// e.printStackTrace();
// an exception is thrown here when refreshing the page, it seems is harmless to catch and ignore it
// i.e.: org.zkoss.zk.ui.UiException: Not unique in the ID space of [Page z_kg_0]: zk_comp_2
}
}
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, new WeakReference<ExecutionCarryOver>(current));
}
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;
}
} catch (Throwable t) {
//restore fail
t.printStackTrace();
appDesktop = null;
Collection<Component> roots = this.getPage().getRoots();
for(Component comp : roots) {
if (!(comp instanceof Keylistener) && !(comp instanceof AdempiereWebUI)) {
comp.detach();
}
}
}
}
}
if (appDesktop == null)
{
//create new desktop //create new desktop
createDesktop(); IDesktop appDesktop = createDesktop();
appDesktop.setClientInfo(clientInfo); appDesktop.setClientInfo(clientInfo);
appDesktop.createPart(this.getPage()); appDesktop.createPart(this.getPage());
currSess.setAttribute(APPLICATION_DESKTOP_KEY, new WeakReference<IDesktop>(appDesktop));
ExecutionCarryOver eco = new ExecutionCarryOver(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())); ctx.put(ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(this.getPage().getDesktop()));
} this.getPage().getDesktop().setAttribute(APPLICATION_DESKTOP_KEY, new WeakReference<IDesktop>(appDesktop));
//track browser tab per session
SessionContextListener.addDesktopId(mSession.getAD_Session_ID(), getPage().getDesktop().getId());
//ensure server push is on //ensure server push is on
if (!this.getPage().getDesktop().isServerPushEnabled()) if (!this.getPage().getDesktop().isServerPushEnabled())
@ -381,9 +277,9 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
return keyListener; return keyListener;
} }
private void createDesktop() private IDesktop createDesktop()
{ {
appDesktop = null; IDesktop appDesktop = null;
String className = MSysConfig.getValue(MSysConfig.ZK_DESKTOP_CLASS); String className = MSysConfig.getValue(MSysConfig.ZK_DESKTOP_CLASS);
if ( className != null && className.trim().length() > 0) if ( className != null && className.trim().length() > 0)
{ {
@ -400,6 +296,8 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
//fallback to default //fallback to default
if (appDesktop == null) if (appDesktop == null)
appDesktop = new DefaultDesktop(); appDesktop = new DefaultDesktop();
return appDesktop;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -438,6 +336,7 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
} }
//stop background thread //stop background thread
IDesktop appDesktop = getAppDeskop();
if (appDesktop != null) if (appDesktop != null)
appDesktop.logout(); appDesktop.logout();
@ -458,6 +357,18 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
*/ */
public IDesktop getAppDeskop() public IDesktop getAppDeskop()
{ {
Desktop desktop = Executions.getCurrent() != null ? Executions.getCurrent().getDesktop() : null;
IDesktop appDesktop = null;
if (desktop != null)
{
@SuppressWarnings("unchecked")
WeakReference<IDesktop> ref = (WeakReference<IDesktop>) desktop.getAttribute(APPLICATION_DESKTOP_KEY);
if (ref != null)
{
appDesktop = ref.get();
}
}
return appDesktop; return appDesktop;
} }
@ -475,6 +386,7 @@ public class AdempiereWebUI extends Window implements EventListener<Event>, IWeb
clientInfo.desktopYOffset = c.getDesktopYOffset(); clientInfo.desktopYOffset = c.getDesktopYOffset();
clientInfo.orientation = c.getOrientation(); clientInfo.orientation = c.getOrientation();
clientInfo.timeZone = c.getTimeZone(); clientInfo.timeZone = c.getTimeZone();
IDesktop appDesktop = getAppDeskop();
if (appDesktop != null) if (appDesktop != null)
appDesktop.setClientInfo(clientInfo); appDesktop.setClientInfo(clientInfo);
String ua = Servlets.getUserAgent((ServletRequest) Executions.getCurrent().getNativeRequest()); String ua = Servlets.getUserAgent((ServletRequest) Executions.getCurrent().getNativeRequest());

View File

@ -27,6 +27,7 @@ import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.factory.InfoManager; import org.adempiere.webui.factory.InfoManager;
import org.adempiere.webui.panel.ADForm; import org.adempiere.webui.panel.ADForm;
import org.adempiere.webui.panel.IHelpContext;
import org.adempiere.webui.panel.InfoPanel; import org.adempiere.webui.panel.InfoPanel;
import org.adempiere.webui.part.WindowContainer; import org.adempiere.webui.part.WindowContainer;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
@ -293,6 +294,8 @@ public abstract class TabbedDesktop extends AbstractDesktop {
windowContainer.insertAfter(windowContainer.getSelectedTab(), tabPanel, title, true, true); windowContainer.insertAfter(windowContainer.getSelectedTab(), tabPanel, title, true, true);
else else
windowContainer.addWindow(tabPanel, title, true); windowContainer.addWindow(tabPanel, title, true);
if (window instanceof IHelpContext)
Events.sendEvent(new Event(WindowContainer.ON_WINDOW_CONTAINER_SELECTION_CHANGED_EVENT, window));
} }
/** /**

View File

@ -17,6 +17,9 @@
package org.adempiere.webui.session; package org.adempiere.webui.session;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -24,6 +27,7 @@ import javax.servlet.http.HttpSession;
import org.adempiere.util.ServerContext; import org.adempiere.util.ServerContext;
import org.adempiere.util.ServerContextURLHandler; import org.adempiere.util.ServerContextURLHandler;
import org.adempiere.webui.AdempiereWebUI;
import org.compiere.model.MSession; import org.compiere.model.MSession;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.zkoss.util.Locales; import org.zkoss.util.Locales;
@ -37,8 +41,10 @@ import org.zkoss.zk.ui.event.EventThreadCleanup;
import org.zkoss.zk.ui.event.EventThreadInit; import org.zkoss.zk.ui.event.EventThreadInit;
import org.zkoss.zk.ui.event.EventThreadResume; import org.zkoss.zk.ui.event.EventThreadResume;
import org.zkoss.zk.ui.event.EventThreadSuspend; import org.zkoss.zk.ui.event.EventThreadSuspend;
import org.zkoss.zk.ui.sys.DesktopCache;
import org.zkoss.zk.ui.sys.DesktopCtrl; import org.zkoss.zk.ui.sys.DesktopCtrl;
import org.zkoss.zk.ui.sys.ServerPush; import org.zkoss.zk.ui.sys.ServerPush;
import org.zkoss.zk.ui.sys.SessionCtrl;
import org.zkoss.zk.ui.util.DesktopCleanup; import org.zkoss.zk.ui.util.DesktopCleanup;
import org.zkoss.zk.ui.util.DesktopInit; import org.zkoss.zk.ui.util.DesktopInit;
import org.zkoss.zk.ui.util.ExecutionCleanup; import org.zkoss.zk.ui.util.ExecutionCleanup;
@ -120,6 +126,8 @@ public class SessionContextListener implements ExecutionInit,
//set locale //set locale
Locales.setThreadLocal(Env.getLanguage(ServerContext.getCurrentInstance()).getLocale()); Locales.setThreadLocal(Env.getLanguage(ServerContext.getCurrentInstance()).getLocale());
} }
Properties ctx = ServerContext.getCurrentInstance();
ctx.put(AdempiereWebUI.ZK_DESKTOP_SESSION_KEY, new WeakReference<Desktop>(exec.getDesktop()));
} }
} }
@ -336,10 +344,12 @@ public class SessionContextListener implements ExecutionInit,
} }
int AD_Session_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Session_ID"); int AD_Session_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Session_ID");
if (AD_Session_ID > 0) { if (AD_Session_ID > 0) {
String key = "ad_session."+AD_Session_ID+".desktop"; String key = getSessionDesktopListKey(AD_Session_ID);
String dtid = (String) Env.getCtx().get(key); @SuppressWarnings("unchecked")
if (dtid != null) { List<String> list = (List<String>) Env.getCtx().get(key);
if (!dtid.equals(desktop.getId())) { if (list != null) {
list.remove(desktop.getId());
if (!isEmpty(list, desktop.getSession())) {
return; return;
} else { } else {
Env.getCtx().remove(key); Env.getCtx().remove(key);
@ -356,6 +366,38 @@ public class SessionContextListener implements ExecutionInit,
} }
} }
private boolean isEmpty(List<String> list, Session session) {
if (list.isEmpty())
return true;
if (session == null)
return false;
DesktopCache desktopCache = ((SessionCtrl)session).getDesktopCache();
if (desktopCache == null)
return false;
int count = 0;
for(String dtid : list) {
Desktop desktop = desktopCache.getDesktopIfAny(dtid);
if (desktop == null) continue;
if (desktop.getFirstPage() == null) continue;
Collection<Component> roots = desktop.getFirstPage().getRoots();
if (roots == null || roots.isEmpty()) continue;
boolean found = false;
for (Component root : roots) {
if (root instanceof AdempiereWebUI) {
found = true;
break;
}
}
if (!found) continue;
count++;
}
return count == 0;
}
@Override @Override
public void init(Desktop desktop, Object request) throws Exception { public void init(Desktop desktop, Object request) throws Exception {
if(Executions.getCurrent()==null) if(Executions.getCurrent()==null)
@ -371,7 +413,32 @@ public class SessionContextListener implements ExecutionInit,
mSession.setProcessed(false); mSession.setProcessed(false);
mSession.saveEx(); mSession.saveEx();
} }
Env.getCtx().put("ad_session."+mSession.getAD_Session_ID()+".desktop", desktop.getId()); addDesktopId(mSession.getAD_Session_ID(), desktop.getId());
} }
} }
public static void addDesktopId(int AD_Session_ID, String dtid)
{
String key = getSessionDesktopListKey(AD_Session_ID);
@SuppressWarnings("unchecked")
List<String> list = (List<String>) Env.getCtx().get(key);
if (list == null) {
list = new ArrayList<String>();
Env.getCtx().put(key, list);
}
if (!list.contains(dtid))
{
list.add(dtid);
}
}
/**
* @param AD_Session_ID
* @return desktop list key
*/
public static String getSessionDesktopListKey(int AD_Session_ID)
{
String key = "ad_session."+AD_Session_ID+".desktop";
return key;
}
} }

View File

@ -20,15 +20,12 @@ package org.adempiere.webui.session;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Properties; import java.util.Properties;
import org.adempiere.webui.AdempiereWebUI;
import org.adempiere.webui.IWebClient; import org.adempiere.webui.IWebClient;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.desktop.IDesktop; import org.adempiere.webui.desktop.IDesktop;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Session;
/** /**
* *
@ -51,28 +48,11 @@ public class SessionManager
&& !"".equals(adClientId) && !"".equals(adOrgId)); && !"".equals(adClientId) && !"".equals(adOrgId));
} }
private static Session getSession()
{
Execution execution = Executions.getCurrent();
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;
}
public static void setSessionApplication(IWebClient app) public static void setSessionApplication(IWebClient app)
{ {
Session session = getSession(); Desktop desktop = AEnv.getDesktop();
if (session != null) if (desktop != null)
session.setAttribute(SESSION_APPLICATION, new WeakReference<IWebClient>(app)); desktop.setAttribute(SESSION_APPLICATION, new WeakReference<IWebClient>(app));
} }
public static IDesktop getAppDesktop() public static IDesktop getAppDesktop()
@ -83,12 +63,12 @@ public class SessionManager
public static IWebClient getSessionApplication() public static IWebClient getSessionApplication()
{ {
Session session = getSession(); Desktop desktop = AEnv.getDesktop();
IWebClient app = null; IWebClient app = null;
if (session != null) if (desktop != null)
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
WeakReference<IWebClient> wref = (WeakReference<IWebClient>) session.getAttribute(SESSION_APPLICATION); WeakReference<IWebClient> wref = (WeakReference<IWebClient>) desktop.getAttribute(SESSION_APPLICATION);
app = wref != null ? wref.get() : null; app = wref != null ? wref.get() : null;
} }
return app; return app;