Hi All,
I want to switch between two tabs in TabSet only when some condition is true (only when tab data was saved) and then initialise
selected tab.
Scenario:
When user click on another tab I want to ask him if he want to save provided data before swithing a tab. I'm catching TabDeselectedEvent
using TabDeselectedHandler() and in onTabDeselected method I'm calling SC.ask("You have to save your data first. Ok?") alert with a question.
Beacause SC.ask(...) returns user's decision asynchronously I have to remeber newly selected tab and to cancel the event and
then to call SC.ask(...). When user decision equals true I'm saving user data and then trying to switch a tab.
Problem:
The problem is that selected tab stays empty (previous is fine but each another stays empty).
It appears when after selection I'm trying to put some canvas (content) into a tab I'm switching to.
I want to initialize tab content and data on first selection (before not selected tabs are empty).
I also need to reinitialize tab data on every selection (to always show a fresh data).
Am I doing something wrong or is there a bug in smartgwt?
Because there's no possibility to stop tab switching in 2.2
release I'm working with 2.3 snapshots. Currently it's
revision 1359
Here's my code:
I want to switch between two tabs in TabSet only when some condition is true (only when tab data was saved) and then initialise
selected tab.
Scenario:
When user click on another tab I want to ask him if he want to save provided data before swithing a tab. I'm catching TabDeselectedEvent
using TabDeselectedHandler() and in onTabDeselected method I'm calling SC.ask("You have to save your data first. Ok?") alert with a question.
Beacause SC.ask(...) returns user's decision asynchronously I have to remeber newly selected tab and to cancel the event and
then to call SC.ask(...). When user decision equals true I'm saving user data and then trying to switch a tab.
Problem:
The problem is that selected tab stays empty (previous is fine but each another stays empty).
It appears when after selection I'm trying to put some canvas (content) into a tab I'm switching to.
I want to initialize tab content and data on first selection (before not selected tabs are empty).
I also need to reinitialize tab data on every selection (to always show a fresh data).
Am I doing something wrong or is there a bug in smartgwt?
Because there's no possibility to stop tab switching in 2.2
release I'm working with 2.3 snapshots. Currently it's
revision 1359
Here's my code:
Code:
public class TabbedPane extends TabSet {
MCXTab oldTab;
public TabbedPane() {
this.data = data;
this.addTabDeselectedHandler(new TabDeselectedHandler() {
@Override
public void onTabDeselected(TabDeselectedEvent event) {
MCXTab tab = (MCXTab) event.getTab();
TabbedPane.this.newTab = (MCXTab) event.getNewTab();
event.cancel();
tab.save(); //invoking method with
//asynchronous SC.ask
EventBus.subscribe("new Tab", //asynchronous answer
//from tab.save
new TopicSubscriber<Object[]>() {
@Override
public void onEvent(Subscription subscription,
Object[] answerObject) {
Boolean answer = (Boolean)answerObject[0];
if (answer) {
int num =TabbedPane.this.
getTabNumber(newTab.getID());
TabbedPane.this.setSelectedTab(num);
//init next Tab:
TabbedPane.this.newTab.
initLayout(TabbedPane.this.data);
} else {
//if answer = false tab should'n be
//changed
}
}
}));
}
});
this.addTabSelectedHandler(new TabSelectedHandler() {
@Override
public void onTabSelected(TabSelectedEvent event) {
MCXTab tab = (MCXTab) event.getTab();
tab.initLayout(TabbedPane.this.data);
}
});
}
public class MCXTab extends Tab{
InitiableComponent componentToDraw;
public MCXTab(InitiableComponent componentToDraw){
super();
this.componentToDraw = componentToDraw;
}
public void initLayout(EntityComponentData data){
Canvas canvas = (Canvas) componentToDraw.initLayout(data);
canvas.redraw();
setPane(canvas);
}
public void save(EntityComponentData data){
this.saveData = data;
SC.ask("save changes?", new BooleanCallback() {
@Override
public void execute(Boolean value) {
if (value != null && value) {
componentToDraw.save(data);
EventBus.publish("new Tab", new Object[] { true });
} else {
EventBus.publish("new Tab", new Object[] { false });
}
}
});
}
}