Search in sources :

Example 6 with Language

use of org.compiere.util.Language in project adempiere by adempiere.

the class WAcctViewerData method getButtonText.

// fillOrg
/**
	 *  Get Button Text
	 *
	 *  @param tableName table
	 *  @param columnName column
	 *  @param selectSQL sql
	 *  @return Text on button
	 */
protected String getButtonText(String tableName, String columnName, String selectSQL) {
    //  SELECT (<embedded>) FROM tableName avd WHERE avd.<selectSQL>
    StringBuffer sql = new StringBuffer("SELECT (");
    Language language = Env.getLanguage(Env.getCtx());
    sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd")).append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL);
    String retValue = "<" + selectSQL + ">";
    try {
        Statement stmt = DB.createStatement();
        ResultSet rs = stmt.executeQuery(sql.toString());
        if (rs.next())
            retValue = rs.getString(1);
        rs.close();
        stmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql.toString(), e);
    }
    return retValue;
}
Also used : Language(org.compiere.util.Language) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet)

Example 7 with Language

use of org.compiere.util.Language in project adempiere by adempiere.

the class AEnv method getLanguage.

//	getHeader
/**
	 * @param ctx
	 * @return Language
	 */
public static Language getLanguage(Properties ctx) {
    Locale locale = getLocale(ctx);
    Language language = Env.getLanguage(ctx);
    if (!language.getLocale().equals(locale)) {
        Language tmp = Language.getLanguage(locale.toString());
        String adLanguage = language.getAD_Language();
        language = new Language(tmp.getName(), adLanguage, tmp.getLocale(), tmp.isDecimalPoint(), tmp.getDateFormat().toPattern(), tmp.getMediaSize());
    }
    return language;
}
Also used : Locale(java.util.Locale) Language(org.compiere.util.Language)

Example 8 with Language

use of org.compiere.util.Language 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 9 with Language

use of org.compiere.util.Language in project adempiere by adempiere.

the class ReportEngineEx method createEXCEL_HTML.

/**************************************************************************
	 * 	Create EXCEL HTML File
	 * 	@param file file
	 *  @param onlyTable if false create complete HTML document
	 *  @param language optional language - if null the default language is used to format nubers/dates
	 * 	@return true if success
	 */
public static boolean createEXCEL_HTML(ReportEngine re, Properties m_ctx, File file, boolean onlyTable, Language language) {
    try {
        Language lang = language;
        if (lang == null)
            lang = Language.getLoginLanguage();
        FileWriter fw = new FileWriter(file, false);
        return createEXCEL_HTML(re, m_ctx, new BufferedWriter(fw), onlyTable, lang);
    } catch (FileNotFoundException fnfe) {
        log.log(Level.SEVERE, "(f) - " + fnfe.toString());
    } catch (Exception e) {
        log.log(Level.SEVERE, "(f)", e);
    }
    return false;
}
Also used : Language(org.compiere.util.Language) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) BufferedWriter(java.io.BufferedWriter)

Example 10 with Language

use of org.compiere.util.Language in project adempiere by adempiere.

the class CompiereService method connect.

public void connect() {
    CompiereUtil.initWeb();
    Env.setCtx(m_ctx);
    Env.setContext(m_ctx, "#AD_Language", "en_US");
    m_lang = Language.getLanguage("en_US");
    // These variables are needed for ADClient.exe
    Language m_lang2 = Language.getLanguage("pl_PL");
    //dateFormat = DisplayType.getDateFormat(DisplayType.Date, m_lang2);
    //dateTimeFormat = DisplayType.getDateFormat(DisplayType.DateTime, m_lang2);
    dateFormat = new SimpleDateFormat(datePattern);
    dateTimeFormat = new SimpleDateFormat(datePattern);
    //dateTimeFormat = DisplayType.getDateFormat(DisplayType.DateTime, m_lang2);
    //
    amountFormat = DisplayType.getNumberFormat(DisplayType.Amount, m_lang2);
    integerFormat = DisplayType.getNumberFormat(DisplayType.Integer, m_lang2);
    numberFormat = DisplayType.getNumberFormat(DisplayType.Number, m_lang2);
    quantityFormat = DisplayType.getNumberFormat(DisplayType.Quantity, m_lang2);
}
Also used : Language(org.compiere.util.Language) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Language (org.compiere.util.Language)43 SQLException (java.sql.SQLException)11 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 Locale (java.util.Locale)8 MLookup (org.compiere.model.MLookup)7 Properties (java.util.Properties)6 PrintInfo (org.compiere.model.PrintInfo)6 MPrintFormat (org.compiere.print.MPrintFormat)5 IOException (java.io.IOException)4 Timestamp (java.sql.Timestamp)4 ArrayList (java.util.ArrayList)4 VLookup (org.compiere.grid.ed.VLookup)4 MQuery (org.compiere.model.MQuery)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 JRException (net.sf.jasperreports.engine.JRException)3 MUser (org.compiere.model.MUser)3 ReportEngine (org.compiere.print.ReportEngine)3 PrinterJob (java.awt.print.PrinterJob)2