use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method getAdapter.
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> required) {
if (IEditorStatusLine.class.equals(required)) {
if (fEditorStatusLine == null) {
IStatusLineManager statusLineManager = getStatusLineManager();
ISelectionProvider selectionProvider = getSelectionProvider();
if (statusLineManager != null && selectionProvider != null)
fEditorStatusLine = new EditorStatusLine(statusLineManager, selectionProvider);
}
return (T) fEditorStatusLine;
}
if (IVerticalRulerInfo.class.equals(required)) {
if (fVerticalRuler != null)
return (T) fVerticalRuler;
}
if (IMarkRegionTarget.class.equals(required)) {
if (fMarkRegionTarget == null) {
IStatusLineManager manager = getStatusLineManager();
if (manager != null)
fMarkRegionTarget = (fSourceViewer == null ? null : new MarkRegionTarget(fSourceViewer, manager));
}
return (T) fMarkRegionTarget;
}
if (IDeleteLineTarget.class.equals(required)) {
if (fDeleteLineTarget == null) {
fDeleteLineTarget = new TextViewerDeleteLineTarget(fSourceViewer);
}
return (T) fDeleteLineTarget;
}
if (IncrementalFindTarget.class.equals(required)) {
if (fIncrementalFindTarget == null) {
IStatusLineManager manager = getStatusLineManager();
if (manager != null)
fIncrementalFindTarget = (fSourceViewer == null ? null : new IncrementalFindTarget(fSourceViewer, manager));
}
return (T) fIncrementalFindTarget;
}
if (IFindReplaceTarget.class.equals(required)) {
if (fFindReplaceTarget == null) {
IFindReplaceTarget target = (fSourceViewer == null ? null : fSourceViewer.getFindReplaceTarget());
if (target != null) {
fFindReplaceTarget = new FindReplaceTarget(this, target);
if (fFindScopeHighlightColor != null)
fFindReplaceTarget.setScopeHighlightColor(fFindScopeHighlightColor);
}
}
return (T) fFindReplaceTarget;
}
if (ITextOperationTarget.class.equals(required))
return (fSourceViewer == null ? null : (T) fSourceViewer.getTextOperationTarget());
if (IRewriteTarget.class.equals(required)) {
if (fSourceViewer instanceof ITextViewerExtension) {
ITextViewerExtension extension = (ITextViewerExtension) fSourceViewer;
return (T) extension.getRewriteTarget();
}
return null;
}
if (Control.class.equals(required))
return fSourceViewer != null ? (T) fSourceViewer.getTextWidget() : null;
if (IColumnSupport.class.equals(required)) {
if (fColumnSupport == null)
fColumnSupport = createColumnSupport();
return (T) fColumnSupport;
}
return super.getAdapter(required);
}
use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.
the class FileSearchPage method getAdapter.
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (IShowInTargetList.class.equals(adapter)) {
return (T) SHOW_IN_TARGET_LIST;
}
if (adapter == IShowInSource.class) {
ISelectionProvider selectionProvider = getSite().getSelectionProvider();
if (selectionProvider == null)
return null;
ISelection selection = selectionProvider.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = ((StructuredSelection) selection);
final Set<Object> newSelection = new HashSet<>(structuredSelection.size());
Iterator<?> iter = structuredSelection.iterator();
while (iter.hasNext()) {
Object element = iter.next();
if (element instanceof LineElement)
element = ((LineElement) element).getParent();
newSelection.add(element);
}
return (T) (IShowInSource) () -> new ShowInContext(null, new StructuredSelection(new ArrayList<>(newSelection)));
}
return null;
}
return null;
}
use of org.eclipse.jface.viewers.ISelectionProvider in project eclipse.platform.text by eclipse.
the class PaintManager method removeListeners.
/**
* Removes our set of listeners from the text viewer and widget,
* respectively.
*/
private void removeListeners() {
ISelectionProvider provider = fTextViewer.getSelectionProvider();
if (provider != null)
provider.removeSelectionChangedListener(this);
fTextViewer.removeTextListener(this);
StyledText text = fTextViewer.getTextWidget();
if (text != null && !text.isDisposed()) {
text.removeKeyListener(this);
text.removeMouseListener(this);
}
}
use of org.eclipse.jface.viewers.ISelectionProvider in project linuxtools by eclipse.
the class SpecfileEditorRPMBuildHandler method getResource.
/**
* Extract the IResource that was selected when the event was fired.
* @param event The fired execution event.
* @return The resource that was selected.
*/
private static IResource getResource(ExecutionEvent event) {
final boolean actOnEditor = Boolean.valueOf(event.getParameter(ON_EDITOR));
if (actOnEditor) {
IEditorPart epart = HandlerUtil.getActiveEditor(event);
if (epart != null) {
IEditorInput input = epart.getEditorInput();
if (input instanceof IFileEditorInput) {
return ((IFileEditorInput) input).getFile();
}
}
return null;
}
IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part == null) {
return null;
}
if (part instanceof EditorPart) {
IEditorInput input = ((EditorPart) part).getEditorInput();
if (input instanceof IFileEditorInput) {
return ((IFileEditorInput) input).getFile();
}
return null;
}
IWorkbenchSite site = part.getSite();
if (site == null) {
return null;
}
ISelectionProvider provider = site.getSelectionProvider();
if (provider == null) {
return null;
}
ISelection selection = provider.getSelection();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IResource) {
return (IResource) element;
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
return adaptable.getAdapter(IResource.class);
} else {
return null;
}
}
return null;
}
use of org.eclipse.jface.viewers.ISelectionProvider in project linuxtools by eclipse.
the class PrepareChangelogKeyHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
IStructuredSelection tempResult = null;
// try getting currently selected project
IWorkbenchPage ref = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part instanceof IEditorPart) {
// If we are in an editor, check if the file being edited is an IResource
// that belongs to a project in the workspace
IEditorPart editorPart = (IEditorPart) part;
IEditorInput input = editorPart.getEditorInput();
IResource r = input.getAdapter(IResource.class);
if (r != null) {
// We have an IResource to work with, so create a selection we can use
// in PrepareChangeLogAction
tempResult = new StructuredSelection(r);
}
} else {
// Otherwise, our view is not an editor, see if we have an IResource or something
// that will lead us to an IResource
ISelection selected = ref.getSelection();
if (selected instanceof IStructuredSelection) {
IResource r = null;
IStructuredSelection iss = (IStructuredSelection) selected;
Object o = ((IStructuredSelection) selected).getFirstElement();
if (o instanceof ISynchronizeModelElement) {
r = ((ISynchronizeModelElement) o).getResource();
} else if (o instanceof IAdaptable) {
r = ((IAdaptable) o).getAdapter(IResource.class);
}
if (r != null)
tempResult = iss;
}
}
if (tempResult == null) {
// choice to fall back on.
for (IViewReference view : ref.getViewReferences()) {
if (view.getId().equals("org.eclipse.team.sync.views.SynchronizeView")) {
// $NON-NLS-1$
IViewPart v = view.getView(false);
ISelection s = null;
ISelectionProvider sp = v.getViewSite().getSelectionProvider();
if (sp != null) {
s = sp.getSelection();
}
if (s instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) s;
Object element = ss.getFirstElement();
IResource r = null;
if (element instanceof ISynchronizeModelElement) {
r = ((ISynchronizeModelElement) element).getResource();
} else if (element instanceof IAdaptable) {
r = ((IAdaptable) element).getAdapter(IResource.class);
}
if (r != null) {
tempResult = ss;
}
}
}
}
}
// If we can't find the project directly, let the user know.
if (tempResult == null) {
// $NON-NLS-1$,
MessageDialog.openInformation(// $NON-NLS-1$,
getActiveWorkbenchShell(), // $NON-NLS-1$,
Messages.getString("ChangeLog.PrepareChangeLog"), // $NON-NLS-1$
Messages.getString("PrepareChangeLog.InfoNoProjectFound"));
return null;
}
final IStructuredSelection result = tempResult;
IAction exampleAction = new PrepareChangeLogAction() {
@Override
public void run() {
setSelection(result);
doRun();
}
};
exampleAction.run();
return null;
}
Aggregations