We are currently evaluating SmartGWT as a platform for developing an internal parts catalog. While playing with the product I have the following problem:
I have a VLayout with a label and a TileLayout. The tile layout contains parts icons and descriptions. By clicking on a tile, the user drills down to the next level of the catalog so the label and the tiles must completely change with the new data.
My first idea was to create a TileLayout in the constructor and then on a page update to clear() it and populate it with new tiles. However I have found out that a call to
clear() doesn’t remove the old tiles from a TileLayout. I have then tried to remove the already existing tiles by calling removeTile() but this method has always removed false (both with a tile index and a tile object as an argument). By the way, wouldn’t it be convenient to have removeTiles() and getTiles() methods?
Finally, I have discovered that a call to the clear() method of the parent VLayout itself doesn’t seem to remove layout members and on subsequent calls I have ended up with many labels and tile layouts in the same VLayout.
The only way I have managed to get working so far is to destoy() all VLayout members on every call and then re-draw the whole thing. However I suspect that this brutal solution is very inefficient and probably wrong.
Here’s a code snippet:
public class CatalogWidget extends VLayout
{
public CatalogWidget()
{
setWidth100();
setHeight100();
}
...
private void loadSubnodes(long nodeId)
{
EdhCatService.Util.getInstance().getSubnodes(lang, nodeId, null, new AsyncCallback<NodeInfo[]>()
{
public void onSuccess(NodeInfo[] result)
{
TileLayout subnodesPanel = new TileLayout();
// clear(); // doesn’t clear the members
// subnodePanel.clear(); // doesn’t clear the tiles
// subnodePanel.removeTiles(); // doesn’t exist
// always returns false, even if tiles are there
// while (subnodePanel.removeTile(0));
clearLayout();
subnodesPanel.setWidth100();
subnodesPanel.setHeight100();
subnodesPanel.setTileWidth(120);
subnodesPanel.setTileHeight(150);
subnodesPanel.setTileHMargin(10);
subnodesPanel.setTileVMargin(20);
subnodesPanel.setOverflow(Overflow.VISIBLE);
for (int i=0; (result != null) && (i < result.length); i++)
{
if ((i == 0) && (result[i].getParentId() > EdhCat.MAX_ROOT_NODE))
addMember(new Label(result[i].getParentName()));
subnodesPanel.addTile(new CategoryWidget(result[i]));
}
addMember(subnodesPanel);
draw();
}
public void onFailure(Throwable caught)
{
// TODO
EdhCatErrorHandler.handleError(caught);
}
});
}
private void clearLayout()
{
Canvas[] members = getMembers();
for (int i = 0; (members != null) && (i <
members.length); i++)
members[i].destroy();
}
...
}
Therefore here are three questions to everybody who is experienced with SmartGwt:
1. What is the most correct way to clear a layout from members and populate it with new members?
2. How to repopulate a TileLayout with a new set of tiles?
3. Suppose we have a layout whose different members are visible at different times (e.g. tiles view, table view, detailed view and possibly a collapsible filter panel visible only on certain conditions...). What would be a correct way to show/hide the members? Would a call to hide()/show() be enough or it is necessary to do other steps as well (e.g. draw() or reflow() )?
Thanks in advance for answering!
I have a VLayout with a label and a TileLayout. The tile layout contains parts icons and descriptions. By clicking on a tile, the user drills down to the next level of the catalog so the label and the tiles must completely change with the new data.
My first idea was to create a TileLayout in the constructor and then on a page update to clear() it and populate it with new tiles. However I have found out that a call to
clear() doesn’t remove the old tiles from a TileLayout. I have then tried to remove the already existing tiles by calling removeTile() but this method has always removed false (both with a tile index and a tile object as an argument). By the way, wouldn’t it be convenient to have removeTiles() and getTiles() methods?
Finally, I have discovered that a call to the clear() method of the parent VLayout itself doesn’t seem to remove layout members and on subsequent calls I have ended up with many labels and tile layouts in the same VLayout.
The only way I have managed to get working so far is to destoy() all VLayout members on every call and then re-draw the whole thing. However I suspect that this brutal solution is very inefficient and probably wrong.
Here’s a code snippet:
public class CatalogWidget extends VLayout
{
public CatalogWidget()
{
setWidth100();
setHeight100();
}
...
private void loadSubnodes(long nodeId)
{
EdhCatService.Util.getInstance().getSubnodes(lang, nodeId, null, new AsyncCallback<NodeInfo[]>()
{
public void onSuccess(NodeInfo[] result)
{
TileLayout subnodesPanel = new TileLayout();
// clear(); // doesn’t clear the members
// subnodePanel.clear(); // doesn’t clear the tiles
// subnodePanel.removeTiles(); // doesn’t exist
// always returns false, even if tiles are there
// while (subnodePanel.removeTile(0));
clearLayout();
subnodesPanel.setWidth100();
subnodesPanel.setHeight100();
subnodesPanel.setTileWidth(120);
subnodesPanel.setTileHeight(150);
subnodesPanel.setTileHMargin(10);
subnodesPanel.setTileVMargin(20);
subnodesPanel.setOverflow(Overflow.VISIBLE);
for (int i=0; (result != null) && (i < result.length); i++)
{
if ((i == 0) && (result[i].getParentId() > EdhCat.MAX_ROOT_NODE))
addMember(new Label(result[i].getParentName()));
subnodesPanel.addTile(new CategoryWidget(result[i]));
}
addMember(subnodesPanel);
draw();
}
public void onFailure(Throwable caught)
{
// TODO
EdhCatErrorHandler.handleError(caught);
}
});
}
private void clearLayout()
{
Canvas[] members = getMembers();
for (int i = 0; (members != null) && (i <
members.length); i++)
members[i].destroy();
}
...
}
Therefore here are three questions to everybody who is experienced with SmartGwt:
1. What is the most correct way to clear a layout from members and populate it with new members?
2. How to repopulate a TileLayout with a new set of tiles?
3. Suppose we have a layout whose different members are visible at different times (e.g. tiles view, table view, detailed view and possibly a collapsible filter panel visible only on certain conditions...). What would be a correct way to show/hide the members? Would a call to hide()/show() be enough or it is necessary to do other steps as well (e.g. draw() or reflow() )?
Thanks in advance for answering!
Comment