org.eclipse.ui.ISelectionService Java Examples

The following examples show how to use org.eclipse.ui.ISelectionService. 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: MigrationStatusView.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createPartControl(final Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayout(GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0, 5).create());

    createTopComposite(mainComposite);
    createTableComposite(mainComposite);
    createBottomComposite(mainComposite);

    final ISelectionService ss = getSite().getWorkbenchWindow().getSelectionService();
    ss.addPostSelectionListener(this);
    final IEditorPart activeEditor = getSite().getPage().getActiveEditor();
    if (activeEditor instanceof DiagramEditor) {
        selectionProvider = activeEditor.getEditorSite().getSelectionProvider();
    }
    getSite().setSelectionProvider(this);
    createActions();
}
 
Example #2
Source File: ProfilesContribution.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IContributionItem[] getContributionItems ()
{
    final ISelectionService ss = this.serviceLocator.getService ( ISelectionService.class );

    if ( ss == null )
    {
        return new IContributionItem[0];
    }

    final ISelection sel = ss.getSelection ();

    final List<IContributionItem> items = new LinkedList<> ();

    addFromFileResource ( items, sel );

    return items.toArray ( new IContributionItem[items.size ()] );
}
 
Example #3
Source File: ValidationViewPart.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void createPartControl(final Composite parent) {
    final Composite mainComposite = new Composite(parent, SWT.NONE);
    mainComposite.setLayout(GridLayoutFactory.fillDefaults()
            .extendedMargins(5, 0, 3, 1).create());
    mainComposite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    createValidateButton(mainComposite);
    createTableComposite(mainComposite);

    final ISelectionService ss = getSite().getWorkbenchWindow()
            .getSelectionService();
    ss.addPostSelectionListener(this);
    if (getSite().getPage().getActiveEditor() != null) {
        selectionProvider = getSite().getPage().getActiveEditor()
                .getEditorSite().getSelectionProvider();
        getSite().setSelectionProvider(this);

    }

    final TableColumnSorter sorter = new TableColumnSorter(tableViewer);
    sorter.setColumn(severityColumn.getColumn());
}
 
Example #4
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private void toggleResourceListener() {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	ISelectionService service = getSite().getWorkbenchWindow()
			.getSelectionService();
	if (listenToDotContent) {
		IWorkbenchPart activeEditor = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();
		checkActiveEditorAndUpdateGraph(activeEditor);
		workspace.addResourceChangeListener(resourceChangeListener,
				IResourceChangeEvent.POST_BUILD
						| IResourceChangeEvent.POST_CHANGE);
		service.addSelectionListener(selectionChangeListener);
	} else {
		workspace.removeResourceChangeListener(resourceChangeListener);
		service.removeSelectionListener(selectionChangeListener);
	}
}
 
Example #5
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 #6
Source File: BugExplorerView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void createPartControl(Composite parent) {
    super.createPartControl(parent);
    // Add selection listener to detect click in problems view or in tree
    // view
    ISelectionService theService = getSite().getWorkbenchWindow().getSelectionService();
    selectionListener = new MarkerSelectionListener(this) {
        @Override
        public void selectionChanged(IWorkbenchPart thePart, ISelection theSelection) {
            selectionInProgress = true;
            super.selectionChanged(thePart, theSelection);
            selectionInProgress = false;
        }
    };
    theService.addSelectionListener(selectionListener);
    getCommonViewer().addSelectionChangedListener(this);
}
 
Example #7
Source File: BugInfoView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Composite createRootControl(Composite parent) {

    createRootComposite(parent);

    createAnnotationList(rootComposite);
    //        initScrolledComposite(parent);
    createBrowser(rootComposite);

    // Add selection listener to detect click in problems view or bug tree
    // view
    ISelectionService theService = getSite().getWorkbenchWindow().getSelectionService();

    selectionListener = new MarkerSelectionListener(this);
    theService.addSelectionListener(selectionListener);

    return rootComposite;
}
 
Example #8
Source File: CppStylePropertyPage.java    From CppStyle with MIT License 6 votes vote down vote up
public static String getCurrentProject() {
	ISelectionService selectionService = Workbench.getInstance()
			.getActiveWorkbenchWindow().getSelectionService();

	ISelection selection = selectionService.getSelection();

	if (selection instanceof IStructuredSelection) {
		Object element = ((IStructuredSelection) selection).getFirstElement();
		IProject project = null;		
		if (element instanceof IResource) {
			project = ((IResource) element).getProject();
		}
		else if (element instanceof ICElement) {
			project = ((ICElement) element).getResource().getProject();
		}
		if (project != null) {
			return project.getLocation().toOSString();
		}
	}
	return null;
}
 
Example #9
Source File: BibtexEntryWatcher.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public BibtexEntryWatcher(ISelectionService selectionService) {
	this.selectionService = selectionService;
	this.selectionListener = new ISelectionListener() {
		@Override
		public void selectionChanged(IWorkbenchPart part, ISelection selection) {
			List<Document> documents = new LinkedList<Document>();

			if (selection instanceof IStructuredSelection)
				for (Object element : ((IStructuredSelection) selection).toList())
					if (element instanceof Document)
						documents.add((Document) element);

			final Document doc;
			if (documents.size() == 1)
				doc = documents.get(0);
			else
				doc = null;
			listeners.stream().forEach(it -> it.accept(doc));
		}
	};
	selectionService.addPostSelectionListener(selectionListener);
}
 
Example #10
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static IProject getSelectedProject(String viewID)
{
	ISelectionService service = UIUtils.getActiveWorkbenchWindow().getSelectionService();
	IStructuredSelection structured = (IStructuredSelection) service.getSelection(viewID);
	if (structured instanceof IStructuredSelection)
	{
		Object selectedObject = ((IStructuredSelection) structured).getFirstElement();
		if (selectedObject instanceof IAdaptable)
		{
			IResource resource = (IResource) ((IAdaptable) selectedObject).getAdapter(IResource.class);
			if (resource != null)
			{
				return resource.getProject();
			}
		}
	}
	return null;
}
 
Example #11
Source File: IndexView.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * addListeners
 */
private void addListeners()
{
	// this.listenForScriptChanges();
	ISelectionService selectionService = getSite().getWorkbenchWindow().getSelectionService();

	// @formatter:off
	selectionService.addPostSelectionListener(
		IPageLayout.ID_PROJECT_EXPLORER,
		new ISelectionListener() {
			public void selectionChanged(IWorkbenchPart part, ISelection selection)
			{
				if (part != IndexView.this && selection instanceof IStructuredSelection)
				{
					setInputFromSelection(selection);
				}
			}
		}
	);
	// @formatter:on
}
 
Example #12
Source File: SpyViewPart.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Uninstall selection listeners.
 */
private void uninstallSelectionListeners() {
  ISelectionService service = getSite().getService(ISelectionService.class);
  service.removePostSelectionListener(selectionListener);
  selectionListener.removeSelectionChangedListener(grammarView);
  selectionListener.removeSelectionChangedListener(eClassTypeView);
  eClassTypeView.removePostSelectionChangedListener(eObjectOutline);
  selectionListener.removeSelectionChangedListener(eObjectOutline);
}
 
Example #13
Source File: SelectionUtils.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the current selection. Will always return <code>null</code> if called from a non-UI
 * thread.
 *
 * @return the current selection, or <code>null</code> if undefined
 * @see ISelectionService#getSelection()
 */
public static ISelection getSelection() {
  final ISelectionService selectionService = getSelectionService();

  if (selectionService == null) return null;

  return selectionService.getSelection();
}
 
Example #14
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 #15
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 #16
Source File: SpyViewPart.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Install selection listeners.
 */
private void installSelectionListeners() {
  ISelectionService service = getSite().getService(ISelectionService.class);
  service.addPostSelectionListener(selectionListener);
  selectionListener.addSelectionChangedListener(grammarView);
  selectionListener.addSelectionChangedListener(eClassTypeView);
  eClassTypeView.addPostSelectionChangedListener(eObjectOutline);
  selectionListener.addSelectionChangedListener(eObjectOutline);
}
 
Example #17
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 #18
Source File: SelectionUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * Returns the current selection in the active part.  If the selection in the
   * active part is <em>undefined</em> (the active part has no selection provider)
   * the result will be <code>null</code>.
   *
   * @return the current selection, or <code>null</code> if undefined
   */
public static IStructuredSelection getStructuredSelection() {
 ISelectionService selectionService = WorkbenchUtils.getSelectionService();
 if (selectionService != null) {
	 ISelection selection = selectionService.getSelection();
	 if (selection instanceof IStructuredSelection) {
		 return (IStructuredSelection)selection;
	 }
 }
 return null;
}
 
Example #19
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 #20
Source File: N4JSMarkerResolutionGenerator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
	}
}
 
Example #21
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);
}
 
Example #22
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
private ISelectionService getSelectionService() {
	return getSite().getWorkbenchWindow().getSelectionService();
}
 
Example #23
Source File: LapseView.java    From lapse-plus with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Initializes this view
 */
public void init(IViewSite site) throws PartInitException {
	
	log("In init(...)");
	
	super.setSite(site);
	
	if (fSuperListener == null) {
		
		
		fSuperListener = new SuperListener(this);
		
		//showMessage("Registering the plugin");
		
		//To track if the plugin is selected
		ISelectionService service = site.getWorkbenchWindow().getSelectionService();
		
		//We add a listener to notify if the selection has changed
		service.addPostSelectionListener(fSuperListener);
		
		//A file that can be edited by more than one client
		FileBuffers.getTextFileBufferManager().addFileBufferListener(fSuperListener);
		
	}
	
	//We create the parser for the Abstract Syntax Tree
	fParser = ASTParser.newParser(AST.JLS3);//Java Language Specifitacion 3
	
	fParser.setResolveBindings(true);//The compiler have to provide binding information for the AST nodes
	
	//Backward slicer from sinks
	fSlicingJob = new SlicingJob("Backward data slicer");
	fSlicingFromSinkJob = new SlicingFromSinkJob("Backward slicer from a sink", this);
	
}
 
Example #24
Source File: SelectionUtils.java    From saros with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the current selection in the given part. Will always return <code>null</code> if called
 * from a non-UI thread.
 *
 * @param partId of the part
 * @return the current selection, or <code>null</code> if undefined
 * @see ISelectionService#getSelection(String)
 */
public static ISelection getSelection(final String partId) {
  final ISelectionService selectionService = getSelectionService();

  if (selectionService == null) return null;

  return selectionService.getSelection(partId);
}
 
Example #25
Source File: CommonOccurrencesUpdater.java    From APICloud-Studio with GNU General Public License v3.0 2 votes vote down vote up
/**
 * getSelectionService
 * 
 * @return
 */
protected ISelectionService getSelectionService() {
	return editor.getSite().getWorkbenchWindow().getSelectionService();
}