Search in sources :

Example 1 with MoveDirectionEnum

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum in project nebula.widgets.nattable by eclipse.

the class DateCellEditor method createEditorControl.

@Override
public DateTime createEditorControl(final Composite parent) {
    final DateTime dateControl = new DateTime(parent, SWT.DATE | SWT.DROP_DOWN);
    // set style information configured in the associated cell style
    dateControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    dateControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    dateControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    // add a key listener that will commit or close the editor for special
    // key strokes
    dateControl.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                boolean commit = (event.stateMask == SWT.MOD3) ? false : true;
                MoveDirectionEnum move = MoveDirectionEnum.NONE;
                if (DateCellEditor.this.moveSelectionOnEnter && DateCellEditor.this.editMode == EditModeEnum.INLINE) {
                    if (event.stateMask == 0) {
                        move = MoveDirectionEnum.DOWN;
                    } else if (event.stateMask == SWT.MOD2) {
                        move = MoveDirectionEnum.UP;
                    }
                }
                if (commit) {
                    commit(move);
                }
                if (DateCellEditor.this.editMode == EditModeEnum.DIALOG) {
                    parent.forceFocus();
                }
            } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
                close();
            }
        }
    });
    return dateControl;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MoveDirectionEnum(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum) KeyAdapter(org.eclipse.swt.events.KeyAdapter) DateTime(org.eclipse.swt.widgets.DateTime)

Example 2 with MoveDirectionEnum

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum in project nebula.widgets.nattable by eclipse.

the class AutoScrollDragMode method mouseMove.

@Override
public void mouseMove(NatTable natTable, MouseEvent event) {
    Rectangle clientArea = natTable.getClientAreaProvider().getClientArea();
    int x = event.x;
    int y = event.y;
    int horizontalDiff = 0;
    MoveDirectionEnum horizontal = MoveDirectionEnum.NONE;
    if (this.horizontal) {
        if (event.x < this.horizontalBorderOffset) {
            horizontal = MoveDirectionEnum.LEFT;
            x = Math.max(0, event.x);
            horizontalDiff = -event.x;
        } else if (event.x > (clientArea.width - this.horizontalBorderOffset)) {
            horizontal = MoveDirectionEnum.RIGHT;
            x = clientArea.width - 1;
            horizontalDiff = event.x - clientArea.width;
        }
    }
    int verticalDiff = 0;
    MoveDirectionEnum vertical = MoveDirectionEnum.NONE;
    if (this.vertical) {
        if (event.y < 0) {
            vertical = MoveDirectionEnum.UP;
            y = 0;
            verticalDiff = -event.y;
        } else if (event.y > clientArea.height) {
            vertical = MoveDirectionEnum.DOWN;
            y = clientArea.height - 1;
            verticalDiff = event.y - clientArea.height;
        }
    }
    if ((!MoveDirectionEnum.NONE.equals(horizontal) || !MoveDirectionEnum.NONE.equals(vertical)) && this.runnable == null) {
        this.runnable = new AutoScrollRunnable(natTable, x, y, horizontal, vertical);
        this.runnable.schedule();
    } else if (MoveDirectionEnum.NONE.equals(horizontal) && MoveDirectionEnum.NONE.equals(vertical) && this.runnable != null) {
        this.runnable.cancel();
        this.runnable = null;
    } else if (this.runnable != null) {
        this.runnable.calculateRepeatDelay(horizontalDiff, verticalDiff);
    }
    performDragAction(natTable, x, y, horizontal, vertical);
}
Also used : MoveDirectionEnum(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 3 with MoveDirectionEnum

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum in project nebula.widgets.nattable by eclipse.

the class CDateTimeCellEditor method createEditorControl.

@Override
public CDateTime createEditorControl(final Composite parent) {
    final CDateTime dateControl = new CDateTime(parent, this.style) {

        @Override
        protected Shell getContentShell() {
            Shell shell = super.getContentShell();
            shell.addShellListener(new ShellAdapter() {

                @Override
                public void shellActivated(ShellEvent e) {
                    if (CDateTimeCellEditor.this.focusListener instanceof InlineFocusListener) {
                        ((InlineFocusListener) CDateTimeCellEditor.this.focusListener).handleFocusChanges = false;
                    }
                }

                @Override
                public void shellClosed(ShellEvent e) {
                    if (CDateTimeCellEditor.this.focusListener instanceof InlineFocusListener) {
                        ((InlineFocusListener) CDateTimeCellEditor.this.focusListener).handleFocusChanges = true;
                    }
                }
            });
            return shell;
        }

        @Override
        protected void addTextListener() {
            super.addTextListener();
            this.text.getControl().addTraverseListener(new TraverseListener() {

                @Override
                public void keyTraversed(TraverseEvent event) {
                    boolean committed = false;
                    if (event.keyCode == SWT.TAB && event.stateMask == SWT.MOD2) {
                        committed = commit(MoveDirectionEnum.LEFT);
                    } else if (event.keyCode == SWT.TAB && event.stateMask == 0) {
                        committed = commit(MoveDirectionEnum.RIGHT);
                    } else if (event.detail == SWT.TRAVERSE_ESCAPE) {
                        close();
                    }
                    if (!committed) {
                        event.doit = false;
                    }
                }
            });
        }
    };
    // set style information configured in the associated cell style
    dateControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    dateControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    // StackOverflowError
    if ((this.style & CDT.SIMPLE) == 0) {
        dateControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    }
    dateControl.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            boolean commit = (event.stateMask == SWT.MOD3) ? false : true;
            MoveDirectionEnum move = MoveDirectionEnum.NONE;
            if (CDateTimeCellEditor.this.moveSelectionOnEnter && CDateTimeCellEditor.this.editMode == EditModeEnum.INLINE) {
                if (event.stateMask == 0) {
                    move = MoveDirectionEnum.DOWN;
                } else if (event.stateMask == SWT.MOD2) {
                    move = MoveDirectionEnum.UP;
                }
            }
            if (commit)
                commit(move);
            if (CDateTimeCellEditor.this.editMode == EditModeEnum.DIALOG) {
                parent.forceFocus();
            }
        }
    });
    return dateControl;
}
Also used : CDateTime(org.eclipse.nebula.widgets.cdatetime.CDateTime) Shell(org.eclipse.swt.widgets.Shell) ShellAdapter(org.eclipse.swt.events.ShellAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MoveDirectionEnum(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ShellEvent(org.eclipse.swt.events.ShellEvent)

Example 4 with MoveDirectionEnum

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum in project nebula.widgets.nattable by eclipse.

the class TextCellEditor method createEditorControl.

/**
 * Creates the editor control that is wrapped by this ICellEditor. Will use
 * the style configurations in ConfigRegistry for styling the control.
 *
 * @param parent
 *            The Composite that will be the parent of the new editor
 *            control. Can not be <code>null</code>
 * @param style
 *            The SWT style of the text control to create.
 * @return The created editor control that is wrapped by this ICellEditor.
 */
protected Text createEditorControl(final Composite parent, int style) {
    // create the Text control based on the specified style
    final Text textControl = new Text(parent, style);
    // set style information configured in the associated cell style
    textControl.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    textControl.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    textControl.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    textControl.setCursor(new Cursor(Display.getDefault(), SWT.CURSOR_IBEAM));
    // add a key listener that will commit or close the editor for special
    // key strokes and executes conversion/validation on input to the editor
    textControl.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (TextCellEditor.this.commitOnEnter && (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR)) {
                boolean commit = (event.stateMask == SWT.MOD3) ? false : true;
                MoveDirectionEnum move = MoveDirectionEnum.NONE;
                if (TextCellEditor.this.moveSelectionOnEnter && TextCellEditor.this.editMode == EditModeEnum.INLINE) {
                    if (event.stateMask == 0) {
                        move = MoveDirectionEnum.DOWN;
                    } else if (event.stateMask == SWT.MOD2) {
                        move = MoveDirectionEnum.UP;
                    }
                }
                if (commit) {
                    commit(move);
                }
                if (TextCellEditor.this.editMode == EditModeEnum.DIALOG) {
                    parent.forceFocus();
                }
            } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
                close();
            } else if ((TextCellEditor.this.commitOnUpDown || TextCellEditor.this.commitOnLeftRight) && TextCellEditor.this.editMode == EditModeEnum.INLINE) {
                Text control = (Text) event.widget;
                if (TextCellEditor.this.commitOnUpDown && event.keyCode == SWT.ARROW_UP) {
                    commit(MoveDirectionEnum.UP);
                } else if (TextCellEditor.this.commitOnUpDown && event.keyCode == SWT.ARROW_DOWN) {
                    commit(MoveDirectionEnum.DOWN);
                } else if (TextCellEditor.this.commitOnLeftRight && control.getSelectionCount() == 0 && event.keyCode == SWT.ARROW_LEFT && control.getCaretPosition() == 0) {
                    commit(MoveDirectionEnum.LEFT);
                } else if (TextCellEditor.this.commitOnLeftRight && control.getSelectionCount() == 0 && event.keyCode == SWT.ARROW_RIGHT && control.getCaretPosition() == control.getCharCount()) {
                    commit(MoveDirectionEnum.RIGHT);
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                // always do the conversion
                Object canonicalValue = getCanonicalValue(TextCellEditor.this.inputConversionErrorHandler);
                // and always do the validation, even if for committing the
                // validation should be skipped, on editing
                // a validation failure should be made visible
                // otherwise there would be no need for validation!
                validateCanonicalValue(canonicalValue, TextCellEditor.this.inputValidationErrorHandler);
            } catch (Exception ex) {
            // do nothing as exceptions caused by conversion or
            // validation are handled already we just need this catch
            // block for stopping the process if conversion failed with
            // an exception
            }
        }
    });
    return textControl;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MoveDirectionEnum(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) Cursor(org.eclipse.swt.graphics.Cursor)

Example 5 with MoveDirectionEnum

use of org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum in project nebula.widgets.nattable by eclipse.

the class ColumnGroupReorderLayer method updateColumnGroupModel.

/**
 * Updates the {@link ColumnGroupModel} with respect to a column reordering
 * operation.
 *
 * @param fromColumnPosition
 *            The column position that should be used for determining the
 *            necessary operation.
 * @param toColumnPosition
 *            The column position to which a column should be reordered.
 * @param reorderToLeftEdge
 *            Whether the toPosition should be calculated for attachment to
 *            the left or not.
 * @param fromColumnPositions
 *            The column positions that should be reordered.
 * @return <code>true</code> if only a {@link ColumnGroupModel} modification
 *         was triggered and no column reordering is necessary,
 *         <code>false</code> if additionally a column reordering needs to
 *         be performed.
 * @since 1.3
 */
public boolean updateColumnGroupModel(int fromColumnPosition, int toColumnPosition, boolean reorderToLeftEdge, List<Integer> fromColumnPositions) {
    MoveDirectionEnum moveDirection = ColumnGroupUtils.getMoveDirection(fromColumnPosition, toColumnPosition);
    if (reorderToLeftEdge && toColumnPosition > 0 && MoveDirectionEnum.RIGHT == moveDirection) {
        toColumnPosition--;
    }
    if (fromColumnPosition == -1 || toColumnPosition == -1) {
        log.error(// $NON-NLS-1$
        "Invalid reorder positions, fromPosition: " + fromColumnPosition + ", toPosition: " + // $NON-NLS-1$
        toColumnPosition);
    }
    boolean jump = Math.abs(fromColumnPosition - toColumnPosition) > 1;
    int fromColumnIndex = this.getUnderlyingLayer().getColumnIndexByPosition(fromColumnPosition);
    int toColumnIndex = this.getUnderlyingLayer().getColumnIndexByPosition(toColumnPosition);
    // check if the column to reorder is part of a group
    ColumnGroup fromColumnGroup = this.model.getColumnGroupByIndex(fromColumnIndex);
    ColumnGroup toColumnGroup = this.model.getColumnGroupByIndex(toColumnIndex);
    int[] fromColumnIndexes = getColumnIndexesForPositions(fromColumnPositions);
    boolean consumeCommand = false;
    // without group modifications
    if (fromColumnGroup != null && toColumnGroup != null && fromColumnGroup.getName().equals(toColumnGroup.getName()) && fromColumnPosition == toColumnPosition) {
        // handle first/last column in last group
        if (fromColumnIndexes.length > 1) {
            if (MoveDirectionEnum.RIGHT == moveDirection) {
                // check if there are columns to the left that are reordered
                // too
                int collectionPos = fromColumnPositions.indexOf(Integer.valueOf(fromColumnPosition));
                if (collectionPos > 0) {
                    this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                } else {
                    this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
            } else if (MoveDirectionEnum.LEFT == moveDirection) {
                // check if there are columns to the right that are
                // reordered too
                int collectionPos = fromColumnPositions.indexOf(Integer.valueOf(fromColumnPosition));
                if (collectionPos == 0) {
                    this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                } else {
                    this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
            }
        } else {
            // only remove if we are at the edge of a column group
            if (ColumnGroupUtils.isLeftEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model) || ColumnGroupUtils.isRightEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model)) {
                this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
            }
        }
        consumeCommand = true;
    } else if (fromColumnGroup == null && toColumnGroup != null) {
        // special case
        // add the column to the column group if we step instead of jumping
        consumeCommand = this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
        if (jump) {
            consumeCommand = false;
        }
    } else if (fromColumnGroup != null && toColumnGroup == null) {
        this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
    } else if (fromColumnGroup == null && toColumnGroup == null && fromColumnPosition == toColumnPosition) {
        // this might happen on drag and drop operations when trying to add
        // a column back into an adjacent column group
        int adjacentPos = (moveDirection == MoveDirectionEnum.RIGHT) ? fromColumnPosition + 1 : fromColumnPosition - 1;
        int adjacentIndex = this.getUnderlyingLayer().getColumnIndexByPosition(adjacentPos);
        // check if there is an adjacent column group
        ColumnGroup adjacentColumnGroup = this.model.getColumnGroupByIndex(adjacentIndex);
        if (adjacentColumnGroup != null) {
            this.model.insertColumnIndexes(adjacentColumnGroup.getName(), fromColumnIndexes);
            consumeCommand = false;
        }
    } else if (fromColumnGroup != null && toColumnGroup != null && !fromColumnGroup.getName().equals(toColumnGroup.getName())) {
        // of the current column group
        if (MoveDirectionEnum.RIGHT == moveDirection) {
            if (toColumnGroup != null) {
                // check if reorder is started from right edge of a group
                boolean fromRightEdge = ColumnGroupUtils.isRightEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model);
                boolean removed = true;
                if (fromColumnGroup != null) {
                    removed = this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
                if (removed && ((!fromRightEdge && !jump) || jump)) {
                    // column removed from another group
                    // not from the right edge of another group
                    // add it to the following group
                    consumeCommand = this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                    if (jump) {
                        consumeCommand = !jump;
                    }
                } else {
                    consumeCommand = !jump;
                }
            }
        } else if (MoveDirectionEnum.LEFT == moveDirection) {
            if (toColumnGroup != null) {
                // check if reorder is started from left edge of a group
                boolean fromLeftEdge = ColumnGroupUtils.isLeftEdgeOfAColumnGroup(this, fromColumnPosition, fromColumnIndex, this.model);
                boolean removed = true;
                if (fromColumnGroup != null) {
                    removed = this.model.removeColumnIndexes(fromColumnGroup.getName(), fromColumnIndexes);
                }
                if (removed && ((!fromLeftEdge && !jump) || jump)) {
                    // column removed from another group
                    // not from the left edge of another group
                    // add it to the previous group
                    consumeCommand = this.model.insertColumnIndexes(toColumnGroup.getName(), fromColumnIndexes);
                    if (jump) {
                        consumeCommand = !jump;
                    }
                } else {
                    consumeCommand = !jump;
                }
            }
        }
    }
    // don't consume the command to perform reordering
    return consumeCommand;
}
Also used : MoveDirectionEnum(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum) ColumnGroup(org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)

Aggregations

MoveDirectionEnum (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum)5 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 CDateTime (org.eclipse.nebula.widgets.cdatetime.CDateTime)1 ColumnGroup (org.eclipse.nebula.widgets.nattable.group.ColumnGroupModel.ColumnGroup)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellAdapter (org.eclipse.swt.events.ShellAdapter)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 Cursor (org.eclipse.swt.graphics.Cursor)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 DateTime (org.eclipse.swt.widgets.DateTime)1 Shell (org.eclipse.swt.widgets.Shell)1 Text (org.eclipse.swt.widgets.Text)1