Package cli_fmw.directory

Source Code of cli_fmw.directory.DialogDirectoryTitleOnlyM

/*
* DialogDirectory.java
* Диалог, позволяющий выбрать одно значение из справочника
* Created on 10 Декабрь 2007 г., 14:35
*/
package cli_fmw.directory;

import cli_fmw.delegate.directory.DirectoryItem;
import cli_fmw.delegate.directory.DirectoryItemRO;
import cli_fmw.delegate.directory.DirectoryMagic;
import cli_fmw.delegate.directory.simple.DirectorySimple;
import cli_fmw.delegate.directory.simple.DirectorySimpleItem;
import cli_fmw.main.ClipsException;
import cli_fmw.report.panels.model.FilteredComboBoxModel;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import framework.beans.directory.DirectoryBeanRemote;
import framework.beans.directory.DirectoryItemDetails;
import framework.beans.directory.simple.DirectorySimpleBeanRemoteAbstract;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.FocusEvent;
import javax.swing.DefaultComboBoxModel;

/**
*
* @param <ITEM>
* @param <DIRECTORY>
* @author  Администратор
*/
abstract public class DialogDirectoryTitleOnlyM<
            ITEM extends DirectoryItem<?>,
            DIRECTORY extends DirectoryMagic<?, ITEM>
            >
        extends ModalDialog {

    private DIRECTORY directory;        //Справочнег
    private boolean withNull;
    private boolean pressedOK = false;
    /**
     * @param parent
     * @param directory справочник, на основе которого создается диалог
     * @param currentValue значение, которое нужно выделить в справочнике при его создании
     * @param withNull
     * @throws ClipsException
     */
    public DialogDirectoryTitleOnlyM(java.awt.Frame parent, final DIRECTORY directory,
            String currentValue, boolean withNull) throws ClipsException {
        super(parent, directory.getDirectoryTitle(), null);
        initComponents();
        this.directory = directory;
        this.withNull = withNull;
        DirectoryItemRO[] arr = directory.toArray(withNull);
        final DefaultComboBoxModel model = new DefaultComboBoxModel(arr);
        DirectoryItemRO currentItem = null;
        for (int i = 0; i < arr.length; i++) {
            DirectoryItemRO item = arr[i];
            if (item.toString().equals(currentValue)) {
                currentItem = item;
                break;
            }
        }
        model.setSelectedItem(currentItem);
        FilteredComboBoxModel filteredModel = new FilteredComboBoxModel(jComboBox1, true) {

            @Override
            public Object addItem(String txt) {
                if (!(EventQueue.getCurrentEvent() instanceof FocusEvent) || pressedOK) {
                    try {
                        ITEM newItem = getNewItem(txt);
                        if (newItem == null) {
                            return null;
                        }
                        directory.getItems().append(newItem);
                        model.addElement(newItem);
                        return newItem;
                    } catch (ClipsException ex) {
                        MessageBox.showException(ex);
                        return null;
                    }
                } else {
                    return null;
                }
            }
        };
        filteredModel.setContainModel(model);

        //Размещение диалога посередине экрана
        Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle dlgSize = this.getBounds();
        this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height -
                dlgSize.height) / 2);
       
        jComboBox1.requestFocus();
    }
   
    /**
     * Возвращает строку которая была выбрана, но еще надо смотреть статус
     * @return
     */
    @SuppressWarnings("unchecked")
    public ITEM getSelectedItem() {
        return (ITEM) jComboBox1.getSelectedItem();
    }
   
    abstract protected ITEM getNewItem(String title);

    /** 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() {

        jPanel2 = new javax.swing.JPanel();
        btOk = new javax.swing.JButton();
        btCancel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        btOk.setText("Выбрать");
        btOk.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btOkMousePressed(evt);
            }
        });
        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 jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btOk)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btCancel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOk});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancel)
                    .addComponent(btOk))
                .addContainerGap())
        );

        jComboBox1.setEditable(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel1, jPanel2});

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

    private void btOkActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btOkActionPerformed
{
        setDlgResult(ModalDialog.DLG_OK);
        setVisible(false);
        /*
            dispose();//GEN-LAST:event_btOkActionPerformed
        */
}                                   

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


    private void closeDialog(java.awt.event.WindowEvent evt)//GEN-FIRST:event_closeDialog
{
        setDlgResult(ModalDialog.DLG_CANCEL);
        setVisible(false);
    }//GEN-LAST:event_closeDialog

    private void btOkMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btOkMousePressed
        pressedOK = true;
    }//GEN-LAST:event_btOkMousePressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancel;
    private javax.swing.JButton btOk;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
   
    /*class ItemsModel
            <DIRECTORYITEM extends DirectoryItemRO<?>>
        extends FilteredComboBoxModel {
    DirectoryMagic dir;
    DIRECTORYITEM selectedItem;

    public ItemsModel(JComboBox combo, DirectoryMagic dir) throws ClipsException {
        super(combo, dir.canEdit());
        ComboBoxModel containModel  = new DefaultComboBoxModel(dir.toArray()){

            public DIRECTORYITEM getSelectedDirectoryItem() throws ClipsException {
                return selectedItem;
            }

            public void setSelectedDirectoryItem(DIRECTORYITEM item) throws ClipsException {
                selectedItem = item;
            }

        };
        super.setContainModel(containModel);
        this.dir = dir;
    }

    @Override
    public Object addItem(String txt) {
        int res = MessageBox.showConfirmYesNo(MessageBox.C_ADD_DIRECTORYITEM);
        if (res == MessageBox.ANSWER_YES) {
            try {
                ITEM item = getNewItem(txt);
                dir.getItems().append(item);
                return item;
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
                return null;
            }
        } else {
            return null;
        }
    }

}*/

}
 
TOP

Related Classes of cli_fmw.directory.DialogDirectoryTitleOnlyM

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.