/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* PanelSerRenSearch.java
*
* Created on 08.05.2009, 11:41:49
*/
package clips.service.search;
import beans.service.search.SerRenFilter;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Printable;
import cli_fmw.main.PageGeneric;
import cli_fmw.utils.EmptyDialog;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.contract.PanelContractSearch;
import clips.delegate.client.ClientLocal;
import clips.delegate.contract.ContractLocal;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import clips.delegate.service.SerRenLocal;
import clips.delegate.service.SerRenSearchLocal;
import clips.directory.dialogs.DirectoryDialogService;
import clips.service.PanelSerRenList;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.infotechservice.ICalendar.DateEvent;
import org.infotechservice.ICalendar.DateListener;
/**
*
* @author lacoste
*/
public class PanelSerRenSearch extends PageGeneric implements Printable {
private SerRenFilter filter;
private DirectoryServiceItem service;
private ContractLocal contract;
private Date dateFrom, dateTill;
private Boolean cond;
private ArrayList<SerRenLocal> serRens;
/** Creates new form PanelSerRenSearch
* @param container
* @throws ClipsException
*/
public PanelSerRenSearch(PageContainer container) throws ClipsException {
super(container);
initComponents();
dateChooserFrom.addDateListener(new DateListener() {
@Override
public void dateChanged(DateEvent evt) {
dateFrom = dateChooserFrom.getDate();
}
});
dateChooserTill.addDateListener(new DateListener() {
@Override
public void dateChanged(DateEvent evt) {
dateTill = dateChooserTill.getDate();
}
});
tabSerRens.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
btSelect.setEnabled(tabSerRens.getSelectedRowSorted() > -1);
}
});
tabSerRens.setModel(new TableModelSerRenFactory(null));
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() {
jPopupMenu1 = new javax.swing.JPopupMenu();
miAll = new javax.swing.JMenuItem();
miRendered = new javax.swing.JMenuItem();
miNotRendered = new javax.swing.JMenuItem();
jPanel1 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel4 = new javax.swing.JPanel();
tfService = new javax.swing.JTextField();
btService = new javax.swing.JButton();
cbService = new javax.swing.JCheckBox();
jPanel5 = new javax.swing.JPanel();
tfContract = new javax.swing.JTextField();
btContract = new javax.swing.JButton();
cbContract = new javax.swing.JCheckBox();
jPanel6 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
dateChooserFrom = new org.infotechservice.ICalendar.components.ICDateChooser();
jLabel5 = new javax.swing.JLabel();
dateChooserTill = new org.infotechservice.ICalendar.components.ICDateChooser();
jPanel7 = new javax.swing.JPanel();
btSearch = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tabSerRens = new cli_fmw.utils.sorted_table.SortedTable();
jPanel2 = new javax.swing.JPanel();
btSelect = new javax.swing.JButton();
miAll.setText("Всех услуг");
miAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miAllActionPerformed(evt);
}
});
jPopupMenu1.add(miAll);
miRendered.setText("Только оказанных");
miRendered.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miRenderedActionPerformed(evt);
}
});
jPopupMenu1.add(miRendered);
miNotRendered.setText("Только неоказанных");
miNotRendered.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
miNotRenderedActionPerformed(evt);
}
});
jPopupMenu1.add(miNotRendered);
jPanel1.setPreferredSize(new java.awt.Dimension(648, 300));
jPanel1.setLayout(new java.awt.GridLayout(5, 1, 5, 5));
jPanel3.setLayout(new java.awt.BorderLayout());
jLabel1.setText("Поиск назначенных услуг");
jPanel3.add(jLabel1, java.awt.BorderLayout.CENTER);
jPanel1.add(jPanel3);
jPanel4.setLayout(new java.awt.BorderLayout(5, 0));
tfService.setEditable(false);
jPanel4.add(tfService, java.awt.BorderLayout.CENTER);
btService.setText("...");
btService.setEnabled(false);
btService.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btServiceActionPerformed(evt);
}
});
jPanel4.add(btService, java.awt.BorderLayout.LINE_END);
cbService.setText("тип услуги:");
cbService.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbServiceActionPerformed(evt);
}
});
jPanel4.add(cbService, java.awt.BorderLayout.LINE_START);
jPanel1.add(jPanel4);
jPanel5.setLayout(new java.awt.BorderLayout(5, 0));
tfContract.setEditable(false);
jPanel5.add(tfContract, java.awt.BorderLayout.CENTER);
btContract.setText("...");
btContract.setEnabled(false);
btContract.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btContractActionPerformed(evt);
}
});
jPanel5.add(btContract, java.awt.BorderLayout.LINE_END);
cbContract.setText("договор, по которому назначена услуга:");
cbContract.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbContractActionPerformed(evt);
}
});
jPanel5.add(cbContract, java.awt.BorderLayout.LINE_START);
jPanel1.add(jPanel5);
jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
jLabel4.setText("Дата назначения: с ");
jPanel6.add(jLabel4);
dateChooserFrom.setPreferredSize(new java.awt.Dimension(130, 27));
jPanel6.add(dateChooserFrom);
jLabel5.setText(" по: ");
jPanel6.add(jLabel5);
dateChooserTill.setPreferredSize(new java.awt.Dimension(130, 27));
jPanel6.add(dateChooserTill);
jPanel1.add(jPanel6);
btSearch.setText("Поиск");
btSearch.setPreferredSize(new java.awt.Dimension(52, 27));
btSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btSearchActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addComponent(btSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(584, Short.MAX_VALUE))
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addComponent(btSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1.add(jPanel7);
tabSerRens.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{},
{},
{},
{}
},
new String [] {
}
));
jScrollPane1.setViewportView(tabSerRens);
jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 0, 0));
btSelect.setText("Выбрать");
btSelect.setEnabled(false);
btSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btSelectActionPerformed(evt);
}
});
jPanel2.add(btSelect);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void btSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSearchActionPerformed
jPopupMenu1.show(btSearch, 0, 0);
}//GEN-LAST:event_btSearchActionPerformed
private void btServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btServiceActionPerformed
try {
DirectoryDialogService dlg = new DirectoryDialogService(false, service);
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
service = (DirectoryServiceItem) dlg.getSelectedItems().get(0);
tfService.setText(service.toString());
}
else if (service == null) {
cbService.setSelected(false);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btServiceActionPerformed
private void btContractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btContractActionPerformed
try {
EmptyDialog dlg = new EmptyDialog(MainWindow.mainWindow, "Выбор контракта", getAuditManager());
PanelContractSearch panel = new PanelContractSearch(dlg, true);
dlg.addNewPage(panel, null);
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
contract = panel.getSelectedContract();
if (contract != null) {
tfContract.setText(contract.getInfo());
}
else {
btContract.setEnabled(false);
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btContractActionPerformed
private void cbServiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbServiceActionPerformed
if (!cbService.isSelected()) {
service = null;
tfService.setText("");
}
else {
btServiceActionPerformed(null);
}
btService.setEnabled(cbService.isSelected());
}//GEN-LAST:event_cbServiceActionPerformed
private void cbContractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbContractActionPerformed
if (!cbContract.isSelected()) {
contract = null;
tfContract.setText("");
}
else {
btContractActionPerformed(null);
}
btContract.setEnabled(cbContract.isSelected());
}//GEN-LAST:event_cbContractActionPerformed
private void miAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAllActionPerformed
cond = null;
goSearch();
}//GEN-LAST:event_miAllActionPerformed
private void miRenderedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miRenderedActionPerformed
cond = true;
goSearch();
}//GEN-LAST:event_miRenderedActionPerformed
private void miNotRenderedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miNotRenderedActionPerformed
cond = false;
goSearch();
}//GEN-LAST:event_miNotRenderedActionPerformed
private void btSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSelectActionPerformed
try {
int row = tabSerRens.getSelectedRowSorted();
SerRenLocal serRen = serRens.get(row);
ClientLocal client = serRen.getPolisData().getClient();
PanelSerRenList panel = new PanelSerRenList(getContainer(), client);
PageGeneric page = getContainer().addNewPage((PageGeneric) panel, this);
getContainer().activatePage(page);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btSelectActionPerformed
private void goSearch() {
try {
filter = new SerRenFilter();
filter.serviceId = service == null ? 0 : service.getID();
filter.contratId = contract == null ? 0 : contract.getID();
filter.dateFrom = dateFrom;
filter.dateTill = dateTill;
filter.rendered = cond;
SerRenSearchLocal searchLocal = new SerRenSearchLocal(getAuditManager());
serRens = searchLocal.findSerRenLocals(filter);
tabSerRens.setModel(new TableModelSerRenFactory(serRens));
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
@Override
public String getPageTitle() {
return "Поиск назначенных услуг";
}
@Override
public DelegateLine2 getDelegate() {
return null;
}
@Override
public boolean readyForPrint() {
return false;
}
@Override
public void print() {
throw new UnsupportedOperationException("Not supported yet.");
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btContract;
private javax.swing.JButton btSearch;
private javax.swing.JButton btSelect;
private javax.swing.JButton btService;
private javax.swing.JCheckBox cbContract;
private javax.swing.JCheckBox cbService;
private org.infotechservice.ICalendar.components.ICDateChooser dateChooserFrom;
private org.infotechservice.ICalendar.components.ICDateChooser dateChooserTill;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPopupMenu jPopupMenu1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JMenuItem miAll;
private javax.swing.JMenuItem miNotRendered;
private javax.swing.JMenuItem miRendered;
private cli_fmw.utils.sorted_table.SortedTable tabSerRens;
private javax.swing.JTextField tfContract;
private javax.swing.JTextField tfService;
// End of variables declaration//GEN-END:variables
}