Browse Source
# Conflicts: # designer-base/src/main/java/com/fr/design/mainframe/JTemplate.javafeature/x
kerry
2 years ago
6 changed files with 325 additions and 64 deletions
@ -0,0 +1,50 @@
|
||||
package com.fr.design.worker.save.type; |
||||
|
||||
/** |
||||
* 保存的类别 |
||||
* |
||||
* @author John.Ying |
||||
* @since 11.0 |
||||
* Created on 2023/4/14 |
||||
*/ |
||||
public class SaveType { |
||||
|
||||
private TypeEnum type; |
||||
//保存时间是否慢(是否展示了保存中的UI界面)
|
||||
private boolean slowly; |
||||
|
||||
public TypeEnum getType() { |
||||
return type; |
||||
} |
||||
|
||||
public void setType(TypeEnum saveType) { |
||||
this.type = saveType; |
||||
} |
||||
|
||||
public boolean isSlowly() { |
||||
return slowly; |
||||
} |
||||
|
||||
public void setSlowly(boolean slowly) { |
||||
this.slowly = slowly; |
||||
} |
||||
|
||||
/** |
||||
* 保存类型:save or saveAs or empty |
||||
*/ |
||||
public enum TypeEnum { |
||||
/** |
||||
* 保存 |
||||
*/ |
||||
SAVE, |
||||
/** |
||||
* 另存 |
||||
*/ |
||||
SAVE_AS, |
||||
/** |
||||
* 空保存 |
||||
*/ |
||||
EMPTY; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,81 @@
|
||||
package com.fr.design.worker.save.type; |
||||
|
||||
|
||||
import com.fr.concurrent.FineExecutors; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.mainframe.DesignerFrameFileDealerPane; |
||||
import com.fr.design.mainframe.EastRegionContainerPane; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.ui.util.UIUtil; |
||||
import com.fr.third.org.apache.commons.lang3.time.StopWatch; |
||||
|
||||
import javax.swing.SwingWorker; |
||||
import java.util.concurrent.Callable; |
||||
import java.util.concurrent.ExecutorService; |
||||
|
||||
/** |
||||
* 判断保存类别时执行的worker |
||||
* |
||||
* @author John.Ying |
||||
* @since 11.0 |
||||
* Created on 2023/4/14 |
||||
*/ |
||||
public class SaveTypeWorker extends SwingWorker<SaveType, Void> { |
||||
|
||||
public static final ExecutorService SAVE_TYPE_POOL = FineExecutors.newSingleThreadExecutor(); |
||||
|
||||
private final Callable<SaveType.TypeEnum> callable; |
||||
|
||||
private static final int TIME_OUT = 400; |
||||
|
||||
private final JTemplate<?, ?> template; |
||||
|
||||
private final SaveType saveType; |
||||
|
||||
|
||||
|
||||
public SaveTypeWorker(Callable<SaveType.TypeEnum> callable, JTemplate<?, ?> template) { |
||||
this.callable = callable; |
||||
this.template = template; |
||||
this.saveType = new SaveType(); |
||||
} |
||||
|
||||
@Override |
||||
protected SaveType doInBackground() throws Exception { |
||||
this.saveType.setType(callable.call()); |
||||
return this.saveType; |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 启动saveTypeWorker |
||||
*/ |
||||
public void start() { |
||||
StopWatch stopWatch = StopWatch.createStarted(); |
||||
this.template.setSaving(true); |
||||
this.execute(); |
||||
SAVE_TYPE_POOL.execute(() -> { |
||||
while (true) { |
||||
//大于最大等待时间或者worker已经完成该线程都要结束循环
|
||||
if (stopWatch.getTime() > TIME_OUT || isDone()) { |
||||
//如果是大于最大等待时间结束的,就需要进行等待中界面的覆盖
|
||||
if (!isDone()) { |
||||
saveType.setSlowly(true); |
||||
UIUtil.invokeLaterIfNeeded(() -> { |
||||
// 开始禁用
|
||||
EastRegionContainerPane.getInstance().updateAllPropertyPane(); |
||||
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover(); |
||||
DesignerFrameFileDealerPane.getInstance().stateChange(); |
||||
}); |
||||
} |
||||
stopWatch.stop(); |
||||
break; |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue