Bug 466345 - [BIDI] BidiUtils.applyBidiProcessing should work on formatting messages
Summary: [BIDI] BidiUtils.applyBidiProcessing should work on formatting messages
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 465495 467836
Blocks: 229010 381487
  Show dependency tree
 
Reported: 2015-05-04 14:13 EDT by Tomer Mahlin CLA
Modified: 2017-05-26 09:21 EDT (History)
4 users (show)

See Also:


Attachments
new API applyBidiProcessing for formatting messages (9.48 KB, patch)
2015-05-21 06:50 EDT, Moshe WAJNBERG CLA
no flags Details | Diff
new API applyBidiProcessing for formatting messages (9.48 KB, patch)
2015-05-21 07:20 EDT, Moshe WAJNBERG CLA
no flags Details | Diff
Unit tests for applyBidiProcessing formatting messages API (4.25 KB, application/octet-stream)
2016-02-21 09:42 EST, Moshe WAJNBERG CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tomer Mahlin CLA 2015-05-04 14:13:52 EDT
The requested signature of API should address following use cases:

1. Concatenations
 displayText = someStr1 + someStr2 + someStr3 + ... + someStrN

2. Templated messages
 - load a message template based on message ID (i.e. "{0} file does not exist")
 - replace the placeholders (i.e. {0}) with actual data (i.e. c:\file.txt)
 - create result display string
Please observe that Concatenation is a particular case of templated messages, since every concatenation can be represented by template like: 
{0}{1}{2}{3}...{n}

In all those cases it might be important (depending on actual text / data) to enforce text direction or order of tokens for either placeholder or/and entire message. 

Suggested signature is: 
applyBidiProcessing(String messageID, String[] placeholdersData, String[] bidiHandlingType)

For covering concatenated scenario (#1 above) we will call: 
   applyBidiProcessing(null, placeholdersData, bidiHandlingType)
For covering templated message scenario (#2 above) we will call:
   applyBidiProcessing("ID123456", placeholdersData, bidiHandlingType)

Internally API will take into account the information about locale / language since this will affect several aspects of handling (i.e. general direction of the message).

Obviously this API is not supposed to be used in EVERY SINGLE context in which message is created. It is very much depends on the type of message and type of data replacing the placeholders. For example: 

1. "{0} users are currently logged in" - it is expected that place holder will be replaced with number. Most probably this message should not be processed in any special way.

2. "User {0} deleted file {1}" - when placeholders are replaced we can get something like: "User moshe deleted file c:\file.txt". In this case we most probably would like to enforce text direction for text replacing placeholder {0} and apply structured text handling for data replacing placeholder {1}

3. <name of user> + "-" + "<file path> - in this case we would like to: 
   - enforce text direction for <name of user>
   - apply Bidi handling for <file path> 
   - assure that for English UI we see: 
         <name of user> - <file path>
   - assure that for Arabic / Hebrew UI we see: 
         <file path> - <name of user>
Comment 1 Tomer Mahlin CLA 2015-05-04 14:15:52 EDT
Each separate placeholder (as well as the entire message as whole if necessary) can be processed using API described in bug 465495
Comment 2 Thomas Watson CLA 2015-05-04 14:19:06 EDT
Which BidiUtils class are you referring to?  I suspect this bug does not belong in the framework.
Comment 3 Tomer Mahlin CLA 2015-05-04 14:24:46 EDT
org.eclipse.jface.util.BidiUtils
Comment 4 Markus Keller CLA 2015-05-05 06:35:06 EDT
JFace is Platform/UI. Moved the bug.

Bug 465880 is also about combining multiple bidi-processed strings, but in a slightly different setup. Maybe there's some code-sharing opportunity between the two bugs.
Comment 5 Tomer Mahlin CLA 2015-05-05 06:41:35 EDT
(In reply to Markus Keller from comment #4)
> JFace is Platform/UI. Moved the bug.
> 
> Bug 465880 is also about combining multiple bidi-processed strings, but in a
> slightly different setup. Maybe there's some code-sharing opportunity
> between the two bugs.


The bug 465880 is about editable control context. API in this bug is working on the string level. Thus there is no any relation besides the fact that Bidi is being handled in both. The only common functionality is usage of low level API injecting UCC into strings. 

This defect is about handling finite well defined (from programmer perspective) string. Bug 465880 is about potentially infinite sequence of tokens not known to developer in advance. I will add more comments on bug 465880 in the bug thread itself.
Comment 6 Tomer Mahlin CLA 2015-05-19 09:10:33 EDT
Most probably the suggested signature will change based on the widely used coding pattern for handling message formatting. For example: 

MessageFormat.format("Exception in {0}.performCopy(): {1}", 
            new Object[] {
                getClass().getName(), 
                e.getTargetException() })
Observe that second argument passed to format function is simply an array of objects which hold values to replace placeholders in the message.

Thus previously suggested pattern:
    applyBidiProcessing(
          String messageID, 
          String[] placeholdersData, 
          String[] bidiHandlingType);

will change to:
  Object[] applyBidiProcessing (
          String typeOfContext, 
          Object ...args);
   - typeOfContext - is used to distinguish between use cases: message with 
                     placeholders vs. concatenations.
   - Object ... args - unlimited number of arguments associated with either 
                       placeholders or concatenated strings. It is always even 
                        number since for each placeholder / piece of text, we
                       need to specify which type of handling is required 
                       (i.e. text direction enforcement, structured text, 
                       no handling).
      

1. Message with placeholders
-----------------------------
Sample call:
   applyBidiProcessing (
      BIDITYPE_MESSAGEWITHPLACEHOLDERS,
      placeholderData_1, BTD_LTR, 
      placeholderData_2, NULL // for numbers
      placeholderData_3, STT_FILEPATH);


2. Concatenation of strings
----------------------------
Sample call:
   applyBidiProcessing (
      BIDITYPE_CONCATENATION,
      firstPieceOfText, BTD_LTR, 
      secondPieceOfText, NULL // for numbers
      thirdPieceOfText, STT_FILEPATH);

The main difference is in the type of result returned by the function. In case of messages it is just array of objects, while in case of concatenations it is array of objects with just one object - String. 

    
Taking typical example of message formatting from above: 

    MessageFormat.format("Exception in {0}.performCopy(): {1}", 
            new Object[] {
                getClass().getName(), 
                e.getTargetException() })

to allow proper Bidi processing in this context we will suggest to change it (for relevant context / messages) as follows:

    MessageFormat.format("Exception in {0}.performCopy(): {1}", 
            applyBidiProcessing(
                   BIDITYPE_MESSAGEWITHPLACEHOLDERS,
                   getClass().getName(),STT_FILEPATH
                   e.getTargetException(),BTD_DEFAULT))

In case of concatenation, we will need to retrieve first object from the result array which will hold the result String.

PS. Important observation, number of arguments to be passed to new function will be always odd and will be at least 3. Each placeholder or piece of concatenated string comes with its type.
Comment 7 Moshe WAJNBERG CLA 2015-05-21 06:50:55 EDT
Created attachment 253623 [details]
new API applyBidiProcessing for formatting messages

Hello Markus,

Could you please review this patch ?

Actually this patch is for both Bug 465495 and Bug 466345. I think it would be much easier for you to review both defects at the same time.

Thank you for your review
Comment 8 Moshe WAJNBERG CLA 2015-05-21 07:20:31 EDT
Created attachment 253627 [details]
new API applyBidiProcessing for formatting messages
Comment 9 Tomer Mahlin CLA 2016-01-06 09:04:24 EST
Dear @markus, any review comments ?
Comment 10 Moshe WAJNBERG CLA 2016-02-21 09:42:38 EST
Created attachment 259850 [details]
Unit tests for applyBidiProcessing formatting messages API

Hello @markus,
'
I've created these unit tests to facilitate your review
Please let me know if you need anything else

Thank you very much for your review
Comment 11 Markus Keller CLA 2016-03-16 09:43:54 EDT
Sorry, I didn't get to this in time for M6, but I'll have a look in M7 and ask for PMC approval for the late API addition.
Comment 12 Tomer Mahlin CLA 2016-03-16 09:54:29 EDT
Thanks Markus ! Appreciate it very much in advance.
Comment 13 Markus Keller CLA 2016-04-21 12:27:47 EDT
Sorry, I have to move this out, just due to lack of time and other higher-priority items.