You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
7.3 KiB
173 lines
7.3 KiB
package com.fr.design.worker.save; |
|
|
|
import com.fr.common.exception.ThrowableHandler; |
|
import com.fr.design.dialog.FineJOptionPane; |
|
import com.fr.design.file.HistoryTemplateListCache; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.lock.LockInfoDialog; |
|
import com.fr.design.mainframe.DesignerContext; |
|
import com.fr.design.mainframe.JTemplate; |
|
import com.fr.design.ui.util.UIUtil; |
|
import com.fr.design.utils.TemplateUtils; |
|
import com.fr.file.FileNodeFILE; |
|
import com.fr.file.filetree.FileNode; |
|
import com.fr.general.IOUtils; |
|
import com.fr.report.LockedException; |
|
import com.fr.report.UnLockedException; |
|
import com.fr.workspace.base.UserInfo; |
|
import com.fr.workspace.exception.DiskSpaceFullException; |
|
import com.fr.report.InconsistentLockException; |
|
import java.awt.Frame; |
|
import javax.swing.JOptionPane; |
|
|
|
/** |
|
* @author hades |
|
* @version 11.0 |
|
* Created by hades on 2021/12/7 |
|
*/ |
|
@SuppressWarnings("all") |
|
public class SaveFailureHandler implements ThrowableHandler { |
|
|
|
private static final SaveFailureHandler INSTANCE = new SaveFailureHandler(); |
|
|
|
public static SaveFailureHandler getInstance() { |
|
return INSTANCE; |
|
} |
|
|
|
@Override |
|
public boolean process(Throwable e) { |
|
UIUtil.invokeLaterIfNeeded(new Runnable() { |
|
@Override |
|
public void run() { |
|
for (Handler handler : Handler.values()) { |
|
try { |
|
if (handler.process(e)) { |
|
break; |
|
} |
|
} catch (Exception ignored) { |
|
} |
|
} |
|
} |
|
}); |
|
return true; |
|
} |
|
|
|
public enum Handler implements ThrowableHandler { |
|
|
|
FullDisk { |
|
@Override |
|
public boolean process(Throwable e) { |
|
if (e.getCause() instanceof DiskSpaceFullException |
|
|| e instanceof DiskSpaceFullException |
|
|| e.getCause().getCause() instanceof DiskSpaceFullException) { |
|
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), |
|
Toolkit.i18nText("Fine_Design_Template_Save_Failed_By_Full_Disk"), |
|
Toolkit.i18nText("Fine-Design_Basic_Alert"), |
|
JOptionPane.WARNING_MESSAGE, |
|
IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png")); |
|
return true; |
|
} |
|
return false; |
|
} |
|
}, |
|
UnLocked { |
|
@Override |
|
public boolean process(Throwable e) { |
|
if (e.getCause() instanceof UnLockedException || e instanceof UnLockedException) { |
|
processUnLocked(Toolkit.i18nText("Fine_Design_Template_Has_Been_UnLocked")); |
|
return true; |
|
} |
|
return false; |
|
} |
|
}, |
|
|
|
InconsistentLock { |
|
@Override |
|
public boolean process(Throwable e) { |
|
if (e.getCause() instanceof InconsistentLockException || e instanceof InconsistentLockException) { |
|
processInconsistentLock(Toolkit.i18nText("Fine_Design_Template_Save_Failed_By_Lock_Inconsistency")); |
|
return true; |
|
} |
|
return false; |
|
} |
|
}, |
|
|
|
LOCKED { |
|
@Override |
|
public boolean process(Throwable e) { |
|
LockedException exception = null; |
|
if (e.getCause() instanceof LockedException) { |
|
exception = (LockedException) e.getCause(); |
|
} |
|
if (e instanceof LockedException) { |
|
exception = (LockedException) e; |
|
} |
|
if (exception != null) { |
|
UserInfo userInfo = exception.getUserInfo(); |
|
LockInfoDialog.show(userInfo); |
|
return true; |
|
} |
|
return false; |
|
} |
|
}, |
|
|
|
Other { |
|
@Override |
|
public boolean process(Throwable e) { |
|
boolean minimized = (DesignerContext.getDesignerFrame().getExtendedState() & Frame.ICONIFIED ) != 0; |
|
FineJOptionPane.showMessageDialog( |
|
minimized ? null : DesignerContext.getDesignerFrame(), |
|
Toolkit.i18nText("Fine-Design-Basic_Save_Failure"), |
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), |
|
JOptionPane.ERROR_MESSAGE); |
|
return true; |
|
} |
|
}; |
|
|
|
|
|
protected void processUnLocked(String tip) { |
|
int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), |
|
tip, |
|
Toolkit.i18nText("Fine-Design_Basic_Alert"), |
|
JOptionPane.YES_NO_OPTION, |
|
JOptionPane.WARNING_MESSAGE, |
|
IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"), |
|
new Object[] {Toolkit.i18nText("Fine_Design_Template_SaveAs_Backup"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null); |
|
if (option == JOptionPane.YES_OPTION) { |
|
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
if (JTemplate.isValid(template)) { |
|
TemplateUtils.createAndOpenTemplate( |
|
Toolkit.i18nText("Fine_Design_Template_Backup"), |
|
new FileNodeFILE(new FileNode(template.getPath(), false)), |
|
true, |
|
true, |
|
//另存之后需要关闭的模板 |
|
template); |
|
} |
|
} |
|
} |
|
|
|
protected void processInconsistentLock(String tip) { |
|
int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), |
|
tip, |
|
Toolkit.i18nText("Fine-Design_Basic_Alert"), |
|
JOptionPane.YES_NO_OPTION, |
|
JOptionPane.WARNING_MESSAGE, |
|
IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"), |
|
new Object[] {Toolkit.i18nText("Fine_Design_Template_SaveAs_Backup"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null); |
|
if (option == JOptionPane.YES_OPTION) { |
|
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
if (JTemplate.isValid(template)) { |
|
TemplateUtils.createAndOpenTemplate( |
|
Toolkit.i18nText("Fine_Design_Template_Backup"), |
|
new FileNodeFILE(new FileNode(template.getPath(), false)), |
|
true, |
|
true, |
|
//另存之后需要关闭的模板 |
|
template); |
|
} |
|
} |
|
} |
|
|
|
} |
|
}
|
|
|