hi all,
i am developing one eclipse plugin. now when user click on any file/folder and click icon(added by me) then i have to get that file location.
can you please help me regarding this one.
Thanks in advance.
hi all,
i am developing one eclipse plugin. now when user click on any file/folder and click icon(added by me) then i have to get that file location.
can you please help me regarding this one.
Thanks in advance.
Every IWorkbenchPartSite has a method
/**
* Sets the selection provider for this workbench site.
*
* @param provider
* the selection provider, or <code>null</code> to clear it
*/
public void setSelectionProvider(ISelectionProvider provider);
When something is selected inside the part site you should get a notification to handle the event.
You can get the Selection by calling
/**
* Returns the current selection for this provider.
*
* @return the current selection
*/
public ISelection getSelection();
I your case the ISelection object should be an instance of IStructuredSelection and the selected objects you can get by calling
public interface IStructuredSelection extends ISelection {
/**
* Returns the first element in this selection, or <code>null</code>
* if the selection is empty.
*
* @return an element, or <code>null</code> if none
*/
public Object getFirstElement();
/**
* Returns an iterator over the elements of this selection.
*
* @return an iterator over the selected elements
*/
public Iterator iterator();
...
}
You should get the IResource directly, when the user selects it in the package explorer for example.
You also can get the current used ISelectionProvider from the PartSite the IResource is selected, after the user pressed your Icon-Button.
You can get some Provider of some open view by calling
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("VIEW-ID").getViewSite().getSelectionProvider();
Views: