Browse Source
* commit '5e68b887b18fabaff35843288b465a61098b2286': 改下名字 pmd魔术数 REPORT-916 [插件管理]提示下载,点取消就弹出一个空白的窗口master
superman
8 years ago
7 changed files with 173 additions and 299 deletions
@ -1,53 +0,0 @@
|
||||
package com.fr.design.actions.server; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.extra.ShopDialog; |
||||
import com.fr.design.extra.PluginWebBridge; |
||||
import com.fr.design.extra.WebManagerPaneFactory; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.menu.MenuKeySet; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/27. |
||||
*/ |
||||
public class ReuseManagerAction extends UpdateAction { |
||||
|
||||
public ReuseManagerAction() { |
||||
this.setMenuKeySet(REUSE_MANAGER); |
||||
this.setName(getMenuKeySet().getMenuKeySetName()); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/server/plugin.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
BasicPane managerPane = new WebManagerPaneFactory().createReusePane(); |
||||
UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane); |
||||
PluginWebBridge.getHelper().setDialogHandle(dlg); |
||||
dlg.setVisible(true); |
||||
} |
||||
|
||||
public static final MenuKeySet REUSE_MANAGER = new MenuKeySet() { |
||||
@Override |
||||
public char getMnemonic() { |
||||
return 'R'; |
||||
} |
||||
|
||||
@Override |
||||
public String getMenuName() { |
||||
return Inter.getLocText("FR-Designer-Reuse_Manager"); |
||||
} |
||||
|
||||
@Override |
||||
public KeyStroke getKeyStroke() { |
||||
return null; |
||||
} |
||||
}; |
||||
} |
@ -0,0 +1,165 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.RestartHelper; |
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.gui.frpane.UITabbedPane; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.plugin.PluginVerifyException; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.net.HttpURLConnection; |
||||
import java.util.concurrent.ExecutionException; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/28. |
||||
*/ |
||||
public class WebDialog { |
||||
private static final String LATEST = "latest"; |
||||
private static final String SHOP_SCRIPTS = "shop_scripts"; |
||||
private static final int VERSION_8 = 8; |
||||
private static String installHome = StableUtils.getInstallHome(); |
||||
|
||||
public static void createPluginDialog() { |
||||
UIDialog dlg; |
||||
if (StableUtils.getMajorJavaVersion() >= VERSION_8) { |
||||
String relativePath = "/scripts/store/web/index.html"; |
||||
String mainJsPath = StableUtils.pathJoin(new File(installHome).getAbsolutePath(), relativePath); |
||||
File file = new File(mainJsPath); |
||||
if (!file.exists()) { |
||||
int rv = JOptionPane.showConfirmDialog( |
||||
null, |
||||
Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.OK_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE |
||||
); |
||||
if (rv == JOptionPane.OK_OPTION) { |
||||
downloadShopScripts(SHOP_SCRIPTS); |
||||
} |
||||
} else { |
||||
updateShopScripts(SHOP_SCRIPTS); |
||||
BasicPane managerPane = new ShopManagerPane(new PluginWebPane(mainJsPath)); |
||||
dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane); |
||||
PluginWebBridge.getHelper().setDialogHandle(dlg); |
||||
dlg.setVisible(true); |
||||
} |
||||
} else { |
||||
BasicPane traditionalStorePane = new BasicPane() { |
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer-Plugin_Manager"); |
||||
} |
||||
}; |
||||
traditionalStorePane.setLayout(new BorderLayout()); |
||||
traditionalStorePane.add(initTraditionalStore(), BorderLayout.CENTER); |
||||
dlg = new ShopDialog(DesignerContext.getDesignerFrame(), traditionalStorePane); |
||||
dlg.setVisible(true); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 以关键词打开设计器商店 |
||||
* <p> |
||||
* // * @param keyword 关键词
|
||||
*/ |
||||
public void createPluginDialog(String keyword) { |
||||
PluginWebBridge.getHelper().openWithSearch(keyword); |
||||
createPluginDialog(); |
||||
} |
||||
|
||||
|
||||
private static Component initTraditionalStore() { |
||||
UITabbedPane tabbedPane = new UITabbedPane(); |
||||
PluginInstalledPane installedPane = new PluginInstalledPane(); |
||||
tabbedPane.addTab(installedPane.tabTitle(), installedPane); |
||||
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_Update"), new PluginUpdatePane(tabbedPane)); |
||||
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); |
||||
return tabbedPane; |
||||
} |
||||
|
||||
private static void downloadShopScripts(final String scriptsId) { |
||||
new SwingWorker<Boolean, Void>() { |
||||
@Override |
||||
protected Boolean doInBackground() throws Exception { |
||||
String username = DesignerEnvManager.getEnvManager().getBBSName(); |
||||
String password = DesignerEnvManager.getEnvManager().getBBSPassword(); |
||||
try { |
||||
PluginHelper.downloadPluginFile(scriptsId, username, password, new Process<Double>() { |
||||
@Override |
||||
public void process(Double integer) { |
||||
} |
||||
}); |
||||
} catch (PluginVerifyException e) { |
||||
JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); |
||||
return false; |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
protected void done() { |
||||
|
||||
try { |
||||
if (get()) { |
||||
IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); |
||||
int rv = JOptionPane.showOptionDialog( |
||||
null, |
||||
Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), |
||||
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 (InterruptedException | ExecutionException e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
|
||||
} |
||||
}.execute(); |
||||
} |
||||
|
||||
private static void updateShopScripts(final String scriptsId) { |
||||
new SwingWorker<Void, Void>() { |
||||
@Override |
||||
protected Void doInBackground() throws Exception { |
||||
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); |
||||
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { |
||||
String text = httpClient.getResponseText(); |
||||
if (!ComparatorUtils.equals(text, LATEST)) { |
||||
int rv = JOptionPane.showConfirmDialog( |
||||
null, |
||||
Inter.getLocText("FR-Designer-Plugin_Shop_Need_Update"), |
||||
Inter.getLocText("FR-Designer-Plugin_Warning"), |
||||
JOptionPane.OK_CANCEL_OPTION, |
||||
JOptionPane.INFORMATION_MESSAGE |
||||
); |
||||
if (rv == JOptionPane.OK_OPTION) { |
||||
downloadShopScripts(scriptsId); |
||||
} |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
}.execute(); |
||||
} |
||||
} |
@ -1,99 +0,0 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.frpane.UITabbedPane; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
import javafx.embed.swing.JFXPanel; |
||||
|
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.net.URL; |
||||
|
||||
/** |
||||
* Created by vito on 2016/9/28. |
||||
*/ |
||||
public class WebManagerPaneFactory { |
||||
private String installHome; |
||||
|
||||
public WebManagerPaneFactory() { |
||||
if (StableUtils.isDebug()) { |
||||
URL url = ClassLoader.getSystemResource(""); |
||||
this.installHome = url.getPath(); |
||||
} else { |
||||
this.installHome = StableUtils.getInstallHome(); |
||||
} |
||||
} |
||||
|
||||
public BasicPane createPluginPane() { |
||||
if (StableUtils.getMajorJavaVersion() == 8) { |
||||
return new ShopManagerPane(new ShopPaneConfig() { |
||||
@Override |
||||
String getMainJS() { |
||||
String relativePath = "/scripts/store/web/index.html"; |
||||
return StableUtils.pathJoin(new File(installHome).getAbsolutePath(), relativePath); |
||||
} |
||||
|
||||
@Override |
||||
String getScriptsId() { |
||||
return "shop_scripts"; |
||||
} |
||||
|
||||
@Override |
||||
JFXPanel getWebPane() { |
||||
return new PluginWebPane(getMainJS()); |
||||
} |
||||
|
||||
}); |
||||
} else { |
||||
BasicPane traditionalStorePane = new BasicPane() { |
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer-Plugin_Manager"); |
||||
} |
||||
}; |
||||
traditionalStorePane.setLayout(new BorderLayout()); |
||||
traditionalStorePane.add(initTraditionalStore(), BorderLayout.CENTER); |
||||
return traditionalStorePane; |
||||
} |
||||
} |
||||
|
||||
public BasicPane createReusePane() { |
||||
return new ShopManagerPane(new ShopPaneConfig() { |
||||
@Override |
||||
String getMainJS() { |
||||
String relativePath = "/scripts/store/reuse/index.html"; |
||||
return StableUtils.pathJoin(new File(installHome).getAbsolutePath(), relativePath); |
||||
} |
||||
|
||||
@Override |
||||
String getScriptsId() { |
||||
return "reuse_scripts"; |
||||
} |
||||
|
||||
@Override |
||||
JFXPanel getWebPane() { |
||||
return new ReuseWebPane(getMainJS()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 以关键词打开设计器商店 |
||||
* |
||||
* @param keyword 关键词 |
||||
*/ |
||||
public BasicPane createPluginPane(String keyword) { |
||||
PluginWebBridge.getHelper().openWithSearch(keyword); |
||||
return createPluginPane(); |
||||
} |
||||
|
||||
private Component initTraditionalStore() { |
||||
UITabbedPane tabbedPane = new UITabbedPane(); |
||||
PluginInstalledPane installedPane = new PluginInstalledPane(); |
||||
tabbedPane.addTab(installedPane.tabTitle(), installedPane); |
||||
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_Update"), new PluginUpdatePane(tabbedPane)); |
||||
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); |
||||
return tabbedPane; |
||||
} |
||||
} |
Loading…
Reference in new issue