/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DlgAddService.java
*
* Created on 26.02.2009, 12:36:21
*/
package clips.directory.editors.serviceGroup;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.SelectorEditableExceptional;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.directory.complex.DirectoryServicesGroupItem;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import clips.delegate.directory.simple.serviceClass.DirectoryServiceClass;
import clips.delegate.directory.simple.serviceClass.DirectoryServiceClassItem;
import beans.directory.service.entity.ServiceDetails;
/**
*
* @author lacoste
*/
public class DlgAddService extends ModalDialog {
private DirectoryServicesGroupItem group;
private DirectoryServiceItem service;
/** Creates new form DlgAddService */
public DlgAddService(java.awt.Frame parent, DirectoryServicesGroupItem group_) throws ClipsException {
super(parent, "Создание новой услуги", null);
initComponents();
this.group = group_;
tfGroupCodePref.setText(group.getFullCode());
DirectoryServiceClass dirClass = DirectoryLocator.getDirectory(DirectoryServiceClass.class);
SelectorEditableExceptional<DirectoryServiceClassItem> it = dirClass.getItems();
for(int i=0; i<it.size(); i++) {
cbClass.addItem(it.get(i));
}
StateSaver.attachTo(this);
}
public DirectoryServiceItem getDlgService() {
return service;
}
/** 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() {
pnlNewNode = new javax.swing.JPanel();
jPanel9 = new javax.swing.JPanel();
tfName = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jPanel8 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jPanel7 = new javax.swing.JPanel();
tfGroupCode = new javax.swing.JTextField();
tfGroupCodePref = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
btOk = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
cbClass = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Создание новой услуги");
pnlNewNode.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
pnlNewNode.setLayout(new java.awt.GridLayout(2, 1, 3, 3));
jPanel9.setLayout(new java.awt.BorderLayout());
jPanel9.add(tfName, java.awt.BorderLayout.CENTER);
jLabel2.setText("Название услуги:");
jLabel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 10));
jPanel9.add(jLabel2, java.awt.BorderLayout.WEST);
pnlNewNode.add(jPanel9);
jPanel8.setLayout(new java.awt.BorderLayout());
jLabel3.setText("Код:");
jLabel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 10));
jPanel8.add(jLabel3, java.awt.BorderLayout.WEST);
jPanel7.setLayout(new java.awt.BorderLayout());
jPanel7.add(tfGroupCode, java.awt.BorderLayout.CENTER);
tfGroupCodePref.setEditable(false);
jPanel7.add(tfGroupCodePref, java.awt.BorderLayout.LINE_START);
jPanel8.add(jPanel7, java.awt.BorderLayout.CENTER);
pnlNewNode.add(jPanel8);
jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
btOk.setText("Оk");
btOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOkActionPerformed(evt);
}
});
jPanel1.add(btOk);
btCancel.setText("Отмена");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancelActionPerformed(evt);
}
});
jPanel1.add(btCancel);
jPanel2.setLayout(new java.awt.GridLayout(2, 1, 0, 3));
jLabel1.setText("Укажите класс услуги");
jPanel2.add(jLabel1);
jPanel2.add(cbClass);
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()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 658, Short.MAX_VALUE)
.addContainerGap())
.addComponent(pnlNewNode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 682, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 682, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlNewNode, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(6, 6, 6))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed
DirectoryServiceClassItem servClass = (DirectoryServiceClassItem) cbClass.getSelectedItem();
if (servClass != null && servClass.getID() != 0
&& !tfGroupCode.getText().isEmpty() && !tfName.getText().isEmpty()) {
ServiceDetails d = new ServiceDetails();
d.id = 0;
d.title = tfName.getText();
d.code = tfGroupCode.getText();
d.serviceClass = servClass.getID();
d.defaultDuration = 0;
d.description = "";
d.serviceGroup = group.getID();
service = new DirectoryServiceItem(d);
setDlgResult(ModalDialog.DLG_OK);
dispose();
}
else {
MessageBox.showWarning(MessageBox.W_NEED_TO_SET_FIELDS);
}
}//GEN-LAST:event_btOkActionPerformed
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
setDlgResult(ModalDialog.DLG_CANCEL);
dispose();
}//GEN-LAST:event_btCancelActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOk;
private javax.swing.JComboBox cbClass;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JPanel jPanel9;
private javax.swing.JPanel pnlNewNode;
private javax.swing.JTextField tfGroupCode;
private javax.swing.JTextField tfGroupCodePref;
private javax.swing.JTextField tfName;
// End of variables declaration//GEN-END:variables
}