Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 112668 - Better approach in resolving context menu items and toolbar items
Summary: Better approach in resolving context menu items and toolbar items
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: TPTP (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: amehrega CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-14 13:29 EDT by amehrega CLA
Modified: 2016-05-05 11:06 EDT (History)
0 users

See Also:


Attachments
Patch (19.25 KB, patch)
2005-12-12 14:14 EST, amehrega CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description amehrega CLA 2005-10-14 13:29:00 EDT
From experience, indexing context menu items and toolbar items has proved to be
an ineffective way of resolving these items.

Find a better approach to resolve them.
Comment 1 amehrega CLA 2005-11-17 01:27:24 EST
Downgrading this to a defect.  The policy currently employed is proving to be a
nuisance.  The indices of menu items constantly change and cause macro breakage.
 We will need to support the current and the new policy.

Keep the following in mind:

1) Users should have the ability to specify a unique ID for a menu/toolbar item
just like how a unique ID can be specified for widgets.

2) Use a default set of (property, weight) pairs if a user entry can't be found.
 Example of properties:

1) Index with variance of 2 (extrinsic property)
2) The presence of an item relative to other items (extrinsic property)
3) The implemented class (intrinsic property)
4) Keyboard shortcut (intrinsic property)
5) Associated icon (extrinsic property)
Comment 2 Allan Pratt CLA 2005-11-17 12:16:13 EST
You didn't mention using the "name" property in the menu. Is that something you 
can't see? That seems like the most obvious thing to use - it's what users go 
by - though of course such a test only works in one locale. Ideally, you could 
go by the message property file tag that leads to the name: that would give you 
locale independence. Maybe after recording you could consult the appropriate 
plugin's property file and do a reverse lookup from the menu item's name to its 
tag, and store the tag in the script. Then on playback you could look up the 
tag in the message file and match the string you find against the menu items' 
names.

Also, using the menu item's name makes the test script more human-readable.
Comment 3 amehrega CLA 2005-11-17 13:00:52 EST
Thanks for your input Allan.  I purposely left out the message property because
of the locale dependency issue.  I have tried not to use any properties that
would make the macro locale dependent.  Mostly because of feature
https://bugs.eclipse.org/bugs/show_bug.cgi?id=110108 which will require a macro
to run under different translations.

I don't think the user experience will be that well if the tool prompted the
user for the properties files for a specific label.
I already have this feature open for making a macro more human-readable: 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=111018
Comment 4 Allan Pratt CLA 2005-11-17 13:42:07 EST
Try this: instead of ignoring the name of the menu item on playback, use it as 
a "hint." If *any* item in the menu matches the text of the label you saw 
during record, then that's your winner. If *none* of them matches, then use the 
other (less-reliable) attributes you recorded. This way, a playback in the same 
locale as the recording will be highly reliable, and a playback in another 
locale (or if the label changes) is still possible. (This advice applies only 
if the label is more reliable in the original locale than your alternatives. 
Right now you know it's more reliable than the index.)

Regarding message property tags: I don't propose prompting the user for them. 
Rather, you can grovel in the plugin's message properties file yourself and 
find them, like this:

During record:
   1. Get the label from the UI.
   2. Look in the plug-in's properties file for a string that matches.
   3. Save the tag for that entry as a property in the recorded script.

During playback:
   4. Look in the plug-in's locale-appropriate properties file for the tag.
   5. Get the string that corresponds to that tag.
   6. Match the string against the item names in the menu.
   7. If you find a match, that's your winner.

Here's an example. During a recording session in English, let's say the string 
in the menu the user hit is "Convert." You look in the current locale's 
properties file to find that string and pull its tag; let's say the tag 
is "CONVERT_ITEM_LABEL." 

Now there's a playback in the French locale. You should look in the now-current 
properties file (French) for the CONVERT_ITEM_LABEL tag. The string you find 
will be "Convertir" or something. So your menu item is the one whose label 
is "Convertir."

This is a fuzzy algorithm. The first fuzzy part is finding the properties file. 
Each each plug-in is free to use any system for internationalization, but there 
are only a couple of systems in actual use, mostly based on OSGI bundles. In 
the case of menu items, most of these come from plugin.xml files where the 
system of turning tags into locale-specific strings is rigid and well-known.

The second fuzzy part is matching "Convert" to CONVERT_ITEM_LABEL during 
record: if there is more than one entry in the properties file whose text 
is "Convert," you don't know which to use. You can give up on this trick at 
that point, or you can store them all and check each of them for a match at run 
time. Either they'll all translate to the same word (so it doesn't matter which 
one(s) you use), or they will translate differently but only one will match the 
menu you're seeing during playback.

The third fuzzy part is that there might not be a properties file you can find, 
or it might not have any entry whose text matches the menu item. In that case 
you're only as bad off as you were before.

The unhappy case is when you find a matching string in the properties file, 
save its tag, and look it up at run time, only to find that the program wasn't 
using the properties file for that string, so no menu item matches the text you 
fond. The WORST case is when ANOTHER menu item, a WRONG menu item, matches the 
string for the (wrong) tag you found. I think this is unlikely, and the 
probability of this failure is small enough that the trick is a net win 
overall. If you can find the properties files.
Comment 5 amehrega CLA 2005-11-17 14:03:01 EST
I think you're right about the added reliability if there is a label for me to 
use.  I will use the label with a high weight.  If the label of a menu item 
equals to that of the one recorded, then that menu item will be selected.  
Otherwise other attributes have to be true in order for me to classify an item 
as a match.  I'm still going to stay away from properties files (i.e. the added 
reliability will be present when the macro is run in the same locale that it 
was recorded in)

Thanks again for your useful comments.
Comment 6 Christophe Telep CLA 2005-12-09 12:29:47 EST
No considered for 4.2, Version=future
Comment 7 Christophe Telep CLA 2005-12-09 12:35:33 EST
Sorry, forget about the previous change and comment. (Version back to = 4.2)
Comment 8 amehrega CLA 2005-12-12 14:14:16 EST
Created attachment 31578 [details]
Patch

Patch.  I will check this in when the stream officially opens in Jan 2006.
Comment 9 amehrega CLA 2005-12-13 14:18:49 EST
Patch checked into head
Comment 10 Paul Slauenwhite CLA 2006-11-16 08:59:24 EST
ACTION: Please verify/close this defect.
Comment 11 Paul Slauenwhite CLA 2007-02-12 12:58:08 EST
Closing by default since not closed by the originator in the 7+ months since being resolved.  

Please reopen if the issue is still present in the latest TPTP release or the resolution is not correct.