General steps for eclipse form primary/Slave (master/details) mode development

Source: Internet
Author: User

The following uses a multi-page editor as an example:
1. First, create a multi-page editor plug-in. After the plug-in is created, change the editor implementation class to formeditor.
(After the creation, you need to import the form package: org. Eclipse. UI. Forms)
2. After the editor is created, our Master/Slave structure will certainly appear on a page. Assume masterdetailspage. That is, you need to create the masterdetailspage class. This class should inherit the following class: formpage. We should set the masterdetailsblock content to the current form. This is usually implemented as follows:
Final scrolledform form = managedform. getform ();
// Formtoolkit toolkit = managedform. gettoolkit ();
Form. settext (messages. getstring ("masterdetailspage. Title "));
Form. setbackgroundimage (formarticleplugin. getdefault (). getimage (formarticleplugin. img_form_bg ));
Block. createcontent (managedform );
3. After the page is defined, the key is to implement the Master/Slave structure on the page. To create a Master/Slave Mode, you need to create a masterdetailsblock class. Here we assume this class is scrolledpropertiesblock, And the scrolledpropertiesblock class implements the masterdetailsblock class. Then the key is to implement the following two methods in this class:
(1) protected void createmasterpart (imanagedform managedform,
Composite parent)
This method is used to create the main screen! Generally, we create a table or a tree. Note that the fireselectionchanged event of managedform is triggered when appropriate. This event is used to update the slave interface corresponding to the current selection! For example, a tree or table can be triggered by its selection of change events. According to the parameter requirements of this event, you also need to create an iformpart object as the parameter to pass in. You can easily create a sectionpart object. Then add this object to managedform. As follows:
Sectionpart Spart = new sectionpart (section );
Managedform. addpart (Spart );
Then, in the select change event, write as follows:
Managedform. fireselectionchanged (Spart, event. getselection ());
(2) protected void registerpages (detailspart)
To register the slave interface, the implementation is as follows:
Detailspart. registerpage (typeone. Class,
New typeonedetailspage ());
The typeone. Class indicates the type of the selected object on the main interface. The typeonedetailpage indicates that when the selected type is typeone, the displayed page is typeonedetailpage.
If you want to switch between vertical and horizontal placement, you should implement the following methods:
Protected void createmedilbaractions (imanagedform managedform)
Generally, you can write as follows:
Final scrolledform form = managedform. getform ();
Action haction = new action ("Horizontal placement", action. as_radio_button ){
Public void run (){
Sashform. setorientation (SWT. Horizontal );
Form. reflow (true );
}
};
Haction. setchecked (true );
Haction. settooltiptext ("Horizontal placement"); haction. setimagedescriptor (icon description );
Action vaction = new action ("vertical placement", action. as_radio_button) {public void run (){
Sashform. setorientation (SWT. Vertical );
Form. reflow (true );
}
};
Vaction. setchecked (false );
Vaction. settooltiptext ("vertical placement"); vaction. setimagedescriptor (icon description );
Form. gettoolbarmanager (). Add (haction );
Form. gettoolbarmanager (). Add (vaction );
4. Finally, implement the slave interface. The interface class (that is, the typeonedetailpage class above) should implement the class: idetailspage. In this class, you can also get the selected change event, which is passed in by the managedform mentioned above. You can use this change to get the selected object:
Public void selectionchanged (iformpart part, iselection selection)
Then, implement your own logic based on this change.
Use the following method to draw controls:
Public void createcontents (composite parent)
One thing to note here is that you should remember to give this parent a layout, or you will find that you will not be able to see the drawn from the interface after running it!
In general, this slave interface should also be painted on the form component like the main interface, so a formtooltip object is required. Generally, a program should not have multiple formtooltip objects, to get this formtooltip object, we should rewrite the following methods:
Public void initialize (imanagedform form ){
This. form = form;
}
Then you can use this form object to get the formtooltip:
Formtoolkit toolkit = form. gettoolkit ();
The above describes the general steps for using the master/slave structure in a multi-page plug-in. If you use it in an application, both step 3 and Step 4 are the same, and step 1 and Step 2 are changed to the following method:
// Create a managedform object
Managedform = new managedform (Shell );
// Set the placement of form Objects Based on the managedform object.
Scrolledform form = managedform. getform ();
Form. settext ("hello ");
Form. setlayoutdata (New griddata (griddata. fill_both ));
// Create a masterdetailsblock object and create content on the managedform object
Customblock block = new customblock ();
Block. createcontent (managedform );

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.