diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java index a9b2beaeb..a5826462e 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java @@ -12,6 +12,7 @@ import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.lock.LockInfoUtils; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.lock.LockInfoDialog; @@ -230,13 +231,15 @@ public class TemplateTreePane extends JPanel implements FileOperations { return; } String lock = node.getLock(); - boolean showLockInfo = (lock != null && !lock.equals(node.getUserID())) - || WorkContext.getCurrent().get(LockInfoOperator.class).isTplLocked(selectedFilePath); + boolean showLockInfo = LockInfoUtils.isCompatibleOperator() ? (lock != null && !lock.equals(node.getUserID())) + : WorkContext.getCurrent().get(LockInfoOperator.class).isTplLocked(selectedFilePath); if (showLockInfo) { UserInfo userInfo = WorkContext.getCurrent().get(LockInfoOperator.class).getUserInfo(selectedFilePath); node.setLock(UUID.randomUUID().toString()); LockInfoDialog.show(userInfo); return; + } else { + node.setLock(null); } DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(selectedFilePath, false))); } diff --git a/designer-base/src/main/java/com/fr/design/lock/LockInfoUtils.java b/designer-base/src/main/java/com/fr/design/lock/LockInfoUtils.java new file mode 100644 index 000000000..ce8c493e9 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/lock/LockInfoUtils.java @@ -0,0 +1,18 @@ +package com.fr.design.lock; + +import com.fr.report.lock.DefaultLockInfoOperator; +import com.fr.report.lock.LockInfoOperator; +import com.fr.workspace.WorkContext; + +/** + * @author hades + * @version 11.0 + * Created by hades on 2021/12/8 + */ +public class LockInfoUtils { + + public static boolean isCompatibleOperator() { + LockInfoOperator lockInfoOperator = WorkContext.getCurrent().get(LockInfoOperator.class); + return lockInfoOperator instanceof DefaultLockInfoOperator; + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 21f891f1f..a08febe68 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -991,7 +991,7 @@ public abstract class JTemplate> throw new UnLockedException(); } // 校验锁定信息是否一致 - if (WorkContext.getCurrent().get(LockInfoOperator.class).isConsistentLock(getEditingFILE().getPath())) { + if (getEditingFILE().exists() && !WorkContext.getCurrent().get(LockInfoOperator.class).isConsistentLock(getEditingFILE().getPath())) { throw new InconsistentLockException(); } return this.getTarget().export(TemplateResourceManager.getResource().saveTemplate(getEditingFILE())); diff --git a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java index b715ec0b8..38eaab2ba 100644 --- a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java @@ -1,7 +1,8 @@ package com.fr.design.utils; import com.fr.base.extension.FileExtension; -import com.fr.design.file.TemplateTreePane; +import com.fr.base.io.BaseBook; +import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; @@ -15,6 +16,7 @@ import com.fr.stable.CoreConstants; import com.fr.stable.ProductConstants; import com.fr.workspace.WorkContext; import com.fr.workspace.server.lock.TplOperator; +import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.swing.SwingWorker; @@ -58,7 +60,19 @@ public class TemplateUtils { @Override protected Void doInBackground() throws Exception { - byte[] content = WorkContext.getWorkResource().readFully(oldPath); + byte[] content = new byte[0]; + if (!needOpen) { + // 从当前编辑模板中生成备份文件 + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BaseBook target = template.getTarget(); + if (target != null) { + target.export(outputStream); + content = outputStream.toByteArray(); + } + } else { + content = WorkContext.getWorkResource().readFully(oldPath); + } if (ArrayUtils.isEmpty(content)) { throw new Exception(oldPath + " content is empty" ); } @@ -90,7 +104,7 @@ public class TemplateUtils { DesignerContext.getDesignerFrame().openTemplate(file); } } catch (Exception e) { - SaveFailureHandler.Handler.FullDisk.process(e); + SaveFailureHandler.getInstance().process(e); FineLoggerFactory.getLogger().error(e.getMessage(), e); } }