Search in sources :

Example 1 with UiException

use of org.zkoss.zk.ui.UiException 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();
    }
}
Also used : ArrayList(java.util.ArrayList) MTheme(org.compiere.model.MTheme) MSession(org.compiere.model.MSession) Page(org.zkoss.zk.ui.Page) SessionCtrl(org.zkoss.zk.ui.sys.SessionCtrl) Properties(java.util.Properties) ExecutionCtrl(org.zkoss.zk.ui.sys.ExecutionCtrl) Execution(org.zkoss.zk.ui.Execution) Language(org.compiere.util.Language) DesktopCtrl(org.zkoss.zk.ui.sys.DesktopCtrl) Component(org.zkoss.zk.ui.Component) MUser(org.compiere.model.MUser) HttpSession(javax.servlet.http.HttpSession) UiException(org.zkoss.zk.ui.UiException) IDesktop(org.adempiere.webui.desktop.IDesktop) UiException(org.zkoss.zk.ui.UiException) ExecutionCarryOver(org.zkoss.zk.ui.impl.ExecutionCarryOver) Visualizer(org.zkoss.zk.ui.sys.Visualizer) DesktopCache(org.zkoss.zk.ui.sys.DesktopCache) MSession(org.compiere.model.MSession) HttpSession(javax.servlet.http.HttpSession) Session(org.zkoss.zk.ui.Session)

Example 2 with UiException

use of org.zkoss.zk.ui.UiException in project adempiere by adempiere.

the class Group method autoFirstCell.

private GroupHeader autoFirstCell() {
    Component cell = getFirstChild();
    if (cell == null || cell instanceof GroupHeader) {
        if (cell == null)
            cell = new GroupHeader();
        cell.applyProperties();
        cell.setParent(this);
        return (GroupHeader) cell;
    }
    throw new UiException("Unsupported child for setLabel: " + cell);
}
Also used : UiException(org.zkoss.zk.ui.UiException) Component(org.zkoss.zk.ui.Component)

Example 3 with UiException

use of org.zkoss.zk.ui.UiException in project adempiere by adempiere.

the class DrillCommand method service.

public boolean service(AuRequest request, boolean everError) {
    if (!DrillEvent.ON_DRILL_ACROSS.equals(request.getCommand()) && !DrillEvent.ON_DRILL_DOWN.equals(request.getCommand()))
        return false;
    final Map<?, ?> map = request.getData();
    JSONArray data = (JSONArray) map.get("data");
    final Component comp = request.getComponent();
    if (comp == null)
        throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
    if (data == null || data.size() < 2)
        throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] { Objects.toString(data), this });
    String columnName = (String) data.get(0);
    String tableName = MQuery.getZoomTableName(columnName);
    String code = (String) data.get(1);
    //
    MQuery query = new MQuery(tableName);
    query.addRestriction(columnName, MQuery.EQUAL, code);
    Events.postEvent(new DrillEvent(request.getCommand(), comp, query));
    return true;
}
Also used : JSONArray(org.zkoss.json.JSONArray) DrillEvent(org.adempiere.webui.event.DrillEvent) MQuery(org.compiere.model.MQuery) UiException(org.zkoss.zk.ui.UiException) Component(org.zkoss.zk.ui.Component)

Example 4 with UiException

use of org.zkoss.zk.ui.UiException in project adempiere by adempiere.

the class ZoomCommand method service.

public boolean service(AuRequest request, boolean everError) {
    if (!ZoomEvent.EVENT_NAME.equals(request.getCommand()))
        return false;
    Map<?, ?> map = request.getData();
    JSONArray data = (JSONArray) map.get("data");
    final Component comp = request.getComponent();
    if (comp == null)
        throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
    if (data == null || data.size() < 2)
        throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] { Objects.toString(data), this });
    String columnName = (String) data.get(0);
    String tableName = MQuery.getZoomTableName(columnName);
    Object code = null;
    if (columnName.endsWith("_ID")) {
        try {
            code = Integer.parseInt((String) data.get(1));
        } catch (Exception e) {
            code = data.get(1);
        }
    } else {
        code = data.get(1);
    }
    //
    MQuery query = new MQuery(tableName);
    query.addRestriction(columnName, MQuery.EQUAL, code);
    query.setRecordCount(1);
    Events.postEvent(new ZoomEvent(comp, query));
    return true;
}
Also used : JSONArray(org.zkoss.json.JSONArray) MQuery(org.compiere.model.MQuery) UiException(org.zkoss.zk.ui.UiException) Component(org.zkoss.zk.ui.Component) UiException(org.zkoss.zk.ui.UiException) ZoomEvent(org.adempiere.webui.event.ZoomEvent)

Example 5 with UiException

use of org.zkoss.zk.ui.UiException in project adempiere by adempiere.

the class WLogin method doCreatePart.

protected Component doCreatePart(Component parent) {
    layout = new Borderlayout();
    if (parent != null)
        layout.setParent(parent);
    else
        layout.setPage(page);
    ThemeUtils.addSclass("ad-wlogin-layout", layout);
    Center center = new Center();
    center.setParent(layout);
    center.setHflex("true");
    center.setVflex("true");
    center.setAutoscroll(true);
    ThemeUtils.addSclass("ad-wlogin-layout-center", center);
    Vbox vb = new Vbox();
    vb.setParent(center);
    vb.setPack("center");
    vb.setAlign("center");
    vb.setWidth("100%");
    vb.setHeight("100%");
    LoginWindow loginWindow = new LoginWindow(app);
    loginWindow.setParent(vb);
    if (!AEnv.isBrowserSupported()) {
        //TODO: localization
        String msg = "You might experience slow performance and user interface anomalies using your current browser to access the application. We recommend the use of Firefox, Google Chrome or Apple Safari.";
        browserWarningWindow = new Window();
        ThemeUtils.addSclass("ad-wlogin-browser-not-supported", browserWarningWindow);
        Div div = new Div();
        div.appendChild(new Text(msg));
        browserWarningWindow.setPosition("top,right");
        browserWarningWindow.appendChild(div);
        browserWarningWindow.setPage(page);
        browserWarningWindow.doOverlapped();
    }
    try {
        String right = ThemeUtils.getLoginRightPanel();
        PageDefinition pageDefintion = Executions.getCurrent().getPageDefinition(right);
        East east = new East();
        ThemeUtils.addSclass("ad-wlogin-east-panel", east);
        addContent(east, pageDefintion);
    } catch (Exception e) {
        //ignore page not found exception
        if (e instanceof UiException) {
            if (!(e.getMessage() != null && e.getMessage().startsWith("Page not found"))) {
                e.printStackTrace();
            }
        } else {
            e.printStackTrace();
        }
    }
    try {
        String left = ThemeUtils.getLoginLeftPanel();
        PageDefinition pageDefintion = Executions.getCurrent().getPageDefinition(left);
        West west = new West();
        ThemeUtils.addSclass("ad-wlogin-west-panel", west);
        addContent(west, pageDefintion);
    } catch (Exception e) {
        //ignore page not found exception
        if (e instanceof UiException) {
            if (!(e.getMessage() != null && e.getMessage().startsWith("Page not found"))) {
                e.printStackTrace();
            }
        } else {
            e.printStackTrace();
        }
    }
    try {
        String top = ThemeUtils.getLoginTopPanel();
        PageDefinition pageDefintion = Executions.getCurrent().getPageDefinition(top);
        North north = new North();
        ThemeUtils.addSclass("ad-wlogin-north-panel", north);
        addContent(north, pageDefintion);
    } catch (Exception e) {
        //ignore page not found exception
        if (e instanceof UiException) {
            if (!(e.getMessage() != null && e.getMessage().startsWith("Page not found"))) {
                e.printStackTrace();
            }
        } else {
            e.printStackTrace();
        }
    }
    try {
        String bottom = ThemeUtils.getLoginBottomPanel();
        PageDefinition pageDefintion = Executions.getCurrent().getPageDefinition(bottom);
        South south = new South();
        ThemeUtils.addSclass("ad-wlogin-south-panel", south);
        addContent(south, pageDefintion);
    } catch (Exception e) {
        //ignore page not found exception
        if (e instanceof UiException) {
            if (!(e.getMessage() != null && e.getMessage().startsWith("Page not found"))) {
                e.printStackTrace();
            }
        } else {
            e.printStackTrace();
        }
    }
    return layout;
}
Also used : LoginWindow(org.adempiere.webui.window.LoginWindow) Window(org.zkoss.zul.Window) PageDefinition(org.zkoss.zk.ui.metainfo.PageDefinition) Center(org.zkoss.zul.Center) LoginWindow(org.adempiere.webui.window.LoginWindow) West(org.zkoss.zul.West) South(org.zkoss.zul.South) Text(org.zkoss.zhtml.Text) Borderlayout(org.zkoss.zul.Borderlayout) UiException(org.zkoss.zk.ui.UiException) UiException(org.zkoss.zk.ui.UiException) Div(org.zkoss.zul.Div) North(org.zkoss.zul.North) Vbox(org.zkoss.zul.Vbox) East(org.zkoss.zul.East)

Aggregations

UiException (org.zkoss.zk.ui.UiException)6 Component (org.zkoss.zk.ui.Component)5 MQuery (org.compiere.model.MQuery)2 JSONArray (org.zkoss.json.JSONArray)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 HttpSession (javax.servlet.http.HttpSession)1 IDesktop (org.adempiere.webui.desktop.IDesktop)1 DrillEvent (org.adempiere.webui.event.DrillEvent)1 TokenEvent (org.adempiere.webui.event.TokenEvent)1 ZoomEvent (org.adempiere.webui.event.ZoomEvent)1 LoginWindow (org.adempiere.webui.window.LoginWindow)1 MSession (org.compiere.model.MSession)1 MTheme (org.compiere.model.MTheme)1 MUser (org.compiere.model.MUser)1 Language (org.compiere.util.Language)1 Text (org.zkoss.zhtml.Text)1 Execution (org.zkoss.zk.ui.Execution)1 Page (org.zkoss.zk.ui.Page)1 Session (org.zkoss.zk.ui.Session)1