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);
}
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);
}
}
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();
}
}
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);
}
}
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);
}
}
}
Aggregations