Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Code Generation
Code Generation [message #60718] Thu, 23 September 2004 22:00 Go to next message
Eclipse UserFriend
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 #60720 is a reply to message #60718] Fri, 24 September 2004 09:32 Go to previous messageGo to next message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Stefan,


> 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:

Could you please rewrite by hand the generated code you included, but in
the way you'd like to see it have been created by the VE ?

Best regards,

Joe Winchester
Re: Code Generation [message #60725 is a reply to message #60720] Fri, 24 September 2004 14:45 Go to previous messageGo to next message
Eclipse UserFriend
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 #61330 is a reply to message #60725] Mon, 27 September 2004 10:26 Go to previous messageGo to next message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Stefan,

Thanks very much for your code examples. 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. One of
the things we also want to do is allow factory style generation where
the same method can be used multiple times which often occurs in SWT
where you have something like

private Button createButton(Composite parent, String text);

that creates the Button and sets its text and creates the correct
GridData constraint.

I'll check with the VE developers who are more knowledgeable in code gen
than me whether or not what you want with the style switch to do can be
done easily.

Best regards,

Joe
Re: Code Generation [message #61516 is a reply to message #61330] Mon, 27 September 2004 13:54 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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.
Re: Code Generation [message #599115 is a reply to message #60718] Fri, 24 September 2004 09:32 Go to previous message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Stefan,


> 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:

Could you please rewrite by hand the generated code you included, but in
the way you'd like to see it have been created by the VE ?

Best regards,

Joe Winchester
Re: Code Generation [message #599155 is a reply to message #60720] Fri, 24 September 2004 14:45 Go to previous message
Stefan Baramov is currently offline Stefan BaramovFriend
Messages: 33
Registered: July 2009
Member
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 #599577 is a reply to message #60725] Mon, 27 September 2004 10:26 Go to previous message
Joe Winchester is currently offline Joe WinchesterFriend
Messages: 496
Registered: July 2009
Senior Member
Hi Stefan,

Thanks very much for your code examples. 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. One of
the things we also want to do is allow factory style generation where
the same method can be used multiple times which often occurs in SWT
where you have something like

private Button createButton(Composite parent, String text);

that creates the Button and sets its text and creates the correct
GridData constraint.

I'll check with the VE developers who are more knowledgeable in code gen
than me whether or not what you want with the style switch to do can be
done easily.

Best regards,

Joe
Re: Code Generation [message #599637 is a reply to message #61330] Mon, 27 September 2004 13:54 Go to previous message
Stefan Baramov is currently offline Stefan BaramovFriend
Messages: 33
Registered: July 2009
Member
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 #599904 is a reply to message #61516] Tue, 28 September 2004 16:24 Go to previous message
Gili Mendel is currently offline Gili MendelFriend
Messages: 338
Registered: July 2009
Senior Member
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.
Previous Topic:Renaming is a waste of time
Next Topic:VE and SWT
Goto Forum:
  


Current Time: Sat Sep 28 00:36:21 GMT 2024

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

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

Back to the top