当前位置:编程学习 > JSP >>

引用 Eclipse Forms Programming Guide

答案:Eclipse Forms Programming GuideInitial creation: 21 February 2004Added table wrap sample: 22 February 2004Introduction
This document has been written to help you use the new Eclipse 3.0 feature called 'Eclipse Forms'. The content will eventually move to Eclipse help. In the mean time, you can start experimenting using examples shown below and code in Eclipse 3.0 integration builds.

Eclipse Forms is a plug-in that exposes a set of customs widgets and other supporting classes that were before used as internal to PDE and Update components. They provide for creating polished, 'Web-like' UIs by modestly extending SWT and/or manipulating style bits, colors, fonts and other properties in order to get the desired behavior. This technology was used throughout PDE multi-page editors and will now be available as public API in Eclipse 3.0.

The document represents the state of API at the time of writing. It is possible that some aspects of the API will slightly change until final release. We anticipate only mechanical name changes rather than more fundamental changes.
Problem definition
When Eclipse platform was designed, there were two distinct context in which SWT widgets could appear:
In traditional dialogs (message boxes, dialogs, wizards, preference pages, property pages) In content areas (views and editors)
Controls in dialogs typically used default colors and fonts as provided by the operating system and were layed out using GridLayout in 9 out of 10 cases. The goal was to look like a dialog and fill the dialog space in both directions.

Controls in views and editors were 'stretchy' i.e. they filled the entire content area. Stretchy controls can scroll their content (trees, tables, text areas, lists etc.). The colors and fonts used here were those provided by the system for use in content area (these colors can be obtained from the Display using SWT.LIST_BACKGROUND or SWT.LIST_FOREGROUND keys).

What was missing was the third option where widgets you would normally see in the dialog context are created in views or editors (where you would expect 'stretchy' controls). Several problems needed to be solved:
SWT controls like buttons, labels, composites etc. look strange in the content areas as-is (with the default dialog background) Composites with GridLayout in the content area are problematic because they are not scrolled. Therefore, it is easy to get the controls to clip or start riding one another. Controls in the content area are normally wrapped to fill the provided width. Wrapping is very hard to accomplish with the existing SWT layouts. When problems 1-3 are fixed, the result looks very much like forms in HTML browsers, and a natural leap is to add hyperlinks and mix them with other controls.
Eclipse Forms were designed to solve these problems. They provide:
A concept of a 'form' that is suitable for inclusion into the content area (editor or view) A toolkit that manages colors, hyperlink groups and other aspects of the form, as well as serve as a factory for a number of SWT controls (these controls are created and configured to fit into the form context) A new layout manager that lays out controls using the algorithm similar to HTML tables Custom controls designed to fit into the form (hyperlink, image hyperlink, scrollable composite, section). Multi-page editor where each page is a form (as in PDE). Setup
In order to be able to use Eclipse Forms, all you need to do is add 'org.eclipse.ui.forms' plug-in to your list of required plug-ins. This plug-ins is RCP-friendly in that it does not have dependency on IDE plug-ins (its only dependency is org.eclipse.ui).
Examples
Source code for most of the examples shown in this document can be found in Eclipse repository (HEAD) as org.eclipse.ui.forms.examples. Check them out into the workspace and look inside the 'src' directory in a Java or PDE perspective.
API packages
Eclipse Forms has the following public (API) packages:
org.eclipse.ui.forms - the main package org.eclipse.ui.forms.editor - classes that employ Eclipse Forms on top of the MultiPageEditorPart to create multi-page editors as seen in PDE org.eclipse.ui.forms.events - new events created to support custom widgets org.eclipse.ui.forms.widgets - a set of custom widgets and layouts created specifically for Eclipse Forms Getting Started
We will start playing with Eclipse Forms by creating an empty form in a view. As we said above, views are content areas that require flexible content. Here is the code sample:

package org.eclipse.ui.forms.examples.views;import org.eclipse.swt.widgets.Composite;import org.eclipse.ui.forms.widgets.*;import org.eclipse.ui.part.ViewPart;

public class FormView extends ViewPart { private FormToolkit toolkit; private ScrolledForm form;
/** * This is a callback that will allow us * to create the viewer and initialize it. */ public void createPartControl(Composite parent) { toolkit = new FormToolkit(parent.getDisplay()); form = toolkit.createForm(parent); form.setText("Hello, Eclipse Forms"); }
/** * Passing the focus request to the form. */ public void setFocus() { form.setFocus(); }



/** * This is a callback that will allow us * to create the viewer and initialize it. */ public void createPartControl(Composite parent) { toolkit = new FormToolkit(parent.getDisplay()); form = toolkit.createForm(parent); form.setText("Hello, Eclipse Forms"); }
/** * Passing the focus request to the form. */ public void setFocus() { form.setFocus(); }


/** * Passing the focus request to the form. */ public void setFocus() { form.setFocus(); }

/** * Disposes the toolkit. */ public void dispose() { toolkit.dispose(); super.dispose(); }}
/** * Disposes the toolkit. */ public void dispose() { toolkit.dispose(); super.dispose(); }} org.eclipse.ui.forms.examples.views;import org.eclipse.swt.widgets.Composite;import org.eclipse.ui.forms.widgets.*;import org.eclipse.ui.part.ViewPart;
public class FormView extends ViewPart { private FormToolkit toolkit; private ScrolledForm form;
/** * This is a callback that will allow us * to create the viewer and initialize it. */ public void createPartControl(Composite parent) { toolkit = new FormToolkit(parent.getDisplay()); form = toolkit.createForm(parent); form.setText("Hello, Eclipse Forms"); }
/** * Passing the focus request to the form. */ public void setFocus() { form.setFocus(); }



/** * This is a callback that will allow us * to create the viewer and initialize it. */ public void createPartControl(Composite parent) { toolkit = new FormToolkit(parent.getDisplay()); form = toolkit.createForm(parent); form.setText("Hello, Eclipse Forms"); }
/** * Passing the focus request to the form. */ public void setFocus() { form.setFocus(); }


/** * Passing the focus request to the form. */ public void setFocus() { form.setFocus(); }

/** * Disposes the toolkit. */ public void dispose() { toolkit.dispose(); super.dispose(); }}
/** * Disposes the toolkit. */ public void dispose() { toolkit.dispose(); super.dispose(); }}
 In the snippet above, we have created a view by creating an instance of a toolkit first. We then used the toolkit to create a form. We set the title of the form. It is important not to forget that toolkit manages resources that need to be disposed of (hence the dispose method).

When we register this view with the workbench and run, we get the following:





The form we just created does the following things:

It renders the title we s

上一个:Google让你突破下载
下一个:Tomcat 5.5.x 配置集锦 (续)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,