ArrayList currentSortedVersusColumns,
Class valueObjectType, Map otherGridParams) {
VariantsMatrixVO matrixVO = (VariantsMatrixVO)otherGridParams.get(ApplicationConsts.VARIANTS_MATRIX_VO);
ArrayList rows = new ArrayList();
CustomValueObject vo = null;
VariantsMatrixRowVO rowVO = null;
for(int i=0;i<matrixVO.getRowDescriptors().length;i++) {
rowVO = (VariantsMatrixRowVO)matrixVO.getRowDescriptors()[i];
vo = new CustomValueObject();
vo.setAttributeNameS0(rowVO.getRowDescription());
rows.add(vo);
}
return new VOListResponse(rows,false,rows.size());
}
});
grid.setValueObjectClassName("org.openswing.swing.customvo.java.CustomValueObject");
grid.getOtherGridParams().put(ApplicationConsts.VARIANTS_MATRIX_VO,vo);
grid.setReorderingAllowed(false);
grid.setVisibleStatusPanel(false);
// if (vo.getManagedVariants().length>1)
// grid.setHeaderHeight(grid.getHeaderHeight()*(vo.getManagedVariants().length-1));
// create grid columns...
ButtonColumn var1Col = new ButtonColumn();
var1Col.setColumnName("attributeNameS0");
var1Col.setEnableInReadOnlyMode(true);
var1Col.setShowAttributeValue(true);
var1Col.setHeaderColumnName(" ");
var1Col.setColumnSelectable(false);
grid.getColumnContainer().add(var1Col,null);
VariantsMatrixColumnVO colVO = null;
DecimalColumn col = null;
for(int i=0;i<vo.getColumnDescriptors().length;i++) {
colVO = (VariantsMatrixColumnVO)vo.getColumnDescriptors()[i];
col = new DecimalColumn();
col.setColumnSelectable(false);
col.setEditableOnEdit(true);
col.setHeaderColumnName(colVO.getColumnDescription());
col.setColumnName("attributeNameN"+i);
col.setColumnRequired(false);
col.setDecimals(vo.getDecimals());
col.setMinWidth(50);
col.setPreferredWidth(20+this.getFontMetrics(this.getFont()).stringWidth(col.getHeaderColumnName()));
grid.getColumnContainer().add(col,null);
}
if (vo.getColumnDescriptors().length==0) {
col = new DecimalColumn();
col.setColumnSelectable(false);
col.setEditableOnEdit(true);
col.setHeaderColumnName(" ");
col.setColumnName("attributeNameN0");
col.setDecimals(vo.getDecimals());
//col.setPreferredWidth(110*(vo.getManagedVariants().length-1));
col.setPreferredWidth(50);
grid.getColumnContainer().add(col,null);
}
grid.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
if (!onValidating)
grid.getTable().getGrid().stopCellEditing();
}
});
buttonsPanel.removeAll();
final VariantNameVO varVO = (VariantNameVO)getVariantsMatrixVO().getManagedVariants()[0];
buttonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT,5,5));
if (showButtons && vo.getManagedVariants().length>1) {
// create a buttons panel used to copy the same qty for all cells matching the same variant value...
for(int i=0;i<vo.getManagedVariants().length;i++) {
GenericButton btn = new GenericButton(new ImageIcon(ClientUtils.getImage("copy.gif")));
final VariantNameVO vnVO = (VariantNameVO)vo.getManagedVariants()[i];
btn.setButtonBehavior(Consts.BUTTON_IMAGE_AND_TEXT);
btn.setHorizontalTextPosition(SwingConstants.LEADING);
btn.setVerticalTextPosition(SwingConstants.CENTER);
btn.setText(vnVO.getDescriptionSYS10());
btn.setToolTipText(ClientSettings.getInstance().getResources().getResource("set the same value when matching the same")+" "+vnVO.getDescriptionSYS10());
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!onValidating)
grid.getTable().getGrid().stopCellEditing();
try {
int row = grid.getSelectedRow();
int col = grid.getTable().getGrid().getSelectedColumn();
if (row!=-1 && col!=-1 && grid.getTable().getGrid().getValueAt(row,col)!=null) {
BigDecimal qty = (BigDecimal)grid.getTable().getGrid().getValueAt(row,col);
VariantsMatrixRowVO currentRowVO = (VariantsMatrixRowVO)getVariantsMatrixVO().getRowDescriptors()[row];
VariantsMatrixColumnVO currentColVO = (VariantsMatrixColumnVO)getVariantsMatrixVO().getColumnDescriptors()[col-1];
String rowtype = null,rowcode = null;
String coltype = null,colcode = null;
String rowtypename = null,rowcodename = null;
String coltypename = null,colcodename = null;
if (getVariantsMatrixVO().getColumnDescriptors().length==0 ||
varVO.getTableName().equals(vnVO.getTableName())) {
rowtype = VariantsMatrixUtils.getVariantType(getVariantsMatrixVO(),currentRowVO);
rowcode = VariantsMatrixUtils.getVariantCode(getVariantsMatrixVO(),currentRowVO);
if (varVO.getTableName().equals("ITM11_VARIANTS_1")) {
rowtypename = "getVariantTypeITM06";
rowcodename = "getVariantCodeITM11";
}
else if (varVO.getTableName().equals("ITM12_VARIANTS_2")) {
rowtypename = "getVariantTypeITM07";
rowcodename = "getVariantCodeITM12";
}
else if (varVO.getTableName().equals("ITM13_VARIANTS_3")) {
rowtypename = "getVariantTypeITM08";
rowcodename = "getVariantCodeITM13";
}
else if (varVO.getTableName().equals("ITM14_VARIANTS_4")) {
rowtypename = "getVariantTypeITM09";
rowcodename = "getVariantCodeITM14";
}
else if (varVO.getTableName().equals("ITM15_VARIANTS_5")) {
rowtypename = "getVariantTypeITM10";
rowcodename = "getVariantCodeITM15";
}
}
else {
if (vnVO.getTableName().equals("ITM11_VARIANTS_1")) {
rowtype = currentRowVO.getVariantTypeITM06();
rowcode = currentRowVO.getVariantCodeITM11();
rowtypename = "getVariantTypeITM06";
rowcodename = "getVariantCodeITM11";
}
else if (vnVO.getTableName().equals("ITM12_VARIANTS_2")) {
coltype = currentColVO.getVariantTypeITM07();
colcode = currentColVO.getVariantCodeITM12();
coltypename = "getVariantTypeITM07";
colcodename = "getVariantCodeITM12";
}
else if (vnVO.getTableName().equals("ITM13_VARIANTS_3")) {
coltype = currentColVO.getVariantTypeITM08();
colcode = currentColVO.getVariantCodeITM13();
coltypename = "getVariantTypeITM08";
colcodename = "getVariantCodeITM13";
}
else if (vnVO.getTableName().equals("ITM14_VARIANTS_4")) {
coltype = currentColVO.getVariantTypeITM09();
colcode = currentColVO.getVariantCodeITM14();
coltypename = "getVariantTypeITM09";
colcodename = "getVariantCodeITM14";
}
else if (vnVO.getTableName().equals("ITM15_VARIANTS_5")) {
coltype = currentColVO.getVariantTypeITM10();
colcode = currentColVO.getVariantCodeITM15();
coltypename = "getVariantTypeITM10";
colcodename = "getVariantCodeITM15";
}
}
VariantsMatrixRowVO rowVO = null;
VariantsMatrixColumnVO colVO = null;
for(int r=0;r<grid.getVOListTableModel().getRowCount();r++) {
rowVO = (VariantsMatrixRowVO)getVariantsMatrixVO().getRowDescriptors()[r];
for (int c = 0;c < getVariantsMatrixVO().getColumnDescriptors().length;c++)
if (! (r == row && c + 1 == col)) {
colVO = (VariantsMatrixColumnVO) getVariantsMatrixVO().getColumnDescriptors()[c];
try {
if (rowtype!=null && rowcode!=null) {
if (rowtype.equals(rowVO.getClass().getMethod(rowtypename,new Class[0]).invoke(rowVO,new Object[0])) &&
rowcode.equals(rowVO.getClass().getMethod(rowcodename,new Class[0]).invoke(rowVO,new Object[0])))
grid.getVOListTableModel().setValueAt(qty, r, c + 1);
}
else if (coltype!=null && colcode!=null) {
if (coltype.equals(colVO.getClass().getMethod(coltypename,new Class[0]).invoke(colVO,new Object[0])) &&
colcode.equals(colVO.getClass().getMethod(colcodename,new Class[0]).invoke(colVO,new Object[0])))