|
|
|
@ -10,8 +10,9 @@ 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.BorderLayout; |
|
|
|
|
import java.awt.CardLayout; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
@ -25,18 +26,46 @@ import java.util.List;
|
|
|
|
|
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.setLayout(new BorderLayout()); |
|
|
|
|
this.cellType = cellType; |
|
|
|
|
this.parentWindow = parentWindow; |
|
|
|
|
this.cardLayout = new CardLayout(); |
|
|
|
|
this.setLayout(cardLayout); |
|
|
|
|
this.setPreferredSize(AlphaFineConstants.PREVIEW_SIZE); |
|
|
|
|
new SwingWorker<Boolean, Void>() { |
|
|
|
|
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 { |
|
|
|
|
add(new SearchLoadingPane()); |
|
|
|
|
switchPane(LOADING_PANE); |
|
|
|
|
return AlphaFineHelper.isNetworkOk(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -45,9 +74,8 @@ public class DefaultPluginContentPane extends DefaultContentPane {
|
|
|
|
|
super.done(); |
|
|
|
|
try { |
|
|
|
|
boolean networkOk = get(); |
|
|
|
|
removeAll(); |
|
|
|
|
if (!networkOk) { |
|
|
|
|
add(new NetWorkFailedPane()); |
|
|
|
|
switchPane(NETWORK_ERROR); |
|
|
|
|
} else { |
|
|
|
|
List<String> searchKeys = new ArrayList<>(); |
|
|
|
|
for (String s : HINTS) { |
|
|
|
@ -64,10 +92,22 @@ public class DefaultPluginContentPane extends DefaultContentPane {
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}.execute(); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void showResult(JPanel result) { |
|
|
|
|
add(result, RESULT_PANE); |
|
|
|
|
switchPane(RESULT_PANE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 网络异常时,重新加载 |
|
|
|
|
*/ |
|
|
|
|
public void reload() { |
|
|
|
|
worker = createWorker(); |
|
|
|
|
worker.execute(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public CellType getCellType() { |
|
|
|
|