You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Дмитрий <dm...@yandex.ru> on 2010/02/09 08:25:24 UTC
WtkxBrowser
Hi,
I have fixed known bugs in wtkx browser (http://issues.apache.org/jira/browse/PIVOT-30).
Results: code, screenshots and distribution, can be found at:
http://code.google.com/p/wtkxbrowser/
While development I have collected several questions I want to ask:
1. Exception appears when wtkx data format is wrong:
org.apache.pivot.beans.PropertyNotFoundException: Property "text1" does not exist or is read-only.
at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
at org.apache.pivot.wtkx.WTKXSerializer.processEndElement(Unknown Source)
at org.apache.pivot.wtkx.WTKXSerializer.readObject(Unknown Source)
at org.apache.pivot.wtkx.WTKXSerializer.readObject(Unknown Source)
at org.apache.pivot.tools.wtkxbrowser.WtkxBrowser$ResourcesChangesMonitorRunnable.reload(WtkxBrowser.java:360)
I want to have line number where problem is happened.
Also, I have worked a bit with KODO-JDO persistence library (don't be afraid yet:) ),
and it has one neat feature in exceptions explanation. When wrong entity name (table or column) appeared in query,
exception not only says: "Wrong column name 'usrId', please fix it on your own" but also suggests most probably correct value found by
Levenshtein algorithm (http://en.wikipedia.org/wiki/Levenshtein_distance), and the result looks like:
"Wrong column name 'usrId', most probably correct value 'userId'".
I think it is possible to add this feature to pivot.
2. org.apache.pivot.wtk.ListView
Here is 3 methods:
getSelectedItem()->Object
getSelectedIndex()->int (index)
getItemAt()->???
I was expected (with expierence based on usage of first two methods) that getItemAt() should return Object,
but real result value is int (index).
3. tabPane.getTabs().remove(0, tabPane.getTabs().getLength());
Yes, I understand that collections framework interfaces is designed to be reasonable small in
implementation. But is it possible to provide some utility class with static methods:
clearList(List)
addAll(List to, List from)
containsAll(List target, List pattern)
and so on. There is method clear() in ArrayList http://pivot.apache.org/1.4/docs/api/org/apache/pivot/collections/ArrayList.html#clear()
But I can't be sure that I'm working with array list all the time.
4. I have problem with focus for component embedded into Prompt window. Here is the code:
final TextInput textInput = new TextInput();
Prompt.prompt(MessageType.QUESTION, "Enter name for a new tab", textInput, window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult() == true) {
addTab(model.createContainer(), textInput.getText());
}
}
});
When prompt appears, my text field is not focused, but I expect that user will provide name for a new tab
through this component. So user is forced to click on my text-input with mouse or press Tab to switch focus.
Is any way to automatically request focus for text-field in this case?
5. setPrompt() method exists for TextInput component but not for ListView:
http://pivot.apache.org/1.4/docs/api/org/apache/pivot/wtk/TextInput.html#setPrompt(java.lang.String)
In wtkx browser I have implemented next feature: when user clicks to empy list of wtkx resources
then FileBrowserSheet appears automatically to select new resources.
It will be good to suggest this feature to user like "Click here to add new resources" in prompt text for ListView.
--
Dmitry
Re: Re: WtkxBrowser
Posted by Дмитрий <dm...@yandex.ru>.
I have changed my code to this:
public void perform() {
final TextInput textInput = new TextInput();
Prompt p = new Prompt(MessageType.QUESTION, "Enter name for a new tab", new ArrayList<String>("OK"), textInput);
p.open(window, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult() == true) {
addTab(model.createContainer(), textInput.getText());
}
}
});
}
and here is a difference between my code and Prompt.prompt(...):
private static Prompt createPrompt(MessageType messageType, String message, Component body) {
List<Object> options = new ArrayList<Object>();
options.add(resources.get("defaultOption"));
Prompt prompt = new Prompt(messageType, message, options, body);
prompt.setTitle((String)resources.get("defaultTitle"));
prompt.setSelectedOption(0); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< here is the differecce <<<<<<<<<<<<<<<<<<<<<<<<<<
return prompt;
}
> As it turns out, the workaround I suggested isn't strictly necessary. When a Prompt is opened, it will focus the selected option button if specified, but will otherwise call requestFocus() on the window (which will set focus to the first focusable child component). If you create your prompt using the Prompt constructor rather than the prompt() method, you won't need to request focus to the text input - it will happen automatically.
> G
It might be two goals it apllication:
1. To ask user to enter text value in prompt (or may be to select one option from list, TextInput is just an example)
=> in this case textInput should be focused when prompt dialog is displayed.
2. or to ask user to _optionally_ enter text value in prompt (where deault value will be good enough for most cases)
=> in this case "OK" button shuld be focused by default.
My application uses first pattern but second one is also possible, so I agree that textInput.requestFocus() problem
is specific to my application.
--
Dmitry
Re: WtkxBrowser
Posted by Greg Brown <gk...@mac.com>.
>>> 4. I have problem with focus for component embedded into Prompt window. Here is the code:
>>> final TextInput textInput = new TextInput();
>>> Prompt.prompt(MessageType.QUESTION, "Enter name for a new tab", textInput, window, new SheetCloseListener() {
>>> @Override
>>> public void sheetClosed(Sheet sheet) {
>>> if (sheet.getResult() == true) {
>>> addTab(model.createContainer(), textInput.getText());
>>> }
>>> }
>>> });
>>> When prompt appears, my text field is not focused, but I expect that user will provide name for a new tab
>>> through this component. So user is forced to click on my text-input with mouse or press Tab to switch focus.
>>> Is any way to automatically request focus for text-field in this case?
>>
>> Prompt will automatically set focus to the selected option button when it is opened. To focus the text input, try calling textInput.requestFocus() immediately after your call to Prompt.prompt().
>
> Yes, it helped. I understand how it works, but it looks a bit tricky for me.
As it turns out, the workaround I suggested isn't strictly necessary. When a Prompt is opened, it will focus the selected option button if specified, but will otherwise call requestFocus() on the window (which will set focus to the first focusable child component). If you create your prompt using the Prompt constructor rather than the prompt() method, you won't need to request focus to the text input - it will happen automatically.
G
Re: WtkxBrowser
Posted by Greg Brown <gk...@mac.com>.
I don't love the "Util" name, but it does make sense. I think we would also want Dictionary.Util and Group.Util.
On Feb 9, 2010, at 8:59 AM, Todd Volkert wrote:
>>> No, sure it's no need in _special_ method for TabPane.TabSequence or any
>> other component. I'm asking about generic methods (probably in static
>> utility class)
>>> which will give me ability to add all elements from one list to another,
>> or to remove all elements from list and so on.
>>
>>> Like
>> http://java.sun.com/javase/6/docs/api/java/util/List.html#addAll(java.util.Collection)<http://java.sun.com/javase/6/docs/api/java/util/List.html#addAll%28java.util.Collection%29>
>> .
>>> So if I'm working with two instances:
>>> List collector;
>>> List portion;
>>> I can call, e.g.
>>> PivotCollections.addAll(collector, portion);
>>> not relying on concrete implementation (ArrayList, or TabSequence or my
>> own implementation of List) instead of writing:
>>> for(Object element:portion){ collector.add(element); }
>>> Not a big deal, but we have this functionality in java.util collections
>> framework.
>>
>> Note that TabSequence is not actually a List - it is a Sequence, which is
>> the super-interface of List. However, I can see the value in adding such
>> utility methods to Sequence (and probably to Dictionary and Group as well).
>>
>
> I think my earlier suggestion may have gotten swallowed in the large email,
> but FWIW, I think a Sequence.Util class could be of value (and I like its
> name and placement better than a catch-all PivotCollections class).
Re: WtkxBrowser
Posted by Todd Volkert <tv...@gmail.com>.
> > No, sure it's no need in _special_ method for TabPane.TabSequence or any
> other component. I'm asking about generic methods (probably in static
> utility class)
> > which will give me ability to add all elements from one list to another,
> or to remove all elements from list and so on.
>
> > Like
> http://java.sun.com/javase/6/docs/api/java/util/List.html#addAll(java.util.Collection)<http://java.sun.com/javase/6/docs/api/java/util/List.html#addAll%28java.util.Collection%29>
> .
> > So if I'm working with two instances:
> > List collector;
> > List portion;
> > I can call, e.g.
> > PivotCollections.addAll(collector, portion);
> > not relying on concrete implementation (ArrayList, or TabSequence or my
> own implementation of List) instead of writing:
> > for(Object element:portion){ collector.add(element); }
> > Not a big deal, but we have this functionality in java.util collections
> framework.
>
> Note that TabSequence is not actually a List - it is a Sequence, which is
> the super-interface of List. However, I can see the value in adding such
> utility methods to Sequence (and probably to Dictionary and Group as well).
>
I think my earlier suggestion may have gotten swallowed in the large email,
but FWIW, I think a Sequence.Util class could be of value (and I like its
name and placement better than a catch-all PivotCollections class).
Re: WtkxBrowser
Posted by Greg Brown <gk...@mac.com>.
> No, sure it's no need in _special_ method for TabPane.TabSequence or any other component. I'm asking about generic methods (probably in static utility class)
> which will give me ability to add all elements from one list to another, or to remove all elements from list and so on.
> Like http://java.sun.com/javase/6/docs/api/java/util/List.html#addAll(java.util.Collection).
> So if I'm working with two instances:
> List collector;
> List portion;
> I can call, e.g.
> PivotCollections.addAll(collector, portion);
> not relying on concrete implementation (ArrayList, or TabSequence or my own implementation of List) instead of writing:
> for(Object element:portion){ collector.add(element); }
> Not a big deal, but we have this functionality in java.util collections framework.
Note that TabSequence is not actually a List - it is a Sequence, which is the super-interface of List. However, I can see the value in adding such utility methods to Sequence (and probably to Dictionary and Group as well).
Re: Re: WtkxBrowser
Posted by Дмитрий <dm...@yandex.ru>.
> > 3. tabPane.getTabs().remove(0, tabPane.getTabs().getLength());
> > Yes, I understand that collections framework interfaces is designed to be reasonable small in
> > implementation. But is it possible to provide some utility class with static methods:
> > clearList(List)
> > addAll(List to, List from)
> > containsAll(List target, List pattern)
> > and so on. There is method clear() in ArrayList http://pivot.apache.org/1.4/docs/api/org/apache/pivot/collections/ArrayList.html#clear()
> > But I can't be sure that I'm working with array list all the time.
>
> We intentionally did not include these methods in TabPane.TabSequence and similar sequences because such methods are not commonly called for components (they are more useful in a generic container such as ArrayList). Because the use cases are uncommon, my feeling is that the implementation of such methods should be left to the application.
No, sure it's no need in _special_ method for TabPane.TabSequence or any other component. I'm asking about generic methods (probably in static utility class)
which will give me ability to add all elements from one list to another, or to remove all elements from list and so on.
Like http://java.sun.com/javase/6/docs/api/java/util/List.html#addAll(java.util.Collection).
So if I'm working with two instances:
List collector;
List portion;
I can call, e.g.
PivotCollections.addAll(collector, portion);
not relying on concrete implementation (ArrayList, or TabSequence or my own implementation of List) instead of writing:
for(Object element:portion){ collector.add(element); }
Not a big deal, but we have this functionality in java.util collections framework.
>
> > 4. I have problem with focus for component embedded into Prompt window. Here is the code:
> > final TextInput textInput = new TextInput();
> > Prompt.prompt(MessageType.QUESTION, "Enter name for a new tab", textInput, window, new SheetCloseListener() {
> > @Override
> > public void sheetClosed(Sheet sheet) {
> > if (sheet.getResult() == true) {
> > addTab(model.createContainer(), textInput.getText());
> > }
> > }
> > });
> > When prompt appears, my text field is not focused, but I expect that user will provide name for a new tab
> > through this component. So user is forced to click on my text-input with mouse or press Tab to switch focus.
> > Is any way to automatically request focus for text-field in this case?
>
> Prompt will automatically set focus to the selected option button when it is opened. To focus the text input, try calling textInput.requestFocus() immediately after your call to Prompt.prompt().
Yes, it helped. I understand how it works, but it looks a bit tricky for me.
>
> > 5. setPrompt() method exists for TextInput component but not for ListView:
> > http://pivot.apache.org/1.4/docs/api/org/apache/pivot/wtk/TextInput.html#setPrompt(java.lang.String)
> >
> > In wtkx browser I have implemented next feature: when user clicks to empy list of wtkx resources
> > then FileBrowserSheet appears automatically to select new resources.
> > It will be good to suggest this feature to user like "Click here to add new resources" in prompt text for ListView.
>
> I agree with Todd - this seems pretty specific to your use case. However, you can easily accomplish this with a decorator (you could potentially use OverlayDecorator, though you may want to write your own or extend that class so it only paints when the list is empty).
Thanks for advice, I will take a look for decorators. Sure this use case is very specific.
--
Dmitry
Re: WtkxBrowser
Posted by Greg Brown <gk...@mac.com>.
> 2. org.apache.pivot.wtk.ListView
> Here is 3 methods:
> getSelectedItem()->Object
> getSelectedIndex()->int (index)
> getItemAt()->???
> I was expected (with expierence based on usage of first two methods) that getItemAt() should return Object,
> but real result value is int (index).
I have to give this some thought. There was a reason we went with getItem() vs. getIndex(), but at the moment I don't remember what it was.
> 3. tabPane.getTabs().remove(0, tabPane.getTabs().getLength());
> Yes, I understand that collections framework interfaces is designed to be reasonable small in
> implementation. But is it possible to provide some utility class with static methods:
> clearList(List)
> addAll(List to, List from)
> containsAll(List target, List pattern)
> and so on. There is method clear() in ArrayList http://pivot.apache.org/1.4/docs/api/org/apache/pivot/collections/ArrayList.html#clear()
> But I can't be sure that I'm working with array list all the time.
We intentionally did not include these methods in TabPane.TabSequence and similar sequences because such methods are not commonly called for components (they are more useful in a generic container such as ArrayList). Because the use cases are uncommon, my feeling is that the implementation of such methods should be left to the application.
> 4. I have problem with focus for component embedded into Prompt window. Here is the code:
> final TextInput textInput = new TextInput();
> Prompt.prompt(MessageType.QUESTION, "Enter name for a new tab", textInput, window, new SheetCloseListener() {
> @Override
> public void sheetClosed(Sheet sheet) {
> if (sheet.getResult() == true) {
> addTab(model.createContainer(), textInput.getText());
> }
> }
> });
> When prompt appears, my text field is not focused, but I expect that user will provide name for a new tab
> through this component. So user is forced to click on my text-input with mouse or press Tab to switch focus.
> Is any way to automatically request focus for text-field in this case?
Prompt will automatically set focus to the selected option button when it is opened. To focus the text input, try calling textInput.requestFocus() immediately after your call to Prompt.prompt().
> 5. setPrompt() method exists for TextInput component but not for ListView:
> http://pivot.apache.org/1.4/docs/api/org/apache/pivot/wtk/TextInput.html#setPrompt(java.lang.String)
>
> In wtkx browser I have implemented next feature: when user clicks to empy list of wtkx resources
> then FileBrowserSheet appears automatically to select new resources.
> It will be good to suggest this feature to user like "Click here to add new resources" in prompt text for ListView.
I agree with Todd - this seems pretty specific to your use case. However, you can easily accomplish this with a decorator (you could potentially use OverlayDecorator, though you may want to write your own or extend that class so it only paints when the list is empty).
Greg
Re: Re: WtkxBrowser
Posted by Дмитрий <dm...@yandex.ru>.
Todd,
Sure, I will try to implement this logic as it was my idea,
may be it will be useful may be not.
> >
> >> Also, I have worked a bit with KODO-JDO persistence library (don't be
> >> afraid yet:) ),
> >> and it has one neat feature in exceptions explanation. When wrong entity
> >> name (table or column) appeared in query,
> >> exception not only says: "Wrong column name 'usrId', please fix it on your
> >> own" but also suggests most probably correct value found by
> >> Levenshtein algorithm (http://en.wikipedia.org/wiki/Levenshtein_distance),
> >> and the result looks like:
> >> "Wrong column name 'usrId', most probably correct value 'userId'".
> >> I think it is possible to add this feature to pivot.
> >>
> >
> > Not a bad suggestion, though I'd only vote to do it if the implementation
> > were fairly trivial. We'd have to iterate over the bean's properties (we
> > already have such an iterator), calculate the Levenshtein distance between
> > that property and the specified key, and if that distance were small enough,
> > include it in the exception. It may in fact be trivial :)
> >
>
> Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
> anyway), but if you wanted to try it out, see how intrusive or trivial it'd
> be, and submit it as a patch, the class in question is located at
> http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
>
>
--
Dmitry
Re: Re: WtkxBrowser
Posted by Дмитрий <dm...@yandex.ru>.
> Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
> anyway), but if you wanted to try it out, see how intrusive or trivial it'd
> be, and submit it as a patch, the class in question is located at
> http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
>
I have created a patch.
Here is some output messages:
org.apache.pivot.beans.PropertyNotFoundException: Property "z" does not exist or is read-only. Most possible matches: "x", "y".
at org.apache.pivot.beans.BeanDictionary.put(BeanDictionary.java:389)
at org.apache.pivot.beans.BeanDictionary.put(BeanDictionary.java:49)
Exception in thread "main" org.apache.pivot.beans.PropertyNotFoundException: Property "~z" does not exist or is final. Most possible matches: "~x", "~y".
at org.apache.pivot.beans.BeanDictionary.put(BeanDictionary.java:352)
at org.apache.pivot.beans.MyBeanDemo.main(MyBeanDemo.java:15)
org.apache.pivot.beans.PropertyNotFoundException: Property "prefferedWidth" does not exist or is read-only. Most possible matches: "preferredWidth".
at org.apache.pivot.beans.BeanDictionary.put(BeanDictionary.java:389)
at org.apache.pivot.beans.BeanDictionary.put(BeanDictionary.java:49)
org.apache.pivot.beans.PropertyNotFoundException: Property "sdjbajksdbasbdk" does not exist or is read-only.
at org.apache.pivot.beans.BeanDictionary.put(BeanDictionary.java:389)
at org.apache.pivot.beans.BeanDictionary.put(BeanDictionary.java:49)
Patch is listed below, hope it will be useful:
# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- C:\work\WtkxBrowser\lib\base.java
+++ C:\work\WtkxBrowser\src\org\apache\pivot\beans\BeanDictionary.java
@@ -27,9 +27,11 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
+import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.Dictionary;
import org.apache.pivot.collections.HashMap;
import org.apache.pivot.collections.HashSet;
+import org.apache.pivot.collections.List;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.util.ThreadUtilities;
import org.apache.pivot.util.Vote;
@@ -348,7 +350,8 @@
if (field == null) {
throw new PropertyNotFoundException("Property \"" + key + "\""
- + " does not exist or is final.");
+ + " does not exist or is final."
+ +adviceMostPossibleCorrectPropertyNamesForGivenKey(key, " Most possible matches: "));
}
Class<?> fieldType = field.getType();
@@ -383,8 +386,8 @@
}
if (setterMethod == null) {
- throw new PropertyNotFoundException("Property \"" + key + "\""
- + " does not exist or is read-only.");
+ throw new PropertyNotFoundException("Property \""+key+"\" does not exist or is read-only."+
+ adviceMostPossibleCorrectPropertyNamesForGivenKey(key, " Most possible matches: "));
}
try {
@@ -405,7 +408,69 @@
return null;
}
+ private String adviceMostPossibleCorrectPropertyNamesForGivenKey(String key, String messagePrefix){
+ List<String> bestMatches = new ArrayList<String>();
+ int bestWeight = 8;
+ for(String property:this){
+ int currentWeight = computeLevenshteinDistance(key, property);
+ if (currentWeight<bestWeight){
+ bestMatches.clear();
+ bestWeight = currentWeight;
+ }
+ if (currentWeight==bestWeight){
+ bestMatches.add(property);
+ }
+ }
+ if (bestMatches.getLength()>0){
+ StringBuilder message = new StringBuilder(messagePrefix);
+ boolean firstIteration = true;
+ for(String possibleKey:bestMatches){
+ if (firstIteration==false){
+ message.append(", ");
+ }
+ message.append('"').append(possibleKey).append('"');
+ firstIteration = false;
+ }
+ message.append(".");
+ return message.toString();
+ }
+ return "";
+ }
+
/**
+ * Levenshtein distance computation algorithm aquired from:
+ * http://en.literateprograms.org/Levenshtein_distance_%28Java%29
+ *
+ * @param s1 one of strings in comparing
+ * @param s2 another of strings in comparing
+ * @return distance
+ */
+ private int computeLevenshteinDistance(String s1, String s2) {
+ int[][] dp = new int[s1.length() + 1][s2.length() + 1];
+
+ for (int i = 0; i < dp.length; i++) {
+ for (int j = 0; j < dp[i].length; j++) {
+
+ dp[i][j] = i == 0 ? j : j == 0 ? i : 0;
+
+ if (i > 0 && j > 0) {
+
+ if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
+ dp[i][j] = dp[i - 1][j - 1];
+ } else {
+ dp[i][j] = Math.min(
+ dp[i][j - 1] + 1,
+ Math.min(
+ dp[i - 1][j - 1] + 1,
+ dp[i - 1][j] + 1));
+ }
+ }
+ }
+ }
+ return dp[s1.length()][s2.length()];
+ }
+
+ /**
* @throws UnsupportedOperationException
* This method is not supported.
*/
--
Dmitry
Re: WtkxBrowser
Posted by Greg Brown <gk...@mac.com>.
That's true.
Adding the property name to the exception is certainly doable.
On Feb 9, 2010, at 4:14 PM, Todd Volkert wrote:
> Except in this case, the client is a WTKX visualization tool that is just
> blindly loading a WTKX file, so calls readObject() and gets an exception --
> it has no way of knowing which property of which bean was responsible...
>
> -T
>
> On Tue, Feb 9, 2010 at 2:38 PM, Greg Brown <gk...@mac.com> wrote:
>
>> I don't think it needs to be passed in the exception. The client code knows
>> which property is being set and can perform the Levenshtein analysis if an
>> exception is thrown.
>>
>> On Feb 9, 2010, at 2:20 PM, Todd Volkert wrote:
>>
>>> That's a good point, though it'd mean that the BeanException would need
>> to
>>> set the invalid key as an exception property.
>>>
>>> -T
>>>
>>> On Tue, Feb 9, 2010 at 12:05 PM, Greg Brown <gk...@mac.com> wrote:
>>>
>>>> Even if the implementation is trivial, this still seems like it should
>> be
>>>> the responsibility of the application. This use case seems pretty
>> specific
>>>> to GUI builders. Just my 2 cents.
>>>>
>>>> On Feb 9, 2010, at 10:05 AM, Todd Volkert wrote:
>>>>
>>>>>>
>>>>>>> Also, I have worked a bit with KODO-JDO persistence library (don't be
>>>>>>> afraid yet:) ),
>>>>>>> and it has one neat feature in exceptions explanation. When wrong
>>>> entity
>>>>>>> name (table or column) appeared in query,
>>>>>>> exception not only says: "Wrong column name 'usrId', please fix it on
>>>> your
>>>>>>> own" but also suggests most probably correct value found by
>>>>>>> Levenshtein algorithm (
>>>> http://en.wikipedia.org/wiki/Levenshtein_distance),
>>>>>>> and the result looks like:
>>>>>>> "Wrong column name 'usrId', most probably correct value 'userId'".
>>>>>>> I think it is possible to add this feature to pivot.
>>>>>>>
>>>>>>
>>>>>> Not a bad suggestion, though I'd only vote to do it if the
>>>> implementation
>>>>>> were fairly trivial. We'd have to iterate over the bean's properties
>>>> (we
>>>>>> already have such an iterator), calculate the Levenshtein distance
>>>> between
>>>>>> that property and the specified key, and if that distance were small
>>>> enough,
>>>>>> include it in the exception. It may in fact be trivial :)
>>>>>>
>>>>>
>>>>> Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
>>>>> anyway), but if you wanted to try it out, see how intrusive or trivial
>>>> it'd
>>>>> be, and submit it as a patch, the class in question is located at
>>>>>
>>>>
>> http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
>>>>
>>>>
>>
>>
Re: WtkxBrowser
Posted by Todd Volkert <tv...@gmail.com>.
Except in this case, the client is a WTKX visualization tool that is just
blindly loading a WTKX file, so calls readObject() and gets an exception --
it has no way of knowing which property of which bean was responsible...
-T
On Tue, Feb 9, 2010 at 2:38 PM, Greg Brown <gk...@mac.com> wrote:
> I don't think it needs to be passed in the exception. The client code knows
> which property is being set and can perform the Levenshtein analysis if an
> exception is thrown.
>
> On Feb 9, 2010, at 2:20 PM, Todd Volkert wrote:
>
> > That's a good point, though it'd mean that the BeanException would need
> to
> > set the invalid key as an exception property.
> >
> > -T
> >
> > On Tue, Feb 9, 2010 at 12:05 PM, Greg Brown <gk...@mac.com> wrote:
> >
> >> Even if the implementation is trivial, this still seems like it should
> be
> >> the responsibility of the application. This use case seems pretty
> specific
> >> to GUI builders. Just my 2 cents.
> >>
> >> On Feb 9, 2010, at 10:05 AM, Todd Volkert wrote:
> >>
> >>>>
> >>>>> Also, I have worked a bit with KODO-JDO persistence library (don't be
> >>>>> afraid yet:) ),
> >>>>> and it has one neat feature in exceptions explanation. When wrong
> >> entity
> >>>>> name (table or column) appeared in query,
> >>>>> exception not only says: "Wrong column name 'usrId', please fix it on
> >> your
> >>>>> own" but also suggests most probably correct value found by
> >>>>> Levenshtein algorithm (
> >> http://en.wikipedia.org/wiki/Levenshtein_distance),
> >>>>> and the result looks like:
> >>>>> "Wrong column name 'usrId', most probably correct value 'userId'".
> >>>>> I think it is possible to add this feature to pivot.
> >>>>>
> >>>>
> >>>> Not a bad suggestion, though I'd only vote to do it if the
> >> implementation
> >>>> were fairly trivial. We'd have to iterate over the bean's properties
> >> (we
> >>>> already have such an iterator), calculate the Levenshtein distance
> >> between
> >>>> that property and the specified key, and if that distance were small
> >> enough,
> >>>> include it in the exception. It may in fact be trivial :)
> >>>>
> >>>
> >>> Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
> >>> anyway), but if you wanted to try it out, see how intrusive or trivial
> >> it'd
> >>> be, and submit it as a patch, the class in question is located at
> >>>
> >>
> http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
> >>
> >>
>
>
Re: WtkxBrowser
Posted by Greg Brown <gk...@mac.com>.
I don't think it needs to be passed in the exception. The client code knows which property is being set and can perform the Levenshtein analysis if an exception is thrown.
On Feb 9, 2010, at 2:20 PM, Todd Volkert wrote:
> That's a good point, though it'd mean that the BeanException would need to
> set the invalid key as an exception property.
>
> -T
>
> On Tue, Feb 9, 2010 at 12:05 PM, Greg Brown <gk...@mac.com> wrote:
>
>> Even if the implementation is trivial, this still seems like it should be
>> the responsibility of the application. This use case seems pretty specific
>> to GUI builders. Just my 2 cents.
>>
>> On Feb 9, 2010, at 10:05 AM, Todd Volkert wrote:
>>
>>>>
>>>>> Also, I have worked a bit with KODO-JDO persistence library (don't be
>>>>> afraid yet:) ),
>>>>> and it has one neat feature in exceptions explanation. When wrong
>> entity
>>>>> name (table or column) appeared in query,
>>>>> exception not only says: "Wrong column name 'usrId', please fix it on
>> your
>>>>> own" but also suggests most probably correct value found by
>>>>> Levenshtein algorithm (
>> http://en.wikipedia.org/wiki/Levenshtein_distance),
>>>>> and the result looks like:
>>>>> "Wrong column name 'usrId', most probably correct value 'userId'".
>>>>> I think it is possible to add this feature to pivot.
>>>>>
>>>>
>>>> Not a bad suggestion, though I'd only vote to do it if the
>> implementation
>>>> were fairly trivial. We'd have to iterate over the bean's properties
>> (we
>>>> already have such an iterator), calculate the Levenshtein distance
>> between
>>>> that property and the specified key, and if that distance were small
>> enough,
>>>> include it in the exception. It may in fact be trivial :)
>>>>
>>>
>>> Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
>>> anyway), but if you wanted to try it out, see how intrusive or trivial
>> it'd
>>> be, and submit it as a patch, the class in question is located at
>>>
>> http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
>>
>>
Re: WtkxBrowser
Posted by Todd Volkert <tv...@gmail.com>.
That's a good point, though it'd mean that the BeanException would need to
set the invalid key as an exception property.
-T
On Tue, Feb 9, 2010 at 12:05 PM, Greg Brown <gk...@mac.com> wrote:
> Even if the implementation is trivial, this still seems like it should be
> the responsibility of the application. This use case seems pretty specific
> to GUI builders. Just my 2 cents.
>
> On Feb 9, 2010, at 10:05 AM, Todd Volkert wrote:
>
> >>
> >>> Also, I have worked a bit with KODO-JDO persistence library (don't be
> >>> afraid yet:) ),
> >>> and it has one neat feature in exceptions explanation. When wrong
> entity
> >>> name (table or column) appeared in query,
> >>> exception not only says: "Wrong column name 'usrId', please fix it on
> your
> >>> own" but also suggests most probably correct value found by
> >>> Levenshtein algorithm (
> http://en.wikipedia.org/wiki/Levenshtein_distance),
> >>> and the result looks like:
> >>> "Wrong column name 'usrId', most probably correct value 'userId'".
> >>> I think it is possible to add this feature to pivot.
> >>>
> >>
> >> Not a bad suggestion, though I'd only vote to do it if the
> implementation
> >> were fairly trivial. We'd have to iterate over the bean's properties
> (we
> >> already have such an iterator), calculate the Levenshtein distance
> between
> >> that property and the specified key, and if that distance were small
> enough,
> >> include it in the exception. It may in fact be trivial :)
> >>
> >
> > Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
> > anyway), but if you wanted to try it out, see how intrusive or trivial
> it'd
> > be, and submit it as a patch, the class in question is located at
> >
> http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
>
>
Re: WtkxBrowser
Posted by Greg Brown <gk...@mac.com>.
Even if the implementation is trivial, this still seems like it should be the responsibility of the application. This use case seems pretty specific to GUI builders. Just my 2 cents.
On Feb 9, 2010, at 10:05 AM, Todd Volkert wrote:
>>
>>> Also, I have worked a bit with KODO-JDO persistence library (don't be
>>> afraid yet:) ),
>>> and it has one neat feature in exceptions explanation. When wrong entity
>>> name (table or column) appeared in query,
>>> exception not only says: "Wrong column name 'usrId', please fix it on your
>>> own" but also suggests most probably correct value found by
>>> Levenshtein algorithm (http://en.wikipedia.org/wiki/Levenshtein_distance),
>>> and the result looks like:
>>> "Wrong column name 'usrId', most probably correct value 'userId'".
>>> I think it is possible to add this feature to pivot.
>>>
>>
>> Not a bad suggestion, though I'd only vote to do it if the implementation
>> were fairly trivial. We'd have to iterate over the bean's properties (we
>> already have such an iterator), calculate the Levenshtein distance between
>> that property and the specified key, and if that distance were small enough,
>> include it in the exception. It may in fact be trivial :)
>>
>
> Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
> anyway), but if you wanted to try it out, see how intrusive or trivial it'd
> be, and submit it as a patch, the class in question is located at
> http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
Re: WtkxBrowser
Posted by Todd Volkert <tv...@gmail.com>.
>
>> Also, I have worked a bit with KODO-JDO persistence library (don't be
>> afraid yet:) ),
>> and it has one neat feature in exceptions explanation. When wrong entity
>> name (table or column) appeared in query,
>> exception not only says: "Wrong column name 'usrId', please fix it on your
>> own" but also suggests most probably correct value found by
>> Levenshtein algorithm (http://en.wikipedia.org/wiki/Levenshtein_distance),
>> and the result looks like:
>> "Wrong column name 'usrId', most probably correct value 'userId'".
>> I think it is possible to add this feature to pivot.
>>
>
> Not a bad suggestion, though I'd only vote to do it if the implementation
> were fairly trivial. We'd have to iterate over the bean's properties (we
> already have such an iterator), calculate the Levenshtein distance between
> that property and the specified key, and if that distance were small enough,
> include it in the exception. It may in fact be trivial :)
>
Dmitry, to be clear, I wasn't planning on doing this (I'm too busy now
anyway), but if you wanted to try it out, see how intrusive or trivial it'd
be, and submit it as a patch, the class in question is located at
http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanDictionary.java
Re: Re: WtkxBrowser
Posted by Дмитрий <dm...@yandex.ru>.
Todd,
> > 1. Exception appears when wtkx data format is wrong:
> > org.apache.pivot.beans.PropertyNotFoundException: Property "text1" does not
> > exist or is read-only.
> > at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
> > at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
> > at org.apache.pivot.wtkx.WTKXSerializer.processEndElement(Unknown
> > Source)
> > at org.apache.pivot.wtkx.WTKXSerializer.readObject(Unknown Source)
> > at org.apache.pivot.wtkx.WTKXSerializer.readObject(Unknown Source)
> > at
> > org.apache.pivot.tools.wtkxbrowser.WtkxBrowser$ResourcesChangesMonitorRunnable.reload(WtkxBrowser.java:360)
> > I want to have line number where problem is happened.
> >
>
> Did you not see more info logged ("An error occurred while processing
> element <...> starting at line number ...") above this stack trace? It
> should be, but perhaps there's a bug.
Now I have checked a console, indeed there is an error message:
An error occurred while processing element <Label> starting at line number 9 in file /C:/work/WtkxBrowser/./demo.wtkx:
org.apache.pivot.beans.PropertyNotFoundException: Property "text1" does not exist or is read-only.
at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
.....................
But line "An error occurred while processing element <Label> starting at line number 9 in file /C:/work/WtkxBrowser/./demo.wtkx:"
is not a part of exception stacktrace so I can't reproduce same message using ex.printStackTrace(myOwnInmemoryStream);
That is why problem line number is not displayed in WtkxBrowser.
--
Dmitry
Re: WtkxBrowser
Posted by Todd Volkert <tv...@gmail.com>.
Dmitry,
This is great feedback - thank you! I've responded inline.
I have fixed known bugs in wtkx browser (
> http://issues.apache.org/jira/browse/PIVOT-30).
> Results: code, screenshots and distribution, can be found at:
> http://code.google.com/p/wtkxbrowser/
>
This looks cool. I've been swamped the past month with other projects and
will be for at least another few weeks, but I plan to check out the code and
have a deeper look.
>
> 1. Exception appears when wtkx data format is wrong:
> org.apache.pivot.beans.PropertyNotFoundException: Property "text1" does not
> exist or is read-only.
> at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
> at org.apache.pivot.beans.BeanDictionary.put(Unknown Source)
> at org.apache.pivot.wtkx.WTKXSerializer.processEndElement(Unknown
> Source)
> at org.apache.pivot.wtkx.WTKXSerializer.readObject(Unknown Source)
> at org.apache.pivot.wtkx.WTKXSerializer.readObject(Unknown Source)
> at
> org.apache.pivot.tools.wtkxbrowser.WtkxBrowser$ResourcesChangesMonitorRunnable.reload(WtkxBrowser.java:360)
> I want to have line number where problem is happened.
>
Did you not see more info logged ("An error occurred while processing
element <...> starting at line number ...") above this stack trace? It
should be, but perhaps there's a bug.
> Also, I have worked a bit with KODO-JDO persistence library (don't be
> afraid yet:) ),
> and it has one neat feature in exceptions explanation. When wrong entity
> name (table or column) appeared in query,
> exception not only says: "Wrong column name 'usrId', please fix it on your
> own" but also suggests most probably correct value found by
> Levenshtein algorithm (http://en.wikipedia.org/wiki/Levenshtein_distance),
> and the result looks like:
> "Wrong column name 'usrId', most probably correct value 'userId'".
> I think it is possible to add this feature to pivot.
>
Not a bad suggestion, though I'd only vote to do it if the implementation
were fairly trivial. We'd have to iterate over the bean's properties (we
already have such an iterator), calculate the Levenshtein distance between
that property and the specified key, and if that distance were small enough,
include it in the exception. It may in fact be trivial :)
> 2. org.apache.pivot.wtk.ListView
> Here is 3 methods:
> getSelectedItem()->Object
> getSelectedIndex()->int (index)
> getItemAt()->???
> I was expected (with expierence based on usage of first two methods) that
> getItemAt() should return Object,
> but real result value is int (index).
>
It's meant to have parity with TableView.getRowAt(),
TableView,getColumnAt(), TreeView.getNodeAt(), which give indexes (or a
Path) given x or y coordinates. However, given the naming of those other
two methods, I can understand your confusion (whereas the method you're
looking for is getListData().get(index:int)). We could change the method to
getIndexAt(). I'm not advocating this yet because we haven't talked it out
as a dev team -- I'm just thinking out loud :)
>
> 3. tabPane.getTabs().remove(0, tabPane.getTabs().getLength());
> Yes, I understand that collections framework interfaces is designed to be
> reasonable small in
> implementation. But is it possible to provide some utility class with
> static methods:
> clearList(List)
> addAll(List to, List from)
> containsAll(List target, List pattern)
> and so on. There is method clear() in ArrayList
> http://pivot.apache.org/1.4/docs/api/org/apache/pivot/collections/ArrayList.html#clear()<http://pivot.apache.org/1.4/docs/api/org/apache/pivot/collections/ArrayList.html#clear%28%29>
> But I can't be sure that I'm working with array list all the time.
>
There are three ways we could go with this. (1) Add a clear() method to
TabPane.TabSequence. (2) Add a Sequence.Util static class that contains a
few common sequence utility methods, like clear(), add(Sequence,Sequence),
contains(Sequence,Sequence). (3) Leave it to the application developer to
build their own static utility methods that best suit their application.
I'd be fine with the addition of a Sequence.Util class, since there are
certain operations on Sequences that are ubiquitous. However, I'd caution
against putting too much in there -- in general, we've shied away from
putting methods in the platform when they're in danger of being too
application-specific.
>
> 4. I have problem with focus for component embedded into Prompt window.
> Here is the code:
> final TextInput textInput = new TextInput();
> Prompt.prompt(MessageType.QUESTION, "Enter name for a new tab",
> textInput, window, new SheetCloseListener() {
> @Override
> public void sheetClosed(Sheet sheet) {
> if (sheet.getResult() == true) {
> addTab(model.createContainer(),
> textInput.getText());
> }
> }
> });
> When prompt appears, my text field is not focused, but I expect that user
> will provide name for a new tab
> through this component. So user is forced to click on my text-input with
> mouse or press Tab to switch focus.
> Is any way to automatically request focus for text-field in this case?
>
When a window is opened (like a Prompt), moveToFront() is called on it,
which I thought would also call requestFocus() on the window... but I must
be wrong :). I'm leaving this one to Greg since he's the expert on Window &
its subclasses.
> 5. setPrompt() method exists for TextInput component but not for ListView:
>
> http://pivot.apache.org/1.4/docs/api/org/apache/pivot/wtk/TextInput.html#setPrompt(java.lang.String)<http://pivot.apache.org/1.4/docs/api/org/apache/pivot/wtk/TextInput.html#setPrompt%28java.lang.String%29>
>
>
> In wtkx browser I have implemented next feature: when user clicks to empy
> list of wtkx resources
> then FileBrowserSheet appears automatically to select new resources.
> It will be good to suggest this feature to user like "Click here to add new
> resources" in prompt text for ListView.
>
An interesting suggestion. Normally, this kind of thing would be the
responsibility of the list view's renderer, but when there are no data
items, the renderer is never invoked because there's nothing to render.
However, it feels a little weird to make the skin responsible for painting a
prompt when the skin won't respond to clicks on the prompt (unlike the case
of TextInput). This *feels* like something that you should do using a
Decorator, but maybe that's just me -- what do others on this list think?