How to create new control object on context menu. [message #143996] |
Wed, 12 March 2008 08:20 |
Eclipse User |
|
|
|
Originally posted by: bran.mm.xxxxx.xx.xx
Hi all.
I'm trying to create new awt.Button object on context menu.
I've added the "add Button" to the menu.(I refered other contribution)
And,I made MyAddButtonActionDelegate(based IObjectActionDelegate).
but, I can't create new awt.Button object.
A cause is CommandInstance was UnExecutableCommand...
I read "Extending The Visual Editor", but deeper info was not there.
Please give me some advice.
This is my code.( MyAddButtonActionDelegate#run())
--
EditPart targetEp = (EditPart)selectedEditParts.get( 0 );
JavaObjectInstance targetObj = (JavaObjectInstance)targetEp.getModel();
Rectangle rect = new Rectangle(0,0,30,30);
CreateRequest cReq = new CreateRequest();
EClass eBtnCls = EcoreFactory.eINSTANCE.createEClass();
eBtnCls.setInstanceClass(Button.class);
eBtnCls.setAbstract(false);
eBtnCls.setInterfase(false);
eBtnCls.setName("sampleBtn");
CreationFactory cFct = new EMFCreationFactory( eBtnCls );
cReq.setFactory(cFct);
cReq.setLocation(rect.getLocation());
cReq.setSize(rect.getSize());
Command cmd = targetEp.getCommand(cReq); // UnexecutableCommand...
EditDomain ed = targetEp.getViewer().getEditDomain();
ed.getCommandStack().execute(cmd);
|
|
|
Powered by
FUDForum. Page generated in 0.02310 seconds