in ui/src/main/java/org/apache/hop/ui/core/widget/TableView.java [792:1063]
private KeyListener createTableKeyListener() {
return new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (activeTableItem == null) {
return;
}
int maxcols = table.getColumnCount();
int maxrows = table.getItemCount();
boolean shift = (e.stateMask & SWT.SHIFT) != 0;
if (!previousShift && shift || selectionStart < 0) {
// Shift is pressed down: reset start of selection
// No start of selection known? reset as well.
selectionStart = activeTableRow;
}
previousShift = shift;
boolean ctrl = ((e.stateMask & SWT.MOD1) != 0);
// Move rows up or down shortcuts...
if (!readonly && e.keyCode == SWT.ARROW_DOWN && ctrl) {
moveRowsDown();
e.doit = false;
return;
}
if (!readonly && e.keyCode == SWT.ARROW_UP && ctrl) {
moveRowsUp();
e.doit = false;
return;
}
// Select extra row down
if (e.keyCode == SWT.ARROW_DOWN && shift) {
activeTableRow++;
if (activeTableRow >= maxrows) {
activeTableRow = maxrows - 1;
}
selectRows(selectionStart, activeTableRow);
table.showItem(table.getItem(activeTableRow));
e.doit = false;
return;
}
// Select extra row up
if (e.keyCode == SWT.ARROW_UP && shift) {
activeTableRow--;
if (activeTableRow < 0) {
activeTableRow = 0;
}
selectRows(activeTableRow, selectionStart);
table.showItem(table.getItem(activeTableRow));
e.doit = false;
return;
}
// Select all rows until end
if (e.keyCode == SWT.HOME && shift) {
activeTableRow = 0;
// Select all indices from "from_selection" to "row"
//
selectRows(selectionStart, activeTableRow);
table.showItem(activeTableItem);
e.doit = false;
return;
}
// Select extra row up
if (e.keyCode == SWT.END && shift) {
activeTableRow = maxrows;
selectRows(selectionStart, activeTableRow);
table.showItem(activeTableItem);
e.doit = false;
return;
}
// Move cursor: set selection on the row in question.
if ((e.keyCode == SWT.ARROW_DOWN && !shift)
|| (e.keyCode == SWT.ARROW_UP && !shift)
|| (e.keyCode == SWT.HOME && !shift)
|| (e.keyCode == SWT.END && !shift)) {
switch (e.keyCode) {
case SWT.ARROW_DOWN:
activeTableRow++;
if (activeTableRow >= maxrows) {
if (!readonly) {
insertRowAfter();
} else {
activeTableRow = maxrows - 1;
}
}
break;
case SWT.ARROW_UP:
activeTableRow--;
if (activeTableRow < 0) {
activeTableRow = 0;
}
break;
case SWT.HOME:
activeTableRow = 0;
break;
case SWT.END:
activeTableRow = maxrows - 1;
break;
default:
break;
}
setPosition(activeTableRow, activeTableColumn);
table.deselectAll();
table.select(activeTableRow);
table.showItem(table.getItem(activeTableRow));
e.doit = false;
return;
}
// CTRL-A --> Select All lines
if (e.keyCode == 'a' && ctrl) {
e.doit = false;
selectAll();
return;
}
// ESC --> unselect all
if (e.keyCode == SWT.ESC) {
e.doit = false;
unselectAll();
selectRows(activeTableRow, activeTableRow);
setFocus();
return;
}
// CTRL-C --> Copy selected lines to clipboard
if (e.keyCode == 'c' && ctrl) {
e.doit = false;
clipSelected();
return;
}
// CTRL-K --> keep only selected lines
if (!readonly && e.keyCode == 'k' && ctrl) {
e.doit = false;
keepSelected();
return;
}
// CTRL-X --> Cut selected infomation...
if (!readonly && e.keyCode == 'x' && ctrl) {
e.doit = false;
cutSelected();
return;
}
// CTRL-V --> Paste selected infomation...
if (!readonly && e.keyCode == 'v' && ctrl) {
e.doit = false;
pasteSelected();
return;
}
// F3 --> optimal width including headers
if (e.keyCode == SWT.F3) {
e.doit = false;
optWidth(true);
return;
}
// DEL --> delete selected lines
if (!readonly && e.keyCode == SWT.DEL) {
e.doit = false;
delSelected();
return;
}
// F4 --> optimal width excluding headers
if (e.keyCode == SWT.F4) {
e.doit = false;
optWidth(false);
return;
}
if (undoEnabled) {
// CTRL-Y --> redo action
if (e.keyCode == 'y' && ctrl) {
e.doit = false;
redoAction();
return;
}
// CTRL-Z --> undo action
if (e.keyCode == 'z' && ctrl) {
e.doit = false;
undoAction();
return;
}
}
// Return: edit the first field in the row.
if (e.keyCode == SWT.CR || e.keyCode == SWT.ARROW_RIGHT || e.keyCode == SWT.TAB) {
activeTableColumn = 1;
edit(activeTableRow, activeTableColumn);
e.doit = false;
return;
}
if (activeTableColumn > 0) {
boolean textChar =
(e.character >= 'a' && e.character <= 'z')
|| (e.character >= 'A' && e.character <= 'Z')
|| (e.character >= '0' && e.character <= '9')
|| (e.character == ' ')
|| (e.character == '_')
|| (e.character == ',')
|| (e.character == '.')
|| (e.character == '+')
|| (e.character == '-')
|| (e.character == '*')
|| (e.character == '/')
|| (e.character == ';');
// character a-z, A-Z, 0-9: start typing...
if (e.character == SWT.CR || e.keyCode == SWT.F2 || textChar) {
boolean selectText = true;
char extraChar = 0;
if (textChar) {
extraChar = e.character;
selectText = false;
}
e.doit = false;
edit(activeTableRow, activeTableColumn, selectText, extraChar);
}
if (e.character == SWT.TAB) {
// TAB
if (e.keyCode == SWT.TAB && ((e.stateMask & SWT.SHIFT) == 0)) {
activeTableColumn++;
}
// Shift Tab
if (e.keyCode == SWT.TAB && ((e.stateMask & SWT.SHIFT) != 0)) {
activeTableColumn--;
}
if (activeTableColumn < 1) { // from SHIFT-TAB
activeTableColumn = maxcols - 1;
if (activeTableRow > 0) {
activeTableRow--;
}
}
if (activeTableColumn >= maxcols) { // from TAB
activeTableColumn = 1;
activeTableRow++;
}
// Tab beyond last line: add a line to table!
if (activeTableRow >= maxrows) {
TableItem item = new TableItem(table, SWT.NONE, activeTableRow);
item.setText(1, "");
setRowNums();
}
e.doit = false;
edit(activeTableRow, activeTableColumn);
}
}
setFocus();
table.setFocus();
}
};
}