Search in sources :

Example 1 with ISelectionService

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;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IJavaProject(org.eclipse.jdt.core.IJavaProject) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 2 with ISelectionService

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 3 with ISelectionService

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;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Example 4 with ISelectionService

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);
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 5 with ISelectionService

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;
    }
}
Also used : ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WrappedException(org.eclipse.emf.common.util.WrappedException)

Aggregations

ISelectionService (org.eclipse.ui.ISelectionService)38 ISelection (org.eclipse.jface.viewers.ISelection)19 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 IResource (org.eclipse.core.resources.IResource)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 IProject (org.eclipse.core.resources.IProject)9 IWorkbench (org.eclipse.ui.IWorkbench)8 IJavaProject (org.eclipse.jdt.core.IJavaProject)7 IEditorPart (org.eclipse.ui.IEditorPart)7 IFile (org.eclipse.core.resources.IFile)6 ExecutionException (org.eclipse.core.commands.ExecutionException)3 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)3 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)3 Repository (org.eclipse.jgit.lib.Repository)3 SWT (org.eclipse.swt.SWT)3 ISelectionListener (org.eclipse.ui.ISelectionListener)3 PlatformUI (org.eclipse.ui.PlatformUI)3 StyleService (eu.esdihumboldt.hale.ui.common.service.style.StyleService)2 GeometrySchemaService (eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)2 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)2