Browse Source
* commit '65b06141b8cfc1d98b2e04dbbcb245ee8a722a16': REPORT-83064【运营产品化二期】10.0仍显示为应用中心,应该改名为插件中心 1、修改国际化 2、排序bug fix REPORT-82937 运营产品化二期的二期,同步到10.0 代码从11合到10 REPORT-82937 运营产品化二期的二期,同步到10.0 代码从11合到10persist/10.0 10.0.19.2022.11.17
superman
2 years ago
78 changed files with 1393 additions and 287 deletions
@ -0,0 +1,229 @@
|
||||
package com.fr.design.actions.help.alphafine.component; |
||||
|
||||
import com.fr.base.svg.IconUtils; |
||||
import com.fr.design.actions.help.alphafine.AlphaFineConfigPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.SwingUtilities; |
||||
import javax.swing.plaf.PanelUI; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Dimension; |
||||
import java.awt.FlowLayout; |
||||
import java.util.ArrayList; |
||||
import java.util.Comparator; |
||||
import java.util.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.function.Function; |
||||
|
||||
/** |
||||
* alphafine设置 - 搜索范围 - 自定义排序 - 弹出面板 |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/18 |
||||
*/ |
||||
public class CustomSortPane extends JPanel { |
||||
|
||||
|
||||
private static final int WIDTH = 147; |
||||
private static final int ITEM_HEIGHT = 23; |
||||
private static final int GAP = 1; |
||||
private static final Color BACKGROUND_COLOR = new Color(0xdadadd); |
||||
|
||||
private UIButton top; |
||||
private UIButton bottom; |
||||
private UIButton up; |
||||
private UIButton down; |
||||
private JPanel toolbarPane; |
||||
private MenuLabelPane sortItemPane; |
||||
private List<UICheckBox> sortItems; |
||||
private MenuLabel selectedLabel; |
||||
private AlphaFineConfigPane parentPane; |
||||
|
||||
public CustomSortPane(List<UICheckBox> items, AlphaFineConfigPane parentPane) { |
||||
this.sortItems = items; |
||||
this.parentPane = parentPane; |
||||
setLayout(new BorderLayout(GAP, GAP)); |
||||
int height = (sortItems.size() + 1) * (ITEM_HEIGHT + GAP) + GAP; |
||||
setPreferredSize(new Dimension(WIDTH, height)); |
||||
initComponent(); |
||||
add(toolbarPane, BorderLayout.NORTH); |
||||
add(sortItemPane, BorderLayout.CENTER); |
||||
revalidate(); |
||||
this.setVisible(true); |
||||
} |
||||
|
||||
@Override |
||||
public void setUI(PanelUI ui) { |
||||
super.setUI(ui); |
||||
setBackground(BACKGROUND_COLOR); |
||||
|
||||
} |
||||
|
||||
private void initComponent() { |
||||
createToolbarPane(); |
||||
createSortItemPane(); |
||||
} |
||||
|
||||
private void createToolbarPane() { |
||||
top = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/top.svg"), false); |
||||
bottom = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/bottom.svg"), false); |
||||
up = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/up.svg"), false); |
||||
down = new UIButton(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/down.svg"), false); |
||||
top.setDisabledIcon(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/top_disable.svg")); |
||||
bottom.setDisabledIcon(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/bottom_disable.svg")); |
||||
up.setDisabledIcon(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/up_disable.svg")); |
||||
down.setDisabledIcon(IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/down_disable.svg")); |
||||
top.addActionListener(e -> { |
||||
SwingUtilities.invokeLater(() -> { |
||||
sortItemPane.setComponentZOrder(selectedLabel, 0); |
||||
setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); |
||||
CustomSortPane.this.revalidate(); |
||||
CustomSortPane.this.repaint(); |
||||
refreshCurrentOrder(); |
||||
}); |
||||
|
||||
}); |
||||
bottom.addActionListener(e -> { |
||||
SwingUtilities.invokeLater(() -> { |
||||
sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentCount() - 1); |
||||
setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); |
||||
CustomSortPane.this.revalidate(); |
||||
CustomSortPane.this.repaint(); |
||||
refreshCurrentOrder(); |
||||
}); |
||||
|
||||
}); |
||||
up.addActionListener(e -> { |
||||
SwingUtilities.invokeLater(() -> { |
||||
sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentZOrder(selectedLabel) - 1); |
||||
setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); |
||||
CustomSortPane.this.revalidate(); |
||||
CustomSortPane.this.repaint(); |
||||
refreshCurrentOrder(); |
||||
}); |
||||
|
||||
}); |
||||
down.addActionListener(e -> { |
||||
SwingUtilities.invokeLater(() -> { |
||||
sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentZOrder(selectedLabel) + 1); |
||||
setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); |
||||
CustomSortPane.this.revalidate(); |
||||
CustomSortPane.this.repaint(); |
||||
refreshCurrentOrder(); |
||||
}); |
||||
|
||||
}); |
||||
toolbarPane = new JPanel(new FlowLayout(FlowLayout.TRAILING, GAP, GAP)); |
||||
toolbarPane.setBorder(BorderFactory.createEmptyBorder()); |
||||
toolbarPane.add(top); |
||||
toolbarPane.add(bottom); |
||||
toolbarPane.add(up); |
||||
toolbarPane.add(down); |
||||
} |
||||
|
||||
private void createSortItemPane() { |
||||
String[] currentTabOrder = parentPane.getCurrentOrder(); |
||||
Map<String, Integer> sortMap = new HashMap<>(); |
||||
for (int i = 0; i < currentTabOrder.length; i++) { |
||||
sortMap.put(currentTabOrder[i], i); |
||||
} |
||||
List<MenuLabel> sortLabels = new ArrayList<>(); |
||||
for (UICheckBox item : sortItems) { |
||||
MenuLabel label = new MenuLabel(item.getText(), (Function<MenuLabel, Object>) o -> { |
||||
selectedLabel = o; |
||||
disableButton(); |
||||
return null; |
||||
}); |
||||
sortLabels.add(label); |
||||
} |
||||
sortLabels.sort(Comparator.comparingInt(tab -> sortMap.get(tab.getText()))); |
||||
sortItemPane = new MenuLabelPane(sortLabels); |
||||
} |
||||
|
||||
/** |
||||
* 如果选中第一个和最后一个,则置灰向上和向下的按钮 |
||||
*/ |
||||
private void disableButton() { |
||||
int order = sortItemPane.getComponentZOrder(selectedLabel); |
||||
if (order == 0) { |
||||
setToolbarEnable(false, false, true, true); |
||||
} else if (order == sortItemPane.getComponentCount() - 1) { |
||||
setToolbarEnable(true, true, false, false); |
||||
} else { |
||||
setToolbarEnable(true, true, true, true); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 设置 置顶,上移,下移,置底 按钮的状态 |
||||
* true:启用 |
||||
* false:关闭 |
||||
*/ |
||||
private void setToolbarEnable(boolean top, boolean up, boolean down, boolean bottom) { |
||||
this.top.setEnabled(top); |
||||
this.up.setEnabled(up); |
||||
this.down.setEnabled(down); |
||||
this.bottom.setEnabled(bottom); |
||||
} |
||||
|
||||
/** |
||||
* 根据选项当前位置以及菜单大小设置 置顶,上移,下移,置底 按钮的状态 |
||||
*/ |
||||
private void setToolbarEnable(int order, int maxOrder) { |
||||
this.top.setEnabled(true); |
||||
this.up.setEnabled(true); |
||||
this.down.setEnabled(true); |
||||
this.bottom.setEnabled(true); |
||||
// 选项处于顶端,则置灰上移和置顶按钮
|
||||
if (order == 0) { |
||||
this.top.setEnabled(false); |
||||
this.up.setEnabled(false); |
||||
} |
||||
// 选项处于底端,则置灰下移和置底按钮
|
||||
if (order == maxOrder - 1) { |
||||
this.down.setEnabled(false); |
||||
this.bottom.setEnabled(false); |
||||
} |
||||
} |
||||
|
||||
private void refreshCurrentOrder() { |
||||
String[] currentTabOrder = parentPane.getCurrentOrder(); |
||||
HashSet<String> selectedTab = new HashSet<>(); |
||||
for (UICheckBox item : sortItems) { |
||||
selectedTab.add(item.getText()); |
||||
} |
||||
|
||||
// 未选中的tab,保持原排序不变
|
||||
Map<String, Integer> exTab = new HashMap<>(); |
||||
for (int i = 0; i < currentTabOrder.length; i++) { |
||||
if (!selectedTab.contains(currentTabOrder[i])) { |
||||
exTab.put(currentTabOrder[i], i); |
||||
} |
||||
} |
||||
|
||||
// 计算当前排序
|
||||
String[] newOrder = new String[currentTabOrder.length]; |
||||
Component[] components = sortItemPane.getComponents(); |
||||
for (String s : exTab.keySet()) { |
||||
newOrder[exTab.get(s)] = s; |
||||
} |
||||
|
||||
int t = 0; |
||||
for (int i = 0; i < newOrder.length; i++) { |
||||
if (StringUtils.isEmpty(newOrder[i])) { |
||||
newOrder[i] = ((MenuLabel) components[t++]).getText(); |
||||
} |
||||
} |
||||
parentPane.setCurrentOrder(newOrder); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,96 @@
|
||||
package com.fr.design.actions.help.alphafine.component; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.utils.DesignUtils; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.plaf.LabelUI; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseListener; |
||||
import java.util.function.Function; |
||||
|
||||
/** |
||||
* 菜单选项label |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/18 |
||||
*/ |
||||
public class MenuLabel extends UILabel { |
||||
|
||||
private static final Color BACKGROUND_COLOR = Color.white; |
||||
private static final Color SELECTED_COLOR = new Color(0x419BF9); |
||||
private static final Color HOVERED_COLOR = new Color(0xd9ebfe); |
||||
private static final int HEIGHT = 23; |
||||
private static final int WIDTH = 147; |
||||
|
||||
private MenuLabelPane parentMenu; |
||||
private final Function function; |
||||
private boolean selected; |
||||
|
||||
public MenuLabel(String text, Function function) { |
||||
super(text); |
||||
this.function = function; |
||||
setOpaque(true); |
||||
addMouseListener(createMouseListener()); |
||||
} |
||||
|
||||
public void setParentMenu(MenuLabelPane menu) { |
||||
this.parentMenu = menu; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void setUI(LabelUI ui) { |
||||
super.setUI(ui); |
||||
this.setBackground(BACKGROUND_COLOR); |
||||
this.setBorder(BorderFactory.createEmptyBorder(2, 10, 1, 10)); |
||||
this.setPreferredSize(new Dimension(WIDTH, HEIGHT)); |
||||
this.setFont(DesignUtils.getDefaultGUIFont().applySize(12)); |
||||
} |
||||
|
||||
public boolean isSelected() { |
||||
return selected; |
||||
} |
||||
|
||||
public void setSelected(boolean selected) { |
||||
if (selected) { |
||||
parentMenu.setNoneSelected(); |
||||
setBackground(SELECTED_COLOR); |
||||
function.apply(this); |
||||
this.selected = true; |
||||
} else { |
||||
setBackground(BACKGROUND_COLOR); |
||||
this.selected = false; |
||||
} |
||||
} |
||||
|
||||
MouseListener createMouseListener() { |
||||
return new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
super.mouseClicked(e); |
||||
setSelected(true); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
super.mouseEntered(e); |
||||
if (!selected) { |
||||
setBackground(HOVERED_COLOR); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
super.mouseExited(e); |
||||
if (!selected) { |
||||
setBackground(BACKGROUND_COLOR); |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.fr.design.actions.help.alphafine.component; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.FlowLayout; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 简单菜单面板 |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/18 |
||||
*/ |
||||
public class MenuLabelPane extends JPanel { |
||||
|
||||
private static final int GAP = 1; |
||||
|
||||
private List<MenuLabel> labels; |
||||
|
||||
public MenuLabelPane(List<MenuLabel> labels) { |
||||
this.labels = labels; |
||||
setLayout(new FlowLayout(FlowLayout.CENTER, GAP, GAP)); |
||||
for (MenuLabel label : labels) { |
||||
label.setParentMenu(this); |
||||
add(label); |
||||
} |
||||
} |
||||
|
||||
public void setNoneSelected() { |
||||
for (MenuLabel label : labels) { |
||||
label.setSelected(false); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.mainframe.alphafine.component; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import javax.swing.JLabel; |
||||
import javax.swing.JPanel; |
||||
import java.awt.Color; |
||||
import java.awt.FlowLayout; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* alphaFine - 推荐搜索词标签 |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/19 |
||||
*/ |
||||
public class RecommendSearchLabel extends JPanel { |
||||
|
||||
private static final Color RECOMMEND_SEARCH_KEY_BLUE = new Color(0x419bf9); |
||||
|
||||
public RecommendSearchLabel(String title, @NotNull List<String> tips) { |
||||
this.setLayout(new FlowLayout(FlowLayout.CENTER)); |
||||
this.setBackground(Color.WHITE); |
||||
JLabel recommend = new JLabel(title); |
||||
this.add(recommend); |
||||
|
||||
for (String key : tips) { |
||||
JLabel keyLabel = new SearchKeyLabel(key); |
||||
this.add(keyLabel); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 推荐搜索词,绑定alphaFine搜索事件 |
||||
*/ |
||||
public class SearchKeyLabel extends JLabel { |
||||
String searchKey; |
||||
|
||||
SearchKeyLabel(String searchKey) { |
||||
this.searchKey = searchKey; |
||||
setText(searchKey); |
||||
setBackground(Color.WHITE); |
||||
setForeground(RECOMMEND_SEARCH_KEY_BLUE); |
||||
addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
AlphaFineHelper.getAlphaFineDialog().fireSearch(searchKey); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,80 @@
|
||||
package com.fr.design.mainframe.alphafine.component; |
||||
|
||||
import com.fr.base.svg.IconUtils; |
||||
import com.fr.common.util.Collections; |
||||
import com.fr.design.actions.help.alphafine.AlphaFineConstants; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.utils.DesignUtils; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.Icon; |
||||
import javax.swing.JLabel; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.SwingConstants; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Dimension; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* alphafine - 搜索提示面板 |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/18 |
||||
*/ |
||||
public class SearchHintPane extends JPanel { |
||||
|
||||
private static final String TITLE = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Search_Title"); |
||||
private static final String RECOMMEND = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend_Search"); |
||||
private static final Icon ICON = IconUtils.readIcon("com/fr/design/mainframe/alphafine/images/search_hint.svg"); |
||||
private static final int HEIGHT = 200; |
||||
private static final int WIDTH = 300; |
||||
private static final int TITLE_LABEL_HEIGHT = 30; |
||||
private static final int TITLE_FONT_SIZE = 14; |
||||
|
||||
public SearchHintPane() { |
||||
this(new ArrayList<>()); |
||||
} |
||||
|
||||
public SearchHintPane(List<String> hints) { |
||||
this(hints, ICON, TITLE); |
||||
} |
||||
|
||||
public SearchHintPane(List<String> hints, Icon icon, String title) { |
||||
setLayout(new BorderLayout()); |
||||
setBorder(BorderFactory.createEmptyBorder(40,0,0,0)); |
||||
setBackground(Color.white); |
||||
setPreferredSize(new Dimension(WIDTH, HEIGHT)); |
||||
setAlignmentY(SwingConstants.CENTER); |
||||
UILabel image = new UILabel(); |
||||
image.setPreferredSize(new Dimension(150, 111)); |
||||
image.setHorizontalAlignment(SwingConstants.CENTER); |
||||
image.setIcon(icon); |
||||
image.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
||||
add(image, BorderLayout.NORTH); |
||||
add(generateDescription(title), BorderLayout.CENTER); |
||||
add(generateHintsLabel(hints), BorderLayout.SOUTH); |
||||
} |
||||
|
||||
protected Component generateDescription(String title) { |
||||
JLabel description = new JLabel(title); |
||||
description.setForeground(AlphaFineConstants.MEDIUM_GRAY); |
||||
description.setFont(DesignUtils.getDefaultGUIFont().applySize(TITLE_FONT_SIZE)); |
||||
description.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
||||
description.setHorizontalAlignment(SwingConstants.CENTER); |
||||
description.setPreferredSize(new Dimension(WIDTH, TITLE_LABEL_HEIGHT)); |
||||
return description; |
||||
} |
||||
|
||||
private Component generateHintsLabel(List<String> hints) { |
||||
if (Collections.isEmpty(hints)) { |
||||
return new JLabel(); |
||||
} |
||||
return new RecommendSearchLabel(RECOMMEND, hints); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
import com.fr.design.actions.help.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.component.AlphaFineFrame; |
||||
import com.fr.design.mainframe.alphafine.component.SearchHintPane; |
||||
import com.fr.design.mainframe.alphafine.search.SearchWorkerManager; |
||||
import com.fr.design.mainframe.alphafine.search.manager.SearchProviderRegistry; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.BorderLayout; |
||||
|
||||
/** |
||||
* alphaFine - 默认展示页面 |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/18 |
||||
*/ |
||||
public class DefaultContentPane extends JPanel { |
||||
|
||||
// 左边展示内容,右边展示搜索提示
|
||||
private SearchWorkerManager searchWorkerManager; |
||||
private CellType cellType; |
||||
|
||||
public DefaultContentPane(CellType cellType, AlphaFineFrame parentWindow) { |
||||
this.setLayout(new BorderLayout()); |
||||
this.setPreferredSize(AlphaFineConstants.PREVIEW_SIZE); |
||||
this.searchWorkerManager = new SearchWorkerManager( |
||||
cellType, |
||||
searchTextBean -> SearchProviderRegistry.getSearchProvider(cellType).getDefaultResult(), |
||||
parentWindow, |
||||
new SimpleRightSearchResultPane(new SearchHintPane()) |
||||
); |
||||
this.searchWorkerManager.showDefault(this); |
||||
} |
||||
|
||||
/** |
||||
* 显示搜索结果 |
||||
*/ |
||||
public void showResult(JPanel result) { |
||||
add(result); |
||||
repaint(); |
||||
} |
||||
|
||||
public DefaultContentPane() { |
||||
|
||||
} |
||||
|
||||
public CellType getCellType() { |
||||
return cellType; |
||||
} |
||||
|
||||
public void setCellType(CellType cellType) { |
||||
this.cellType = cellType; |
||||
} |
||||
} |
@ -0,0 +1,120 @@
|
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
import com.fr.design.actions.help.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.component.AlphaFineFrame; |
||||
import com.fr.design.mainframe.alphafine.component.SearchHintPane; |
||||
import com.fr.design.mainframe.alphafine.search.SearchWorkerManager; |
||||
import com.fr.design.mainframe.alphafine.search.manager.SearchProviderRegistry; |
||||
import com.fr.general.CloudCenter; |
||||
import com.fr.log.FineLoggerFactory; |
||||
|
||||
import javax.swing.JPanel; |
||||
import javax.swing.SwingWorker; |
||||
import java.awt.CardLayout; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* alphafine插件默认页 |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/18 |
||||
*/ |
||||
public class DefaultPluginContentPane extends DefaultContentPane { |
||||
|
||||
private static final String[] HINTS = CloudCenter.getInstance().acquireConf("alphafine.plugin.recommend", "JS,API,JSON").split(","); |
||||
private static final String LOADING_PANE = "loading"; |
||||
private static final String NETWORK_ERROR = "networkError"; |
||||
private static final String RESULT_PANE = "result"; |
||||
private SearchWorkerManager searchWorkerManager; |
||||
private CellType cellType; |
||||
private AlphaFineFrame parentWindow; |
||||
private CardLayout cardLayout; |
||||
private SearchLoadingPane searchLoadingPane; |
||||
private NetWorkFailedPane netWorkFailedPane; |
||||
private SwingWorker<Boolean, Void> worker; |
||||
|
||||
|
||||
public DefaultPluginContentPane(CellType cellType, AlphaFineFrame parentWindow) { |
||||
super(); |
||||
this.cellType = cellType; |
||||
this.parentWindow = parentWindow; |
||||
this.cardLayout = new CardLayout(); |
||||
this.setLayout(cardLayout); |
||||
this.setPreferredSize(AlphaFineConstants.PREVIEW_SIZE); |
||||
initPanel(); |
||||
add(searchLoadingPane, LOADING_PANE); |
||||
add(netWorkFailedPane, NETWORK_ERROR); |
||||
worker = createWorker(); |
||||
worker.execute(); |
||||
} |
||||
|
||||
private void initPanel() { |
||||
this.searchLoadingPane = new SearchLoadingPane(); |
||||
this.netWorkFailedPane = new NetWorkFailedPane(()-> reload()); |
||||
} |
||||
|
||||
private void switchPane(String tag) { |
||||
cardLayout.show(this, tag); |
||||
} |
||||
|
||||
private SwingWorker<Boolean, Void> createWorker() { |
||||
return new SwingWorker<Boolean, Void>() { |
||||
@Override |
||||
protected Boolean doInBackground() throws Exception { |
||||
switchPane(LOADING_PANE); |
||||
return AlphaFineHelper.isNetworkOk(); |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
super.done(); |
||||
try { |
||||
boolean networkOk = get(); |
||||
if (!networkOk) { |
||||
switchPane(NETWORK_ERROR); |
||||
} else { |
||||
List<String> searchKeys = new ArrayList<>(); |
||||
for (String s : HINTS) { |
||||
searchKeys.add(s); |
||||
} |
||||
searchWorkerManager = new SearchWorkerManager( |
||||
cellType, |
||||
searchTextBean -> SearchProviderRegistry.getSearchProvider(cellType).getDefaultResult(), |
||||
parentWindow, |
||||
new SimpleRightSearchResultPane(new SearchHintPane(searchKeys)) |
||||
); |
||||
searchWorkerManager.showDefault(DefaultPluginContentPane.this); |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void showResult(JPanel result) { |
||||
add(result, RESULT_PANE); |
||||
switchPane(RESULT_PANE); |
||||
} |
||||
|
||||
/** |
||||
* 网络异常时,重新加载 |
||||
*/ |
||||
public void reload() { |
||||
worker = createWorker(); |
||||
worker.execute(); |
||||
} |
||||
|
||||
public CellType getCellType() { |
||||
return cellType; |
||||
} |
||||
|
||||
public void setCellType(CellType cellType) { |
||||
this.cellType = cellType; |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager; |
||||
|
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; |
||||
import com.fr.design.mainframe.alphafine.search.manager.impl.ActionSearchManager; |
||||
import com.fr.design.mainframe.alphafine.search.manager.impl.FileSearchManager; |
||||
import com.fr.design.mainframe.alphafine.search.manager.impl.PluginSearchManager; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* alphafine搜索提供者注册到这里 |
||||
* |
||||
* @author Link |
||||
* @version 11.0 |
||||
* Created by Link on 2022/9/18 |
||||
*/ |
||||
public class SearchProviderRegistry { |
||||
private static Map<CellType, AlphaFineSearchProvider> map; |
||||
|
||||
static { |
||||
map = new HashMap<>(); |
||||
map.put(CellType.PLUGIN, PluginSearchManager.getInstance()); |
||||
map.put(CellType.ACTION, ActionSearchManager.getInstance()); |
||||
map.put(CellType.FILE, FileSearchManager.getInstance()); |
||||
} |
||||
|
||||
/** |
||||
* 根据celltype获得对应searchProvider |
||||
*/ |
||||
public static AlphaFineSearchProvider getSearchProvider(CellType cellType) { |
||||
return map.get(cellType); |
||||
} |
||||
} |
After Width: | Height: | Size: 4.3 KiB |
Loading…
Reference in new issue