use of org.eclipse.ui.ISelectionService in project azure-tools-for-java by Microsoft.
the class SDKJarsFilter method getSelectedProject.
private IProject getSelectedProject() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
ISelectionService service = window.getSelectionService();
ISelection selection = service.getSelection();
Object element = null;
IResource resource;
IProject selProject = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSel = (IStructuredSelection) selection;
element = structuredSel.getFirstElement();
}
if (element instanceof IProject) {
resource = (IResource) element;
selProject = resource.getProject();
} else if (element instanceof IJavaProject) {
IJavaProject proj = ((IJavaElement) element).getJavaProject();
selProject = proj.getProject();
}
return selProject;
}
use of org.eclipse.ui.ISelectionService in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method getCurrentSelectedProject.
public static IProject getCurrentSelectedProject() {
IProject project = null;
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IResource) {
project = ((IResource) element).getProject();
} else if (element instanceof PackageFragmentRoot) {
IJavaProject jProject = ((PackageFragmentRoot) element).getJavaProject();
project = jProject.getProject();
} else if (element instanceof IJavaElement) {
IJavaProject jProject = ((IJavaElement) element).getJavaProject();
project = jProject.getProject();
}
}
if (project == null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (workspace.getRoot() != null && workspace.getRoot().getProjects().length > 0) {
IProject[] projects = workspace.getRoot().getProjects();
project = projects[projects.length - 1];
} else {
PluginUtil.displayErrorDialog(Display.getDefault().getActiveShell(), "No Active Project", "Must have a project first");
}
}
return project;
}
use of org.eclipse.ui.ISelectionService in project yamcs-studio by yamcs.
the class LauncherHelper method systemPathToWorkspacePath.
/**
* Check the resources that are selected in the navigator and find the one that matches the given path. The returned
* path is always the path within the workspace whereas the parameter is an absolute system path.
*
* @param path the path for which we need a workspace resource path
* @return the workspace path if a match in the workspace was found or the same path if a match was not found
*/
public static IPath systemPathToWorkspacePath(IPath path) {
// path is an absolute file location, which needs to be transformed into a workspace resource
// This method was triggered from the resource navigator, therefore the current selection should contain the
// resource that matches this path
ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = service.getSelection();
if (selection instanceof IStructuredSelection) {
Iterator<?> elements = ((IStructuredSelection) selection).iterator();
while (elements.hasNext()) {
Object e = elements.next();
// of the selected file
if (e instanceof IResource && ((IResource) e).getLocation().equals(path)) {
// reality it is a very unlikely event.
return ((IResource) e).getFullPath();
}
}
}
OPIBuilderPlugin.getLogger().info(NLS.bind("A workspace match for {0} could not be found.", path));
return path;
}
use of org.eclipse.ui.ISelectionService in project liferay-ide by liferay.
the class WorkingSetCustomPart method init.
@Override
protected void init() {
super.init();
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ISelectionService service = (ISelectionService) activeWorkbenchWindow.getSelectionService();
ISelection selection = service.getSelection();
if (selection instanceof IStructuredSelection) {
final IWorkingSet workingSet = SelectionUtil.getSelectedWorkingSet((IStructuredSelection) selection);
if (workingSet != null) {
_workingSets.add(workingSet);
}
}
}
use of org.eclipse.ui.ISelectionService in project n4js by eclipse.
the class N4JSMarkerResolutionGenerator method isMultiApplyAttempt.
/**
* Returns true iff the user is trying to apply quick fixes to multiple issues / markers at once.
* <p>
* Implementation note: this method assumes that the entire code of class MarkerResolutionGenerator is only invoked
* if quick fixes are initiated via the Problems view (not if they are initiated from within the editor). Therefore,
* this method simply checks whether the Problems view contains a selection of multiple, i.e. two or more, elements.
*/
private boolean isMultiApplyAttempt() {
if (workbench == null)
return false;
try {
// get the current selection in the problems view
final ISelectionService service = workbench.getActiveWorkbenchWindow().getSelectionService();
final IStructuredSelection sel = (IStructuredSelection) service.getSelection(IPageLayout.ID_PROBLEM_VIEW);
return sel != null && sel.size() >= 2;
} catch (Exception e) {
return false;
}
}
Aggregations