|
|
@ -10,8 +10,9 @@ import com.fr.design.mainframe.alphafine.search.manager.SearchProviderRegistry; |
|
|
|
import com.fr.general.CloudCenter; |
|
|
|
import com.fr.general.CloudCenter; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
import javax.swing.SwingWorker; |
|
|
|
import javax.swing.SwingWorker; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.CardLayout; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
@ -25,18 +26,46 @@ import java.util.List; |
|
|
|
public class DefaultPluginContentPane extends DefaultContentPane { |
|
|
|
public class DefaultPluginContentPane extends DefaultContentPane { |
|
|
|
|
|
|
|
|
|
|
|
private static final String[] HINTS = CloudCenter.getInstance().acquireConf("alphafine.plugin.recommend", "JS,API,JSON").split(","); |
|
|
|
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 SearchWorkerManager searchWorkerManager; |
|
|
|
private CellType cellType; |
|
|
|
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) { |
|
|
|
public DefaultPluginContentPane(CellType cellType, AlphaFineFrame parentWindow) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
this.setLayout(new BorderLayout()); |
|
|
|
this.cellType = cellType; |
|
|
|
|
|
|
|
this.parentWindow = parentWindow; |
|
|
|
|
|
|
|
this.cardLayout = new CardLayout(); |
|
|
|
|
|
|
|
this.setLayout(cardLayout); |
|
|
|
this.setPreferredSize(AlphaFineConstants.PREVIEW_SIZE); |
|
|
|
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 |
|
|
|
@Override |
|
|
|
protected Boolean doInBackground() throws Exception { |
|
|
|
protected Boolean doInBackground() throws Exception { |
|
|
|
add(new SearchLoadingPane()); |
|
|
|
switchPane(LOADING_PANE); |
|
|
|
return AlphaFineHelper.isNetworkOk(); |
|
|
|
return AlphaFineHelper.isNetworkOk(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -45,9 +74,8 @@ public class DefaultPluginContentPane extends DefaultContentPane { |
|
|
|
super.done(); |
|
|
|
super.done(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
boolean networkOk = get(); |
|
|
|
boolean networkOk = get(); |
|
|
|
removeAll(); |
|
|
|
|
|
|
|
if (!networkOk) { |
|
|
|
if (!networkOk) { |
|
|
|
add(new NetWorkFailedPane()); |
|
|
|
switchPane(NETWORK_ERROR); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
List<String> searchKeys = new ArrayList<>(); |
|
|
|
List<String> searchKeys = new ArrayList<>(); |
|
|
|
for (String s : HINTS) { |
|
|
|
for (String s : HINTS) { |
|
|
@ -64,10 +92,22 @@ public class DefaultPluginContentPane extends DefaultContentPane { |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
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() { |
|
|
|
public CellType getCellType() { |
|
|
|