/** * Static function for exporting a JXTable to a CSV text file * * @param table - table to export * @param file - file to export to */ public static void exportToCSV(JXTable table, File file) { int i = 0; int j = 0; try { TableModel model = table.getModel(); FileWriter csv = new FileWriter(file); for (i = 0; i < model.getColumnCount(); i++) { csv.write(model.getColumnName(i) + ","); } csv.write(System.getProperty("line.separator")); for (i = 0; i < model.getRowCount(); i++) { for (j = 0; j < (model.getColumnCount()); j++) { if (model.getValueAt(i, j) == null) { csv.write("" + ","); } else { csv.write(model.getValueAt(i, j).toString() + ","); } } csv.write(System.getProperty("line.separator")); } csv.close(); } catch (IOException e) { JOptionPane.showMessageDialog( App.mainFrame, "Error saving file '" + file.getName() + "'\n" + e.getLocalizedMessage()); e.printStackTrace(); } }
private void deleteCitaSelected() { int index = getSelected(masterTable); EntityTableModel etm = (EntityTableModel) masterTable.getModel(); Cita c = (Cita) etm.getBeanAt(index); em.getTransaction().begin(); em.remove(c); em.getTransaction().commit(); filterSearch(); }
public void repopulateTable() { populateTable(); iProductsTable.scrollRowToVisible(0); TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>((DefaultTableModel) iProductsTable.getModel()); iProductsTable.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 0; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); }
/** * DOCUMENT ME! * * @param evt DOCUMENT ME! */ private void cbxAbgearbeitetActionPerformed(final java.awt.event.ActionEvent evt) { try { final int displayedIndex = jXTable1.getSelectedRow(); final int modelIndex = jXTable1.getFilters().convertRowIndexToModel(displayedIndex); final CidsBean selectedFortfuehrungBean = ((FortfuehrungenTableModel) jXTable1.getModel()).getCidsBeanByIndex(modelIndex); selectedFortfuehrungBean.setProperty( FortfuehrungPropertyConstants.PROP__IST_ABGEARBEITET, cbxAbgearbeitet.isSelected()); selectedFortfuehrungBean.persist(); jXTable1.repaint(); } catch (Exception ex) { LOG.error("fehler beim setzen von ist_abgearbeitet", ex); } }
private void getAllBrandTypes() throws ClassNotFoundException, SQLException { ArrayList<Brand> allBrands = BrandController.getAllBrands(); DefaultTableModel dtm = (DefaultTableModel) brandTable.getModel(); dtm.setRowCount(0); for (Brand brand : allBrands) { dtm.addRow(new Object[] {brand.getBrandId(), brand.getBrand()}); } int size = allBrands.size(); if (size != 0) { generateId(allBrands.get(size - 1).getBrandId()); } else { brandIdTextField.setText("B-001"); brandTextField.setText(""); } }
public InventoryController(App view, final Connection connection) { this.view = view; model = new InventoryModel(connection); addItem = new AddItem(); iSupplierList = addItem.getiSupplierList(); iProductLineList = addItem.getiProductLineList(); iSupplierCodeText = addItem.getiSupplierCodeText(); iUnitPriceText = addItem.getiUnitPriceText(); iSellingPriceText = addItem.getiSellingPriceText(); iQtyText = addItem.getiQtyText(); iThresholdText = addItem.getiThresholdText(); iCharacteristics = addItem.getiCharacteristicsText(); iModelText = addItem.getiModelText(); iDescriptionText = addItem.getiDescriptionText(); iSearchField = view.getiSearchField(); iProductsTable = view.getiProductsTable(); tableModel = (DefaultTableModel) iProductsTable.getModel(); selectionModel = (ListSelectionModel) iProductsTable.getSelectionModel(); iProductName = view.getiProductName(); iItemNumber = view.getiItemNo(); iAddMotoCode = view.getiAddMotoCode(); iProductLine = view.getiProductLine(); iItemDescription = view.getiItemDescription(); iOnHandQuantity = view.getiOnHandQuantity(); iStatus = view.getiStatus(); iSupplier = view.getiSupplier(); iShowHistory = view.getiShowHistory(); iEditUpdateRSP = view.getiEditUpdateRSP(); iEditUpdateUC = view.getiEditUpdateUC(); iEditUpdateQT = view.getiEditUpdateQT(); iCancelRSP = view.getiCancelRSP(); iCancelUC = view.getiCancelUC(); iCancelQT = view.getiCancelQT(); iSellingPrice = view.getiSellingPrice(); iSellingPrice.setDisabledTextColor(Color.BLACK); iUnitCost = view.getiUnitCost(); iUnitCost.setDisabledTextColor(Color.BLACK); iQtyThreshold = view.getiThreshold(); iQtyThreshold.setDisabledTextColor(Color.BLACK); iAddNew = view.getiAddNew(); iAddNewPLine = view.getiAddNewPLine(); setDefaultViews(); populate(); setListeners(); }
/** * DOCUMENT ME! * * @param e DOCUMENT ME! */ private void fortfuehrungsTableListSelectionChanged(final ListSelectionEvent e) { final int selectedIndex = jXTable1.getSelectedRow(); final CidsBean selectedFortfuehrungBean; if (selectedIndex >= 0) { final int rowIndex = jXTable1.convertRowIndexToModel(selectedIndex); selectedFortfuehrungBean = ((FortfuehrungenTableModel) jXTable1.getModel()).getCidsBeanByIndex(rowIndex); } else { selectedFortfuehrungBean = null; } if (selectedFortfuehrungBean != null) { new SwingWorker<Set<Integer>, Void>() { @Override protected Set<Integer> doInBackground() throws Exception { lstKassenzeichen.setEnabled(false); cbxAbgearbeitet.setEnabled(false); jProgressBar1.setVisible(true); final List<CidsBean> geomBeans = (List<CidsBean>) selectedFortfuehrungBean.getBeanCollectionProperty( FortfuehrungPropertyConstants.PROP__GEOMETRIEN); final KassenzeichenGeomSearch geomSearch = new KassenzeichenGeomSearch(); final Set<Integer> kassenzeichennummern = new HashSet<Integer>(); for (final CidsBean geomBean : geomBeans) { if (geomBean != null) { try { final Geometry geom = (Geometry) geomBean.getProperty(GeomPropertyConstants.PROP__GEO_FIELD); geomSearch.setGeometry(geom.buffer(FLURSTUECKBUFFER_FOR_KASSENZEICHEN_GEOMSEARCH)); kassenzeichennummern.addAll( (Collection<Integer>) SessionManager.getProxy() .customServerSearch(SessionManager.getSession().getUser(), geomSearch)); } catch (final Exception ex) { LOG.error("fehler beim suchen von kassenzeichen über eine geometrie", ex); } } } return kassenzeichennummern; } @Override protected void done() { try { final Set<Integer> kassenzeichennummern = get(); setDetailEnabled(true); setKassenzeichenNummern(kassenzeichennummern); cbxAbgearbeitet.setSelected( (Boolean) selectedFortfuehrungBean.getProperty( FortfuehrungPropertyConstants.PROP__IST_ABGEARBEITET)); final CidsBean urlBean = (CidsBean) selectedFortfuehrungBean.getProperty( FortfuehrungPropertyConstants.PROP__DOKUMENTURL); final String protPrefix = (String) urlBean.getProperty("url_base_id.prot_prefix"); final String server = (String) urlBean.getProperty("url_base_id.server"); final String path = (String) urlBean.getProperty("url_base_id.path"); final String objectName = (String) urlBean.getProperty("object_name"); final String urlString = protPrefix + server + path + objectName; setDokumentLink(urlString); } catch (final Exception ex) { setKassenzeichenNummern(null); cbxAbgearbeitet.setSelected(false); LOG.fatal("", ex); } lstKassenzeichen.setEnabled(true); cbxAbgearbeitet.setEnabled(true); jProgressBar1.setVisible(false); } }.execute(); } else { setDetailEnabled(false); setKassenzeichenNummern(null); cbxAbgearbeitet.setSelected(false); setDokumentLink(null); } }