Package clips.directory.editors.update.updaters.collaborators

Source Code of clips.directory.editors.update.updaters.collaborators.DialogPolling

/*
* DialogAddress.java
*
* Created on 24 Январь 2008 г., 10:08
*/
package clips.directory.editors.update.updaters.collaborators;

import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.audit.AuditManager;
import cli_fmw.utils.EmptyDialog;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.delegate.client.ClientLocal;
import clips.delegate.directory.simple.name.DirectoryName;
import clips.delegate.directory.simple.pathron.DirectoryPathron;
import clips.delegate.directory.simple.surname.DirectorySurname;
import clips.userseach.PanelUserSearch;
import java.awt.Frame;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import javax.swing.table.TableColumn;

/**
* Диалог, позволяющий редактировать адрес (либо клиента либо предприятия)
* @author lacoste
*/
public class DialogPolling extends ModalDialog {
    private HashMap<ColDataKey, ArrayList<ClientLocal>> map;
    private ArrayList<ColDataKey> keyList;
    DirectorySurname dirSurname;
    DirectoryName dirName;
    DirectoryPathron dirPathron;

    public DialogPolling(Frame parent, HashMap<ColDataKey, ArrayList<ClientLocal>> map, AuditManager am) throws ClipsException {
        super(parent, "Соответствие Врач - Пациент", am);
        initComponents();
        this.map = map;
        keyList = new ArrayList<ColDataKey>(map.keySet());
        dirSurname = DirectoryLocator.getDirectory(DirectorySurname.class);
        dirName = DirectoryLocator.getDirectory(DirectoryName.class);
        dirPathron = DirectoryLocator.getDirectory(DirectoryPathron.class);

        setEndabledComponents();

        sortedTable1.setModel(new TableModelPollingCollabData(keyList, map));
        sortedTable1.setDefaultRenderer(Object.class, new TableCellRendererPollingCollab(keyList, map));
        resizeColumn();
        StateSaver.attachTo(this);
    }

    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelPollingCollabData.COL_COLLAB,         10);
    state.setPreferredWidth(TableModelPollingCollabData.COL_CLIENT,         10);
      StateSaver.setDefaultState(this, sortedTable1, state);
    }

    private void setEndabledComponents() {
        boolean good = true;
        Collection<ArrayList<ClientLocal>> values = map.values();
        for (ArrayList<ClientLocal> clientList : values) {
            if (clientList.size() != 1) {
                good = false;
            }
        }
        btOK.setEnabled(good);
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        sortedTable1 = new cli_fmw.utils.sorted_table.SortedTable();
        panelOkCancel = new javax.swing.JPanel();
        btOK = new javax.swing.JButton();
        btCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Соответствие Врач - Пациент"));

        sortedTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        sortedTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sortedTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(sortedTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 742, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 742, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 392, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        panelOkCancel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 0));

        btOK.setText("     Да     ");
        btOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOKActionPerformed(evt);
            }
        });
        panelOkCancel.add(btOK);

        btCancel.setText("Отмена");
        btCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelActionPerformed(evt);
            }
        });
        panelOkCancel.add(btCancel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelOkCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 778, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 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.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelOkCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
        setDlgResult(DLG_OK);
        dispose();
    }//GEN-LAST:event_btOKActionPerformed

    private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
        setDlgResult(DLG_CANCEL);
        dispose();
    }//GEN-LAST:event_btCancelActionPerformed

    private void sortedTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sortedTable1MouseClicked
        int row = sortedTable1.getSelectedRowSorted();
        int col = sortedTable1.columnAtPoint(evt.getPoint());
        TableColumn tableColumn = sortedTable1.getColumnModel().getColumn(col);
        col = tableColumn.getModelIndex();
        if (row < 0 || evt.getClickCount() < 2 || col != TableModelPollingCollabData.COL_CLIENT) {
            return;
        }
        ColDataKey key = keyList.get(row);
        try {
            EmptyDialog dialog = new EmptyDialog(MainWindow.mainWindow, "Выбор пациента", getAuditManager());
            PanelUserSearch panel = new PanelUserSearch(dialog, PanelUserSearch.MODE_SELECT);
            String surName = dirSurname.getItemFromID(key.surnameID).getTitle();
            String name = dirName.getItemFromID(key.nameID).getTitle();
            String pathron = dirPathron.getItemFromID(key.pathronID).getTitle();
            panel.setFIO(surName + " " + name + " " + pathron);
            dialog.addNewPage((PageGeneric) panel, null);
            dialog.setVisible(true);
            ClientLocal client = panel.getSelectedClient();
            if (dialog.getDlgResult() == ModalDialog.DLG_OK) {
                ArrayList<ClientLocal> clientList = new ArrayList<ClientLocal>(1);
                if (client != null) {
                    clientList.add(client);
                }
                map.put(key, clientList);
                sortedTable1.updateUI();
            }
        } catch (PageException ex) {
            MessageBox.showException(ex);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
        setEndabledComponents();
    }//GEN-LAST:event_sortedTable1MouseClicked

    // 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 jScrollPane1;
    private javax.swing.JPanel panelOkCancel;
    private cli_fmw.utils.sorted_table.SortedTable sortedTable1;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of clips.directory.editors.update.updaters.collaborators.DialogPolling

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.