Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cursor position tool should consider locale when parsing coord string #330

Merged
merged 7 commits into from Dec 7, 2018

Conversation

nprigour
Copy link
Contributor

Setting the coordinate in the cursor position textbox seems to be problematic when locale used is one that uses comma (,) separator instead of dot (.)
before this patch --> based on the locale of the application the format displayed could be either:
xxxx.xxxx, yyyy.yyyy (i.e. US locale) or xxxx,xxxx, yyyy,yyyy (i.e. German or France locale). In the latter case when trying to center the viewport around the coordinate the coord coefficient parsing is problematic.
Afte the patch --> based on the locale of the application the format displayed could be either:
xxxx.xxxx yyyy.yyyy (i.e. US locale) or xxxx,xxxx yyyy,yyyy (i.e. German or France locale). Parsing and viewport setting does not suffer from the issue of multiple commas and works correct

Signed-off-by: Nikolaos Pringouris nprigour@gmail.com

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
@fgdrf
Copy link
Contributor

fgdrf commented Nov 21, 2018

Great, thanks for this fix

Any chance to implement tests for these scenarios. would help to assure for future refactorings/changes.

@fgdrf fgdrf added this to the 2.1.0 milestone Nov 21, 2018
@fgdrf fgdrf added the bug label Nov 21, 2018
@nprigour
Copy link
Contributor Author

The problem with adding a test for this PR is that in order to verify the behavior of the tool we need the udig application with a map loaded and the ability to input coordinates in the cursor position line item (see below) in order to verify proper setting of viewport.
image

Is this somehow possible with the present test framework?

@fgdrf
Copy link
Contributor

fgdrf commented Nov 27, 2018

I guess CursorPositionTest implemented such tests already and I'm wondering if we could make it parametrized

Also I'm not sure if test would fail if it runs different locale settings. in static CursorPosition.parse() method is a similiar implementation with comma and space. Maybe its worth to refactor class under test

CursorPositionTest to better handle Locale settings.

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
@nprigour
Copy link
Contributor Author

nprigour commented Nov 28, 2018

Hi @fgdrf ,

I proceed with another commit which provides a refactored implementation of CursorPositionTest that checks parsing using 2 different Locales (one where decimal separator in . and another one with ,)

Furthermore I proceed with further enhancements in CursorPosition so that:

  1. Locale setting are correctly retrieved during parse() and getString() method
  2. parsing of String to coordinate now utilizes StringUtils which provides for better handling of split process, trimming, removal of undesired characters and handling of consecutive characters (i.e multiple spaces between coord coefficients)
  3. dot (.) as decimal separator can now be used always independent of Locale when setting coordinates. On the contrary comma (,) as decimal separator may apply only to specific locales (i.e. FR, DE, GR etc)
  4. comma (except for Locales like FR, DE etc and in the case there are decimal digits) or space may be used as coordinate coefficient separators
  5. getString(Coordinate coord) method moved outside from inner class and become public and static so that it can be available by other classes that may need to have a common way to transform Coordinates to String

P.S: the formatting of the CursorPosition class is awful. Maybe it is worth after reviewing these commits and before closing the PR to apply style formatter to the whole class.

classes

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
@nprigour
Copy link
Contributor Author

Hi @fgdrf ,
I added the locale rule you suggested and split tests to 2 different classes based on applied Locale

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
import org.junit.runners.model.Statement;

/** JUnit rule for taking control over the Locale. */
public final class DefaultLocaleRule implements TestRule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess regarding Eclipse IP its not allowed to copy code from other projects. So it can inspire uDig but this class needs to be re-written or we add a dependency to the project to use it as a library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is quite elementary in terms of behavior and applied logic. Would it be OK if I just rename it (for example ConfigureLocaleRule) and possibly alter a couple of Comments

CursorPosition parse

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
@nprigour
Copy link
Contributor Author

nprigour commented Dec 4, 2018

Latest commit addresses:

  • refactor of test code to avoid eclipse IP issues
  • addition of header comment in newly created files
  • fix of an erroneous if check introduced during previous commit in CursorPosition.parse(...) method

@fgdrf
Copy link
Contributor

fgdrf commented Dec 6, 2018

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
@nprigour
Copy link
Contributor Author

nprigour commented Dec 6, 2018

Hmm the failure seems to be related to the naming convention of the concrete test classes which should be in the the form XXXXXTest.java otherwise the class is not recognized as a junit test from maven. I rename them so now the test should be OK. Please re-run jenkins CI

@fgdrf
Copy link
Contributor

fgdrf commented Dec 7, 2018

here we go : https://ci.eclipse.org/udig/job/uDig-PR/36/

@nprigour
Copy link
Contributor Author

nprigour commented Dec 7, 2018

@fgdrf ,

If jenkins job executes without errors I would strongly suggest before you merge the PR to let me push another commit for fixing formatting in CursorPosition class which as I mentioned in a previous comment is "awful".

@fgdrf
Copy link
Contributor

fgdrf commented Dec 7, 2018

Job feedback looks good, waiting for your re-formatings

Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
@nprigour
Copy link
Contributor Author

nprigour commented Dec 7, 2018

I just apply udig formatting to CursorPosition class. I also slightly reformat the modified test classes

@fgdrf fgdrf merged commit 0dde77a into locationtech:master Dec 7, 2018
@fgdrf
Copy link
Contributor

fgdrf commented Dec 7, 2018

https://ci.eclipse.org/udig/job/uDig-PR/37/ was fine. Thanks for contributing!

fgdrf pushed a commit to fgdrf/udig-platform that referenced this pull request Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants