use of org.eclipse.nebula.widgets.nattable.export.command.ExportTableCommand in project nebula.widgets.nattable by eclipse.
the class MenuItemProviders method exportToImageMenuItemProvider.
/**
* Will create and return the {@link IMenuItemProvider} that adds the action
* for executing the {@link ExportTableCommand} to a popup menu. This
* command is intended to export the NatTable to image.
* <p>
* The {@link MenuItem} will be shown with the given menu label.
* </p>
* <p>
* <b>IMPORTANT:</b> the {@link ImageExporter} needs to be configured for
* the configuration attribute {@link ExportConfigAttributes#TABLE_EXPORTER}
* to really export to an image. Also the {@link ExportTableCommandHandler}
* needs to be registered on an {@link ILayer} in the layer stack, e.g. the
* GridLayer.
* </p>
*
* @param menuLabel
* The text that will be showed for the generated
* {@link MenuItem}
* @return The {@link IMenuItemProvider} for the {@link MenuItem} that
* executes the {@link ExportTableCommand}.
* @since 1.5
*/
public static IMenuItemProvider exportToImageMenuItemProvider(final String menuLabel) {
return new IMenuItemProvider() {
@Override
public void addMenuItem(final NatTable natTable, Menu popupMenu) {
MenuItem exportToImage = new MenuItem(popupMenu, SWT.PUSH);
exportToImage.setText(Messages.getLocalizedMessage(menuLabel));
// $NON-NLS-1$
exportToImage.setImage(GUIHelper.getImage("export_image"));
exportToImage.setEnabled(true);
exportToImage.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new ExportTableCommand(natTable.getConfigRegistry(), natTable.getShell()));
}
});
}
};
}
Aggregations