Code Generation [message #60718] |
Thu, 23 September 2004 22:00 |
Eclipse User |
|
|
|
Originally posted by: stefan.baramov.trx.com
I am happy to see a support for SWT from the latest VE 1.0. However, I am
kind of disappointed with the generated code. For example:
private void createComposite() {
GridData gridData3 = new GridData();
GridData gridData2 = new GridData();
GridLayout gridLayout1 = new GridLayout();
composite = new Composite(sShell, SWT.NONE);
label = new Label(composite, SWT.NONE);
text = new Text(composite, SWT.BORDER);
button = new Button(composite, SWT.NONE);
createComposite1();
composite.setLayout(gridLayout1); // Generated
gridLayout1.numColumns = 3; // Generated
label.setText("Project :"); // Generated
label.setLayoutData(gridData3); // Generated
button.setText("Browse..."); // Generated
gridData2.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL; //
Generated
gridData2.grabExcessHorizontalSpace = true; // Generated
text.setLayoutData(gridData2); // Generated
gridData3.horizontalAlignment = org.eclipse.swt.layout.GridData.END; //
Generated
}
It is difficult to read and understand. This is not the case when the
generated code is Swing.
So are there any plans to imporve the code generation for SWT? If there are
any, then when ? May be VE 1.1 ?
Thanks,
Stefan
|
|
|
|
Re: Code Generation [message #60725 is a reply to message #60720] |
Fri, 24 September 2004 14:45 |
Eclipse User |
|
|
|
Originally posted by: stefan.baramov.trx.com
Here is an example how to code could look like:
private void createComposite() {
composite = new Composite(sShell, SWT.NONE);
// layout data
GridLayout gridLayout1 = new GridLayout();
gridLayout1.numColumns = 3;
composite.setLayout(gridLayout1);
// elements
createLabel(composite);
createText(composite);
createButton(composite);
}
private void createLabel(Composite parent) {
label = new Label(composite, SWT.NONE);
label.setText("Project :"); // Generated
// layout data
GridData gridData = new GridData();
gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.END;
label.setLayoutData(gridData);
}
private void createText(Composite parent) {
text = new Text(composite, SWT.BORDER);
// layout data
GridData gridData2 = new GridData();
gridData2.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData2.grabExcessHorizontalSpace = true;
text.setLayoutData(gridData2);
}
private void createButton(Composite parent) {
button = new Button(composite, SWT.NONE);
button.setText("Browse...");
}
Note: this is the same pattern used by the Swing version of the VE. All I am
saying is if the Swing VE can generate a good looking code, why can't the
SWT VE generate a good looking code?
- Stefan
|
|
|
|
Re: Code Generation [message #61516 is a reply to message #61330] |
Mon, 27 September 2004 13:54 |
Eclipse User |
|
|
|
Originally posted by: stefan.baramov.trx.com
Joe Winchester wrote:
> We did at one point generate
> SWT code the way you describe with lots of methods, however we then
> steered away from it and settled on the one where each composite has a
> method. This is controlled by a flag that unfortunately isn't public,
> although one of the things we want to work on it to open up the whole
> API for code generation with user configurable styles and also ones
> where plugin developers can customize the VE code generation.
Apperantly, if I refactor my code in the desire pattern the VE still
reconginize it and allows me to edit it. Works for me !
- Stefan
|
|
|
Re: Code Generation [message #62344 is a reply to message #61516] |
Tue, 28 September 2004 16:24 |
Eclipse User |
|
|
|
Originally posted by: mendelgili.netscape.net
Stefan Baramov wrote:
> Joe Winchester wrote:
>
>> We did at one point generate SWT code the way you describe with lots
>> of methods, however we then steered away from it and settled on the
>> one where each composite has a method. This is controlled by a flag
>> that unfortunately isn't public, although one of the things we want to
>> work on it to open up the whole API for code generation with user
>> configurable styles and also ones where plugin developers can
>> customize the VE code generation.
>
>
> Apperantly, if I refactor my code in the desire pattern the VE still
> reconginize it and allows me to edit it. Works for me !
>
> - Stefan
There are two levels to the code pattern you suggested:
1. a separate create method for each visual component (similar to the getter Swing version)
VE can generate/reverse parse these methods as long as the method initializes/create a
(single) instance. At this point for SWT, the default behavior
is to create a separate method for composites only - we can provide a pref. support to override this.
However, the pattern that is mostly used with SWT is a factory method that mostly is called once
(but not always). This method contains the initialization for all the "root" components.
Our goal is to support factory methods.
2. Better grouping of expressions within a method
VE uses a rough weight base dependency rule when it determines where to insert a new expression...
We can definitly do a better job there.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04478 seconds