Browse Source

REPORT-28459 JWorkBook 未释放 同步到final

final/10.0
hades 5 years ago
parent
commit
63d019cb6e
  1. 17
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  2. 28
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java
  3. 33
      designer-base/src/test/java/com/fr/design/file/HistoryTemplateListCacheTest.java

17
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -178,15 +178,28 @@ public class HistoryTemplateListCache implements CallbackEvent {
* @return 位置
*/
public int contains(JTemplate<?, ?> jt) {
return contains(jt, null);
}
public int contains(FILE file) {
return contains(null, file);
}
private int contains(JTemplate jt, FILE file) {
FILE item = null;
if (jt != null) {
item = jt.getEditingFILE();
} else {
item = file;
}
for (int i = 0; i < historyList.size(); i++) {
if (ComparatorUtils.equals(historyList.get(i).getEditingFILE(), jt.getEditingFILE())) {
if (ComparatorUtils.equals(historyList.get(i).getEditingFILE(), item)) {
return i;
}
}
return -1;
}
/**
* 判断是否打开过该模板
* 由于切换环境不会关闭模板可能存在同名的模板所以该方法不能准确找到所选的模板

28
designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java

@ -1085,6 +1085,14 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
*/
private void openFile(FILE tplFile) {
if (tplFile != null) {
int index = HistoryTemplateListCache.getInstance().contains(tplFile);
if (index != -1) {
HistoryTemplateListCache.getInstance().getHistoryList().get(index).activeOldJTemplate();
return;
}
}
JTemplate jt = JTemplateFactory.createJTemplate(tplFile);
if (jt == null) {
return;
@ -1094,26 +1102,6 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
this.addAndActivateJTemplate();
MutilTempalteTabPane.getInstance().setTemTemplate(
HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
} else {
activeTemplate(jt);
}
}
/**
* 激活指定的模板
*
* @param jt 当前报表
* @date 2014-10-14-下午6:31:23
*/
private void activeTemplate(JTemplate jt) {
// 如果该模板已经打开,则进行激活就可以了
int index = HistoryTemplateListCache.getInstance().contains(jt);
List<JTemplate<?, ?>> historyList = HistoryTemplateListCache.getInstance().getHistoryList();
if (index != -1) {
JTemplate currentTemplate = historyList.get(index);
// 双击激活已经打开的模板之前 需要释放一下
currentTemplate.whenClose();
currentTemplate.activeJTemplate(index, jt);
} else {
this.addAndActivateJTemplate(jt);
}

33
designer-base/src/test/java/com/fr/design/file/HistoryTemplateListCacheTest.java

@ -0,0 +1,33 @@
package com.fr.design.file;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import com.fr.invoke.Reflect;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.Assert;
import java.util.ArrayList;
import java.util.Arrays;
/**
* @author hades
* @version 10.0
* Created by hades on 2020/3/23
*/
public class HistoryTemplateListCacheTest extends TestCase {
public void testContains() {
JTemplate jTemplate = EasyMock.mock(JTemplate.class);
FILE file = EasyMock.mock(FILE.class);
EasyMock.expect(jTemplate.getEditingFILE()).andReturn(file).anyTimes();
EasyMock.replay(file);
EasyMock.replay(jTemplate);
Assert.assertEquals(-1, HistoryTemplateListCache.getInstance().contains(file));
Assert.assertEquals(-1, HistoryTemplateListCache.getInstance().contains(jTemplate));
Reflect.on(HistoryTemplateListCache.getInstance()).set("historyList", new ArrayList<>(Arrays.asList(jTemplate)));
Assert.assertEquals(0, HistoryTemplateListCache.getInstance().contains(file));
Assert.assertEquals(0, HistoryTemplateListCache.getInstance().contains(jTemplate));
}
}
Loading…
Cancel
Save