Search in sources :

Example 1 with ColumnSelectionList

use of org.knime.core.node.util.ColumnSelectionList in project knime-core by knime.

the class DnDColumnSelectionSearchableListPanel method enableDragAndDropSupport.

/**
 * Convenient method to enable the drag and drop support of the list view at the left side.
 *
 * @param dndStateListener notified if drag is started and finished
 * @since 2.11
 */
public void enableDragAndDropSupport(final DnDStateListener dndStateListener) {
    ColumnSelectionList columnList = getColumnList();
    columnList.setDragEnabled(true);
    JPopupMenu popup = new JPopupMenu();
    final JMenuItem jMenuItem = new JMenuItem("New Configuration", DnDConfigurationPanel.ADD_ICON_16);
    popup.add(jMenuItem);
    popup.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
            boolean enable = true;
            for (DataColumnSpec col : getSelectedColumns()) {
                if (m_configuredColumnDeterminer.isConfiguredColumn(col)) {
                    enable = false;
                    break;
                }
            }
            jMenuItem.setEnabled(enable);
        }

        @Override
        public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(final PopupMenuEvent e) {
        }
    });
    jMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            fireConfigurationRequested(Type.CREATION);
        }
    });
    columnList.setComponentPopupMenu(popup);
    final TransferHandler handler = columnList.getTransferHandler();
    columnList.setTransferHandler(new DnDColumnSpecSourceTransferHandler(handler, dndStateListener) {

        @Override
        protected List<DataColumnSpec> getColumnsSpecsToDrag() {
            return getSelectedColumns();
        }
    });
}
Also used : ColumnSelectionList(org.knime.core.node.util.ColumnSelectionList) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) TransferHandler(javax.swing.TransferHandler) List(java.util.List) ColumnSelectionList(org.knime.core.node.util.ColumnSelectionList) JMenuItem(javax.swing.JMenuItem) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 List (java.util.List)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 TransferHandler (javax.swing.TransferHandler)1 PopupMenuEvent (javax.swing.event.PopupMenuEvent)1 PopupMenuListener (javax.swing.event.PopupMenuListener)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 ColumnSelectionList (org.knime.core.node.util.ColumnSelectionList)1