yaoh.wu
7 years ago
7 changed files with 1136 additions and 534 deletions
@ -0,0 +1,93 @@
|
||||
package com.fr.env; |
||||
|
||||
import com.fr.dav.LocalEnv; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itextarea.UITextArea; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.gui.itree.filetree.JFileTree; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.file.filter.OnlyShowDirectoryFileFilter; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.JPanel; |
||||
import javax.swing.JScrollPane; |
||||
import javax.swing.event.TreeSelectionEvent; |
||||
import javax.swing.event.TreeSelectionListener; |
||||
import java.awt.BorderLayout; |
||||
import java.io.File; |
||||
|
||||
/** |
||||
* @author yaohwu |
||||
*/ |
||||
public class LocalEnvPane extends BasicBeanPane<LocalEnv> { |
||||
|
||||
private UITextField pathTextField; |
||||
private JFileTree localEnvTree; |
||||
|
||||
public LocalEnvPane() { |
||||
this.setLayout(FRGUIPaneFactory.createM_BorderLayout()); |
||||
|
||||
// northPane
|
||||
JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
this.add(northPane, BorderLayout.NORTH); |
||||
|
||||
northPane.add(new UILabel(Inter.getLocText("Location") + ":"), BorderLayout.WEST); |
||||
northPane.add(pathTextField = new UITextField(), BorderLayout.CENTER); |
||||
|
||||
// 删除选择文件按钮 添加JFileTree
|
||||
|
||||
// centerPane
|
||||
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
this.add(centerPane, BorderLayout.CENTER); |
||||
|
||||
// 添加JFileTree
|
||||
localEnvTree = new JFileTree(); |
||||
JScrollPane localEnvPane = new JScrollPane(localEnvTree); |
||||
centerPane.add(localEnvPane, BorderLayout.CENTER); |
||||
|
||||
// 设置根路径File 和 文件过滤类型
|
||||
localEnvTree.setFileFilter(new OnlyShowDirectoryFileFilter()); |
||||
localEnvTree.setRootFiles(File.listRoots()); |
||||
localEnvTree.addTreeSelectionListener(new TreeSelectionListener() { |
||||
|
||||
@Override |
||||
public void valueChanged(TreeSelectionEvent e) { |
||||
pathTextField.setText(localEnvTree.getSelectedFile().getPath()); |
||||
} |
||||
}); |
||||
|
||||
UITextArea description = new UITextArea(); |
||||
centerPane.add(description, BorderLayout.SOUTH); |
||||
description.setText(Inter.getLocText("Env-Des1")); |
||||
description.setEditable(false); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("Location"); |
||||
} |
||||
|
||||
@Override |
||||
public LocalEnv updateBean() { |
||||
String path = pathTextField.getText(); |
||||
return LocalEnv.createEnv(path); |
||||
} |
||||
|
||||
public String getPath() { |
||||
return pathTextField.getText(); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(LocalEnv ob) { |
||||
if (StringUtils.isBlank(ob.getPath())) { |
||||
return; |
||||
} |
||||
pathTextField.setText(ob.getPath()); |
||||
|
||||
final File tmpFile = new File(ob.getPath()); |
||||
localEnvTree.selectFile(tmpFile); |
||||
localEnvTree.setEnabled(true); |
||||
} |
||||
} |
@ -0,0 +1,555 @@
|
||||
package com.fr.env; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.border.UITitledBorder; |
||||
import com.fr.design.dialog.InformationWarnPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.icheckbox.UICheckBox; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ipasswordfield.UIPassWordField; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.scrollruler.ModLineBorder; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JFileChooser; |
||||
import javax.swing.JOptionPane; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JTextPane; |
||||
import javax.swing.SwingConstants; |
||||
import javax.swing.SwingUtilities; |
||||
import javax.swing.ToolTipManager; |
||||
import javax.swing.border.EmptyBorder; |
||||
import javax.swing.event.DocumentEvent; |
||||
import javax.swing.event.DocumentListener; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Dimension; |
||||
import java.awt.FlowLayout; |
||||
import java.awt.Toolkit; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.KeyEvent; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.io.File; |
||||
|
||||
import static com.fr.design.layout.TableLayout.FILL; |
||||
import static com.fr.design.layout.TableLayout.PREFERRED; |
||||
|
||||
/** |
||||
* @author yaohwu |
||||
*/ |
||||
public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> { |
||||
|
||||
private static final Color TIPS_FONT_COLOR = new Color(0x8f8f92); |
||||
|
||||
/** |
||||
* 是否启用 https 勾选框 |
||||
*/ |
||||
private UICheckBox httpsCheckbox = new UICheckBox(Inter.getLocText("FR-Designer_RemoteEnv_Enable_Https")); |
||||
/** |
||||
* 主机位置输入框 |
||||
*/ |
||||
private UITextField remoteEnvURLInput = new UITextField(); |
||||
/** |
||||
* 主机名输入框 |
||||
*/ |
||||
private UITextField hostNameInput = new UITextField(); |
||||
/** |
||||
* 端口输入框 |
||||
*/ |
||||
private UITextField portInput = new UITextField(); |
||||
/** |
||||
* Web 应用名输入框 |
||||
*/ |
||||
private UITextField webAppNameInput = new UITextField(); |
||||
/** |
||||
* Servlet 名称输入框 |
||||
*/ |
||||
private UITextField servletNameInput = new UITextField(); |
||||
/** |
||||
* 用户名 |
||||
*/ |
||||
private UITextField usernameInput = new UITextField(); |
||||
/** |
||||
* 密码 |
||||
*/ |
||||
private UIPassWordField passwordInput = new UIPassWordField(); |
||||
/** |
||||
* https证书路径 |
||||
*/ |
||||
private UITextField certPathInput = new UITextField(); |
||||
/** |
||||
* https密钥 |
||||
*/ |
||||
private UIPassWordField certSecretKeyInput = new UIPassWordField(); |
||||
/** |
||||
* 选择证书文件按钮 |
||||
*/ |
||||
private UIButton fileChooserButton = new UIButton("..."); |
||||
/** |
||||
* 主机位置 |
||||
*/ |
||||
private RemoteEnvURL remoteEnvURL; |
||||
/** |
||||
* https 配置面板 |
||||
*/ |
||||
private JPanel httpsConfigPanel; |
||||
/** |
||||
* https 密钥标签 |
||||
*/ |
||||
private UILabel certSecretKeyLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Https_Secret_Key")); |
||||
/** |
||||
* https证书路径标签 |
||||
*/ |
||||
private UILabel certPathLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Https_Cert_Path")); |
||||
/** |
||||
* https 证书路径输入框 |
||||
*/ |
||||
private JPanel httpsCertFileInputPanel; |
||||
/** |
||||
* 主机名,web应用,Servlet,端口监听器 |
||||
*/ |
||||
private DocumentListener individualDocListener = new DocumentListener() { |
||||
|
||||
@Override |
||||
public void changedUpdate(DocumentEvent e) { |
||||
updateRemoteURL(); |
||||
fillRemoteEnvURLField(); |
||||
} |
||||
|
||||
@Override |
||||
public void insertUpdate(DocumentEvent e) { |
||||
updateRemoteURL(); |
||||
fillRemoteEnvURLField(); |
||||
} |
||||
|
||||
@Override |
||||
public void removeUpdate(DocumentEvent e) { |
||||
updateRemoteURL(); |
||||
fillRemoteEnvURLField(); |
||||
} |
||||
}; |
||||
/** |
||||
* 路径输入框监听器 |
||||
*/ |
||||
private DocumentListener overallDocListener = new DocumentListener() { |
||||
@Override |
||||
public void insertUpdate(DocumentEvent e) { |
||||
actionURLInputChange(); |
||||
} |
||||
|
||||
@Override |
||||
public void removeUpdate(DocumentEvent e) { |
||||
actionURLInputChange(); |
||||
} |
||||
|
||||
@Override |
||||
public void changedUpdate(DocumentEvent e) { |
||||
actionURLInputChange(); |
||||
} |
||||
}; |
||||
/** |
||||
* https checkbox listener |
||||
*/ |
||||
private ActionListener httpsCheckboxListener = new ActionListener() { |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
boolean isHttps = httpsCheckbox.isSelected(); |
||||
|
||||
DesignerEnvManager.getEnvManager().setHttps(isHttps); |
||||
|
||||
fileChooserButton.setEnabled(isHttps); |
||||
updateHttpsConfigPanel(); |
||||
|
||||
remoteEnvURL.setHttps(isHttps); |
||||
fillRemoteEnvURLField(); |
||||
fillIndividualField(); |
||||
} |
||||
}; |
||||
|
||||
|
||||
public RemoteEnvPane() { |
||||
// 配置内容面板
|
||||
JPanel contentPanel = new JPanel(new BorderLayout()); |
||||
contentPanel.setBorder( |
||||
BorderFactory.createCompoundBorder( |
||||
new EmptyBorder(6, 0, 0, 0), |
||||
UITitledBorder.createBorderWithTitle(Inter.getLocText("FR-Designer_RemoteEnv_Config"))) |
||||
); |
||||
|
||||
|
||||
// 服务器地址地址
|
||||
JPanel configPanel = new JPanel(new BorderLayout()); |
||||
configPanel.setBorder( |
||||
BorderFactory.createCompoundBorder( |
||||
new EmptyBorder(15, 0, 0, 0), |
||||
BorderFactory.createTitledBorder( |
||||
new ModLineBorder(ModLineBorder.TOP), |
||||
Inter.getLocText("FR-Designer_RemoteEnv_Server") |
||||
) |
||||
) |
||||
); |
||||
|
||||
|
||||
certPathLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
certSecretKeyLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
|
||||
packConfigPanel(configPanel); |
||||
|
||||
// 服务器账号配置
|
||||
JPanel accountPanel = new JPanel(new BorderLayout()); |
||||
|
||||
|
||||
accountPanel.setBorder(BorderFactory.createCompoundBorder( |
||||
new EmptyBorder(15, 0, 0, 0), |
||||
BorderFactory.createTitledBorder( |
||||
new ModLineBorder(ModLineBorder.TOP), |
||||
Inter.getLocText("FR-Designer_RemoteEnv_Platform_Account") |
||||
) |
||||
)); |
||||
|
||||
packAccountPanel(accountPanel); |
||||
|
||||
|
||||
// 测试链接按钮
|
||||
JPanel testPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
||||
testPanel.setBorder(BorderFactory.createEmptyBorder()); |
||||
testPanel.setPreferredSize(new Dimension(437, 20)); |
||||
UIButton testConnectionButton = new UIButton(Inter.getLocText("FR-Designer_RemoteEnv_Test_Connection")); |
||||
|
||||
testConnectionButton.setToolTipText(Inter.getLocText("Datasource-Test_Connection")); |
||||
testConnectionButton.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent ev) { |
||||
if (testConnection()) { |
||||
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this), Inter.getLocText("Datasource-Connection_successfully")); |
||||
} |
||||
} |
||||
}); |
||||
testPanel.add(testConnectionButton); |
||||
|
||||
|
||||
contentPanel.add(configPanel, BorderLayout.NORTH); |
||||
contentPanel.add(accountPanel, BorderLayout.CENTER); |
||||
|
||||
this.setLayout(new BorderLayout()); |
||||
this.add(contentPanel, BorderLayout.NORTH); |
||||
this.add(testPanel, BorderLayout.CENTER); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(RemoteEnv ob) { |
||||
|
||||
if (StringUtils.isEmpty(ob.getPath())) { |
||||
remoteEnvURL = RemoteEnvURL.createDefaultURL(); |
||||
} else { |
||||
remoteEnvURL = new RemoteEnvURL(ob.getPath()); |
||||
} |
||||
fillRemoteEnvURLField(); |
||||
fillIndividualField(); |
||||
httpsCheckbox.setSelected(remoteEnvURL.getHttps()); |
||||
|
||||
DesignerEnvManager.getEnvManager().setHttps(remoteEnvURL.getHttps()); |
||||
fileChooserButton.setEnabled(remoteEnvURL.getHttps()); |
||||
updateHttpsConfigPanel(); |
||||
|
||||
this.usernameInput.setText(ob.getUser() == null ? StringUtils.EMPTY : ob.getUser()); |
||||
this.passwordInput.setText(ob.getPassword() == null ? StringUtils.EMPTY : ob.getPassword()); |
||||
} |
||||
|
||||
@Override |
||||
public RemoteEnv updateBean() { |
||||
|
||||
String path = remoteEnvURL.getURL(); |
||||
String user = this.usernameInput.getText(); |
||||
String password = new String(this.passwordInput.getPassword()); |
||||
|
||||
return new RemoteEnv(path, user, password); |
||||
} |
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return "Remote"; |
||||
} |
||||
|
||||
|
||||
private void packConfigPanel(JPanel configPanel) { |
||||
|
||||
|
||||
// 主机名
|
||||
UILabel hostNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Host_IP")); |
||||
hostNameLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
// 端口
|
||||
UILabel portLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Port")); |
||||
portLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
// web应用
|
||||
UILabel webAppNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Web_Name")); |
||||
webAppNameLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
// servlet
|
||||
UILabel servletNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Servlet_Name")); |
||||
servletNameLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
// 主机位置
|
||||
UILabel remoteEnvURLLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_URL")); |
||||
remoteEnvURLLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
|
||||
enableSubDocListener(); |
||||
|
||||
JPanel urlPanel = TableLayoutHelper.createGapTableLayoutPane( |
||||
new Component[][]{ |
||||
new Component[]{hostNameLabel, hostNameInput}, |
||||
new Component[]{portLabel, portInput}, |
||||
new Component[]{webAppNameLabel, webAppNameInput}, |
||||
new Component[]{servletNameLabel, servletNameInput}, |
||||
new Component[]{remoteEnvURLLabel, remoteEnvURLInput} |
||||
}, |
||||
new double[]{PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED}, |
||||
new double[]{PREFERRED, FILL}, |
||||
5, |
||||
10 |
||||
|
||||
); |
||||
|
||||
TableLayoutHelper.modifyTableLayoutIndexVGap(urlPanel, 0, 10); |
||||
|
||||
JTextPane urlTipsPane = new JTextPane(); |
||||
urlTipsPane.setEditable(false); |
||||
urlTipsPane.setText(Inter.getLocText("FR-Designer_RemoteEnv_Server_Config_Tips")); |
||||
urlTipsPane.setBackground(urlPanel.getBackground()); |
||||
urlTipsPane.setForeground(TIPS_FONT_COLOR); |
||||
|
||||
|
||||
httpsCheckbox.addActionListener(httpsCheckboxListener); |
||||
// 初始化 https 可被刷新展示的面板
|
||||
httpsConfigPanel = new JPanel(new BorderLayout()); |
||||
// 初始化 https 证书文件输入框
|
||||
httpsCertFileInputPanel = createHttpsCertFileInputPanel(); |
||||
packHttpsConfigPanel(); |
||||
|
||||
JTextPane httpsTipsPane = new JTextPane(); |
||||
httpsTipsPane.setEditable(false); |
||||
httpsTipsPane.setText(Inter.getLocText("FR-Designer_RemoteEnv_Https_Tips")); |
||||
httpsTipsPane.setBackground(configPanel.getBackground()); |
||||
httpsTipsPane.setForeground(TIPS_FONT_COLOR); |
||||
|
||||
configPanel.add(TableLayoutHelper.createTableLayoutPane( |
||||
new Component[][]{ |
||||
new Component[]{urlPanel}, |
||||
new Component[]{urlTipsPane}, |
||||
new Component[]{httpsConfigPanel}, |
||||
new Component[]{httpsTipsPane} |
||||
}, |
||||
new double[]{PREFERRED, PREFERRED, PREFERRED, PREFERRED}, |
||||
new double[]{FILL} |
||||
)); |
||||
} |
||||
|
||||
|
||||
private void enableSubDocListener() { |
||||
hostNameInput.getDocument().addDocumentListener(individualDocListener); |
||||
portInput.getDocument().addDocumentListener(individualDocListener); |
||||
webAppNameInput.getDocument().addDocumentListener(individualDocListener); |
||||
servletNameInput.getDocument().addDocumentListener(individualDocListener); |
||||
} |
||||
|
||||
private void disableSubDocListener() { |
||||
hostNameInput.getDocument().removeDocumentListener(individualDocListener); |
||||
portInput.getDocument().removeDocumentListener(individualDocListener); |
||||
webAppNameInput.getDocument().removeDocumentListener(individualDocListener); |
||||
servletNameInput.getDocument().removeDocumentListener(individualDocListener); |
||||
} |
||||
|
||||
private void packHttpsConfigPanel() { |
||||
|
||||
|
||||
double[] rows = new double[]{PREFERRED}; |
||||
boolean httpsEnabled = httpsCheckbox.isSelected(); |
||||
|
||||
if (httpsEnabled) { |
||||
rows = new double[]{PREFERRED, PREFERRED, PREFERRED}; |
||||
} |
||||
JPanel content = TableLayoutHelper.createGapTableLayoutPane( |
||||
new Component[][]{ |
||||
new Component[]{httpsCheckbox, new JPanel()}, |
||||
new Component[]{certPathLabel, httpsCertFileInputPanel}, |
||||
new Component[]{certSecretKeyLabel, certSecretKeyInput} |
||||
}, |
||||
rows, |
||||
new double[]{PREFERRED, FILL}, |
||||
5, |
||||
10 |
||||
); |
||||
httpsConfigPanel.add(content, BorderLayout.CENTER); |
||||
} |
||||
|
||||
|
||||
private void packAccountPanel(JPanel accountPanel) { |
||||
|
||||
// 用户名
|
||||
UILabel userNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Account_Username")); |
||||
userNameLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
// 密码
|
||||
UILabel passwordLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Account_Password")); |
||||
passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
||||
|
||||
//输入密码的时候检测下大写锁定
|
||||
passwordInput.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
if (Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) { |
||||
passwordInput.setToolTipText(Inter.getLocText("CapsLock")); |
||||
} else { |
||||
passwordInput.setToolTipText(null); |
||||
} |
||||
ToolTipManager.sharedInstance().setInitialDelay(100); |
||||
} |
||||
}); |
||||
|
||||
Component[][] accountComponents = new Component[][]{ |
||||
new Component[]{userNameLabel, usernameInput}, |
||||
new Component[]{passwordLabel, passwordInput} |
||||
}; |
||||
|
||||
JPanel content = TableLayoutHelper.createGapTableLayoutPane(accountComponents, |
||||
new double[]{PREFERRED, PREFERRED}, |
||||
new double[]{PREFERRED, FILL}, |
||||
5, |
||||
10 |
||||
); |
||||
TableLayoutHelper.modifyTableLayoutIndexVGap(content, 0, 10); |
||||
|
||||
accountPanel.add(content, BorderLayout.CENTER); |
||||
} |
||||
|
||||
|
||||
private JPanel createHttpsCertFileInputPanel() { |
||||
JPanel inputPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); |
||||
inputPanel.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
inputPanel.add(certPathInput, BorderLayout.CENTER); |
||||
inputPanel.add(fileChooserButton, BorderLayout.EAST); |
||||
fileChooserButton.setPreferredSize(new Dimension(20, 20)); |
||||
fileChooserButton.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
JFileChooser fileChooser = new JFileChooser(); |
||||
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
||||
int saveValue = fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this)); |
||||
if (saveValue == JFileChooser.APPROVE_OPTION) { |
||||
File selectedFile = fileChooser.getSelectedFile(); |
||||
certPathInput.setText(selectedFile.getAbsolutePath()); |
||||
} |
||||
} |
||||
}); |
||||
return inputPanel; |
||||
} |
||||
|
||||
|
||||
private void setHttpsParas() { |
||||
System.setProperty("javax.net.ssl.trustStore", this.certPathInput.getText()); |
||||
System.setProperty("javax.net.ssl.trustStorePassword", new String(this.certSecretKeyInput.getPassword())); |
||||
DesignerEnvManager manager = DesignerEnvManager.getEnvManager(); |
||||
manager.setCertificatePath(this.certPathInput.getText()); |
||||
manager.setCertificatePass(new String(this.certSecretKeyInput.getPassword())); |
||||
manager.setHttps(this.httpsCheckbox.isSelected()); |
||||
} |
||||
|
||||
private boolean testConnection() { |
||||
RemoteEnv env = new RemoteEnv(); |
||||
String url = remoteEnvURL.getURL(); |
||||
env.setPath(url); |
||||
env.setUser(usernameInput.getText()); |
||||
env.setPassword(new String(passwordInput.getPassword())); |
||||
boolean connect = false; |
||||
try { |
||||
if (StringUtils.isNotEmpty(url)) { |
||||
if (remoteEnvURL.getHttps()) { |
||||
setHttpsParas(); |
||||
} |
||||
connect = env.testConnectionWithOutRegisteServer(this); |
||||
} |
||||
} catch (Exception e) { |
||||
JOptionPane.showMessageDialog(this, Inter.getLocText("Datasource-Connection_failed")); |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
if (connect) { |
||||
try { |
||||
String remoteVersion = env.getDesignerVersion(); |
||||
if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) { |
||||
String info = Inter.getLocText("Server-version-tip") + "。"; |
||||
String moreInfo = Inter.getLocText("Server-version-tip-moreInfo") + "。"; |
||||
new InformationWarnPane(info, moreInfo, Inter.getLocText("Tooltips")).show(); |
||||
return false; |
||||
} |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
return connect; |
||||
} |
||||
|
||||
/** |
||||
* 自动填充主机位置输入框 |
||||
*/ |
||||
private void fillRemoteEnvURLField() { |
||||
remoteEnvURLInput.getDocument().removeDocumentListener(overallDocListener); |
||||
remoteEnvURLInput.setText(remoteEnvURL.getURL()); |
||||
remoteEnvURLInput.getDocument().addDocumentListener(overallDocListener); |
||||
} |
||||
|
||||
/** |
||||
* 自动填充子条目输入框 |
||||
*/ |
||||
private void fillIndividualField() { |
||||
if (remoteEnvURL == null) { |
||||
return; |
||||
} |
||||
disableSubDocListener(); |
||||
hostNameInput.setText(remoteEnvURL.hasDefaultHostName() ? StringUtils.EMPTY : remoteEnvURL.getHost()); |
||||
portInput.setText(remoteEnvURL.getPort()); |
||||
webAppNameInput.setText(remoteEnvURL.getWeb()); |
||||
servletNameInput.setText(remoteEnvURL.getServlet()); |
||||
enableSubDocListener(); |
||||
} |
||||
|
||||
private void updateRemoteURL() { |
||||
boolean isHttps = httpsCheckbox.isSelected(); |
||||
String host = hostNameInput.getText(); |
||||
String port = portInput.getText(); |
||||
String web = webAppNameInput.getText(); |
||||
String servlet = servletNameInput.getText(); |
||||
remoteEnvURL.setHttps(isHttps); |
||||
remoteEnvURL.setHost(host); |
||||
remoteEnvURL.setPort(port); |
||||
remoteEnvURL.setWeb(web); |
||||
remoteEnvURL.setServlet(servlet); |
||||
} |
||||
|
||||
|
||||
private void updateHttpsConfigPanel() { |
||||
httpsConfigPanel.removeAll(); |
||||
packHttpsConfigPanel(); |
||||
httpsConfigPanel.revalidate(); |
||||
httpsConfigPanel.repaint(); |
||||
} |
||||
|
||||
private void actionURLInputChange() { |
||||
remoteEnvURL = new RemoteEnvURL(remoteEnvURLInput.getText()); |
||||
fillIndividualField(); |
||||
|
||||
httpsCheckbox.setSelected(remoteEnvURL.getHttps()); |
||||
boolean isHttps = httpsCheckbox.isSelected(); |
||||
DesignerEnvManager.getEnvManager().setHttps(isHttps); |
||||
fileChooserButton.setEnabled(isHttps); |
||||
updateHttpsConfigPanel(); |
||||
} |
||||
} |
@ -0,0 +1,228 @@
|
||||
package com.fr.env; |
||||
|
||||
import com.fr.stable.FCloneable; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* @author yaohwu |
||||
*/ |
||||
public class RemoteEnvURL implements FCloneable { |
||||
|
||||
/** |
||||
* 默认 hostname |
||||
*/ |
||||
private static final String DEFAULT_HOST_NAME = "${IP}"; |
||||
/** |
||||
* 默认 web app name |
||||
*/ |
||||
private static final String DEFAULT_WEB_APP_NAME = "WebReport"; |
||||
/** |
||||
* 默认 servlet name |
||||
*/ |
||||
private static final String DEFAULT_SERVLET_NAME = "ReportServer"; |
||||
/** |
||||
* 默认端口 |
||||
*/ |
||||
private static final String DEFAULT_PORT = "8080"; |
||||
private static final String HTTPS = "https://"; |
||||
private static final String HTTP = "http://"; |
||||
|
||||
public static final RemoteEnvURL DEFAULT_URL = |
||||
new RemoteEnvURL( |
||||
false, |
||||
DEFAULT_HOST_NAME, |
||||
DEFAULT_PORT, |
||||
DEFAULT_WEB_APP_NAME, |
||||
DEFAULT_SERVLET_NAME); |
||||
|
||||
private boolean isHttps; |
||||
private String host; |
||||
private String port; |
||||
private String web; |
||||
private String servlet; |
||||
|
||||
|
||||
/** |
||||
* 解析 url 字符串 生成 RemoteEnvURL 对象 |
||||
* url 字符串格式 (http(s)://)host(:port)/+web/+servlet/+(others)
|
||||
* |
||||
* @param url x:x/x/x/x |
||||
*/ |
||||
public RemoteEnvURL(String url) { |
||||
|
||||
// 没有写协议名称 默认 使用 http 协议
|
||||
if (!url.startsWith(HTTPS) && !url.startsWith(HTTP)) { |
||||
url = HTTP + url; |
||||
} |
||||
// 第二次出现":"的地方,port位置起始点
|
||||
int portIndex = url.indexOf(":", url.indexOf(":") + 1); |
||||
// 第三次出现"/"的地方
|
||||
int webIndex = url.indexOf("/", url.indexOf("://") + 3); |
||||
|
||||
isHttps = url.startsWith(HTTPS); |
||||
|
||||
if (portIndex > webIndex && webIndex != -1) { |
||||
portIndex = -1; |
||||
} |
||||
|
||||
if (portIndex == -1) { |
||||
if (webIndex == -1) { |
||||
host = isHttps ? url.substring(HTTPS.length()) : url.substring(HTTP.length()); |
||||
port = StringUtils.EMPTY; |
||||
web = StringUtils.EMPTY; |
||||
servlet = StringUtils.EMPTY; |
||||
} else { |
||||
host = isHttps ? url.substring(HTTPS.length(), webIndex) : url.substring(HTTP.length(), webIndex); |
||||
port = StringUtils.EMPTY; |
||||
web = StringUtils.EMPTY; |
||||
servlet = StringUtils.EMPTY; |
||||
String[] lefts = url.substring(webIndex + 1).split("/+"); |
||||
parserWebAndServlet(lefts); |
||||
} |
||||
} else { |
||||
if (webIndex == -1) { |
||||
host = isHttps ? url.substring(HTTPS.length(), portIndex) : url.substring(HTTP.length(), portIndex); |
||||
port = url.substring(portIndex + 1); |
||||
web = StringUtils.EMPTY; |
||||
servlet = StringUtils.EMPTY; |
||||
} else { |
||||
host = isHttps ? url.substring(HTTPS.length(), portIndex) : url.substring(HTTP.length(), portIndex); |
||||
port = url.substring(portIndex + 1, webIndex); |
||||
web = StringUtils.EMPTY; |
||||
servlet = StringUtils.EMPTY; |
||||
String[] lefts = url.substring(webIndex + 1).split("/+"); |
||||
parserWebAndServlet(lefts); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public boolean hasDefaultHostName() { |
||||
return DEFAULT_HOST_NAME.equals(host); |
||||
} |
||||
|
||||
public static RemoteEnvURL createDefaultURL() { |
||||
return DEFAULT_URL.clone(); |
||||
} |
||||
|
||||
|
||||
public RemoteEnvURL(boolean isHttps, String host, String port, String web, String servlet) { |
||||
this.isHttps = isHttps; |
||||
this.host = host != null ? host.trim() : StringUtils.EMPTY; |
||||
this.port = port != null ? port.trim() : StringUtils.EMPTY; |
||||
this.web = web != null ? web.trim() : StringUtils.EMPTY; |
||||
this.servlet = servlet != null ? servlet.trim() : StringUtils.EMPTY; |
||||
} |
||||
|
||||
public String getURL() { |
||||
String prefix = isHttps ? HTTPS : HTTP; |
||||
String portColon = StringUtils.isNotEmpty(port) ? ":" : StringUtils.EMPTY; |
||||
String webAppNameSlash = StringUtils.isNotEmpty(web) ? "/" : StringUtils.EMPTY; |
||||
String servletNameSlash = StringUtils.isNotEmpty(servlet) ? "/" : StringUtils.EMPTY; |
||||
return prefix + host + portColon + port + webAppNameSlash + web + servletNameSlash + servlet; |
||||
} |
||||
|
||||
|
||||
public void setHttps(boolean https) { |
||||
isHttps = https; |
||||
} |
||||
|
||||
public void setHost(String host) { |
||||
this.host = host != null ? host.trim() : StringUtils.EMPTY; |
||||
} |
||||
|
||||
public void setPort(String port) { |
||||
this.port = port != null ? port.trim() : StringUtils.EMPTY; |
||||
} |
||||
|
||||
public void setWeb(String web) { |
||||
this.web = web != null ? web.trim() : StringUtils.EMPTY; |
||||
} |
||||
|
||||
public void setServlet(String servlet) { |
||||
this.servlet = servlet != null ? servlet.trim() : StringUtils.EMPTY; |
||||
} |
||||
|
||||
public boolean getHttps() { |
||||
return isHttps; |
||||
} |
||||
|
||||
public String getHost() { |
||||
return host; |
||||
} |
||||
|
||||
public String getPort() { |
||||
return port; |
||||
} |
||||
|
||||
public String getWeb() { |
||||
return web; |
||||
} |
||||
|
||||
public String getServlet() { |
||||
return servlet; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (o == null || getClass() != o.getClass()) { |
||||
return false; |
||||
} |
||||
RemoteEnvURL that = (RemoteEnvURL) o; |
||||
return isHttps == that.isHttps && |
||||
Objects.equals(host, that.host) && |
||||
Objects.equals(port, that.port) && |
||||
Objects.equals(web, that.web) && |
||||
Objects.equals(servlet, that.servlet); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
|
||||
return Objects.hash(isHttps, host, port, web, servlet); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "RemoteEnvURL{" + |
||||
"isHttps=" + isHttps + |
||||
", host='" + host + '\'' + |
||||
", port='" + port + '\'' + |
||||
", web='" + web + '\'' + |
||||
", servlet='" + servlet + '\'' + |
||||
'}'; |
||||
} |
||||
|
||||
@Override |
||||
public RemoteEnvURL clone() { |
||||
RemoteEnvURL cloned; |
||||
try { |
||||
cloned = (RemoteEnvURL) super.clone(); |
||||
return cloned; |
||||
} catch (CloneNotSupportedException e) { |
||||
// this shouldn't happen, since we are Cloneable
|
||||
throw new InternalError(e); |
||||
} |
||||
} |
||||
|
||||
private void parserWebAndServlet(String[] lefts) { |
||||
int index; |
||||
for (index = 0; index < lefts.length; index++) { |
||||
if (StringUtils.isNotEmpty(lefts[index])) { |
||||
web = lefts[index]; |
||||
index++; |
||||
break; |
||||
} |
||||
} |
||||
for (int servletIndex = index; servletIndex < lefts.length; servletIndex++) { |
||||
if (StringUtils.isNotEmpty(lefts[servletIndex])) { |
||||
servlet = lefts[servletIndex]; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,199 @@
|
||||
package com.fr.env; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
|
||||
/** |
||||
* @author yaohwu |
||||
*/ |
||||
public class RemoteEnvURLTest { |
||||
|
||||
@Test |
||||
public void testURLParser() { |
||||
|
||||
String a; |
||||
RemoteEnvURL b; |
||||
|
||||
// https or http begin
|
||||
a = "www.baidu.com:9090/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
Assert.assertFalse(b.getHttps()); |
||||
|
||||
a = "http://www.baidu.com:9090/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
Assert.assertFalse(b.getHttps()); |
||||
|
||||
a = "https://www.baidu.com:9090/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
Assert.assertTrue(b.getHttps()); |
||||
// https or http end
|
||||
|
||||
// host begin
|
||||
a = "https://www.baidu.com/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("www.baidu.com", b.getHost()); |
||||
|
||||
a = "https://baidu.com/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("baidu.com", b.getHost()); |
||||
|
||||
a = "https://192.168.1/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("192.168.1", b.getHost()); |
||||
|
||||
a = "https://中文·o((⊙﹏⊙))o囖/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("中文·o((⊙﹏⊙))o囖", b.getHost()); |
||||
|
||||
a = "https://a.b.c.d.e.f/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("a.b.c.d.e.f", b.getHost()); |
||||
// host end
|
||||
|
||||
//port begin
|
||||
a = "https://www.baidu.com:9090/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("9090", b.getPort()); |
||||
|
||||
a = "https://www.baidu.com:/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getPort()); |
||||
|
||||
a = "https://www.baidu.com/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getPort()); |
||||
|
||||
a = "https://www.baidu.com:kk/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("kk", b.getPort()); |
||||
|
||||
a = "https://www.baidu.com:中文·o((⊙﹏⊙))o囖/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("中文·o((⊙﹏⊙))o囖", b.getPort()); |
||||
|
||||
a = "https://www.baidu.com:中文·o((⊙﹏⊙))o囖"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("中文·o((⊙﹏⊙))o囖", b.getPort()); |
||||
|
||||
a = "https://www.baidu.com:中文·o((⊙﹏⊙))o囖///////"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("中文·o((⊙﹏⊙))o囖", b.getPort()); |
||||
//port end
|
||||
|
||||
|
||||
//web begin
|
||||
|
||||
a = "https://www.baidu.com:9090///"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getWeb()); |
||||
|
||||
a = "https://www.baidu.com:9090"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getWeb()); |
||||
|
||||
a = "https://www.baidu.com:9090/"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getWeb()); |
||||
|
||||
a = "https://www.baidu.com:9090///web///servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("web", b.getWeb()); |
||||
|
||||
a = "https://www.baidu.com:9090/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("web", b.getWeb()); |
||||
|
||||
a = "https://www.baidu.com:9090/中文·o((⊙﹏⊙))o囖/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("中文·o((⊙﹏⊙))o囖", b.getWeb()); |
||||
|
||||
a = "https://www.baidu.com:9090/web///servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("web", b.getWeb()); |
||||
|
||||
a = "https://www.baidu.com:9090///web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("web", b.getWeb()); |
||||
//web end
|
||||
|
||||
//servlet begin
|
||||
a = "https://www.baidu.com:9090///web////servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("servlet", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090/"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//web"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//web//"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//web/"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//web//"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//web/a/"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("a", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//web/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("a", b.getServlet()); |
||||
|
||||
|
||||
a = "https://www.baidu.com:9090//web/a//"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("a", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com:9090//web/中文·o((⊙﹏⊙))o囖//"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("中文·o((⊙﹏⊙))o囖", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com//web//"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com//web/a/"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("a", b.getServlet()); |
||||
|
||||
a = "https://www.baidu.com//web/a"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("a", b.getServlet()); |
||||
|
||||
|
||||
a = "https://www.baidu.com//web/a//"; |
||||
b = new RemoteEnvURL(a); |
||||
assertEquals("a", b.getServlet()); |
||||
// servlet end
|
||||
|
||||
//others begin
|
||||
a = "https://www.baidu.com/web/servlet/ahttps://www.baidu.com/web/servlet/a"; |
||||
b = new RemoteEnvURL(a); |
||||
Assert.assertTrue(b.getHttps()); |
||||
assertEquals("www.baidu.com", b.getHost()); |
||||
assertEquals("", b.getPort()); |
||||
assertEquals("web", b.getWeb()); |
||||
assertEquals("servlet", b.getServlet()); |
||||
//others begin
|
||||
} |
||||
} |
Loading…
Reference in new issue