Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to Clear VLayout and Add new Item?

    Hello Friends,

    I am confused by few things. I have created three layouts.
    1. HLayout - main layout which will contain other two layouts
    2. VLayout - menu layout which will be displayed on left side
    3. Valyout - content layout which will be placed on right side.

    On clicking of any menu from left side right Canvas items should be remove and new Canvas Items should be getting displayed.

    For clearing the old item i am using .clear() method. And for adding new Canvas on right side i am using .addMember() method. And after clear and add operation i am calling the .draw() method again.

    But the main problem is that the old Canvas Items is not getting cleared from VLayout and new Canvas item added in VLayout. Can you suggest where i am being wrong?

    Below is the code for same thing:

    EntryPoint.java:
    Code:
    final HLayout mainPanel = new HLayout();
    mainPanel.setHeight100();
    		
    final VLayout firstPanel = new VLayout();
    firstPanel.setHeight100();
    firstPanel.setWidth(100);
    firstPanel.setShowResizeBar(true);
    
    final VLayout secondPanel = new VLayout(); 
    
    Button btn1 = new Button("Click Me");
    btn1.addClickHandler(new ClickHandler() {
    			
    	@Override
    	public void onClick(ClickEvent event) {
    		secondPanel.clear();
    		secondPanel.addChild(new CustomDSTest());
    		secondPanel.draw();
    	}
    });
    
    firstPanel.addMember(btn1);
    
    mainPanel.addMember(firstPanel);
    mainPanel.addMember(secondPanel);	
    mainPanel.draw();
    CustomDSTest.java:
    Code:
    public class CustomDSTest extends Canvas {
               public CustomDSTest() {
                       //Create the Vstack containing ListGrid, DynamicForm
                       this.addChild(Vstack);
               }
    }

    #2
    To remove a member from a layout, call layout.removeMember()

    Comment


      #3
      Thanks for such a quick guidance. It was so helpful and resolved the problem.

      Comment


        #4
        Hi every body,

        i'm just wondering, if the member is going to be destroyed, if i call layout.removeMember() for it?

        actually i hope so :-)

        andre

        Comment


          #5
          ok,

          my layout animates members: layout.setAnimateMembers(true);
          i just tested the layout.removeMember() method
          the member is not destroyed, after all it seems just reasonable...

          now if i call the member.destroy() method, i get this error
          Code:
          08:55:17.245:TMR2:WARN:Animation:Attempt to fire registered animation:{ID: "_51", target: [DynamicForm ID:isc_DynamicForm_15], callback: Canvas.fireAnimationHide(), duration: 300, elapsed: 41, totalFrames: 8, currentFrame: 1, maxDuration: 900, acceleration: [c]Animation.smoothEnd()}
          Caused an error:No valid target. Target may have been destroyed since animation commenced
          and this is right, because the layout tries to animate hide, and the destroy() method kills the member at this moment... additionally it looks not too good...

          so how can i remove the member from a layout and afterwards destroy it?

          is this a possible way?
          Code:
          public static void removeAndDestroy(final Layout layout, final Canvas member) {
                  member.animateHide(AnimationEffect.WIPE, new AnimationCallback() {
                      public void execute(boolean earlyFinish) {
                          layout.removeMember(member);
                          member.destroy();
                      }
                  });
              }
          cheers
          andre

          Comment

          Working...
          X