2c00L
2c00L

Reputation: 514

Eclipse RCP: boolean variable to check a View active or not

I want to have a Boolean variable that is true if a view has already been activated in the RCP GUI, otherwise false.

I tried the following code:

        IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("view.id");

        if (view != null){
            System.out.println("View Active");
        }

But it returns a view even though it has not been activated in the GUI.

Upvotes: 1

Views: 294

Answers (2)

Artur Biesiadowski
Artur Biesiadowski

Reputation: 3698

findView should return null if view has not been created at all. If by 'active' you mean brought up to front/visible currently, try using IWorkbenchPage.isPartVisible

Upvotes: 3

Alex K.
Alex K.

Reputation: 3304

Try finding a view reference, without trying to restore the view, like this:

IViewReference viewReference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findViewReference("view.id");

if (viewReference.getView(false) != null) {
    System.out.println("View Active");
}

Upvotes: 1

Related Questions