pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gkbr...@mac.com>
Subject Re: Trouble adding components dynamically
Date Mon, 01 Mar 2010 19:55:01 GMT
I can certainly understand your frustration. We've all been there.  :-)

You may want to look into using the Bindable interface. It is designed to help simplify the
task of loading and binding to multiple WTKX files and includes. It is new and not well-documented
at the moment, but you can see an example here:

http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/BindableTest.java
http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/BindableWindow.java
http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/BindableWindow.json
http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/bindable_test.wtkx

Basically, the idea is that you create a custom subclass of your root element class that implements
Bindable. Then WTKXSerializer calls the initialize() method to notify you when all of the
variables have been bound.


On Mar 1, 2010, at 2:12 PM, David McNelis wrote:

> I figured out what my issue was, and it has to do, I think, with Greg’s earlier email
about what I’m trying to add to.
>  
> Because I initially lacked a bit of understanding about the pre-processing of the wtkx:include
directive I had set up multiple  WTKXSerializers for each of my different markup files in
order to bind what I needed to be able to edit.  So, my “parent” was being set up by serializer
B, while the “grandparent” was in serializer A.  When I just changed the parent to be
built based off of serializer A, everything started showing up.
>  
> Thank you all, for your patience in helping me with this problem.  I don’t know if
I should laugh at the simplicity of the solution, or cry for the day and a half I’ve been
pounding my head on my desk for this because I’m an idiot.
>  
> Again, thanks.
>  
> David
>  
> From: Todd Volkert [mailto:tvolkert@gmail.com] 
> Sent: Monday, March 01, 2010 11:12 AM
> To: user@pivot.apache.org
> Subject: Re: Trouble adding components dynamically
>  
> Hi David,
> 
> I tried reproducing your example given your code, and the child.wtkx file shows up for
me when added programatically.  One thing was a little weird though -- the fact that you have
the preferred size of the parent border set to the same as the preferred size of the child
box pane means that each child box pane will take up the size of the border entirely.  Couple
this with the fact that you're using a verticalScrollBarPolicy of "fill" means that you're
guaranteed to never see any but the first box pane.  If I let the scroll pane keep its default
vertical scroll bar policy ("auto"), then a scroll bar shows up, and I see the child box panes...
> 
> For reference, here's my exact test case based on your samples:
> 
> gp.wtkx:
> 
> <Window title="Template Builder UI!"
>     maximized="true"
>     xmlns:wtkx="http://pivot.apache.org/wtkx"
>     xmlns="org.apache.pivot.wtk">
>     <content>
>         <Border styles="{padding:12}">
>             <content>
>                 <BoxPane>
>                     <TabPane>
>                         <tabs>
>                             <BoxPane TabPane.label="tab number 1"
>                                 styles="{horizontalAlignment:'center', verticalAlignment:'center'}"
>                                 wtkx:id="tab1">
>                                 <!-- content -->
>                             </BoxPane>
>                             <BoxPane wtkx:id="tab2" TabPane.label="tab number 2"
>                                 styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
>                                 <wtkx:include src="parent.wtkx">
>                                 </wtkx:include>
>                             </BoxPane>
>                         </tabs>
>                     </TabPane>
>                 </BoxPane>
>             </content>
>         </Border>
>     </content>
> </Window>
> 
> parent.wtkx:
> 
> <Border xmlns:wtkx="http://pivot.apache.org/wtkx"
>     xmlns="org.apache.pivot.wtk"
>     preferredWidth="800" preferredHeight="600">
>     <content>
>         <ScrollPane horizontalScrollBarPolicy="fill" verticalScrollBarPolicy="fill">
>             <view>
>                 <BoxPane orientation="vertical" wtkx:id="containerPane"/>
>             </view>
>         </ScrollPane>
>     </content>
> </Border>
> 
> child.wtkx: (same as yours)
> 
> Foo.java
> 
> public class Foo implements Application {
>     private Window window = null;
> 
>     @WTKX public BoxPane containerPane;
> 
>     @Override
>     public void startup(Display display, Map<String, String> properties) throws
Exception {
>         WTKXSerializer wtkxSerializer = new WTKXSerializer();
>         window = (Window)wtkxSerializer.readObject(this, "gp.wtkx");
>         wtkxSerializer.bind(this);
> 
>         for(int i = 0; i < 10; i++) {
>             WTKXSerializer wtkx = new WTKXSerializer();
>             BoxPane singlePane = null;
> 
>             singlePane = (BoxPane)wtkx.readObject(this, "child.wtkx");
>             containerPane.add(singlePane);
>         }
> 
>         window.open(display);
>     }
> 
>     @Override
>     public boolean shutdown(boolean optional) throws Exception {
>         if (window != null) {
>             window.close();
>         }
> 
>         return false;
>     }
> 
>     @Override
>     public void suspend() {
>     }
> 
>     @Override
>     public void resume() {
>     }
> }
> 
> 
> On Mon, Mar 1, 2010 at 11:28 AM, Greg Brown <gkbrown@mac.com> wrote:
> Yeah, your understanding is correct.
>  
> I don't immediately see the problem - anyone else have any ideas?
>  
>  
> On Mar 1, 2010, at 11:23 AM, David McNelis wrote:
> 
> 
> I’m including the “parent” inside the tab in the ‘grandparent’ wtkx file, which
is structured thusly:
>  
> <?xml version="1.0" encoding="UTF-8"?>
> <Window title="Template Builder UI!" maximized="true" xmlns:wtkx="http://pivot.apache.org/wtkx"
xmlns="org.apache.pivot.wtk">
> <content>
> <Border styles="{padding:12}">
>  
> <content>
>                                
>                 <BoxPane>
>                 <TabPane>
>                 <tabs>
>                                 <BoxPane TabPane.label="tab number 1"
>                                                 styles="{horizontalAlignment:'center',
verticalAlignment:'center'}"
>                                                 wtkx:id="tab1">
>                                                                
>                                                                 <!-- content -->
>                                 </BoxPane>
>  
>                                 <BoxPane wtkx:id="tab2" TabPane.label="tab number
2"
>                                                 styles="{horizontalAlignment:'center',
verticalAlignment:'center'}">
>                                                 <wtkx:include
>                                                                 src="parent.xml">
>                                                 </wtkx:include>
>                                 </BoxPane>
>  
> </tabs></TabPane></BoxPane></content></Border></content></Window>
>  
> My understanding is that the parent.xml would be compiled into the ‘grandparent’
file and would end up in the tab panes sequence.  Do I understand that correctly? 
>  
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Monday, March 01, 2010 10:11 AM
> To: user@pivot.apache.org
> Subject: Re: Trouble adding components dynamically
>  
> Are you adding the parent to the tab pane's tab sequence, or directly to the tab pane
itself? If you are doing the latter, it could definitely be the cause of the problem.
>  
> On Mar 1, 2010, at 11:08 AM, David McNelis wrote:
>  
> 
> I also tried adding a test label to my parent wtkx, then loading it into the code, with
>  
> Label testLabel = (Label) parentSerializer.get(“testLabel”);
>  
> I then spit out the current label text.  Then set the label to different text.  However
the new text value never ends up being re-painted on the screen, despite direct calls to repaint
the label, the box pane, the window…  but when I spit the testLabel.getText() to system
out again, it does contain the new value.
>  
> I don’t know if it makes any difference but the parent component hear is living inside
a TabPane…I had left that out previously because it seems kind of inconsequential…and
in my other TabPanes I haven’t had issues adding or removing components.
>  
> From: David McNelis [mailto:Dmcnelis@sharedmarketing.com] 
> Sent: Monday, March 01, 2010 9:03 AM
> To: user@pivot.apache.org
> Subject: RE: Trouble adding components dynamically
>  
> Hopefully this doesn’t get too jacked up in email, but here is an excerpt of the code
and the wtkx files that I’m using.    I also tried just adding a test label to the containerPane
as well and that did not show up either.  But if I wtkx:include the child component as a child
of the “containerPane” then the child component does display.
>  
> Code:
>  
> containerPane = (BoxPane)parentSerializer.get("containerPane");
>  
> for(int i=0, n=array.getLength(); i<n; i++){           
>                 WTKXSerializer wtkx = new WTKXSerializer();
>                 BoxPane singlePane = null;
>  
>                 try {
>                                 singlePane = (BoxPane)wtkx.readObject(this, "child.wtkx");
>                 } catch (IOException e) {
>                                                                
>                                 e.printStackTrace();
>                 } catch (SerializationException e) {
>                                                
>                                 e.printStackTrace();
>                 }
>                                
>                 singlePane.setVisible(true);
>                                
>                 containerPane.add(singlePane);
> }
>  
>  
> Parent component:
>  
> <Border xmlns:wtkx="http://pivot.apache.org/wtkx" xmlns="org.apache.pivot.wtk" preferredWidth="800"
preferredHeight="600">
>                
> <content>
>  
> <ScrollPane horizontalScrollBarPolicy="fill" verticalScrollBarPolicy="fill">
>  
>                 <view>
>  
>                                 <BoxPane orientation="vertical" wtkx:id="containerPane">
>                 </BoxPane>
> </view></ScrollPane></content></Border>
>  
> Child component:
>  
> <BoxPane xmlns:wtkx="http://pivot.apache.org/wtkx"
> xmlns="org.apache.pivot.wtk" preferredWidth="800" preferredHeight="600" orientation="vertical">
 
>  
> <BoxPane orientation="vertical" wtkx:id="childPane">
>  
>                                
> <BoxPane orientation="horizontal">
>                                 <Label text="Blah blah"></Label>
>                                 <ListButton wtkx:id="button1"></ListButton>
>                                 <Label text="Blah blah:"></Label>
>                                 <ListButton wtkx:id="button2"></ListButton>
>                 </BoxPane>
>                 <BoxPane orientation="vertical">
>                 <Label text="Filler:"></Label>
>  
>                 <Border>
>                 <content>
>                 <ScrollPane preferredHeight="25"
>                                 horizontalScrollBarPolicy="fill"
>                                 verticalScrollBarPolicy="fill_to_capacity">
>                 <view>
>                 <TextArea wtkx:id="textarea1"
>                                 preferredWidth="600" text="Sample Text">
>                 </TextArea>
>                 </view>
>                 </ScrollPane>
>                 </content>
>                 </Border>
>                 </BoxPane>
>                 <BoxPane orientation="vertical">
>                 <Label text="More stuff:"></Label>
>  
>                 <Border>
>                 <content>
>                 <ScrollPane preferredHeight="100"
>                 horizontalScrollBarPolicy="fill"
>                 verticalScrollBarPolicy="fill_to_capacity">
>                 <view>
>                                 <TextArea wtkx:id="textarea2"
>                                                 preferredWidth="600" text="Sample Text">
>                                 </TextArea>
>                 </view>
>                 </ScrollPane>
>                 </content>
>                 </Border>
> </BoxPane>
> </BoxPane>
> </BoxPane>
>  
> From: Greg Brown [mailto:gkbrown@mac.com] 
> Sent: Monday, March 01, 2010 8:40 AM
> To: user@pivot.apache.org
> Subject: Re: Trouble adding components dynamically
>  
> That sounds like it should work. Can you provide some sample code? That might help identify
the issue.
>  
> On Mar 1, 2010, at 9:28 AM, David McNelis wrote:
>  
> 
> Morning,
>  
> I have a situation where I am cycling through an array and for each element in the array
I need to add a set of components to a BoxPane.  To do this, I wrote a wtkx file that contained
the components that I need to create each time I go through the array.  As I go through an
iteration I read in the wtkx file with a WTKXSerializer.readObject, casting into another BoxPane,
then attempt to add the new object to my parent.  Essentially like so:
>  
> WTKXSerializer wtkx = new WTKXSerializer();
> BoxPane child = (BoxPane) wtxk.readObject(this,”myfile.wtkx”);
>  
> parent.add(child);
>  
> This as I go through my application I get no errors, no warnings, but myfile.wtkx does
not actually display.  I tried doing something akin to child.setVisible(true), but it hasn’t
made any difference. 
>  
> I thought that maybe there was an issue with my parent BoxPane, so I tried including
myfile.wtkx as a wtkx:include parameter in the parent file, and to my surprise the components
in myfile.wtkx displayed as I would have expected it to using the programmatic method.  Am
I doing something clearly wrong?  Is there likely an issue with my parent or child wtkx file
that I should be looking for?
>  
> Also, the parent.add(child) is executing…its not like I never get to that block of
code…feel like I need to mention that since it’s the first thing that comes to mind as
a simple issue.
>  
> Thanks for any thoughts.
>  
> David
>  
>  
>  
>  
>  
>  


Mime
View raw message