@Override public void loadData() throws AppException { Session session = HibernateUtils.openSession(); try { String code = txtKode.getText(); String barcode = txtBarcode.getText(); String name = txtNama.getText(); boolean disabled = rdBarangTidakAktif.isSelected(); ItemFacade facade = ItemFacade.getInstance(); List<Item> items = facade.search(code, barcode, name, disabled, session); XTableModel tableModel = (XTableModel) table.getModel(); tableModel.setRowCount(items.size()); for (int i = 0; i < items.size(); ++i) { Item item = items.get(i); tableModel.setValueAt( item.getCode(), i, tableParameters.get(ColumnEnum.CODE).getColumnIndex()); tableModel.setValueAt( item.getName(), i, tableParameters.get(ColumnEnum.NAME).getColumnIndex()); tableModel.setValueAt( Formatter.formatNumberToString(facade.calculateStock(item)), i, tableParameters.get(ColumnEnum.STOCK).getColumnIndex()); tableModel.setValueAt( item.getUnit(), i, tableParameters.get(ColumnEnum.UNIT).getColumnIndex()); tableModel.setValueAt( Formatter.formatNumberToString(facade.getLastBuyPrice(item)), i, tableParameters.get(ColumnEnum.BUY_PRICE).getColumnIndex()); tableModel.setValueAt( Formatter.formatNumberToString(item.getSellPrice()), i, tableParameters.get(ColumnEnum.SELL_PRICE).getColumnIndex()); tableModel.setValueAt(item.getId(), i, tableParameters.get(ColumnEnum.ID).getColumnIndex()); } } finally { session.close(); } }
public StockListDialog(Window parent) { super(parent); setTitle("Master Barang"); setPermissionCode(PermissionConstants.STOCK_LIST); getContentPane().setLayout(new MigLayout("", "[1000]", "[][300,grow][]")); table = new XJTable() { private static final long serialVersionUID = 1L; @Override public void rowSelected() { btnDetail.doClick(); } }; XTableUtils.initTable(table, tableParameters); XJPanel pnlFilter = new XJPanel(); getContentPane().add(pnlFilter, "cell 0 0,grow"); pnlFilter.setLayout(new MigLayout("", "[][grow][]", "[][][][grow]")); XJLabel lblKode = new XJLabel(); lblKode.setText("Kode Barang"); pnlFilter.add(lblKode, "cell 0 0"); txtKode = new XJTextField(); txtKode.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { /* * TODO Perbaiki supaya kalo pas key = alt+tab, ga usah load * data */ loadDataInThread(); } catch (Exception ex) { ExceptionHandler.handleException(StockListDialog.this, ex); } } }); pnlFilter.add(txtKode, "cell 1 0 2 1,growx"); txtKode.setColumns(10); XJLabel lblNama = new XJLabel(); lblNama.setText("Nama Barang"); pnlFilter.add(lblNama, "cell 0 1"); txtNama = new XJTextField(); txtNama.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { loadDataInThread(); } catch (Exception ex) { ExceptionHandler.handleException(StockListDialog.this, ex); } } }); pnlFilter.add(txtNama, "cell 1 1 2 1,growx"); txtNama.setColumns(10); lblBarcodef = new XJLabel(); lblBarcodef.setText("Barcode [F8]"); pnlFilter.add(lblBarcodef, "cell 0 2"); txtBarcode = new XJTextField(); txtBarcode.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { loadDataInThread(); } catch (Exception ex) { ExceptionHandler.handleException(StockListDialog.this, ex); } } }); pnlFilter.add(txtBarcode, "cell 1 2 2 1,growx"); XJPanel pnlRadioButton = new XJPanel(); pnlFilter.add(pnlRadioButton, "cell 1 3,grow"); pnlRadioButton.setLayout(new MigLayout("", "[]", "[][]")); rdBarangAktif = new XJRadioButton(); rdBarangAktif.setText("Barang Aktif"); pnlRadioButton.add(rdBarangAktif, "cell 0 0"); rdBarangAktif.setSelected(true); btnGroup.add(rdBarangAktif); rdBarangTidakAktif = new XJRadioButton(); rdBarangTidakAktif.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { try { loadDataInThread(); } catch (Exception ex) { ExceptionHandler.handleException(StockListDialog.this, ex); } } }); rdBarangTidakAktif.setText("Barang Tidak Aktif"); pnlRadioButton.add(rdBarangTidakAktif, "cell 0 1"); btnGroup.add(rdBarangTidakAktif); btnRefresh = new XJButton(); btnRefresh.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { loadDataInThread(); } catch (Exception ex) { ExceptionHandler.handleException(StockListDialog.this, ex); } } }); btnRefresh.setMnemonic('R'); btnRefresh.setText("<html><center>Refresh<br/>[Alt+R]</center></html>"); pnlFilter.add(btnRefresh, "cell 2 3,grow"); JScrollPane scrollPane = new JScrollPane(table); getContentPane().add(scrollPane, "cell 0 1,grow"); XJPanel panel = new XJPanel(); getContentPane().add(panel, "cell 0 2,alignx center,growy"); panel.setLayout(new MigLayout("", "[][][][]", "[]")); btnRegistrasi = new XJButton(); btnRegistrasi.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tambah(); } }); XJButton btnKeluar = new XJButton(); btnKeluar.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); btnKeluar.setText("<html><center>Keluar<br/>[Esc]</center></html>"); panel.add(btnKeluar, "cell 0 0"); panel.add(btnRegistrasi, "cell 1 0"); btnRegistrasi.setText("<html><center>Registrasi Barang Baru<br/>[F5]</center><html>"); btnDetail = new XJButton(); btnDetail.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { showDetail(); } catch (Exception ex) { ExceptionHandler.handleException(StockListDialog.this, ex); } } }); btnPrintBarcode = new XJButton(); btnPrintBarcode.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { printBarcode(); } catch (Exception ex) { ExceptionHandler.handleException(StockListDialog.this, ex); } } }); btnPrintBarcode.setText("<html><center>Print Barcode<br/>[F6]</center><html>"); panel.add(btnPrintBarcode, "cell 2 0"); btnDetail.setText("<html><center>Lihat Detail<br/>[Enter]</center></html>"); panel.add(btnDetail, "cell 3 0"); btnRefresh.doClick(); pack(); setLocationRelativeTo(parent); }