kuangshuai
4 years ago
31 changed files with 1451 additions and 479 deletions
@ -0,0 +1,485 @@
|
||||
package com.fr.design.gui.controlpane; |
||||
|
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.gui.icontainer.UIScrollPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ilist.JNameEdList; |
||||
import com.fr.design.gui.ilist.ListModelElement; |
||||
import com.fr.design.gui.ilist.ModNameActionListener; |
||||
import com.fr.design.gui.ilist.UINameEdList; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.widget.EventCreator; |
||||
import com.fr.form.event.Listener; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.general.NameObject; |
||||
import com.fr.report.web.util.ReportEngineEventMapping; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.Nameable; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.DefaultListModel; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.ListSelectionModel; |
||||
import javax.swing.event.ListDataEvent; |
||||
import javax.swing.event.ListDataListener; |
||||
import javax.swing.event.ListSelectionEvent; |
||||
import javax.swing.event.ListSelectionListener; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import java.awt.FlowLayout; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.lang.reflect.Constructor; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Created by kerry on 5/31/21 |
||||
*/ |
||||
public abstract class UIListGroupControlPane extends UIControlPane implements ListControlPaneProvider { |
||||
private boolean isPopulating = false; |
||||
private UINameEdList selectNameEdList; |
||||
|
||||
private Map<String, ListWrapperPane> nameEdListMap = new HashMap<>(); |
||||
|
||||
private CommonShortCutHandlers commonHandlers; |
||||
|
||||
private ListControlPaneHelper helper; |
||||
|
||||
private JPanel contentPane; |
||||
|
||||
public JPanel getContentPane() { |
||||
return contentPane; |
||||
} |
||||
|
||||
private ListControlPaneHelper getHelper() { |
||||
if (helper == null) { |
||||
helper = ListControlPaneHelper.newInstance(this); |
||||
} |
||||
return helper; |
||||
} |
||||
|
||||
private CommonShortCutHandlers getCommonHandlers() { |
||||
if (commonHandlers == null) { |
||||
commonHandlers = CommonShortCutHandlers.newInstance(this); |
||||
} |
||||
return commonHandlers; |
||||
} |
||||
|
||||
public boolean isPopulating() { |
||||
return isPopulating; |
||||
} |
||||
|
||||
@Override |
||||
protected void initLeftPane(JPanel leftPane) { |
||||
leftPane.add(new UIScrollPane(contentPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 0)), BorderLayout.CENTER); |
||||
} |
||||
|
||||
|
||||
protected void refreshPane(Widget widget, NameableCreator[] creators) { |
||||
refreshContentPane(widget.supportedEvents()); |
||||
refreshNameableCreator(creators); |
||||
populateNameObjects(widget); |
||||
} |
||||
|
||||
|
||||
private void refreshContentPane(String[] supportedEvents) { |
||||
for (String event : supportedEvents) { |
||||
if (nameEdListMap.containsKey(event)) { |
||||
continue; |
||||
} |
||||
UINameEdList list = createJNameList(event); |
||||
ListWrapperPane wrapperPane = new ListWrapperPane(switchLang(event), list); |
||||
if (this.selectNameEdList == null) { |
||||
this.selectNameEdList = wrapperPane.getNameEdList(); |
||||
} |
||||
contentPane.add(wrapperPane); |
||||
nameEdListMap.put(event, wrapperPane); |
||||
} |
||||
} |
||||
|
||||
protected void populateNameObjects(Widget widget) { |
||||
ArrayList<NameObject> nameObjectList = new ArrayList<>(); |
||||
for (int i = 0, size = widget.getListenerSize(); i < size; i++) { |
||||
Listener listener = widget.getListener(i); |
||||
if (!listener.isDefault()) { |
||||
nameObjectList.add(i, new NameObject(switchLang(listener.getEventName()) + (i + 1), listener)); |
||||
} |
||||
} |
||||
populate(getHelper().processCatalog(nameObjectList)); |
||||
checkButtonEnabled(); |
||||
this.repaint(); |
||||
} |
||||
|
||||
private void populate(Map<String, List<NameObject>> map) { |
||||
isPopulating = true; // 加一个标识位,避免切换单元格时,触发 saveSettings
|
||||
Iterator<Map.Entry<String, List<NameObject>>> iterator = map.entrySet().iterator(); |
||||
while (iterator.hasNext()) { |
||||
Map.Entry<String, List<NameObject>> entry = iterator.next(); |
||||
List<NameObject> valueList = entry.getValue(); |
||||
ListWrapperPane eventListWrapperPane = nameEdListMap.get(entry.getKey()); |
||||
populateChildNameList(eventListWrapperPane.getNameEdList(), valueList.toArray(new NameObject[valueList.size()])); |
||||
} |
||||
this.checkButtonEnabled(); |
||||
refreshEventListWrapperPane(); |
||||
isPopulating = false; |
||||
} |
||||
|
||||
private void refreshEventListWrapperPane() { |
||||
Iterator<Map.Entry<String, ListWrapperPane>> iterator = nameEdListMap.entrySet().iterator(); |
||||
while (iterator.hasNext()) { |
||||
Map.Entry<String, ListWrapperPane> entry = iterator.next(); |
||||
ListWrapperPane eventListWrapperPane = entry.getValue(); |
||||
UINameEdList nameEdList = eventListWrapperPane.getNameEdList(); |
||||
int listSize = nameEdList.getModel().getSize(); |
||||
if (this.selectNameEdList.getModel().getSize() == 0 && listSize > 0) { |
||||
this.selectNameEdList = nameEdList; |
||||
} |
||||
eventListWrapperPane.setVisible(listSize > 0); |
||||
} |
||||
if (this.selectNameEdList != null) { |
||||
this.selectNameEdList.setSelectedIndex(0); |
||||
} |
||||
this.repaint(); |
||||
} |
||||
|
||||
|
||||
private void populateChildNameList(UINameEdList nameableList, Nameable[] nameableArray) { |
||||
nameableList.getCellEditor().stopCellEditing(); |
||||
DefaultListModel listModel = (DefaultListModel) nameableList.getModel(); |
||||
listModel.removeAllElements(); |
||||
if (ArrayUtils.isEmpty(nameableArray)) { |
||||
isPopulating = false; |
||||
return; |
||||
} |
||||
|
||||
listModel.setSize(nameableArray.length); |
||||
for (int i = 0; i < nameableArray.length; i++) { |
||||
listModel.set(i, new ListModelElement(nameableArray[i])); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
private UINameEdList createJNameList(String text) { |
||||
UINameEdList nameEdList = new UINameEdList(new DefaultListModel()) { |
||||
@Override |
||||
protected void doAfterLostFocus() { |
||||
((JControlUpdatePane) controlUpdatePane).update(); |
||||
} |
||||
|
||||
@Override |
||||
protected void doAfterStopEditing() { |
||||
saveSettings(); |
||||
} |
||||
}; |
||||
|
||||
nameEdList.setCellRenderer(new UINameableListCellRenderer(true, this.creators)); |
||||
nameEdList.setName(text); |
||||
nameEdList.setSelectionBackground(UIConstants.ATTRIBUTE_PRESS); |
||||
nameEdList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
||||
nameEdList.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseReleased(MouseEvent e) { |
||||
selectNameEdList = nameEdList; |
||||
updateUINameListSelect(); |
||||
} |
||||
}); |
||||
nameEdList.addMouseListener(getHelper().getListMouseListener(nameEdList, this)); |
||||
nameEdList.addModNameActionListener(new ModNameActionListener() { |
||||
@Override |
||||
public void nameModed(int index, String oldName, String newName) { |
||||
saveSettings(); |
||||
} |
||||
}); |
||||
nameEdList.addListSelectionListener(new ListSelectionListener() { |
||||
public void valueChanged(ListSelectionEvent evt) { |
||||
// richie:避免多次update和populate大大降低效率
|
||||
if (!evt.getValueIsAdjusting()) { |
||||
// shoc 切换的时候加检验
|
||||
if (hasInvalid(false)) { |
||||
return; |
||||
} |
||||
((JControlUpdatePane) UIListGroupControlPane.this.controlUpdatePane).update(); |
||||
((JControlUpdatePane) UIListGroupControlPane.this.controlUpdatePane).populate(); |
||||
UIListGroupControlPane.this.checkButtonEnabled(); |
||||
} |
||||
} |
||||
}); |
||||
nameEdList.getModel().addListDataListener(new ListDataListener() { |
||||
@Override |
||||
public void intervalAdded(ListDataEvent e) { |
||||
saveSettings(); |
||||
} |
||||
|
||||
@Override |
||||
public void intervalRemoved(ListDataEvent e) { |
||||
saveSettings(); |
||||
} |
||||
|
||||
@Override |
||||
public void contentsChanged(ListDataEvent e) { |
||||
saveSettings(); |
||||
} |
||||
}); |
||||
return nameEdList; |
||||
} |
||||
|
||||
private void updateUINameListSelect() { |
||||
Iterator<Map.Entry<String, ListWrapperPane>> iterator = nameEdListMap.entrySet().iterator(); |
||||
while (iterator.hasNext()) { |
||||
Map.Entry<String, ListWrapperPane> entry = iterator.next(); |
||||
UINameEdList nameEdList = entry.getValue().getNameEdList(); |
||||
if (nameEdList != selectNameEdList) { |
||||
nameEdList.clearSelection(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void checkButtonEnabled() { |
||||
getHelper().checkButtonEnabled(); |
||||
} |
||||
|
||||
|
||||
|
||||
private String switchLang(String eventName) { |
||||
// 在 properties 文件中找到相应的 key 值
|
||||
String localeKey = ReportEngineEventMapping.getLocaleName(eventName); |
||||
return com.fr.design.i18n.Toolkit.i18nText(localeKey); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* 生成不重复的名字 |
||||
* |
||||
* @param prefix 名字前缀 |
||||
* @return 名字 |
||||
*/ |
||||
@Override |
||||
public String createUnrepeatedName(String prefix) { |
||||
return getCommonHandlers().createUnrepeatedName(prefix); |
||||
} |
||||
|
||||
private void updateSelectedNameList(NameableCreator creator) { |
||||
String eventName = ((EventCreator) creator).getEventName(); |
||||
ListWrapperPane wrapperPane = nameEdListMap.get(eventName); |
||||
wrapperPane.setVisible(true); |
||||
setSelectNameEdList(wrapperPane.getNameEdList()); |
||||
} |
||||
|
||||
private void setSelectNameEdList(UINameEdList nameEdList) { |
||||
if (this.selectNameEdList != null) { |
||||
this.selectNameEdList.clearSelection(); |
||||
} |
||||
this.selectNameEdList = nameEdList; |
||||
} |
||||
|
||||
@Override |
||||
public void onAddItem(NameableCreator creator) { |
||||
updateSelectedNameList(creator); |
||||
getCommonHandlers().onAddItem(creator); |
||||
} |
||||
|
||||
@Override |
||||
public void onRemoveItem() { |
||||
getCommonHandlers().onRemoveItem(); |
||||
refreshEventListWrapperPane(); |
||||
} |
||||
|
||||
@Override |
||||
public void onCopyItem() { |
||||
getCommonHandlers().onCopyItem(); |
||||
} |
||||
|
||||
@Override |
||||
public void onMoveUpItem() { |
||||
getCommonHandlers().onMoveUpItem(); |
||||
} |
||||
|
||||
@Override |
||||
public void onMoveDownItem() { |
||||
getCommonHandlers().onMoveDownItem(); |
||||
} |
||||
|
||||
@Override |
||||
public void onSortItem(boolean isAtoZ) { |
||||
Iterator<Map.Entry<String, ListWrapperPane>> iterator = nameEdListMap.entrySet().iterator(); |
||||
while (iterator.hasNext()) { |
||||
Map.Entry<String, ListWrapperPane> entry = iterator.next(); |
||||
UINameEdList nameEdList = entry.getValue().getNameEdList(); |
||||
getCommonHandlers().onSortItem(isAtoZ, nameEdList); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public boolean isItemSelected() { |
||||
return getModel().getSize() > 0 && getSelectedIndex() != -1; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected JPanel createControlUpdatePane() { |
||||
return JControlUpdatePane.newInstance(this); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Nameable[] update() { |
||||
java.util.List<Nameable> res = new java.util.ArrayList<Nameable>(); |
||||
getControlUpdatePane().update(); |
||||
Iterator<Map.Entry<String, ListWrapperPane>> iterator = nameEdListMap.entrySet().iterator(); |
||||
while (iterator.hasNext()) { |
||||
Map.Entry<String, ListWrapperPane> entry = iterator.next(); |
||||
UINameEdList nameEdList = entry.getValue().getNameEdList(); |
||||
DefaultListModel listModel = (DefaultListModel) nameEdList.getModel(); |
||||
for (int i = 0, len = listModel.getSize(); i < len; i++) { |
||||
res.add(((ListModelElement) listModel.getElementAt(i)).wrapper); |
||||
} |
||||
} |
||||
return res.toArray(new Nameable[0]); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public abstract NameableCreator[] createNameableCreators(); |
||||
|
||||
@Override |
||||
public abstract void saveSettings(); |
||||
|
||||
|
||||
public BasicBeanPane createPaneByCreators(NameableCreator creator) { |
||||
try { |
||||
return creator.getUpdatePane().newInstance(); |
||||
} catch (InstantiationException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (IllegalAccessException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
public BasicBeanPane createPaneByCreators(NameableCreator creator, String string) { |
||||
Constructor constructor = null; |
||||
try { |
||||
constructor = creator.getUpdatePane().getDeclaredConstructor(new Class[]{String.class}); |
||||
constructor.setAccessible(true); |
||||
return (BasicBeanPane) constructor.newInstance(string); |
||||
} catch (NoSuchMethodException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (InstantiationException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (IllegalAccessException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (InvocationTargetException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public DefaultListModel getModel() { |
||||
if (this.selectNameEdList == null) { |
||||
return new DefaultListModel(); |
||||
} |
||||
return (DefaultListModel) this.selectNameEdList.getModel(); |
||||
} |
||||
|
||||
/** |
||||
* 检查是否符合规范 |
||||
* |
||||
* @throws Exception |
||||
*/ |
||||
@Override |
||||
public void checkValid() throws Exception { |
||||
((JControlUpdatePane) this.controlUpdatePane).checkValid(); |
||||
} |
||||
|
||||
@Override |
||||
public boolean hasInvalid(boolean isAdd) { |
||||
return getHelper().hasInvalid(isAdd); |
||||
} |
||||
|
||||
public void addNameable(Nameable nameable, int index) { |
||||
getHelper().addNameable(nameable, index); |
||||
popupEditDialog(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 设置选中项 |
||||
* |
||||
* @param index 选中项的序列号 |
||||
*/ |
||||
public void setSelectedIndex(int index) { |
||||
if (this.selectNameEdList != null) { |
||||
this.selectNameEdList.setSelectedIndex(index); |
||||
|
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getSelectedIndex() { |
||||
if (this.selectNameEdList == null) { |
||||
return -1; |
||||
} |
||||
return this.selectNameEdList.getSelectedIndex(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public ListModelElement getSelectedValue() { |
||||
if (this.selectNameEdList == null) { |
||||
return null; |
||||
} |
||||
return (ListModelElement) this.selectNameEdList.getSelectedValue(); |
||||
} |
||||
|
||||
@Override |
||||
public JControlUpdatePane getControlUpdatePane() { |
||||
return (JControlUpdatePane) controlUpdatePane; |
||||
} |
||||
|
||||
@Override |
||||
public JNameEdList getNameableList() { |
||||
return this.selectNameEdList; |
||||
} |
||||
|
||||
private void popupEditDialog() { |
||||
getHelper().popupEditDialog(null, this.selectNameEdList, this); |
||||
} |
||||
|
||||
protected String getWrapperLabelText(){ |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
|
||||
private class ListWrapperPane extends JPanel { |
||||
private UINameEdList nameEdList; |
||||
|
||||
public ListWrapperPane(String labelText, UINameEdList nameEdList) { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
UILabel label = new UILabel(labelText + getWrapperLabelText()); |
||||
label.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); |
||||
label.setBackground(Color.decode("#FFFFFF")); |
||||
label.setPreferredSize(new Dimension(224, 26)); |
||||
this.nameEdList = nameEdList; |
||||
this.add(label, BorderLayout.NORTH); |
||||
this.add(this.nameEdList, BorderLayout.CENTER); |
||||
} |
||||
|
||||
public UINameEdList getNameEdList() { |
||||
return this.nameEdList; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -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,66 @@
|
||||
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.plugin.chart.base.VanChartHtmlLabel; |
||||
import com.fr.stable.Filter; |
||||
import java.util.HashSet; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
/** |
||||
* 管理所有需要替换内容的对象 |
||||
* |
||||
* @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()); |
||||
set.add(VanChartHtmlLabel.class.getName()); |
||||
} |
||||
|
||||
public void searchObject(Object ob) { |
||||
objectMap = ClassHelper.searchObject(ob, set, ModClassFilter.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; |
||||
} |
||||
|
||||
@Nullable |
||||
public Map<String, Set<Object>> getObjectMap() { |
||||
return objectMap; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.fr.design.mod; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/31 |
||||
*/ |
||||
public class ContentReplaceUtil { |
||||
|
||||
public static final String EQ_STRING = "="; |
||||
|
||||
public static String replaceContent(String content, String oldName, String newName) { |
||||
return content.replaceAll(generateStr(oldName), generateStr(newName)); |
||||
} |
||||
|
||||
private static String generateStr(String str) { |
||||
return "\"" + str + "\""; |
||||
} |
||||
|
||||
} |
@ -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,108 @@
|
||||
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.design.mod.impl.change.VanChartHtmlLabelContentChange; |
||||
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) { |
||||
if (param.getChangeMap().isEmpty()) { |
||||
return; |
||||
} |
||||
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 {} ms", (System.currentTimeMillis() - start)); |
||||
FineLoggerFactory.getLogger().debug("search result: {}", ContentObjectManager.getInstance().getObjectMap() == null |
||||
? null : ContentObjectManager.getInstance().getObjectMap().keySet()); |
||||
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()); |
||||
contentChangeList.add(new VanChartHtmlLabelContentChange()); |
||||
} |
||||
|
||||
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 {} ms", (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,33 @@
|
||||
package com.fr.design.mod; |
||||
|
||||
import com.fr.stable.Filter; |
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/31 |
||||
*/ |
||||
public class ModClassFilter implements Filter<String> { |
||||
|
||||
private static final Set<String> FILTER_SET = new HashSet<>(); |
||||
|
||||
private static final Filter<String> INSTANCE = new ModClassFilter(); |
||||
|
||||
public static Filter<String> getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
static { |
||||
FILTER_SET.add("java.awt.image.BufferedImage"); |
||||
FILTER_SET.add("sun.awt.AppContext"); |
||||
FILTER_SET.add("com.fr.poly.creator.ECBlockCreator"); |
||||
FILTER_SET.add("io.netty.channel.nio.SelectedSelectionKeySet"); |
||||
} |
||||
|
||||
@Override |
||||
public boolean accept(String s) { |
||||
return FILTER_SET.contains(s); |
||||
} |
||||
} |
@ -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,35 @@
|
||||
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.VanChartHtmlLabelContentReplacer; |
||||
import com.fr.plugin.chart.base.VanChartHtmlLabel; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/31 |
||||
*/ |
||||
public class VanChartHtmlLabelContentChange implements ContentChange<VanChartHtmlLabel> { |
||||
|
||||
private final Map<ChangeItem, ContentReplacer<VanChartHtmlLabel>> map; |
||||
|
||||
public VanChartHtmlLabelContentChange() { |
||||
map = new HashMap<>(); |
||||
map.put(ChangeItem.WIDGET_NAME, new VanChartHtmlLabelContentReplacer()); |
||||
map.put(ChangeItem.TABLE_DATA_NAME, new VanChartHtmlLabelContentReplacer()); |
||||
} |
||||
|
||||
@Override |
||||
public String type() { |
||||
return VanChartHtmlLabel.class.getName(); |
||||
} |
||||
|
||||
@Override |
||||
public Map<ChangeItem, ContentReplacer<VanChartHtmlLabel>> 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,22 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.design.mod.ContentReplaceUtil; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.parser.FRFormulaTransformer; |
||||
|
||||
/** |
||||
* @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) { |
||||
FRFormulaTransformer frFormulaTransformer = new FRFormulaTransformer(); |
||||
frFormulaTransformer.addRenamedDataset(oldName, newName); |
||||
formula.setContent(ContentReplaceUtil.EQ_STRING + frFormulaTransformer.transform(formula.getPureContent())); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.design.mod.ContentReplaceUtil; |
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.parser.FRFormulaTransformer; |
||||
|
||||
/** |
||||
* @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) { |
||||
FRFormulaTransformer frFormulaTransformer = new FRFormulaTransformer(); |
||||
frFormulaTransformer.addRenamedWidget(oldName, newName); |
||||
formula.setContent(ContentReplaceUtil.EQ_STRING + frFormulaTransformer.transform(formula.getPureContent())); |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.design.mod.ContentReplaceUtil; |
||||
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(ContentReplaceUtil.replaceContent(javaScript.getContent(), oldName, newName)); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.fr.design.mod.impl.repalce; |
||||
|
||||
import com.fr.design.mod.ContentReplacer; |
||||
import com.fr.design.mod.ContentReplaceUtil; |
||||
import com.fr.plugin.chart.base.VanChartHtmlLabel; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/5/31 |
||||
*/ |
||||
public class VanChartHtmlLabelContentReplacer implements ContentReplacer<VanChartHtmlLabel> { |
||||
|
||||
@Override |
||||
public void replace(VanChartHtmlLabel vanChartHtmlLabel, String oldName, String newName) { |
||||
if (StringUtils.isNotEmpty(vanChartHtmlLabel.getCustomText())) { |
||||
vanChartHtmlLabel.setCustomText( |
||||
ContentReplaceUtil.replaceContent(vanChartHtmlLabel.getCustomText(), oldName, newName)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,106 @@
|
||||
package com.fr.design.mainframe.app; |
||||
|
||||
import com.fr.invoke.Reflect; |
||||
import com.fr.plugin.context.PluginMarker; |
||||
import com.fr.plugin.context.PluginMarkerAdapter; |
||||
import com.fr.plugin.engine.remote.PluginRemoteSync; |
||||
import com.fr.stable.TemplateIOErrorContextHolder; |
||||
import com.fr.third.guava.collect.Multimap; |
||||
import org.easymock.EasyMock; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.powermock.api.easymock.PowerMock; |
||||
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||
import org.powermock.modules.junit4.PowerMockRunner; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.HashMap; |
||||
import java.util.HashSet; |
||||
|
||||
/** |
||||
* @author vito |
||||
* @version 10.0 |
||||
* Created by vito on 2021/5/31 |
||||
*/ |
||||
@RunWith(PowerMockRunner.class) |
||||
@PrepareForTest({PluginRemoteSync.class}) |
||||
public class DesignerAppUtilsTest { |
||||
@Test |
||||
public void testDealWithErrorDetailMultiLineAndCache() { |
||||
TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{ |
||||
put("2", "好用的插件"); |
||||
}},new HashSet<>()); |
||||
TemplateIOErrorContextHolder.addNeedEnablePlugin(PluginMarkerAdapter.create("1", "1.0", "1插件")); |
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("2", "1.0")); |
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("3", "1.0")); |
||||
String log = DesignerAppUtils.dealWithErrorDetailMultiLineAndCache("template1"); |
||||
Assert.assertTrue(log.contains("1插件")); |
||||
Assert.assertTrue(log.contains("好用的插件")); |
||||
Assert.assertTrue(log.contains("3")); |
||||
Multimap<String, PluginMarkerAdapter> map = DesignerAppUtils.popPluginInfoMap("template1"); |
||||
Assert.assertEquals(3, map.size()); |
||||
Assert.assertNull(DesignerAppUtils.popPluginInfoMap("template1")); |
||||
} |
||||
|
||||
@Test |
||||
public void testInvalidatePlugins() { |
||||
TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{ |
||||
put("2", "好用的插件"); |
||||
}},new HashSet<>()); |
||||
TemplateIOErrorContextHolder.addNeedEnablePlugin(PluginMarkerAdapter.create("1", "1.0", "1插件")); |
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("2", "1.0")); |
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("3", "1.0")); |
||||
String log = DesignerAppUtils.dealWithErrorDetailMultiLineAndCache("template1"); |
||||
Assert.assertTrue(log.contains("1插件")); |
||||
Assert.assertTrue(log.contains("好用的插件")); |
||||
Assert.assertTrue(log.contains("3")); |
||||
DesignerAppUtils.invalidatePlugins("template1"); |
||||
Assert.assertNull(DesignerAppUtils.popPluginInfoMap("template1")); |
||||
} |
||||
|
||||
@Test |
||||
public void testRearrange(){ |
||||
// 远程插件模拟注册
|
||||
PluginRemoteSync pluginRemoteSync = EasyMock.createMock(PluginRemoteSync.class); |
||||
EasyMock.expect(pluginRemoteSync.getPluginRemoteStatusByIdIndex()).andReturn(new HashMap<String, PluginRemoteSync.PluginStatus>(){{ |
||||
put("com.fr.plugin1", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin1","1",true).get()); |
||||
put("com.fr.plugin2", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin2","1",true).get()); |
||||
put("com.fr.plugin3", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin3","1",false).get()); |
||||
put("com.fr.plugin4", Reflect.on(PluginRemoteSync.PluginStatus.class).call("create","com.fr.plugin4","1",false).get()); |
||||
}}).anyTimes(); |
||||
EasyMock.replay(pluginRemoteSync); |
||||
PowerMock.mockStaticPartial(PluginRemoteSync.class, "getInstance"); |
||||
EasyMock.expect(PluginRemoteSync.getInstance()).andReturn(pluginRemoteSync).anyTimes(); |
||||
PowerMock.replay(PluginRemoteSync.class); |
||||
|
||||
// 本地插件模拟检查
|
||||
TemplateIOErrorContextHolder.registerPluginNameMap(new HashMap<String, String>() {{ |
||||
put("com.fr.plugin1", "好用的插件1"); |
||||
put("com.fr.plugin2", "好用的插件2"); |
||||
put("com.fr.plugin3", "好用的插件3"); |
||||
put("com.fr.plugin4", "好用的插件4"); |
||||
put("com.fr.plugin5", "好用的插件5"); |
||||
}},new HashSet<>()); |
||||
// unknown
|
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("com.fr.plugin7", "1")); |
||||
// disable
|
||||
TemplateIOErrorContextHolder.addNeedEnablePlugin(PluginMarkerAdapter.create("com.fr.plugin5", "1", "plugin5")); |
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("com.fr.plugin3", "1")); |
||||
// not install
|
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("com.fr.plugin1", "1")); |
||||
TemplateIOErrorContextHolder.addNeedInstallPlugin(PluginMarker.create("com.fr.plugin4", "1")); |
||||
|
||||
Multimap<String, PluginMarkerAdapter> pendingPlugins = TemplateIOErrorContextHolder.getPendingPlugin(); |
||||
|
||||
Reflect.on(DesignerAppUtils.class).call("rearrange",pendingPlugins).get(); |
||||
Assert.assertEquals(1,pendingPlugins.get(TemplateIOErrorContextHolder.UNKNOWN_PLUGIN).size()); |
||||
Collection<PluginMarkerAdapter> pluginMarkerAdapters = pendingPlugins.get(TemplateIOErrorContextHolder.DISABLE_PLUGIN); |
||||
Assert.assertEquals(2, pluginMarkerAdapters.size()); |
||||
pluginMarkerAdapters.contains(PluginMarker.create("com.fr.plugin3", "1")); |
||||
pluginMarkerAdapters.contains(PluginMarker.create("com.fr.plugin4", "1")); |
||||
Collection<PluginMarkerAdapter> pluginMarkerAdapters1 = pendingPlugins.get(TemplateIOErrorContextHolder.NOT_INSTALLED_PLUGIN); |
||||
Assert.assertEquals(1, pluginMarkerAdapters1.size()); |
||||
pluginMarkerAdapters1.contains(PluginMarker.create("com.fr.plugin5","1")); |
||||
} |
||||
} |
Loading…
Reference in new issue