@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.SwingWorker ;
import javax.swing.SwingWorker ;
import java.io.OutputStream ;
import java.io.OutputStream ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.List ;
import java.util.concurrent.CompletableFuture ;
import java.util.concurrent.CompletableFuture ;
import java.util.function.Function ;
import java.util.function.Function ;
@ -65,14 +66,7 @@ public class TemplateUtils {
if ( file = = null ) {
if ( file = = null ) {
return ;
return ;
}
}
Runnable doAfterCreateTemplate ;
createAndOpenTemplate0 ( file , oldPath , createByEditingTemplate , openNewTemplate , null ) ;
//判断一下要保存的文件是否已打开
int index = HistoryTemplateListCache . getInstance ( ) . contains ( file ) ;
JTemplate template = null ;
if ( index ! = - 1 ) {
template = HistoryTemplateListCache . getInstance ( ) . getHistoryList ( ) . get ( index ) ;
}
createAndOpenTemplate0 ( file , oldPath , createByEditingTemplate , openNewTemplate , template ) ;
}
}
/ * *
/ * *
@ -181,23 +175,29 @@ public class TemplateUtils {
* @param template 需要关闭的模板
* @param template 需要关闭的模板
* /
* /
private static void openNewTemplateAndCloseOldTemplate ( FILE file , boolean openNewTemplate , @Nullable JTemplate < ? , ? > template ) {
private static void openNewTemplateAndCloseOldTemplate ( FILE file , boolean openNewTemplate , @Nullable JTemplate < ? , ? > template ) {
new SwingWorker < Boolean , Void > ( ) {
new SwingWorker < List < JTemplate < ? , ? > > , Void > ( ) {
@Override
@Override
protected Boolean doInBackground ( ) throws Exception {
protected List < JTemplate < ? , ? > > doInBackground ( ) throws Exception {
List < JTemplate < ? , ? > > needCloseTemplate = new ArrayList < > ( ) ;
//判断一下要保存的副本文件是否已打开
int index = HistoryTemplateListCache . getInstance ( ) . contains ( file ) ;
if ( index ! = - 1 ) {
WorkContext . getCurrent ( ) . get ( TplOperator . class ) . closeAndFreeFile ( file . getPath ( ) ) ;
needCloseTemplate . add ( HistoryTemplateListCache . getInstance ( ) . getHistoryList ( ) . get ( index ) ) ;
}
if ( JTemplate . isValid ( template ) ) {
if ( JTemplate . isValid ( template ) ) {
//给要关闭的模板解锁
//给要关闭的模板解锁
WorkContext . getCurrent ( ) . get ( TplOperator . class ) . closeAndFreeFile ( template . getPath ( ) ) ;
WorkContext . getCurrent ( ) . get ( TplOperator . class ) . closeAndFreeFile ( template . getPath ( ) ) ;
return true ;
needCloseTemplate . add ( template ) ;
}
}
return false ;
return needCloseTemplat e;
}
}
@Override
@Override
protected void done ( ) {
protected void done ( ) {
try {
try {
if ( get ( ) ) {
//获取需要关闭的模板
//模板释放锁成功后关闭该模板
List < JTemplate < ? , ? > > jTemplates = get ( ) ;
HistoryTemplateListCache . getInstance ( ) . closeSelectedReport ( template ) ;
jTemplates . forEach ( jTemplate - > HistoryTemplateListCache . getInstance ( ) . closeSelectedReport ( jTemplate ) ) ;
}
if ( openNewTemplate ) {
if ( openNewTemplate ) {
DesignerContext . getDesignerFrame ( ) . openTemplate ( file ) ;
DesignerContext . getDesignerFrame ( ) . openTemplate ( file ) ;
}
}