Use retarget action in eclipse Development

Source: Internet
Author: User

 

Retarget action

This is an action that has certain semantics but has no actual function. Its only function is to occupy a position on the main menu bar or main toolbar, the editor can map actions with actual functions to a retarget action. When the editor is activated, the retarget action on the main menu/Toolbar will have that action function. For example, eclipse provides iworkbenchactionconstants. copy this retarget action. Its text and icons are pre-defined. Suppose our editor needs a "Copy node to clipboard" function, because the semantics of the words "Copy node" and "copy" are very similar, you can create a new

Copynodeaction (extends action), and then call the following code at an appropriate location to map the two:

Iactionbars. setglobalactionhandler (iworkbenchactionconstants. Copy, copynodeaction)

When the editor is activated, eclipse checks the ing to make the copy item available. When the user presses it, It executes the operation defined in copynodeaction, that is, run () code in the method.

Eclipse introduces retarget action to minimize the consumption of rebuilding the main menu/toolbar and facilitate user consistency. In the GEF application, because there are likely to be multiple views (for example, editing a view and outline view, even if there is only one view, you must consider the possibility of extension in the future ), each view should be able to perform similar operations. For example, in the Outline View of the tree structure, you should be able to delete the selected node like editing the view, therefore, general operations should be established by ing to retarget action.

 

 

We can not only use the built-in retarget action on the eclipse platform, such as actionfactory. Cut, actionfactory. Copy, and actionfactory. paste.

You can also define your own retarget action. You only need to inherit org. Eclipse. UI. Actions. retargetaciton. For example:

The following code comes from the open-source RCP application javasset.pdf.

Package net. sourceForge. export settables; import Org. eclipse. UI. iworkbenchwindow; import Org. eclipse. UI. actions. retargetaction; // inherited from retargetactionpublic class settingsaction extends retargetaction {public settingsaction (iworkbenchwindow window) {super ("Settings", "Settings... "); // The former is ID, and the latter is the display text window. getpartservice (). addpartlistener (this); setactiondefinitionid ("org. eclipse. UI. edit. settings "); // quick Key setting preparation} 1. In the makeactions method of applicationactionbar, create a retarget action. Settingsaction = new settingsaction (window); registger (settingsaction); 2. in fillmenubar, use: menu. add (settingsaction); 3. in the view or editor that needs to use retargetaction, use it in this way, as shown in the createpartcontrol method of a view to make: iactionbars actionbars = getviewsite (). getactionbars (); actionbars. setglobalactionhandler ("cut", cutaction); actionbars. setglobalactionhandler ("copy", copyaction); actionbars. setglobalactionhandler ("Paste", pasteaction = new pasteaction (this); actionbars. setglobalactionhandler ("delete", deleteaction); actionbars. setglobalactionhandler ("Settings", new action () {// public void run () {watchlistsettingsdialog DLG = new watchlistsettingsdialog (getwatchlist (), getviewsite (). getshell (); DLG. open ();}});

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.