When executing saveCommand the timer on confirmClose is resetted

FEA: ItEr77S03Community
This commit is contained in:
Lorenzo Tilve Álvaro 2012-11-26 09:44:09 +01:00 committed by Manuel Rego Casasnovas
parent 3a4e0fae55
commit 25e9184c48
2 changed files with 43 additions and 5 deletions

View file

@ -104,6 +104,11 @@ import org.zkoss.ganttz.data.DependencyType.Point;
import org.zkoss.ganttz.data.GanttDate;
import org.zkoss.ganttz.data.constraint.Constraint;
import org.zkoss.ganttz.extensions.IContext;
import org.zkoss.ganttz.util.LongOperationFeedback;
import org.zkoss.ganttz.util.LongOperationFeedback.IBackGroundOperation;
import org.zkoss.ganttz.util.LongOperationFeedback.IDesktopUpdate;
import org.zkoss.ganttz.util.LongOperationFeedback.IDesktopUpdatesEmitter;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Label;
@ -125,6 +130,7 @@ import org.zkoss.zul.Messagebox;
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class SaveCommandBuilder {
private static final int WARNING_ON_EXIT_MS = 3000;
private static final Log LOG = LogFactory.getLog(SaveCommandBuilder.class);
@ -275,13 +281,36 @@ public class SaveCommandBuilder {
@Override
public void doActions() {
notifyUserThatSavingIsDone();
if (Executions.getCurrent() != null) {
Clients.confirmClose(null);
}
}
});
}
private void confirmCloseThread(Desktop desktop) {
LongOperationFeedback
.progressive(
desktop,
new IBackGroundOperation<LongOperationFeedback.IDesktopUpdate>() {
@Override
public void doOperation(
IDesktopUpdatesEmitter<IDesktopUpdate> desktopUpdateEmitter) {
try {
Thread.sleep(WARNING_ON_EXIT_MS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
desktopUpdateEmitter
.doUpdate(new IDesktopUpdate() {
@Override
public void doUpdate() {
Clients.confirmClose(_("You are about to leave the planning edition, unsaved changes will be lost."));
}
});
}
});
}
@Override
public void save(final IBeforeSaveActions beforeSaveActions,
IAfterSaveActions afterSaveActions) {
@ -368,6 +397,13 @@ public class SaveCommandBuilder {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// Reset timer of warning on leaving page
Clients.confirmClose(null);
if (Executions.getCurrent() != null) {
Clients.confirmClose(null);
confirmCloseThread(Executions.getCurrent().getDesktop());
}
}
private void doTheSaving() {

View file

@ -87,6 +87,8 @@ import org.zkoss.zk.ui.util.Composer;
public class MultipleTabsPlannerController implements Composer,
IGlobalViewEntryPoints {
private static final int WARNING_ON_EXIT_MS = 30000; // 30 seconds
private final class TabWithLoadingFeedback extends TabProxy {
private boolean feedback = true;
@ -461,7 +463,7 @@ public class MultipleTabsPlannerController implements Composer,
public void doOperation(
IDesktopUpdatesEmitter<IDesktopUpdate> desktopUpdateEmitter) {
try {
Thread.sleep(1000);
Thread.sleep(WARNING_ON_EXIT_MS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@ -471,7 +473,7 @@ public class MultipleTabsPlannerController implements Composer,
@Override
public void doUpdate() {
Clients.confirmClose(null);
Clients.confirmClose(_("You are about to leave the project planning edition, please confirm that you have saved your changes"));
Clients.confirmClose(_("You are about to leave the planning edition, unsaved changes will be lost."));
}
});
}