private void init() {
// define combo on item types...
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());
}
}
colItemType.setDomain(d);
colItemType.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange()==e.SELECTED) {
try {
int selIndex = ((JComboBox)e.getSource()).getSelectedIndex();
Object selValue = d.getDomainPairList()[selIndex].getCode();
ItemTypeVO vo = (ItemTypeVO)itemTypes.get(selIndex);
treeLevelDataLocator.getTreeNodeParams().put(ApplicationConsts.PROGRESSIVE_HIE02,selValue);
treeLevelDataLocator.getTreeNodeParams().put(ApplicationConsts.COMPANY_CODE_SYS01,vo.getCompanyCodeSys01ITM02());
itemDataLocator.getLookupFrameParams().put(ApplicationConsts.COMPANY_CODE_SYS01,vo.getCompanyCodeSys01ITM02());
itemDataLocator.getLookupValidationParameters().put(ApplicationConsts.COMPANY_CODE_SYS01,vo.getCompanyCodeSys01ITM02());
// controlItemCode.setValue(null);
// controlItemCode.validateCode(null);
}
catch (Exception ex) {
}
}
}
});
// define grids...
gridSheets.setAutoLoadData(false);
docsPanel.getDocsGrid().setAutoLoadData(false);
gridSheets.setController(new ItemSheetsGridPanelController(this));
gridSheets.setGridDataLocator(gridDataLocator);
gridDataLocator.setServerMethodName("loadItemSheets");
gridSpareParts.setController(new SheetSparePartsController(this));
gridSpareParts.setGridDataLocator(gridDataLocator3);
gridDataLocator3.setServerMethodName("loadSheetSpareParts");
// define popup menu...
menuStart.setEnabled(false);
menuSave.setEnabled(false);
popup.add(menuStart);
popup.add(menuClear);
popup.add(menuSave);
menuStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
menuStart.setEnabled(false);
}
});
menuClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
points.clear();
imgPanel.repaint();
menuStart.setEnabled(true);
}
});
menuSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String polStr = "";
for (int i = 0; i < points.size(); i++) {
polStr += points.get(i) + "\n";
}
ItemSheetVO sheetVO = (ItemSheetVO) gridSheets.getVOListTableModel().getObjectForRow(gridSheets.getSelectedRow());
SubsheetVO vo = new SubsheetVO();
vo.setCompanyCodeSys01ITM30(sheetVO.getCompanyCodeSys01ITM25());
vo.setParentSheetCodeItm25ITM30(parentVO.getSheetCodeITM25());
vo.setSheetCodeItm25ITM30(sheetVO.getSheetCodeITM25());
vo.setPolygonITM30(polStr);
Response res = ClientUtils.getData("updateSubsheet", vo);
points.clear();
imgPanel.repaint();
menuStart.setEnabled(true);
if (res.isError()) {
OptionPane.showMessageDialog(MDIFrame.getInstance(),
res.getErrorMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
}
else {
Polygon pol = getPolygon(vo);
pols.set(gridSheets.getSelectedRow(), pol);
imgPanel.repaint();
}
}
});
// define image panel management...
imgPanel.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
try {
// check if user is over a matching region...
Polygon pol = null;
for (int i = 0; i < pols.size(); i++) {
pol = (Polygon) pols.get(i);
if (pol != null && pol.contains(e.getX(), e.getY())) {
imgPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
return;
}
}
imgPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
catch (Exception ex) {
ex.printStackTrace();
}
}
});
imgPanel.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
try {
imgPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
catch (Exception ex) {
}
}
public void mouseClicked(MouseEvent e) {
try {
if (e.getClickCount() == 1 && parentVO != null && bytes != null &&
gridSheets.getSelectedRow() != -1) {
if (SwingUtilities.isRightMouseButton(e) && !readOnly) {
popup.show(imgPanel, e.getX(), e.getY());
}
else if (SwingUtilities.isLeftMouseButton(e) && !menuStart.isEnabled()) {
// user has clicked on the image, in order to define a region...
points.add(e.getX() + "," + e.getY());
imgPanel.repaint();
}
else if (SwingUtilities.isLeftMouseButton(e) && menuStart.isEnabled()) {
// user has clicked on the image: check for a matching region...
Polygon pol = null;
for (int i = 0; i < pols.size(); i++) {
pol = (Polygon) pols.get(i);
if (pol != null && pol.contains(e.getX(), e.getY())) {
ItemSheetVO sheetVO = (ItemSheetVO) gridSheets.getVOListTableModel().getObjectForRow(i);
addLink(sheetVO);
break;
}
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
});
// define sheets lookup...
sheetDataLocator.setGridMethodName("loadItemSheets");
sheetDataLocator.setValidationMethodName("validateSheetCode");
colSheetCode.setLookupController(sheetController);
sheetController.setLookupDataLocator(sheetDataLocator);
sheetController.setFrameTitle("sheets");
sheetController.setLookupValueObjectClassName("org.jallinone.items.spareparts.java.ItemSheetVO");
Method[] mm = ItemSheetVO.class.getMethods();
String attr = null;
for(int i=0;i<mm.length;i++) {
if (mm[i].getName().startsWith("get") && mm[i].getName().endsWith("ITM25")) {
attr = mm[i].getName().substring(3);
attr = attr.substring(0,1).toLowerCase()+attr.substring(1);
sheetController.addLookup2ParentLink(attr,attr);
}
}
sheetController.setAllColumnVisible(false);
sheetController.setVisibleColumn("sheetCodeITM25", true);
sheetController.setVisibleColumn("descriptionSYS10", true);
sheetController.setPreferredWidthColumn("descriptionSYS10",250);
sheetController.setFramePreferedSize(new Dimension(370,500));
sheetController.addLookupListener(new LookupListener() {
public void codeValidated(boolean validated) {}
public void codeChanged(ValueObject parentVO,Collection parentChangedAttributes) {
ItemSheetVO vo = (ItemSheetVO)sheetController.getLookupVO();
gridSheets.getVOListTableModel().updateObjectAt(vo,gridSheets.getSelectedRow());
}
public void beforeLookupAction(ValueObject gridVO) {
sheetDataLocator.getLookupFrameParams().put(ApplicationConsts.COMPANY_CODE_SYS01,parentVO.getCompanyCodeSys01ITM25());
sheetDataLocator.getLookupFrameParams().put(ApplicationConsts.ID,parentVO.getSheetCodeITM25());
sheetDataLocator.getLookupFrameParams().put(ApplicationConsts.LEVEL,parentVO.getLevITM25().add(new BigDecimal(1)));
sheetDataLocator.getLookupValidationParameters().put(ApplicationConsts.COMPANY_CODE_SYS01,parentVO.getCompanyCodeSys01ITM25());
sheetDataLocator.getLookupValidationParameters().put(ApplicationConsts.ID,parentVO.getSheetCodeITM25());
sheetDataLocator.getLookupValidationParameters().put(ApplicationConsts.LEVEL,parentVO.getLevITM25().add(new BigDecimal(1)));
}
public void forceValidate() {}
});
// define spare parts lookup...
itemDataLocator.setGridMethodName("loadItems");
itemDataLocator.setValidationMethodName("validateItemCode");
colItemCode.setLookupController(itemController);
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("companyCodeSys01ITM01", "companyCodeSys01ITM27");
itemController.addLookup2ParentLink("itemCodeITM01", "itemCodeItm01ITM27");
itemController.addLookup2ParentLink("descriptionSYS10", "descriptionSYS10");
itemController.setAllColumnVisible(false);
itemController.setVisibleColumn("companyCodeSys01ITM01", true);
itemController.setVisibleColumn("itemCodeITM01", true);
itemController.setVisibleColumn("descriptionSYS10", true);
itemController.setPreferredWidthColumn("descriptionSYS10", 200);
itemController.setFramePreferedSize(new Dimension(650,500));
itemController.setShowErrorMessage(false);
itemController.addLookupListener(new LookupListener() {
public void codeValidated(boolean validated) {}
public void codeChanged(ValueObject parentVO,Collection parentChangedAttributes) {}
public void beforeLookupAction(ValueObject gridVO) {
itemDataLocator.getLookupFrameParams().put(ApplicationConsts.COMPANY_CODE_SYS01,parentVO.getCompanyCodeSys01ITM25());
itemDataLocator.getLookupValidationParameters().put(ApplicationConsts.COMPANY_CODE_SYS01,parentVO.getCompanyCodeSys01ITM25());
}
public void forceValidate() {}
});
// define sheets grid additional columns..
TextColumn tCol = null;
DateColumn dCol = null;
DecimalColumn nCol = null;
for(int i=0;i<10;i++) {
tCol = new TextColumn();
tCol.setColumnName("sProp"+i+"ITM25");
tCol.setColumnVisible(false);
tCol.setColumnRequired(false);
tCol.setPreferredWidth(80);
additionalCols.add(tCol);
gridSheets.getColumnContainer().add(tCol,null);
dCol = new DateColumn();
dCol.setColumnName("dProp"+i+"ITM25");
dCol.setColumnVisible(false);
dCol.setColumnRequired(false);
dCol.setPreferredWidth(80);
additionalCols.add(dCol);
gridSheets.getColumnContainer().add(dCol,null);
nCol = new DecimalColumn();
nCol.setColumnName("nProp"+i+"ITM25");
nCol.setColumnVisible(false);
nCol.setColumnRequired(false);
nCol.setPreferredWidth(60);
additionalCols.add(nCol);
gridSheets.getColumnContainer().add(nCol,null);
}
// retrieve levels info...
res = ClientUtils.getData("loadItemSheetLevels",null);
if (res.isError()) {
OptionPane.showMessageDialog(MDIFrame.getInstance(), res.getErrorMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
}
else {
java.util.List vos = ((VOListResponse)res).getRows();
ItemSheetLevelVO vo = null;
for(int i=0;i<vos.size();i++) {
vo = (ItemSheetLevelVO)vos.get(i);
levelsPerCompanyCode.put(vo.getCompanyCodeSys01ITM29()+"_"+vo.getLevITM29(),vo);
}
}
}