Disable the current (active) view and all views

Source: Internet
Author: User

Close a view usually hides the view (hide. View the Code directly:

1. Disable the current (active) view

Public class closeaction extends action

{

 

Public closeaction ()

{

Settext ("close ");

Setactiondefinitionid ("org. Eclipse. UI. file. Close"); // we recommend that you set

}

 

/* (Non-javadoc)

* @ See org. Eclipse. jface. action. Action # Run ()

*/

Public void run ()

{

Iworkbenchpage = platformui. getworkbench (). getactiveworkbenchwindow (). getactivepage ();

 

System. Out. println (page. getactivepart (). gettitle ());

Iworkbenchpart part = page. getactivepart (); // The current iworkbenchpart obtained may be ieditorpart (editor) or iviewpart (view ). So we need to make

 

Instanceof judgment. Of course, iworkbenchpage also provides the method to directly obtain the current ieditorpart.

If (Part instanceof iviewpart)

Page. hideview (iviewpart) part );

}

}

 

2. Close all views

To close all views, you first obtain an iviewreference array for all views. Also hide viewpart (hide)

Public class closeallaction extends action

{

 

Public closeallaction ()

{

Settext ("close all ");

Setactiondefinitionid ("org. Eclipse. UI. file. closeall"); // $ NON-NLS-1 $

}

 

/* (Non-javadoc)

* @ See org. Eclipse. jface. action. Action # Run ()

*/

Public void run ()

{

Iworkbenchpage = platformui. getworkbench (). getactiveworkbenchwindow (). getactivepage ();

Iviewreference [] refs = page. getviewreferences (); // not directly obtaining viewpart. In fact, iworkbenchpage does provide the method for obtaining all views, but what is obtained here is

 

Iviewpeference.

 

For (INT I = 0; I <refs. length; I ++)

{

Iworkbenchpart part = refs [I]. getpart (false); // obtain the view

If (Part instanceof iviewpart)

Page. hideview (iviewpart) part );

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.