Create SWT Widget in Containment Handler of parent Composite [message #129337] |
Sun, 30 July 2006 10:30  |
Eclipse User |
|
|
|
Is it possible to create SWT Widgets in Containment handler of parent
Composite? For example, I want to create buttons when my custom
Composite is dropped from palette and want to have the result like:
private MyComposite myComposite = null;
private Button button1 = null;
private Button button2 = null;
private Button button3 = null;
private void initialize() {
createMyComposite();
}
private void createMyComposite() {
GridLayout gridLayout1 = new GridLayout();
gridLayout1.numColumns = 3;
myComposite = new MyComposite(this, SWT.NONE);
myComposite.setLayout(gridLayout1);
button1 = new Button(myComposite, SWT.NONE);
button1.setText("Button 1");
button2 = new Button(myComposite, SWT.NONE);
button2.setText("Button 2");
button3 = new Button(myComposite, SWT.NONE);
button3.setText("Button 3");
}
I could have IJavaInstance and assigned to "data" with following code
PTClassInstanceCreation classInstanceCreation = InstantiationFactory.eINSTANCE.createPTClassInstanceCreation () ;
classInstanceCreation.setType("org.eclipse.swt.widgets.Button ");
PTInstanceReference parentReference = InstantiationFactory.eINSTANCE.createPTInstanceReference(mod el) ;
classInstanceCreation.getArguments().add(parentReference);
PTName SWTType = InstantiationFactory.eINSTANCE.createPTName("org.eclipse.swt.SWT ");
PTFieldAccess fieldAccess = InstantiationFactory.eINSTANCE.createPTFieldAccess(SWTType, "NONE");
classInstanceCreation.getArguments().add(fieldAccess) ;
JavaAllocation alloc = InstantiationFactory.eINSTANCE.createParseTreeAllocation(cla ssInstanceCreation);
JavaHelpers boxLayoutJavaClass = JavaRefFactory.eINSTANCE.reflectType("org.eclipse.swt.SWT", resourceSet);
IJavaInstance jo = BeanUtilities.createJavaObject(boxLayoutJavaClass, resourceSet, alloc);
EStructuralFeature structuredFeature = model.eClass().getEStructuralFeature("data");
commandBuilder.applyAttributeSetting(model, structuredFeature, jo);
it generates
myComposite.setData(new Button(myComposite, SWT.NONE));
but I want to add buttons as separate fields and do not need to set them as
the data of MyComposite (data can contain only one Button anyway).
Apparently, it seems that I should give unique field names to buttons and
append them to parent Composite. I would like to know how (or if) I can
accomplish this from the containment handler of MyComposite. Thank you.
Tami
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04359 seconds