use of org.eclipse.ui.swt.IFocusService in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonEditor method doCreateSourceViewer.
protected ISourceViewer doCreateSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
ProjectionViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles) {
private IInformationPresenter outlinePresenter;
@Override
public void doOperation(int operation) {
if (operation == OpenQuickOutlineHandler.QUICK_OUTLINE && outlinePresenter != null) {
outlinePresenter.showInformation();
return;
}
super.doOperation(operation);
}
@Override
public boolean canDoOperation(int operation) {
if (operation == OpenQuickOutlineHandler.QUICK_OUTLINE && outlinePresenter != null) {
return true;
}
return super.canDoOperation(operation);
}
@Override
public void configure(SourceViewerConfiguration configuration) {
super.configure(configuration);
if (configuration instanceof JsonSourceViewerConfiguration) {
JsonSourceViewerConfiguration c = (JsonSourceViewerConfiguration) configuration;
outlinePresenter = c.getOutlinePresenter(this);
if (outlinePresenter != null) {
outlinePresenter.install(this);
}
}
}
};
IFocusService focusService = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(viewer.getTextWidget(), "com.reprezen.swagedit.editor.sourceViewer");
}
viewer.getTextWidget().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// detectOutlineLocationChanged();
}
});
viewer.getTextWidget().setData(ISourceViewer.class.getName(), viewer);
getSourceViewerDecorationSupport(viewer);
return viewer;
}
use of org.eclipse.ui.swt.IFocusService in project dbeaver by serge-rider.
the class UIUtils method addFocusTracker.
public static void addFocusTracker(IServiceLocator serviceLocator, String controlID, Control control) {
IFocusService focusService = serviceLocator.getService(IFocusService.class);
if (focusService == null) {
focusService = UIUtils.getActiveWorkbenchWindow().getService(IFocusService.class);
}
if (focusService != null) {
IFocusService finalFocusService = focusService;
finalFocusService.addFocusTracker(control, controlID);
control.addDisposeListener(e -> {
// Unregister from focus service
finalFocusService.removeFocusTracker(control);
});
} else {
log.debug("Focus service not found in " + serviceLocator);
}
}
use of org.eclipse.ui.swt.IFocusService in project statecharts by Yakindu.
the class StyledTextXtextAdapter method adapt.
public void adapt(StyledText styledText) {
this.styledText = styledText;
// perform initialization of fake resource context
updateFakeResourceContext();
// connect Xtext document to fake resource
initXtextDocument(getFakeResourceContext());
// connect xtext document to xtext source viewer
this.sourceviewer = createXtextSourceViewer();
this.decorationSupport = createSourceViewerDecorationSupport();
configureSourceViewerDecorationSupport(getDecorationSupport());
// install semantic highlighting support
installHighlightingHelper();
this.validationJob = createValidationJob();
getXtextDocument().setValidationJob(getValidationJob());
styledText.setData(StyledTextXtextAdapter.class.getCanonicalName(), this);
final IContentAssistant contentAssistant = getXtextSourceviewer().getContentAssistant();
final CompletionProposalAdapter completionProposalAdapter = new CompletionProposalAdapter(styledText, contentAssistant, KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null);
if ((styledText.getStyle() & SWT.SINGLE) != 0) {
// The regular key down event is too late (after popup is closed).
// when using the StyledText.VerifyKey event (3005), we get the
// event early enough!
styledText.addListener(3005, new Listener() {
public void handleEvent(Event event) {
if (event.character == SWT.CR && !completionProposalAdapter.isProposalPopupOpen()) {
Event selectionEvent = new Event();
selectionEvent.type = SWT.DefaultSelection;
selectionEvent.widget = event.widget;
for (Listener l : event.widget.getListeners(SWT.DefaultSelection)) {
l.handleEvent(selectionEvent);
}
}
}
});
}
// Register focus tracker for evaluating the active focus control in
// core expression
IFocusService service = (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);
service.addFocusTracker(styledText, StyledText.class.getCanonicalName());
// add JDT Style code completion hint decoration
this.decoration = createContentAssistDecoration(styledText);
initSelectionProvider();
}
Aggregations