/*
* Main.java
*
* Created on 27 Декабрь 2007 г., 1:40
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package cli_fmw;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.login.LoginDialogFrame;
import cli_fmw.login.UserInfoAbstract;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.utils.ClientUncaughtExceptionHandler;
import cli_fmw.utils.ConfigGui;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.SafeExit;
import java.awt.SplashScreen;
/**
*
* @author Axe Ilshat
*/
public abstract class MainAbstract implements Application {
/** Creates a new instance of Main */
protected MainAbstract() {
}
protected abstract void beforeRun();
public void appRun() {
beforeRun();
if (SplashScreen.getSplashScreen() != null) {
SplashScreen.getSplashScreen().close();
}
login();
}
@Override
public void logout(){
try {
if (UserInfoAbstract.get() != null) {
UserInfoAbstract.get().logout();
}
}
catch (ClipsException ex) {
try {
if (UserInfoAbstract.get() != null) {
UserInfoAbstract.get().logout();
}
}
catch (Exception ex1) {
ex1.printStackTrace();
MessageBox.showExceptionAndHalt(ex);
System.exit(20);
}
MessageBox.showException(ex);
}
DirectoryLocator.clear();
}
protected abstract LoginDialogFrame getLoginWindow() throws ClipsException;
protected abstract MainWindow getMainWindow() throws ClipsException;
@Override
public void login(){
try {
LoginDialogFrame dialog = getLoginWindow();
dialog.setVisible(true);
if (dialog.getDlgResult() == ModalDialog.DLG_CANCEL) {
onAppExit();
return;
}
DirectoryLocator.clear();
getMainWindow().setVisible(true);
}
catch (ClipsException ex) {
MessageBox.showExceptionAndHalt(ex);
System.exit(19);
}
}
protected abstract void beforeAppExit();
@Override
public void onAppExit(){
ConfigGui.getInstance().save();
beforeAppExit();
ConfigGui.getInstance().save();
SafeExit.onExit();
}
protected void init(String[] args) throws Exception{
SafeExit.installExitMon();
ClientUncaughtExceptionHandler.attach();
}
public void start(final String[] args){
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
init(args);
appRun();
}catch (Exception ex) {
MessageBox.showExceptionAndHalt(ex);
System.exit(21);
}
}
});
}
}