benjamin84 / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

JTreeFixture#selectPath with separator in path element #171

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I am using version 1.0a3 of the FEST-Swing module.

I just started using JTreeFixture and I ran into a problem.
I want to select a node based on its path.
The problem is that some path elements contain the separator.
An escape mechanism could be provided.

There could be an escape character, like \.
It could be used to escape the path element separator, like \/.
It could also be used to escape itself, like \\.
JTreeDriver#splitPath could easily be modified to handle paths this way.
But I think that there's a better solution.

Paths should be represented by arrays.
This has several advantages over using a single String.
First of all, the problem of the path element separator wouldn't exist.
Secondly, path elements could be represented by not only strings.
For example, an array of java.util.regex.Pattern s could be used.
Using arrays proved useful with menuItemWithPath.

Thank you,
Csabi

Original issue reported on code.google.com by csaba.ju...@gmail.com on 10 Jul 2008 at 9:00

GoogleCodeExporter commented 9 years ago
Hi again,

I temporarily replaced the implementation of JTreeDriver#splitPath.
It uses an escape character.
I hope it helps other people who have encountered the same problem.
I would still prefer if paths were given as arrays.

Here's the method:

private String[] splitPath(final String path) {
    List<String> result = new ArrayList<String>();

    String pathElement = "";

    int i = 0;

    int pathLength = path.length();
    while (i < pathLength) {
        char c = path.charAt(i++);

        if (c == ESCAPE_CHARACTER) {
            pathElement += path.charAt(i++);
        } else {
            if (c == SEPARATOR_CHARACTER) {
                result.add(pathElement);

                pathElement = "";
            } else {
                pathElement += c;
            }
        }
    }

    result.add(pathElement);

    return result.toArray(new String[result.size()]);
}

where

private static final char ESCAPE_CHARACTER = '\\';
private static final char SEPARATOR_CHARACTER = '/';

are fields of JTreeDriver.

I hope it helps,
Csabi

Original comment by csaba.ju...@gmail.com on 10 Jul 2008 at 1:38

GoogleCodeExporter commented 9 years ago
Hi Csabi,

JTreeFixture has a method 'separator(String)' that allows you to change the
separator. I think that will fix your problem. Please let me know if that is 
the case.

Cheers,
-Alex

Original comment by Alex.Rui...@gmail.com on 10 Jul 2008 at 2:21

GoogleCodeExporter commented 9 years ago
Hi Alex,

Using the separator(String) method did fix the problem in my use case, but I'm
getting the path elements from resource bundles.
One could presume that certain characters, like '~' or '+' for example, never 
appear
in path elements, but I'm not sure.
What do you think?

Best regards,
Csabi

Original comment by csaba.ju...@gmail.com on 11 Jul 2008 at 9:20

GoogleCodeExporter commented 9 years ago
Hi Csabi,

It is really hard to tell. So far I haven't seen those characters in path 
elements.

What are your thoughts about closing this bug?

Thanks!
-Alex

Original comment by Alex.Rui...@gmail.com on 14 Jul 2008 at 7:09

GoogleCodeExporter commented 9 years ago
Hi Alex,

You're probably right.
If a test would fail because of this, I'm sure I would find a separator.

This really isn't a bug, so you can close it right away.
I didn't even realize this was a bug report. :)
I guess I just wanted some insight into some design decisions.

Thanks and sorry for keeping you busy with this one,
Csabi

Original comment by csaba.ju...@gmail.com on 15 Jul 2008 at 12:27

GoogleCodeExporter commented 9 years ago
Hi Csabi,

No need to apologize. In fact, I prefer using this issue page rather the mailing
list. Sometimes I have too much e-mail that is difficult to recognize any
FEST-related one. On the other hand, having an issue in the issue page is a lot
easier to handle. Please feel free to file any issues if you have any
questions/comments/suggestions! :)

Thank you for helping us improve FEST!

Best regards,
-Alex

Original comment by Alex.Rui...@gmail.com on 15 Jul 2008 at 12:32

GoogleCodeExporter commented 9 years ago
Oops, forgot to close issue.

Original comment by Alex.Rui...@gmail.com on 15 Jul 2008 at 12:32

GoogleCodeExporter commented 9 years ago

Hi Alex,

I've done some thinking.

In my initial post I've said that having an array of Strings instead of a single
String to represent the path would be useful, but it would mean that methods 
which
accept several paths, like selectPaths, would need to accept a two-dimensional 
array,
which would really be ugly.

I've also said that using an array would allow the use of not only Strings, but
regular expressions too. An alternative providing similar functionality could 
be a
method on tree node fixtures (see issue 185) to return fixtures for all child 
nodes
whose text (read by a JTreeCellReader) matches a regular expression.

Best regards,
Csabi

Original comment by csaba.ju...@gmail.com on 16 Sep 2008 at 1:24

GoogleCodeExporter commented 9 years ago
Set the module as a label, instead of being part of the title.

Original comment by Alex.Rui...@gmail.com on 1 Dec 2008 at 2:07