/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DialogSelectFunctions.java
*
* Created on 22.06.2009, 17:44:43
*/
package clips.doctor;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.accountant.TableModelFunctions;
import clips.delegate.directory.complex.DirectoryCollaboratorFunctionsItem;
import java.util.ArrayList;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
*
* @author petr
*/
public class DialogSelectFunctions extends ModalDialog {
private ArrayList<DirectoryCollaboratorFunctionsItem> items;
private int row;
/** Creates new form DialogSelectFunctions */
public DialogSelectFunctions(java.awt.Frame parent, ArrayList<DirectoryCollaboratorFunctionsItem> list) {
super(parent, "Выбор исполняемых обязанностей", null);
initComponents();
items = list;
tblFunctions.setModel(new TableModelFunctions(list));
tblFunctions.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tblFunctions.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
btOk.setEnabled(tblFunctions.getSelectedRowCount()==1);
}
});
StateSaver.attachTo(this);
}
/** 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() {
jScrollPane1 = new javax.swing.JScrollPane();
tblFunctions = new cli_fmw.utils.sorted_table.SortedTable();
btOk = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
tblFunctions.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(tblFunctions);
btOk.setText("Принять");
btOk.setEnabled(false);
btOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOkActionPerformed(evt);
}
});
btCancel.setText("Отмена");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancelActionPerformed(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()
.addComponent(btOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 773, Short.MAX_VALUE))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOk});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOk))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed
this.setDlgResult(ModalDialog.DLG_OK);
this.row = tblFunctions.getSelectedRowSorted();
this.dispose();
}//GEN-LAST:event_btOkActionPerformed
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
this.setDlgResult(ModalDialog.DLG_CANCEL);
this.dispose();
}//GEN-LAST:event_btCancelActionPerformed
public DirectoryCollaboratorFunctionsItem getResult(){
return items.get(row);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOk;
private javax.swing.JScrollPane jScrollPane1;
private cli_fmw.utils.sorted_table.SortedTable tblFunctions;
// End of variables declaration//GEN-END:variables
}