Search in sources :

Example 6 with IFocusService

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;
}
Also used : YEditSourceViewerConfiguration(org.dadacoalition.yedit.editor.YEditSourceViewerConfiguration) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IInformationPresenter(org.eclipse.jface.text.information.IInformationPresenter) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) IFocusService(org.eclipse.ui.swt.IFocusService) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer)

Example 7 with IFocusService

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);
    }
}
Also used : IFocusService(org.eclipse.ui.swt.IFocusService)

Example 8 with IFocusService

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();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) StyledText(org.eclipse.swt.custom.StyledText) CompletionProposalAdapter(org.yakindu.base.xtext.utils.jface.fieldassist.CompletionProposalAdapter) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) IFocusService(org.eclipse.ui.swt.IFocusService)

Aggregations

IFocusService (org.eclipse.ui.swt.IFocusService)8 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 AbstractMarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage)4 MarkupLanguage (org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 Point (org.eclipse.swt.graphics.Point)2 URL (java.net.URL)1 YEditSourceViewerConfiguration (org.dadacoalition.yedit.editor.YEditSourceViewerConfiguration)1 CoreException (org.eclipse.core.runtime.CoreException)1 Region (org.eclipse.jface.text.Region)1 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)1 URLHyperlink (org.eclipse.jface.text.hyperlink.URLHyperlink)1