Search in sources :

Example 1 with LayerPrinter

use of org.eclipse.nebula.widgets.nattable.print.LayerPrinter 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

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 LayerPrinter (org.eclipse.nebula.widgets.nattable.print.LayerPrinter)1 PrintCommand (org.eclipse.nebula.widgets.nattable.print.command.PrintCommand)1 PrintCommandHandler (org.eclipse.nebula.widgets.nattable.print.command.PrintCommandHandler)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1