Browse Source

fix 封装调整

feature/big-screen
hades 5 years ago
parent
commit
ac2fc4dda2
  1. 146
      designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java

146
designer-realize/src/main/java/com/fr/start/LifecycleFatalErrorHandler.java

@ -16,6 +16,8 @@ import com.fr.stable.lifecycle.FineLifecycleFatalError;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import javax.swing.*; import javax.swing.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author hades * @author hades
@ -25,75 +27,111 @@ import javax.swing.*;
public class LifecycleFatalErrorHandler { public class LifecycleFatalErrorHandler {
private static final LifecycleFatalErrorHandler INSTANCE = new LifecycleFatalErrorHandler(); private static final LifecycleFatalErrorHandler INSTANCE = new LifecycleFatalErrorHandler();
private Map<ErrorType, Handler> map = new HashMap<>();
private LifecycleFatalErrorHandler() {
for (ErrorType type : ErrorType.values()) {
if (ErrorType.FINEDB.equals(type)) {
map.put(type, FineDBHandler.SELF);
} else {
map.put(type, DefaultHandler.SELF);
}
}
}
public static LifecycleFatalErrorHandler getInstance() { public static LifecycleFatalErrorHandler getInstance() {
return INSTANCE; return INSTANCE;
} }
public void handle(FineLifecycleFatalError fatal) { public void handle(FineLifecycleFatalError fatal) {
SplashContext.getInstance().hide(); SplashContext.getInstance().hide();
if (ErrorType.FINEDB.equals(fatal.getErrorType())) { map.get(fatal.getErrorType()).handle(fatal);
StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.FINEDB_PROBLEM.getId(), }
DesignerErrorMessage.FINEDB_PROBLEM.getMessage(),
fatal.getMessage()); interface Handler {
FineLoggerFactory.getLogger().error(DesignerErrorMessage.FINEDB_PROBLEM.getId() + ": " + DesignerErrorMessage.FINEDB_PROBLEM.getMessage()); void handle(FineLifecycleFatalError error);
int result = FineJOptionPane.showOptionDialog(null, }
Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset"),
Toolkit.i18nText("Fine-Design_Basic_Error_Tittle"), /**
JOptionPane.YES_NO_OPTION, * finedb处理
JOptionPane.ERROR_MESSAGE, */
IOUtils.readIcon("com/fr/design/images/error/error2.png"), enum FineDBHandler implements Handler {
new Object[] {Toolkit.i18nText("Fine-Design_Basic_Reset"), Toolkit.i18nText("Fine-Design_Basic_Cancel")},
null); SELF {
if (result == JOptionPane.YES_OPTION) { @Override
boolean success = false; public void handle(FineLifecycleFatalError fatal) {
try { StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.FINEDB_PROBLEM.getId(),
ResourceIOUtils.copy(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME), DesignerErrorMessage.FINEDB_PROBLEM.getMessage(),
StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_BAK_NAME)); fatal.getMessage());
success = ResourceIOUtils.delete(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME)); FineLoggerFactory.getLogger().error(DesignerErrorMessage.FINEDB_PROBLEM.getId() + ": " + DesignerErrorMessage.FINEDB_PROBLEM.getMessage());
} catch (Exception e) { int result = FineJOptionPane.showOptionDialog(null,
FineLoggerFactory.getLogger().error(e.getMessage(), e); Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset"),
afterBackupFailed(); Toolkit.i18nText("Fine-Design_Basic_Error_Tittle"),
} JOptionPane.YES_NO_OPTION,
if (!success) { JOptionPane.ERROR_MESSAGE,
afterBackupFailed(); IOUtils.readIcon("com/fr/design/images/error/error2.png"),
new Object[] {Toolkit.i18nText("Fine-Design_Basic_Reset"), Toolkit.i18nText("Fine-Design_Basic_Cancel")},
null);
if (result == JOptionPane.YES_OPTION) {
boolean success = false;
try {
ResourceIOUtils.copy(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME),
StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_BAK_NAME));
success = ResourceIOUtils.delete(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME));
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
afterBackupFailed();
}
if (!success) {
afterBackupFailed();
} else {
RestartHelper.restart();
}
} else { } else {
RestartHelper.restart(); DesignerExiter.getInstance().execute();
} }
} else {
DesignerExiter.getInstance().execute();
} }
}
FineLoggerFactory.getLogger().error(fatal.getMessage(), fatal); private void afterBackupFailed() {
StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.UNEXCEPTED_START_FAILED.getId(), FineJOptionPane.showMessageDialog(null,
DesignerErrorMessage.UNEXCEPTED_START_FAILED.getMessage(), Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset_Result",
fatal.getMessage()); ResourceIOUtils.getRealPath(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME))),
ErrorDialog dialog = new ErrorDialog(null, Toolkit.i18nText("Fine-Design_Error_Start_Apology_Message"), Toolkit.i18nText("Fine-Design_Basic_Error"),
Toolkit.i18nText("Fine-Design_Error_Start_Report"), JOptionPane.ERROR_MESSAGE);
fatal.getMessage()) {
@Override
protected void okEvent() {
dispose();
DesignerExiter.getInstance().execute(); DesignerExiter.getInstance().execute();
} }
}
}
/**
* 默认处理
*/
enum DefaultHandler implements Handler {
SELF {
@Override @Override
protected void restartEvent() { public void handle(FineLifecycleFatalError fatal) {
dispose(); FineLoggerFactory.getLogger().error(fatal.getMessage(), fatal);
RestartHelper.restart(); StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.UNEXCEPTED_START_FAILED.getId(),
} DesignerErrorMessage.UNEXCEPTED_START_FAILED.getMessage(),
}; fatal.getMessage());
dialog.setVisible(true); ErrorDialog dialog = new ErrorDialog(null, Toolkit.i18nText("Fine-Design_Error_Start_Apology_Message"),
} Toolkit.i18nText("Fine-Design_Error_Start_Report"),
fatal.getMessage()) {
@Override
protected void okEvent() {
dispose();
DesignerExiter.getInstance().execute();
}
private void afterBackupFailed() { @Override
FineJOptionPane.showMessageDialog(null, protected void restartEvent() {
Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset_Result", dispose();
ResourceIOUtils.getRealPath(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME))), RestartHelper.restart();
Toolkit.i18nText("Fine-Design_Basic_Error"), }
JOptionPane.ERROR_MESSAGE); };
DesignerExiter.getInstance().execute(); dialog.setVisible(true);
}
}
} }

Loading…
Cancel
Save