Bug 232924 - [templates] SWT templates should fill in string variable
Summary: [templates] SWT templates should fill in string variable
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-20 05:28 EDT by Dani Megert CLA
Modified: 2016-02-09 04:42 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2008-05-20 05:28:08 EDT
3.4 RC1.

SWT templates that e.g. set a text (Button.setText()) are not filling in a string variable but leave the input empty.

E.g. having:
    String text= "aklsdjaks";
    Button<code assist>

should insert setText(text).
Comment 1 Dani Megert CLA 2008-05-20 05:28:43 EDT
Would probably be easy to fix. If so, we should consider doing this for RC2.
Comment 2 Benno Baumgartner CLA 2008-05-20 06:16:54 EDT
I would close this as wontfix. I'm using the ${word_selection} variable. This allows to select something like:

"Press Me" 

and then invoke the Button template, resulting in:

Button button = new Button(parent, SWT.PUSH);
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
		false));
button.setText("Press Me");

IMHO this is the 80% case. Using a variable for the string is not the common code pattern. The common case is using a string literal and then maybe later extract to local or more likely externalize string. Of course I have no prove for this statement, but it sounds reasonable.

What we could do is improve the word_selection variable to something like

${word_selection(java.lang.String})

where a variable of type String is resolved in the context only if word_selection is empty. But that's not an easy fix and not for 3.4 and does not make the template variable stuff easier to use.
Comment 3 Dani Megert CLA 2008-05-20 06:20:51 EDT
>IMHO this is the 80% case.
I disagree. The 80% case is: type some prefix + code assist.
Comment 4 Dani Megert CLA 2008-05-20 06:24:09 EDT
Since we don't agree on a common solution, I agree to not investigate further at this point. But disagree to 'wontfix'.
Comment 5 Benno Baumgartner CLA 2008-05-20 06:31:03 EDT
(In reply to comment #3)
> >IMHO this is the 80% case.
> I disagree. The 80% case is: type some prefix + code assist.

Ok, agreed. But in 80% of this cases you don't want a string variable to be filled into setText() but type in a string literal. 
Comment 6 Dani Megert CLA 2008-05-20 06:42:43 EDT
>But in 80% of this cases you don't want a string variable to be
>filled into setText() but type in a string literal. 
Recently when I used the SWT templates I used them in existing code where the strings were already there as vars. But agree that this is less common than start from scratch. Your proposal from comment 2 sounds interesting.
Comment 7 Lars Vogel CLA 2016-02-09 04:42:59 EST
A similar solution, but not the same is handled by Bug 486903, which will allow to define defaults in the template.