use of org.eclipse.jface.viewers.ISelectionProvider in project linuxtools by eclipse.
the class RPMHandlerUtils 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.
*/
public static IResource getResource(ExecutionEvent event) {
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 knime-core by knime.
the class AbstractNodeAction method getSelectedObjects.
/**
* {@inheritDoc}
*/
@Override
protected List getSelectedObjects() {
ISelectionProvider provider = m_editor.getEditorSite().getSelectionProvider();
if (provider == null) {
return Collections.EMPTY_LIST;
}
ISelection sel = provider.getSelection();
if (!(sel instanceof IStructuredSelection)) {
return Collections.EMPTY_LIST;
}
return ((IStructuredSelection) sel).toList();
}
use of org.eclipse.jface.viewers.ISelectionProvider in project knime-core by knime.
the class WorkflowCoachView method updateFrequencyColumnHeadersAndToolTips.
/**
* Updates the names and tooltips of the frequency column headers.
*/
private void updateFrequencyColumnHeadersAndToolTips() {
m_namesAndToolTips = NodeRecommendationManager.getInstance().getNodeTripleProviders().stream().filter(p -> p.isEnabled()).map(p -> new Pair<>(p.getName(), p.getDescription())).collect(Collectors.toList());
if (m_namesAndToolTips == null || m_namesAndToolTips.isEmpty()) {
updateInputNoProvider();
return;
}
// reset table sorter
IElementComparer sorter = m_viewer.getComparer();
if (sorter != null && sorter instanceof TableColumnSorter) {
((TableColumnSorter) sorter).setColumn(null);
}
// enforce to change the viewer state to update the headers
m_viewerState = null;
m_lastSelection = "";
changeViewerStateTo(ViewerState.RECOMMENDATIONS);
// get current selection from the workbench and update the recommendation list
IEditorPart activeEditor = getViewSite().getPage().getActiveEditor();
if (activeEditor == null) {
// if no workflow is opened
updateInput(NO_WORKFLOW_OPENED_MESSAGE);
} else {
IWorkbenchPartSite site = activeEditor.getSite();
if (site != null) {
ISelectionProvider selectionProvider = site.getSelectionProvider();
if (selectionProvider != null) {
ISelection selection = selectionProvider.getSelection();
if (selection != null && selection instanceof IStructuredSelection) {
updateInput(selection);
return;
}
}
}
updateInput(StructuredSelection.EMPTY);
}
}
Aggregations