/*
* DialogJob.java
*
* Created on 15 Февраль 2008 г., 17:38
*/
package clips.doctor.certificate.controlPanels;
import clips.delegate.doctor.certificate.tag.interfaces.TypeMultiSelectable;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.ArrayList;
import framework.utils.PairIntStr;
/**
*
* @author vip
*/
public class DialogMultiSelect extends ModalDialog {
private TypeMultiSelectable certTag;
private TableModelMultiSelect model;
private ArrayList<Integer> selectedItems;
private ArrayList<PairIntStr> allItems;
public DialogMultiSelect(java.awt.Frame parent, TypeMultiSelectable certTag) throws ClipsException {
super(parent, "", null);
initComponents();
this.certTag = certTag;
//Составление списка всех итемов
PairIntStr[] allItems1 = certTag.getAllItems();
allItems = new ArrayList<PairIntStr>(allItems1.length);
for (int i = 0; i < allItems1.length; i++) {
PairIntStr pair = allItems1[i];
allItems.add(pair);
}
//Составление списка выбранных итемов
selectedItems = new ArrayList<Integer>(certTag.getItems());
model = new TableModelMultiSelect(allItems, selectedItems);
sortedTable1.setModel(model);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize = this.getBounds();
this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height - dlgSize.height) / 2);
resizeColumn();
StateSaver.attachTo(this);
}
public ArrayList<PairIntStr> getSelectedItems() {
ArrayList<PairIntStr> res = new ArrayList<PairIntStr>();
for (int i = 0; i < allItems.size(); i++) {
PairIntStr pair = allItems.get(i);
if (selectedItems.contains(pair.num)) {
res.add(pair);
}
}
return res;
}
private void resizeColumn() {
TableState state = new TableState();
state.setPreferredWidth(TableModelMultiSelect.COL_SELECTED, 1);
state.setPreferredWidth(TableModelMultiSelect.COL_ITEM_TITLE, 6);
StateSaver.setDefaultState(this, sortedTable1, state);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel4 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
sortedTable1 = new cli_fmw.utils.sorted_table.SortedTable();
pnlBottom = new javax.swing.JPanel();
btOK = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jPanel4.setLayout(new java.awt.BorderLayout());
jScrollPane1.setViewportView(sortedTable1);
jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);
getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
pnlBottom.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
btOK.setText(" ОК ");
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 pnlBottomLayout = new javax.swing.GroupLayout(pnlBottom);
pnlBottom.setLayout(pnlBottomLayout);
pnlBottomLayout.setHorizontalGroup(
pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBottomLayout.createSequentialGroup()
.addContainerGap(369, Short.MAX_VALUE)
.addComponent(btOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel)
.addContainerGap())
);
pnlBottomLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK});
pnlBottomLayout.setVerticalGroup(
pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlBottomLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOK))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().add(pnlBottom, java.awt.BorderLayout.SOUTH);
pack();
}// </editor-fold>//GEN-END:initComponents
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setDlgResult(DLG_CANCEL);
dispose();
}//GEN-LAST:event_closeDialog
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
setDlgResult(DLG_CANCEL);
dispose();
}//GEN-LAST:event_btCancelActionPerformed
private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
setDlgResult(DLG_OK);//GEN-LAST:event_btOKActionPerformed
dispose();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOK;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JPanel pnlBottom;
private cli_fmw.utils.sorted_table.SortedTable sortedTable1;
// End of variables declaration//GEN-END:variables
}