Reputation: 515
I am using eclipse RCP. I have an item in a table and when I double click on the item it opens a view . If the user does not have access to the view, then the user cannot open the view.
So I checked for the access rights for the user on the item and I close the perspective.
if (!user.hasReadAccess())
final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (int w = 0; w < windows.length; w++)
{
final IWorkbenchPage[] pages = windows[w].getPages();
for (int p = 0; p < pages.length; p++)
{
final IWorkbenchPage page = pages[p];
// page.hideView(page.findView(MYViewID));
final IViewReference[] viewRefs = page.getViewReferences();
for (int v = 0; v < viewRefs.length; v++)
{
for (IPerspectiveDescriptor ipd : page.getOpenPerspectives())
{
if (ipd.getId().equalsIgnoreCase(PERSPECTIVE_ID))
{
page.closePerspective(page.getPerspective(), true, true);
break;
}
}
}
}
}
It hides the perspective but it always opens the perspective and close it immediately.
In other words, even after the closePerspective()
is called, the CreatePartControl
method of the ViewPart
is still invoked and the user is able to see the view getting opened and closed immediately. What causes this problem and how can I solve it?
Upvotes: 1
Views: 203
Reputation: 14238
There should be a method on IWorkbenchPage that you use to open a view like :
public IViewPart showView(String viewId, String secondaryId, int mode)
throws PartInitException;
you should call this method in an if condition saying
if ( userHasReadAccess ) {
page.showView(viewId, secondaryId, IworkbenchPage.VIEW_ACTIVATE );
}
Upvotes: 0