Search in sources :

Example 61 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class WBrowserTable method setRowChecked.

/**
     * If the table row has a IDColumn or a boolean checkbox in the KeyColumnIndex
     * this function will set the checkbox according to the setValue parameter
     * @param row - the view row
     * @param setValue - the checkbox value to set
     */
public void setRowChecked(int row, boolean setValue) {
    //  The key column will be defined or zero by default.
    //  Check the class of the data in the cell to verify if
    //  it is a selection column.  Selection columns can be
    //  of type IDColumn or Boolean.
    Object data = this.getValueAt(row, this.convertColumnIndexToView(getKeyColumnIndex()));
    if (data instanceof IDColumn) {
        IDColumn id = (IDColumn) data;
        id.setSelected(setValue);
    } else if (data instanceof Boolean) {
        data = setValue;
    } else
        return;
    this.setValueAt(data, row, this.convertColumnIndexToView(getKeyColumnIndex()));
}
Also used : IDColumn(org.compiere.minigrid.IDColumn)

Example 62 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class WPOSOrderLinePanel method tableChanged.

@Override
public void tableChanged(WTableModelEvent event) {
    boolean isUpdate = (event.getType() == ListDataEvent.CONTENTS_CHANGED);
    int col = event.getColumn();
    int row = posTable.getSelectedRow();
    /*if(event.getColumn() == POSOrderLineTableHandle.POSITION_DELETE){
			posTable.getModel().removeTableModelListener(this);
			ListModelTable m_model = (ListModelTable)event.getModel();
			for(int x = 0; x < posTable.getRowCount(); x++){
				String value = m_model.getValueAt(x, 1).toString();
				if(value.length() == 0){
					IDColumn key = (IDColumn) m_model.getValueAt(x, 0);
					orderLineId = key.getRecord_ID();
					posPanel.deleteLine(orderLineId);
					posTable.getModel().remove(x);
				}
			}

			posTable.getModel().addTableModelListener(this);
			posPanel.refreshHeader();
			return;
		}*/
    if (!isUpdate || (col != POSOrderLineTableHandle.POSITION_QTYORDERED && col != POSOrderLineTableHandle.POSITION_PRICE)) {
        return;
    }
    if (event.getModel().equals(posTable.getModel())) {
        //Add Minitable Source Condition
        if (row != -1) {
            ListModelTable model = posTable.getModel();
            IDColumn key = (IDColumn) model.getValueAt(row, 0);
            posTable.getModel().removeTableModelListener(this);
            //	Validate Key
            if (key != null) {
                //	Set Current Order Line
                orderLineId = key.getRecord_ID();
                BigDecimal m_QtyOrdered = (BigDecimal) posTable.getValueAt(row, POSOrderLineTableHandle.POSITION_QTYORDERED);
                BigDecimal m_Price = (BigDecimal) posTable.getValueAt(row, POSOrderLineTableHandle.POSITION_PRICE);
                BigDecimal discountPercentage = (BigDecimal) posTable.getValueAt(row, POSOrderLineTableHandle.POSITION_DISCOUNT);
                posPanel.setQty(m_QtyOrdered);
                posPanel.setPrice(m_Price);
                posPanel.setDiscountPercentage(discountPercentage);
                updateLine();
            }
        }
    }
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ListModelTable(org.adempiere.webui.component.ListModelTable) BigDecimal(java.math.BigDecimal)

Example 63 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class WPOSTable method loadTable.

/**
	 *	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 if (columnClass == DeleteColumn.class) {
                    // TODO factor out this generation
                    data = new DeleteColumn(rs.getInt(rsColIndex));
                } 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) DeleteColumn(org.compiere.minigrid.DeleteColumn) Timestamp(java.sql.Timestamp) IDColumn(org.compiere.minigrid.IDColumn) ApplicationException(org.adempiere.webui.exception.ApplicationException) KeyNamePair(org.compiere.util.KeyNamePair)

Example 64 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class WMatch method tableChanged.

/***************************************************************************
	 *  Table Model Listener - calculate matchd Qty
	 *  @param e event
	 */
public void tableChanged(WTableModelEvent e) {
    if (e.getColumn() != 0)
        return;
    log.config("Row=" + e.getFirstRow() + "-" + e.getLastRow() + ", Col=" + e.getColumn() + ", Type=" + e.getType());
    //  Matched From
    int matchedRow = xMatchedTable.getSelectedRow();
    KeyNamePair Product = (KeyNamePair) xMatchedTable.getValueAt(matchedRow, 5);
    //  Matched To
    double qty = 0.0;
    int noRows = 0;
    for (int row = 0; row < xMatchedToTable.getRowCount(); row++) {
        IDColumn id = (IDColumn) xMatchedToTable.getValueAt(row, 0);
        if (id != null && id.isSelected()) {
            KeyNamePair ProductCompare = (KeyNamePair) xMatchedToTable.getValueAt(row, 5);
            if (Product.getKey() != ProductCompare.getKey()) {
                id.setSelected(false);
            } else {
                if (matchMode.getSelectedIndex() == MODE_NOTMATCHED)
                    //  doc
                    qty += ((Double) xMatchedToTable.getValueAt(row, I_QTY)).doubleValue();
                //  matched
                qty -= ((Double) xMatchedToTable.getValueAt(row, I_MATCHED)).doubleValue();
                noRows++;
            }
        }
    }
    //  update qualtities
    m_xMatchedTo = new BigDecimal(qty);
    xMatchedTo.setValue(m_xMatchedTo);
    difference.setValue(m_xMatched.subtract(m_xMatchedTo));
    bProcess.setEnabled(noRows != 0);
    //  Status
    statusBar.setStatusDB(noRows + "");
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) KeyNamePair(org.compiere.util.KeyNamePair) BigDecimal(java.math.BigDecimal)

Example 65 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InvoiceGenFromShipment method saveSelection.

/**
	 *	Save Selection & return selection Query or ""
	 *  @return where clause like M_InOut_ID IN (...)
	 */
public void saveSelection(IMiniTable miniTable) {
    log.info("");
    //  Array of Integers
    ArrayList<Integer> results = new ArrayList<Integer>();
    setSelection(null);
    //	Get selected entries
    int rows = miniTable.getRowCount();
    for (int i = 0; i < rows; i++) {
        //  ID in column 0
        IDColumn id = (IDColumn) miniTable.getValueAt(i, 0);
        //log.fine( "Row=" + i + " - " + id);
        if (id != null && id.isSelected())
            results.add(id.getRecord_ID());
    }
    if (results.size() == 0)
        return;
    log.config("Selected #" + results.size());
    setSelection(results);
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ArrayList(java.util.ArrayList)

Aggregations

IDColumn (org.compiere.minigrid.IDColumn)79 SQLException (java.sql.SQLException)25 BigDecimal (java.math.BigDecimal)20 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)20 ArrayList (java.util.ArrayList)16 KeyNamePair (org.compiere.util.KeyNamePair)13 Timestamp (java.sql.Timestamp)8 Vector (java.util.Vector)5 GridField (org.compiere.model.GridField)5 MBrowseField (org.adempiere.model.MBrowseField)4 ApplicationException (org.adempiere.webui.exception.ApplicationException)4 SimpleDateFormat (java.text.SimpleDateFormat)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 PO (org.compiere.model.PO)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 DecimalFormat (java.text.DecimalFormat)2 Date (java.util.Date)2 ChangeEvent (javax.swing.event.ChangeEvent)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2