Tải bản đầy đủ - 0 (trang)
Chapter 2. A Simple Plug-in Example

Chapter 2. A Simple Plug-in Example

Tải bản đầy đủ - 0trang

2.1.TheFavoritesPlug-in

TheFavoritesplug-in,whichyou'llbuildoverthecourseofthis

book,displaysalistofresources,letsyouaddandremove

resourcesfromthelist,easilyopensaneditoronaselected

resource,updatesthelistautomaticallyasaresultofevents

elsewhereinthesystem,andmore.Subsequentchapters

discussaspectsofcommercialplug-indevelopmentintermsof

enhancementstotheFavoritesplug-in.

Thischapterstartstheprocessbycoveringthecreationofthe

Favoritesplug-ininitssimplestformusingthefollowingsteps:

Creatingaplug-inproject

Reviewingthegeneratedcode

Buildingaproduct

Installingandrunningtheproduct



2.2.CreatingaPlug-inProject

Thefirststepistocreateaplug-inprojectusingtheEclipse

NewProjectwizard.Inadditiontocreatinganewproject,this

wizardhasanumberofdifferentcodegenerationoptions,such

asviews,editors,andactions,forcreatingsampleplug-incode.

Tokeepthingssimpleandfocusonlyontheessentialsofplugincreation,selectthePlug-inwithaviewoption,whichis

discussedinthenextsubsection.



2.2.1.NewPlug-inProjectwizard

FromtheFilemenu,selectNew>ProjecttolaunchtheNew

Projectwizard(seeFigure2-1).Onthisfirstpageofthe

wizard,selectPlug-inProjectfromthelistandthenclickthe

Nextbutton.



Figure2-1.NewProjectwizardpage1selectinga

projecttype.

TheEclipse3.1versionisshownontheleft,andtheEclipse3.2

versionisshownontheright.



[Viewfullsizeimage]



Onthenextpageofthewizard(seeFigure2-2),enterthe

nameoftheproject;inthiscase,it'scom.qualityeclipse.favorites,

whichisthesameastheFavoritesplug-inidentifier.Chapter3,

EclipseInfrastructure,discussesplug-inidentifiersandother

aspectsofplug-inarchitectureinmoredetail.Fillintheother

fieldsasshownandthenclicktheNextbutton.



Figure2-2.NewProjectwizardpage2namingthe

project.

TheEclipse3.1versionisshownontheleftandtheEclipse3.2

versionisshownontheright.Notetheminordifferencesin

optionsavailableinthelowersectionofthepage.



[Viewfullsizeimage]



Tip

Aprojectcanbenamedanything,butitiseasierto

nameitthesameastheplug-inidentifier.By

convention,thisistheplug-inproject-naming

schemethattheEclipseorganizationusesformost

ofitswork.Becauseofthis,theNewProjectwizard

assumesthattheprojectnameandtheplug-in

identifierarethesame.



2.2.2.Definetheplug-in

Everyplug-inhasaMETA-INF/MANIFEST.MFfile.Inaddition,itmay

containaplugin.xmlfileand/oraJavaclassthatrepresentsthe

plug-inprogrammatically.Thenextwizardpagedisplaysoptions



forgeneratingboththeplug-inmanifestandplug-inJavaclass.

SupplythePlug-inID,Plug-inVersion,Plug-inNameand

morefortheplug-inasshowninFigure2-3thenclicktheNext

button.



Figure2-3.NewProjectwizardpage3describing

theplug-in.

TheEclipse3.1versionisshownontheleft,andtheEclipse3.2

versionisshownontheright.Notetheminordifferencesin

terminologyinthecentersectionofthepage.



[Viewfullsizeimage]



Next,theNewPlug-inProjectwizardnextdisplaysthe

variousplug-inpiecesthatcanbeautomaticallygeneratedby

thewizard(seeFigure2-4).Therearemanydifferentoptions

onthispageforgeneratingquiteabitofsamplecode.Itis

usefultotryouteachoptionandreviewthecodethatis

generated;howeverforthisexample,selectPlug-inwitha



viewandthenclicktheNextbutton.



Figure2-4.NewPlug-inProjectwizardpage

4selectingaplug-intype.



2.2.3.Definetheview

Selectingviewcodegenerationoptionsisthenextstepinthis

process.Enterthevaluesforthispage(seeFigure2-5),

unchecktheAddtheviewtotheresourceperspective



checkboxtosimplifythegeneratedplug-inmanifestfileand

clicktheNextbutton.



Figure2-5.NewPlug-inProjectwizardpage

5definingtheview.



Finally,uncheckeachofthecodegenerationoptionsonthelast

wizardpage(seeFigure2-6).Eachofthesecheckboxes

representscodethatcouldbegeneratedaspartofthe

Favoritesview.Thesearecoveredinsubsequentchapters.

WhenyouclicktheFinishbutton,thenewplug-inprojectis

createdandtheplug-inmanifesteditorisautomaticallyopened



(seeFigure2-9).



Figure2-6.NewPlug-inProjectwizardpage

6codegenerationoptionsfortheview.







2.3.ReviewingtheGeneratedCode

ReviewingthecodegeneratedbytheNewPlug-inProject

wizardprovidesabrieflookatthefollowingmajorparts

comprisingthesampleplug-in.

Theplug-inmanifests

Theplug-inclass

TheFavoritesview



2.3.1.ThePlug-inmanifests

Theplug-inmanifesteditorshowsthecontentsofthetwopluginmanifestfiles,META-INF/MANIFEST.MFandplugin.xml,whichdefine

howthisplug-inrelatestoalltheothersinthesystem.This

editorisautomaticallyopenedtoitsfirstpage(seeFigure2-9)

asaresultofcreatinganewplug-inproject.Iftheplug-in

manifesteditorisclosed,double-clickingoneithertheMETAINF/MANIFEST.MFortheplugin.xmlfilereopenstheeditor.The

followingisanoverviewofthemanifesteditor,whilemore

detailontheplug-inmanifestitselfcanbefoundinChapter3.

Althoughtheeditorisaconvenientwaytomodifytheplug-in's

description,it'sstillusefultopeekatthesourcebehindthe

scenestoseehowtheeditor'sdifferentpartsrelatetothe

underlyingcode.ClicktheMANIFEST.MFtabtodisplaythe

sourceoftheMETA-INF/MANIFEST.MFfilethatdefinestheruntime

aspectsofthisplug-in(seeFigure2-7).Thefirsttwolines

defineitasanOSGimanifestfile(seeSection3.3,Plug-in

Manifest,onpage107).Subsequentlinesspecifyplug-inname,

version,identifier,classpath,andplug-insonwhichthisplug-in



depends.Alltheseaspectsareeditableusingotherpagesinthe

plug-inmanifesteditor.



Figure2-7.Plug-inmanifesteditorMANIFEST.MF

page.



[Viewfullsizeimage]



NewinEclipse3.2

TheEclipse-AutoStart:truedirectiveintheMANIFEST.MF

filehasbeenreplacedwithEclipse-LazyStart:true.

Bothdirectiveshavethesamesemantics;onlythe

namehaschanged.



Clickingontheplugin.xmltaboftheeditordisplaysthe

plugin.xmlfilethatdefinestheextensionaspectsofthisplug-in

(seeFigure2-8).ThefirstlinedeclaresthistobeanXMLfile,

whilesubsequentlinesspecifyplug-inextensions.



Figure2-8.Plug-inmanifesteditorplugin.xml

page.



[Viewfullsizeimage]



TheOverviewpageofthemanifesteditorshowsasummaryof

theplug-inmanifest(seeFigure2-9).Thesectiononthispage

describinggeneralinformation,suchastheplug-inidentifier

(ID),version,name,class,andprovider,correspondstothe

firstchunkofsourceintheMETA-INF/MANIFEST.MFfile:



Bundle-Name:FavoritesPlug-in

Bundle-SymbolicName:com.qualityeclipse.favorites;singleton:=t

Bundle-Version:1.0.0

Bundle-Activator:com.qualityeclipse.favorites.FavoritesPlugin

Bundle-Vendor:QualityEclipse



Figure2-9.Plug-inmanifesteditorOverview



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 2. A Simple Plug-in Example

Tải bản đầy đủ ngay(0 tr)

×