Browse Source

update

master
Fangjie Hu 8 years ago
parent
commit
84127e8dbe
  1. 3
      designer_base/src/com/fr/design/extra/PluginHelper.java
  2. 32
      designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java
  3. 23
      designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUtils.java

3
designer_base/src/com/fr/design/extra/PluginHelper.java

@ -126,6 +126,7 @@ public class PluginHelper {
//将所有未配置好的资源文件依赖准备好 //将所有未配置好的资源文件依赖准备好
private static void checkDependenceEnv(Plugin plugin) { private static void checkDependenceEnv(Plugin plugin) {
PluginDependence dependence = plugin.getDependence(); PluginDependence dependence = plugin.getDependence();
String currentID = dependence.getCurrentPluginID();
if (dependence == null){ if (dependence == null){
return; return;
} }
@ -133,7 +134,7 @@ public class PluginHelper {
for (int i = 0;list != null && i < list.size(); i++){ for (int i = 0;list != null && i < list.size(); i++){
PluginDependenceUnit preDependence = list.get(i); PluginDependenceUnit preDependence = list.get(i);
if (!preDependence.checkFileEnv()){ if (!preDependence.checkFileEnv()){
DownLoadDependenceUtils.preDependenceOnline(preDependence.getDependenceID(), preDependence.getFileDir()); DownLoadDependenceUtils.preDependenceOnline(currentID, preDependence.getDependenceID(), preDependence.getFileDir());
} }
} }
} }

32
designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java

@ -42,8 +42,9 @@ public class DownLoadDependenceUI implements ActionListener {
private final int LOAD_HEIGHT = 295; private final int LOAD_HEIGHT = 295;
//安装环境相关信息 //安装环境相关信息
private String ID; private String currentID;
private String dir; private String dependenceID;
private String dependenceDir;
//安装结果 //安装结果
private boolean result = false; private boolean result = false;
//链接服务器的客户端 //链接服务器的客户端
@ -54,9 +55,12 @@ public class DownLoadDependenceUI implements ActionListener {
private int totalSize = 0; private int totalSize = 0;
public DownLoadDependenceUI(String ID, String dir) { public DownLoadDependenceUI(String ID, String dir) {
this.ID = ID; }
this.dir = dir;
this.totalSize = getFileLength(); public DownLoadDependenceUI(String currentID, String dependenceID, String dependenceDir) {
this.currentID = currentID;
this.dependenceID = dependenceID;
this.dependenceDir = dependenceDir;
init(); init();
} }
@ -84,7 +88,7 @@ public class DownLoadDependenceUI implements ActionListener {
timer = new Timer(100, this); timer = new Timer(100, this);
frame = new JDialog(DesignerContext.getDesignerFrame(), true); frame = new JDialog(DesignerContext.getDesignerFrame(), true);
frame.setTitle("在线安装" + ID); frame.setTitle(Inter.getLocText("FR-Designer-Dependence_Install_Online") + dependenceID);
frame.setSize(LOAD_WIDTH, LOAD_HEIGHT); frame.setSize(LOAD_WIDTH, LOAD_HEIGHT);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(screenSize.width/2-LOAD_WIDTH/2,screenSize.height/2-LOAD_HEIGHT/2); frame.setLocation(screenSize.width/2-LOAD_WIDTH/2,screenSize.height/2-LOAD_HEIGHT/2);
@ -107,13 +111,13 @@ public class DownLoadDependenceUI implements ActionListener {
//是否可以连接服务器 //是否可以连接服务器
private boolean connectToServer(){ private boolean connectToServer(){
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(ID)); httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID));
return httpClient.getResponseCode() == HttpURLConnection.HTTP_OK; return httpClient.getResponseCode() == HttpURLConnection.HTTP_OK;
} }
//获取依赖文件大小 //获取依赖文件大小
private int getFileLength(){ private int getFileLength(){
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(ID)); HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
return httpClient.getContentLength(); return httpClient.getContentLength();
} }
@ -147,7 +151,7 @@ public class DownLoadDependenceUI implements ActionListener {
} }
private String downloadPluginPhantomJSFile() throws Exception { private String downloadPluginPhantomJSFile() throws Exception {
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(ID)); httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream reader = httpClient.getResponseStream(); InputStream reader = httpClient.getResponseStream();
String temp = StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE); String temp = StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE);
@ -194,7 +198,7 @@ public class DownLoadDependenceUI implements ActionListener {
//安装已经下载好的文件 //安装已经下载好的文件
private void installPluginPhantomJsFile(String filePath){ private void installPluginPhantomJsFile(String filePath){
IOUtils.unzip(new File(filePath), dir); IOUtils.unzip(new File(filePath), dependenceDir);
} }
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -211,18 +215,18 @@ public class DownLoadDependenceUI implements ActionListener {
} }
public boolean preOnline() { public boolean preOnline() {
int choose = JOptionPane.showConfirmDialog(null, "新图表需要" + ID + "支持。是否需要安装" + ID + "(" + showFileLength() + " m)", "install tooltip", JOptionPane.YES_NO_OPTION); int choose = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer-Plugin_Plugin") + currentID + Inter.getLocText("Need") + dependenceID + Inter.getLocText("Support") + "," + Inter.getLocText("Need_Install") + dependenceID + "(" + showFileLength() + " m)?", "install tooltip", JOptionPane.YES_NO_OPTION);
if (choose == 0){//下载安装 if (choose == 0){//下载安装
if (!connectToServer()){ if (!connectToServer()){
JOptionPane.showMessageDialog(null, "无法连接远程服务器!!", "警告", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error"), "alert", JOptionPane.ERROR_MESSAGE);
return false; return false;
} }
//安装依赖环境 //安装依赖环境
if (install()){ if (install()){
JOptionPane.showMessageDialog(null, "安装成功!!"); JOptionPane.showMessageDialog(null, Inter.getLocText("Install_Succeed") + "!!");
return true; return true;
}else { }else {
JOptionPane.showMessageDialog(null, "安装失败!!", "警告", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, Inter.getLocText("Install_Failed") + "!!", "alert", JOptionPane.ERROR_MESSAGE);
return false; return false;
} }
}else {//不安装。无需为用户准备环境 }else {//不安装。无需为用户准备环境

23
designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUtils.java

@ -3,30 +3,11 @@ package com.fr.design.extra.plugindependence;
/** /**
* Created by hufan on 2016/8/31. * Created by hufan on 2016/8/31.
*/ */
import com.fr.design.extra.PluginConstants;
import com.fr.design.extra.PluginHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import javax.swing.*;
public class DownLoadDependenceUtils { public class DownLoadDependenceUtils {
public static boolean preDependenceOnline(String dependenceID, String dir) { public static boolean preDependenceOnline(String currentID, String dependenceID, String dependenceDir) {
DownLoadDependenceUI ui = new DownLoadDependenceUI(dependenceID, dir); DownLoadDependenceUI ui = new DownLoadDependenceUI(currentID, dependenceID, dependenceDir);
return ui.preOnline(); return ui.preOnline();
} }
} }

Loading…
Cancel
Save