Browse Source

设计器插件商店更新和搜索API改动

master
vito 9 years ago
parent
commit
31cc16f4c8
  1. 55
      designer/src/com/fr/design/mainframe/bbs/BBSDialog.java
  2. 5
      designer_base/src/com/fr/design/actions/server/PluginManagerAction.java
  3. 13
      designer_base/src/com/fr/design/extra/PluginManagerPane.java
  4. 9
      designer_base/src/com/fr/design/extra/PluginShopDialog.java
  5. 4
      designer_base/src/com/fr/design/extra/PluginStatusCheckCompletePane.java
  6. 18
      designer_base/src/com/fr/design/extra/PluginTask.java
  7. 22
      designer_base/src/com/fr/design/extra/PluginUpdatePane.java
  8. 104
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  9. 27
      designer_base/src/com/fr/design/extra/PluginWebPane.java
  10. 61
      designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java
  11. 1
      designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java
  12. 10
      designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java

55
designer/src/com/fr/design/mainframe/bbs/BBSDialog.java

@ -1,6 +1,7 @@
package com.fr.design.mainframe.bbs;
import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
@ -19,8 +20,6 @@ import netscape.javascript.JSObject;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
/**
* @author richie
@ -53,7 +52,7 @@ public class BBSDialog extends UIDialog {
}
private void disableLink(final WebEngine eng) {
try{
try {
// webView端不跳转 虽然webView可以指定本地浏览器打开某个链接,但是当本地浏览器跳转到指定链接的同时,webView也做了跳转,
// 为了避免出现在一个600*400的资讯框里加载整个网页的情况,webView不跳转到新网页
Platform.runLater(new Runnable() {
@ -62,16 +61,17 @@ public class BBSDialog extends UIDialog {
eng.executeScript("history.go(0)");
}
});
}catch(Exception e){
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
/**
* 打开资讯框
*
* @param url 资讯链接
*/
public void showWindow(final String url){
public void showWindow(final String url) {
GUICoreUtils.centerWindow(this);
this.setResizable(false);
Platform.runLater(new Runnable() {
@ -92,20 +92,19 @@ public class BBSDialog extends UIDialog {
root.getChildren().add(view);
eng.locationProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue)
{
disableLink(eng);
// webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转
if(ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, BBSConstants.BBS_MOBILE_MOD)){
return;
}
openUrlAtLocalWebBrowser(eng,newValue);
}
});
public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue) {
disableLink(eng);
// webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转
if (ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, BBSConstants.BBS_MOBILE_MOD)) {
return;
}
PluginWebBridge.getHelper().openUrlAtLocalWebBrowser(eng, newValue);
}
});
eng.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
if (newValue == Worker.State.SUCCEEDED){
if (newValue == Worker.State.SUCCEEDED) {
JSObject obj = (JSObject) eng.executeScript("window");
obj.setMember("BBSWebBridge", BBSDialog.this);
setVisible(true);
@ -116,29 +115,6 @@ public class BBSDialog extends UIDialog {
});
}
// 在本地浏览器里打开url
private void openUrlAtLocalWebBrowser(WebEngine eng,String url){
if(Desktop.isDesktopSupported()){
try{
//创建一个URI实例,注意不是URL
URI uri = URI.create(url);
//获取当前系统桌面扩展
Desktop desktop = Desktop.getDesktop();
//判断系统桌面是否支持要执行的功能
if(desktop.isSupported(Desktop.Action.BROWSE)){
//获取系统默认浏览器打开链接
desktop.browse(uri);
}
}catch(NullPointerException e){
//此为uri为空时抛出异常
FRLogger.getLogger().error(e.getMessage());
}catch(IOException e){
//此为无法获取系统默认浏览器
FRLogger.getLogger().error(e.getMessage());
}
}
}
/**
* 提供给web页面调用的关闭窗口
*/
@ -146,6 +122,7 @@ public class BBSDialog extends UIDialog {
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setVisible(false);
}
/**
*
*/

5
designer_base/src/com/fr/design/actions/server/PluginManagerAction.java

@ -2,11 +2,10 @@ package com.fr.design.actions.server;
import com.fr.base.BaseUtils;
import com.fr.design.actions.UpdateAction;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.PluginManagerPane;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.ShopDialog;
import com.fr.design.extra.PluginShopDialog;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.menu.MenuKeySet;
import com.fr.general.Inter;
@ -31,7 +30,7 @@ public class PluginManagerAction extends UpdateAction {
@Override
public void actionPerformed(ActionEvent e) {
final PluginManagerPane managerPane = new PluginManagerPane();
UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(),managerPane);
UIDialog dlg = new PluginShopDialog(DesignerContext.getDesignerFrame(),managerPane);
PluginWebBridge.getHelper().setDialogHandle(dlg);
dlg.setVisible(true);
}

13
designer_base/src/com/fr/design/extra/PluginManagerPane.java

@ -2,23 +2,10 @@ package com.fr.design.extra;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.stable.StableUtils;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.scene.web.WebEngine;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.swing.*;
import java.awt.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
/**

9
designer_base/src/com/fr/design/extra/ShopDialog.java → designer_base/src/com/fr/design/extra/PluginShopDialog.java

@ -9,11 +9,11 @@ import java.awt.*;
/**
* Created by vito on 16/4/18.
*/
public class ShopDialog extends UIDialog{
private static final Dimension DEFAULT_SHOP = new Dimension(900, 760);
public class PluginShopDialog extends UIDialog {
private static final Dimension DEFAULT_SHOP = new Dimension(900, 710);
public ShopDialog(Frame frame, BasicPane pane) {
super(frame, pane,false);
public PluginShopDialog(Frame frame, BasicPane pane) {
super(frame, pane, false);
setSize(DEFAULT_SHOP);
GUICoreUtils.centerWindow(this);
setResizable(false);
@ -21,6 +21,5 @@ public class ShopDialog extends UIDialog{
@Override
public void checkValid() throws Exception {
}
}

4
designer_base/src/com/fr/design/extra/PluginStatusCheckCompletePane.java

@ -67,8 +67,8 @@ public abstract class PluginStatusCheckCompletePane extends PluginAbstractViewPa
public void setProgress(double percent) {
progressBar.setVisible(true);
progressBar.setValue((int)percent);
progressBar.setString((int)percent + "%");
progressBar.setValue((int) percent);
progressBar.setString((int) percent + "%");
progressBar.repaint();
}

18
designer_base/src/com/fr/design/extra/PluginTask.java

@ -27,7 +27,7 @@ public class PluginTask<T> extends Task<T> {
messageProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
String fun = "(" + callback + ")('" + newValue + "')";
String fun = "(" + callback + ")(\"" + newValue + "\")";
try {
webEngine.executeScript(fun);
} catch (Exception e) {
@ -49,7 +49,7 @@ public class PluginTask<T> extends Task<T> {
@Override
public void process(String s) {
if (StringUtils.isNotBlank(s)) {
updateMessage(s);
updateMessage(changText(s));
}
}
});
@ -59,6 +59,18 @@ public class PluginTask<T> extends Task<T> {
@Override
protected void done() {
updateMessage(executor.getTaskFinishMessage());
updateMessage(changText(executor.getTaskFinishMessage()));
}
/**
* 转换掉一些会造成错误的特殊字符
* 1 ""中的""必须转义
* 2 js字符串中的\n会导致js字符串变成多行,而js字符创不支持多行拼接
*
* @param old 原始字符串
* @return 处理之后的字符串
*/
private String changText(String old) {
return old.replaceAll("\"", "\\\\\"").replaceAll("\n", "");
}
}

22
designer_base/src/com/fr/design/extra/PluginUpdatePane.java

@ -25,7 +25,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
private PluginControlPane controlPane;
private JLabel errorMsgLabel;
private UITabbedPane tabbedPane;
private static final int PERSENT = 100;
public PluginUpdatePane(UITabbedPane tabbedPane) {
@ -35,6 +35,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
/**
* 更新pane
*
* @return 同上
*/
public JPanel createSuccessPane() {
@ -56,7 +57,6 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
}
@Override
public String textForInstallFromDiskButton() {
return Inter.getLocText("FR-Designer_Plugin_Normal_Update_From_Local");
@ -79,6 +79,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
/**
* 出错pane
*
* @return 同上
*/
@Override
@ -104,7 +105,6 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
}
@Override
public String textForInstallFromDiskButton() {
return Inter.getLocText("FR-Designer_Plugin_Normal_Update_From_Local");
@ -119,6 +119,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
/**
* 加载插件
*
* @return 所有插件
*/
public Plugin[] loadData() throws Exception {
@ -127,7 +128,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
/**
* 加载成功处理
*
*
* @param plugins 插件
*/
public void loadOnSuccess(Plugin[] plugins) {
@ -137,7 +138,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
/**
* 加载失败处理
*
*
* @param e 异常
*/
public void loadOnFailed(Exception e) {
@ -146,6 +147,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
/**
*
*
* @return
*/
@Override
@ -165,11 +167,11 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
}
private void doUpdateOnline(final PluginStatusCheckCompletePane pane) {
if (StringUtils.isEmpty(DesignerEnvManager.getEnvManager().getBBSName())){
if (StringUtils.isEmpty(DesignerEnvManager.getEnvManager().getBBSName())) {
LoginCheckContext.fireLoginCheckListener();
}
if (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())){
new SwingWorker<Void, Double>(){
if (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())) {
new SwingWorker<Void, Double>() {
@Override
protected Void doInBackground() throws Exception {
@ -181,7 +183,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(id,username,password, new Process<Double>() {
PluginHelper.downloadPluginFile(id, username, password, new Process<Double>() {
@Override
public void process(Double integer) {
publish(integer);
@ -264,12 +266,14 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
/**
* 从磁盘安装按钮的提示
*
* @return 按钮标题字符串
*/
@Override
public String textForInstallFromDiskFileButton() {
return Inter.getLocText("FR-Designer_Plugin_Normal_Update_From_Local");
}
@Override
protected String title4PopupWindow() {
return "Update";

104
designer_base/src/com/fr/design/extra/PluginWebBridge.java

@ -6,7 +6,6 @@ import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.*;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.http.HttpClient;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import com.fr.stable.ArrayUtils;
@ -18,7 +17,10 @@ import javafx.stage.Stage;
import netscape.javascript.JSObject;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
@ -31,7 +33,7 @@ public class PluginWebBridge {
private UIDialog uiDialog;
public static final String PLUGIN_SHOP = "http://127.0.0.1:8080/ShopServer?pg=plist";
public static final String PLUGIN_SHOP = "http://192.168.101.20/ShopServer?pg=plist";
public static PluginWebBridge getHelper() {
if (helper != null) {
@ -56,13 +58,14 @@ public class PluginWebBridge {
private PluginWebBridge() {
}
public void setEngine(WebEngine webEngine){
public void setEngine(WebEngine webEngine) {
this.webEngine = webEngine;
}
public void setDialogHandle(UIDialog uiDialog){
public void setDialogHandle(UIDialog uiDialog) {
this.uiDialog = uiDialog;
}
/**
* 从插件服务器上安装插件
*
@ -196,45 +199,35 @@ public class PluginWebBridge {
return list.toArray(new String[len]);
}
public String getPluginFromStore(String category, String seller, String fee) {
StringBuilder url = new StringBuilder(PLUGIN_SHOP);
if (StringUtils.isNotBlank(category)) {
url.append("&cid=").append(category.split("-")[1]);
}
if (StringUtils.isNotBlank(seller)) {
url.append("&seller=").append(seller.split("-")[1]);
}
if (StringUtils.isNotBlank(fee)) {
url.append("&fee=").append(fee.split("-")[1]);
}
String resText = null;
try {
HttpClient httpClient = new HttpClient(url.toString());
httpClient.setTimeout(3000);
resText = httpClient.getResponseText();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
return resText == null ? StringUtils.EMPTY : resText;
}
/**
* 搜索在线插件
*
* @param keyword 关键字
*/
public String searchPlugin(String keyword) {
try {
HttpClient httpClient = new HttpClient(PluginWebBridge.PLUGIN_SHOP + "&keyword=" + keyword);
return httpClient.getResponseText();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
return StringUtils.EMPTY;
public void searchPlugin(String keyword, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new SearchExecutor(keyword));
new Thread(task).start();
}
/**
* 根据条件获取在线插件的
*
* @param category 分类
* @param seller 卖家性质
* @param fee 收费类型
* @param callback 回调函数
*/
public void getPluginFromStore(String category, String seller, String fee, final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new GetPluginFromStoreExecutor(category, seller, fee));
new Thread(task).start();
}
public void showRestartMessage(String message){
/**
* 展示一个重启的对话框(少用,莫名其妙会有bug)
*
* @param message 展示的消息
*/
public void showRestartMessage(String message) {
int rv = JOptionPane.showOptionDialog(
null,
message,
@ -250,6 +243,9 @@ public class PluginWebBridge {
}
}
/**
* 关闭窗口
*/
public void closeWindow() {
if (uiDialog != null) {
uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
@ -257,7 +253,40 @@ public class PluginWebBridge {
}
}
public void updateFileFromDisk(File fileOnDisk){
/**
* 在本地浏览器里打开url
*
* @param eng web引擎
* @param url 要打开的地址
*/
public void openUrlAtLocalWebBrowser(WebEngine eng, String url) {
if (Desktop.isDesktopSupported()) {
try {
//创建一个URI实例,注意不是URL
URI uri = URI.create(url);
//获取当前系统桌面扩展
Desktop desktop = Desktop.getDesktop();
//判断系统桌面是否支持要执行的功能
if (desktop.isSupported(Desktop.Action.BROWSE)) {
//获取系统默认浏览器打开链接
desktop.browse(uri);
}
} catch (NullPointerException e) {
//此为uri为空时抛出异常
FRLogger.getLogger().error(e.getMessage());
} catch (IOException e) {
//此为无法获取系统默认浏览器
FRLogger.getLogger().error(e.getMessage());
}
}
}
/**
* 从硬盘升级
*
* @param fileOnDisk 硬盘上的文件
*/
public void updateFileFromDisk(File fileOnDisk) {
try {
Plugin plugin = PluginHelper.readPlugin(fileOnDisk);
if (plugin == null) {
@ -289,7 +318,6 @@ public class PluginWebBridge {
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
// 如果不是立即重启,就把要删除的文件存放起来
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
RestartHelper.saveFilesWhichToDelete(files);

27
designer_base/src/com/fr/design/extra/PluginWebPane.java

@ -1,6 +1,9 @@
package com.fr.design.extra;
import com.fr.general.FRLogger;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Scene;
@ -36,6 +39,13 @@ public class PluginWebPane extends JFXPanel {
showAlert(event.getData());
}
});
webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue) {
disableLink(webEngine);
PluginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue);
}
});
JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine));
root.setCenter(webView);
@ -43,6 +53,19 @@ public class PluginWebPane extends JFXPanel {
});
}
private void disableLink(final WebEngine webEngine) {
try {
Platform.runLater(new Runnable() {
@Override
public void run() {
webEngine.executeScript("history.go(0)");
}
});
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
private void showAlert(final String message) {
SwingUtilities.invokeLater(new Runnable() {
@Override
@ -50,9 +73,5 @@ public class PluginWebPane extends JFXPanel {
JOptionPane.showMessageDialog(PluginWebPane.this, message);
}
});
// Dialog<Void> alert = new Dialog<>();
// alert.getDialogPane().setContentText(message);
// alert.getDialogPane().getButtonTypes().add(ButtonType.OK);
// alert.showAndWait();
}
}

61
designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java

@ -0,0 +1,61 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginWebBridge;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.http.HttpClient;
import com.fr.stable.StringUtils;
/**
* Created by vito on 16/4/18.
* 获取插件分类信息
*/
public class GetPluginFromStoreExecutor implements Executor {
private String result = "[]";
private String category;
private String seller;
private String fee;
public GetPluginFromStoreExecutor(String category, String seller, String fee) {
this.category = category;
this.seller = seller;
this.fee = fee;
}
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return StringUtils.EMPTY;
}
@Override
public void run(Process<String> process) {
StringBuilder url = new StringBuilder(PluginWebBridge.PLUGIN_SHOP);
if (StringUtils.isNotBlank(category)) {
url.append("&cid=").append(category.split("-")[1]);
}
if (StringUtils.isNotBlank(seller)) {
url.append("&seller=").append(seller.split("-")[1]);
}
if (StringUtils.isNotBlank(fee)) {
url.append("&fee=").append(fee.split("-")[1]);
}
try {
HttpClient httpClient = new HttpClient(url.toString());
result = httpClient.getResponseText();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
};
}
}

1
designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java

@ -34,6 +34,7 @@ public class ModifyStatusExecutor implements Executor {
public String getExecuteMessage() {
return StringUtils.EMPTY;
}
@Override
public void run(Process<String> process) {
plugin = PluginLoader.getLoader().getPluginById(pluginID);

10
designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java

@ -81,7 +81,7 @@ public class UpdateOnlineExecutor implements Executor {
};
}
private void updateFileFromDisk(File fileOnDisk){
private void updateFileFromDisk(File fileOnDisk) {
try {
Plugin plugin = PluginHelper.readPlugin(fileOnDisk);
if (plugin == null) {
@ -92,10 +92,10 @@ public class UpdateOnlineExecutor implements Executor {
if (oldPlugin != null) {
String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin);
PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() {
@Override
public void done() {
}
});
@Override
public void done() {
}
});
} else {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}

Loading…
Cancel
Save