Java Code Examples for org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener()

The following examples show how to use org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener() . 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: DelegatingSelectionProvider.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets a new selection provider to delegate to. Selection listeners registered with the
 * previous delegate are removed before.
 * 
 * @param newDelegate
 *            new selection provider
 */
public void setSelectionProviderDelegate(ISelectionProvider newDelegate){
	if (delegate == newDelegate) {
		return;
	}
	if (delegate != null) {
		delegate.removeSelectionChangedListener(selectionListener);
		if (delegate instanceof IPostSelectionProvider) {
			((IPostSelectionProvider) delegate)
				.removePostSelectionChangedListener(postSelectionListener);
		}
	}
	delegate = newDelegate;
	if (newDelegate != null) {
		newDelegate.addSelectionChangedListener(selectionListener);
		if (newDelegate instanceof IPostSelectionProvider) {
			((IPostSelectionProvider) newDelegate)
				.addPostSelectionChangedListener(postSelectionListener);
		}
		fireSelectionChanged(newDelegate.getSelection());
		firePostSelectionChanged(newDelegate.getSelection());
	}
}
 
Example 2
Source File: OpenViewActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void initialize(ISelectionProvider provider) {
	fSelectionProvider= provider;
	ISelection selection= provider.getSelection();
	fOpenImplementation.update(selection);
	fOpenSuperImplementation.update(selection);
	fOpenAttachedJavadoc.update(selection);
	fOpenTypeHierarchy.update(selection);
	fOpenCallHierarchy.update(selection);
	if (!fEditorIsOwner) {
		if (fShowOpenPropertiesAction) {
			if (selection instanceof IStructuredSelection) {
				fOpenPropertiesDialog.selectionChanged((IStructuredSelection) selection);
			} else {
				fOpenPropertiesDialog.selectionChanged(selection);
			}
		}
		provider.addSelectionChangedListener(fOpenImplementation);
		provider.addSelectionChangedListener(fOpenSuperImplementation);
		provider.addSelectionChangedListener(fOpenAttachedJavadoc);
		provider.addSelectionChangedListener(fOpenTypeHierarchy);
		provider.addSelectionChangedListener(fOpenCallHierarchy);
		// no need to register the open properties dialog action since it registers itself
	}
}
 
Example 3
Source File: UIHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Tries to set the given message on the workbench's status line. This is a
 * best effort method which fails to set the status line if there is no
 * active editor present from where the statuslinemanager can be looked up.
 * 
 * @param msg
 *            The message to be shown on the status line
 */
public static void setStatusLineMessage(final String msg) {
	IStatusLineManager statusLineManager = null;
	ISelectionProvider selectionService = null;

	// First try to get the StatusLineManager from the IViewPart and only
	// resort back to the editor if a view isn't active right now.
	final IWorkbenchPart workbenchPart = getActiveWindow().getActivePage().getActivePart();
	if (workbenchPart instanceof IViewPart) {
		final IViewPart viewPart = (IViewPart) workbenchPart;
		statusLineManager = viewPart.getViewSite().getActionBars().getStatusLineManager();
		selectionService = viewPart.getViewSite().getSelectionProvider();
	} else if (getActiveEditor() != null) {
		final IEditorSite editorSite = getActiveEditor().getEditorSite();
		statusLineManager = editorSite.getActionBars().getStatusLineManager();
		selectionService = editorSite.getSelectionProvider();
	}

	if (statusLineManager != null && selectionService != null) {
		statusLineManager.setMessage(msg);
		selectionService.addSelectionChangedListener(new StatusLineMessageEraser(statusLineManager,
				selectionService));
	}
}
 
Example 4
Source File: ShowActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void initialize(IWorkbenchSite site, boolean isJavaEditor) {
	fSite= site;
	ISelectionProvider provider= fSite.getSelectionProvider();
	ISelection selection= provider.getSelection();
	fShowInPackagesViewAction.update(selection);
	if (!isJavaEditor) {
		provider.addSelectionChangedListener(fShowInPackagesViewAction);
	}
}
 
Example 5
Source File: SelectionListenerWithASTManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void install(ISelectionListenerWithAST listener) {
	if (isEmpty()) {
		fPart.getEditorSite().getPage().addPostSelectionListener(fPostSelectionListener);
		ISelectionProvider selectionProvider= fPart.getSelectionProvider();
		if (selectionProvider != null)
				selectionProvider.addSelectionChangedListener(fSelectionListener);
	}
	fAstListeners.add(listener);
}
 
Example 6
Source File: ExecuteCommandHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add the selection changed listener
 *  
 * @param selectionProvider
 */
private void addListener(ISelectionProvider selectionProvider, ISelectionChangedListener listener) {
	if (selectionProvider instanceof IPostSelectionProvider)  {
		IPostSelectionProvider provider= (IPostSelectionProvider) selectionProvider;
		provider.addPostSelectionChangedListener(listener);
	} else  {
		selectionProvider.addSelectionChangedListener(listener);
	}
}
 
Example 7
Source File: ProjectActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new <code>ProjectActionGroup</code>. The group requires
 * that the selection provided by the given selection provider is of type
 * {@link IStructuredSelection}.
 *
 * @param site the site that will own the action group.
 * @param selectionProvider the selection provider used instead of the
 *  page selection provider.
 *
 * @since 3.4
 */
public ProjectActionGroup(IWorkbenchSite site, ISelectionProvider selectionProvider) {
	fSelectionProvider= selectionProvider;
	ISelection selection= selectionProvider.getSelection();

	fCloseAction= new CloseResourceAction(site);
	fCloseAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_CLOSE_PROJECT);

	fCloseUnrelatedAction= new CloseUnrelatedProjectsAction(site);
	fCloseUnrelatedAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_CLOSE_UNRELATED_PROJECTS);

	fOpenAction= new OpenProjectAction(site);
	fOpenAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_OPEN_PROJECT);
	if (selection instanceof IStructuredSelection) {
		IStructuredSelection s= (IStructuredSelection)selection;
		fOpenAction.selectionChanged(s);
		fCloseAction.selectionChanged(s);
		fCloseUnrelatedAction.selectionChanged(s);
	}

	fSelectionChangedListener= new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			ISelection s= event.getSelection();
			if (s instanceof IStructuredSelection) {
				performSelectionChanged((IStructuredSelection) s);
			}
		}
	};
	selectionProvider.addSelectionChangedListener(fSelectionChangedListener);

	IWorkspace workspace= ResourcesPlugin.getWorkspace();
	workspace.addResourceChangeListener(fOpenAction);
	workspace.addResourceChangeListener(fCloseAction);
	workspace.addResourceChangeListener(fCloseUnrelatedAction);
}
 
Example 8
Source File: AbstractGlobalSelectionAction.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected AbstractGlobalSelectionAction( ISelectionProvider provider, String id )
{
	super( null );
	Assert.isNotNull( provider );
	setId( id );
	setSelectionProvider( provider );
	provider.addSelectionChangedListener( new ISelectionChangedListener( ) {

		public void selectionChanged( SelectionChangedEvent event )
		{
			update( );
		}
	} );
	setLazyEnablementCalculation( true );
}
 
Example 9
Source File: AbstractThemeableEditor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void install(ISelectionProvider selectionProvider)
{
	if (selectionProvider == null)
	{
		return;
	}
	if (selectionProvider instanceof IPostSelectionProvider)
	{
		((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener(this);
	}
	else
	{
		selectionProvider.addSelectionChangedListener(this);
	}
}
 
Example 10
Source File: GWTOpenEditorActionGroup.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void initialize(ISelectionProvider provider) {
  ISelection selection = provider.getSelection();
  openAction.update(selection);
  if (!isEditorOwner) {
    provider.addSelectionChangedListener(openAction);
  }
}
 
Example 11
Source File: JavaScriptLightWeightEditor.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Installs this selection changed listener with the given selection
 * provider. If the selection provider is a post selection provider,
 * post selection changed events are the preferred choice, otherwise
 * normal selection changed events are requested.
 *
 * @param selectionProvider
 */
public void install(ISelectionProvider selectionProvider) {
	if (selectionProvider == null)
		return;

	if (selectionProvider instanceof IPostSelectionProvider) {
		IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider;
		provider.addPostSelectionChangedListener(this);
	} else {
		selectionProvider.addSelectionChangedListener(this);
	}
}
 
Example 12
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Installs this target. I.e. adds all required listeners.
 */
private boolean install() {
	if (editor instanceof AbstractTextEditor && !isInstalled()) {
		bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		viewer = findSourceViewer(editor);
		if (viewer != null) {
			widget = viewer.getTextWidget();
			if (widget == null || widget.isDisposed()) {
				viewer = null;
				widget = null;
				return false;
			}
			widget.addMouseListener(this);
			widget.addFocusListener(this);
			viewer.addTextListener(this);

			ISelectionProvider selectionProvider = viewer.getSelectionProvider();
			if (selectionProvider != null)
				selectionProvider.addSelectionChangedListener(this);

			if (viewer instanceof ITextViewerExtension){
				((ITextViewerExtension) viewer).prependVerifyKeyListener(this);
				KbdMacroSupport.getInstance().continueKbdMacro(this,editor);
			} else {
				widget.addVerifyKeyListener(this);
			}
			addOtherListeners(page,viewer, widget);
			installed = true;
		}
	}
	addStatusContribution(editor);		
	return installed;
}
 
Example 13
Source File: OpenEditorActionGroup.java    From typescript.java with MIT License 5 votes vote down vote up
private void initialize(ISelectionProvider provider) {
	ISelection selection= provider.getSelection();
	fOpen.update(selection);
	if (!fIsEditorOwner) {
		provider.addSelectionChangedListener(fOpen);
	}
}
 
Example 14
Source File: OutlineWithEditorLinker.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void activate(OutlinePage outlinePage) {
	this.outlinePage = outlinePage;
	treeViewer = outlinePage.getTreeViewer();
	treeListener = new TreeListener();
	treeViewer.addPostSelectionChangedListener(treeListener);
	treeViewer.addDoubleClickListener(treeListener);
	textViewer = outlinePage.getSourceViewer();
	textListener = new TextListener();
	ISelectionProvider textSelectionProvider = textViewer.getSelectionProvider();
	if (textSelectionProvider instanceof IPostSelectionProvider)
		((IPostSelectionProvider) textSelectionProvider).addPostSelectionChangedListener(textListener);
	else
		textSelectionProvider.addSelectionChangedListener(textListener);
}
 
Example 15
Source File: OccurrencesSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, ISelectionProvider specialSelectionProvider) {
	action.update(selection);
	provider.addSelectionChangedListener(action);
	if (specialSelectionProvider != null)
		action.setSpecialSelectionProvider(specialSelectionProvider);
}
 
Example 16
Source File: ReferencesSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, ISelectionProvider specialSelectionProvider) {
	action.update(selection);
	provider.addSelectionChangedListener(action);
	if (specialSelectionProvider != null)
		action.setSpecialSelectionProvider(specialSelectionProvider);
}
 
Example 17
Source File: ReadReferencesSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection, ISelectionProvider specialSelectionProvider) {
	action.update(selection);
	provider.addSelectionChangedListener(action);
	if (specialSelectionProvider != null)
		action.setSpecialSelectionProvider(specialSelectionProvider);
}
 
Example 18
Source File: GenerateActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void registerSelectionListener(ISelectionProvider provider, ISelectionChangedListener listener) {
	if (fRegisteredSelectionListeners == null)
		fRegisteredSelectionListeners= new ArrayList<ISelectionChangedListener>(20);
	provider.addSelectionChangedListener(listener);
	fRegisteredSelectionListeners.add(listener);
}
 
Example 19
Source File: ChartActionBarContributor.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void activate ()
{
    this.activeEditorPart.addPropertyListener ( this );

    this.deleteAction.setActiveWorkbenchPart ( this.activeEditorPart );
    this.cutAction.setActiveWorkbenchPart ( this.activeEditorPart );
    this.copyAction.setActiveWorkbenchPart ( this.activeEditorPart );
    this.pasteAction.setActiveWorkbenchPart ( this.activeEditorPart );
    this.undoAction.setActiveWorkbenchPart ( this.activeEditorPart );
    this.redoAction.setActiveWorkbenchPart ( this.activeEditorPart );

    if ( this.loadResourceAction != null )
    {
        this.loadResourceAction.setActiveWorkbenchPart ( this.activeEditorPart );
    }

    if ( this.controlAction != null )
    {
        this.controlAction.setActiveWorkbenchPart ( this.activeEditorPart );
    }

    if ( this.validateAction != null )
    {
        this.validateAction.setActiveWorkbenchPart ( this.activeEditorPart );
    }

    final ISelectionProvider selectionProvider = this.activeEditorPart instanceof ISelectionProvider ? (ISelectionProvider)this.activeEditorPart : this.activeEditorPart.getSite ().getSelectionProvider ();

    if ( selectionProvider != null )
    {
        selectionProvider.addSelectionChangedListener ( this.deleteAction );
        selectionProvider.addSelectionChangedListener ( this.cutAction );
        selectionProvider.addSelectionChangedListener ( this.copyAction );
        selectionProvider.addSelectionChangedListener ( this.pasteAction );

        if ( this.validateAction != null )
        {
            selectionProvider.addSelectionChangedListener ( this.validateAction );
        }

        if ( this.controlAction != null )
        {
            selectionProvider.addSelectionChangedListener ( this.controlAction );
        }

        if ( this.saveAsAction != null )
        {
            selectionProvider.addSelectionChangedListener ( this.saveAsAction );
        }
    }

    update ();
}
 
Example 20
Source File: RefactorActionGroup.java    From typescript.java with MIT License 3 votes vote down vote up
/**
 * Sets actionDefinitionId, updates enablement, adds to fActions, and adds
 * selection changed listener if provider is not <code>null</code>.
 *
 * @param action
 *            the action
 * @param provider
 *            can be <code>null</code>
 * @param specialProvider
 *            a special selection provider or <code>null</code>
 * @param selection
 *            the selection
 * @param actionDefinitionId
 *            the action definition id
 */
private void initUpdatingAction(SelectionDispatchAction action, ISelectionProvider provider,
		ISelectionProvider specialProvider, ISelection selection, String actionDefinitionId) {
	action.setActionDefinitionId(actionDefinitionId);
	action.update(selection);
	if (provider != null)
		provider.addSelectionChangedListener(action);
	if (specialProvider != null)
		action.setSpecialSelectionProvider(specialProvider);
	fActions.add(action);
}