Good blog for eclipse plugin developers https://cvalcarcel.wordpress.com/
Java, Eclipse Plugin Development and best software development practices
Showing posts with label eclipse plugin development. Show all posts
Showing posts with label eclipse plugin development. Show all posts
Thursday, January 23, 2020
Tuesday, May 5, 2015
Listening to project explorer changes
If you want to control some actions based on the selection of an element from the project explorer, we can register a post selection changes through service registry.
//Register listener
ISelectionService ss = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ProjectExplorerSelectionListener selectionListener = new ProjectExplorerSelectionListener();
ss.addPostSelectionListener(IPageLayout.ID_PROJECT_EXPLORER, selectionListener);
//Listener
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
{
public void selectionChanged(IWorkbenchPart part, ISelection newSelection)
{
if (newSelection instanceof IStructuredSelection)
{
Object element = ((IStructuredSelection) newSelection).getFirstElement();
if (element instanceof IAdaptable)
{
IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
final IProject project = resource.getProject();
//do your action here!!
}}
}
Subscribe to:
Posts (Atom)