Search in sources :

Example 1 with PeakIdentitySetupDialog

use of net.sf.mzmine.util.dialogs.PeakIdentitySetupDialog in project mzmine2 by mzmine.

the class PeakListTable method getCellEditor.

public TableCellEditor getCellEditor(int row, int column) {
    CommonColumnType commonColumn = pkTableModel.getCommonColumn(column);
    if (commonColumn == CommonColumnType.IDENTITY) {
        row = this.convertRowIndexToModel(row);
        peakListRow = peakList.getRow(row);
        PeakIdentity[] identities = peakListRow.getPeakIdentities();
        PeakIdentity preferredIdentity = peakListRow.getPreferredPeakIdentity();
        JComboBox<Object> combo;
        if ((identities != null) && (identities.length > 0)) {
            combo = new JComboBox<Object>(identities);
            combo.addItem("-------------------------");
            combo.addItem(REMOVE_IDENTITY);
            combo.addItem(EDIT_IDENTITY);
        } else {
            combo = new JComboBox<Object>();
        }
        combo.setFont(comboFont);
        combo.addItem(NEW_IDENTITY);
        if (preferredIdentity != null) {
            combo.setSelectedItem(preferredIdentity);
        }
        combo.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                JComboBox<?> combo = (JComboBox<?>) e.getSource();
                Object item = combo.getSelectedItem();
                if (item != null) {
                    if (item.toString() == NEW_IDENTITY) {
                        PeakIdentitySetupDialog dialog = new PeakIdentitySetupDialog(window, peakListRow);
                        dialog.setVisible(true);
                        return;
                    }
                    if (item.toString() == EDIT_IDENTITY) {
                        PeakIdentitySetupDialog dialog = new PeakIdentitySetupDialog(window, peakListRow, peakListRow.getPreferredPeakIdentity());
                        dialog.setVisible(true);
                        return;
                    }
                    if (item.toString() == REMOVE_IDENTITY) {
                        PeakIdentity identity = peakListRow.getPreferredPeakIdentity();
                        if (identity != null) {
                            peakListRow.removePeakIdentity(identity);
                            DefaultComboBoxModel<?> comboModel = (DefaultComboBoxModel<?>) combo.getModel();
                            comboModel.removeElement(identity);
                        }
                        return;
                    }
                    if (item instanceof PeakIdentity) {
                        peakListRow.setPreferredPeakIdentity((PeakIdentity) item);
                        return;
                    }
                }
            }
        });
        // Keep the reference to the editor
        currentEditor = new DefaultCellEditor(combo);
        return currentEditor;
    }
    return super.getCellEditor(row, column);
}
Also used : PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) ActionListener(java.awt.event.ActionListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) PeakIdentitySetupDialog(net.sf.mzmine.util.dialogs.PeakIdentitySetupDialog) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JComboBox (javax.swing.JComboBox)1 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)1 PeakIdentitySetupDialog (net.sf.mzmine.util.dialogs.PeakIdentitySetupDialog)1