Destiny.Lin
1 year ago
3 changed files with 132 additions and 79 deletions
@ -0,0 +1,122 @@ |
|||||||
|
package com.fr.design.mainframe.vcs.common; |
||||||
|
|
||||||
|
import com.fr.base.vcs.DesignerMode; |
||||||
|
import com.fr.design.dialog.BasicDialog; |
||||||
|
import com.fr.design.dialog.FineJOptionPane; |
||||||
|
import com.fr.design.file.HistoryTemplateListCache; |
||||||
|
import com.fr.design.file.MultiTemplateTabPane; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.JTemplate; |
||||||
|
import com.fr.design.mainframe.vcs.ui.VcsNewPane; |
||||||
|
import com.fr.design.worker.save.CallbackSaveWorker; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
|
||||||
|
import javax.swing.JOptionPane; |
||||||
|
|
||||||
|
/** |
||||||
|
* 版本管理关闭模板辅助类 |
||||||
|
* |
||||||
|
* @author Destiny.Lin |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2023/7/27 |
||||||
|
*/ |
||||||
|
public class VcsCloseTemplateHelper { |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据传入的pane与dialog生成指定面板的Vcs模板关闭的处理方法 |
||||||
|
* 如果指定模板已经打开: |
||||||
|
* <p>1.如果该模板已保存,则正常打开新版本管理弹窗 |
||||||
|
* <p>2.如果该模板未保存,触发保存逻辑 |
||||||
|
* <li>a.如果用户选择保存,则保存并不关闭模板,弹出新版本管理弹窗 |
||||||
|
* <li>b.如果用户选择不保存,则关闭当前模板,弹出新版本管理弹窗 |
||||||
|
* <li>c.如果用户选择取消, 则啥操作都不做 |
||||||
|
* |
||||||
|
* @param path 对应模板路径 |
||||||
|
* @param isCurrentEditing 是否是正在编辑的模板 |
||||||
|
* @param dialog 生成的新版本管理的详情面板的父面板 |
||||||
|
*/ |
||||||
|
public static void checkTemplateSavedAndShowVcsNewPane(String path, boolean isCurrentEditing, BasicDialog dialog, VcsNewPane pane) { |
||||||
|
for (JTemplate jTemplate : HistoryTemplateListCache.getInstance().getHistoryList()) { |
||||||
|
if (ComparatorUtils.equals(jTemplate.getEditingFILE().getPath(), path)) { |
||||||
|
if (!jTemplate.isALLSaved()) { |
||||||
|
MultiTemplateTabPane.getInstance().setIsCloseCurrent(isCurrentEditing); |
||||||
|
MultiTemplateTabPane.getInstance().closeFormat(jTemplate); |
||||||
|
confirmCloseAndShowVcsNewPane(jTemplate, path, dialog, pane); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
showVcsNewPane(path, dialog, pane); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 自己生成新的VcsNewPane的Vcs模板关闭的处理方法 |
||||||
|
*/ |
||||||
|
public static void checkTemplateSavedAndShowVcsNewPane(String path, boolean isCurrentEditing) { |
||||||
|
checkTemplateSavedAndShowVcsNewPane(path, isCurrentEditing, null, null); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 是否是当前编辑的模板 |
||||||
|
* |
||||||
|
* @param path 对应模板路径 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public static boolean isCurrentEditing(String path) { |
||||||
|
JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||||
|
if (JTemplate.isValid(jt)) { |
||||||
|
String editing = jt.getEditingFILE().getPath(); |
||||||
|
return ComparatorUtils.equals(editing, path); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static void confirmCloseAndShowVcsNewPane(JTemplate<?, ?> specifiedTemplate, String path, BasicDialog dialog, VcsNewPane pane) { |
||||||
|
if (specifiedTemplate == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
if (!specifiedTemplate.isALLSaved() && !DesignerMode.isVcsMode()) { |
||||||
|
specifiedTemplate.stopEditing(); |
||||||
|
int returnVal = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Would_You_Like_To_Save") + " \"" + specifiedTemplate.getEditingFILE() + "\" ?", |
||||||
|
Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); |
||||||
|
if (returnVal == JOptionPane.YES_OPTION) { |
||||||
|
CallbackSaveWorker worker = specifiedTemplate.save(); |
||||||
|
worker.addSuccessCallback(() -> { |
||||||
|
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName())); |
||||||
|
showVcsNewPane(path, dialog, pane); |
||||||
|
}); |
||||||
|
worker.start(specifiedTemplate.getRuntimeId()); |
||||||
|
} else if (returnVal == JOptionPane.NO_OPTION) { |
||||||
|
closeTpl(specifiedTemplate); |
||||||
|
showVcsNewPane(path, dialog, pane); |
||||||
|
} |
||||||
|
} else { |
||||||
|
showVcsNewPane(path, dialog, pane); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void showVcsNewPane(String path, BasicDialog dialog, VcsNewPane pane) { |
||||||
|
if (pane != null) { |
||||||
|
pane.showDialog(dialog); |
||||||
|
} else { |
||||||
|
VcsNewPane newPane = new VcsNewPane(path); |
||||||
|
newPane.showDialog(dialog); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static void closeTpl(JTemplate<?, ?> specifiedTemplate) { |
||||||
|
HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate); |
||||||
|
MultiTemplateTabPane.getInstance().closeAndFreeLock(specifiedTemplate); |
||||||
|
MultiTemplateTabPane.getInstance().activePrevTemplateAfterClose(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue