Announcement

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

    How to Hide a Tile from a TileLayout?

    I am trying to initially hide a Tile from a TileLayout.
    I tried many different ways to do it, and some work, but others do not work: see code below.
    I expected to be able to add a Canvas to a TileLayout, then call canvas.hide (), and for that Canvas to "disappear", but it does not.

    This is easy to work-around in a simple test environment, but not so much when I am running in an MVC/MVP where I create a layout in one place, and it gets added to the UI in a different place...
    At any rate, I am looking for suggestions/workarounds to effectively accomplish this:
    Code:
    final TileLayout tileLayout = new TileLayout ();
    final Canvas tile = new Canvas ();
    tileLayout.addTile (tile);
    tile.hide (); // seems to not work
    Running
    SmartGWT 3.0
    GWT 2.3.0
    Chrome 17.0.963.56 m
    FireFox 6.0.2

    Sample code
    Code:
    import com.smartgwt.client.widgets.tile.TileLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.DrawHandler;
    import com.smartgwt.client.widgets.events.DrawEvent;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.core.client.Scheduler;
    
    public class TestTileLayoutHideTile implements EntryPoint {
    
      // my attributes
      final Canvas tile1 = new Canvas ();
      final Canvas tile2 = new Canvas ();
      final Canvas tile3 = new Canvas ();
    
      /**
       * The EntryPoint interface
       */
      public void onModuleLoad () {
    
        // create a TileLayout
        final TileLayout tileLayout = new TileLayout () {
          @Override
          public void onDraw () {
            // propagate
            super.onDraw ();
    
            // BUG? initially hide tile2, but the Tile still shows
            // GWT.log ("TileLayout.onDraw (): hiding tile2");
            // tile2.hide ();
          }
        };
        final int tileWidth = 300;
        final int tileMargin = 25;
        tileLayout.setShowEdges (false);
        tileLayout.setTileWidth (tileWidth);
        tileLayout.setTileHeight (100);
        tileLayout.setTileMargin (tileMargin);
        tileLayout.setWidth (tileWidth * 2 + tileMargin * 3 + tileMargin);
        tileLayout.setHeight (400);
        tileLayout.setAnimateTileChange (true);
    
        // add a couple tiles
        tile1.setBackgroundColor ("red");
        tileLayout.addTile (tile1);
    
        tile2.setBackgroundColor ("green");
        tileLayout.addTile (tile2);
    
        tile3.setBackgroundColor ("blue");
        tileLayout.addTile (tile3);
    
        // BUG? initially hide tile2, but the Tile still shows
        // GWT.log ("hiding tile2 after adding Tile to TileLayout");
        // tile2.hide ();
    
        // BUG? this gets called, but the tile stil shows
        tileLayout.addDrawHandler (new DrawHandler () {
          public void onDraw (final DrawEvent event) {
            // GWT.log ("DrawHandler.onDraw (): hiding tile2");
            // tile2.hide ();
          }
        });
        
        // this seems to work
        final Scheduler scheduler = Scheduler.get ();
        scheduler.scheduleDeferred (new Scheduler.ScheduledCommand() {
          public void execute() {
            GWT.log ("Deferred: hiding tile2");
            tile2.hide ();
          }
        });
    
        // show/hide tile2
        final IButton showTile2Button = new IButton ();
        showTile2Button.setTitle ("Show Tile 2");
        showTile2Button.addClickHandler (new ClickHandler () {
          public void onClick (final ClickEvent event) {
            tile2.show ();
          }
        });
    
        final IButton hideTile2Button = new IButton ();
        hideTile2Button.setTitle ("Hide Tile 2");
        hideTile2Button.addClickHandler (new ClickHandler () {
          public void onClick (final ClickEvent event) {
            tile2.hide ();
          }
        });
    
        // display
        final VLayout layout = new VLayout ();
        layout.addMember (tileLayout);
        layout.addMember (showTile2Button);
        layout.addMember (hideTile2Button);
        layout.show ();
        
        // this seems to work
        // GWT.log ("hiding tile2 after adding showing TileLayout");
        // tile2.hide ();
      }
    }
    Attached Files

    #2
    The workaround I am using is to NOT add tiles that I want initially hidden, but rather add them later when I known I need them.

    However this is more work than I want because:
    1. I have to keep track of which tiles have already been added so I do not add them again, and
    2. It is harder to maintain the order of tiles. If I could add the tiles initially hidden, I would expect that showing them would automatically make space within the layout in the order in which I added them, and vice-versa for hiding them.

    Any ideas?

    Comment

    Working...
    X