private void init() {
Response res = ClientUtils.getData("loadItemTypes",new GridParams());
final Domain d = new Domain("ITEM_TYPES");
if (!res.isError()) {
ItemTypeVO vo = null;
itemTypes = ((VOListResponse)res).getRows();
for(int i=0;i<itemTypes.size();i++) {
vo = (ItemTypeVO)itemTypes.get(i);
d.addDomainPair(vo.getProgressiveHie02ITM02(),vo.getDescriptionSYS10());
}
}
controlItemType.setDomain(d);
controlItemType.getComboBox().addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == e.SELECTED) {
int selIndex = ( (JComboBox) e.getSource()).getSelectedIndex();
Object selValue = d.getDomainPairList()[selIndex].getCode();
ItemTypeVO vo = (ItemTypeVO)itemTypes.get(controlItemType.getSelectedIndex());
treeLevelDataLocator.getTreeNodeParams().put(ApplicationConsts.COMPANY_CODE_SYS01, vo.getCompanyCodeSys01ITM02());
treeLevelDataLocator.getTreeNodeParams().put(ApplicationConsts.PROGRESSIVE_HIE02, selValue);
}
}
});
// item code lookup...
itemDataLocator.setGridMethodName("loadItems");
itemDataLocator.setValidationMethodName("validateItemCode");
controlItem.setLookupController(itemController);
controlItem.setControllerMethodName("getItemsList");
itemController.setForm(filterPanel);
itemController.setLookupDataLocator(itemDataLocator);
itemController.setFrameTitle("items");
itemController.setCodeSelectionWindow(itemController.TREE_GRID_FRAME);
treeLevelDataLocator.setServerMethodName("loadCompanyHierarchy");
itemDataLocator.setTreeDataLocator(treeLevelDataLocator);
itemDataLocator.setNodeNameAttribute("descriptionSYS10");
itemController.setLookupValueObjectClassName("org.jallinone.items.java.GridItemVO");
itemController.addLookup2ParentLink("itemCodeITM01", "itemCode");
itemController.setAllColumnVisible(false);
itemController.setVisibleColumn("itemCodeITM01", true);
itemController.setVisibleColumn("descriptionSYS10", true);
itemController.setPreferredWidthColumn("descriptionSYS10", 250);
itemController.setFramePreferedSize(new Dimension(680,500));
itemController.addLookupListener(new LookupListener() {
public void codeValidated(boolean validated) {}
public void codeChanged(ValueObject parentVO,Collection parentChangedAttributes) {
if (itemController.getLookupVO()==null) {
controlITemDescr.setText("");
}
else {
GridItemVO vo = (GridItemVO)itemController.getLookupVO();
controlITemDescr.setText(vo.getDescriptionSYS10());
}
}
public void beforeLookupAction(ValueObject parentVO) {
itemController.getLookupDataLocator().getLookupFrameParams().put(ApplicationConsts.PROGRESSIVE_HIE02,controlItemType.getValue());
itemController.getLookupDataLocator().getLookupFrameParams().put(ApplicationConsts.COMPANY_CODE_SYS01,controlComp.getValue());
itemController.getLookupDataLocator().getLookupValidationParameters().put(ApplicationConsts.PROGRESSIVE_HIE02,controlItemType.getValue());
itemController.getLookupDataLocator().getLookupValidationParameters().put(ApplicationConsts.COMPANY_CODE_SYS01,controlComp.getValue());
}
public void forceValidate() {}
});
// customer lookup...
customerDataLocator.setGridMethodName("loadCustomers");
customerDataLocator.setValidationMethodName("validateCustomerCode");
controlCust.setLookupController(customerController);
controlCust.setControllerMethodName("getCustomersList");
customerController.setForm(filterPanel);
customerController.setLookupDataLocator(customerDataLocator);
customerController.setFrameTitle("customers");
customerController.setLookupValueObjectClassName("org.jallinone.sales.customers.java.GridCustomerVO");
customerController.addLookup2ParentLink("customerCodeSAL07","customerCode");
customerController.setAllColumnVisible(false);
customerController.setVisibleColumn("companyCodeSys01REG04", true);
customerController.setFilterableColumn("companyCodeSys01REG04", true);
customerController.setFilterableColumn("customerCodeSAL07", true);
customerController.setFilterableColumn("name_1REG04", true);
customerController.setFilterableColumn("name_2REG04", true);
customerController.setFilterableColumn("cityREG04", true);
customerController.setFilterableColumn("provinceREG04", true);
customerController.setSortableColumn("companyCodeSys01REG04", true);
customerController.setSortableColumn("customerCodeSAL07", true);
customerController.setSortableColumn("name_1REG04", true);
customerController.setSortableColumn("name_2REG04", true);
customerController.setSortableColumn("cityREG04", true);
customerController.setSortableColumn("provinceREG04", true);
customerController.setVisibleColumn("customerCodeSAL07", true);
customerController.setVisibleColumn("name_1REG04", true);
customerController.setVisibleColumn("name_2REG04", true);
customerController.setVisibleColumn("cityREG04", true);
customerController.setVisibleColumn("provinceREG04", true);
customerController.setVisibleColumn("countryREG04", true);
customerController.setVisibleColumn("taxCodeREG04", true);
customerController.setHeaderColumnName("cityREG04", "city");
customerController.setHeaderColumnName("provinceREG04", "prov");
customerController.setHeaderColumnName("countryREG04", "country");
customerController.setHeaderColumnName("taxCodeREG04", "taxCode");
customerController.setPreferredWidthColumn("name_1REG04", 200);
customerController.setPreferredWidthColumn("name_2REG04", 150);
customerController.setFramePreferedSize(new Dimension(750,500));
customerController.addLookupListener(new LookupListener() {
public void codeValidated(boolean validated) {}
public void codeChanged(ValueObject parentVO,Collection parentChangedAttributes) {
if (customerController.getLookupVO()==null) {
controlCustName1.setText("");
controlCustName2.setText("");
}
else {
GridCustomerVO vo = (GridCustomerVO)customerController.getLookupVO();
controlCustName1.setText(vo.getName_1REG04());
controlCustName2.setText(vo.getName_2REG04());
}
}
public void beforeLookupAction(ValueObject parentVO) {
customerDataLocator.getLookupFrameParams().put(ApplicationConsts.COMPANY_CODE_SYS01,controlComp.getValue());
customerDataLocator.getLookupValidationParameters().put(ApplicationConsts.COMPANY_CODE_SYS01,controlComp.getValue());
}
public void forceValidate() {}
});
pivotTable.setController(new PivotTableController(){
public Response getPivotTableModel(PivotTableParameters pars) {
filterPanel.pull();
SalesPivotVO vo= (SalesPivotVO)filterPanel.getVOModel().getValueObject();
vo.setPivotPars(pars);
pars.setInputFilter(new InputFilter());
Response res = ClientUtils.getData("salesPivot",vo);
if (res.isError())
OptionPane.showMessageDialog(SalesPivotFrame.this,res.getErrorMessage(),"Error while loading data",JOptionPane.ERROR_MESSAGE);
return res;
}
});
RowField rowFieldItem = new RowField("itemCodeItm01DOC02",100);
RowField rowFieldCustomer = new RowField("customerCodeSAL07",150);
RowField rowFieldWarehouse = new RowField("warehouseCodeWar01DOC01",100);
pivotTable.getAllRowFields().add(rowFieldItem);
pivotTable.getAllRowFields().add(rowFieldCustomer);
pivotTable.getAllRowFields().add(rowFieldWarehouse);
pivotTable.addRowField(rowFieldWarehouse);
// pivotTable.addRowField(rowFieldItem);
ColumnField columnFieldYear = new ColumnField("docDateDOC01","year",new YearAggregator());
ColumnField columnFieldQuarter = new ColumnField("docDateDOC01","quarter",new QuarterAggregator());
pivotTable.getAllColumnFields().add(columnFieldYear);
pivotTable.getAllColumnFields().add(columnFieldQuarter);
pivotTable.addColumnField(columnFieldYear);
pivotTable.addColumnField(columnFieldQuarter);
NumberFormat nf = NumberFormat.getCurrencyInstance();
Currency currency = Currency.getInstance(Locale.getDefault()); // to review...
nf.setCurrency(currency);
nf.setMaximumFractionDigits(2);
nf.setMinimumFractionDigits(2);
nf.setGroupingUsed(true);
DataField dataFieldTotal = new DataField("totalDOC01",80,"sellAmount",new SumFunction()); // sum function...
dataFieldTotal.setFormatter(nf);
NumberFormat nf2 = NumberFormat.getIntegerInstance();
DataField dataFieldItemQty = new DataField("qtyDOC02",80,"sellQty",new SumFunction()); // sum function...
dataFieldItemQty.setFormatter(nf2);
pivotTable.getAllDataFields().add(dataFieldTotal);
pivotTable.getAllDataFields().add(dataFieldItemQty);
pivotTable.addDataField(dataFieldTotal);
pivotTable.setDataFieldRenderer(new DataFieldRenderer() {
/**
* @param currentColor current color to set
* @param rowPath GenericNodeKey row fields path that identify current row
* @param colPath GenericNodeKey column fields path that identify current column
* @param value value to show in the specified cell
* @param row current row
* @param col current column
* @return Color background color to set
*/
public Color getBackgroundColor(Color currentColor,GenericNodeKey rowPath,GenericNodeKey colPath,Object value,int row,int col) {
if (rowPath.getPath().length<pivotTable.getPivotTableParameters().getRowFields().size() ||
colPath.getPath().length<pivotTable.getPivotTableParameters().getColumnFields().size()+1) {
int c = 200+rowPath.getPath().length*colPath.getPath().length*5;
return new Color(c,c,c);
}
return currentColor;
}
/**
* @param currentColor current color to set
* @param rowPath GenericNodeKey row fields path that identify current row
* @param colPath GenericNodeKey column fields path that identify current column
* @param value value to show in the specified cell
* @param row current row
* @param col current column
* @return Color foreground color to set
*/
public Color getForegroundColor(Color currentColor,GenericNodeKey rowPath,GenericNodeKey colPath,Object value,int row,int col) {
return currentColor;
}
/**
* @param currentFont current font to set
* @param rowPath GenericNodeKey row fields path that identify current row
* @param colPath GenericNodeKey column fields path that identify current column
* @param value value to show in the specified cell
* @param row current row
* @param col current column
* @return font to set
*/
public Font getFont(Font currentFont,GenericNodeKey rowPath,GenericNodeKey colPath,Object value,int row,int col) {
if (rowPath.getPath().length<pivotTable.getPivotTableParameters().getRowFields().size() ||
colPath.getPath().length<pivotTable.getPivotTableParameters().getColumnFields().size()+1)
return new Font(currentFont.getFontName(),Font.BOLD,currentFont.getSize());
return currentFont;
}
});
controlComp.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
Object companyCodeSys01 = controlComp.getValue();
if (companyCodeSys01==null)
companyCodeSys01 = controlComp.getDomain().getDomainPairList()[0].getCode();
SalesPivotVO vo= (SalesPivotVO)filterPanel.getVOModel().getValueObject();
vo.setCompanyCode((String)companyCodeSys01);
}
});
}