/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DlgDloDrugChooser.java
*
* Created on 06.12.2009, 17:30:11
*/
package clips.doctor.prescriptiondlo;
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.Selector;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.delegate.directory.complex.DirectoryDloDrugSection;
import clips.delegate.directory.complex.DirectoryDloDrugSectionItem;
import clips.delegate.directory.complex.DirectoryDrugList;
import clips.delegate.directory.complex.DirectoryDrugListItem;
import clips.delegate.directory.simple.dlo.DirectoryDrugFarmGroup;
import clips.delegate.directory.simple.dlo.DirectoryDrugFarmGroupItem;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import javax.swing.ListSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
*
* @author lacoste
*/
public class DlgDloDrugChooser extends ModalDialog {
private DirectoryDrugListItem item;
private DirectoryDrugList dirDrug;
private DirectoryDrugFarmGroup dirGroup;
private DirectoryDloDrugSection dirSection;
Selector<DirectoryDrugListItem> items;
/** Creates new form DlgDloDrugChooser */
public DlgDloDrugChooser(java.awt.Frame parent, boolean modal) throws ClipsException {
super(parent, "Льготные ЛС", null);
initComponents();
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize = new Rectangle((int)(0.6 * scrSize.width), (int)(0.6 * scrSize.height));
this.setBounds(dlgSize);
this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height - dlgSize.height) / 2);
dirGroup = DirectoryLocator.getDirectory(DirectoryDrugFarmGroup.class);
dirSection = DirectoryLocator.getDirectory(DirectoryDloDrugSection.class);
dirDrug = DirectoryLocator.getDirectory(DirectoryDrugList.class);
tableDrugListGroup.setModel(new TableModelDrugList(items));
tableDrugListGroup.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableDrugListGroup.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
btOK.setEnabled(tableDrugListGroup.getSelectedRowCount() > 0);
if (tableDrugListGroup.getSelectedRowSorted() > -1) {
item = items.get(tableDrugListGroup.getSelectedRowSorted());
}
else {
item = null;
}
}
});
tableDrugListSection.setModel(new TableModelDrugList(items));
tableDrugListSection.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableDrugListSection.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
btOK.setEnabled(tableDrugListSection.getSelectedRowCount() > 0);
if (tableDrugListSection.getSelectedRowSorted() > -1) {
item = items.get(tableDrugListSection.getSelectedRowSorted());
}
else {
item = null;
}
}
});
jTabbedPane1.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
treeFarmGroupValueChanged(null);
treeSectionValueChanged(null);
}
});
resizeColumns();
setFarmGroupTree();
setSectionTree();
StateSaver.attachTo(this);
}
private void setFarmGroupTree() throws ClipsException {
treeFarmGroup.setModel(new TreeModelDloFarmGroup(dirGroup));
treeFarmGroup.setSelectionPath(null);
}
private void setSectionTree() throws ClipsException {
treeSection.setModel(new TreeModelDloSection(dirSection));
treeSection.setSelectionPath(null);
}
private void resizeColumns() {
TableState state = new TableState();
state.setPreferredWidth(TableModelDrugList.COL_CODE, 2);
state.setPreferredWidth(TableModelDrugList.COL_TITLE, 10);
state.setPreferredWidth(TableModelDrugList.COL_TRN, 10);
state.setPreferredWidth(TableModelDrugList.COL_MNN, 10);
state.setPreferredWidth(TableModelDrugList.COL_LF, 7);
state.setPreferredWidth(TableModelDrugList.COL_DOSAGE, 6);
state.setPreferredWidth(TableModelDrugList.COL_DOSAGE_UNIT, 3);
state.setPreferredWidth(TableModelDrugList.COL_DOSAGE_QUANTITY, 3);
state.setPreferredWidth(TableModelDrugList.COL_BEGIN, 4);
state.setPreferredWidth(TableModelDrugList.COL_END, 4);
StateSaver.setDefaultState(this, tableDrugListGroup, state);
}
public DirectoryDrugListItem getSelectedDrug() {
return item;
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
btOK = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
jTabbedPane1 = new javax.swing.JTabbedPane();
panFarmGroup = new javax.swing.JPanel();
jSplitPane1 = new javax.swing.JSplitPane();
jScrollPane2 = new javax.swing.JScrollPane();
treeFarmGroup = new javax.swing.JTree();
jScrollPane3 = new javax.swing.JScrollPane();
tableDrugListGroup = new cli_fmw.utils.sorted_table.SortedTable();
panSection = new javax.swing.JPanel();
jSplitPane2 = new javax.swing.JSplitPane();
jScrollPane4 = new javax.swing.JScrollPane();
treeSection = new javax.swing.JTree();
jScrollPane5 = new javax.swing.JScrollPane();
tableDrugListSection = new cli_fmw.utils.sorted_table.SortedTable();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
btOK.setText(" ОК ");
btOK.setEnabled(false);
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);
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
panFarmGroup.setLayout(new java.awt.BorderLayout());
jSplitPane1.setResizeWeight(0.15);
treeFarmGroup.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
treeFarmGroupValueChanged(evt);
}
});
jScrollPane2.setViewportView(treeFarmGroup);
jSplitPane1.setLeftComponent(jScrollPane2);
tableDrugListGroup.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"
}
));
tableDrugListGroup.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tableDrugListGroupMouseClicked(evt);
}
});
jScrollPane3.setViewportView(tableDrugListGroup);
jSplitPane1.setRightComponent(jScrollPane3);
panFarmGroup.add(jSplitPane1, java.awt.BorderLayout.CENTER);
jTabbedPane1.addTab("По фармгруппам", panFarmGroup);
panSection.setLayout(new java.awt.BorderLayout());
jSplitPane2.setResizeWeight(0.15);
treeSection.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
treeSectionValueChanged(evt);
}
});
jScrollPane4.setViewportView(treeSection);
jSplitPane2.setLeftComponent(jScrollPane4);
tableDrugListSection.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"
}
));
tableDrugListSection.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tableDrugListSectionMouseClicked(evt);
}
});
jScrollPane5.setViewportView(tableDrugListSection);
jSplitPane2.setRightComponent(jScrollPane5);
panSection.add(jSplitPane2, java.awt.BorderLayout.CENTER);
jTabbedPane1.addTab("По разделам перечня", panSection);
getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
setDlgResult(ModalDialog.DLG_OK);
dispose();
}//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
private void treeFarmGroupValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeFarmGroupValueChanged
try {
if (treeFarmGroup.getSelectionPath() != null) {
Object obj = treeFarmGroup.getSelectionPath().getLastPathComponent();
items = null;
if (obj instanceof DirectoryDrugFarmGroupItem) {
DirectoryDrugFarmGroupItem farmGroup = (DirectoryDrugFarmGroupItem) obj;
items = dirDrug.getItemsByFarmGroup(farmGroup);
}
tableDrugListGroup.setModel(new TableModelDrugList(items));
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_treeFarmGroupValueChanged
private void treeSectionValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeSectionValueChanged
try {
if (treeSection.getSelectionPath() != null) {
Object obj = treeSection.getSelectionPath().getLastPathComponent();
items = null;
if (obj instanceof DirectoryDloDrugSectionItem) {
DirectoryDloDrugSectionItem section = (DirectoryDloDrugSectionItem) obj;
items = dirDrug.getItemsBySection(section);
}
tableDrugListSection.setModel(new TableModelDrugList(items));
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_treeSectionValueChanged
private void tableDrugListSectionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableDrugListSectionMouseClicked
if (evt.getClickCount() >= 2) {
btOKActionPerformed(null);
}
}//GEN-LAST:event_tableDrugListSectionMouseClicked
private void tableDrugListGroupMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableDrugListGroupMouseClicked
if (evt.getClickCount() >= 2) {
btOKActionPerformed(null);
}
}//GEN-LAST:event_tableDrugListGroupMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOK;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JSplitPane jSplitPane2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JPanel panFarmGroup;
private javax.swing.JPanel panSection;
private cli_fmw.utils.sorted_table.SortedTable tableDrugListGroup;
private cli_fmw.utils.sorted_table.SortedTable tableDrugListSection;
private javax.swing.JTree treeFarmGroup;
private javax.swing.JTree treeSection;
// End of variables declaration//GEN-END:variables
}