Ieditexceptionbarcontributor of editpart

Source: Internet
Author: User

The difference between Editor and view is not only that the classic open --> modify --> Save.
It is also reflected in that the view has its own unique toolbar and drop-down menu, while the editor shares the common menu bar and toolbar.

The ieditexceptionbarcontributor class is used to add operations to the main menu bar and toolbar for one or more editors.
Generally, the shared menu bar and toolbar are added when the editor is opened. When the editor is closed (all of the same types are closed), the shared menu bar and toolbar are dispose.

Editexceptionbarcontributor is the standard implementation of the ieditexceptionbarcontributor interface. If we need
To add a shared object, you can do the following:
/**
* Contributes to the given menu.
If you need to add a menu for the opened editorpart, implement this method
*/
Public void contributetomenu (imenumanager menumanager ){
}

/**
* Contributes to the given status line.
*/
Public void contributetostatusline (istatuslinemanager statuslinemanager ){
}

/**
* Contributes to the given tool bar.
*/
Public void contributetotoolbar (itoolbarmanager toolbarmanager ){
}

/**
* Contributes to the given cool bar.
*/
Public void contributetocoolbar (icoolbarmanager coolbarmanager ){
}

In addition, let's focus on the setactiveeditor method. This method is called when the editor is opened.
In general, we will reference global activeeditor in this method, and may also associate retargetaction.
 
According to the sample rules, let's take a look at the basic implementation in Eclipse:
Okay. Let's take a look at how actionbarcontributor is implemented in GEF.
Let's take a look at the implementation of setactiveeditor:
Public void setactiveeditor (ieditorpart Editor ){
Actionregistry registry = (actionregistry) Editor. getadapter (actionregistry. Class );
Iactionbars bars = getactionbars ();
For (INT I = 0; I <globalactionkeys. Size (); I ++ ){
String id = (string) globalactionkeys. Get (I );
Bars. setglobalactionhandler (ID, registry. getaction (ID); // associate retarget action (Hook)
}
}



Let's look at a basic implementation of the open-source RCP application zdt:
Public class categoryeditexceptionbarcontributor extends
Editexceptionbarcontributor {

Private addentryaction;
Private editentryaction;

// Create an action and add it to the edit menu
Public void contributetomenu (imenumanager menumanager ){
Addentryaction = new addentryaction ();
Addentryaction. settooltiptext ("Add an entry ");
Editentryaction = new editentryaction ();
Addentryaction. settooltiptext ("edit an entry ");
Imenumanager editmenu = menumanager. findmenuusingpath ("edit ");
Editmenu. Add (new separator ());
Editmenu. Add (addentryaction );
Editmenu. Add (editentryaction );

}
//
Public void setactiveeditor (ieditorpart targeteditor ){
Addentryaction. setactiveeditor (targeteditor );
Editentryaction. setactiveeditor (targeteditor); // pass the opened Editor to the action
Targeteditor. getsite (). getpage (). addselectionlistener (editentryaction );
}
}

Public class addentryaction extends action
{
Private ieditorpart editor;
Private Final Static string id = "net. SourceForge. zdt. flashcard. commands. addentry ";

Public addentryaction ()
{
This. settext ("& add entry ");
This. setid ("# Add entry ");
This. setactiondefinitionid (ID );
}

Public void run ()
{
Categoryeditor chareditor = (categoryeditor) editor; // get the activated editorpart
Addentrywizard wizard = new addentrywizard ();
// Instantiates the wizard container with the wizard and opens
// It
Wizarddialog dialog = new wizarddialog (display. getdefault ()
. Getactiveshell (), wizard );
Dialog. Create ();
If (dialog. open () = Window. OK ){
Entryvalue EV = wizard. getentryvalue ();
Chareditor. addentrytoui (EV, true );
}
}

Public void setactiveeditor (ieditorpart targeteditor)
{
Editor = targeteditor;
}
}

In general, editexceptionbarcontributor is quite simple.

 

 

 

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.