(EXT) Several methods frequently invoked in the development of Eclipse RCP Plug-ins

Source: Internet
Author: User
Tags gettext
accessing Statusline in Plug-ins

Workbenchwindow window = Platfromui.getworkbench (). Getactiveworkbenchwindow (); Istatuslinemanager status = Window.getstatuslinemanager (); Quit RCP program

Platformui.getworkbench (). restart (); Restart RCP application

Platformui.getworkbench (). restart ();
Look for perspective in the plug-in repository (other extend point resources are similar)

Iperspectivedescriptor IPD = Platformui.getworkbench (). Getperspectiveregistry (). Findperspectivewithid ( Favoriteperspective.id); Get the shell of the current RCP application

Shell shell = Platformui.getworkbench (). Getactiveworkbenchwindow (). Getshell (); Display Help information

Platformui.getworkbench (). Gethelpsystem (). Displayhelp (); Show memory

Platformui.getpreferencestore (). SetValue (Iworkbenchpreferenceconstants.show_memory_monitor, true); A method for capturing the image resource sharing of Eclipse platform

Platformui.getworkbench (). Getsharedimages (). Getimagedescriptor (Isharedimages.img_objs_info_task)); RCP (plug-in development) get Plug-in version information

/**
* Get Plugin version
* @return
*/
Public String getversion () {
Return ((Bundlehost) Getbundle ()). GetVersion (). toString ();
}
* Get a reference to a view in another view

Platformui.getworkbench (). Getactiveworkbenchwindow (). GetActivePage (). Findview ("Viewid"); How to restart the RCP program using code.

Platformui.getworkbench (). restart (); Several ways to get the parent shell

Iviewpart or Ieditorpart:

Ishellprovider Shellprovider = Vieworeditor.getsite ();
Platformui:

Shell Parentshell =
Platformui.getworkbench (). Getactiveworkbenchwindow (). Getshell ();
Display:

Shell Parentshell = Display.getdefault (). Getactiveshell ();
In a class that implements the Iworkbenchwindowactiondelegate interface:

Private Iworkbenchwindow window;

public void init (Iworkbenchwindow window) {
This.window = window;
}
public void Run (IAction action) {
Shell Parentshell = Window.getshell ();
Mydialog dialog = new Mydialog (Parentshell,);
etc
Get program Startup Parameters

string[] args = Platform.getcommandlineargs (); Closes a current perspective to open a new perspective

Iworkbench W=platformui.getworkbench ();

Actionfactory.iworkbenchaction closeperspectiveaction
= ActionFactory.CLOSE_PERSPECTIVE.create (W.getactiveworkbenchwindow ());
Closeperspectiveaction.run ();

Try ... {
Platformui.getworkbench (). Showperspective ("Com.ibm.demo.saic.ui.views.NextPerspective"),
W.getactiveworkbenchwindow ());
catch (Workbenchexception e) ... {
E.printstacktrace ();
Customize Console View toolbar: Remove the Open console and select in RCP console view
the console button.

Workbenchpage page = Platformui.getworkbench (). Getworkbenchwindows () [0].getpages () [0];
Iviewpart Viewpart = Page.findview (Iconsoleconstants.id_console_view);
Iactionbars Actionbar = Viewpart.getviewsite (). Getactionbars ();
Itoolbarmanager toolbarmgr = Actionbar.gettoolbarmanager ();
icontributionitem[] items = Toolbarmgr.getitems ();
for (Icontributionitem Item:items) {
if (item instanceof Actioncontributionitem) {
IAction action = ((Actioncontributionitem) item). Getaction ();
String text = Action.gettext ();
if (text.equals ("Open console") | | text.equals ("SELECT Console")) {
Toolbarmgr.remove (item);
}
}
}
Actionbar.updateactionbars (); If you don't need anything in the toobar, you can directly

Toolbarmgr.removeall (); You can see that there are a lot of menubar on RCP now, which we don't need, and you can simplify by adding the following code to the code

MenuBar

Iworkbenchpage page = Platformui.getworkbench (). Getworkbenchwindows () [0]
. GetPages () [0];
Iviewpart Viewpart = Page.findview (Iconsoleconstants.id_console_view);
//Iactionbars Actionbar = Viewpart.getviewsite (). Getactionbars ();
Itoolbarmanager toolbarmgr = Viewpart.getviewsite (). Getactionbars ()
. Gettoolbarmanager ();
//Itoolbarmanager toolbarmgr = Actionbar.gettoolbarmanager ();
icontributionitem[] items = Toolbarmgr.getitems ();
for (Icontributionitem item:items) {
if (item instanceof actioncontributionitem) {
IAction action = (Act Ioncontributionitem) Item). Getaction ();
String Text = Action.gettext ();
if (text.equals ("Open console")
| | text.equals ("SELECT Console")) {
Toolbarmgr.remove (item);
}
}
}
Viewpart.getviewsite (). Getactionbars (). Updateactionbars ();

Related Article

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.