Eclipse custom extension points

Source: Internet
Author: User
In RCP programs, the main means to achieve scalability and insertion is to create custom extensions. Of course, the software itself must be properly designed. This section describes how to create a custom extension point by adding a node to the function navigator of the SMS project. The final result is 33.3. Fig 33.3 Add a custom extension pointAdd the following statement to the In in. xml file to create an extension point. As shown in figure 33.4, an additional item is displayed on the "extension point" page of the plug-in List editor. <Extension-point id = "navigators" name = "Navigator tree entries"/> "extended points" Interface Use custom extension pointsThere is no essential difference between using a custom extension point and using an eclipse extension point. The key is what information needs to be set for this extension point. Review the tree node of the function navigator, which is the responsibility of the navigatorentry class. This class has six attributes: ● name: node name. ● Image: the node icon. ● Parententry: parent node. ● Children: subnode set. ● Editorinput: The editorinput of the editor corresponding to the node. ● Editorid: The editor corresponds to the ID value in plugin. xml. To simplify the example, only the name and image settings are provided, which is enough for the nodes to be displayed in the function navigator. Add the following extension points to the plugin. xml file. <Extension point = "cn.com. chengang. SMS. navigators "> <navigator class =" cn.com. chengang. SMS. navigator. pluginnavigatorentry "icon =" icons/project.gif "name =" extended node "/> </extension> Description: ● define an extension point using" extension-point ", "extension point" is used for extension points, with slight differences between the two. ● The ID of the original defined extension point is navigators. The plug-in ID must be prefixed with cn.com. chengang. SMS. navigators. ● Plugin. XML is essentially an XML file. You can change the class to class1 or the icon to image. However, after this modification, the program code for reading the plugin. xml setting information should also be changed accordingly. In general, try to use the common name in eclipse. Create extension point-defined class pluginnavigatorentryThe Code is as follows: Package cn.com. chengang. SMS. navigator; public class pluginnavigatorentry extends navigatorentry {}. This class inherits the navigatorentry node class and can be added to the Code required by the application in actual development. As an example, there is no need to add code. Read extended point definition InformationYou have defined extension points in plugin. xml and created related classes. The key of this step is to read the settings of custom extension points in plugin. xml and create node instances accordingly. Add the following code to the smsfactory class. // Obtain plugin. add the custom nodes in XML to the Private Static list <itreeentry> getpluginnavigator () {list <itreeentry> result = new arraylist <itreeentry> () in a list set (); // from plugin. retrieve the information of the custom extended point navigators in XML iextensionregistry = platform. Getextensionregistry(); Iextensionpoint extension = registry. getextensionpoint ("cn.com. chengang. SMS. navigators"); If (extension = NULL) return collections. Emptylist(); // Retrieve plugin. the configuration information iconfigurationelement [] configelements = extension. getconfigurationelements (); For (iconfigurationelement Ce: configelements) {try {// create an instance of the defined class navigatorentry navigator = (navigatorentry) Ce based on the class attribute of the configuration information. createexecutableextension ("class"); navigator. setname (string) CE. getattribute ("name"); string icon = (string) CE. getattribute ("icon"); navigator. se Timage (activator. getimagedescriptor (icon ). createimage (); result. add (Navigator);} catch (coreexception e) {e. printstacktrace () ;}} return result ;}modify the method for creating a function navigator Tree node in the smsfactory class and add the custom node to the Tree node set. Public static list <itreeentry> createnavigatorentrytree (){...... The previous Code remains unchanged and is omitted. List. addall (getpluginnavigator (); return list;} if the information of custom extension points is more complex, you can imitate *. UI. views can read extended point information in three different categories: ● viewdescriptor-this is a data class corresponding to a custom extended point, it actually disables access to the iconfigurationelement class. ● Viewregistry -- If viewdescriptor is the information encapsulation of a certain extension point, viewregistry encapsulates all information of a custom extension point. If viewdescriptor is compared to a province, viewregistry is the whole country. ● Viewregistryreader-This class is responsible for transmitting data to viewregistry. If viewregistry is blind, viewregistryreader is the reader. SummaryAfter completing the above steps, run the SMS project and you will see Figure 33.3. From this example, we can see that there is no big difference between custom extension points in eclipse and common programming methods of "configuration file + code reading". If you have used spring or other frameworks, this is easier to understand. Create a schema file for the extension pointIn the past, when using extensions, it was possible that the class attribute could be mistakenly written to clasa. In this case, eclipse will prompt an error, but this custom extension point does not exist. In the past, when creating an extension point on the "extension" interface of the plug-in List editor, a graphical editing interface exists, but this custom extension point does not exist. The reason for this lack of intelligence is that a schema file is rarely created. The custom extension point uses XML, and the XML specification contains a schema file (in the past DTD) that can be used to constrain the XML format. Schema defines the XML items and subitems, the attributes of each item, the names of the attributes, whether the attributes are numeric or numeric, and whether the attributes are optional. Eclipse uses the schema file of the extension point to check whether the extension point statement written by the user is incorrect. It creates the graphic editing interface for the extension point based on the schema definition. How to define a schema? You can refer to how eclipse's view extension point org. Eclipse. UI. Views is defined, and then simulate it. * The address of the schema file of the UI. Views extension point is C:/Eclipse/plugins/org. Eclipse. RCP. Source... /Src/org. Eclipse. UI... /Schema/views. exsd: copy it to the schema subdirectory of the SMS project root directory (the directory name can be retrieved) and change the file name to navigators. exsd (the file name can be any, but it is generally the same as the corresponding extension point name ). To enable the custom extension point to accept the schema specification, add schema = "schema/navigators. exsd" to the end of the definition statement of the custom extension point "., When schema is added, an error is immediately displayed on the Left bar of Eclipse. This is because the schema file was originally prepared for the extended point views. Of course, it is not suitable for custom extended point navigators. The impact of schema on the extended points is modified according to the actual situation of the navigators extension points. exsd file: Open navigators. the exsd file displays a graphic editor, where "general information" items are modified according to Figure 33.6. The following is equivalent to the help information. Go to the "Definition" interface, where you can define the items and sub-items that the extension points should contain and what attributes each item has. Delete unnecessary attribute items from the definition of the original views extension point; change the view item to navigator; change the "extension" item (parent class) of the class attribute to the navigatorentry class; delete the original views node of the "option" node and add a reference node of the navigator. The final result. % Tip: Right-click the shortcut menu in the list to add or delete nodes. Navigators. in the "general information" and "Definition" interface of exsd, the class attribute setting interface saves navigators. after exsd, You can see plugin. the original warning prompt in the XML editor is no longer displayed. Go to the "extension" Page and you can see that the new custom extension point also has a graphic editing interface. Graphic editing page after creating a custom extension point

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.