/*
* Copyright (c) 2010-2012 Thiago T. Sá
*
* This file is part of CloudReports.
*
* CloudReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CloudReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For more information about your rights as a user of CloudReports,
* refer to the LICENSE file or see <http://www.gnu.org/licenses/>.
*/
package cloudreports.gui.customers;
import cloudreports.dao.CustomerRegistryDAO;
import cloudreports.gui.CloudTree;
import cloudreports.gui.Dialog;
import cloudreports.gui.MainView;
import cloudreports.models.CustomerRegistry;
/**
* The RemoveCustomer form.
* Most of its code is generated automatically by the NetBeans IDE.
*
* @author Thiago T. Sá
* @since 1.0
*/
public class RemoveCustomer extends javax.swing.JDialog {
/** The instance of the main form's CloudTree. */
private CloudTree tree;
/** Creates a new RemoveUserGroup form. */
public RemoveCustomer(CloudTree tree) {
this.tree=tree;
initComponents();
int i=0;
CustomerRegistryDAO crDAO = new CustomerRegistryDAO();
for(CustomerRegistry c : crDAO.getListOfCustomers()) {
jComboBox1.insertItemAt(c.getName(), i);
i++;
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
cancelButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Remove Customer");
setModal(true);
setResizable(false);
jLabel1.setText("Select a customer to be removed:");
cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/cancel.png"))); // NOI18N
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
okButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/ok.png"))); // NOI18N
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 208, Short.MAX_VALUE)
.addComponent(okButton)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cancelButton))
.addComponent(jLabel1))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(okButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Removes the selected customer when the OK button is clicked.
*
* @param evt an action event.
* @since 1.0
*/
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
String name = (String) jComboBox1.getSelectedItem();
CustomerRegistryDAO crDAO = new CustomerRegistryDAO();
if(crDAO.removeCustomerRegistry(name)) {
MainView.setUserGroupModified(true);
tree.removeNode(name, 1);
dispose();
}
else {
Dialog.showWarning(this, "Error deleting user group.\nPlease try again.");
}
}//GEN-LAST:event_okButtonActionPerformed
/**
* Closes the form when the Cancel button is clicked.
*
* @param evt an action event.
* @since 1.0
*/
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
}