Search in sources :

Example 81 with KeyNamePair

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

the class WListbox method loadTable.

//  setColorColumn
/**
	 *	Load Table from ResultSet - The ResultSet is not closed.
	 *
	 *  @param rs 	ResultSet containing data t enter int the table.
	 *  			The contents must conform to the column layout defined in
	 *  			{@link #prepareTable(ColumnInfo[], String, String, boolean, String)}
	 */
public void loadTable(ResultSet rs) {
    int no = 0;
    // model row
    int row = 0;
    // model column
    int col = 0;
    Object data = null;
    // index into result set
    int rsColIndex = 0;
    //  result set columns start with 1
    int rsColOffset = 1;
    // class of the column
    Class columnClass;
    if (getLayout() == null) {
        throw new UnsupportedOperationException("Layout not defined");
    }
    clearTable();
    try {
        while (rs.next()) {
            row = getItemCount();
            setRowCount(row + 1);
            rsColOffset = 1;
            no++;
            for (col = 0; col < m_layout.length; col++) {
                //reset the data value
                data = null;
                columnClass = m_layout[col].getColClass();
                rsColIndex = col + rsColOffset;
                if (isColumnClassMismatch(col, columnClass)) {
                    throw new ApplicationException("Cannot enter a " + columnClass.getName() + " in column " + col + ". " + "An object of type " + m_modelHeaderClass.get(col).getSimpleName() + " was expected.");
                }
                if (columnClass == IDColumn.class && !m_layout[col].getColSQL().equals("'Row' AS \"Row\"")) {
                    data = new IDColumn(rs.getInt(rsColIndex));
                } else if (columnClass == IDColumn.class && m_layout[col].getColSQL().equals("'Row' AS \"Row\"")) {
                    data = new IDColumn(no);
                } else if (columnClass == Boolean.class) {
                    data = rs.getString(rsColIndex) == null ? new Boolean(false) : new Boolean(rs.getString(rsColIndex).equals("Y"));
                } else if (columnClass == Timestamp.class) {
                    data = rs.getTimestamp(rsColIndex);
                } else if (columnClass == BigDecimal.class) {
                    data = rs.getBigDecimal(rsColIndex);
                } else if (columnClass == Double.class) {
                    data = new Double(rs.getDouble(rsColIndex));
                } else if (columnClass == Integer.class) {
                    data = new Integer(rs.getInt(rsColIndex));
                } else if (columnClass == KeyNamePair.class) {
                    // TODO factor out this generation
                    String display = rs.getString(rsColIndex);
                    int key = rs.getInt(rsColIndex + 1);
                    data = new KeyNamePair(key, display);
                    rsColOffset++;
                } else {
                    // TODO factor out this cleanup
                    String s = rs.getString(rsColIndex);
                    if (s != null) {
                        //	problems with NCHAR
                        data = s.trim();
                    } else {
                        data = null;
                    }
                }
                //  store in underlying model
                getModel().setDataAt(data, row, col);
            }
        }
    } catch (SQLException exception) {
        logger.log(Level.SEVERE, "", exception);
    }
    autoSize();
    if (getShowTotals())
        addTotals(m_layout);
    // repaint the table
    this.repaint();
    logger.config("Row(rs)=" + getRowCount());
    return;
}
Also used : SQLException(java.sql.SQLException) Timestamp(java.sql.Timestamp) IDColumn(org.compiere.minigrid.IDColumn) ApplicationException(org.adempiere.webui.exception.ApplicationException) KeyNamePair(org.compiere.util.KeyNamePair)

Example 82 with KeyNamePair

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

the class MAcctSchemaGL method getAcctInfo.

//	MAcctSchemaGL
/**
	 * 	Get Acct Info list 
	 *	@return list
	 */
public ArrayList<KeyNamePair> getAcctInfo() {
    ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
    for (int i = 0; i < get_ColumnCount(); i++) {
        String columnName = get_ColumnName(i);
        if (columnName.endsWith("Acct")) {
            int id = ((Integer) get_Value(i));
            list.add(new KeyNamePair(id, columnName));
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) KeyNamePair(org.compiere.util.KeyNamePair)

Example 83 with KeyNamePair

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

the class Viewer method cmd_report.

/**
	 * 	Report Combo - Start other Report or create new one
	 *	@param isSummaryChanged for when the check Is Summary is changed
	 */
private void cmd_report(boolean isSummaryChanged) {
    KeyNamePair pp = (KeyNamePair) comboReport.getSelectedItem();
    if (pp == null)
        return;
    //
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    MPrintFormat pf = null;
    int AD_PrintFormat_ID = pp.getKey();
    //	create new
    if (AD_PrintFormat_ID == -1) {
        int AD_ReportView_ID = m_reportEngine.getPrintFormat().getAD_ReportView_ID();
        if (AD_ReportView_ID != 0) {
            String name = m_reportEngine.getName();
            int index = name.lastIndexOf('_');
            if (index != -1)
                name = name.substring(0, index);
            pf = MPrintFormat.createFromReportView(m_ctx, AD_ReportView_ID, name);
        } else {
            int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID();
            pf = MPrintFormat.createFromTable(m_ctx, AD_Table_ID);
        }
        if (pf != null)
            fillComboReport(pf.get_ID());
        else
            return;
    } else //copy current
    if (AD_PrintFormat_ID == -2) {
        MPrintFormat current = m_reportEngine.getPrintFormat();
        if (current != null) {
            pf = MPrintFormat.copyToClient(m_ctx, current.getAD_PrintFormat_ID(), Env.getAD_Client_ID(m_ctx));
            if (pf != null)
                fillComboReport(pf.get_ID());
            else
                return;
        } else
            return;
    } else
        pf = MPrintFormat.get(Env.getCtx(), AD_PrintFormat_ID, true);
    //	FR [ 238 ]
    if (pf == null)
        return;
    //	
    if (!isSummaryChanged) {
        summary.setSelected(pf.isSummary());
    }
    // Set Summary for report
    m_reportEngine.setSummary(summary.isSelected());
    //	Get Language from previous - thanks Gunther Hoppe 
    if (m_reportEngine.getPrintFormat() != null) {
        //	needs to be re-set - otherwise viewer will be blank
        pf.setLanguage(m_reportEngine.getPrintFormat().getLanguage());
        pf.setTranslationLanguage(m_reportEngine.getPrintFormat().getLanguage());
    }
    //	FR [ 237 ]
    KeyNamePair reportView = (KeyNamePair) comboReportView.getSelectedItem();
    if (reportView != null) {
        m_reportEngine.setAD_ReportView_ID(reportView.getKey());
    }
    //	
    m_reportEngine.setPrintFormat(pf);
    revalidate();
    //	setCursor
    cmd_drill();
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair) Point(java.awt.Point)

Example 84 with KeyNamePair

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

the class Viewer method cmd_report.

//	cmd_export
/**
	 * 	Report Combo - Start other Report or create new one
	 */
private void cmd_report() {
    KeyNamePair pp = (KeyNamePair) comboReport.getSelectedItem();
    if (pp != null && pp.getKey() >= 0) {
        //	Set Default Report View
        MPrintFormat pf = MPrintFormat.get(Env.getCtx(), pp.getKey(), true);
        selectReportView(pf.getAD_ReportView_ID());
    }
    //	Call Report
    cmd_report(false);
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 85 with KeyNamePair

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

the class Viewer method fillComboReport.

//	dynInit
/**
	 * 	Fill ComboBox comboReport (report options)
	 *  @param AD_PrintFormat_ID item to be selected
	 */
private void fillComboReport(int AD_PrintFormat_ID) {
    comboReport.removeActionListener(this);
    comboReport.removeAllItems();
    KeyNamePair selectValue = null;
    //	fill Report Options
    String sql = MRole.getDefault().addAccessSQL("SELECT AD_PrintFormat_ID, Name, Description " + "FROM AD_PrintFormat " + "WHERE AD_Table_ID=? " + //Added Lines by Armen
    "AND IsActive='Y' " + //End of Added Lines
    "ORDER BY Name", "AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID();
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_Table_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
            comboReport.addItem(pp);
            if (rs.getInt(1) == AD_PrintFormat_ID)
                selectValue = pp;
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    StringBuffer sb = new StringBuffer("** ").append(Msg.getMsg(m_ctx, "NewReport")).append(" **");
    KeyNamePair pp = new KeyNamePair(-1, sb.toString());
    comboReport.addItem(pp);
    sb = new StringBuffer("** ").append(Msg.getMsg(m_ctx, "CopyReport")).append(" **");
    pp = new KeyNamePair(-2, sb.toString());
    comboReport.addItem(pp);
    if (selectValue != null)
        comboReport.setSelectedItem(selectValue);
    comboReport.addActionListener(this);
    //	FR [ 237 ]
    fillComboReportView();
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) Point(java.awt.Point)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7