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 );
}
}
}