Search in sources :

Example 1 with PrintCommandHandler

use of org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler in project nebula.widgets.nattable by eclipse.

the class GridLayer method registerCommandHandlers.

@Override
protected void registerCommandHandlers() {
    registerCommandHandler(new PrintCommandHandler(this));
    registerCommandHandler(new ExportCommandHandler(this));
    registerCommandHandler(new AutoResizeColumnCommandHandler(this));
    registerCommandHandler(new AutoResizeRowCommandHandler(this));
}
Also used : PrintCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler) AutoResizeRowCommandHandler(org.eclipse.nebula.widgets.nattable.grid.command.AutoResizeRowCommandHandler) ExportCommandHandler(org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler) AutoResizeColumnCommandHandler(org.eclipse.nebula.widgets.nattable.grid.command.AutoResizeColumnCommandHandler)

Example 2 with PrintCommandHandler

use of org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler in project nebula.widgets.nattable by eclipse.

the class _801_VerticalCompositionWithFeaturesExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    ConfigRegistry configRegistry = new ConfigRegistry();
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(false, false).applyTo(buttonPanel);
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    List<Person> values = PersonService.getPersons(10);
    final EventList<Person> eventList = GlazedLists.eventList(values);
    TransformedList<Person, Person> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
    // use the SortedList constructor with 'null' for the Comparator because
    // the Comparator will be set by configuration
    SortedList<Person> sortedList = new SortedList<>(rowObjectsGlazedList, null);
    // wrap the SortedList with the FilterList
    FilterList<Person> filterList = new FilterList<>(sortedList);
    IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
    final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
    GlazedListsEventLayer<Person> eventLayer = new GlazedListsEventLayer<>(bodyDataLayer, filterList);
    final SelectionLayer selectionLayer = new SelectionLayer(eventLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    // add sorting
    SortHeaderLayer<Person> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer), false);
    // add the filter row functionality
    final FilterRowHeaderComposite<Person> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(filterList, columnPropertyAccessor, configRegistry), sortHeaderLayer, columnHeaderDataProvider, configRegistry);
    // set the region labels to make default configurations work, e.g.
    // editing, selection
    CompositeLayer compositeLayer = new CompositeLayer(1, 2);
    compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, filterRowHeaderLayer, 0, 0);
    compositeLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
    // add edit configurations
    compositeLayer.addConfiguration(new DefaultEditConfiguration());
    compositeLayer.addConfiguration(new DefaultEditBindings());
    // add print support
    compositeLayer.registerCommandHandler(new PrintCommandHandler(compositeLayer));
    compositeLayer.addConfiguration(new DefaultPrintBindings());
    // add excel export support
    compositeLayer.registerCommandHandler(new ExportCommandHandler(compositeLayer));
    compositeLayer.addConfiguration(new DefaultExportBindings());
    final NatTable natTable = new NatTable(gridPanel, compositeLayer, false);
    natTable.setConfigRegistry(configRegistry);
    // adding this configuration adds the styles and the painters to use
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
            // birthday is never editable
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Gender.FEMALE, Gender.MALE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, getGenderBooleanConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new ComboBoxCellEditor(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
        }
    });
    natTable.configure();
    final RowSelectionProvider<Person> selectionProvider = new RowSelectionProvider<>(selectionLayer, bodyDataProvider, false);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Button button = new Button(buttonPanel, SWT.PUSH);
    button.setText("Remove selected item");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // the NatTable context
            if (natTable.getActiveCellEditor() != null) {
                natTable.commitAndCloseActiveCellEditor();
            }
            Person item = (Person) ((IStructuredSelection) selectionProvider.getSelection()).getFirstElement();
            eventList.remove(item);
        }
    });
    return panel;
}
Also used : HashMap(java.util.HashMap) DefaultPrintBindings(org.eclipse.nebula.widgets.nattable.print.config.DefaultPrintBindings) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) SortedList(ca.odell.glazedlists.SortedList) DefaultExportBindings(org.eclipse.nebula.widgets.nattable.export.config.DefaultExportBindings) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) ExportCommandHandler(org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) GridLayout(org.eclipse.swt.layout.GridLayout) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) PrintCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler) Composite(org.eclipse.swt.widgets.Composite) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FilterList(ca.odell.glazedlists.FilterList) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 3 with PrintCommandHandler

use of org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler in project nebula.widgets.nattable by eclipse.

the class _761_PrintExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(100), propertyNames);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // add the PrintCommandHandler to the ViewportLayer in order to make
    // printing work
    viewportLayer.registerCommandHandler(new PrintCommandHandler(viewportLayer));
    final NatTable natTable = new NatTable(gridPanel, viewportLayer, false);
    // adding this configuration adds the styles and the painters to use
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new DefaultPrintBindings());
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("Print");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new PrintCommand(natTable.getConfigRegistry(), natTable.getShell()));
        }
    });
    return panel;
}
Also used : PrintCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler) Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) DefaultPrintBindings(org.eclipse.nebula.widgets.nattable.print.config.DefaultPrintBindings) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) PrintCommand(org.eclipse.nebula.widgets.nattable.print.command.PrintCommand) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable)

Example 4 with PrintCommandHandler

use of org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler in project nebula.widgets.nattable by eclipse.

the class _762_MultiPrintExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Composite gridPanel = new Composite(panel, SWT.NONE);
    gridPanel.setLayout(layout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
    Composite buttonPanel = new Composite(panel, SWT.NONE);
    buttonPanel.setLayout(new GridLayout(4, false));
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    NatTable headerTable = createSmallTable(gridPanel);
    NatTable bodyTable = createGrid(gridPanel);
    // create a custom command handler for printing of multiple NatTable
    // instances
    PrintCommandHandler handler = new PrintCommandHandler(headerTable.getLayer()) {

        @Override
        public boolean doCommand(PrintCommand command) {
            LayerPrinter printer = new LayerPrinter(headerTable, headerTable.getConfigRegistry(), _762_MultiPrintExample.this.repeatHeaderTableButton.getSelection());
            printer.joinPrintTargets(_762_MultiPrintExample.this.joinTablesButton.getSelection());
            if (_762_MultiPrintExample.this.repeatColumnHeaderButton.getSelection()) {
                printer.addPrintTarget(bodyTable, ((GridLayer) bodyTable.getLayer()).getColumnHeaderLayer(), bodyTable.getConfigRegistry());
            } else {
                printer.addPrintTarget(bodyTable, bodyTable.getConfigRegistry());
            }
            printer.print(headerTable.getShell());
            return true;
        }
    };
    // register the handler to both NatTable instances
    headerTable.getLayer().registerCommandHandler(handler);
    bodyTable.getLayer().registerCommandHandler(handler);
    Composite multiTableConfigPanel = new Composite(buttonPanel, SWT.NONE);
    multiTableConfigPanel.setLayout(new RowLayout(SWT.VERTICAL));
    this.joinTablesButton = new Button(multiTableConfigPanel, SWT.CHECK);
    this.joinTablesButton.setText("Join Tables");
    this.repeatHeaderTableButton = new Button(multiTableConfigPanel, SWT.CHECK);
    this.repeatHeaderTableButton.setText("Repeat Header Table");
    this.repeatColumnHeaderButton = new Button(multiTableConfigPanel, SWT.CHECK);
    this.repeatColumnHeaderButton.setText("Repeat Column Header");
    Composite fittingConfigPanel = new Composite(buttonPanel, SWT.NONE);
    fittingConfigPanel.setLayout(new RowLayout(SWT.VERTICAL));
    Button fitHorizontalButton = new Button(fittingConfigPanel, SWT.CHECK);
    fitHorizontalButton.setText("Fit Horizontally");
    Button fitVerticalButton = new Button(fittingConfigPanel, SWT.CHECK);
    fitVerticalButton.setText("Fit Vertically");
    Button stretchButton = new Button(fittingConfigPanel, SWT.CHECK);
    stretchButton.setText("Stretch");
    stretchButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            headerTable.getConfigRegistry().registerConfigAttribute(PrintConfigAttributes.STRETCH, stretchButton.getSelection());
        }
    });
    fitHorizontalButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateFittingConfig(headerTable.getConfigRegistry(), fitHorizontalButton.getSelection(), fitVerticalButton.getSelection());
        }
    });
    fitVerticalButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateFittingConfig(headerTable.getConfigRegistry(), fitHorizontalButton.getSelection(), fitVerticalButton.getSelection());
        }
    });
    Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
    addColumnButton.setText("Print");
    addColumnButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            headerTable.doCommand(new PrintCommand(headerTable.getConfigRegistry(), headerTable.getShell()));
        }
    });
    return panel;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) PrintCommandHandler(org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) PrintCommand(org.eclipse.nebula.widgets.nattable.print.command.PrintCommand) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) LayerPrinter(org.eclipse.nebula.widgets.nattable.print.LayerPrinter)

Aggregations

PrintCommandHandler (org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 HashMap (java.util.HashMap)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 ExportCommandHandler (org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 PrintCommand (org.eclipse.nebula.widgets.nattable.print.command.PrintCommand)2 DefaultPrintBindings (org.eclipse.nebula.widgets.nattable.print.config.DefaultPrintBindings)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)2 Composite (org.eclipse.swt.widgets.Composite)2 FilterList (ca.odell.glazedlists.FilterList)1 SortedList (ca.odell.glazedlists.SortedList)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1