forked from fanruan/design
hades
4 years ago
21 changed files with 524 additions and 1 deletions
@ -0,0 +1,29 @@
|
||||
package com.fr.design.mod; |
||||
|
||||
import com.fr.design.mod.bean.ChangeItem; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/27 |
||||
*/ |
||||
public interface ContentChange<T> { |
||||
|
||||
/** |
||||
* 标识内容替换类型 |
||||
* |
||||
* @return |
||||
*/ |
||||
String type(); |
||||
|
||||
/** |
||||
* 替换详情信息 |
||||
* |
||||
* @return |
||||
*/ |
||||
Map<ChangeItem, ContentReplacer<T>> changeInfo(); |
||||
|
||||
} |
@ -0,0 +1,62 @@
|
||||
package com.fr.design.mod; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.chart.web.ChartHyperRelateCellLink; |
||||
import com.fr.chart.web.ChartHyperRelateFloatLink; |
||||
import com.fr.design.file.filter.ClassFilter; |
||||
import com.fr.invoke.ClassHelper; |
||||
import com.fr.js.JavaScriptImpl; |
||||
import com.fr.stable.Filter; |
||||
import java.util.HashSet; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 管理所有需要替换内容的对象 |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/4/28 |
||||
*/ |
||||
public class ContentObjectManager { |
||||
|
||||
private static ContentObjectManager INSTANCE = new ContentObjectManager(); |
||||
|
||||
public static ContentObjectManager getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
/** |
||||
* 放置所有需要替换内容的对象 |
||||
*/ |
||||
private Map<String, Set<Object>> objectMap; |
||||
|
||||
private final Set<String> set = new HashSet<>(); |
||||
|
||||
private ContentObjectManager() { |
||||
set.add(Formula.class.getName()); |
||||
set.add(JavaScriptImpl.class.getName()); |
||||
set.add(ChartHyperRelateCellLink.class.getName()); |
||||
set.add(ChartHyperRelateFloatLink.class.getName()); |
||||
} |
||||
|
||||
public void searchObject(Object ob) { |
||||
objectMap = ClassHelper.searchObject(ob, set, ClassFilter.getInstance()); |
||||
} |
||||
|
||||
public void searchObject(Object ob, Filter<String> filter) { |
||||
objectMap = ClassHelper.searchObject(ob, set, filter); |
||||
} |
||||
|
||||
public void searchObject(Object ob, Set<String> set, Filter<String> filter) { |
||||
objectMap = ClassHelper.searchObject(ob, set, filter); |
||||
} |
||||
public void clearObject() { |
||||
objectMap = null; |
||||
} |
||||
|
||||
public Map<String, Set<Object>> getObjectMap() { |
||||
return objectMap; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.design.mod; |
||||
|
||||
/** |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/27 |
||||
*/ |
||||
public interface ContentReplacer<T> { |
||||
|
||||
void replace(T t, String oldName, String newName); |
||||
|
||||
} |
@ -0,0 +1,101 @@
|
||||
package com.fr.design.mod; |
||||
|
||||
import com.fr.design.mod.bean.ChangeItem; |
||||
import com.fr.design.mod.bean.ContentChangeItem; |
||||
import com.fr.design.mod.event.TableDataModifyEvent; |
||||
import com.fr.design.mod.event.WidgetNameModifyEvent; |
||||
import com.fr.design.mod.impl.change.ChartHyperRelateCellLinkContentChange; |
||||
import com.fr.design.mod.impl.change.ChartHyperRelateFloatLinkContentChange; |
||||
import com.fr.design.mod.impl.change.FormulaContentChange; |
||||
import com.fr.design.mod.impl.change.JavaScriptContentChange; |
||||
import com.fr.event.Event; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.event.Listener; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 默认联动内容替换器实现 |
||||
* |
||||
* 当前替换顺序:组件名-> 数据集名 |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/27 |
||||
*/ |
||||
public class ContentReplacerCenter { |
||||
|
||||
private static final ContentReplacerCenter INSTANCE = new ContentReplacerCenter(); |
||||
|
||||
public static ContentReplacerCenter getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
private List<ContentChange> contentChangeList = new ArrayList<>(); |
||||
private List<ContentChangeItem> items = new ArrayList<>(); |
||||
|
||||
private ContentReplacerCenter() { |
||||
|
||||
EventDispatcher.listen(WidgetNameModifyEvent.INSTANCE, new Listener<ContentChangeItem>() { |
||||
@Override |
||||
public void on(Event event, ContentChangeItem param) { |
||||
items.add(param); |
||||
} |
||||
}); |
||||
|
||||
EventDispatcher.listen(TableDataModifyEvent.INSTANCE, new Listener<ContentChangeItem>() { |
||||
@Override |
||||
public void on(Event event, ContentChangeItem param) { |
||||
items.add(param); |
||||
long start = System.currentTimeMillis(); |
||||
ContentObjectManager.getInstance().searchObject(param.getObject()); |
||||
FineLoggerFactory.getLogger().debug("search object spend {} ", (System.currentTimeMillis() - start)); |
||||
List<ContentChangeItem> itemsCopy = new ArrayList<>(items); |
||||
items.clear(); |
||||
onRename(itemsCopy, contentChangeList); |
||||
} |
||||
}); |
||||
|
||||
} |
||||
|
||||
public void register() { |
||||
contentChangeList.add(new ChartHyperRelateCellLinkContentChange()); |
||||
contentChangeList.add(new ChartHyperRelateFloatLinkContentChange()); |
||||
contentChangeList.add(new FormulaContentChange()); |
||||
contentChangeList.add(new JavaScriptContentChange()); |
||||
} |
||||
|
||||
private void onRename(List<ContentChangeItem> contentChangeItemList, List<ContentChange> contentChangeList) { |
||||
Map<String, Set<Object>> objectMap = ContentObjectManager.getInstance().getObjectMap(); |
||||
if (objectMap != null) { |
||||
long start = System.currentTimeMillis(); |
||||
for (ContentChange contentChange : contentChangeList) { |
||||
Set<Object> set = objectMap.get(contentChange.type()); |
||||
// 所有需要处理的js等对象
|
||||
if (set != null) { |
||||
for (Object ob : set) { |
||||
fireChange(ob, contentChange, contentChangeItemList); |
||||
} |
||||
} |
||||
} |
||||
objectMap.clear(); |
||||
FineLoggerFactory.getLogger().debug("replace all content spend {} ", (System.currentTimeMillis() - start)); |
||||
} |
||||
} |
||||
|
||||
private void fireChange(Object o, ContentChange contentChange, List<ContentChangeItem> itemList) { |
||||
// 当前两项存在两项: 数据集名称和组件名称
|
||||
for (ContentChangeItem contentChangeItem : itemList) { |
||||
Map<ChangeItem, ContentReplacer> map = contentChange.changeInfo(); |
||||
if (map.containsKey(contentChangeItem.getChangeItem())) { |
||||
// 具体重命名取决于复用组件存在多少个组件或数据集
|
||||
for (Map.Entry<String, String> entry : contentChangeItem.getChangeMap().entrySet()) { |
||||
map.get(contentChangeItem.getChangeItem()).replace(o, entry.getKey(), entry.getValue()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.design.mod.bean; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public enum ChangeItem { |
||||
|
||||
TABLE_DATA_NAME, |
||||
|
||||
WIDGET_NAME |
||||
|
||||
} |
@ -0,0 +1,33 @@
|
||||
package com.fr.design.mod.bean; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class ContentChangeItem { |
||||
|
||||
private final Map<String, String> changeMap; |
||||
private final ChangeItem changeItem; |
||||
private final Object object; |
||||
|
||||
public ContentChangeItem(Map<String, String> changeMap,Object object, ChangeItem changeItem) { |
||||
this.changeMap = changeMap; |
||||
this.changeItem = changeItem; |
||||
this.object = object; |
||||
} |
||||
|
||||
public Map<String, String> getChangeMap() { |
||||
return changeMap; |
||||
} |
||||
|
||||
public ChangeItem getChangeItem() { |
||||
return changeItem; |
||||
} |
||||
|
||||
public Object getObject() { |
||||
return object; |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.fr.design.mod.event; |
||||
|
||||
import com.fr.design.mod.bean.ContentChangeItem; |
||||
import com.fr.event.Event; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class ModifyEvent implements Event<ContentChangeItem> { |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.fr.design.mod.event; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class TableDataModifyEvent extends ModifyEvent { |
||||
|
||||
public static final TableDataModifyEvent INSTANCE = new TableDataModifyEvent(); |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.fr.design.mod.event; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class WidgetNameModifyEvent extends ModifyEvent { |
||||
|
||||
public static final WidgetNameModifyEvent INSTANCE = new WidgetNameModifyEvent(); |
||||
|
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.fr.design.mod.impl.change; |
||||
|
||||
import com.fr.chart.web.ChartHyperRelateCellLink; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class ChartHyperRelateCellLinkContentChange extends ChartHyperRelateLinkContentChange { |
||||
|
||||
@Override |
||||
public String type() { |
||||
return ChartHyperRelateCellLink.class.getName(); |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.fr.design.mod.impl.change; |
||||
|
||||
import com.fr.chart.web.ChartHyperRelateFloatLink; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class ChartHyperRelateFloatLinkContentChange extends ChartHyperRelateLinkContentChange{ |
||||
|
||||
@Override |
||||
public String type() { |
||||
return ChartHyperRelateFloatLink.class.getName(); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.fr.design.mod.impl.change; |
||||
|
||||
import com.fr.chart.web.ChartHyperRelateLink; |
||||
import com.fr.design.mod.ContentChange; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.design.mod.bean.ChangeItem; |
||||
import com.fr.design.mod.impl.repalce.ChartHyperRelateLink4WidgetNameContentReplacer; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/27 |
||||
*/ |
||||
public abstract class ChartHyperRelateLinkContentChange implements ContentChange<ChartHyperRelateLink> { |
||||
|
||||
private final Map<ChangeItem, ContentReplacer<ChartHyperRelateLink>> map; |
||||
|
||||
public ChartHyperRelateLinkContentChange() { |
||||
this.map = new HashMap<>(); |
||||
map.put(ChangeItem.WIDGET_NAME, new ChartHyperRelateLink4WidgetNameContentReplacer()); |
||||
} |
||||
|
||||
@Override |
||||
public Map<ChangeItem, ContentReplacer<ChartHyperRelateLink>> changeInfo() { |
||||
return map; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.fr.design.mod.impl.change; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.design.mod.ContentChange; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.design.mod.bean.ChangeItem; |
||||
import com.fr.design.mod.impl.repalce.Formula4TableDataNameContentReplacer; |
||||
import com.fr.design.mod.impl.repalce.Formula4WidgetNameContentReplacer; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/27 |
||||
*/ |
||||
public class FormulaContentChange implements ContentChange<Formula> { |
||||
|
||||
private final Map<ChangeItem, ContentReplacer<Formula>> map; |
||||
|
||||
public FormulaContentChange() { |
||||
map = new HashMap<>(); |
||||
map.put(ChangeItem.WIDGET_NAME, new Formula4WidgetNameContentReplacer()); |
||||
map.put(ChangeItem.TABLE_DATA_NAME, new Formula4TableDataNameContentReplacer()); |
||||
} |
||||
|
||||
@Override |
||||
public String type() { |
||||
return Formula.class.getName(); |
||||
} |
||||
|
||||
@Override |
||||
public Map<ChangeItem, ContentReplacer<Formula>> changeInfo() { |
||||
return map; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.design.mod.impl.change; |
||||
|
||||
import com.fr.design.mod.ContentChange; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.design.mod.bean.ChangeItem; |
||||
import com.fr.design.mod.impl.repalce.JavaScriptContentReplacer; |
||||
import com.fr.js.JavaScriptImpl; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/27 |
||||
*/ |
||||
public class JavaScriptContentChange implements ContentChange<JavaScriptImpl> { |
||||
|
||||
private final Map<ChangeItem, ContentReplacer<JavaScriptImpl>> map; |
||||
|
||||
public JavaScriptContentChange() { |
||||
map = new HashMap<>(); |
||||
map.put(ChangeItem.WIDGET_NAME, new JavaScriptContentReplacer()); |
||||
map.put(ChangeItem.TABLE_DATA_NAME, new JavaScriptContentReplacer()); |
||||
} |
||||
|
||||
@Override |
||||
public String type() { |
||||
return JavaScriptImpl.class.getName(); |
||||
} |
||||
|
||||
@Override |
||||
public Map<ChangeItem, ContentReplacer<JavaScriptImpl>> changeInfo() { |
||||
return map; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.chart.web.ChartHyperRelateLink; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.general.ComparatorUtils; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class ChartHyperRelateLink4WidgetNameContentReplacer implements ContentReplacer<ChartHyperRelateLink> { |
||||
|
||||
@Override |
||||
public void replace(ChartHyperRelateLink chartHyperRelateLink, String oldName, String newName) { |
||||
if (ComparatorUtils.equals(chartHyperRelateLink.getRelateCCName(), oldName)) { |
||||
chartHyperRelateLink.setRelateCCName(newName); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class Formula4TableDataNameContentReplacer implements ContentReplacer<Formula> { |
||||
|
||||
@Override |
||||
public void replace(Formula formula, String oldName, String newName) { |
||||
//todo 等接口
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,17 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class Formula4WidgetNameContentReplacer implements ContentReplacer<Formula> { |
||||
|
||||
@Override |
||||
public void replace(Formula formula, String oldName, String newName) { |
||||
//todo 等接口
|
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.js.JavaScriptImpl; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/28 |
||||
*/ |
||||
public class JavaScriptContentReplacer implements ContentReplacer<JavaScriptImpl> { |
||||
|
||||
@Override |
||||
public void replace(JavaScriptImpl javaScript, String oldName, String newName) { |
||||
if (StringUtils.isNotEmpty(javaScript.getContent())) { |
||||
javaScript.setContent(javaScript.getContent().replaceAll(generateStr(oldName), generateStr(newName))); |
||||
} |
||||
} |
||||
|
||||
private String generateStr(String str) { |
||||
return "\"" + str + "\""; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue