Java Code Examples for org.eclipse.ui.IWorkbenchWindow#getSelectionService()

The following examples show how to use org.eclipse.ui.IWorkbenchWindow#getSelectionService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTreeAction.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Changes the workbench part this <code>Action</code> listens to for
 * selection changes.
 * 
 * @param partId
 *            The ID of the part whose selections will be used by this
 *            <code>Action</code>.
 */
public void setPartId(String partId) {

	if (partId != null && !partId.equals(this.partId)) {
		// Get the Eclipse UI selection service.
		IWorkbench bench = PlatformUI.getWorkbench();
		IWorkbenchWindow window = bench.getActiveWorkbenchWindow();
		ISelectionService selectionService = window.getSelectionService();

		// Unregister from the previous part's selection.
		selectionService.removeSelectionListener(partId, this);

		// Set the partId and register for the part's selection changes.
		this.partId = partId;
		selectionService.addSelectionListener(partId, this);
	}

	return;
}
 
Example 2
Source File: SelectedResourceManager.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
 */
public void windowActivated(IWorkbenchWindow window) {
    ISelectionService service = window.getSelectionService(); 
    service.addSelectionListener(this);
    IWorkbenchPage page = window.getActivePage();
    if (page != null) {
        IWorkbenchPart part = page.getActivePart();
        if (part != null) {             
            ISelection selection = service.getSelection();
            if (selection != null) {
                selectionChanged(part, selection);
            }
        }
    }
}
 
Example 3
Source File: WorkbenchUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static ISelectionService getSelectionService() {
	IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (w != null) {
		return w.getSelectionService();
	}
	return null;
}
 
Example 4
Source File: NewModelHandlerSelectedDelegate.java    From tlaplus with MIT License 5 votes vote down vote up
private static ISelection getSelection() {
	try {
		IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (ww != null) {
			ISelectionService service = ww.getSelectionService();
			if (service != null) {
				return service.getSelection();
			}
		}
	} catch(IllegalStateException e) {
		return null;
	}
	return null;
}
 
Example 5
Source File: SelectionUtils.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the {@link ISelectionService selection service}. Will always return <code>null</code>
 * if called from a non-UI thread.
 *
 * @return the current selection service or <code>null</code> if it is not available
 */
public static ISelectionService getSelectionService() {
  final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

  if (workbenchWindow == null) return null;

  return workbenchWindow.getSelectionService();
}
 
Example 6
Source File: StartupJob.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * The added listener will be a PostSelectionListener.
 * @param win The {@link IWorkbenchWindow} that gets listened.
 */
private void addListenerToWorkbenchWindow(IWorkbenchWindow win) {
    ISelectionService ss = win.getSelectionService();
    ss.addPostSelectionListener(IPageLayout.ID_PROJECT_EXPLORER, projectExplorerSelectionlistener);
    win.getActivePage().addPartListener(partListener);
}