Search in sources :

Example 1 with ExportTableCommand

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()));
                }
            });
        }
    };
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) ExportTableCommand(org.eclipse.nebula.widgets.nattable.export.command.ExportTableCommand)

Aggregations

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 ExportTableCommand (org.eclipse.nebula.widgets.nattable.export.command.ExportTableCommand)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1