Example #1
0
 /** Creates new form ViewProductsDialog */
 public ViewProductsDialog(java.awt.Frame parent, boolean modal, ProductDao dao) {
   super(parent, modal);
   this.dao = dao;
   productModel = new ProductListModel(dao.getAll());
   categoryModel = new ProductListModel(dao.getCategories());
   initComponents();
   lstProducts.setModel(productModel);
 }
Example #2
0
 private void btnSearchActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSearchActionPerformed
   String id = txtSearch.getText(); // Get the ID from the text field.
   if (id.isEmpty()) {
     productModel.updateItems(dao.getAll());
   } else {
     productModel.updateItems(
         dao.getById(id)); // Update the model with the product that is retrieved from getById.
   }
 } // GEN-LAST:event_btnSearchActionPerformed
Example #3
0
 private void btnDeleteActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnDeleteActionPerformed
   Product product = (Product) lstProducts.getSelectedValue();
   int result =
       JOptionPane.showConfirmDialog(
           this,
           "Are you sure you want to delete Product ID:"
               + product.getProductID()
               + ", Name: "
               + product.getName());
   if (result == JOptionPane.YES_OPTION) {
     dao.delete(product);
   }
   productModel.updateItems(dao.getAll());
 } // GEN-LAST:event_btnDeleteActionPerformed
Example #4
0
  private void btnEditActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnEditActionPerformed
    Product product = (Product) lstProducts.getSelectedValue();
    if (product == null) {
      JOptionPane.showMessageDialog(
          this,
          "You have not selected a product to edit.",
          "Inane error",
          JOptionPane.ERROR_MESSAGE);

    } else {
      ProductEditorDialog peDialog = new ProductEditorDialog(this, true, product, dao);
      peDialog.setVisible(true);
      productModel.updateItems(dao.getAll());
    } // GEN-LAST:event_btnEditActionPerformed
  }