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();
}
});
}
Aggregations