Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Eclipse Integration (How to initialize an element)

1 view
Skip to first unread message

Dave Couture

unread,
Jan 31, 2007, 9:47:14 PM1/31/07
to
I try to initialize a modeling element using an Eclipse' plugin. In my
exemple, I try to add a Operation with a predefined stereotype to an
existing Class. This action is triggered using a pop-up menu (menu item
Initialize).

My problem is that I'm not able to create a new Operation and add it to the
Class. The Factory requires an EClass for the Create method and an EDataType
for the CreateFromStringMethod.

private void initialiserElement() {


if (this._structuredSelection.size() == 1) {


Object selectedObject = this._structuredSelection.getFirstElement();
EObject selectedEObject =
(EObject)Platform.getAdapterManager().getAdapter(selectedObject,
EObject.class);


if (selectedEObject instanceof
com.borland.tg.emfapi.uml20.classes.Class) {


com.borland.tg.emfapi.uml20.classes.Class classe =
(com.borland.tg.emfapi.uml20.classes.Class)selectedEObject;
com.borland.tg.emfapi.uml20.Uml20Factory factory =
com.borland.tg.emfapi.uml20.Uml20Factory.REGISTRY.getFactory(classe.getIProject(),
classe.getSession());


// don't know what to do with the factory...

}
}
}

Can anyone help?


ElenaA

unread,
Feb 2, 2007, 3:41:00 AM2/2/07
to
try the following:

KernelFactory kFactory =
KernelFactory.REGISTRY.getFactory(classe.getIProject(),
classe.getSession());

TogetherFactory tgFactory =
TogetherFactory.REGISTRY.getFactory(classe.getIProject(),
classe.getSession());

FeaturesFactory fFactory =
FeaturesFactory.REGISTRY.getFactory(classe.getIProject(),
classe.getSession());

PrimitiveTypesRoot tRoot = tgFactory.createPrimitiveTypesRoot();

//create return parameter for operation

Parameter param = kFactory.createParameter();

param.setName("param");

param.setType(tRoot.getPrimitiveType(PrimitiveTypeEnum.get("STRING")));

//create operation

Operation opp = fFactory.createOperation();

opp.setName("myOperation");

opp.setReturnResult(param);

opp.setPropertyValue("stereotype", "bla_bla_bla");

//add this new operation to our class

classe.getFeatures().add(opp);

"Dave Couture" <dave_c...@dmr.ca> wrote in message
news:45c15479$1...@newsgroups.borland.com...

Dave Couture

unread,
Feb 2, 2007, 8:35:33 AM2/2/07
to
Cool! It is working!

By the way, it is very complicated. I've to develop a plugin that initialize
diagram based on the Fujitsu's Macroscope development method stereotype.
Hard time to come...

Thanks,

Dave

"ElenaA" <Elena.A...@borland.com> a écrit dans le message de news:
45c2f8dd$1...@newsgroups.borland.com...

0 new messages