use of org.eclipse.ui.contexts.IContextActivation in project dbeaver by serge-rider.
the class BaseValueEditor method initInlineControl.
protected void initInlineControl(final Control inlineControl) {
boolean isInline = (valueController.getEditType() == IValueController.EditType.INLINE);
if (isInline && UIUtils.isInDialog(inlineControl)) {
//isInline = false;
}
UIUtils.enableHostEditorKeyBindingsSupport(valueController.getValueSite(), inlineControl);
// if (!isInline) {
// inlineControl.setBackground(valueController.getEditPlaceholder().getBackground());
// }
final IContextService contextService = valueController.getValueSite().getService(IContextService.class);
inlineControl.addFocusListener(new FocusListener() {
private IContextActivation activationEditor;
@Override
public void focusGained(FocusEvent e) {
if (contextService != null) {
activationEditor = contextService.activateContext(RESULTS_EDIT_CONTEXT_ID);
}
}
@Override
public void focusLost(FocusEvent e) {
contextService.deactivateContext(activationEditor);
activationEditor = null;
}
});
if (isInline) {
inlineControl.setFont(valueController.getEditPlaceholder().getFont());
inlineControl.setFocus();
if (valueController instanceof IMultiController) {
// In dialog it also should handle all standard stuff because we have params dialog
inlineControl.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
saveValue();
((IMultiController) valueController).closeInlineEditor();
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
} else if (e.detail == SWT.TRAVERSE_ESCAPE) {
((IMultiController) valueController).closeInlineEditor();
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
} else if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
saveValue();
((IMultiController) valueController).nextInlineEditor(e.detail == SWT.TRAVERSE_TAB_NEXT);
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
}
}
});
if (!UIUtils.isInDialog(inlineControl)) {
addAutoSaveSupport(inlineControl);
}
}
}
final ControlModifyListener modifyListener = new ControlModifyListener();
control.addListener(SWT.Modify, modifyListener);
control.addListener(SWT.Selection, modifyListener);
}
Aggregations