Bug 387272 - [templates] SWT templates - add SelectionListener
Summary: [templates] SWT templates - add SelectionListener
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday
Depends on:
Blocks:
 
Reported: 2012-08-15 06:45 EDT by Lars Vogel CLA
Modified: 2013-04-29 19:09 EDT (History)
4 users (show)

See Also:


Attachments
Template change for button (1.59 KB, patch)
2013-03-05 15:54 EST, Lars Vogel CLA
no flags Details | Diff
Text template change (1.58 KB, patch)
2013-03-05 16:05 EST, Lars Vogel CLA
no flags Details | Diff
Link template patch (1.04 KB, patch)
2013-03-05 16:18 EST, Lars Vogel CLA
no flags Details | Diff
Patch for the SWT templates (11.34 KB, patch)
2013-04-29 04:08 EDT, Lars Vogel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2012-08-15 06:45:35 EDT
The SWT Button template does not inluded a SelectionListener. I never use a Button without a SelectionListener. 

If you want, I can add this to the template and provide a patch.

If changing the template is not desired, please close this bug.
Comment 1 Dani Megert CLA 2012-08-20 10:23:29 EDT
(In reply to comment #0)
> The SWT Button template does not inluded a SelectionListener. I never use a
> Button without a SelectionListener. 

Makes sense.

 
> If you want, I can add this to the template and provide a patch.

That would be nice. Please go over the SWT templates and also add other things you think make sense, e.g. selection listener for 'Link' template.
Comment 2 Lars Vogel CLA 2012-10-10 11:19:21 EDT
I also see that the Text template uses SWT.LEAD. AFAIK SWT.LEAD is not used in Text. Ok to remove this?
Comment 3 Dani Megert CLA 2012-10-11 04:32:01 EDT
(In reply to comment #2)
> I also see that the Text template uses SWT.LEAD. AFAIK SWT.LEAD is not used
> in Text. Ok to remove this?

yes.
Comment 4 Lars Vogel CLA 2013-03-05 15:54:40 EST
Created attachment 227964 [details]
Template change for button

Attached the proposed template change for the button. It adds the selectionListener. It also puts quotes around the wordselection, as I think a word selection is rarely used and this avoids a syntax error after using the template.

If you ok with this change, I change Link and Text.
Comment 5 Lars Vogel CLA 2013-03-05 16:05:03 EST
Created attachment 227965 [details]
Text template change

Removes SWT.LEAD from Text and wraps word selection into "" to avoid syntax error if no word selection is done (standard case IMHO)
Comment 6 Lars Vogel CLA 2013-03-05 16:18:37 EST
Created attachment 227966 [details]
Link template patch

Link template patch
Comment 7 Lars Vogel CLA 2013-03-05 16:20:58 EST
If the change with the quotes around the wordselection is ok for you I adjust all other templates. If not let me know, I can change the patches.

These patches try to be in the spirit of Git really small and isolated, if you prefer one patch for everything also let me know.

I must say that the wordselection patch would make my life easier, as the templates would not create syntax errors anymore.
Comment 8 Lars Vogel CLA 2013-04-09 01:08:04 EDT
Any feedback on the patches? I'm particular found of the change that avoids the syntax error after using the template. If you agree with this change, I adjust the remaining templates.
Comment 9 Dani Megert CLA 2013-04-09 02:57:43 EDT
(In reply to comment #8)
> Any feedback on the patches? I'm particular found of the change that avoids
> the syntax error after using the template. If you agree with this change, I
> adjust the remaining templates.

Sorry, but we are currently very busy with other work. I'll try to look at it before M7, but no promise.
Comment 10 Lars Vogel CLA 2013-04-09 18:57:50 EDT
Thanks Dani, if it helps the patch is trivial and I would like to know if you agree with the change that avoids the syntax error because if you do, I would need to adjust the other templates.
Comment 11 Dani Megert CLA 2013-04-28 13:50:37 EDT
I like the change regarding the quotes. The link template change seems incomplete as it missed some of the required imports (SelectionEvent, SelectionAdapter).

NOTE: If I get new patches before Monday 18:00 CEST I will try to put it into 4.3, otherwise this will have to be deferred to 4.4.
Comment 12 Lars Vogel CLA 2013-04-28 14:05:00 EDT
Thanks for the feedback. I try to update all templates accordingly before this tied deadline. :-)
Comment 13 Dani Megert CLA 2013-04-29 02:57:53 EDT
Internal note: all tests pass with the 3 proposed patches.
Comment 14 Lars Vogel CLA 2013-04-29 03:59:06 EDT
TableColumn also only allows to use LEFT, RIGHT, CENTER according to its Javadoc. I included that also fix also in the patch.
Comment 15 Lars Vogel CLA 2013-04-29 03:59:46 EDT
Same for TreeColumn
Comment 16 Lars Vogel CLA 2013-04-29 04:08:32 EDT
Created attachment 230235 [details]
Patch for the SWT templates

Updated patch with avoids getting a syntax errors for all templates (usage of "") and adds selection listener to Link and Button. It also removes the usage of SWT.LEAD and SWT.TRAIL for Text, TableColumn and TreeColumn

I tested if this patch applies with EGit and it did for me based on commit 29b40ac, please let me know if you encounter any issues.
Comment 17 Lars Vogel CLA 2013-04-29 09:54:28 EDT
Your deadline is approaching. Are you ok with the suggested patch or do you require changes?
Comment 18 Dani Megert CLA 2013-04-29 11:28:37 EDT
After a second though I decided to only take the selection listener addition:
- LEAD is not used often in our code, but it is the correct/preferred thing to 
  use in newer applications, see SWT.LEAD and SWT.LEFT for details. And also
  bug 401291.
- Using quotes looks helpful at first, but for people who select Java code (e.g.
  an NLS constant) or a string literal, we create more work (deleting the quotes 
  is harder than adding them).

Some other trivial changes:
- make sure the cursor is at the end of the template and not inside the listener
- used our copyright notice format
- updated copyright date


Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=cf4a6483b2973f177218ad73eb61797eee47e0e5
Comment 19 Dani Megert CLA 2013-04-29 11:28:55 EDT
NOTE: Change is too small for N&N.
Comment 20 Lars Vogel CLA 2013-04-29 11:39:07 EDT
> Using quotes looks helpful at first, but for people who select Java code
> (e.g. an NLS constant) or a string literal, we create more work (deleting the
> quotes is harder than adding them).

I think selecting a string and using a template on this, is the exception not the normal case. Leaving that change out, still creates syntax errors for the IMHO 90% use case. 

I assume you, the JDT developers, are also good example for the usage of the SWT templates. Is your normal flow to select a text or to use the templates without text selection? Please close the bug again, if your experience is different from mine.
Comment 21 Dani Megert CLA 2013-04-29 11:57:59 EDT
(In reply to comment #20)
> > Using quotes looks helpful at first, but for people who select Java code
> > (e.g. an NLS constant) or a string literal, we create more work (deleting the
> > quotes is harder than adding them).
> 
> I think selecting a string and using a template on this, is the exception
> not the normal case.

Correct. But, users can easily select code, like <MyString.getText()>. And we also don't add quotes around the word selection in other templates, e.g. 'sysout'.
Comment 22 Lars Vogel CLA 2013-04-29 11:59:29 EDT
If there a construct to detect user selection? If, we could have a conditional statement.
Comment 23 Dani Megert CLA 2013-04-29 12:02:00 EDT
(In reply to comment #22)
> If there a construct to detect user selection? If, we could have a
> conditional statement.

Not sure what you exactly mean.
Comment 24 Lars Vogel CLA 2013-04-29 12:07:26 EDT
I don't now if the templates allow to check if the word selection is empty. If this would be possible we could create templates which are both correct in case something is selected (use no "") and if case nothing is selected (use "" to avoid syntax error).

In ;seudo-code:

if word selection.isEmpty()) {
use quotes for the template} else {
no quotes for the template}
Comment 25 Dani Megert CLA 2013-04-29 12:22:35 EDT
(In reply to comment #24)
> I don't now if the templates allow to check if the word selection is empty.
> If this would be possible we could create templates which are both correct
> in case something is selected (use no "") and if case nothing is selected
> (use "" to avoid syntax error).

That would not help much. I can navigate to setText(|) using Tabs and then start to add code using content assist. I'd hate if there are "" at this location in this scenario. Also, for me, having setText("") is worse than having a compile error that indicates, work has to be done there.


And to answer your question: there is no way to interpret the word selection inside the template definition.