[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools.emf] Re: use EMF model from GEF
|
Nikolaj,
You don't actually need to use adapters if all you want is to access the model
objects directly. The adapters are used to support standard viewer APIs.
Once you've aquired the ResourceSet, you can get your Candy resource like this:
ResourceSet foo = ...
Resource candyResource = (Resource)foo.getResources().get(0);
From the resource, you can access your candy box like this:
CandyBox candyBox = (CandyBox)candyResource.getContents().get(0);
Now you can access the candy like this:
for (Iterator iter = candyBox.getCandy().iterator(); iter.hasNext(); ) {
Candy candy = (Candy)iter.next();
...
}
I hope this helps.
Frank.
Nikolaj Berntsen wrote:
> Frank (or any other EMF-gifted person),
>
> > You can access the model from the EditingDomain returned by
> > getEditingDomain() of the generated editor. The EditingDomain is the central
> > holder of the model for an Editor. The model objects are retrieved by
> > calling getResourceSet() on it. After that you can get the children,
> > properties, etc., by calling adapt() on the editors adapter factory, using
> > the appropriate adapter type.
>
> Can you be a bit more explicit (until your book [1] arrives .-).
>
> Say I have (in package foo.model)
>
> ---- Candybox.java
> /** @model */
> interface CandyBox extends EObject {
> /** @model type="Candy" containment="true"*/
> EList getCandy()
> }
>
> --- Candy.java
> /** @model */
> interface Candy extends EObject {
> /** @model */
> String getType();
> }
>
> I have used the generated Editor to create the following XML file (in
> meta notation)
> <CandyBox>
> <Candy type="sugar bomb"/>
> <Candy type="wine gum"/>
> </CandyBox>
>
> Now, in the generated Editor, I write
>
> ResourceSet foo = getEditingDomain().getResourceSet();
> /* Now I imagine I should interpret your answer to tell me to */
> Adapter bar = adapterFactory.adapt(XXX,YYY); /* adapterFactory is a
>
> generated variable */
> CandyBox goo = bar.ZZZ();
> Candy moo = bar.XYZ();
>
> Please tell me if I am out in the woods. Any hints to what XXX,YYY, ZZZ
> and XYZ might be would be much appreciated?
>
> XXX I could imagine to be, say, CandyBoxImpl, but that is not visible
> from the editor.
> YYY I could imagine to be ModelItemProviderAdapterFactory.java
> (generated, in .edit)
> XYZ I could imagine to be getChild (perhaps with another YYY, than
> proposed here).
>
> Thanks,
> /\/ikolaj
>
> [1]
> > I realize that this is a shameless plug, but if you're having trouble
> > getting your head around all of the framework pieces, our EMF book,
> > http://www.awprofessional.com/titles/0131425420 , is the best resource.