forked from fanruan/design
Lanlan
4 years ago
10 changed files with 202 additions and 64 deletions
@ -0,0 +1,78 @@
|
||||
package com.fr.design; |
||||
|
||||
import com.fr.design.constants.DesignerLaunchStatus; |
||||
import com.fr.design.file.HistoryTemplateListCache; |
||||
import com.fr.design.fun.HyperlinkProvider; |
||||
import com.fr.design.fun.TableDataDefineProvider; |
||||
import com.fr.plugin.observer.PluginEvent; |
||||
import com.fr.plugin.observer.PluginEventListener; |
||||
import com.fr.plugin.observer.PluginEventType; |
||||
import com.fr.plugin.observer.PluginListenerRegistration; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/12/17 |
||||
*/ |
||||
public class PluginClassRefreshManager { |
||||
|
||||
|
||||
private static final PluginClassRefreshManager INSTANCE = new PluginClassRefreshManager(); |
||||
|
||||
private final Set<String> context = new HashSet<>(); |
||||
|
||||
private final PluginEventListener pluginAfterRunEventListener = new PluginEventListener() { |
||||
@Override |
||||
public void on(PluginEvent event) { |
||||
// 兼容之前版本特性
|
||||
for (String tag : context) { |
||||
if (event.getContext().contain(tag)) { |
||||
HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); |
||||
return; |
||||
} |
||||
} |
||||
// 重新载入模板xml内容 到 Workbook/Form对象中
|
||||
HistoryTemplateListCache.getInstance().reloadAllEditingTemplateByPlugin(event.getContext()); |
||||
} |
||||
}; |
||||
|
||||
|
||||
public static PluginClassRefreshManager getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
public void load() { |
||||
context.add(TableDataDefineProvider.XML_TAG); |
||||
context.add(HyperlinkProvider.XML_TAG); |
||||
} |
||||
|
||||
private PluginClassRefreshManager() { |
||||
PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeAllActive, new PluginEventListener() { |
||||
@Override |
||||
public void on(PluginEvent event) { |
||||
removePluginListener(); |
||||
} |
||||
}); |
||||
PluginListenerRegistration.getInstance().listen(PluginEventType.AfterAllActive, new PluginEventListener() { |
||||
@Override |
||||
public void on(PluginEvent event) { |
||||
addPluginListener(); |
||||
if (DesignerLaunchStatus.getStatus() != DesignerLaunchStatus.WORKSPACE_INIT_COMPLETE) { |
||||
HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public void removePluginListener() { |
||||
PluginListenerRegistration.getInstance().stopListen(this.pluginAfterRunEventListener); |
||||
} |
||||
|
||||
public void addPluginListener() { |
||||
PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.fr.base; |
||||
|
||||
import com.fr.form.main.Form; |
||||
import com.fr.invoke.ClassHelper; |
||||
import com.fr.main.impl.WorkBook; |
||||
import java.util.Set; |
||||
import junit.framework.TestCase; |
||||
import org.junit.Assert; |
||||
|
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/12/28 |
||||
*/ |
||||
public class ClassHelperTest extends TestCase { |
||||
|
||||
|
||||
public void testGetClassLoaders() { |
||||
WorkBook workBook = new WorkBook(); |
||||
Set<ClassLoader> set = ClassHelper.getClassLoaders(workBook); |
||||
Assert.assertFalse(set.isEmpty()); |
||||
Form form = new Form(); |
||||
Set<ClassLoader> set1 = ClassHelper.getClassLoaders(form); |
||||
Assert.assertFalse(set1.isEmpty()); |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue