PDA

View Full Version : [CLOSED] Beta4: Adding TableItem to table within non-active CardLayout bug



andrey
4 Jun 2008, 7:25 AM
This appears to be a bug:

I have a ContentPanel with a CardLayout. One of the cards is another ContentPanel containing a Table. If you add a TableItem to the Table before it has been rendered as part of making it's content panel active in the CardLayout, then the new table row is formatted fine. However, if you view the Table by making it's card active, and then switch to another card, and then add a table item, and then view the table again, the new item is not formatted in the table.

The test code below demonstrates the problem if you follow the procedure above. I am looking for any kind of work-around if anyone has one.

Thx,
Andre



import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.CardLayout;
import com.extjs.gxt.ui.client.widget.layout.FillLayout;
import com.extjs.gxt.ui.client.widget.table.RowSelectionModel;
import com.extjs.gxt.ui.client.widget.table.Table;
import com.extjs.gxt.ui.client.widget.table.TableColumn;
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
import com.extjs.gxt.ui.client.widget.table.TableItem;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class TestTableAdd implements EntryPoint {
public void onModuleLoad() {
final Viewport viewport = new Viewport();
viewport.setLayout(new BorderLayout());

final ContentPanel cardPanel = new ContentPanel();
cardPanel.setHeading("Card Panel");
final CardLayout cardLayout = new CardLayout();
cardPanel.setLayout(cardLayout);

final ContentPanel tablePanel = new ContentPanel();
tablePanel.setLayout(new FillLayout());
tablePanel.setHeading("Table Panel");

TableColumn[] columns = new TableColumn[2];

columns[0] = new TableColumn("Col1", .25f);
columns[0].setAlignment(Style.HorizontalAlignment.CENTER);

columns[1] = new TableColumn("Col2", .75f);
columns[1].setAlignment(Style.HorizontalAlignment.LEFT);

TableColumnModel columnModel = new TableColumnModel(columns);

final Table<RowSelectionModel> table = new Table<RowSelectionModel>(columnModel);
tablePanel.add(table);
cardPanel.add(tablePanel);
viewport.add(cardPanel, new BorderLayoutData(LayoutRegion.CENTER, .75f, 100, 800));

final ContentPanel dummyPanel = new ContentPanel();
dummyPanel.add(new Label("This is another card"));

cardPanel.add(dummyPanel);

cardLayout.setActiveItem(dummyPanel);

ButtonBar buttonBar = new ButtonBar();
Button addButton = new Button("Add Row");
addButton.addListener(Events.OnClick, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
Object[] values = new Object[2];
values[0] = "col1";
values[1] = "col2";
TableItem item = new TableItem(values);
table.add(item);
tablePanel.layout();
}
});
buttonBar.add(addButton);

Button swapButton = new Button("Swap Cards");
swapButton.addListener(Events.OnClick, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
cardLayout.setActiveItem(cardLayout.getActiveItem() == dummyPanel ? tablePanel : dummyPanel);
cardPanel.layout();
}
});
buttonBar.add(swapButton);

viewport.add(buttonBar, new BorderLayoutData(LayoutRegion.SOUTH, .25f, 100, 800));

viewport.layout();
RootPanel.get("slot1").add(viewport);
}
}

andrey
4 Jun 2008, 7:47 AM
Forgot to add that in the case where the newly added TableItem row is not formatted correctly, you can adjust the column width and the table will layout correctly.

andrey
4 Jun 2008, 12:26 PM
The attached screen shot was after inserting two rows before showing the table, then while the table was in a non-active card, inserting two more rows, and then making the table card visible.

darrellmeyer
4 Jun 2008, 9:41 PM
Tables will not recalculate their layout if their size has not been changed since the last time calculations were run. You can force the execution by calling recalculate.


TableItem item = new TableItem(values);
table.add(item);
//tablePanel.layout();
table.recalculate();