我目前正在开发一个GWT应用程序,我遇到一个问题。当我在某个选项卡上选择一个项目,然后我转到其他选项卡,当我返回时,仍然选择了所选项目。但是当我回到该选项卡上时,我不希望选择项目。以下是我的一些标签中的一段代码:
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setWidth("100%");
BorderLayoutData messageLayout = new BorderLayoutData(LayoutRegion.NORTH, 0.06f);
messageLayout.setMargins(new Margins(5));
Text welcomeMessage = new Text();
welcomeMessage.setText(MSGS.topicTabItemMessage());
add(welcomeMessage, messageLayout);
LayoutContainer tables = new LayoutContainer(new BorderLayout());
BorderLayoutData tablesLayout = new BorderLayoutData(LayoutRegion.CENTER);
tablesLayout.setMargins(new Margins(0, 5, 0, 5));
tablesLayout.setMinSize(250);
add(tables, tablesLayout);
BorderLayoutData topicLayout = new BorderLayoutData(LayoutRegion.WEST, 0.5f);
topicTable = new TopicsTable(currentSession);
topicTable.setBorders(false);
topicLayout.setMargins(new Margins(0, 5, 0, 0));
topicLayout.setSplit(true);
topicTable.addSelectionChangedListener(new SelectionChangedListener<GwtTopic>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtTopic> selectedTopic) {
refreshButton.enable();
metricsTable.refresh(selectedTopic.getSelectedItem());
}
});
tables.add(topicTable, topicLayout);
BorderLayoutData metricLayout = new BorderLayoutData(LayoutRegion.CENTER);
metricLayout.setMargins(new Margins(0, 0, 0, 5));
metricsTable = new MetricsTable(currentSession, MetricsTable.Type.TOPIC);
metricsTable.addSelectionListener(new SelectionChangedListener<GwtHeader>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtHeader> se) {
if (!se.getSelection().isEmpty()) {
queryButton.enable();
} else {
queryButton.disable();
}
}
});
tables.add(metricsTable, metricLayout);
BorderLayoutData queryButtonLayout = new BorderLayoutData(LayoutRegion.SOUTH, 0.1f);
queryButtonLayout.setMargins(new Margins(5));
queryButton = new Button(MSGS.topicTabItemQueryButtonText(), new KapuaIcon(IconSet.SEARCH), new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
GwtTopic topic = topicTable.getSelectedTopic();
List<GwtHeader> metrics = metricsTable.getSelectedMetrics();
resultsTable.refresh(topic, metrics);
}
});
queryButton.disable();
TableLayout queryButtonTL = new TableLayout();
queryButtonTL.setCellPadding(0);
LayoutContainer queryButtonContainer = new LayoutContainer(queryButtonTL);
refreshButton = new Button(MSGS.refresh(), new KapuaIcon(IconSet.REFRESH), new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
GwtTopic topic = topicTable.getSelectedTopic();
List<GwtHeader> metrics = metricsTable.getSelectedMetrics();
resultsTable.refresh(topic, metrics);
metricsTable.refresh();
}
});
refreshButton.disable();
toolbar = new ToolBar();
toolbar.add(queryButton);
toolbar.add(new SeparatorToolItem());
toolbar.add(refreshButton);
queryButtonContainer.add(toolbar);
tables.add(queryButtonContainer, queryButtonLayout);
BorderLayoutData resultsLayout = new BorderLayoutData(LayoutRegion.SOUTH, 0.5f);
resultsLayout.setSplit(true);
TabPanel resultsTabPanel = new TabPanel();
resultsTabPanel.setPlain(true);
resultsTabPanel.setBorders(false);
resultsTabPanel.setBodyBorder(false);
resultsTable = new ResultsTable(currentSession);
TabItem resultsTableTabItem = new TabItem(MSGS.resultsTableTabItemTitle(), new KapuaIcon(IconSet.TABLE));
resultsTableTabItem.setLayout(new FitLayout());
resultsTableTabItem.add(resultsTable);
resultsTabPanel.add(resultsTableTabItem);
add(resultsTabPanel, resultsLayout);
}
如何解决这个问题?提前谢谢。