Search in sources :

Example 46 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class NatTable method initInternalListener.

protected void initInternalListener() {
    this.modeSupport = new ModeSupport(this);
    this.modeSupport.registerModeEventHandler(Mode.NORMAL_MODE, new ConfigurableModeEventHandler(this.modeSupport, this));
    this.modeSupport.switchMode(Mode.NORMAL_MODE);
    addPaintListener(this);
    addFocusListener(new FocusListener() {

        @Override
        public void focusLost(final FocusEvent arg0) {
            redraw();
        }

        @Override
        public void focusGained(final FocusEvent arg0) {
            redraw();
        }
    });
    addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(final Event e) {
            doCommand(new ClientAreaResizeCommand(NatTable.this));
            redraw();
        }
    });
}
Also used : ModeSupport(org.eclipse.nebula.widgets.nattable.ui.mode.ModeSupport) DisposeListener(org.eclipse.swt.events.DisposeListener) PaintListener(org.eclipse.swt.events.PaintListener) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) ConfigurableModeEventHandler(org.eclipse.nebula.widgets.nattable.ui.mode.ConfigurableModeEventHandler) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) CellVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.CellVisualUpdateEvent) CellEditorCreatedEvent(org.eclipse.nebula.widgets.nattable.edit.CellEditorCreatedEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) CellSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent) ColumnVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnVisualUpdateEvent) IVisualChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IVisualChangeEvent) Event(org.eclipse.swt.widgets.Event) RowVisualUpdateEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowVisualUpdateEvent) RowSelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent) ISelectionEvent(org.eclipse.nebula.widgets.nattable.selection.event.ISelectionEvent) ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 47 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class DataLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        boolean refresh = false;
        if (isColumnPercentageSizing()) {
            this.columnWidthConfig.calculatePercentages(this.columnWidthConfig.downScale(clientAreaResizeCommand.getCalcArea().width), getColumnCount());
            refresh = true;
        }
        if (isRowPercentageSizing()) {
            this.rowHeightConfig.calculatePercentages(this.rowHeightConfig.downScale(clientAreaResizeCommand.getCalcArea().height), getRowCount());
            refresh = true;
        }
        if (refresh) {
            fireLayerEvent(new ResizeStructuralRefreshEvent(this));
        }
        return refresh;
    } else if (command instanceof StructuralRefreshCommand) {
        // that the percentage values are re-calculated
        if (isColumnPercentageSizing()) {
            this.columnWidthConfig.updatePercentageValues(getColumnCount());
        }
        if (isRowPercentageSizing()) {
            this.rowHeightConfig.updatePercentageValues(getRowCount());
        }
    }
    return super.doCommand(command);
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) ResizeStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.ResizeStructuralRefreshEvent)

Example 48 with ClientAreaResizeCommand

use of org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof SelectCellCommand && command.convertToTargetLayer(this)) {
        // perform selection of level on level header click
        SelectCellCommand selection = (SelectCellCommand) command;
        if (isLevelHeaderColumn(selection.getColumnPosition())) {
            ILayerCell clickedCell = getCellByPosition(selection.getColumnPosition(), selection.getRowPosition());
            // calculate number of header columns to the right
            int levelHeaderCount = 0;
            for (int i = this.levelHeaderPositions.length - 1; i >= 0; i--) {
                if (this.levelHeaderPositions[i] >= selection.getColumnPosition()) {
                    levelHeaderCount++;
                }
            }
            SelectRegionCommand selectRegion = new SelectRegionCommand(this, clickedCell.getColumnPosition() + 1, clickedCell.getOriginRowPosition(), getColumnCount() - levelHeaderCount - (clickedCell.getColumnPosition()), clickedCell.getRowSpan(), selection.isShiftMask(), selection.isControlMask());
            this.underlyingLayer.doCommand(selectRegion);
            return true;
        }
    } else if (command instanceof ConfigureScalingCommand) {
        this.dpiConverter = ((ConfigureScalingCommand) command).getHorizontalDpiConverter();
    } else if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        Rectangle possibleArea = clientAreaResizeCommand.getScrollable().getClientArea();
        // remove the tree level header width from the client area to
        // ensure that the percentage calculation is correct
        possibleArea.width = possibleArea.width - (this.levelHeaderPositions.length * getScaledLevelHeaderWidth());
        clientAreaResizeCommand.setCalcArea(possibleArea);
    } else if (command instanceof ColumnReorderCommand) {
        ColumnReorderCommand crCommand = ((ColumnReorderCommand) command);
        if (!isValidTargetColumnPosition(crCommand.getFromColumnPosition(), crCommand.getToColumnPosition())) {
            // command without doing anything
            return true;
        }
        if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
            // tree level header
            return super.doCommand(new ColumnReorderCommand(this, crCommand.getFromColumnPosition(), crCommand.getToColumnPosition() + 1));
        }
    } else if (command instanceof MultiColumnReorderCommand) {
        MultiColumnReorderCommand crCommand = ((MultiColumnReorderCommand) command);
        for (int fromColumnPosition : crCommand.getFromColumnPositions()) {
            if (!isValidTargetColumnPosition(fromColumnPosition, crCommand.getToColumnPosition())) {
                // command would be skipped
                return true;
            }
        }
        if (isLevelHeaderColumn(crCommand.getToColumnPosition())) {
            // tree level header
            return super.doCommand(new MultiColumnReorderCommand(this, crCommand.getFromColumnPositions(), crCommand.getToColumnPosition() + 1));
        }
    }
    return super.doCommand(command);
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ConfigureScalingCommand(org.eclipse.nebula.widgets.nattable.layer.command.ConfigureScalingCommand)

Aggregations

ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)48 Rectangle (org.eclipse.swt.graphics.Rectangle)46 Test (org.junit.Test)31 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)17 Shell (org.eclipse.swt.widgets.Shell)17 Before (org.junit.Before)9 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)4 Properties (java.util.Properties)3 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)3 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)3 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)2 RowResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.RowResizeCommand)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)1 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)1 CellEditorCreatedEvent (org.eclipse.nebula.widgets.nattable.edit.CellEditorCreatedEvent)1