package com.cedarsoft.spring.rcp.commands;
import com.cedarsoft.spring.rcp.async.BackgroundAction;
import com.cedarsoft.spring.rcp.async.BlockingBackgroundActionRunner;
import com.cedarsoft.CanceledException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* //todo remove vererbung
*/
@Deprecated
public abstract class AbstractBackgroundCommand extends ExtendedCommand {
private BlockingBackgroundActionRunner actionRunner;
protected AbstractBackgroundCommand( @NotNull @NonNls String commandId ) {
super( commandId );
}
@Override
protected void executeCommand() throws Exception {
BackgroundAction action = new BackgroundAction( getId() + ".message" ) {
@Override
protected void prepare() throws CanceledException {
AbstractBackgroundCommand.this.prepare();
}
@Override
protected void executeInBackground() throws Exception {
AbstractBackgroundCommand.this.executeInBackground();
}
@Override
protected boolean confirm() {
return AbstractBackgroundCommand.this.confirm();
}
};
actionRunner = new BlockingBackgroundActionRunner( getApplicationWindow(), action, false );
actionRunner.run();
}
public void setProgressMessage( @NotNull @NonNls String key, @NotNull Object... objects ) {
if ( actionRunner != null ) {
actionRunner.setProgressMessage( key, objects );
}
}
protected abstract void prepare() throws CanceledException;
protected abstract void executeInBackground() throws Exception;
protected abstract boolean confirm();
}