Eclipse Form Programming Guide (1)

Source: Internet
Author: User
Tags event listener requires
Program | design
1. Introduction

L Eclipse form is a new feature of Eclipse 3.0

L The Eclipse form is a set of custom widgets and support classes that were used internally by the PDE and update components and have become public APIs in Eclipse 3.0

L Eclipse Form provides:

N fits the "Form" concept included in the content area (editor or view)

n a toolkit for managing colors, hyperlink groups, and other form appearance like SWT controls

N A new layout manager layout like an HTML table

N Custom controls (hyperlinks, image links, scrollable composite, etc.) Designed for form

n Each page is a multiple-page editor of a form (just like PDE)





2. Quick Start

(1) HelloWorld example

L The following example creates an empty form in the view

public class FormView extends Viewpart {
Private Formtoolkit Toolkit;
Private Scrolledform form;
public void Createpartcontrol (composite parent) {
Toolkit = new Formtoolkit (Parent.getdisplay ());
Form = Toolkit.createscrolledform (parent);
Form.settext ("Hello, Eclipse Forms");
}







public void SetFocus () {
Form.setfocus ();
}







public void Dispose () {
Toolkit.dispose ();
Super.dispose ();
}
}



L First create a Formtoolkit object instance

L Create a Form object from Formtoolkit (this is scrolledform)

L CALL the Scrolledform SetText () method, set the caption content at the top of the form

L Note: The last Formtoolkit object to dispose of management resources

L to run in Workbench, you need plugin.xml, add org.eclipse.ui.forms to the list of required plug-ins, and register the view



<?xml version= "1.0" encoding= "UTF-8"?>
<?eclipse version= "3.0"?>
<plugin
Id= "Formsamples"
Name= "Formsamples Plug-in"
version= "1.0.0"
Provider-name= "Nelson_tu"
class= "Org.xqtu.samples.FormSamplesPlugin" >
<runtime>
<library name= "Formsamples.jar" >
<export name= "*"/>
</library>
</runtime>
<requires>
<import plugin= "Org.eclipse.ui"/>
<import plugin= "Org.eclipse.core.runtime"/>
<import plugin= "Org.eclipse.ui.forms"/>
</requires>
<extension

Point= "Org.eclipse.ui.views" > 

<view

Class= "Org.xqtu.samples.views.FormView" 

Name= "Form Sample"

Id= "FormView"/> 

</extension> 

</plugin>



(2) Add content

public void Createpartcontrol (composite parent) {

Toolkit = new Formtoolkit (Parent.getdisplay ());

Form = Toolkit.createscrolledform (parent);

Form.settext ("Hello, Eclipse Forms");

Composite BODY = Form.getbody ();

GridLayout layout = new GridLayout ();

Body.setlayout (layout);

Hyperlink link = toolkit.createhyperlink, "click here."

Swt. WRAP);

Link.addhyperlinklistener (New Hyperlinkadapter () {

public void linkactivated (Hyperlinkevent e) {

System.out.println ("Link activated!");

}



});



}



L first get the body content of the form, it's a composite object

L set its layout to GridLayout

L Create a hyperlink (Hyperlink) control through Formtoolkit

L Add a hyperlink event listener to respond to a hyperlink click

(3) Adding common controls

L allows an SWT control to be created because the form's body content is a composite object

L but SWT controls are designed to fit into Windows, dialog boxes, so using in form is problematic

L in form, use Formtoolkit to create the corresponding generic control

public void Createpartcontrol (composite parent) {



Toolkit = new Formtoolkit (Parent.getdisplay ());



Form = Toolkit.createscrolledform (parent);



Form.settext ("Hello, Eclipse Forms");







Composite BODY = Form.getbody ();



GridLayout layout = new GridLayout ();



Body.setlayout (layout);



Hyperlink link = toolkit.createhyperlink, "click here."



Swt. WRAP);



Link.addhyperlinklistener (New Hyperlinkadapter () {



public void linkactivated (Hyperlinkevent e) {



System.out.println ("Link activated!");



}



});







Layout.numcolumns = 2;



Griddata gd = new Griddata ();



Gd.horizontalspan = 2;



Link.setlayoutdata (GD);



Label label = Toolkit.createlabel (Body, "Text field Label:");



Text text = Toolkit.createtext (Body, "");



Text.setlayoutdata (New Griddata (griddata.fill_horizontal));



Text.setdata (Formtoolkit.key_draw_border, Formtoolkit.text_border);



Button button = Toolkit.createbutton (Body,



"An example of the A checkbox in a form", SWT. CHECK);



GD = new Griddata ();



Gd.horizontalspan = 2;



Button.setlayoutdata (GD);



Toolkit.paintbordersfor (body);



}



L The example above adds three common controls: Label, text, and checkbox

Because the appearance of the text control created by default is 3D, you need to do some extra work to achieve a flat appearance like PDE:

n Invoke the SetData () method to add additional information about the redraw border

N Call the Formtoolkit paintbordersfor () method to redraw the border of the flat skin


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.