use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.
the class InfoProduct method refreshAtpTab.
// initAtpTab
/**
* Refresh ATP
*/
private void refreshAtpTab() {
boolean showDetail = checkShowDetail.isSelected();
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
int M_Warehouse_ID = 0;
// row to prevent array index out of bounds. BF 3051361
if (warehouseTbl.getRowCount() > 0) {
int selectedRow = warehouseTbl.getSelectedRow();
if (selectedRow < 0)
selectedRow = 0;
Object wh_data = warehouseTbl.getValueAt(selectedRow, warehouseTbl.getKeyColumnIndex());
if (wh_data != null && wh_data instanceof IDColumn) {
IDColumn dataColumn = (IDColumn) wh_data;
M_Warehouse_ID = dataColumn.getRecord_ID();
}
} else {
M_Warehouse_ID = m_M_Warehouse_ID;
}
if (M_Warehouse_ID == 0) {
// Can't find a warehouse to load. Clear the table
clearAtpTab();
return;
} else // Update the table
{
// Create the SELECT ..UNION. clause
// This is done in-line rather than using prepareTable() so we can add a running sum to the data.
String sql;
if (!showDetail)
sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, 0 as ID, null as Date," + " sum(s.QtyOnHand) as AvailQty, null as DeltaQty, sum(s.QtyOrdered) as QtyOrdered, sum(s.QtyReserved) as QtyReserved," + // " s.PASI,"
" null as sumPASI," + " 0 as ASI," + " null as BP_Name, null as DocumentNo, 10 as SeqNo";
else
sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, s.M_AttributeSetInstance_ID as ID, now() as Date," + " s.QtyOnHand as AvailQty, null as DeltaQty, s.QtyOrdered as QtyOrdered, s.QtyReserved as QtyReserved," + " CASE WHEN s.PASI = '' THEN '{' || COALESCE(s.M_AttributeSetInstance_ID,0) || '}' ELSE s.PASI END as sumPASI," + " COALESCE(M_AttributeSetInstance_ID,0) as ASI," + " null as BP_Name, null as DocumentNo, 10 as SeqNo";
sql += " FROM (SELECT M_Product_ID, M_Locator_ID, QtyOnHand, QtyReserved, QtyOrdered," + " COALESCE(productAttribute(M_AttributeSetInstance_ID)::varchar, '') as PASI," + " COALESCE(M_AttributeSetInstance_ID,0) as M_AttributeSetInstance_ID FROM M_Storage) s " + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " AND s.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND l.M_Warehouse_ID=" + M_Warehouse_ID;
// sql += " AND s.M_AttributeSetInstance_ID=?";
if (!showDetail) {
//sql += " AND (s.QtyOnHand<>0)";
sql += " GROUP BY s.M_Product_ID, w.Name, l.value, s.M_Locator_ID, sumPASI, ASI, BP_Name, DocumentNo, SeqNo ";
} else
//sql += " AND (s.QtyOnHand<>0) ";
;
sql += " UNION ALL ";
// Orders
sql += "SELECT ol.M_Product_ID, w.Name as warehouse, null as locator, ol.M_AttributeSetInstance_ID as ID, o.DatePromised as date," + " null as AvailQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE -ol.QtyReserved END as DeltaQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE null END as QtyOrdered," + " CASE WHEN dt.DocBaseType = 'POO' THEN 0 ELSE 0 END as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM C_Order o" + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Warehouse w ON (ol.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp ON (o.C_BPartner_ID=bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO')" + " AND ol.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
//if (m_M_AttributeSetInstance_ID > 0)
// sql += " AND ol.M_AttributeSetInstance_ID=?";
//sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator";
sql += " UNION ALL ";
// Distribution Orders out bound
sql += "SELECT ol.M_Product_ID, wf.Name as warehouse, lf.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " -ol.QtyOrdered+ol.QtyInTransit+ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp ON (o.C_BPartner_ID = bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered = 'N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND wf.M_Warehouse_ID=" + M_Warehouse_ID;
//if (m_M_AttributeSetInstance_ID > 0)
// sql += " AND ol.M_AttributeSetInstance_ID=?";
sql += " UNION ALL ";
// Distribution Orders in bound
sql += "SELECT ol.M_Product_ID, w.Name as warehouse, l.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " ol.QtyOrdered-ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp ON (wf.AD_Org_ID=bp.AD_OrgBP_ID) " + "WHERE ol.QtyOrdered - ol.Qtydelivered > 0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered='N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
if (M_Warehouse_ID != 0)
sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
//if (m_M_AttributeSetInstance_ID > 0)
// sql += " AND ol.M_AttributeSetInstance_ID=?";
sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator)";
double qty = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
int index = 1;
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
// The order of data matches the layout, not the query
// M_Product_ID, warehouse, locator, ID, Date, AvailQty, DeltaQty, (1..7)
// QtyOrdered, QtyReserved, (8..9)
// sumPASI, ASI, (10..11)
// BP_Name, DocumentNo, SeqNo (12..14)
Vector<Object> line = new Vector<Object>(10);
// M_Product_ID
line.add(rs.getInt(1));
// warehouse
line.add(rs.getString(2));
// Locator
line.add(rs.getString(3));
// Date
line.add(rs.getTimestamp(5));
double deltaQty = rs.getDouble(7);
qty += +rs.getDouble(6) + deltaQty;
// Qty Available (running sum)
line.add(new Double(qty) - rs.getDouble(9));
// Qty on hand (this line)
line.add(new Double(rs.getDouble(6)));
// Delta Qty
line.add(new Double(rs.getDouble(7)));
// BPartner
line.add(rs.getString(12));
// QtyOrdered
line.add(new Double(rs.getDouble(8)));
// QtyReserved
line.add(new Double(rs.getDouble(9)));
// ASI
line.add(rs.getString(10));
// DocumentNo
line.add(rs.getString(13));
data.add(line);
}
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
}
// Update the table
// Header
Vector<String> columnNames = new Vector<String>();
for (int i = 0; i < m_layoutATP.length; i++) {
columnNames.add(m_layoutATP[i].getColHeader());
}
m_modelAtp = new DefaultTableModel();
m_modelAtp.setDataVector(data, columnNames);
// Avoid an exception
SwingUtilities.invokeLater(new Runnable() {
public void run() {
m_tableAtp.setModel(m_modelAtp);
// set editors (two steps)
for (int i = 0; i < m_layoutATP.length; i++) {
m_tableAtp.setColumnClass(i, m_layoutATP[i].getColClass(), m_layoutATP[i].isReadOnly(), m_layoutATP[i].getColHeader());
if (m_layoutATP[i].isColorColumn()) {
// QtyAvailable.
m_tableAtp.setColorColumn(i);
}
}
m_tableAtp.autoSize();
}
});
}
use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.
the class InvoiceHistory method initUnconfirmedTab.
// initReservedOrderedTab
/**
* Query Unconfirmed
*/
private void initUnconfirmedTab() {
// Done already
if (m_modelUnconfirmed != null)
return;
// Header
Vector<String> columnNames = new Vector<String>();
columnNames.add(Msg.translate(Env.getCtx(), m_C_BPartner_ID == 0 ? "C_BPartner_ID" : "M_Product_ID"));
columnNames.add(Msg.translate(Env.getCtx(), "MovementQty"));
columnNames.add(Msg.translate(Env.getCtx(), "MovementDate"));
columnNames.add(Msg.translate(Env.getCtx(), "IsSOTrx"));
columnNames.add(Msg.translate(Env.getCtx(), "DocumentNo"));
columnNames.add(Msg.translate(Env.getCtx(), "M_Warehouse_ID"));
// Fill Data
String sql = null;
int parameter = 0;
if (m_C_BPartner_ID == 0) {
sql = "SELECT bp.Name," + " CASE WHEN io.IsSOTrx='Y' THEN iol.MovementQty*-1 ELSE iol.MovementQty END AS MovementQty," + " io.MovementDate,io.IsSOTrx," + " dt.PrintName || ' ' || io.DocumentNo As DocumentNo," + " w.Name " + "FROM M_InOutLine iol" + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID)" + " INNER JOIN C_BPartner bp ON (io.C_BPartner_ID=bp.C_BPartner_ID)" + " INNER JOIN C_DocType dt ON (io.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Warehouse w ON (io.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_InOutLineConfirm lc ON (iol.M_InOutLine_ID=lc.M_InOutLine_ID) " + "WHERE iol.M_Product_ID=?" + " AND lc.Processed='N' " + "ORDER BY io.MovementDate,io.IsSOTrx";
parameter = m_M_Product_ID;
} else {
sql = "SELECT p.Name," + " CASE WHEN io.IsSOTrx='Y' THEN iol.MovementQty*-1 ELSE iol.MovementQty END AS MovementQty," + " io.MovementDate,io.IsSOTrx," + " dt.PrintName || ' ' || io.DocumentNo As DocumentNo," + " w.Name " + "FROM M_InOutLine iol" + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID)" + " INNER JOIN M_Product p ON (iol.M_Product_ID=p.M_Product_ID)" + " INNER JOIN C_DocType dt ON (io.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Warehouse w ON (io.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_InOutLineConfirm lc ON (iol.M_InOutLine_ID=lc.M_InOutLine_ID) " + "WHERE io.C_BPartner_ID=?" + " AND lc.Processed='N' " + "ORDER BY io.MovementDate,io.IsSOTrx";
parameter = m_C_BPartner_ID;
}
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, parameter);
rs = pstmt.executeQuery();
while (rs.next()) {
Vector<Object> line = new Vector<Object>(6);
// 1-Name, 2-MovementQty, 3-MovementDate, 4-IsSOTrx, 5-DocumentNo
// Name
line.add(rs.getString(1));
// Qty
line.add(new Double(rs.getDouble(2)));
// Date
line.add(rs.getTimestamp(3));
// IsSOTrx
line.add(new Boolean("Y".equals(rs.getString(4))));
// DocNo
line.add(rs.getString(5));
// Warehouse
line.add(rs.getString(6));
data.add(line);
}
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("#" + data.size());
// Table
m_modelUnconfirmed = new DefaultTableModel(data, columnNames);
m_tableUnconfirmed.setModel(m_modelUnconfirmed);
MiniTable table = m_tableUnconfirmed;
//
// Product/Partner
table.setColumnClass(0, String.class, true);
// MovementQty
table.setColumnClass(1, Double.class, true);
// MovementDate
table.setColumnClass(2, Timestamp.class, true);
// IsSOTrx
table.setColumnClass(3, Boolean.class, true);
// DocNo
table.setColumnClass(4, String.class, true);
// Warehouse
table.setColumnClass(5, String.class, true);
//
table.autoSize();
}
use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.
the class Find method parseUserQuery.
/**
* Parse delimited string into user query
* Old field sequence: column, operator, value, value to
* New field sequence: column, operator, value, value to, and/or, left brackets, right brackets
* @param userQuery
*/
private void parseUserQuery(MUserQuery userQuery) {
String code = userQuery.getCode();
log.fine("Parse user query: " + code);
String[] segments = code.split(Pattern.quote(SEGMENT_SEPARATOR), -1);
advancedTable.stopEditor(true);
DefaultTableModel model = (DefaultTableModel) advancedTable.getModel();
int cnt = model.getRowCount();
for (int i = cnt - 1; i >= 0; i--) model.removeRow(i);
for (int i = 0; i < segments.length; i++) {
String[] fields = segments[i].split(Pattern.quote(FIELD_SEPARATOR));
model.addRow(new Object[] { "", "", null, MQuery.OPERATORS[MQuery.EQUAL_INDEX], null, null, "" });
String columnName = null;
for (int j = 0; j < fields.length; j++) {
// column
if (j == 0) {
for (ValueNamePair vnp : columnValueNamePairs) {
if (vnp.getValue().equals(fields[j])) {
model.setValueAt(vnp, i, INDEX_COLUMNNAME);
columnName = fields[j];
break;
}
}
} else // operator
if (j == 1) {
for (ValueNamePair vnp : MQuery.OPERATORS) {
if (vnp.getValue().equals(fields[j])) {
model.setValueAt(vnp, i, INDEX_OPERATOR);
break;
}
}
} else // value
if (j == 2 && fields[j].length() > 0) {
GridField field = getTargetMField(columnName);
Object value = parseString(field, fields[j]);
model.setValueAt(value, i, INDEX_VALUE);
} else // value 2
if (j == 3 && fields[j].length() > 0) {
GridField field = getTargetMField(columnName);
Object value = parseString(field, fields[j]);
model.setValueAt(value, i, INDEX_VALUE2);
} else // and/or
if (j == 4 && fields[j].length() > 0) {
if (i != 0)
model.setValueAt(fields[j], i, INDEX_ANDOR);
} else if (j == 5 && fields[j].length() > 0) {
model.setValueAt(fields[j], i, INDEX_LEFTBRACKET);
} else if (j == 6 && fields[j].length() > 0) {
model.setValueAt(fields[j], i, INDEX_RIGHTBRACKET);
}
}
}
advancedTable.invalidate();
}
use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.
the class myJTree method loadTableBOM.
// preInit
/**
* Static Init.
* <pre>
* mainPanel
* northPanel
* centerPanel
* xMatched
* xPanel
* xMathedTo
* southPanel
* </pre>
* @throws Exception
*/
private void loadTableBOM() {
// Header Info
columnNames = new Vector<String>(18);
// 0
columnNames.add(Msg.translate(getCtx(), "Select"));
// 1
columnNames.add(Msg.translate(getCtx(), "IsActive"));
// 2
columnNames.add(Msg.translate(getCtx(), "Line"));
// 3
columnNames.add(Msg.translate(getCtx(), "M_Product_ID"));
// 4
columnNames.add(Msg.translate(getCtx(), "C_UOM_ID"));
// 5
columnNames.add(Msg.translate(getCtx(), "QtyBOM"));
// Remove previous listeners
tableBOM.getModel().removeTableModelListener(this);
// Remove previous listeners
tableBOM.getModel().removeTableModelListener(this);
// Set Model
DefaultTableModel model = new DefaultTableModel(dataBOM, columnNames);
model.addTableModelListener(this);
tableBOM.setModel(model);
// 0 Select
tableBOM.setColumnClass(0, Boolean.class, false);
// 1 IsActive
tableBOM.setColumnClass(1, Boolean.class, false);
// 2 Line
tableBOM.setColumnClass(2, Integer.class, false);
// 3 M_Product_ID
tableBOM.setColumnClass(3, KeyNamePair.class, false);
// 4 C_UOM_ID
tableBOM.setColumnClass(4, KeyNamePair.class, false);
// 5 QtyBOM
tableBOM.setColumnClass(5, BigDecimal.class, false);
tableBOM.setMultiSelection(false);
tableBOM.setColumnVisibility(tableBOM.getColumn(0), false);
tableBOM.autoSize();
}
use of javax.swing.table.DefaultTableModel in project adempiere by adempiere.
the class Preference method cmd_displayErrors.
// cmd_save
/**
* (Re)Display Errors
*/
private void cmd_displayErrors() {
Vector data = CLogErrorBuffer.get(true).getLogData(bErrorsOnly.isSelected());
Vector columnNames = CLogErrorBuffer.get(true).getColumnNames(Env.getCtx());
DefaultTableModel model = new DefaultTableModel(data, columnNames);
errorTable.setModel(model);
//
if (bErrorsOnly.isSelected())
tabPane.setTitleAt(4, Msg.getMsg(Env.getCtx(), "Errors") + " (" + data.size() + ")");
else
tabPane.setTitleAt(4, Msg.getMsg(Env.getCtx(), "TraceInfo") + " (" + data.size() + ")");
errorTable.autoSize();
}
Aggregations