* @param columns Columns
* @param acm AttributeColumnsManipulator
* @return Prepared JCommandButton
*/
private JCommandButton prepareJCommandButton(final AttributeTable table, final AttributeColumn[] columns, final AttributeColumnsManipulator acm) {
JCommandButton manipulatorButton;
if (acm.getIcon() != null) {
manipulatorButton = new JCommandButton(acm.getName(), ImageWrapperResizableIcon.getIcon(acm.getIcon(), new Dimension(16, 16)));
} else {
manipulatorButton = new JCommandButton(acm.getName());
}
manipulatorButton.setCommandButtonKind(JCommandButton.CommandButtonKind.POPUP_ONLY);
manipulatorButton.setDisplayState(CommandButtonDisplayState.MEDIUM);
if (acm.getDescription() != null && !acm.getDescription().isEmpty()) {
manipulatorButton.setPopupRichTooltip(new RichTooltip(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.RichToolTip.title.text"), acm.getDescription()));
}
final ArrayList<AttributeColumn> availableColumns = new ArrayList<AttributeColumn>();
for (final AttributeColumn column : columns) {
if (acm.canManipulateColumn(table, column)) {
availableColumns.add(column);
}
}
if (!availableColumns.isEmpty()) {
manipulatorButton.setPopupCallback(new PopupPanelCallback() {
public JPopupPanel getPopupPanel(JCommandButton jcb) {
JCommandPopupMenu popup = new JCommandPopupMenu();
JCommandMenuButton button;
for (final AttributeColumn column : availableColumns) {
button = new JCommandMenuButton(column.getTitle(), ImageWrapperResizableIcon.getIcon(ImageUtilities.loadImage("org/gephi/desktop/datalab/resources/column.png"), new Dimension(16, 16)));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DataLaboratoryHelper.getDefault().executeAttributeColumnsManipulator(acm, table, column);
}
});
popup.addMenuButton(button);
}
return popup;
}
});
} else {
manipulatorButton.setEnabled(false);
}
return manipulatorButton;
}