Introduction to the Eclipse Form Programming Guide

Source: Internet
Author: User
Tags add object event listener requires version
program | Design 1, Introduction

· Eclipse form is a new feature of Eclipse 3.0

· 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

· The Eclipse form provides:

* the "Form" concept for inclusion in the content area (editor or view)

* A toolkit for managing colors, hyperlink groups, and other form appearance like SWT controls

* New layout manager layout like HTML table

* Custom controls designed for form (hyperlinks, image links, scrollable composite, etc.)

* Each page is a multiple-page editor for a form (just like PDE)

2. Quick Start

(1) HelloWorld example

• 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 ();
}
}


• First create a Formtoolkit object instance

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

• Invoke the Scrolledform SetText () method to set the caption content at the top of the form

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

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

>
Id= "Formsamples"
Name= "Formsamples Plug-in"
version= "1.0.0"
Provider-name= "Nelson_tu"
Class= "Org.xqtu.samples.FormSamplesPlugin" >












Point= "Org.eclipse.ui.views" >
Class= "Org.xqtu.samples.views.FormView"
Name= "Form Sample"
Id= "FormView"/>


(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 (body, "click here.", SWT. WRAP);
Link.addhyperlinklistener (New Hyperlinkadapter () {
public void linkactivated (Hyperlinkevent e) {
System.out.println ("Link activated!");
}
});
}


• First get the body content of the form, which is a composite object

• Set its layout to GridLayout

• Create a hyperlink (Hyperlink) control through Formtoolkit

• Add a hyperlink event listener that responds to a hyperlink click

(3) Adding common controls

• Allows an SWT control to be created because the body content of the form is a composite object

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

• 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 (body, "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 a checkbox in a form", SWT. CHECK);
GD = new Griddata ();
Gd.horizontalspan = 2;
Button.setlayoutdata (GD);
Toolkit.paintbordersfor (body);
}


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

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

1) Call the SetData () method to add additional information about the redraw border

2) 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.