use of org.eclipse.swt.events.TraverseListener in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup method addCommandSupport.
/**
* Adds command support to the given control.
*
* @param control the control to watch for focus
* @since 3.2
*/
private void addCommandSupport(final Control control) {
final KeySequence commandSequence = fContentAssistant.getRepeatedInvocationKeySequence();
if (commandSequence != null && !commandSequence.isEmpty() && fContentAssistant.isRepeatedInvocationMode()) {
control.addFocusListener(new FocusListener() {
private CommandKeyListener fCommandKeyListener;
@Override
public void focusGained(FocusEvent e) {
if (Helper.okToUse(control)) {
if (fCommandKeyListener == null) {
fCommandKeyListener = new CommandKeyListener(commandSequence);
fProposalTable.addKeyListener(fCommandKeyListener);
}
}
}
@Override
public void focusLost(FocusEvent e) {
if (fCommandKeyListener != null) {
control.removeKeyListener(fCommandKeyListener);
fCommandKeyListener = null;
}
}
});
}
if (fAdditionalInfoController != null) {
control.addFocusListener(new FocusListener() {
private TraverseListener fTraverseListener;
@Override
public void focusGained(FocusEvent e) {
if (Helper.okToUse(control)) {
if (fTraverseListener == null) {
fTraverseListener = new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent event) {
if (event.detail == SWT.TRAVERSE_TAB_NEXT) {
IInformationControl iControl = fAdditionalInfoController.getCurrentInformationControl2();
if (fAdditionalInfoController.getInternalAccessor().canReplace(iControl)) {
fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true);
event.doit = false;
}
}
}
};
fProposalTable.addTraverseListener(fTraverseListener);
}
}
}
@Override
public void focusLost(FocusEvent e) {
if (fTraverseListener != null) {
control.removeTraverseListener(fTraverseListener);
fTraverseListener = null;
}
}
});
}
}
use of org.eclipse.swt.events.TraverseListener in project eclipse.platform.swt by eclipse.
the class GridLayoutTab method createChildWidgets.
/**
* Creates the widgets in the "child" group.
*/
@Override
void createChildWidgets() {
/* Create the TraverseListener */
final TraverseListener traverseListener = e -> {
if (e.detail == SWT.TRAVERSE_RETURN || e.detail == SWT.TRAVERSE_TAB_NEXT)
resetEditors();
if (e.detail == SWT.TRAVERSE_ESCAPE)
disposeEditors();
};
/* Add common controls */
super.createChildWidgets();
/* Add hovers to the column headers whose field names have been shortened to save space */
table.getColumn(HALIGN_COL).setToolTipText("horizontalAlignment");
table.getColumn(VALIGN_COL).setToolTipText("verticalAlignment");
table.getColumn(HGRAB_COL).setToolTipText("grabExcessHorizontalSpace");
table.getColumn(VGRAB_COL).setToolTipText("grabExcessVerticalSpace");
table.getColumn(HSPAN_COL).setToolTipText("horizontalSpan");
table.getColumn(VSPAN_COL).setToolTipText("verticalSpan");
table.getColumn(HINDENT_COL).setToolTipText("horizontalIndent");
table.getColumn(VINDENT_COL).setToolTipText("verticalIndent");
table.getColumn(MINWIDTH_COL).setToolTipText("minimumWidth");
table.getColumn(MINHEIGHT_COL).setToolTipText("minimumHeight");
/* Add TableEditors */
nameEditor = new TableEditor(table);
comboEditor = new TableEditor(table);
widthEditor = new TableEditor(table);
heightEditor = new TableEditor(table);
vAlignEditor = new TableEditor(table);
hAlignEditor = new TableEditor(table);
hGrabEditor = new TableEditor(table);
vGrabEditor = new TableEditor(table);
hSpanEditor = new TableEditor(table);
vSpanEditor = new TableEditor(table);
hIndentEditor = new TableEditor(table);
vIndentEditor = new TableEditor(table);
minWidthEditor = new TableEditor(table);
minHeightEditor = new TableEditor(table);
excludeEditor = new TableEditor(table);
table.addMouseListener(MouseListener.mouseDownAdapter(e -> {
resetEditors();
index = table.getSelectionIndex();
Point pt = new Point(e.x, e.y);
newItem = table.getItem(pt);
if (newItem == null)
return;
TableItem oldItem = comboEditor.getItem();
if (newItem == oldItem || newItem != lastSelected) {
lastSelected = newItem;
return;
}
table.showSelection();
nameText = new Text(table, SWT.SINGLE);
nameText.setText(data.get(index)[NAME_COL]);
createTextEditor(nameText, nameEditor, NAME_COL);
combo = new CCombo(table, SWT.READ_ONLY);
createComboEditor(combo, comboEditor);
widthText = new Text(table, SWT.SINGLE);
widthText.setText(data.get(index)[WIDTH_COL]);
createTextEditor(widthText, widthEditor, WIDTH_COL);
heightText = new Text(table, SWT.SINGLE);
heightText.setText(data.get(index)[HEIGHT_COL]);
createTextEditor(heightText, heightEditor, HEIGHT_COL);
String[] alignValues = new String[] { "BEGINNING", "CENTER", "END", "FILL" };
hAlign = new CCombo(table, SWT.NONE);
hAlign.setItems(alignValues);
hAlign.setText(newItem.getText(HALIGN_COL));
hAlignEditor.horizontalAlignment = SWT.LEFT;
hAlignEditor.grabHorizontal = true;
hAlignEditor.minimumWidth = 50;
hAlignEditor.setEditor(hAlign, newItem, HALIGN_COL);
hAlign.addTraverseListener(traverseListener);
vAlign = new CCombo(table, SWT.NONE);
vAlign.setItems(alignValues);
vAlign.setText(newItem.getText(VALIGN_COL));
vAlignEditor.horizontalAlignment = SWT.LEFT;
vAlignEditor.grabHorizontal = true;
vAlignEditor.minimumWidth = 50;
vAlignEditor.setEditor(vAlign, newItem, VALIGN_COL);
vAlign.addTraverseListener(traverseListener);
String[] boolValues = new String[] { "false", "true" };
hGrab = new CCombo(table, SWT.NONE);
hGrab.setItems(boolValues);
hGrab.setText(newItem.getText(HGRAB_COL));
hGrabEditor.horizontalAlignment = SWT.LEFT;
hGrabEditor.grabHorizontal = true;
hGrabEditor.minimumWidth = 50;
hGrabEditor.setEditor(hGrab, newItem, HGRAB_COL);
hGrab.addTraverseListener(traverseListener);
vGrab = new CCombo(table, SWT.NONE);
vGrab.setItems(boolValues);
vGrab.setText(newItem.getText(VGRAB_COL));
vGrabEditor.horizontalAlignment = SWT.LEFT;
vGrabEditor.grabHorizontal = true;
vGrabEditor.minimumWidth = 50;
vGrabEditor.setEditor(vGrab, newItem, VGRAB_COL);
vGrab.addTraverseListener(traverseListener);
hSpan = new Text(table, SWT.SINGLE);
hSpan.setText(data.get(index)[HSPAN_COL]);
createTextEditor(hSpan, hSpanEditor, HSPAN_COL);
vSpan = new Text(table, SWT.SINGLE);
vSpan.setText(data.get(index)[VSPAN_COL]);
createTextEditor(vSpan, vSpanEditor, VSPAN_COL);
hIndent = new Text(table, SWT.SINGLE);
hIndent.setText(data.get(index)[HINDENT_COL]);
createTextEditor(hIndent, hIndentEditor, HINDENT_COL);
vIndent = new Text(table, SWT.SINGLE);
vIndent.setText(data.get(index)[VINDENT_COL]);
createTextEditor(vIndent, vIndentEditor, VINDENT_COL);
minWidthText = new Text(table, SWT.SINGLE);
minWidthText.setText(data.get(index)[MINWIDTH_COL]);
createTextEditor(minWidthText, minWidthEditor, MINWIDTH_COL);
minHeightText = new Text(table, SWT.SINGLE);
minHeightText.setText(data.get(index)[MINHEIGHT_COL]);
createTextEditor(minHeightText, minHeightEditor, MINHEIGHT_COL);
exclude = new CCombo(table, SWT.NONE);
exclude.setItems(boolValues);
exclude.setText(newItem.getText(EXCLUDE_COL));
excludeEditor.horizontalAlignment = SWT.LEFT;
excludeEditor.grabHorizontal = true;
excludeEditor.minimumWidth = 50;
excludeEditor.setEditor(exclude, newItem, EXCLUDE_COL);
exclude.addTraverseListener(traverseListener);
for (int i = 0; i < table.getColumnCount(); i++) {
Rectangle rect = newItem.getBounds(i);
if (rect.contains(pt)) {
switch(i) {
case NAME_COL:
nameText.setFocus();
break;
case COMBO_COL:
combo.setFocus();
break;
case WIDTH_COL:
widthText.setFocus();
break;
case HEIGHT_COL:
heightText.setFocus();
break;
case HALIGN_COL:
hAlign.setFocus();
break;
case VALIGN_COL:
vAlign.setFocus();
break;
case HGRAB_COL:
hGrab.setFocus();
break;
case VGRAB_COL:
vGrab.setFocus();
break;
case HSPAN_COL:
hSpan.setFocus();
break;
case VSPAN_COL:
vSpan.setFocus();
break;
case HINDENT_COL:
hIndent.setFocus();
break;
case VINDENT_COL:
vIndent.setFocus();
break;
case MINWIDTH_COL:
minWidthText.setFocus();
break;
case MINHEIGHT_COL:
minHeightText.setFocus();
break;
case EXCLUDE_COL:
exclude.setFocus();
break;
default:
resetEditors();
break;
}
}
}
}));
}
use of org.eclipse.swt.events.TraverseListener in project translationstudio8 by heartsome.
the class DateCellEditor method createControl.
/**
* Create the chooser control.
*
* @param table parent table.
*/
private void createControl(JaretTable table) {
_table = table;
if (_chooser == null) {
_chooser = new DateChooser(table, SWT.NULL);
// TODO locale dependent
IFieldIdentifier fi = new SimpleFieldIdentifier(".", new int[] { Calendar.DAY_OF_MONTH, Calendar.MONTH, Calendar.YEAR });
_chooser.setFieldIdentifier(fi);
_chooser.setSelectAllOnFocusGained(false);
_chooser.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
_chooser.addFocusListener(this);
_chooser.addDateChooserListener(this);
_chooser.getTextField().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.TAB) {
_chooser.validateInput();
stopEditing(true);
// do not further process
event.doit = false;
_table.forceFocus();
_table.focusRight();
} else if (event.keyCode == SWT.CR) {
_chooser.validateInput();
stopEditing(true);
// do not further process
event.doit = false;
_table.forceFocus();
_table.focusDown();
} else if (event.keyCode == SWT.ESC) {
stopEditing(false);
restoreOldVal();
// do not further process
event.doit = false;
_table.forceFocus();
}
}
public void keyReleased(KeyEvent e) {
}
});
// add a traverse listener so the TAB-key won't traverse the focus out of the table
_chooser.getTextField().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
e.doit = false;
}
});
}
}
use of org.eclipse.swt.events.TraverseListener in project cubrid-manager by CUBRID.
the class DataTypeCellEditor method createControl.
protected Control createControl(Composite parent) {
comboBox = new DataTypeCombo(parent, getStyle());
comboBox.setFont(parent.getFont());
populateComboBoxItems();
// comboBox.addKeyListener(new KeyAdapter() {
// public void keyPressed(KeyEvent event) {
// if (event.character == '\r') {
// applyEditorValueAndDeactivate();
// }
// keyReleaseOccured(event);
// }
//
// public void keyReleased(KeyEvent event) {
// }
// });
comboBox.addModifyListener(getModifyListener());
comboBox.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent event) {
applyEditorValueAndDeactivate();
}
public void widgetSelected(SelectionEvent event) {
value = comboBox.getText();
}
});
comboBox.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent event) {
if (event.detail == SWT.TRAVERSE_ESCAPE || event.detail == SWT.TRAVERSE_RETURN) {
event.doit = false;
}
}
});
comboBox.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
applyEditorValueAndDeactivate();
DataTypeCellEditor.this.focusLost();
}
});
return comboBox;
}
use of org.eclipse.swt.events.TraverseListener 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);
}
}
Aggregations