pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anton dos santos <adsan...@free.fr>
Subject Re: Adding listeners in BXML
Date Wed, 02 Feb 2011 17:58:46 GMT
Hi

Most of the time I try to put in BXML the GUI layout and user interactions, whereas the bindable
is 
for  back-end integration, data transformations and loading the GUI.
In this case, I wanted to have buttons that get pressed when user hits return key and since
I prefer 
java to javascript ...
Anyway, I can can live without this feature, but at least it would be good to document in
the 
tutorial that only scripted listeners are possible in BXML.

Regards
Anton

On 02/02/2011 05:11, Greg Brown wrote:
> Hi,
>
> I had replied to this last night, but apparently my phone decided to send the reply to
the 
> original sender, not the list.  :-P
>
> Listener list properties are currently handled differently than other properties. The
assumption 
> was that if you want to define a listener in Java or other compiled language, you'll
probably want 
> to use Bindable and attach your listeners that way. It is possible to support the described
syntax 
> - I just didn't expect developers to want to do that.  :-)
>
> G
>
> On Feb 1, 2011, at 7:55 AM, Chris Bartlett wrote:
>
>> Anton,
>>
>> Thanks for all the info.
>>
>> I was just getting ready to reply back to you to let you know that I was wrong, and
this is not 
>> currently possible.  Only listeners defined in script are supported.
>>
>> I'm not sure if this is due to a technical limitation or if it is just something
that has not 
>> been required/requested.
>> Greg - perhaps you could clarify?
>>
>> Chris
>>
>> On 1 February 2011 22:40, anton dos santos <adsantos@free.fr <mailto:adsantos@free.fr>>
wrote:
>>
>>     Here the exception:
>>     An error occurred at line number 10 in file /D:/DVPT/PIVOT/src/test/ButtonPressTest.bxml:
>>     java.lang.NullPointerException: null script
>>             at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:122)
>>             at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
>>             at org.apache.pivot.beans.BXMLSerializer.processEndElement(BXMLSerializer.java:1250)
>>             at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:440)
>>             at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:614)
>>             at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:568)
>>             at org.apache.pivot.beans.BXMLSerializer.readObject(BXMLSerializer.java:534)
>>             at test.ButtonPressTest.startup(ButtonPressTest.java:37)
>>             at
>>     org.apache.pivot.wtk.DesktopApplicationContext$2.run(DesktopApplicationContext.java:594)
>>             at
>>     org.apache.pivot.wtk.ApplicationContext$QueuedCallback.run(ApplicationContext.java:1474)
>>             at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
>>             at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
>>             at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
>>             at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
>>             at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
>>             at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
>>             at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
>>             at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
>>     Here is the code: ButtonPressTest.java
>>     package test;
>>     import org.apache.pivot.beans.BXMLSerializer;
>>     import org.apache.pivot.collections.Map;
>>     import org.apache.pivot.wtk.*;
>>     public class ButtonPressTest implements Application {
>>       public static final class ButtonPress implements ButtonPressListener {
>>         public void buttonPressed(Button button) {
>>           System.out.println("button pressed");
>>         }
>>       }
>>       private Window window = null;
>>       public void startup(Display display, Map<String, String> properties)
throws Exception {
>>         BXMLSerializer bxmlSerializer = new BXMLSerializer();
>>         window = (Window) bxmlSerializer.readObject(ButtonPressTest.class, "ButtonPressTest.bxml");
>>         ((PushButton)bxmlSerializer.getNamespace().get("Button2")).getButtonPressListeners().add(
>>     new ButtonPress());
>>         window.open(display);
>>       }
>>       public boolean shutdown(boolean optional) throws Exception {
>>         if (window != null) {
>>           window.close();
>>         }
>>         return false;
>>       }
>>       public void suspend() throws Exception {
>>       }
>>       public void resume() throws Exception {
>>       }
>>       public static void main(String[] args) {
>>         DesktopApplicationContext.main(ButtonPressTest.class, args);
>>       }
>>     }
>>     And the BXML: ButtonPressTest.bxml
>>     <Window title="Test" maximized="true"
>>         xmlns:bxml="http://pivot.apache.org/bxml" <http://pivot.apache.org/bxml>
>>         xmlns:test="test"
>>         xmlns="org.apache.pivot.wtk">
>>     <BoxPane orientation="horizontal">
>>     <PushButton bxml:id="Button1" buttonData="Listener added in BXML">
>>     <buttonPressListeners>
>>     <test:ButtonPressTest.ButtonPress/>
>>     </buttonPressListeners>
>>     </PushButton>
>>     <PushButton bxml:id="Button2" buttonData="Listener added in Java">
>>     </PushButton>
>>     </BoxPane>
>>     </Window>
>>
>>
>>
>>     On 31/01/2011 21:16, Chris Bartlett wrote:
>>>     I am pretty sure that it is possible, and the syntax looks OK to me.  I don't
have a dev
>>>     environment in front of me to check though.
>>>
>>>     What exception are you seeing?  Can you try to post a short example of a
simple listener and
>>>     BXML which demonstrate the exception.
>>>
>>>     Chris
>>>
>>>     On 1 February 2011 02:13, anton dos santos <adsantos@free.fr <mailto:adsantos@free.fr>>
wrote:
>>>
>>>         Hi
>>>         I want to add a listener coded in java to a button. I tried following
syntax:
>>>
>>>         |||<||PushButton| |buttonData||=||"Click Me!"||>|
>>>         |||<||buttonPressListeners||>|
>>>         |<utils:MyListener/>|
>>>         |||</||buttonPressListeners||>|
>>>         |||</||PushButton||>|
>>>
>>>         but got an exception.
>>>         It seems to me that only scripts can be added as listeners in BXML. Is
this right or am
>>>         I doing something wrong in the above code ?
>>>
>>>         Regards
>>>         Anton
>>>
>>>
>>
>>
>


Mime
View raw message