Eclipse Forms Programming Guide文档格式.docx
- 文档编号:21056533
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:42
- 大小:569.95KB
Eclipse Forms Programming Guide文档格式.docx
《Eclipse Forms Programming Guide文档格式.docx》由会员分享,可在线阅读,更多相关《Eclipse Forms Programming Guide文档格式.docx(42页珍藏版)》请在冰豆网上搜索。
ThedocumentrepresentsthestateofAPIatthetimeofwriting.ItispossiblethatsomeaspectsoftheAPIwillslightlychangeuntilfinalrelease.Weanticipateonlymechanicalnamechangesratherthanmorefundamentalchanges.
Problemdefinition
WhenEclipseplatformwasdesigned,thereweretwodistinctcontextinwhichSWTwidgetscouldappear:
∙Intraditionaldialogs(messageboxes,dialogs,wizards,preferencepages,propertypages)
∙Incontentareas(viewsandeditors)
ControlsindialogstypicallyuseddefaultcolorsandfontsasprovidedbytheoperatingsystemandwerelayedoutusingGridLayoutin9outof10cases.Thegoalwastolooklikeadialogandfillthedialogspaceinbothdirections.
Controlsinviewsandeditorswere'
stretchy'
i.e.theyfilledtheentirecontentarea.Stretchycontrolscanscrolltheircontent(trees,tables,textareas,listsetc.).Thecolorsandfontsusedherewerethoseprovidedbythesystemforuseincontentarea(thesecolorscanbeobtainedfromtheDisplayusingSWT.LIST_BACKGROUNDorSWT.LIST_FOREGROUNDkeys).
Whatwasmissingwasthethirdoptionwherewidgetsyouwouldnormallyseeinthedialogcontextarecreatedinviewsoreditors(whereyouwouldexpect'
controls).Severalproblemsneededtobesolved:
1.SWTcontrolslikebuttons,labels,compositesetc.lookstrangeinthecontentareasas-is(withthedefaultdialogbackground)
2.CompositeswithGridLayoutinthecontentareaareproblematicbecausetheyarenotscrolled.Therefore,itiseasytogetthecontrolstocliporstartridingoneanother.
3.Controlsinthecontentareaarenormallywrappedtofilltheprovidedwidth.WrappingisveryhardtoaccomplishwiththeexistingSWTlayouts.
4.Whenproblems1-3arefixed,theresultlooksverymuchlikeformsinHTMLbrowsers,andanaturalleapistoaddhyperlinksandmixthemwithothercontrols.
EclipseFormsweredesignedtosolvetheseproblems.Theyprovide:
1.Aconceptofa'
form'
thatissuitableforinclusionintothecontentarea(editororview)
2.Atoolkitthatmanagescolors,hyperlinkgroupsandotheraspectsoftheform,aswellasserveasafactoryforanumberofSWTcontrols(thesecontrolsarecreatedandconfiguredtofitintotheformcontext)
3.AnewlayoutmanagerthatlaysoutcontrolsusingthealgorithmsimilartoHTMLtables
4.Customcontrolsdesignedtofitintotheform(hyperlink,imagehyperlink,scrollablecomposite,section).
5.Multi-pageeditorwhereeachpageisaform(asinPDE).
Setup
InordertobeabletouseEclipseForms,allyouneedtodoisadd'
org.eclipse.ui.forms'
plug-intoyourlistofrequiredplug-ins.Thisplug-insisRCP-friendlyinthatitdoesnothavedependencyonIDEplug-ins(itsonlydependencyisorg.eclipse.ui).
Examples
SourcecodeformostoftheexamplesshowninthisdocumentcanbefoundinEclipserepository(HEAD)asorg.eclipse.ui.forms.examples.Checkthemoutintotheworkspaceandlookinsidethe'
src'
directoryinaJavaorPDEperspective.
APIpackages
EclipseFormshasthefollowingpublic(API)packages:
∙org.eclipse.ui.forms-themainpackage
∙org.eclipse.ui.forms.editor-classesthatemployEclipseFormsontopoftheMultiPageEditorParttocreatemulti-pageeditorsasseeninPDE
∙org.eclipse.ui.forms.events-neweventscreatedtosupportcustomwidgets
∙org.eclipse.ui.forms.widgets-asetofcustomwidgetsandlayoutscreatedspecificallyforEclipseForms
GettingStarted
WewillstartplayingwithEclipseFormsbycreatinganemptyforminaview.Aswesaidabove,viewsarecontentareasthatrequireflexiblecontent.Hereisthecodesample:
packageorg.eclipse.ui.forms.examples.views;
importorg.eclipse.swt.widgets.Composite;
importorg.eclipse.ui.forms.widgets.*;
importorg.eclipse.ui.part.ViewPart;
publicclassFormViewextendsViewPart{
privateFormToolkittoolkit;
privateScrolledFormform;
/**
*Thisisacallbackthatwillallowus
*tocreatetheviewerandinitializeit.
*/
publicvoidcreatePartControl(Compositeparent){
toolkit=newFormToolkit(parent.getDisplay());
form=toolkit.createForm(parent);
form.setText("
Hello,EclipseForms"
);
}
*Passingthefocusrequesttotheform.
publicvoidsetFocus(){
form.setFocus();
*Disposesthetoolkit.
publicvoiddispose(){
toolkit.dispose();
super.dispose();
}
/***
Disposesthetoolkit.
*/
public
void
dispose(){toolkit.dispose();
}}
org.eclipse.ui.forms.examples.views;
import
org.eclipse.swt.widgets.Composite;
org.eclipse.ui.forms.widgets.*;
org.eclipse.ui.part.ViewPart;
Inthesnippetabove,wehavecreatedaviewbycreatinganinstanceofatoolkitfirst.Wethenusedthetoolkittocreateaform.Wesetthetitleoftheform.Itisimportantnottoforgetthattoolkitmanagesresourcesthatneedtobedisposedof(hencethe
dispose
method).
Whenweregisterthisviewwiththeworkbenchandrun,wegetthefollowing:
Theformwejustcreateddoesthefollowingthings:
∙Itrendersthetitlewesetusing
setText
∙Itcanrenderabackgroundimagebehindthetitle
∙Thetitlewillwrapifthereisnospacetoshowitononeline
∙Theformwillintroducescrollbarsifthecontentcannotbeshownintheprovidedspace
Thelastiteminthelistneedssomeclarification.Insomeinstances,youwillwanttomaketheformbeachildofamorecomplexlayoutthatisitselfcapableofscrolling.Inthatcase,youmaywanttogetallthecapabilitiesofaform,butwithoutscrolling.Inthatcaseyouwouldusetheclass
Form
insteadof
ScrolledForm
(infact,
has-a
asaninternalobjectanddelegatesmostofthemethodslike
setText
toit).
Addingcontent
Nowthatwehavetheformviewrunning,wecanstartaddingsomecontenttoit.Eclipseformshaveabodyandallthecontentshouldbecreatedthere:
toolkit=newFormToolkit(parent.getDisplay());
form=toolkit.createForm(parent);
form.setText("
GridLayoutlayout=newGridLayout();
form.getBody().setLayout(layout);
Hyperlinklink=toolkit.createHyperlink(form.getBody(),"
Clickhere."
SWT.WRAP);
link.addHyperlinkListener(newHyperlinkAdapter(){
publicvoidlinkActivated(HyperlinkEvente){
System.out.println("
Linkactivated!
"
}
});
Noticethatwefirstsetlayoutonthebody,thenusedthebodyasaparenttocreateahyperlink.HyperlinkcontrolisoneofthecustomwidgetsinEclipseFormsandactslikealabelthatisclickable.Anewtypeoflistener(HyperlinkListener),itsdefaultimplementation(HyperlinkAdapter)andtheeventypearealldefinedinEclipseFormstosupportthehyperlink.HandlingeventsofthehyperlinkareverysimilartootherSWTwidgets,asshowninthecodeabove.Ourviewnowlookslikethis:
Notehowhyperlinkhasfocusrectanglepaintedaroundit.Whentheviewisactivated,focusistransferredtotheform,whichpassesittothefirstcontrolcapableofacceptingfocus,ourlinkinthiscase.
HyperlinkGroups
Formtoolkithashyperlinkgroupthateachhyperlinkcreatedbyitisaddedto.Hyperlinkgroupsserveseveralroles:
∙Theycapturecolors(bothnormal,hoverandactive)forall
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Eclipse Forms Programming Guide