use of org.eclipse.swt.events.KeyEvent in project translationstudio8 by heartsome.
the class EnumComboEditor method getEditorControl.
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
_items = new Object[] {};
if (_combo == null) {
_combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
_combo.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_combo.addFocusListener(this);
}
Class<?> clazz = column.getContentClass(row);
if (clazz != null && Enum.class.isAssignableFrom(clazz)) {
_items = clazz.getEnumConstants();
} else {
_items = new Object[] {};
}
Object value = column.getValue(row);
_oldVal = value;
int selIdx = -1;
String[] stringItems = new String[_items.length];
for (int i = 0; i < _items.length; i++) {
stringItems[i] = _items[i].toString();
if (value != null && value.equals(_items[i])) {
selIdx = i;
}
}
_combo.setItems(stringItems);
if (selIdx != -1) {
_combo.select(selIdx);
}
return _combo;
}
use of org.eclipse.swt.events.KeyEvent in project translationstudio8 by heartsome.
the class ObjectComboEditor method getEditorControl.
/**
* {@inheritDoc}
*/
public Control getEditorControl(JaretTable table, IRow row, IColumn column, char typedKey) {
super.getEditorControl(table, row, column, typedKey);
if (_combo == null) {
_combo = new Combo(table, SWT.BORDER | SWT.READ_ONLY);
_combo.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_combo.addFocusListener(this);
_combo.setItems(_stringItems);
}
Object value = column.getValue(row);
_oldVal = value;
int selIdx = -1;
if (_allowNull && value == null) {
selIdx = 0;
} else {
selIdx = _itemList.indexOf(value);
selIdx = _allowNull ? selIdx + 1 : selIdx;
}
if (selIdx != -1) {
_combo.select(selIdx);
}
return _combo;
}
use of org.eclipse.swt.events.KeyEvent in project translationstudio8 by heartsome.
the class IntegerCellEditor method createControl.
/**
* Create the control.
*
* @param table parent table
*/
private void createControl(JaretTable table) {
if (_spinner == null) {
_table = table;
_spinner = new Spinner(table, SWT.BORDER);
_spinner.setMaximum(_max);
_spinner.setMinimum(_min);
_spinner.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
e.doit = false;
}
});
_spinner.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
event.doit = false;
stopEditing(true);
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
event.doit = false;
stopEditing(false);
_column.setValue(_row, _oldVal);
_table.forceFocus();
}
}
public void keyReleased(KeyEvent arg0) {
}
});
_spinner.addFocusListener(this);
}
}
use of org.eclipse.swt.events.KeyEvent in project translationstudio8 by heartsome.
the class ColumnCategoriesDialog method addListenersToListViewer.
private void addListenersToListViewer() {
listViewer.getControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
removeSelected();
}
});
listViewer.getControl().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
if (controlMask && e.keyCode == SWT.ARROW_UP) {
moveSelectedUp();
e.doit = false;
} else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
moveSelectedDown();
e.doit = false;
}
}
@Override
public void keyReleased(KeyEvent e) {
if (e.character == ' ')
removeSelected();
}
});
}
use of org.eclipse.swt.events.KeyEvent in project translationstudio8 by heartsome.
the class ColumnChooserDialog method populateDialogArea.
@Override
public void populateDialogArea(Composite parent) {
GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
parent.setLayout(new GridLayout(4, false));
createLabels(parent, availableLabel, selectedLabel);
availableTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
GridData gridData = GridDataFactory.fillDefaults().grab(true, true).create();
availableTree.setLayoutData(gridData);
availableTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
addSelected();
}
});
availableTree.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == ' ')
addSelected();
}
});
Composite buttonComposite = new Composite(parent, SWT.NONE);
buttonComposite.setLayout(new GridLayout(1, true));
Button addButton = new Button(buttonComposite, SWT.PUSH);
addButton.setImage(GUIHelper.getImage("arrow_right"));
gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
addButton.setLayoutData(gridData);
addButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
addSelected();
}
});
Button removeButton = new Button(buttonComposite, SWT.PUSH);
removeButton.setImage(GUIHelper.getImage("arrow_left"));
gridData = GridDataFactory.copyData(gridData);
removeButton.setLayoutData(gridData);
removeButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
removeSelected();
}
});
selectedTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
gridData = GridDataFactory.fillDefaults().grab(true, true).create();
selectedTree.setLayoutData(gridData);
selectedTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
removeSelected();
}
});
selectedTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
if (controlMask && e.keyCode == SWT.ARROW_UP) {
moveSelectedUp();
e.doit = false;
} else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
moveSelectedDown();
e.doit = false;
}
}
@Override
public void keyReleased(KeyEvent e) {
if (e.character == ' ')
removeSelected();
}
});
selectedTree.addTreeListener(new TreeListener() {
public void treeCollapsed(TreeEvent event) {
selectedTreeCollapsed(event);
}
public void treeExpanded(TreeEvent event) {
selectedTreeExpanded(event);
}
});
selectedTree.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
public void widgetSelected(SelectionEvent event) {
toggleColumnGroupSelection((TreeItem) event.item);
}
});
Composite upDownbuttonComposite = new Composite(parent, SWT.NONE);
upDownbuttonComposite.setLayout(new GridLayout(1, true));
Button upButton = new Button(upDownbuttonComposite, SWT.PUSH);
upButton.setImage(GUIHelper.getImage("arrow_up"));
gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
upButton.setLayoutData(gridData);
upButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
moveSelectedUp();
}
});
Button downButton = new Button(upDownbuttonComposite, SWT.PUSH);
downButton.setImage(GUIHelper.getImage("arrow_down"));
gridData = GridDataFactory.copyData(gridData);
downButton.setLayoutData(gridData);
downButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
moveSelectedDown();
}
});
}
Aggregations