Skip to main content



      Home
Home » Archived » Visual Editor (VE) » Create SWT Widget in Containment Handler of parent Composite
Create SWT Widget in Containment Handler of parent Composite [message #613628] Sun, 30 July 2006 10:30
Eclipse UserFriend
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
Previous Topic:Setting the Alignment of Labels
Next Topic:JVE log
Goto Forum:
  


Current Time: Sat Jun 21 17:40:02 EDT 2025

Powered by FUDForum. Page generated in 0.05650 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top