Eclipse Form Program Design Guide (1)

xiaoxiao2021-03-06  18

1 Introduction

l Eclipse Form is the new feature of Eclipse 3.0

l Eclipse Form is a set of plugins that custom widgets and support classes, previously used by PDE and UPDATE components, which has become a public API in Eclipse 3.0.

l Eclipse Form provides:

n Suitable for "form" concepts in the content area (editor or view)

n Toolkit used to manage color, hyperlink groups, and other icons like SWT controls

N like a new layout manager like an HTML form

n Take a custom control (hyperlink, image link, scrollable Composite, etc.)

N per page is a multi-page editor (like PDE)

2, get started

(1) HelloWorld example

l The following example Creates an empty Form in the view

Public class formview extends viewpart {

Private formtoolkit.

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 to create a formtoolkit object instance

l Create a FormToolkit (here is scrolledform)

l Call the ScrolledForm's setText () method, set the title content on the top of the Form

l Note: Finally, the FormToolkit object for Dispose is managed.

l To run in Workbench, you need plugin.xml to add org.eclipse.ui.forms to the required plug-in list, 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!");

}

});

}

l First get the content of the FORM, it is a Composite object

l Set its layout for GridLayout

l Create a hyperlink control via FormToolkit

l Add hyperlink event listener, respond to the click of the hyperlink

(3) Add universal control

l Since the content of the Form is a Composite object, SWT control is allowed.

l But the SWT control is designed to fit the window, the dialog is used, so it is problematic in Form.

l In Form, use FormToolkit to create a corresponding general 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_hizontal);

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);

}

l The above example adds three general controls: Label, Text and Checkbox

l Since the default version of the Text control is 3D, but to achieve a FLAT appearance like PDE, you need to do additional work:

n Call the setData () method, add additional information to the redo border

N calling formtoolkit's PaintBordersfor () method Heavy view of the Flat appearance

转载请注明原文地址:https://www.9cbs.com/read-41395.html

New Post(0)