Eclipse Forms Programming Guide.docx

上传人:b****5 文档编号:7921672 上传时间:2023-01-27 格式:DOCX 页数:42 大小:569.95KB
下载 相关 举报
Eclipse Forms Programming Guide.docx_第1页
第1页 / 共42页
Eclipse Forms Programming Guide.docx_第2页
第2页 / 共42页
Eclipse Forms Programming Guide.docx_第3页
第3页 / 共42页
Eclipse Forms Programming Guide.docx_第4页
第4页 / 共42页
Eclipse Forms Programming Guide.docx_第5页
第5页 / 共42页
点击查看更多>>
下载资源
资源描述

Eclipse Forms Programming Guide.docx

《Eclipse Forms Programming Guide.docx》由会员分享,可在线阅读,更多相关《Eclipse Forms Programming Guide.docx(42页珍藏版)》请在冰豆网上搜索。

Eclipse Forms Programming Guide.docx

EclipseFormsProgrammingGuide

EclipseFormsProgrammingGuide 

Initialcreation:

21February2004

Addedtablewrapsample:

22February2004

Introduction

ThisdocumenthasbeenwrittentohelpyouusethenewEclipse3.0featurecalled'EclipseForms'.ThecontentwilleventuallymovetoEclipsehelp.Inthemeantime,youcanstartexperimentingusingexamplesshownbelowandcodeinEclipse3.0integrationbuilds.

EclipseFormsisaplug-inthatexposesasetofcustomswidgetsandothersupportingclassesthatwerebeforeusedasinternaltoPDEandUpdatecomponents.Theyprovideforcreatingpolished,'Web-like'UIsbymodestlyextendingSWTand/ormanipulatingstylebits,colors,fontsandotherpropertiesinordertogetthedesiredbehavior.ThistechnologywasusedthroughoutPDEmulti-pageeditorsandwillnowbeavailableaspublicAPIinEclipse3.0.

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'stretchy'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();

}

/**

*Thisisacallbackthatwillallowus

*tocreatetheviewerandinitializeit.

*/

publicvoidcreatePartControl(Compositeparent){

toolkit=newFormToolkit(parent.getDisplay());

form=toolkit.createForm(parent);

form.setText("Hello,EclipseForms");

}

/**

*Passingthefocusrequesttotheform.

*/

publicvoidsetFocus(){

form.setFocus();

}

/**

*Passingthefocusrequesttotheform.

*/

publicvoidsetFocus(){

form.setFocus();

}

/**

*Disposesthetoolkit.

*/

publicvoiddispose(){

toolkit.dispose();

super.dispose();

}

}

/*** Disposesthetoolkit. */ 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;

publicclassFormViewextendsViewPart{

privateFormToolkittoolkit;

privateScrolledFormform;

/**

*Thisisacallbackthatwillallowus

*tocreatetheviewerandinitializeit.

*/

publicvoidcreatePartControl(Compositeparent){

toolkit=newFormToolkit(parent.getDisplay());

form=toolkit.createForm(parent);

form.setText("Hello,EclipseForms");

}

/**

*Passingthefocusrequesttotheform.

*/

publicvoidsetFocus(){

form.setFocus();

}

/**

*Thisisacallbackthatwillallowus

*tocreatetheviewerandinitializeit.

*/

publicvoidcreatePartControl(Compositeparent){

toolkit=newFormToolkit(parent.getDisplay());

form=toolkit.createForm(parent);

form.setText("Hello,EclipseForms");

}

/**

*Passingthefocusrequesttotheform.

*/

publicvoidsetFocus(){

form.setFocus();

}

/**

*Passingthefocusrequesttotheform.

*/

publicvoidsetFocus(){

form.setFocus();

}

/**

*Disposesthetoolkit.

*/

publicvoiddispose(){

toolkit.dispose();

super.dispose();

}

}

/*** Disposesthetoolkit. */ public void dispose(){toolkit.dispose();super.dispose();}}

 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, ScrolledForm has-a Form asaninternalobjectanddelegatesmostofthemethodslike setText toit).

Addingcontent

Nowthatwehavetheformviewrunning,wecanstartaddingsomecontenttoit.Eclipseformshaveabodyandallthecontentshouldbecreatedthere:

publicvoidcreatePartControl(Compositeparent){

toolkit=newFormToolkit(parent.getDisplay());

form=toolkit.createForm(parent);

form.setText("Hello,EclipseForms");

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模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1