[FR 1913527] - http://sourceforge.net/tracker/index.php?func=detail&aid=1913527&group_id=176962&atid=879335
Thanks goes to Michael Judd for developing this awesome functionality! I just backported it from trunk into stable. Regards, Fernando
This commit is contained in:
parent
061de127b3
commit
18071c1e3b
|
@ -520,7 +520,18 @@ public class MColumn extends X_AD_Column
|
|||
}
|
||||
//end vpj-cd e-evolution
|
||||
|
||||
|
||||
/**
|
||||
* Get Table Id for a column
|
||||
* @param ctx context
|
||||
* @param AD_Column_ID id
|
||||
* @param trxName transaction
|
||||
* @return MColumn
|
||||
*/
|
||||
public static int getTable_ID(Properties ctx, int AD_Column_ID, String trxName)
|
||||
{
|
||||
String sqlStmt = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
|
||||
return DB.getSQLValue(trxName, sqlStmt, AD_Column_ID);
|
||||
}
|
||||
|
||||
|
||||
} // MColumn
|
||||
|
|
|
@ -418,6 +418,12 @@ public abstract class Info extends CDialog
|
|||
if (layout[i].getColClass() == IDColumn.class)
|
||||
m_keyColumnIndex = i;
|
||||
}
|
||||
|
||||
// Table Selection (Invoked before setting column class so that row selection is enabled)
|
||||
p_table.setRowSelectionAllowed(true);
|
||||
p_table.addMouseListener(this);
|
||||
p_table.setMultiSelection(p_multiSelection);
|
||||
|
||||
// set editors (two steps)
|
||||
for (int i = 0; i < layout.length; i++)
|
||||
p_table.setColumnClass(i, layout[i].getColClass(), layout[i].isReadOnly(), layout[i].getColHeader());
|
||||
|
@ -435,11 +441,6 @@ public abstract class Info extends CDialog
|
|||
if (m_keyColumnIndex == -1)
|
||||
log.log(Level.SEVERE, "No KeyColumn - " + sql);
|
||||
|
||||
// Table Selection
|
||||
p_table.setRowSelectionAllowed(true);
|
||||
p_table.addMouseListener(this);
|
||||
p_table.setMultiSelection(p_multiSelection);
|
||||
|
||||
// Window Sizing
|
||||
parameterPanel.setPreferredSize(new Dimension (INFO_WIDTH, parameterPanel.getPreferredSize().height));
|
||||
//Begin - [FR 1823612 ] Product Info Screen Improvements
|
||||
|
@ -527,6 +528,7 @@ public abstract class Info extends CDialog
|
|||
// Multi Selection
|
||||
if (p_multiSelection)
|
||||
{
|
||||
m_results.addAll(getSelectedRowKeys());
|
||||
}
|
||||
else // singleSelection
|
||||
{
|
||||
|
@ -549,17 +551,67 @@ public abstract class Info extends CDialog
|
|||
*/
|
||||
protected Integer getSelectedRowKey()
|
||||
{
|
||||
int row = p_table.getSelectedRow();
|
||||
if (row != -1 && m_keyColumnIndex != -1)
|
||||
ArrayList<Integer> selectedDataList = getSelectedRowKeys();
|
||||
if (selectedDataList.size() == 0)
|
||||
{
|
||||
Object data = p_table.getModel().getValueAt(row, m_keyColumnIndex);
|
||||
if (data instanceof IDColumn)
|
||||
data = ((IDColumn)data).getRecord_ID();
|
||||
if (data instanceof Integer)
|
||||
return (Integer)data;
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return selectedDataList.get(0);
|
||||
}
|
||||
return null;
|
||||
} // getSelectedRowKey
|
||||
|
||||
/**
|
||||
* Get the keys of selected row/s based on layout defined in prepareTable
|
||||
* @return IDs if selection present
|
||||
* @author ashley
|
||||
*/
|
||||
protected ArrayList<Integer> getSelectedRowKeys()
|
||||
{
|
||||
ArrayList<Integer> selectedDataList = new ArrayList<Integer>();
|
||||
|
||||
if (m_keyColumnIndex == -1)
|
||||
{
|
||||
return selectedDataList;
|
||||
}
|
||||
|
||||
if (p_multiSelection)
|
||||
{
|
||||
int rows = p_table.getRowCount();
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
Object data = p_table.getModel().getValueAt(row, m_keyColumnIndex);
|
||||
if (data instanceof IDColumn)
|
||||
{
|
||||
IDColumn dataColumn = (IDColumn)data;
|
||||
if (dataColumn.isSelected())
|
||||
{
|
||||
selectedDataList.add(dataColumn.getRecord_ID());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log.severe("For multiple selection, IDColumn should be key column for selection");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedDataList.size() == 0)
|
||||
{
|
||||
int row = p_table.getSelectedRow();
|
||||
if (row != -1 && m_keyColumnIndex != -1)
|
||||
{
|
||||
Object data = p_table.getModel().getValueAt(row, m_keyColumnIndex);
|
||||
if (data instanceof IDColumn)
|
||||
selectedDataList.add(((IDColumn)data).getRecord_ID());
|
||||
if (data instanceof Integer)
|
||||
selectedDataList.add((Integer)data);
|
||||
}
|
||||
}
|
||||
|
||||
return selectedDataList;
|
||||
} // getSelectedRowKeys
|
||||
|
||||
/**
|
||||
* Get selected Keys
|
||||
|
@ -569,7 +621,9 @@ public abstract class Info extends CDialog
|
|||
{
|
||||
if (!m_ok || m_results.size() == 0)
|
||||
return null;
|
||||
return m_results.toArray();
|
||||
Integer values[] = new Integer[m_results.size()];
|
||||
m_results.toArray(values);
|
||||
return values;
|
||||
} // getSelectedKeys;
|
||||
|
||||
/**
|
||||
|
@ -786,12 +840,15 @@ public abstract class Info extends CDialog
|
|||
} // calueChanged
|
||||
|
||||
/**
|
||||
* Enable OK, History, Zoom if row selected
|
||||
* Enable OK, History, Zoom if row/s selected
|
||||
* ---
|
||||
* Changes: Changed the logic for accomodating multiple selection
|
||||
* @author ashley
|
||||
*/
|
||||
protected void enableButtons ()
|
||||
{
|
||||
boolean enable = p_table.getSelectedRow() != -1;
|
||||
confirmPanel.getOKButton().setEnabled(enable);
|
||||
boolean enable = (p_table.getSelectedRowCount() == 1);
|
||||
confirmPanel.getOKButton().setEnabled(p_table.getSelectedRowCount() > 0);
|
||||
|
||||
if (hasHistory())
|
||||
confirmPanel.getHistoryButton().setEnabled(enable);
|
||||
|
|
|
@ -936,7 +936,7 @@ public final class InfoProduct extends Info implements ActionListener
|
|||
if (s_productLayout == null)
|
||||
{
|
||||
ArrayList<Info_Column> list = new ArrayList<Info_Column>();
|
||||
list.add(new Info_Column(" ", "p.M_Product_ID", IDColumn.class));
|
||||
list.add(new Info_Column(" ", "p.M_Product_ID", IDColumn.class, !p_multiSelection));
|
||||
list.add(new Info_Column(Msg.translate(Env.getCtx(), "Discontinued").substring(0, 1), "p.Discontinued", Boolean.class));
|
||||
list.add(new Info_Column(Msg.translate(Env.getCtx(), "Value"), "p.Value", String.class));
|
||||
list.add(new Info_Column(Msg.translate(Env.getCtx(), "Name"), "p.Name", String.class));
|
||||
|
|
|
@ -48,6 +48,20 @@ public class Info_Column
|
|||
{
|
||||
this(colHeader, colSQL, colClass, true, false, IDcolSQL);
|
||||
} // Info_Column
|
||||
|
||||
/**
|
||||
* Create Info Column (not color column)
|
||||
*
|
||||
* @param colHeader Column Header
|
||||
* @param colSQL SQL select code for column
|
||||
* @param colClass class of column - determines display
|
||||
* @param readOnly column is read only
|
||||
* @author ashley
|
||||
*/
|
||||
public Info_Column (String colHeader, String colSQL, Class colClass, boolean readOnly)
|
||||
{
|
||||
this(colHeader, colSQL, colClass, readOnly, false, null);
|
||||
} // Info_Column
|
||||
|
||||
/**
|
||||
* Create Info Column
|
||||
|
|
|
@ -1037,6 +1037,53 @@ public class GridController extends CPanel
|
|||
} // rowChanged
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Save Multiple records - Clone a record and assign new values to each
|
||||
* clone for a specific column.
|
||||
* @param ctx context
|
||||
* @param tableName Table Name
|
||||
* @param columnName Column for which value need to be changed
|
||||
* @param recordId Record to clone
|
||||
* @param values Values to be assigned to clones for the specified column
|
||||
* @param trxName Transaction
|
||||
* @throws Exception If error is occured when loading the PO or saving clones
|
||||
*
|
||||
* @author ashley
|
||||
*/
|
||||
protected void saveMultipleRecords(Properties ctx, String tableName,
|
||||
String columnName, int recordId, Integer[] values,
|
||||
String trxName) throws Exception
|
||||
{
|
||||
if (values == null)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
int oldRow = m_mTab.getCurrentRow();
|
||||
GridField lineField = m_mTab.getField("Line");
|
||||
|
||||
for (int i = 0; i < values.length; i++)
|
||||
{
|
||||
if (!m_mTab.dataNew(true))
|
||||
{
|
||||
throw new IllegalStateException("Could not clone tab");
|
||||
}
|
||||
|
||||
m_mTab.setValue(columnName, values[i]);
|
||||
|
||||
if (lineField != null)
|
||||
{
|
||||
m_mTab.setValue(lineField, 0);
|
||||
}
|
||||
|
||||
if (!m_mTab.dataSave(false))
|
||||
{
|
||||
throw new IllegalStateException("Could not update tab");
|
||||
}
|
||||
|
||||
m_mTab.setCurrentRow(oldRow);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Vetoable Change Listener.
|
||||
|
@ -1104,7 +1151,38 @@ public class GridController extends CPanel
|
|||
else
|
||||
{
|
||||
// mTable.setValueAt (e.getNewValue(), row, col, true);
|
||||
mTable.setValueAt (e.getNewValue(), row, col); // -> dataStatusChanged -> dynamicDisplay
|
||||
/*
|
||||
* Changes: Added the logic below to handle multiple values for a single field
|
||||
* due to multiple selection in Lookup (Info).
|
||||
* @author ashley
|
||||
*/
|
||||
Object newValue = e.getNewValue();
|
||||
Integer newValues[] = null;
|
||||
|
||||
if (newValue instanceof Integer[])
|
||||
{
|
||||
newValues = ((Integer[])newValue);
|
||||
newValue = newValues[0];
|
||||
|
||||
if (newValues.length > 1)
|
||||
{
|
||||
Integer valuesCopy[] = new Integer[newValues.length - 1];
|
||||
System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
|
||||
newValues = valuesCopy;
|
||||
}
|
||||
else
|
||||
{
|
||||
newValues = null;
|
||||
}
|
||||
}
|
||||
else if (newValue instanceof Object[])
|
||||
{
|
||||
log.severe("Multiple values can only be processed for IDs (Integer)");
|
||||
throw new PropertyVetoException("Multiple Selection values not available for this field", e);
|
||||
}
|
||||
|
||||
mTable.setValueAt (newValue, row, col); // -> dataStatusChanged -> dynamicDisplay
|
||||
|
||||
// Force Callout
|
||||
if (e.getPropertyName().equals("S_ResourceAssignment_ID"))
|
||||
{
|
||||
|
@ -1112,6 +1190,37 @@ public class GridController extends CPanel
|
|||
if (mField != null && mField.getCallout().length() > 0)
|
||||
m_mTab.processFieldChange(mField); // Dependencies & Callout
|
||||
}
|
||||
|
||||
if (newValues != null && newValues.length > 0)
|
||||
{
|
||||
// Save data, since record need to be used for generating clones.
|
||||
if (!m_mTab.dataSave(false))
|
||||
{
|
||||
throw new PropertyVetoException("SaveError", e);
|
||||
}
|
||||
|
||||
// Retrieve the current record ID
|
||||
int recordId = m_mTab.getKeyID(m_mTab.getCurrentRow());
|
||||
|
||||
Trx trx = Trx.get(Trx.createTrxName(), true);
|
||||
trx.start();
|
||||
try
|
||||
{
|
||||
saveMultipleRecords(Env.getCtx(), mTable.getTableName(), e.getPropertyName(), recordId, newValues, trx.getTrxName());
|
||||
trx.commit();
|
||||
m_mTab.dataRefreshAll();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
trx.rollback();
|
||||
log.severe(ex.getMessage());
|
||||
throw new PropertyVetoException("SaveError", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
trx.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log.config( "GridController.vetoableChange (" + m_mTab.toString() + ") - fini", e.getPropertyName() + "=" + e.getNewValue());
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue