3

I have a viewpart with closable set to true. The user clicks the x. I want to hide the viewpart rather then close it. how can this be done?

Xander
  • 9,069
  • 14
  • 70
  • 129

4 Answers4

3

This is possible, but it is tricky!

Closing the view actually 'hides' it from the current perspective. If the view is not shown anywhere, it is disposed.

You can check this by adding two perspectives to your RCP application, including the same view in both. Now, closing your view in perspective A will not dispose of it because it is still open in perspective B.

So to avoid disposing the view, you should just make sure it is included in another perspective. If your RCP application does not use perspectives, you can use a 'hidden' perspective which is never shown, but where you store all 'hidden' views so they are not disposed.

See also How to close a ViewPart in Eclipse? where the exact opposite is requested.

Community
  • 1
  • 1
parasietje
  • 1,529
  • 8
  • 36
0

You can try this:

shell.addShellListener(new ShellListener() {
            public void shellIconified(ShellEvent e) {
            }
            public void shellDeiconified(ShellEvent e) {
            }
            public void shellDeactivated(ShellEvent e) {
            }
            public void shellClosed(ShellEvent e) {
                shell.setVisible(false);
                e.doit = false;
            }
            public void shellActivated(ShellEvent e) {
            }
        });

Where shell is the immediate parent shell of the Viewpart. Main point to note is the e.doit=false, which essentially nullifies the close event.

Favonius
  • 13,959
  • 3
  • 55
  • 95
0

To my knowledge this is not possible in general. Basically a workbench part is shared between all the perspectives of a workbench window that has the editor or view "open". So when you switch perspective the to Composite of the part is simply resized to match the new presentation site where the part should be shown.

When a part is closed on for a specific perspective, it is hidden as you want it to be. When the part is hidden for all perspectives of the window, it is disposed. And as far as I can see, there are no way to prevent that.

Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70
0

If your app was created from a template that makes contributions to the UI it should have a WorkbenchWindowAdvisor file in one of the pregenerated packages. Not sure about the exact implementation details to hide the window on close, but it sounds like you will need to modify the preWindowShellClose method in the WorkbenchWindowAdvisor implementation of your application.

Adam Green
  • 171
  • 1
  • 7