Search in sources :

Example 6 with IPostSelectionProvider

use of org.eclipse.jface.viewers.IPostSelectionProvider in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method createPages.

/**
 * Creates the pages of the multi-page editor.
 */
protected void createPages() {
    super.createPages();
    // selectionProvider = getSelectionManager();
    // getEditorSite().setSelectionProvider(selectionProvider);
    // 
    // structuredTextEditor = new StructuredTextEditor();
    // model = buildModel((IFileEditorInput) getEditorInput());
    // createGraphPage();
    // createSourcePage();
    openOnSelectionHelper = new OpenOnSelectionHelper(getTextEditor(), getXSDSchema());
    ISelectionProvider provider = getTextEditor().getSelectionProvider();
    fSourceEditorSelectionListener = new SourceEditorSelectionListener();
    if (provider instanceof IPostSelectionProvider) {
        ((IPostSelectionProvider) provider).addPostSelectionChangedListener(fSourceEditorSelectionListener);
    } else {
        provider.addSelectionChangedListener(fSourceEditorSelectionListener);
    }
    fXSDSelectionListener = new XSDSelectionManagerSelectionListener();
    getSelectionManager().addSelectionChangedListener(fXSDSelectionListener);
    xsdPreferenceStoreListener = new XSDPreferenceStoreListener();
    XSDEditorPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(xsdPreferenceStoreListener);
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) OpenOnSelectionHelper(org.eclipse.wst.xsd.ui.internal.utils.OpenOnSelectionHelper)

Example 7 with IPostSelectionProvider

use of org.eclipse.jface.viewers.IPostSelectionProvider in project webtools.sourceediting by eclipse.

the class XMLMultiPageEditorPart method connectDesignPage.

/**
 * Connects the design viewer with the viewer selection manager. Should be
 * done after createSourcePage() is done because we need to get the
 * ViewerSelectionManager from the TextEditor. setModel is also done here
 * because getModel() needs to reference the TextEditor.
 */
private void connectDesignPage() {
    if (fDesignViewer != null) {
        fDesignViewer.setDocument(getDocument());
    }
    /*
		 * Connect selection from the Design page to the selection provider
		 * for the XMLMultiPageEditorPart so that selection changes in the
		 * Design page will propagate across the workbench
		 */
    if (fDesignViewer.getSelectionProvider() instanceof IPostSelectionProvider) {
        ((IPostSelectionProvider) fDesignViewer.getSelectionProvider()).addPostSelectionChangedListener(new ISelectionChangedListener() {

            public void selectionChanged(SelectionChangedEvent event) {
                if (getActivePage() != fSourcePageIndex) {
                    ((MultiPageSelectionProvider) getSite().getSelectionProvider()).firePostSelectionChanged(event);
                }
            }
        });
    }
    fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (getActivePage() != fSourcePageIndex) {
                ((MultiPageSelectionProvider) getSite().getSelectionProvider()).fireSelectionChanged(event);
            }
        }
    });
    fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (getActivePage() != fSourcePageIndex) {
                try {
                    updateStatusLine(event.getSelection());
                } catch (Exception exception) {
                    Logger.logException(exception);
                }
            }
        }
    });
    /*
		 * Handle double-click in the Design page by selecting the
		 * corresponding amount of text in the Source page.
		 * 
		 * Warning: This implies more knowledge of the design viewer's underlying
		 * Control than expressed in the IDesignViewer interface
		 */
    fDesignViewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            ISelection selection = fDesignViewer.getSelectionProvider().getSelection();
            int start = -1;
            int length = -1;
            if (selection instanceof IStructuredSelection) {
                /*
					 * selection goes from the start of the first object to
					 * the end of the last
					 */
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                Object o = structuredSelection.getFirstElement();
                Object o2 = null;
                if (structuredSelection.size() > 1) {
                    o2 = structuredSelection.toArray()[structuredSelection.size() - 1];
                } else {
                    o2 = o;
                }
                if (o instanceof IndexedRegion) {
                    start = ((IndexedRegion) o).getStartOffset();
                    length = ((IndexedRegion) o2).getEndOffset() - start;
                } else if (o2 instanceof ITextRegion) {
                    start = ((ITextRegion) o).getStart();
                    length = ((ITextRegion) o2).getEnd() - start;
                }
            } else if (selection instanceof ITextSelection) {
                start = ((ITextSelection) selection).getOffset();
                length = ((ITextSelection) selection).getLength();
            }
            if ((start > -1) && (length > -1)) {
                getTextEditor().selectAndReveal(start, length);
            }
        }
    });
    /*
		 * Connect selection from the Source page to the selection provider of
		 * the Design page so that selection in the Source page will drive
		 * selection in the Design page. Prefer post selection.
		 */
    ISelectionProvider provider = getTextEditor().getSelectionProvider();
    if (fTextEditorSelectionListener == null) {
        fTextEditorSelectionListener = new TextEditorPostSelectionAdapter();
    }
    if (provider instanceof IPostSelectionProvider) {
        fTextEditorSelectionListener.forcePostSelection = false;
        ((IPostSelectionProvider) provider).addPostSelectionChangedListener(fTextEditorSelectionListener);
    } else {
        fTextEditorSelectionListener.forcePostSelection = true;
        provider.addSelectionChangedListener(fTextEditorSelectionListener);
    }
}
Also used : IPropertyListener(org.eclipse.ui.IPropertyListener) IWindowListener(org.eclipse.ui.IWindowListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) ITextInputListener(org.eclipse.jface.text.ITextInputListener) IPartListener(org.eclipse.ui.IPartListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) ITextSelection(org.eclipse.jface.text.ITextSelection) IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event)

Example 8 with IPostSelectionProvider

use of org.eclipse.jface.viewers.IPostSelectionProvider in project erlide_eclipse by erlang.

the class MarkOccurencesSupport method installOccurrencesFinder.

protected void installOccurrencesFinder(final boolean forceUpdate) {
    fMarkOccurrenceAnnotations = true;
    fPostSelectionListener = event -> {
        final ISelection selection = event.getSelection();
        editor.markOccurencesHandler.updateOccurrenceAnnotations((ITextSelection) selection, editor.getModule());
    };
    final ISelectionProvider selectionProvider = editor.getSelectionProvider();
    if (selectionProvider != null) {
        ((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener(fPostSelectionListener);
        if (forceUpdate) {
            fForcedMarkOccurrencesSelection = selectionProvider.getSelection();
            final IErlModule module = editor.getModule();
            if (module != null) {
                editor.markOccurencesHandler.updateOccurrenceAnnotations((ITextSelection) fForcedMarkOccurrencesSelection, module);
            }
        }
    }
    if (fOccurrencesFinderJobCanceler == null) {
        fOccurrencesFinderJobCanceler = new OccurrencesFinderJobCanceler();
        fOccurrencesFinderJobCanceler.install();
    }
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelection(org.eclipse.jface.viewers.ISelection) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 9 with IPostSelectionProvider

use of org.eclipse.jface.viewers.IPostSelectionProvider in project xtext-eclipse by eclipse.

the class XtextEditor method installSelectionChangedListener.

private void installSelectionChangedListener() {
    selectionChangedListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            updateStatusLine();
        }
    };
    final ISelectionProvider selectionProvider = getSelectionProvider();
    if (selectionProvider instanceof IPostSelectionProvider) {
        final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider;
        postSelectionProvider.addPostSelectionChangedListener(selectionChangedListener);
    } else {
        getSelectionProvider().addSelectionChangedListener(selectionChangedListener);
    }
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 10 with IPostSelectionProvider

use of org.eclipse.jface.viewers.IPostSelectionProvider in project xtext-eclipse by eclipse.

the class XtextEditor method uninstallSelectionChangedListener.

private void uninstallSelectionChangedListener() {
    ISelectionProvider selectionProvider = getSelectionProvider();
    if (selectionProvider != null) {
        if (selectionProvider instanceof IPostSelectionProvider) {
            final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider;
            postSelectionProvider.removePostSelectionChangedListener(selectionChangedListener);
        } else {
            selectionProvider.removeSelectionChangedListener(selectionChangedListener);
        }
    }
}
Also used : IPostSelectionProvider(org.eclipse.jface.viewers.IPostSelectionProvider) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider)

Aggregations

IPostSelectionProvider (org.eclipse.jface.viewers.IPostSelectionProvider)17 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 CoreException (org.eclipse.core.runtime.CoreException)2 ITextViewer (org.eclipse.jface.text.ITextViewer)2 ISelection (org.eclipse.jface.viewers.ISelection)2 Iterator (java.util.Iterator)1 TimeoutException (java.util.concurrent.TimeoutException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 DocShare (org.eclipse.ecf.docshare2.DocShare)1 ResourcesShare (org.eclipse.ecf.internal.sync.resources.core.ResourcesShare)1 ITextInputListener (org.eclipse.jface.text.ITextInputListener)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1