Search in sources :

Example 31 with Language

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

the class MPrintFormatItem method createFromColumn.

//	getColumnName
/**************************************************************************
	 * 	Create Print Format Item from Column
	 *  @param format parent
	 * 	@param AD_Column_ID column
	 *  @param seqNo sequence of display if 0 it is not printed
	 * 	@return Print Format Item
	 */
public static MPrintFormatItem createFromColumn(MPrintFormat format, int AD_Column_ID, int seqNo) {
    MPrintFormatItem pfi = new MPrintFormatItem(format.getCtx(), 0, format.get_TrxName());
    pfi.setAD_PrintFormat_ID(format.getAD_PrintFormat_ID());
    pfi.setClientOrg(format);
    pfi.setAD_Column_ID(AD_Column_ID);
    pfi.setPrintFormatType(PRINTFORMATTYPE_Field);
    //	translation is done by trigger
    String sql = //	1..3
    "SELECT c.ColumnName,e.Name,e.PrintName, " + //	4..6
    "c.AD_Reference_ID,c.IsKey,c.SeqNo " + "FROM AD_Column c, AD_Element e " + "WHERE c.AD_Column_ID=?" + " AND c.AD_Element_ID=e.AD_Element_ID";
    //	translate base entry if single language - trigger copies to trl tables
    Language language = format.getLanguage();
    boolean trl = !Env.isMultiLingualDocument(format.getCtx()) && !language.isBaseLanguage();
    if (trl)
        sql = //	1..3
        "SELECT c.ColumnName,e.Name,e.PrintName, " + //	4..6
        "c.AD_Reference_ID,c.IsKey,c.SeqNo " + "FROM AD_Column c, AD_Element_Trl e " + "WHERE c.AD_Column_ID=?" + " AND c.AD_Element_ID=e.AD_Element_ID" + " AND e.AD_Language=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, format.get_TrxName());
        pstmt.setInt(1, AD_Column_ID);
        if (trl)
            pstmt.setString(2, language.getAD_Language());
        rs = pstmt.executeQuery();
        if (rs.next()) {
            String ColumnName = rs.getString(1);
            pfi.setName(rs.getString(2));
            pfi.setPrintName(rs.getString(3));
            int displayType = rs.getInt(4);
            if (DisplayType.isNumeric(displayType))
                pfi.setFieldAlignmentType(FIELDALIGNMENTTYPE_TrailingRight);
            else if (displayType == DisplayType.Text || displayType == DisplayType.Memo)
                pfi.setFieldAlignmentType(FIELDALIGNMENTTYPE_Block);
            else
                pfi.setFieldAlignmentType(FIELDALIGNMENTTYPE_LeadingLeft);
            boolean isKey = "Y".equals(rs.getString(5));
            //
            if (isKey || ColumnName.startsWith("Created") || ColumnName.startsWith("Updated") || ColumnName.equals("AD_Client_ID") || ColumnName.equals("AD_Org_ID") || ColumnName.equals("IsActive") || displayType == DisplayType.Button || displayType == DisplayType.Binary || displayType == DisplayType.ID || displayType == DisplayType.Image || displayType == DisplayType.RowID || seqNo == 0) {
                pfi.setIsPrinted(false);
                pfi.setSeqNo(0);
            } else {
                pfi.setIsPrinted(true);
                pfi.setSeqNo(seqNo);
            }
            //	IsIdentifier SortNo
            int idSeqNo = rs.getInt(6);
            if (idSeqNo > 0) {
                pfi.setIsOrderBy(true);
                pfi.setSortNo(idSeqNo);
            }
        } else
            s_log.log(Level.SEVERE, "Not Found AD_Column_ID=" + AD_Column_ID + " Trl=" + trl + " " + language.getAD_Language());
    } catch (SQLException e) {
        s_log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    if (!pfi.save())
        return null;
    //	pfi.dump();
    return pfi;
}
Also used : Language(org.compiere.util.Language) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 32 with Language

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

the class AcctViewerData 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 33 with Language

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

the class VSortTab method getIdentifier.

//	dynInit
/**
	 * get Identifier
	 * @param tableName
	 * @param columnName
	 * @param AD_Column_ID
	 * @param isTranslated
	 * @return Sql
	 */
private String getIdentifier(String tableName, String columnName, Integer AD_Column_ID, boolean isTranslated) {
    Language language = Language.getLanguage(Env.getAD_Language(Env.getCtx()));
    StringBuilder sql = new StringBuilder("");
    MColumn column = MColumn.get(Env.getCtx(), AD_Column_ID);
    if (DisplayType.TableDir == column.getAD_Reference_ID() || DisplayType.Search == column.getAD_Reference_ID())
        sql.append("(").append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "t")).append(")");
    else if (DisplayType.Table == column.getAD_Reference_ID())
        sql.append("(").append(MLookupFactory.getLookup_TableEmbed(language, column.getColumnName(), "t", column.getAD_Reference_Value_ID())).append(")");
    else if (DisplayType.List == column.getAD_Reference_ID())
        sql.append("(").append(MLookupFactory.getLookup_ListEmbed(language, column.getAD_Reference_Value_ID(), columnName)).append(")");
    else
        sql.append(isTranslated ? "tt." : "t.").append(columnName);
    return sql.toString();
}
Also used : MColumn(org.compiere.model.MColumn) Language(org.compiere.util.Language)

Example 34 with Language

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

the class WLogin method createFirstPage.

//  checkLogin
/**************************************************************************
	 *  First Login Page
	 *  @param cProp Login Cookie information for defaults
	 *  @param request request
	 *  @param errorMessage error message
	 *  @return WDoc page
	 */
private MobileDoc createFirstPage(Properties cProp, HttpServletRequest request, String errorMessage) {
    log.info(" - " + errorMessage);
    String AD_Language = (cProp.getProperty(Env.LANGUAGE, Language.getAD_Language(request.getLocale())));
    //
    String windowTitle = Msg.getMsg(AD_Language, "Login");
    String usrText = Msg.getMsg(AD_Language, "User");
    String pwdText = Msg.getMsg(AD_Language, "Password");
    String lngText = Msg.translate(AD_Language, "AD_Language");
    //	Form - post to same URL
    String action = request.getRequestURI();
    form myForm = null;
    myForm = new form(action).setName("Login1");
    myForm.setID(windowTitle);
    myForm.setTitle(windowTitle);
    myForm.addAttribute("selected", "true");
    myForm.setClass("panel");
    myForm.setMethod("post");
    myForm.addAttribute("autocomplete", "off");
    fieldset fs = new fieldset();
    div div1 = new div();
    div1.setClass("row");
    //	Username
    String userData = cProp.getProperty(P_USERNAME, "");
    label usrLabel = new label().setFor(P_USERNAME + "F").addElement(usrText);
    usrLabel.setID(P_USERNAME + "L");
    div1.addElement(usrLabel);
    input usr = new input(input.TYPE_TEXT, P_USERNAME, userData).setSize(20).setMaxlength(30);
    usr.setID(P_USERNAME + "F");
    div1.addElement(usr);
    fs.addElement(div1);
    div1 = new div();
    div1.setClass("row");
    //  Password
    String pwdData = cProp.getProperty(P_PASSWORD, "");
    label pwdLabel = new label().setFor(P_PASSWORD + "F").addElement(pwdText);
    pwdLabel.setID(P_PASSWORD + "L");
    div1.addElement(pwdLabel);
    input pwd = new input(input.TYPE_PASSWORD, P_PASSWORD, pwdData).setSize(20).setMaxlength(30);
    pwd.setID(P_PASSWORD + "F");
    div1.addElement(pwd);
    fs.addElement(div1);
    div1 = new div();
    div1.setClass("row");
    //	Language Pick
    label langLabel = new label().setFor(Env.LANGUAGE + "F").addElement(lngText);
    langLabel.setID(Env.LANGUAGE + "L");
    div1.addElement(langLabel);
    option[] options = new option[Language.getLanguageCount()];
    for (int i = 0; i < Language.getLanguageCount(); i++) {
        Language language = Language.getLanguage(i);
        options[i] = new option(language.getAD_Language()).addElement(Util.maskHTML(language.getName()));
        if (language.getAD_Language().equals(AD_Language))
            options[i].setSelected(true);
        else
            options[i].setSelected(false);
    }
    div1.addElement(new select(Env.LANGUAGE, options).setID(Env.LANGUAGE + "F"));
    fs.addElement(div1);
    div1 = new div();
    div1.setClass("row");
    //  ErrorMessage
    if (errorMessage != null && errorMessage.length() > 0) {
        div1 = new div();
        div1.setClass("row");
        //  color, size
        div1.addElement(new font(HtmlColor.red, 4).addElement(new b(errorMessage)));
        fs.addElement(div1);
    }
    myForm.addElement(fs);
    //<a class="whiteButton" type="submit" href="#">Login</a>
    //  Finish
    a button = new a("#", windowTitle);
    button.addAttribute("type", "submit");
    button.setClass("whiteButton");
    //
    myForm.addElement(button);
    //  Document
    MobileDoc doc = MobileDoc.createWindow(windowTitle);
    div div = new div();
    div.setClass("toolbar");
    h1 header = new h1();
    header.setID("pageTitle");
    div.addElement(header);
    a anchor = new a();
    anchor.setID("backButton");
    anchor.setClass("button");
    div.addElement(anchor);
    doc.getBody().addElement(myForm).addElement(div).setTitle(windowTitle);
    doc.getHead().addElement(new script((Element) null, MobileEnv.getBaseDirectory("/js/login.js")));
    return doc;
}
Also used : org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) org.apache.ecs.xhtml.meta(org.apache.ecs.xhtml.meta) org.apache.ecs.xhtml.b(org.apache.ecs.xhtml.b) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) Element(org.apache.ecs.Element) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) org.apache.ecs.xhtml.label(org.apache.ecs.xhtml.label) org.apache.ecs.xhtml.script(org.apache.ecs.xhtml.script) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) Language(org.compiere.util.Language) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option) org.apache.ecs.xhtml.font(org.apache.ecs.xhtml.font)

Example 35 with Language

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

the class MobileSessionCtx method setLanguage.

//	getDefaults
/**************************************************************************
	 *  Set Language from request or session in.
	 *  - Properties
	 *  - Cookie
	 *  - Session
	 *  @param request request
	 */
private void setLanguage(HttpServletRequest request) {
    //  Get Cookie
    Properties cProp = MobileUtil.getCookieProprties(request);
    //red1 Get Environment Ctx first
    String AD_Language = Env.getAD_Language(ctx);
    //  Get/set Parameter:      Language
    String mobileLanguage = MobileUtil.getParameter(request, Env.LANGUAGE);
    if (mobileLanguage != null)
        AD_Language = mobileLanguage;
    if (AD_Language == null) {
        //  Check Cookie
        AD_Language = cProp.getProperty(Env.LANGUAGE);
        if (AD_Language == null) {
            //  Check Request Locale
            Locale locale = request.getLocale();
            AD_Language = Language.getAD_Language(locale);
        }
    }
    if (AD_Language != null) {
        Language lang = Language.getLanguage(AD_Language);
        Env.verifyLanguage(ctx, lang);
        Env.setContext(ctx, Env.LANGUAGE, lang.getAD_Language());
        Msg.getMsg(ctx, "0");
        cProp.setProperty(Env.LANGUAGE, lang.getAD_Language());
        setLanguage(lang);
    } else if (//	set base language
    language == null)
        setLanguage(Language.getBaseLanguage());
}
Also used : Locale(java.util.Locale) Language(org.compiere.util.Language) Properties(java.util.Properties)

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