- remove swing dependency from CreateFromShipment, IMiniTable and WListbox
This commit is contained in:
Heng Sin Low 2009-07-08 05:59:34 +00:00
parent 05099dacae
commit e930ee3960
5 changed files with 72 additions and 95 deletions

View File

@ -14,7 +14,6 @@
package org.compiere.grid;
import java.awt.Component;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -22,12 +21,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import javax.swing.AbstractCellEditor;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import org.compiere.minigrid.IMiniTable;
import org.compiere.model.GridTab;
import org.compiere.model.MInOut;
@ -41,7 +34,6 @@ import org.compiere.model.MProduct;
import org.compiere.model.MRMA;
import org.compiere.model.MRMALine;
import org.compiere.model.MWarehouse;
import org.compiere.model.Query;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@ -495,65 +487,13 @@ public class CreateFromShipment extends CreateFrom
{
} // infoInvoice
/**
* Custom cell editor for setting locator from minitable.
*
* @author Daniel Tamm
*
*/
public class InnerLocatorTableCellEditor extends AbstractCellEditor implements TableCellEditor {
/**
*
*/
private static final long serialVersionUID = -7143484413792778213L;
KeyNamePair currentValue;
JTextField editor;
@Override
public Object getCellEditorValue() {
String locatorValue = editor.getText();
MLocator loc = null;
try {
// Lookup locator using value
loc = new Query(Env.getCtx(), MLocator.Table_Name, "value=?", null)
.setParameters(new Object[]{locatorValue})
.setClient_ID()
.first();
// Set new keyNamePair for minitable
currentValue = getLocatorKeyNamePair(loc.get_ID());
} catch (Exception e) {
String message = Msg.getMsg(Env.getCtx(), "Invalid") + " " + editor.getText();
JOptionPane.showMessageDialog(null, message);
}
return(currentValue);
}
@Override
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
currentValue = (KeyNamePair)value;
editor = new JTextField();
editor.setText(currentValue.getName());
return(editor);
}
}
protected void configureMiniTable (IMiniTable miniTable)
{
miniTable.setColumnClass(0, Boolean.class, false); // Selection
miniTable.setColumnClass(1, BigDecimal.class, false); // Qty
miniTable.setColumnClass(2, String.class, true); // UOM
miniTable.setColumnClass(3, String.class, false); // Locator
// Set custom cell editor to enable editing locators
TableColumn col = miniTable.getColumn(3);
col.setCellEditor(new InnerLocatorTableCellEditor());
miniTable.setColumnClass(4, String.class, true); // Product
miniTable.setColumnClass(5, String.class, true); // VendorProductNo
miniTable.setColumnClass(6, String.class, true); // Order

View File

@ -15,6 +15,7 @@
package org.compiere.grid;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
@ -28,23 +29,29 @@ import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import javax.swing.AbstractCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import org.compiere.apps.AEnv;
import org.compiere.grid.ed.VLocator;
import org.compiere.grid.ed.VLookup;
import org.compiere.minigrid.IMiniTable;
import org.compiere.minigrid.MiniTable;
import org.compiere.model.GridTab;
import org.compiere.model.MDocType;
import org.compiere.model.MLocator;
import org.compiere.model.MLocatorLookup;
import org.compiere.model.MLookup;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MProduct;
import org.compiere.model.Query;
import org.compiere.swing.CPanel;
import org.compiere.util.CLogger;
import org.compiere.util.DisplayType;
@ -54,8 +61,6 @@ import org.compiere.util.Msg;
public class VCreateFromShipmentUI extends CreateFromShipment implements ActionListener, VetoableChangeListener
{
private static final long serialVersionUID = 1L;
private VCreateFromDialog dialog;
public VCreateFromShipmentUI(GridTab mTab)
@ -477,6 +482,61 @@ public class VCreateFromShipmentUI extends CreateFromShipment implements ActionL
}
return(-1);
}
@Override
protected void configureMiniTable(IMiniTable miniTable) {
super.configureMiniTable(miniTable);
// Set custom cell editor to enable editing locators
MiniTable swingTable = (MiniTable) miniTable;
TableColumn col = swingTable.getColumn(3);
col.setCellEditor(new InnerLocatorTableCellEditor());
}
/**
* Custom cell editor for setting locator from minitable.
*
* @author Daniel Tamm
*
*/
public class InnerLocatorTableCellEditor extends AbstractCellEditor implements TableCellEditor {
/**
*
*/
private static final long serialVersionUID = -7143484413792778213L;
KeyNamePair currentValue;
JTextField editor;
public Object getCellEditorValue() {
String locatorValue = editor.getText();
MLocator loc = null;
try {
// Lookup locator using value
loc = new Query(Env.getCtx(), MLocator.Table_Name, "value=?", null)
.setParameters(new Object[]{locatorValue})
.setClient_ID()
.first();
// Set new keyNamePair for minitable
currentValue = getLocatorKeyNamePair(loc.get_ID());
} catch (Exception e) {
String message = Msg.getMsg(Env.getCtx(), "Invalid") + " " + editor.getText();
JOptionPane.showMessageDialog(null, message);
}
return(currentValue);
}
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
currentValue = (KeyNamePair)value;
editor = new JTextField();
editor.setText(currentValue.getName());
return(editor);
}
}
}

View File

@ -2,8 +2,6 @@ package org.compiere.minigrid;
import java.sql.ResultSet;
import javax.swing.table.TableColumn;
import org.compiere.model.PO;
public interface IMiniTable
@ -37,9 +35,7 @@ public interface IMiniTable
public void setRowCount (int rowCount);
public ColumnInfo[] getLayoutInfo();
public TableColumn getColumn(int col);
public int getColumnCount();
public int getRowCount();

View File

@ -73,7 +73,7 @@ public class MiniTable extends CTable implements IMiniTable
/**
*
*/
private static final long serialVersionUID = 2209340448348079989L;
private static final long serialVersionUID = 2853772547464132496L;
/**
* Default Constructor
@ -747,14 +747,12 @@ public class MiniTable extends CTable implements IMiniTable
Object[] total = new Object[layout.length];
for (int row = 0 ; row < getRowCount(); row ++)
{
int colOffset = 1; // columns start with 1
{
for (int col = 0; col < layout.length; col++)
{
Object data = getModel().getValueAt(row, col);
Class<?> c = layout[col].getColClass();
int colIndex = col + colOffset;
if (c == BigDecimal.class)
{
BigDecimal subtotal = Env.ZERO;
@ -789,11 +787,9 @@ public class MiniTable extends CTable implements IMiniTable
int row = getRowCount() + 1;
setRowCount(row);
int colOffset = 1; // columns start with 1
for (int col = 0; col < layout.length; col++)
{
Class<?> c = layout[col].getColClass();
int colIndex = col + colOffset;
if (c == BigDecimal.class)
{
setValueAt(total[col] , row - 1, col);
@ -826,14 +822,12 @@ public class MiniTable extends CTable implements IMiniTable
Object[] total = new Object[layout.length];
for (int row = 0 ; row < getRowCount(); row ++)
{
int colOffset = 1; // columns start with 1
{
for (int col = 0; col < layout.length; col++)
{
Object data = getModel().getValueAt(row, col);
Class<?> c = layout[col].getColClass();
int colIndex = col + colOffset;
if (c == BigDecimal.class)
{
BigDecimal subtotal = Env.ZERO;
@ -868,11 +862,9 @@ public class MiniTable extends CTable implements IMiniTable
int row = getRowCount() + 1;
setRowCount(row);
int colOffset = 1; // columns start with 1
for (int col = 0; col < layout.length; col++)
{
Class<?> c = layout[col].getColClass();
int colIndex = col + colOffset;
if (c == BigDecimal.class)
{
setValueAt(total[col] , row - 1, col);

View File

@ -23,11 +23,8 @@ import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import javax.swing.table.TableColumn;
import org.adempiere.webui.event.TableValueChangeEvent;
import org.adempiere.webui.event.TableValueChangeListener;
import org.adempiere.webui.event.WTableModelEvent;
@ -1038,16 +1035,8 @@ public class WListbox extends Listbox implements IMiniTable, TableValueChangeLis
//no op
}
@Override
public TableColumn getColumn(int col) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return 0;
return getModel() != null ? getModel().getNoColumns() : 0;
}
}