Search in sources :

Example 36 with Language

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

the class VOrderDistributionReceipt method fillPicks.

//	jbInit
/**
	 *	Fill Picks.
	 *		Column_ID from C_Order
	 *  @throws Exception if Lookups cannot be initialized
	 */
private void fillPicks() throws Exception {
    Language language = Language.getLoginLanguage();
    MLookup orderL = MLookupFactory.get(Env.getCtx(), m_WindowNo, MColumn.getColumn_ID(MDDOrder.Table_Name, MDDOrder.COLUMNNAME_DD_Order_ID), DisplayType.Search, language, MDDOrder.COLUMNNAME_DD_Order_ID, 0, false, "DocStatus='CO' AND IsInTransit='Y'");
    fOrder = new VLookup(MDDOrder.COLUMNNAME_DD_Order_ID, true, false, true, orderL);
    lOrder.setText(Msg.translate(Env.getCtx(), MDDOrder.COLUMNNAME_DD_Order_ID));
    fOrder.addVetoableChangeListener(this);
    Timestamp today = new Timestamp(System.currentTimeMillis());
    m_MovementDate = today;
    fMovementDate.setValue(today);
    fMovementDate.addVetoableChangeListener(this);
}
Also used : Language(org.compiere.util.Language) MLookup(org.compiere.model.MLookup) VLookup(org.compiere.grid.ed.VLookup) Timestamp(java.sql.Timestamp)

Example 37 with Language

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

the class VOrderReceiptIssue method fillPicks.

// init
/**
	 * Fill Picks Column_ID from C_Order This is only run as part of the windows
	 * initialization process
	 * 
	 * @throws Exception
	 *             if Lookups cannot be initialized
	 */
private void fillPicks() throws Exception {
    Properties ctx = Env.getCtx();
    // Base Language
    Language language = Language.getLoginLanguage();
    MLookup orderL = MLookupFactory.get(ctx, m_WindowNo, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_PP_Order_ID), DisplayType.Search, language, "PP_Order_ID", 0, false, "PP_Order.DocStatus = '" + MPPOrder.DOCACTION_Complete + "'");
    orderField = new VLookup("PP_Order_ID", false, false, true, orderL);
    orderField.setBackground(AdempierePLAF.getInfoBackground());
    orderField.addVetoableChangeListener(this);
    MLookup resourceL = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_S_Resource_ID), DisplayType.TableDir);
    resourceField = new VLookup("S_Resource_ID", false, false, false, resourceL);
    MLookup warehouseL = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_Warehouse_ID), DisplayType.TableDir);
    warehouseField = new VLookup("M_Warehouse_ID", false, false, false, warehouseL);
    MLookup productL = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_Product_ID), DisplayType.TableDir);
    productField = new VLookup("M_Product_ID", false, false, false, productL);
    MLookup uomL = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_C_UOM_ID), DisplayType.TableDir);
    uomField = new VLookup("C_UOM_ID", false, false, false, uomL);
    MLookup uomorderL = MLookupFactory.get(ctx, m_WindowNo, 0, MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_C_UOM_ID), DisplayType.TableDir);
    uomorderField = new VLookup("C_UOM_ID", false, false, false, uomorderL);
    MLocatorLookup locatorL = new MLocatorLookup(ctx, m_WindowNo);
    locatorField = new VLocator("M_Locator_ID", true, false, true, locatorL, m_WindowNo);
    MPAttributeLookup attributeL = new MPAttributeLookup(ctx, m_WindowNo);
    attribute = new VPAttribute(false, false, true, m_WindowNo, attributeL, false);
    attribute.setValue(0);
    // Tab, Window
    int m_Window = MWindow.getWindow_ID("Manufacturing Order");
    GridFieldVO vo = GridFieldVO.createStdField(ctx, m_WindowNo, 0, m_Window, MTab.getTab_ID(m_Window, "Order"), false, false, false);
    // M_AttributeSetInstance_ID
    vo.AD_Column_ID = MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_AttributeSetInstance_ID);
    GridField field = new GridField(vo);
    attribute.setField(field);
    // 4Layers - Further init
    scrapQtyField.setValue(Env.ZERO);
    rejectQty.setValue(Env.ZERO);
    // 4Layers - end
    pickcombo.addItem(new KeyNamePair(1, Msg.parseTranslation(Env.getCtx(), "@IsBackflush@")));
    pickcombo.addItem(new KeyNamePair(2, Msg.parseTranslation(Env.getCtx(), "@OnlyIssue@")));
    pickcombo.addItem(new KeyNamePair(3, Msg.parseTranslation(Env.getCtx(), "@OnlyReceiptProduct@")));
    pickcombo.addActionListener(this);
    Process.addActionListener(this);
    toDeliverQty.addActionListener(this);
    scrapQtyField.addActionListener(this);
}
Also used : MLocatorLookup(org.compiere.model.MLocatorLookup) VPAttribute(org.compiere.grid.ed.VPAttribute) Language(org.compiere.util.Language) GridFieldVO(org.compiere.model.GridFieldVO) MLookup(org.compiere.model.MLookup) VLookup(org.compiere.grid.ed.VLookup) VLocator(org.compiere.grid.ed.VLocator) GridField(org.compiere.model.GridField) KeyNamePair(org.compiere.util.KeyNamePair) Properties(java.util.Properties) MPAttributeLookup(org.compiere.model.MPAttributeLookup)

Example 38 with Language

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

the class ADSortTab 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 39 with Language

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

the class ReportStarter method startProcess.

/**
	 *  Start the process.
	 *  Called then pressing the Process button in R_Request.
	 *  It should only return false, if the function could not be performed
	 *  as this causes the process to abort.
	 *  @author rlemeill
	 *  @param ctx context
	 *  @param pi standard process info
	 *  @param trx
	 *  @return true if success
	 */
public boolean startProcess(Properties ctx, ProcessInfo pi, Trx trx) {
    processInfo = pi;
    String Name = pi.getTitle();
    int AD_PInstance_ID = pi.getAD_PInstance_ID();
    int Record_ID = pi.getRecord_ID();
    log.info("Name=" + Name + "  AD_PInstance_ID=" + AD_PInstance_ID + " Record_ID=" + Record_ID);
    String trxName = null;
    if (trx != null) {
        trxName = trx.getTrxName();
    }
    ReportData reportData = getReportData(pi, trxName);
    if (reportData == null) {
        reportResult(AD_PInstance_ID, "Can not find report data", trxName);
        return false;
    }
    String reportPath = reportData.getReportFilePath();
    if (Util.isEmpty(reportPath, true)) {
        reportResult(AD_PInstance_ID, "Can not find report", trxName);
        return false;
    }
    JasperData data = null;
    File reportFile = null;
    String fileExtension = "";
    HashMap<String, Object> params = new HashMap<String, Object>();
    addProcessParameters(AD_PInstance_ID, params, trxName);
    addProcessInfoParameters(params, pi.getParameter());
    reportFile = getReportFile(reportPath, (String) params.get("ReportType"));
    if (reportFile == null || reportFile.exists() == false) {
        log.severe("No report file found for given type, falling back to " + reportPath);
        reportFile = getReportFile(reportPath);
    }
    if (reportFile == null || reportFile.exists() == false) {
        String tmp = "Can not find report file at path - " + reportPath;
        log.severe(tmp);
        reportResult(AD_PInstance_ID, tmp, trxName);
    }
    if (reportFile != null) {
        data = processReport(reportFile);
        if (data.getJasperReport() == null) {
            log.severe("Could not load Jasper Report " + reportPath);
            return false;
        }
        fileExtension = reportFile.getName().substring(reportFile.getName().lastIndexOf("."), reportFile.getName().length());
    } else {
        return false;
    }
    JasperReport jasperReport = data.getJasperReport();
    String jasperName = data.getJasperName();
    String name = jasperReport.getName();
    File reportDir = data.getReportDir();
    // Add reportDir to class path
    ClassLoader scl = ClassLoader.getSystemClassLoader();
    try {
        java.net.URLClassLoader ucl = new java.net.URLClassLoader(new java.net.URL[] { reportDir.toURI().toURL() }, scl);
        net.sf.jasperreports.engine.util.JRResourcesUtil.setThreadClassLoader(ucl);
    } catch (MalformedURLException me) {
        log.warning("Could not add report directory to classpath: " + me.getMessage());
    }
    if (jasperReport != null) {
        File[] subreports;
        // Subreports
        if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
            // Locate and download subreports from remote webcontext
            subreports = getHttpSubreports(jasperName + "Subreport", reportPath, fileExtension);
        } else if (reportPath.startsWith("attachment:")) {
            subreports = getAttachmentSubreports(reportPath);
        } else if (reportPath.startsWith("resource:")) {
            subreports = getResourceSubreports(name + "Subreport", reportPath, fileExtension);
        } else // TODO: Implement file:/ lookup for subreports
        {
            // Locate subreports from local/remote filesystem
            subreports = reportDir.listFiles(new FileFilter(jasperName + "Subreport", reportDir, fileExtension));
        }
        for (int i = 0; i < subreports.length; i++) {
            // @Trifon - begin
            if (subreports[i].getName().toLowerCase().endsWith(".jasper") || subreports[i].getName().toLowerCase().endsWith(".jrxml")) {
                JasperData subData = processReport(subreports[i]);
                if (subData.getJasperReport() != null) {
                    params.put(subData.getJasperName(), subData.getJasperFile().getAbsolutePath());
                }
            }
        // @Trifon - end
        }
        if (Record_ID > 0)
            params.put("RECORD_ID", new Integer(Record_ID));
        // contribution from Ricardo (ralexsander)
        // in iReports you can 'SELECT' AD_Client_ID, AD_Org_ID and AD_User_ID using only AD_PINSTANCE_ID
        params.put("AD_PINSTANCE_ID", new Integer(AD_PInstance_ID));
        // FR [3123850] - Add continiuosly needed parameters to Jasper Starter - Carlos Ruiz - GlobalQSS
        params.put("AD_CLIENT_ID", new Integer(Env.getAD_Client_ID(Env.getCtx())));
        params.put("AD_ROLE_ID", new Integer(Env.getAD_Role_ID(Env.getCtx())));
        params.put("AD_USER_ID", new Integer(Env.getAD_User_ID(Env.getCtx())));
        Language currLang = Env.getLanguage(Env.getCtx());
        String printerName = null;
        MPrintFormat printFormat = null;
        PrintInfo printInfo = null;
        ProcessInfoParameter[] pip = pi.getParameter();
        // Get print format and print info parameters
        if (pip != null) {
            for (int i = 0; i < pip.length; i++) {
                if (ServerReportCtl.PARAM_PRINT_FORMAT.equalsIgnoreCase(pip[i].getParameterName())) {
                    printFormat = (MPrintFormat) pip[i].getParameter();
                }
                if (ServerReportCtl.PARAM_PRINT_INFO.equalsIgnoreCase(pip[i].getParameterName())) {
                    printInfo = (PrintInfo) pip[i].getParameter();
                }
                if (ServerReportCtl.PARAM_PRINTER_NAME.equalsIgnoreCase(pip[i].getParameterName())) {
                    printerName = (String) pip[i].getParameter();
                }
            }
        }
        if (printFormat != null) {
            if (printInfo != null) {
                // Set the language of the print format if we're printing a document
                if (printInfo.isDocument()) {
                    currLang = printFormat.getLanguage();
                }
            }
            // Set printer name unless already set.
            if (printerName == null) {
                printerName = printFormat.getPrinterName();
            }
        }
        params.put("CURRENT_LANG", currLang.getAD_Language());
        params.put(JRParameter.REPORT_LOCALE, currLang.getLocale());
        // Resources
        File resFile = null;
        if (reportPath.startsWith("attachment:") && attachment != null) {
            resFile = getAttachmentResourceFile(jasperName, currLang);
        } else if (reportPath.startsWith("resource:")) {
            resFile = getResourcesForResourceFile(jasperName, currLang);
        // TODO: Implement file:/ for resources
        } else {
            resFile = new File(jasperName + "_" + currLang.getLocale().getLanguage() + ".properties");
            if (!resFile.exists()) {
                resFile = null;
            }
            if (resFile == null) {
                resFile = new File(jasperName + ".properties");
                if (!resFile.exists()) {
                    resFile = null;
                }
            }
        }
        if (resFile != null) {
            try {
                PropertyResourceBundle res = new PropertyResourceBundle(new FileInputStream(resFile));
                params.put("RESOURCE", res);
            } catch (IOException e) {
                ;
            }
        }
        Connection conn = null;
        try {
            conn = trx != null ? trx.getConnection() : getConnection();
            jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);
            if (reportData.isDirectPrint() && !processInfo.isPrintPreview()) {
                log.info("ReportStarter.startProcess print report -" + jasperPrint.getName());
                //RF 1906632
                if (!processInfo.isBatch()) {
                    // Get printer job
                    PrinterJob printerJob = org.compiere.print.CPrinter.getPrinterJob(printerName);
                    // Set print request attributes
                    //	Paper Attributes:
                    PrintRequestAttributeSet prats = new HashPrintRequestAttributeSet();
                    //	add:				copies, job-name, priority
                    if (// @Trifon
                    printInfo == null || printInfo.isDocumentCopy() || printInfo.getCopies() < 1)
                        prats.add(new Copies(1));
                    else
                        prats.add(new Copies(printInfo.getCopies()));
                    Locale locale = Language.getLoginLanguage().getLocale();
                    // @Trifon
                    String printFormat_name = printFormat == null ? "" : printFormat.getName();
                    int numCopies = printInfo == null ? 0 : printInfo.getCopies();
                    prats.add(new JobName(printFormat_name + "_" + pi.getRecord_ID(), locale));
                    prats.add(PrintUtil.getJobPriority(jasperPrint.getPages().size(), numCopies, true));
                    // Create print service exporter
                    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
                    ;
                    // Set parameters
                    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, printerJob.getPrintService());
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printerJob.getPrintService().getAttributes());
                    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, prats);
                    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
                    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
                    // Print report / document
                    exporter.exportReport();
                } else {
                    // Used For the PH
                    try {
                        File PDF = File.createTempFile("mail", ".pdf");
                        JasperExportManager.exportReportToPdfFile(jasperPrint, PDF.getAbsolutePath());
                        processInfo.setPDFReport(PDF);
                    } catch (IOException e) {
                        log.severe("ReportStarter.startProcess: Can not make PDF File - " + e.getMessage());
                    }
                }
            // You can use JasperPrint to create PDF
            //                        JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
            } else {
                log.info("ReportStarter.startProcess run report -" + jasperPrint.getName());
                JRViewerProvider viewerLauncher = getReportViewerProvider();
                //viewerLauncher.openViewer(jasperPrint, pi.getTitle()+" - " + reportPath);
                viewerLauncher.openViewer(jasperPrint, pi.getTitle() + "_" + pi.getRecord_ID() + ".pdf");
            }
        } catch (JRException e) {
            log.severe("ReportStarter.startProcess: Can not run report - " + e.getMessage());
        } finally {
            if (conn != null && trx == null)
                try {
                    conn.close();
                } catch (SQLException e) {
                    throw new AdempiereException("@Error@ " + e);
                }
        }
    }
    reportResult(AD_PInstance_ID, null, trxName);
    return true;
}
Also used : Locale(java.util.Locale) MalformedURLException(java.net.MalformedURLException) JRException(net.sf.jasperreports.engine.JRException) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) JobName(javax.print.attribute.standard.JobName) PrintInfo(org.compiere.model.PrintInfo) JasperReport(net.sf.jasperreports.engine.JasperReport) PropertyResourceBundle(java.util.PropertyResourceBundle) PrinterJob(java.awt.print.PrinterJob) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) Language(org.compiere.util.Language) JRPrintServiceExporter(net.sf.jasperreports.engine.export.JRPrintServiceExporter) Copies(javax.print.attribute.standard.Copies) Connection(java.sql.Connection) CConnection(org.compiere.db.CConnection) IOException(java.io.IOException) JasperPrint(net.sf.jasperreports.engine.JasperPrint) FileInputStream(java.io.FileInputStream) ProcessInfoParameter(org.compiere.process.ProcessInfoParameter) MPrintFormat(org.compiere.print.MPrintFormat) AdempiereException(org.adempiere.exceptions.AdempiereException) DigestOfFile(org.compiere.util.DigestOfFile) File(java.io.File) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 40 with Language

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

the class ALogin method languageComboChanged.

/**
	 *	Change Language
	 */
private void languageComboChanged() {
    String langName = (String) languageCombo.getSelectedItem();
    //	log.info( "Language: " + langName);
    Language language = Language.getLanguage(langName);
    Language.setLoginLanguage(language);
    Env.setContext(m_ctx, Env.LANGUAGE, language.getAD_Language());
    //	Locales
    Locale loc = language.getLocale();
    Locale.setDefault(loc);
    this.setLocale(loc);
    res = ResourceBundle.getBundle(RESOURCE, loc);
    //
    this.setTitle(res.getString("Login"));
    hostLabel.setText(res.getString("Host"));
    userLabel.setText(res.getString("User"));
    userLabel.setToolTipText(res.getString("EnterUser"));
    passwordLabel.setText(res.getString("Password"));
    passwordLabel.setToolTipText(res.getString("EnterPassword"));
    languageLabel.setText(res.getString("Language"));
    languageLabel.setToolTipText(res.getString("SelectLanguage"));
    //
    roleLabel.setText(res.getString("Role"));
    clientLabel.setText(res.getString("Client"));
    orgLabel.setText(res.getString("Organization"));
    dateLabel.setText(res.getString("Date"));
    warehouseLabel.setText(res.getString("Warehouse"));
    printerLabel.setText(res.getString("Printer"));
    defaultPanel.setToolTipText(res.getString("Defaults"));
    connectionPanel.setToolTipText(res.getString("Connection"));
    //
    //	txt_Connected = res.getString("Connected");
    txt_NotConnected = res.getString("NotConnected");
    txt_NoDatabase = res.getString("DatabaseNotFound");
    txt_UserPwdError = res.getString("UserPwdError");
    txt_RoleError = res.getString("RoleNotFound");
    txt_LoggedIn = res.getString("Authorized");
    //
    loginTabPane.setTitleAt(0, res.getString("Connection"));
    loginTabPane.setTitleAt(1, res.getString("Defaults"));
    confirmPanel.getOKButton().setToolTipText(res.getString("Ok"));
    confirmPanel.getCancelButton().setToolTipText(res.getString("Cancel"));
    //	DateField with new format
    dateField.setFormat();
    dateField.setValue(new Timestamp(System.currentTimeMillis()));
    //
    if (m_connectionOK) {
        this.setTitle(hostField.getDisplay());
        statusBar.setStatusLine(txt_LoggedIn);
    } else {
        this.setTitle(res.getString("Login"));
        statusBar.setStatusLine(txt_NotConnected, true);
    }
}
Also used : Locale(java.util.Locale) Language(org.compiere.util.Language) Timestamp(java.sql.Timestamp)

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