Package reportgen.gui.genepanel.corepanel.inlinepanel

Source Code of reportgen.gui.genepanel.corepanel.inlinepanel.InlineTablePanel$ListSelectionListenerImpl

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* columnPanel.java
*
* Created on 02.04.2009, 16:55:01
*/

package reportgen.gui.genepanel.corepanel.inlinepanel;

import java.awt.Window;
import javax.swing.DefaultComboBoxModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import reportgen.gui.genepanel.corepanel.inlinepanel.dlg.InlineQueryDlg;
import reportgen.prototype.QCoreInline;
import reportgen.prototype.inline.InlineCoreList;
import reportgen.utils.ReportException;
import reportgen.utils.Message;

/**
*
* @author axe
*/
public class InlineTablePanel extends javax.swing.JPanel {

    private Window parent;
    private final InlineCoreList lst;
    private DefaultComboBoxModel model;
    private ListSelectionListener listener = new ListSelectionListenerImpl();

    public InlineTablePanel(Window parent, InlineCoreList lst, String title) {
        initComponents();
        this.lst = lst;
        this.parent = parent;
        titleLabel.setText(title);
        initList(-1);
    }

    private void initList(int selectedIndex) {
        model = new DefaultComboBoxModel(lst.getList().toArray());
        mainList.setModel(model);

        mainList.getSelectionModel().removeListSelectionListener(listener);
        mainList.getSelectionModel().addListSelectionListener(listener);
        mainList.setSelectedIndex(selectedIndex);
    }

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

        jPanel9 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        addBtn = new javax.swing.JButton();
        editBtn = new javax.swing.JButton();
        delResultColBtn = new javax.swing.JButton();
        upBtn = new javax.swing.JButton();
        downBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        mainList = new javax.swing.JList();
        titleLabel = new javax.swing.JLabel();

        jPanel9.setLayout(new java.awt.BorderLayout(5, 5));

        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        addBtn.setText("add");
        addBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addBtnActionPerformed(evt);
            }
        });
        jPanel6.add(addBtn);

        editBtn.setText("edit");
        editBtn.setEnabled(false);
        editBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editBtnActionPerformed(evt);
            }
        });
        jPanel6.add(editBtn);

        delResultColBtn.setText("del");
        delResultColBtn.setEnabled(false);
        delResultColBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delResultColBtnActionPerformed(evt);
            }
        });
        jPanel6.add(delResultColBtn);

        upBtn.setText("up");
        upBtn.setEnabled(false);
        upBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                upBtnActionPerformed(evt);
            }
        });
        jPanel6.add(upBtn);

        downBtn.setText("down");
        downBtn.setEnabled(false);
        downBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downBtnActionPerformed(evt);
            }
        });
        jPanel6.add(downBtn);

        jPanel9.add(jPanel6, java.awt.BorderLayout.SOUTH);

        mainList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(mainList);

        jPanel9.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        titleLabel.setText("---");
        jPanel9.add(titleLabel, java.awt.BorderLayout.NORTH);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed
        try {
            QCoreInline child = lst.createNewChild();
            InlineQueryDlg dlg = new InlineQueryDlg(parent, child);
            dlg.setVisible(true);
            if(dlg.isOK()) {
                lst.add(child);
                initList(lst.size()-1);
            }
        } catch (ReportException reportException) {
            Message.error(this, reportException);
        }
}//GEN-LAST:event_addBtnActionPerformed

    private void delResultColBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delResultColBtnActionPerformed
        int index = mainList.getSelectedIndex();
        if(index != -1) {
            try {
                lst.remove(index);
                initList(index-1);
            }catch (ReportException ex) {
                Message.warning(this, ex);
            }
        }
}//GEN-LAST:event_delResultColBtnActionPerformed

    private void editBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBtnActionPerformed
        int index = mainList.getSelectedIndex();
        if(index != -1) {
            QCoreInline core = (QCoreInline) lst.get(index);
            InlineQueryDlg dlg = new InlineQueryDlg(parent, core);
            dlg.setVisible(true);
        }
    }//GEN-LAST:event_editBtnActionPerformed

    private void upBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upBtnActionPerformed
        int index = mainList.getSelectedIndex();
        if(index == -1) {
            upBtn.setEnabled(false);
        } else {
            int sel = lst.moveUp(index);
            initList(sel);
        }
    }//GEN-LAST:event_upBtnActionPerformed

    private void downBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downBtnActionPerformed
        int index = mainList.getSelectedIndex();
        if(index == -1) {
            upBtn.setEnabled(false);
        } else {
            int sel = lst.moveDown(index);
            initList(sel);
        }
    }//GEN-LAST:event_downBtnActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addBtn;
    private javax.swing.JButton delResultColBtn;
    private javax.swing.JButton downBtn;
    private javax.swing.JButton editBtn;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList mainList;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JButton upBtn;
    // End of variables declaration//GEN-END:variables

    private class ListSelectionListenerImpl implements ListSelectionListener {

        public ListSelectionListenerImpl() {
        }

        @Override
        public void valueChanged(ListSelectionEvent arg0) {
            boolean selected = mainList.getSelectedIndex() != -1;
            delResultColBtn.setEnabled(selected);
            editBtn.setEnabled(selected);
            upBtn.setEnabled(selected);
            downBtn.setEnabled(selected);
        }
    }

}
TOP

Related Classes of reportgen.gui.genepanel.corepanel.inlinepanel.InlineTablePanel$ListSelectionListenerImpl

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.