/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* directorySelectDialog.java
*
* Created on Apr 27, 2009, 4:26:57 PM
*/
package clips.service.mes;
import beans.report.SelectedIdList;
import cli_fmw.delegate.directory.DirectoryItemRecursive;
import cli_fmw.delegate.directory.DirectoryRecursive;
import cli_fmw.main.ClipsException;
import clips.report.panels.utils.DirectoryTreeSellectPanel;
import java.awt.Window;
import java.util.HashSet;
import java.util.Set;
/**
*
* @param <T>
* @author finder
*/
public class DirectoryRecursiveSelectDialog<T extends DirectoryItemRecursive> extends javax.swing.JDialog {
private static final long serialVersionUID = 1L;
public static final int DLG_OK = 1;
public static final int DLG_CANCEL = 0;
private DirectoryTreeSellectPanel treePanel;
private DirectoryRecursive<?, ? extends T> dir;
private int[] items;
private int resould = DLG_CANCEL;
class IdList implements SelectedIdList{
@Override
public int[] getItems() {
return items;
}
@Override
public void setItems(int[] items) {
DirectoryRecursiveSelectDialog.this.items = items;
treePanel.onTreeUpdated();
}
@Override
public int[] getExcludedItems() {
return null;
}
@Override
public void setExcludedItems(int[] excludedItems) {
}
}
/** Creates new form directorySelectDialog
* @param parent
* @param itemSet
* @param dir
*/
public DirectoryRecursiveSelectDialog(Window parent, Set<T> itemSet, DirectoryRecursive<?, ? extends T> dir) throws ClipsException {
super(parent, ModalityType.APPLICATION_MODAL);
initComponents();
items = new int[itemSet.size()];
int i = 0;
for (DirectoryItemRecursive directoryItemRecursive : itemSet) {
items[i++] = directoryItemRecursive.getID();
}
treePanel = new DirectoryTreeSellectPanel(dir);
treePanel.setObject(new IdList());
}
/** 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() {
btOk = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
pnContent = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
btOk.setText("OK");
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);
}
});
pnContent.setLayout(new java.awt.GridLayout());
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(259, Short.MAX_VALUE)
.addComponent(btOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel)
.addGap(12, 12, 12))
.addComponent(pnContent, javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE)
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOk});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(pnContent, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btOk)
.addComponent(btCancel))
.addContainerGap())
);
pack();
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Dimension dialogSize = getSize();
setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
}// </editor-fold>//GEN-END:initComponents
private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed
resould = DLG_OK;
dispose();
}//GEN-LAST:event_btOkActionPerformed
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
resould = DLG_CANCEL;
dispose();
}//GEN-LAST:event_btCancelActionPerformed
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOk;
private javax.swing.JPanel pnContent;
// End of variables declaration//GEN-END:variables
public Set<T> getItems() throws ClipsException {
HashSet<T> target = new HashSet<T>();
for (int id : items) {
target.add(dir.getItemFromID(id));
}
return target;
}
public int getResould() {
return resould;
}
}