Browse Source

REPORT-2354 兼容传统插件商城

master
kerry 8 years ago
parent
commit
8bc49176fa
  1. 43
      designer_base/src/com/fr/design/extra/PluginControlPane.java
  2. 6
      designer_base/src/com/fr/design/extra/PluginDetailPane.java
  3. 125
      designer_base/src/com/fr/design/extra/PluginFromStorePane.java
  4. 79
      designer_base/src/com/fr/design/extra/PluginInstalledPane.java
  5. 53
      designer_base/src/com/fr/design/extra/PluginOperateUtils.java
  6. 60
      designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java
  7. 5
      designer_base/src/com/fr/design/extra/PluginSelectListener.java
  8. 125
      designer_base/src/com/fr/design/extra/PluginUpdatePane.java
  9. 49
      designer_base/src/com/fr/design/extra/PluginUtils.java
  10. 18
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  11. 52
      designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java
  12. 41
      designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java
  13. 41
      designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java
  14. 68
      designer_base/src/com/fr/design/extra/exe/GetPluginFromStoreExecutor.java
  15. 103
      designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java
  16. 124
      designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java
  17. 74
      designer_base/src/com/fr/design/extra/exe/ModifyStatusExecutor.java
  18. 49
      designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java
  19. 49
      designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java
  20. 47
      designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java
  21. 62
      designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java
  22. 81
      designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java
  23. 118
      designer_base/src/com/fr/design/extra/exe/UpdateOnlineExecutor.java
  24. 1
      designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java
  25. 2
      designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java
  26. 6
      designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java
  27. 7
      designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java
  28. 31
      designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java
  29. 1
      designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java
  30. 9
      designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java
  31. 9
      designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java
  32. 11
      designer_base/src/com/fr/design/extra/exe/extratask/AbstractExtraPluginTask.java
  33. 11
      designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java
  34. 8
      designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java
  35. 55
      designer_base/src/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java

43
designer_base/src/com/fr/design/extra/PluginControlPane.java

@ -8,10 +8,13 @@ import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.view.PluginView;
import com.fr.stable.StringUtils;
import javax.swing.*;
@ -20,7 +23,8 @@ import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.util.ArrayList;
import java.util.*;
import java.util.List;
/**
* @author richie
@ -32,7 +36,7 @@ public class PluginControlPane extends BasicPane {
private DefaultListModel listModel;
private PluginDetailPane detailPane;
private java.util.List<PluginSelectListener> listeners = new ArrayList<PluginSelectListener>();
private Plugin[] plugins;
private List<PluginView> plugins;
private UITextField searchTextField;
public PluginControlPane() {
@ -63,8 +67,8 @@ public class PluginControlPane extends BasicPane {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Plugin) {
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(((Plugin) value).getId());
if (value instanceof PluginView) {
PluginLicense pluginLicense = PluginLicenseManager.getInstance().getPluginLicenseByID(((PluginView) value).getID());
String extraInfo = "";
if (pluginLicense.isJarDamage()) {
extraInfo = "(" + Inter.getLocText("FR-Plugin-Plugin_Damaged") + ")";
@ -75,7 +79,7 @@ public class PluginControlPane extends BasicPane {
extraInfo = "(" + (pluginLicense.isTrial() ? Inter.getLocText("FR-Plugin-Designer_Trial") : Inter.getLocText("FR-Plugin-Designer_Authorized")) + Inter.getLocText("FR-Plugin-Designer_Expired") + ")";
}
}
setText(((Plugin) value).getName() + extraInfo);
setText(((PluginView) value).getName() + extraInfo);
setIcon(IOUtils.readIcon("/com/fr/design/images/server/plugin.png"));
}
return this;
@ -101,7 +105,7 @@ public class PluginControlPane extends BasicPane {
pluginList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Plugin plugin = (Plugin) pluginList.getSelectedValue();
PluginView plugin = (PluginView) pluginList.getSelectedValue();
if (plugin != null) {
detailPane.populate(plugin);
for (PluginSelectListener l : listeners) {
@ -118,9 +122,9 @@ public class PluginControlPane extends BasicPane {
listeners.add(l);
}
public void loadPlugins(Plugin[] plugins) {
public void loadPlugins(java.util.List<PluginView> plugins) {
this.plugins = plugins;
for (Plugin plugin : plugins) {
for (PluginView plugin : plugins) {
listModel.addElement(plugin);
}
}
@ -128,21 +132,28 @@ public class PluginControlPane extends BasicPane {
private void doSearch(String text) {
if (StringUtils.isNotBlank(text)) {
listModel.clear();
for (Plugin plugin : plugins) {
if (plugin.match(text)) {
for (PluginView plugin : plugins) {
if (PluginUtils.isPluginMatch(plugin, text)) {
listModel.addElement(plugin);
}
}
}
}
public Plugin getSelectedPlugin() {
return (Plugin) pluginList.getSelectedValue();
public PluginView getSelectedPlugin() {
return (PluginView) pluginList.getSelectedValue();
}
public void deletePlugin(Plugin plugin) {
public void deletePlugin(PluginView plugin) {
listModel.removeElement(plugin);
PluginLoader.getLoader().deletePlugin(plugin);
String id = plugin.getID();
String version = plugin.getVersion();
PluginManager.getController().uninstall(PluginMarker.create(id, version), true, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult result) {
}
});
}
@Override

6
designer_base/src/com/fr/design/extra/PluginDetailPane.java

@ -3,7 +3,7 @@ package com.fr.design.extra;
import com.fr.design.dialog.BasicPane;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.view.PluginView;
import com.fr.stable.StringUtils;
import javax.swing.*;
@ -56,8 +56,8 @@ public class PluginDetailPane extends BasicPane {
}
public void populate(Plugin plugin) {
textPane.setText(plugin.toHTML());
public void populate(PluginView plugin) {
textPane.setText(PluginUtils.pluginToHtml(plugin));
}
public void reset() {

125
designer_base/src/com/fr/design/extra/PluginFromStorePane.java

@ -1,26 +1,29 @@
package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.extra.tradition.callback.UpdateOnlineCallback;
import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.stable.StringUtils;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import com.fr.plugin.view.PluginView;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* @author richie
* @date 2015-03-10
* @since 8.0
*/
public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[], Void> {
public class PluginFromStorePane extends PluginAbstractLoadingViewPane<List<PluginView>, Void> {
private UILabel errorMsgLabel;
private UITabbedPane tabbedPane;
private PluginControlPane controlPane;
@ -29,7 +32,6 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
private static final int LISTNUM100 = 100;
public PluginFromStorePane(final UITabbedPane tabbedPane) {
super(tabbedPane);
this.tabbedPane = tabbedPane;
@ -37,10 +39,11 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
/**
* 创建成功页面
*
* @return 创建的页面对象
*/
public JPanel createSuccessPane() {
return new PluginStatusCheckCompletePane(){
return new PluginStatusCheckCompletePane() {
@Override
@ -70,7 +73,7 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
final PluginStatusCheckCompletePane s = this;
controlPane.addPluginSelectionListener(new PluginSelectListener() {
@Override
public void valueChanged(Plugin plugin) {
public void valueChanged(PluginView plugin) {
s.setInstallButtonEnable(true);
}
});
@ -81,6 +84,7 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
/**
* 创建错误页面
*
* @return 创建的页面对象
*/
@Override
@ -88,7 +92,7 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
errorMsgLabel = new UILabel();
errorMsgLabel.setHorizontalAlignment(SwingConstants.CENTER);
return new PluginStatusCheckCompletePane(){
return new PluginStatusCheckCompletePane() {
@Override
public void pressInstallButton() {
@ -120,24 +124,27 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
/**
* 加载数据
*
* @return 插件
*/
public Plugin[] loadData() throws Exception {
public List<PluginView> loadData() throws Exception {
//Thread.sleep(3000);
return PluginsReaderFromStore.readPlugins();
}
/**
* 加载成功处理
*
* @param plugins 插件
*/
public void loadOnSuccess(Plugin[] plugins) {
public void loadOnSuccess(List<PluginView> plugins) {
controlPane.loadPlugins(plugins);
tabbedPane.setTitleAt(2, Inter.getLocText("FR-Designer-Plugin_All_Plugins") + "(" + plugins.length + ")");
tabbedPane.setTitleAt(2, Inter.getLocText("FR-Designer-Plugin_All_Plugins") + "(" + plugins.size() + ")");
}
/**
* 加载失败
*
* @param e 异常消息
*/
public void loadOnFailed(Exception e) {
@ -159,85 +166,52 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
private void installFromDiskZipFile(File chosenFile) {
try {
PluginHelper.installPluginFromDisk(chosenFile, new After() {
PluginManager.getController().install(chosenFile, new ProgressCallback() {
@Override
public void done() {
int rv = JOptionPane.showOptionDialog(
PluginFromStorePane.this,
Inter.getLocText("FR-Designer-Plugin_Install_Successful"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")},
null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
public void updateProgress(String description, double progress) {
}
});
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
} }
});
} catch (Exception e1) {
JOptionPane.showMessageDialog(PluginFromStorePane.this, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
private void doUpdateOnline(final PluginStatusCheckCompletePane pane) {
if (StringUtils.isEmpty(DesignerEnvManager.getEnvManager().getBBSName())){
if (!BBSPluginLogin.getInstance().hasLogin()) {
LoginCheckContext.fireLoginCheckListener();
}
if (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())){
new SwingWorker<Void, Double>(){
@Override
protected Void doInBackground() throws Exception {
Plugin plugin = controlPane.getSelectedPlugin();
String id = null;
if (plugin != null) {
id = plugin.getId();
}
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(id,username,password, new Process<Double>() {
@Override
public void process(Double integer) {
publish(integer);
}
});
Thread.sleep(2000);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
return null;
}
if (BBSPluginLogin.getInstance().hasLogin()) {
PluginView plugin = controlPane.getSelectedPlugin();
String id = null;
if (plugin != null) {
id = plugin.getID();
}
public void process(List<Double> list) {
pane.setProgress(list.get(list.size() - LISTNUM1) * LISTNUM100);
}
try {
PluginMarker pluginMarker = PluginMarker.create(id, plugin.getVersion());
String latestPluginInfo = PluginUtils.getLatestPluginInfo(id);
PluginMarker toPluginMarker = PluginMarker.create(id, latestPluginInfo);
PluginManager.getController().download(pluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane));
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
public void done() {
//下载完成,开始执行安装
try {
get();
pane.didTaskFinished();
installFromDiskZipFile(PluginHelper.getDownloadTempFile());
} catch (InterruptedException e) {
FRContext.getLogger().error(e.getMessage(), e);
} catch (ExecutionException e) {
FRContext.getLogger().error(e.getMessage(), e);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}.execute();
}
}
/**
* 正在加载页的标题
*
* @return 标题字符串
*/
public String textForLoadingLabel() {
@ -246,11 +220,12 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane<Plugin[],
/**
* 从磁盘安装按钮的提示
*
* @return 按钮标题字符串
*/
@Override
public String textForInstallFromDiskFileButton() {
return Inter.getLocText("FR-Designer-Plugin_Install_From_Local");
return Inter.getLocText("FR-Designer-Plugin_Install_From_Local");
}
@Override

79
designer_base/src/com/fr/design/extra/PluginInstalledPane.java

@ -1,16 +1,22 @@
package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.design.RestartHelper;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.view.PluginView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
/**
* @author richie
@ -42,7 +48,7 @@ public class PluginInstalledPane extends PluginAbstractViewPane {
panel.add(deleteButton);
controlPane.addPluginSelectionListener(new PluginSelectListener() {
@Override
public void valueChanged(Plugin plugin) {
public void valueChanged(PluginView plugin) {
disableButton.setEnabled(true);
deleteButton.setEnabled(true);
changeTextForButton(plugin);
@ -51,28 +57,35 @@ public class PluginInstalledPane extends PluginAbstractViewPane {
disableButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Plugin plugin = controlPane.getSelectedPlugin();
PluginView plugin = controlPane.getSelectedPlugin();
if (plugin != null) {
plugin.setActive(!plugin.isActive());
changeTextForButton(plugin);
try {
FRContext.getCurrentEnv().writePlugin(plugin);
int rv = JOptionPane.showOptionDialog(
PluginInstalledPane.this,
plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")},
null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
} catch (Exception e1) {
FRContext.getLogger().error(e1.getMessage(), e1);
boolean isActive = plugin.isActive();
PluginMarker pluginMarker = PluginMarker.create(plugin.getID(), plugin.getVersion());
String modifyMessage = isActive ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled");
if (isActive) {
PluginManager.getController().forbid(pluginMarker, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, modifyMessage);
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
} else {
PluginManager.getController().enable(pluginMarker, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, modifyMessage);
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
changeTextForButton(plugin);
}
}
});
@ -83,21 +96,25 @@ public class PluginInstalledPane extends PluginAbstractViewPane {
}
});
PluginLoader loader = PluginLoader.getLoader();
Plugin[] plugins = loader.getInstalled();
controlPane.loadPlugins(plugins);
num = plugins.length;
List<PluginContext> plugins = PluginManager.getContexts();
List<PluginView> pluginViews = new ArrayList<>();
for (PluginContext plugin : plugins) {
pluginViews.add((PluginView) plugin);
}
controlPane.loadPlugins(pluginViews);
num = plugins.size();
}
/**
* tab标题
*
* @return 同上
*/
public String tabTitle() {
return Inter.getLocText("FR-Designer-Plugin_Installed") + "(" + num + ")";
}
private void doDelete(Plugin plugin) {
private void doDelete(PluginView plugin) {
int rv = JOptionPane.showOptionDialog(
PluginInstalledPane.this,
Inter.getLocText("FR-Designer-Plugin_Will_Be_Delete"),
@ -116,9 +133,7 @@ public class PluginInstalledPane extends PluginAbstractViewPane {
}
try {
String[] filesToBeDelete = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), plugin);
controlPane.deletePlugin(plugin);
RestartHelper.saveFilesWhichToDelete(filesToBeDelete);
} catch (Exception e) {
JOptionPane.showMessageDialog(PluginInstalledPane.this, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
@ -128,7 +143,7 @@ public class PluginInstalledPane extends PluginAbstractViewPane {
}
}
private void changeTextForButton(Plugin plugin) {
private void changeTextForButton(PluginView plugin) {
if (plugin.isActive()) {
disableButton.setText(Inter.getLocText("FR-Designer-Plugin_Disable"));
} else {

53
designer_base/src/com/fr/design/extra/PluginOperateUtils.java

@ -15,13 +15,11 @@ import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.view.PluginView;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
import org.json.JSONArray;
import sun.plugin2.main.server.Plugin;
import javax.swing.*;
import java.io.File;
@ -45,23 +43,17 @@ public class PluginOperateUtils {
}
}
public static void installPluginFromDisk(final String filePath, JSCallback jsCallback) {
PluginManager.getController().install(new File(filePath), new InstallFromDiskCallback(new File(filePath), jsCallback));
public static void installPluginFromDisk(File zipFile, JSCallback jsCallback) {
PluginManager.getController().install(zipFile, new InstallFromDiskCallback(zipFile, jsCallback));
}
public static void updatePluginOnline(JSObject pluginIDs, JSCallback jsCallback) {
String[] pluginInfos = jsObjectToStringArray(pluginIDs);
public static void updatePluginOnline(List<PluginMarker> pluginMarkerList, JSCallback jsCallback) {
if (!(BBSPluginLogin.getInstance().hasLogin())) {
LoginCheckContext.fireLoginCheckListener();
}
if (BBSPluginLogin.getInstance().hasLogin()) {
List<PluginMarker> pluginMarkerList = new ArrayList<PluginMarker>();
for (int i = 0; i < pluginInfos.length; i++) {
pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i]));
}
for (int i = 0; i < pluginMarkerList.size(); i++) {
try {
//todo check下此插件的最新版本
String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarkerList.get(i).getPluginID());
if (StringUtils.isEmpty(latestPluginInfo) || PluginConstants.CONNECTION_404.equals(latestPluginInfo)) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Connect_Failed"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
@ -86,7 +78,7 @@ public class PluginOperateUtils {
public static void setPluginActive(String pluginInfo, JSCallback jsCallback) {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
PluginContext plugin = PluginManager.getContext(pluginMarker);
boolean active = !plugin.isActive();
boolean active = plugin.isActive();
PluginTaskCallback modifyStatusCallback = new ModifyStatusCallback(active);
if (active) {
PluginManager.getController().forbid(pluginMarker, modifyStatusCallback);
@ -100,13 +92,13 @@ public class PluginOperateUtils {
PluginManager.getController().uninstall(pluginMarker, isForce, new UnistallPluginCallback());
}
public static void readUpdateOnline(JSCallback jsCallback){
public static void readUpdateOnline(JSCallback jsCallback) {
try {
String [] plugins = PluginReaderForDesigner.readPluginsForUpdate();
List<PluginView> plugins = PluginsReaderFromStore.readPluginsForUpdate();
JSONArray jsonArray = new JSONArray();
for (String plugin : plugins) {
for (PluginView plugin : plugins) {
org.json.JSONObject jsonObject = new org.json.JSONObject();
jsonObject.put("pluginid", plugin);
jsonObject.put("pluginid", plugin.getID());
jsonArray.put(jsonObject);
}
String result = jsonArray.toString();
@ -127,7 +119,7 @@ public class PluginOperateUtils {
}
}
public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback){
public static void getPluginFromStore(String category, String seller, String fee, JSCallback jsCallback) {
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist");
if (StringUtils.isNotBlank(plistUrl)) {
StringBuilder url = new StringBuilder();
@ -154,7 +146,7 @@ public class PluginOperateUtils {
}
}
public static void getPluginCategories(JSCallback jsCallback){
public static void getPluginCategories(JSCallback jsCallback) {
String result;
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category");
if (url != null) {
@ -166,27 +158,22 @@ public class PluginOperateUtils {
jsCallback.execute(result);
}
public static void getLoginInfo(JSCallback jsCallback){
public static void getLoginInfo(JSCallback jsCallback) {
String username = BBSPluginLogin.getInstance().getUserInfo().getUserName();
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName();
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) {
return;
}else {
String result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername;
jsCallback.execute(result);
} else {
String result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername;
jsCallback.execute(result);
}
}
private static String[] jsObjectToStringArray(JSObject obj) {
if (obj == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
int len = (int) obj.getMember("length");
List<String> list = new ArrayList<>();
for (int i = 0; i < len; i++) {
list.add(obj.getSlot(i).toString());
}
return list.toArray(new String[len]);
public static boolean pluginValidate(PluginView pluginView){
return StringUtils.isNotEmpty(pluginView.getID())
&& StringUtils.isNotEmpty(pluginView.getName())
&& StringUtils.isNotEmpty(pluginView.getVersion())
&& StringUtils.isNotEmpty(pluginView.getEnvVersion());
}
}

60
designer_base/src/com/fr/design/extra/PluginReaderForDesigner.java

@ -1,60 +0,0 @@
package com.fr.design.extra;
import com.fr.general.GeneralUtils;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.plugin.manage.PluginManager;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/**
* Created by ibm on 2017/5/25.
*/
public class PluginReaderForDesigner {
private static Set<String> pluginsToUpdate = new HashSet<String>();
/**
* 从插件商店服务器读取插件信息以JSON形式返回
*
* @return 插件信息
*/
public static String[] readPluginsForUpdate() throws Exception {
String resText = null;
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.update");
if (StringUtils.isNotEmpty(url)) {
HashMap<String, String> para = new HashMap<String, String>();
para.put("plugins", PluginUtils.transPluginsToString(PluginManager.getContexts()));
//只有当前设计器的jar高于插件新版本需要的jarTime时, 才提示更新该插件.
para.put("jarTime", GeneralUtils.readBuildNO());
HttpClient httpClient = new HttpClient(url, para);
resText = httpClient.getResponseText();
String charSet = EncodeConstants.ENCODING_UTF_8;
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet);
}
if (StringUtils.isNotEmpty(resText)) {
try {
pluginsToUpdate.clear();
JSONArray jsonArray = new JSONArray(resText);
for (int i = 0, size = jsonArray.length(); i < size; i++) {
JSONObject jo = jsonArray.optJSONObject(i);
String id = jo.optString("id");
if(StringUtils.isNotEmpty(id)){
pluginsToUpdate.add(jo.optString("id", ""));
}
}
} catch (JSONException e) {
throw new Exception(Inter.getLocText("FS-Web-Plugin_Read_Plugin_List_Error"));
}
}
return pluginsToUpdate.toArray(new String[pluginsToUpdate.size()]);
}
}

5
designer_base/src/com/fr/design/extra/PluginSelectListener.java

@ -1,6 +1,7 @@
package com.fr.design.extra;
import com.fr.plugin.Plugin;
import com.fr.plugin.view.PluginView;
/**
* @author richie
@ -9,5 +10,5 @@ import com.fr.plugin.Plugin;
*/
public interface PluginSelectListener {
public void valueChanged(Plugin plugin);
public void valueChanged(PluginView plugin);
}

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

@ -3,12 +3,20 @@ package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper;
import com.fr.design.extra.tradition.callback.UpdateOnlineCallback;
import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import com.fr.plugin.view.PluginView;
import com.fr.stable.StringUtils;
import sun.plugin2.main.server.Plugin;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
@ -20,7 +28,7 @@ import java.util.List;
* @date 2015-03-10
* @since 8.0
*/
public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Void> {
public class PluginUpdatePane extends PluginAbstractLoadingViewPane<List<PluginView>, Void> {
private PluginControlPane controlPane;
private JLabel errorMsgLabel;
@ -68,7 +76,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
final PluginStatusCheckCompletePane s = this;
controlPane.addPluginSelectionListener(new PluginSelectListener() {
@Override
public void valueChanged(Plugin plugin) {
public void valueChanged(PluginView plugin) {
s.setInstallButtonEnable(true);
}
});
@ -122,7 +130,7 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
*
* @return 所有插件
*/
public Plugin[] loadData() throws Exception {
public List<PluginView> loadData() throws Exception {
return PluginsReaderFromStore.readPluginsForUpdate();
}
@ -131,9 +139,9 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
*
* @param plugins 插件
*/
public void loadOnSuccess(Plugin[] plugins) {
public void loadOnSuccess(List<PluginView> plugins) {
controlPane.loadPlugins(plugins);
tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer-Plugin_Update") + "(" + plugins.length + ")");
tabbedPane.setTitleAt(1, Inter.getLocText("FR-Designer-Plugin_Update") + "(" + plugins.size() + ")");
}
/**
@ -167,101 +175,36 @@ public class PluginUpdatePane extends PluginAbstractLoadingViewPane<Plugin[], Vo
}
private void doUpdateOnline(final PluginStatusCheckCompletePane pane) {
if (StringUtils.isEmpty(DesignerEnvManager.getEnvManager().getBBSName())) {
if (!BBSPluginLogin.getInstance().hasLogin()) {
LoginCheckContext.fireLoginCheckListener();
}
if (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())) {
new SwingWorker<Void, Double>() {
@Override
protected Void doInBackground() throws Exception {
Plugin plugin = controlPane.getSelectedPlugin();
String id = null;
if (plugin != null) {
id = plugin.getId();
}
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(id, username, password, new Process<Double>() {
@Override
public void process(Double integer) {
publish(integer);
}
});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
return null;
}
public void process(List<Double> list) {
pane.setProgress(list.get(list.size() - 1) * PERSENT);
}
public void done() {
//下载完成,开始执行安装
try {
get();
pane.didTaskFinished();
doUpdateFromFile(PluginHelper.getDownloadTempFile());
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}.execute();
if (BBSPluginLogin.getInstance().hasLogin()) {
PluginView plugin = controlPane.getSelectedPlugin();
PluginMarker pluginMarker = PluginMarker.create(plugin.getID(), plugin.getVersion());
String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarker.getPluginID());
PluginMarker toPluginMarker = PluginMarker.create(pluginMarker.getPluginID(), latestPluginInfo);
PluginManager.getController().download(pluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane));
}
}
private void doUpdateFromFile(File chosenFile) {
try {
Plugin plugin = PluginHelper.readPlugin(chosenFile);
if (plugin == null) {
JOptionPane.showMessageDialog(PluginUpdatePane.this, Inter.getLocText("FR-Designer-Plugin_Illegal_Plugin_Zip"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
PluginManager.getController().update(chosenFile, new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
Plugin oldPlugin = PluginLoader.getLoader().getPluginById(plugin.getId());
if (oldPlugin != null) {
// 说明安装了同ID的插件,再比较两个插件的版本
if (PluginHelper.isNewThan(plugin, oldPlugin)) {
// 说明是新的插件,删除老的然后安装新的
final String[] files = PluginHelper.uninstallPlugin(FRContext.getCurrentEnv(), oldPlugin);
PluginHelper.installPluginFromUnzippedTempDir(FRContext.getCurrentEnv(), plugin, new After() {
@Override
public void done() {
int rv = JOptionPane.showOptionDialog(
PluginUpdatePane.this,
Inter.getLocText("FR-Designer-Plugin_Update_Successful"),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"),
Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")
},
null
);
if (rv == JOptionPane.OK_OPTION) {
RestartHelper.restart();
}
// 如果不是立即重启,就把要删除的文件存放起来
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
RestartHelper.saveFilesWhichToDelete(files);
}
}
});
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
JOptionPane.showMessageDialog(PluginUpdatePane.this, Inter.getLocText("FR-Designer-Plugin_Version_Is_Lower_Than_Current"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(PluginUpdatePane.this, Inter.getLocText("FR-Designer-Plugin_Cannot_Update_Not_Install"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(PluginUpdatePane.this, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
});
}
/**

49
designer_base/src/com/fr/design/extra/PluginUtils.java

@ -1,5 +1,6 @@
package com.fr.design.extra;
import com.fr.base.TemplateUtils;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
@ -9,17 +10,20 @@ import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.view.PluginView;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by ibm on 2017/5/25.
@ -104,4 +108,49 @@ public class PluginUtils {
return resText;
}
public static boolean isPluginMatch(PluginView pluginView, String text){
return StringUtils.contains(pluginView.getID(), text)
|| StringUtils.contains(pluginView.getName(), text)
|| StringUtils.contains(pluginView.getVersion(), text)
|| StringUtils.contains(pluginView.getEnvVersion(), text)
|| StringUtils.contains(pluginView.getVendor(), text)
|| StringUtils.contains(pluginView.getDescription(), text)
|| StringUtils.contains(pluginView.getChangeNotes(), text);
}
public static String pluginToHtml(PluginView pluginView){
String pluginName = Inter.getLocText("FR-Plugin-Plugin_Name");
String pluginVersion = Inter.getLocText("FR-Plugin-Plugin_Version");
String startVersion = Inter.getLocText("FR-Plugin-Start_Version");
String developer = Inter.getLocText("FR-Plugin_Developer");
String desc = Inter.getLocText("FR-Plugin-Function_Description");
String updateLog = Inter.getLocText("FR-Plugin-Update_Log");
Map<String, String> map = new HashMap<String, String>();
map.put("name", pluginName);
map.put("name_value", pluginView.getName());
map.put("version", pluginVersion);
map.put("version_value", pluginView.getVersion());
map.put("env", startVersion);
map.put("env_value", pluginView.getEnvVersion());
map.put("dev", developer);
map.put("dev_value", pluginView.getVendor());
map.put("fun", desc);
map.put("fun_value", pluginView.getDescription());
map.put("update", updateLog);
map.put("update_value", pluginView.getDescription());
try {
return TemplateUtils.renderTemplate("/com/fr/plugin/plugin.html", map);
} catch (IOException e) {
return StringUtils.EMPTY;
}
}
}

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

@ -6,6 +6,8 @@ import com.fr.design.RestartHelper;
import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.*;
import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.design.extra.exe.extratask.ExtraPluginTask;
import com.fr.design.extra.exe.extratask.UpdatePluginTask;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
@ -13,6 +15,7 @@ import com.fr.general.SiteCenter;
import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
@ -145,15 +148,14 @@ public class PluginWebBridge {
* 从插件服务器上安装插件
*
* @param pluginInfo 插件的ID
* @param callback 回调函数
* @param callback 回调函数
*/
public void installPluginOnline(final String pluginInfo, final JSObject callback) {
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.installPluginOnline(pluginInfo,jsCallback);
PluginOperateUtils.installPluginOnline(pluginInfo, jsCallback);
}
/**
* 从磁盘上选择插件安装包进行安装
*
@ -161,7 +163,8 @@ public class PluginWebBridge {
*/
public void installPluginFromDisk(final String filePath, final JSObject callback) {
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.installPluginFromDisk(filePath,jsCallback);
File file = new File(filePath);
PluginOperateUtils.installPluginFromDisk(file, jsCallback);
}
/**
@ -182,7 +185,12 @@ public class PluginWebBridge {
*/
public void updatePluginOnline(JSObject pluginIDs, final JSObject callback) {
JSCallback jsCallback = new JSCallback(webEngine, callback);
PluginOperateUtils.updatePluginOnline(pluginIDs, jsCallback);
String[] pluginInfos = jsObjectToStringArray(pluginIDs);
List<PluginMarker> pluginMarkerList = new ArrayList<PluginMarker>();
for (int i = 0; i < pluginInfos.length; i++) {
pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i]));
}
PluginOperateUtils.updatePluginOnline(pluginMarkerList, jsCallback);
}
/**

52
designer_base/src/com/fr/design/extra/PluginsReaderFromStore.java

@ -6,15 +6,14 @@ import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLoader;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.view.PluginView;
import com.fr.plugin.view.PluginViewReader;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
/**
* @author richie
@ -22,15 +21,15 @@ import java.util.Set;
* @since 8.0
*/
public class PluginsReaderFromStore {
private static Set<Plugin> plugins = new HashSet<Plugin>();
private static Set<Plugin> pluginsToUpdate = new HashSet<Plugin>();
private static Set<PluginView> plugins = new HashSet<PluginView>();
private static Set<PluginView> pluginsToUpdate = new HashSet<PluginView>();
/**
* 从插件商店服务器读取插件信息以JSON形式返回
*
* @return 插件信息
*/
public static Plugin[] readPlugins() throws Exception {
public static List<PluginView> readPlugins() throws Exception {
String resText;
try {
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.store"));
@ -40,23 +39,7 @@ public class PluginsReaderFromStore {
} catch (Exception e) {
throw new Exception(Inter.getLocText("FR-Designer-Plugin_PluginMarket_Coding"));
}
if (StringUtils.isNotEmpty(resText)) {
try {
plugins.clear();//先清空set
JSONArray jsonArray = new JSONArray(resText);
for (int i = 0, size = jsonArray.length(); i < size; i++) {
Plugin plugin = new Plugin();
plugin.parseJSON(jsonArray.optJSONObject(i));
if (plugin.isValidate()) {
plugins.add(plugin);
}
}
} catch (JSONException e) {
throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error"));
}
}
return plugins.toArray(new Plugin[plugins.size()]);
return parseResText(resText, plugins);
}
/**
@ -64,12 +47,12 @@ public class PluginsReaderFromStore {
*
* @return 插件信息
*/
public static Plugin[] readPluginsForUpdate() throws Exception {
public static List<PluginView> readPluginsForUpdate() throws Exception {
String resText = null;
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.update");
if (StringUtils.isNotEmpty(url)) {
HashMap<String, String> para = new HashMap<String, String>();
para.put("plugins", PluginLoader.getLoader().pluginsToString());
para.put("plugins", PluginUtils.transPluginsToString(PluginManager.getContexts()));
//只有当前设计器的jar高于插件新版本需要的jarTime时, 才提示更新该插件.
para.put("jarTime", GeneralUtils.readBuildNO());
HttpClient httpClient = new HttpClient(url, para);
@ -77,22 +60,25 @@ public class PluginsReaderFromStore {
String charSet = EncodeConstants.ENCODING_UTF_8;
resText = URLDecoder.decode(URLDecoder.decode(resText, charSet), charSet);
}
return parseResText(resText, pluginsToUpdate);
}
private static List<PluginView> parseResText(String resText, Set<PluginView> plugins) throws Exception {
if (StringUtils.isNotEmpty(resText)) {
try {
pluginsToUpdate.clear();
plugins.clear();
JSONArray jsonArray = new JSONArray(resText);
for (int i = 0, size = jsonArray.length(); i < size; i++) {
Plugin plugin = new Plugin();
plugin.parseJSON(jsonArray.optJSONObject(i));
if (plugin.isValidate()) {
pluginsToUpdate.add(plugin);
PluginView pluginView = PluginViewReader.readFromJson(jsonArray.optJSONObject(i));
if (PluginOperateUtils.pluginValidate(pluginView)) {
plugins.add(pluginView);
}
}
} catch (JSONException e) {
throw new Exception(Inter.getLocText("FR-Designer-Plugin_Read_Plugin_List_Error"));
}
}
return pluginsToUpdate.toArray(new Plugin[pluginsToUpdate.size()]);
return new ArrayList<>(plugins);
}
}

41
designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java

@ -1,41 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.DesignerEnvManager;
import com.fr.design.extra.Process;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.stable.StringUtils;
/**
* Created by lp on 2016/8/16.
*/
public class GetLoginInfoExecutor implements Executor {
private String result = "[]";
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
String username = BBSPluginLogin.getInstance().getUserInfo().getUserName();
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName();
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) {
return;
}else {
result = StringUtils.isEmpty(inShowUsername) ? username : inShowUsername;
}
}
}
};
}
}

41
designer_base/src/com/fr/design/extra/exe/GetPluginCategoriesExecutor.java

@ -1,41 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginConstants;
import com.fr.design.extra.Process;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
/**
* Created by vito on 16/5/16.
*/
public class GetPluginCategoriesExecutor implements Executor {
private String result = "[]";
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
String url = SiteCenter.getInstance().acquireUrlByKind("plugin.category");
if (url != null) {
HttpClient httpClient = new HttpClient(url);
result = httpClient.getResponseText();
} else {
result = PluginConstants.CONNECTION_404;
}
}
}
};
}
}

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

@ -1,68 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginConstants;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.SiteCenter;
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) {
String plistUrl = SiteCenter.getInstance().acquireUrlByKind("plugin.plist");
if (StringUtils.isNotBlank(plistUrl)) {
StringBuilder url = new StringBuilder();
url.append(plistUrl);
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());
}
} else {
result = PluginConstants.CONNECTION_404;
}
}
}
};
}
}

103
designer_base/src/com/fr/design/extra/exe/InstallFromDiskExecutor.java

@ -1,103 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import javax.swing.*;
import java.io.File;
/**
* Created by richie on 16/3/19.
*/
public class InstallFromDiskExecutor implements Executor {
private String filePath;
public InstallFromDiskExecutor(String filePath) {
this.filePath = filePath;
}
@Override
public String getTaskFinishMessage() {
return Inter.getLocText("FR-Designer-Plugin_Success_Install");
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return Inter.getLocText("FR-Designer-Plugin_Unzipping") + filePath;
}
@Override
public void run(Process<java.lang.String> process) {
}
},
new Command() {
@Override
public String getExecuteMessage() {
return Inter.getLocText("FR-Designer-Plugin_Installing");
}
@Override
public void run(Process<String> process) {
PluginManager.getController().install(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
} else if(result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()){
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")),
Inter.getLocText("FR-Designer-Plugin_Warning"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
installWithDependence();
}else{
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
};
}
public void installWithDependence(){
PluginManager.getController().install(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else{
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}

124
designer_base/src/com/fr/design/extra/exe/InstallOnlineExecutor.java

@ -1,124 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.LoginCheckContext;
import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import javax.swing.*;
/**
* Created by richie on 16/3/19.
*/
public class InstallOnlineExecutor implements Executor {
private String pluginInfo;
public InstallOnlineExecutor(String pluginInfo) {
this.pluginInfo = pluginInfo;
}
@Override
public String getTaskFinishMessage() {
return "task succeed";
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return Inter.getLocText("FR-Designer-Plugin_Downloading") + ":" + pluginInfo.split("_")[0];
}
@Override
public void run(final Process<String> process) {
//下载插件
if (!BBSPluginLogin.getInstance().hasLogin()) {
LoginCheckContext.fireLoginCheckListener();
}
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
if (BBSPluginLogin.getInstance().hasLogin()) {
PluginManager.getController().download(pluginMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double aProgress) {
// process.process(Math.round(aProgress * 100) + "%");
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
installPlugin(pluginMarker);
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
}
};
}
public void installPlugin(PluginMarker pluginMarker) {
PluginManager.getController().install(pluginMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
installPluginWithDependence(pluginMarker);
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
public void installPluginWithDependence(PluginMarker pluginMarker) {
PluginManager.getController().install(pluginMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}

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

@ -1,74 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process;
import com.fr.general.Inter;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.stable.StringUtils;
import javax.swing.*;
/**
* Created by richie on 16/3/19.
*/
public class ModifyStatusExecutor implements Executor {
private String pluginInfo;
private boolean active;
private PluginContext plugin;
public ModifyStatusExecutor(String pluginInfo) {
this.pluginInfo = pluginInfo;
}
@Override
public String getTaskFinishMessage() {
return plugin.isActive() ? Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived") : Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled");
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return StringUtils.EMPTY;
}
@Override
public void run(Process<String> process) {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
plugin = PluginManager.getContext(pluginMarker);
active = !plugin.isActive();
if (active) {
PluginManager.getController().forbid(pluginMarker, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Has_Been_Disabled"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
} else {
PluginManager.getController().enable(pluginMarker, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Has_Been_Actived"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
}
};
}
}

49
designer_base/src/com/fr/design/extra/exe/PluginLoginExecutor.java

@ -1,49 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.LoginWebBridge;
import com.fr.design.extra.Process;
import com.fr.design.gui.ilable.UILabel;
/**
* Created by Slpire on 2016/11/7.
*/
public class PluginLoginExecutor implements Executor {
private String result = "[]";
private String username;
private String password;
private UILabel uiLabel;
public PluginLoginExecutor(String username, String password, UILabel uiLabel) {
this.username = username;
this.password = password;
this.uiLabel = uiLabel;
}
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[] {
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
String loginResult = LoginWebBridge.getHelper().login(username, password, uiLabel);
if (Integer.valueOf(loginResult) == 0) {
LoginWebBridge.getHelper().updateMessageCount();
}
result = loginResult;
}
}
};
}
}

49
designer_base/src/com/fr/design/extra/exe/ReadUpdateOnlineExecutor.java

@ -1,49 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginReaderForDesigner;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.stable.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Created by vito on 16/4/19.
*/
public class ReadUpdateOnlineExecutor implements Executor {
private String[] plugins;
private String result;
@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) {
try {
plugins = PluginReaderForDesigner.readPluginsForUpdate();
JSONArray jsonArray = new JSONArray();
for (String plugin : plugins) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("pluginid", plugin);
jsonArray.put(jsonObject);
}
result = jsonArray.toString();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
};
}
}

47
designer_base/src/com/fr/design/extra/exe/SearchOnlineExecutor.java

@ -1,47 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.stable.StringUtils;
/**
* Created by vito on 16/4/18.
*/
public class SearchOnlineExecutor implements Executor {
private String result;
private String keyword;
public SearchOnlineExecutor(String keyword) {
this.keyword = keyword;
}
@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) {
try {
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("plugin.plist") + "&keyword=" + keyword);
result = httpClient.getResponseText();
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
};
}
}

62
designer_base/src/com/fr/design/extra/exe/UninstallExecutor.java

@ -1,62 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import javax.swing.*;
/**
* Created by richie on 16/3/19.
*/
public class UninstallExecutor implements Executor {
private String pluginInfo;
private boolean isForce;
private String result = "undo";
public UninstallExecutor(String pluginInfo, boolean isForce) {
this.pluginInfo = pluginInfo;
this.isForce = isForce;
}
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
PluginMarker pluginMarker = PluginUtils.createPluginMarker(pluginInfo);
PluginManager.getController().uninstall(pluginMarker, isForce, new PluginTaskCallback() {
@Override
public void done(PluginTaskResult pluginTaskResult) {
if (pluginTaskResult.isSuccess()) {
result = "done";
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed"));
JOptionPane.showMessageDialog(null, pluginTaskResult.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
};
}
}

81
designer_base/src/com/fr/design/extra/exe/UpdateFromDiskExecutor.java

@ -1,81 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import javax.swing.*;
import java.io.File;
/**
* Created by richie on 16/3/19.
*/
public class UpdateFromDiskExecutor implements Executor {
private String filePath;
public UpdateFromDiskExecutor(String filePath) {
this.filePath = filePath;
}
@Override
public String getTaskFinishMessage() {
return Inter.getLocText("FR-Designer-Plugin_Update_End");
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
PluginManager.getController().update(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
updatePluginWithDependence();
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}
};
}
public void updatePluginWithDependence() {
PluginManager.getController().update(new File(filePath), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
}

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

@ -1,118 +0,0 @@
package com.fr.design.extra.exe;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.extra.*;
import com.fr.design.extra.Process;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.bbs.BBSPluginLogin;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import com.fr.stable.StringUtils;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
/**
* Created by richie on 16/3/19.
*/
public class UpdateOnlineExecutor implements Executor {
private String[] pluginInfos;
private static final int PERCENT_100 = 100;
public UpdateOnlineExecutor(String[] pluginInfos) {
this.pluginInfos = pluginInfos;
}
@Override
public String getTaskFinishMessage() {
return "task succeed";
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
if (!(BBSPluginLogin.getInstance().hasLogin())){
LoginCheckContext.fireLoginCheckListener();
}
if (BBSPluginLogin.getInstance().hasLogin()) {
List<PluginMarker> pluginMarkerList = new ArrayList<PluginMarker>();
for (int i = 0; i < pluginInfos.length; i++) {
pluginMarkerList.add(PluginUtils.createPluginMarker(pluginInfos[i]));
}
updatePlugins(pluginMarkerList, process); }
}
}
};
}
public void updatePluginWithDependence(PluginMarker pluginMarker, PluginMarker toMarker) {
PluginManager.getController().update(pluginMarker, toMarker, new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
}
public void updatePlugins(List<PluginMarker> pluginMarkerList, Process<String> process) {
for (int i = 0; i < pluginMarkerList.size(); i++) {
try {
int a = i;
//todo check下此插件的最新版本
String latestPluginInfo = PluginUtils.getLatestPluginInfo(pluginMarkerList.get(i).getPluginID());
if (StringUtils.isEmpty(latestPluginInfo) || PluginConstants.CONNECTION_404.equals(latestPluginInfo)) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Connect_Failed"), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return;
}
JSONObject resultArr = new JSONObject(latestPluginInfo);
String latestPluginVersion = (String) resultArr.get("version");
PluginManager.getController().update(pluginMarkerList.get(i), PluginMarker.create(pluginMarkerList.get(i).getPluginID(), latestPluginVersion), new ProgressCallback() {
@Override
public void updateProgress(String description, double progress) {
process.process(PERCENT_100 / pluginMarkerList.size() * (a + 1) + "%");
}
@Override
public void done(PluginTaskResult result) {
if (result.isSuccess()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
updatePluginWithDependence(pluginMarkerList.get(a), PluginMarker.create(pluginMarkerList.get(a).getPluginID(), latestPluginVersion));
} else {
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
}

1
designer_base/src/com/fr/design/extra/exe/callback/AbstractPluginTaskCallback.java

@ -10,7 +10,6 @@ import com.fr.plugin.manage.control.ProgressCallback;
public abstract class AbstractPluginTaskCallback implements ProgressCallback{
protected PluginMarker pluginMarker;
protected JSCallback jsCallback;
@Override
public void updateProgress(String description, double aProgress) {

2
designer_base/src/com/fr/design/extra/exe/callback/DownloadCallback.java

@ -11,6 +11,7 @@ import javax.swing.*;
*/
public class DownloadCallback extends AbstractPluginTaskCallback {
private ExtraPluginTask extraPluginTask;
protected JSCallback jsCallback;
public DownloadCallback(ExtraPluginTask extraPluginTask, JSCallback jsCallback) {
this.extraPluginTask = extraPluginTask;
@ -24,6 +25,7 @@ public class DownloadCallback extends AbstractPluginTaskCallback {
@Override
public void done(PluginTaskResult result) {
jsCallback.execute("done");
if (result.isSuccess()) {
extraPluginTask.doExtraPluginTask();
} else {

6
designer_base/src/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java

@ -14,6 +14,7 @@ import java.io.File;
*/
public class InstallFromDiskCallback extends AbstractPluginTaskCallback {
private File zipFile;
protected JSCallback jsCallback;
public InstallFromDiskCallback(File zipFile, JSCallback jsCallback) {
this.zipFile = zipFile;
@ -28,14 +29,15 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback {
@Override
public void done(PluginTaskResult result) {
jsCallback.execute("done");
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")),
Inter.getLocText("FR-Designer-Plugin_Install_Success"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,

7
designer_base/src/com/fr/design/extra/exe/callback/InstallOnlineCallback.java

@ -13,6 +13,8 @@ import javax.swing.*;
* Created by ibm on 2017/5/26.
*/
public class InstallOnlineCallback extends AbstractPluginTaskCallback {
protected JSCallback jsCallback;
public InstallOnlineCallback(PluginMarker pluginMarker, JSCallback jsCallback){
this.pluginMarker = pluginMarker;
@ -27,14 +29,15 @@ public class InstallOnlineCallback extends AbstractPluginTaskCallback {
@Override
public void done(PluginTaskResult result) {
jsCallback.execute("done");
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")),
Inter.getLocText("FR-Designer-Plugin_Install_Success"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,

31
designer_base/src/com/fr/design/extra/exe/callback/JSCallback.java

@ -1,5 +1,6 @@
package com.fr.design.extra.exe.callback;
import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine;
import netscape.javascript.JSObject;
@ -16,7 +17,7 @@ public class JSCallback {
}
public void execute(String newValue) {
String fun = "(" + callback + ")(\"" + newValue + "\")";
String fun = "(" + callback + ")(\"" + trimText(newValue) + "\")";
try {
webEngine.executeScript(fun);
} catch (Exception e) {
@ -24,6 +25,34 @@ public class JSCallback {
}
}
public void execute(double progress) {
String fun = "(" + callback + ")(\"" + trimText(String.valueOf(progress)) + "\")";
try {
webEngine.executeScript(fun);
} catch (Exception e) {
webEngine.executeScript("alert(\"" + e.getMessage() + "\")");
}
}
/**
* vito:由于使用webEngine.executeScript("(" + callback + ")(\"" + newValue + "\")")
* 执行脚本所以原来规范的json格式也会在拼接字符串后可能抛出参数异常需要转换掉一些会造成错误的特殊字符
* 选择在java端替换的原因是异常抛出自executeScript方法的参数.
* <p>
* 1.""中的""必须转义
* 2.js字符串中的\n会导致js字符串变成多行,而js字符串不支持多行拼接
* 3.由JSONObject.toString()得到的字符串中html标签的属性会自动加上\造成替换难度加大
* 这边建议去除所有的html标签
*
* @param old 原始字符串
* @return 处理之后的字符串
*/
private String trimText(String old) {
if (StringUtils.isNotBlank(old)) {
return old.replaceAll("\n", "").replaceAll("\"", "\\\\\"").replaceAll("\'", "\\\\\'");
}
return StringUtils.EMPTY;
}
}

1
designer_base/src/com/fr/design/extra/exe/callback/UnistallPluginCallback.java

@ -4,7 +4,6 @@ import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.manage.control.PluginTaskCallback;
import com.fr.plugin.manage.control.PluginTaskResult;
import sun.plugin2.main.server.Plugin;
import javax.swing.*;

9
designer_base/src/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java

@ -2,7 +2,6 @@ package com.fr.design.extra.exe.callback;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.jsqlparser.expression.StringValue;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
@ -15,8 +14,9 @@ import java.io.File;
*/
public class UpdateFromDiskCallback extends AbstractPluginTaskCallback {
private File zipFile;
protected JSCallback jsCallback;
public UpdateFromDiskCallback(File zipFile,JSCallback jsCallback) {
public UpdateFromDiskCallback(File zipFile, JSCallback jsCallback) {
this.zipFile = zipFile;
this.jsCallback = jsCallback;
}
@ -29,14 +29,15 @@ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback {
@Override
public void done(PluginTaskResult result) {
jsCallback.execute("done");
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Install_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")),
Inter.getLocText("FR-Designer-Plugin_Install_Success"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,

9
designer_base/src/com/fr/design/extra/exe/callback/UpdateOnlineCallback.java

@ -14,9 +14,9 @@ import javax.swing.*;
*/
public class UpdateOnlineCallback extends AbstractPluginTaskCallback {
public PluginMarker toPluginMarker;
protected JSCallback jsCallback;
public UpdateOnlineCallback(PluginMarker pluginMarker , PluginMarker toPluginMarker, JSCallback jsCallback) {
public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) {
this.pluginMarker = pluginMarker;
this.toPluginMarker = toPluginMarker;
this.jsCallback = jsCallback;
@ -29,14 +29,15 @@ public class UpdateOnlineCallback extends AbstractPluginTaskCallback {
@Override
public void done(PluginTaskResult result) {
jsCallback.execute("done");
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Success")),
Inter.getLocText("FR-Designer-Plugin_Install_Dependence"),
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")),
Inter.getLocText("FR-Designer-Plugin_Install_Success"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,

11
designer_base/src/com/fr/design/extra/exe/extratask/AbstractExtraPluginTask.java

@ -0,0 +1,11 @@
package com.fr.design.extra.exe.extratask;
import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.plugin.context.PluginMarker;
/**
* Created by ibm on 2017/5/27.
*/
public abstract class AbstractExtraPluginTask implements ExtraPluginTask {
protected PluginMarker pluginMarker;
}

11
designer_base/src/com/fr/design/extra/exe/extratask/InstallPluginTask.java

@ -6,18 +6,19 @@ import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
import javax.swing.*;
/**
* Created by ibm on 2017/5/27.
*/
public class InstallPluginTask implements ExtraPluginTask{
public PluginMarker pluginMarker;
public JSCallback jsCallback;
public InstallPluginTask(PluginMarker pluginMarker, JSCallback jsCallback){
public class InstallPluginTask extends AbstractExtraPluginTask {
protected JSCallback jsCallback;
public InstallPluginTask(PluginMarker pluginMarker, JSCallback jsCallback) {
this.pluginMarker = pluginMarker;
this.jsCallback = jsCallback;
}
@Override
public void doExtraPluginTask() {
PluginManager.getController().install(pluginMarker, new InstallOnlineCallback(pluginMarker, jsCallback));

8
designer_base/src/com/fr/design/extra/exe/extratask/UpdatePluginTask.java

@ -2,20 +2,18 @@ package com.fr.design.extra.exe.extratask;
import com.fr.design.extra.exe.callback.JSCallback;
import com.fr.design.extra.exe.callback.UpdateOnlineCallback;
import com.fr.form.ui.WaterMark;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.manage.PluginManager;
/**
* Created by ibm on 2017/5/27.
*/
public class UpdatePluginTask implements ExtraPluginTask {
public class UpdatePluginTask extends AbstractExtraPluginTask {
public PluginMarker pluginMarker;
public PluginMarker toPluginMarker;
public JSCallback jsCallback;
protected JSCallback jsCallback;
public UpdatePluginTask(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback){
public UpdatePluginTask(PluginMarker pluginMarker, PluginMarker toPluginMarker, JSCallback jsCallback) {
this.pluginMarker = pluginMarker;
this.toPluginMarker = toPluginMarker;
this.jsCallback = jsCallback;

55
designer_base/src/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java

@ -0,0 +1,55 @@
package com.fr.design.extra.tradition.callback;
import com.fr.design.extra.PluginStatusCheckCompletePane;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.error.PluginErrorCode;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginTaskResult;
import com.fr.plugin.manage.control.ProgressCallback;
import javax.swing.*;
/**
* Created by ibm on 2017/5/31.
*/
public class UpdateOnlineCallback implements ProgressCallback {
private PluginStatusCheckCompletePane pane;
private PluginMarker pluginMarker;
private PluginMarker toPluginMarker;
public UpdateOnlineCallback(PluginMarker pluginMarker, PluginMarker toPluginMarker, PluginStatusCheckCompletePane pane){
this.pluginMarker = pluginMarker;
this.toPluginMarker = toPluginMarker;
this.pane = pane;
}
public void updateProgress(String description, double progress){
pane.setProgress(progress);
}
public void done(PluginTaskResult result){
if (result.isSuccess()) {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Update_Success"));
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Plugin_Install_Successful"));
} else if (result.errorCode() == PluginErrorCode.OperationNotSupport.getCode()) {
int rv = JOptionPane.showOptionDialog(
null,
Inter.getLocText(Inter.getLocText("FR-Designer-Plugin_Install_Dependence")),
Inter.getLocText("FR-Designer-Plugin_Install_Success"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null
);
if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {
return;
}
PluginManager.getController().update(pluginMarker, toPluginMarker, new UpdateOnlineCallback(pluginMarker, toPluginMarker, pane));
} else {
FRLogger.getLogger().info(Inter.getLocText("FR-Designer-Plugin_Delete_Failed"));
JOptionPane.showMessageDialog(null, result.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
}
}
}
Loading…
Cancel
Save