use of org.zkoss.zk.ui.Execution in project adempiere by adempiere.
the class AdempiereWebUI method loginCompleted.
/* (non-Javadoc)
* @see org.adempiere.webui.IWebClient#loginCompleted()
*/
public void loginCompleted() {
Properties ctx = Env.getCtx();
// to reload preferences when the user refresh the browser
userPreference = loadUserPreference(Env.getAD_User_ID(ctx));
// Set the theme according to the user preferences. If the theme changes, the page will
// be reloaded again - so do this first thing.
int theme_id = userPreference.getPropertyAsInt(UserPreference.P_ZK_THEME_PREFERENCE);
if (theme_id > 0) {
// If theme_id == 0, don't bother setting a new MTheme. Just use the current theme.
MTheme theme = MTheme.get(ctx, theme_id);
if (ThemeUtils.makeCurrent(theme)) {
// Make the theme active and reload the page.
return;
}
}
ThemeUtils.addBrowserIconAndTitle(this.getPage());
if (loginDesktop != null) {
loginDesktop.detach();
loginDesktop = null;
}
String langLogin = Env.getContext(ctx, Env.LANGUAGE);
if (langLogin == null || langLogin.length() <= 0) {
langLogin = langSession;
Env.setContext(ctx, Env.LANGUAGE, langSession);
}
// Validate language
Language language = Language.getLanguage(langLogin);
String locale = Env.getContext(ctx, AEnv.LOCALE);
if (locale != null && locale.length() > 0 && !language.getLocale().toString().equals(locale)) {
String adLanguage = language.getAD_Language();
Language tmp = Language.getLanguage(locale);
language = new Language(tmp.getName(), adLanguage, tmp.getLocale(), tmp.isDecimalPoint(), tmp.getDateFormat().toPattern(), tmp.getMediaSize());
} else {
Language tmp = language;
language = new Language(tmp.getName(), tmp.getAD_Language(), tmp.getLocale(), tmp.isDecimalPoint(), tmp.getDateFormat().toPattern(), tmp.getMediaSize());
}
Env.verifyLanguage(ctx, language);
//Bug
Env.setContext(ctx, Env.LANGUAGE, language.getAD_Language());
// Create adempiere Session - user id in ctx
Execution exec = Executions.getCurrent();
Session currSess = exec.getDesktop().getSession();
HttpSession httpSess = (HttpSession) currSess.getNativeSession();
MSession mSession = MSession.get(ctx, exec.getRemoteAddr(), exec.getRemoteHost(), httpSess.getId());
//enable full interface, relook into this when doing preference
Env.setContext(ctx, "#ShowTrl", true);
Env.setContext(ctx, "#ShowAcct", MRole.getDefault().isShowAcct());
Env.setContext(ctx, "#ShowAdvanced", true);
//auto commit user preference
String autoCommit = userPreference.getProperty(UserPreference.P_AUTO_COMMIT);
Env.setAutoCommit(ctx, "true".equalsIgnoreCase(autoCommit) || "y".equalsIgnoreCase(autoCommit));
//auto new user preference
String autoNew = userPreference.getProperty(UserPreference.P_AUTO_NEW);
Env.setAutoNew(ctx, "true".equalsIgnoreCase(autoNew) || "y".equalsIgnoreCase(autoNew));
IDesktop d = (IDesktop) currSess.getAttribute("application.desktop");
if (d != null && d instanceof IDesktop) {
ExecutionCarryOver eco = (ExecutionCarryOver) currSess.getAttribute(EXECUTION_CARRYOVER_SESSION_KEY);
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();
Collection<?> collection = page.getRoots();
Object[] objects = new Object[0];
objects = collection.toArray(objects);
for (Object obj : objects) {
if (obj instanceof Component) {
((Component) obj).detach();
rootComponents.add((Component) obj);
}
}
appDesktop.getComponent().detach();
DesktopCache desktopCache = ((SessionCtrl) currSess).getDesktopCache();
if (desktopCache != null)
desktopCache.removeDesktop(Executions.getCurrent().getDesktop());
} catch (Exception e) {
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());
currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, current);
}
currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
} catch (Throwable t) {
//restore fail
appDesktop = null;
}
}
}
if (appDesktop == null) {
//create new desktop
createDesktop();
appDesktop.setClientInfo(clientInfo);
appDesktop.createPart(this.getPage());
currSess.setAttribute("application.desktop", appDesktop);
ExecutionCarryOver eco = new ExecutionCarryOver(this.getPage().getDesktop());
currSess.setAttribute(EXECUTION_CARRYOVER_SESSION_KEY, eco);
currSess.setAttribute(ZK_DESKTOP_SESSION_KEY, this.getPage().getDesktop());
}
if ("Y".equalsIgnoreCase(Env.getContext(ctx, BrowserToken.REMEMBER_ME)) && MSystem.isZKRememberUserAllowed()) {
MUser user = MUser.get(ctx);
BrowserToken.save(mSession, user);
} else {
BrowserToken.remove();
}
}
use of org.zkoss.zk.ui.Execution in project adempiere by adempiere.
the class ThemeUtils method setSystemDefaultTheme.
/**
* Set the current theme to the system default theme.
* @return True if a redirect has been requested. Use this to stop loading during page setup.
*/
public static boolean setSystemDefaultTheme() {
// Set the system default theme. This will fall back to defaults
// if the MTheme has no default themes.
DefaultTheme dt = new DefaultTheme();
Execution exec = Executions.getCurrent();
String themeName = dt.get_themeName();
String currentTheme = Themes.getCurrentTheme();
if (currentTheme.equals(themeName)) {
// No need to do anything
return false;
}
Themes.setTheme(exec, themeName);
// reload the current page
Executions.sendRedirect(null);
return true;
}
use of org.zkoss.zk.ui.Execution in project collect by openforis.
the class ComponentUtil method getCurrentComponent.
/**
* Returns the component handled by the current {@link Execution} object
* @return
*/
public static Component getCurrentComponent() {
Execution execution = Executions.getCurrent();
ExecutionResolver variableResolver = (ExecutionResolver) execution.getVariableResolver();
Object self = variableResolver.getSelf();
Component component = (Component) self;
return component;
}
use of org.zkoss.zk.ui.Execution in project adempiere by adempiere.
the class ThemeUtils method makeCurrent.
/**
* Make this theme the current theme. Only applies to ZK
* @return - true if a redirect/reload has been requested. Use this to stop loading
* other elements of the page during setup.
*/
public static boolean makeCurrent(MTheme theme) {
if (theme == null) {
return false;
}
Execution exec = Executions.getCurrent();
String themeName = "";
if (theme.get_ID() <= 0) {
// No theme was identified, use the default
DefaultTheme dt = new DefaultTheme();
themeName = dt.get_themeName();
} else {
themeName = theme.get_themeName();
}
String currentTheme = Themes.getCurrentTheme();
if (!currentTheme.equals(themeName)) {
Themes.setTheme(exec, themeName);
// reload the current page
Executions.sendRedirect(null);
return true;
}
return false;
}
use of org.zkoss.zk.ui.Execution in project adempiere by adempiere.
the class AEnv method isFirefox2.
// getImageIcon
/**
*
* @return boolean
*/
public static boolean isFirefox2() {
Execution execution = Executions.getCurrent();
if (execution == null)
return false;
Object n = execution.getNativeRequest();
if (n instanceof ServletRequest) {
String userAgent = Servlets.getUserAgent((ServletRequest) n);
return userAgent.indexOf("Firefox/2") >= 0;
} else {
return false;
}
}
Aggregations