You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
654 lines
26 KiB
654 lines
26 KiB
package com.fr.env; |
|
|
|
import com.fine.swing.ui.layout.Layouts; |
|
import com.fine.theme.icon.LazyIcon; |
|
import com.fine.theme.utils.FineUIScale; |
|
import com.fine.theme.utils.FineUIUtils; |
|
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
|
import com.fr.design.DesignerEnvManager; |
|
import com.fr.design.ExtraDesignClassManager; |
|
import com.fr.design.beans.BasicBeanPane; |
|
import com.fr.design.env.RemoteDesignerWorkspaceInfo; |
|
import com.fr.design.env.processor.RemoteDesignerWorkspaceInfoProcessor; |
|
import com.fr.design.fun.DesignerEnvProcessor; |
|
import com.fr.design.gui.ibutton.UIButton; |
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
import com.fr.design.gui.icontainer.UIScrollPane; |
|
import com.fr.design.gui.ifilechooser.FileChooserArgs; |
|
import com.fr.design.gui.ifilechooser.FileChooserFactory; |
|
import com.fr.design.gui.ifilechooser.FileChooserProvider; |
|
import com.fr.design.gui.ifilechooser.FileSelectionMode; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.gui.ipasswordfield.UIPassWordField; |
|
import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength; |
|
import com.fr.design.gui.itextfield.UITextField; |
|
import com.fr.design.i18n.DesignSizeI18nManager; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.design.layout.TableLayoutHelper; |
|
import com.fr.env.handler.WorkspaceExceptionHandler; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.third.guava.base.Strings; |
|
import com.fr.workspace.WorkContext; |
|
import com.fr.workspace.connect.WorkspaceConnectionInfo; |
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.JDialog; |
|
import javax.swing.JFileChooser; |
|
import javax.swing.JPanel; |
|
import javax.swing.JTextPane; |
|
import javax.swing.SwingConstants; |
|
import javax.swing.SwingUtilities; |
|
import javax.swing.SwingWorker; |
|
import javax.swing.ToolTipManager; |
|
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.Dialog; |
|
import java.awt.Dimension; |
|
import java.awt.FlowLayout; |
|
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.awt.event.WindowAdapter; |
|
import java.awt.event.WindowEvent; |
|
import java.io.File; |
|
|
|
|
|
import static com.fr.design.layout.TableLayout.FILL; |
|
import static com.fr.design.layout.TableLayout.PREFERRED; |
|
import static com.fr.third.guava.base.Optional.fromNullable; |
|
|
|
/** |
|
* @author yaohwu |
|
*/ |
|
@SuppressWarnings("squid:MaximumInheritanceDepth") |
|
public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> { |
|
|
|
private static final Color TIPS_FONT_COLOR = new Color(0x8f8f92); |
|
|
|
private JDialog dialog; |
|
private UILabel message = new UILabel(); |
|
private UIButton okButton = new UIButton(Toolkit.i18nText("Fine-Design_Report_OK")); |
|
private UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); |
|
private UILabel uiLabel = new UILabel(); |
|
private final int FIRST_COL_WIDTH = 80; |
|
private final int SECOND_COL_WIDTH = 68; |
|
|
|
|
|
/** |
|
* 是否启用 https 勾选框 |
|
*/ |
|
private UICheckBox httpsCheckbox = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_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 UIPasswordFieldWithFixedLength(); |
|
/** |
|
* 是否记住密码 |
|
*/ |
|
private UICheckBox rememberPwdCheckbox = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Remember_Password")); |
|
/** |
|
* https证书路径 |
|
*/ |
|
private UITextField certPathInput = new UITextField(); |
|
/** |
|
* https密钥 |
|
*/ |
|
private UIPassWordField certSecretKeyInput = new UIPasswordFieldWithFixedLength(); |
|
/** |
|
* 选择证书文件按钮 |
|
*/ |
|
private UIButton fileChooserButton = new UIButton("..."); |
|
/** |
|
* 主机位置 |
|
*/ |
|
@SuppressWarnings("squid:S1948") |
|
private RemoteWorkspaceURL remoteWorkspaceURL = new RemoteWorkspaceURL(""); |
|
/** |
|
* https 配置面板 |
|
*/ |
|
private JPanel httpsConfigPanel; |
|
/** |
|
* https 密钥标签 |
|
*/ |
|
private UILabel certSecretKeyLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Https_Secret_Key")); |
|
/** |
|
* https证书路径标签 |
|
*/ |
|
private UILabel certPathLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Https_Cert_Path")); |
|
/** |
|
* https 证书路径输入框 |
|
*/ |
|
private JPanel httpsCertFileInputPanel; |
|
|
|
/** |
|
* 当前远程工作目录是否为新创建的 |
|
*/ |
|
private boolean newCreated; |
|
|
|
/** |
|
* 主机名,web应用,Servlet,端口监听器 |
|
*/ |
|
@SuppressWarnings("squid:S1948") |
|
private DocumentListener individualDocListener = new DocumentListener() { |
|
|
|
@Override |
|
public void changedUpdate(DocumentEvent e) { |
|
updateRemoteURL(); |
|
fillRemoteEnvURLField(); |
|
} |
|
|
|
@Override |
|
public void insertUpdate(DocumentEvent e) { |
|
changedUpdate(e); |
|
} |
|
|
|
@Override |
|
public void removeUpdate(DocumentEvent e) { |
|
changedUpdate(e); |
|
} |
|
|
|
private void updateRemoteURL() { |
|
boolean isHttps = httpsCheckbox.isSelected(); |
|
String host = hostNameInput.getText(); |
|
String port = portInput.getText(); |
|
String web = webAppNameInput.getText(); |
|
String servlet = servletNameInput.getText(); |
|
remoteWorkspaceURL.setHttps(isHttps); |
|
remoteWorkspaceURL.setHost(host); |
|
remoteWorkspaceURL.setPort(port); |
|
remoteWorkspaceURL.setWeb(web); |
|
remoteWorkspaceURL.setServlet(servlet); |
|
remoteWorkspaceURL.resetUrl(); |
|
} |
|
}; |
|
/** |
|
* 路径输入框监听器 |
|
*/ |
|
@SuppressWarnings("squid:S1948") |
|
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(); |
|
} |
|
|
|
private void actionURLInputChange() { |
|
remoteWorkspaceURL = new RemoteWorkspaceURL(remoteEnvURLInput.getText()); |
|
fillIndividualField(); |
|
|
|
httpsCheckbox.setSelected(remoteWorkspaceURL.getHttps()); |
|
boolean isHttps = httpsCheckbox.isSelected(); |
|
DesignerEnvManager.getEnvManager().setHttps(isHttps); |
|
fileChooserButton.setEnabled(isHttps); |
|
updateHttpsConfigPanel(); |
|
} |
|
}; |
|
/** |
|
* https checkbox listener |
|
*/ |
|
@SuppressWarnings("squid:S1948") |
|
private ActionListener httpsCheckboxListener = new ActionListener() { |
|
|
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
boolean isHttps = httpsCheckbox.isSelected(); |
|
|
|
DesignerEnvManager.getEnvManager().setHttps(isHttps); |
|
|
|
fileChooserButton.setEnabled(isHttps); |
|
updateHttpsConfigPanel(); |
|
|
|
remoteWorkspaceURL.setHttps(isHttps); |
|
// reset下url,将勾选状态是否https加到url里 |
|
remoteWorkspaceURL.resetUrl(); |
|
|
|
fillRemoteEnvURLField(); |
|
fillIndividualField(); |
|
} |
|
}; |
|
/** |
|
* 测试链接对话框确定取消按钮面板 |
|
*/ |
|
private JPanel dialogDownPane = new JPanel(); |
|
|
|
|
|
public RemoteEnvPane() { |
|
// 配置内容面板 |
|
JPanel contentPanel = new JPanel(new BorderLayout()); |
|
|
|
// 服务器地址地址 |
|
final JPanel configPanel = new JPanel(new BorderLayout()); |
|
certPathLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
certSecretKeyLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
|
|
packConfigPanel(configPanel); |
|
|
|
// 服务器账号配置 |
|
JPanel accountPanel = new JPanel(new BorderLayout()); |
|
accountPanel.setBorder(new ScaledEmptyBorder(10, 0, 0, 0)); |
|
packAccountPanel(accountPanel); |
|
|
|
// 测试链接按钮 |
|
JPanel testPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
|
testPanel.setBorder(BorderFactory.createEmptyBorder()); |
|
UIButton testConnectionButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Test_Connection")); |
|
|
|
testConnectionButton.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_Datasource_Test_Connection")); |
|
testConnectionButton.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent ev) { |
|
tryConnectRemoteEnv(); |
|
} |
|
}); |
|
testPanel.add(testConnectionButton); |
|
|
|
contentPanel.add(configPanel, BorderLayout.NORTH); |
|
contentPanel.add(accountPanel, BorderLayout.CENTER); |
|
UILabel label = new UILabel(); |
|
FineUIUtils.wrapBoldLabelWithUnderline(label); |
|
contentPanel.add(label, BorderLayout.SOUTH); |
|
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
panel.add(FineUIUtils.wrapComponentWithTitle(contentPanel, Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Config")), BorderLayout.NORTH); |
|
panel.add(testPanel, BorderLayout.CENTER); |
|
panel.setPreferredSize(new Dimension(FineUIScale.scale(440), (int) panel.getPreferredSize().getHeight())); |
|
UIScrollPane scrollPane = new UIScrollPane(panel); |
|
this.setLayout(new BorderLayout()); |
|
this.add(scrollPane); |
|
} |
|
|
|
@Override |
|
public void populateBean(RemoteDesignerWorkspaceInfo ob) { |
|
WorkspaceConnectionInfo connection = ob.getConnection(); |
|
if (connection != null) { |
|
this.remoteWorkspaceURL = Strings.isNullOrEmpty(connection.getUrl()) |
|
? RemoteWorkspaceURL.createDefaultURL() |
|
: new RemoteWorkspaceURL(connection.getUrl()); |
|
String username = fromNullable(connection.getUserName()).or(StringUtils.EMPTY); |
|
String pwd = fromNullable(connection.getPassword()).or(StringUtils.EMPTY); |
|
String certPath = fromNullable(connection.getCertPath()).or(StringUtils.EMPTY); |
|
String certSecretKey = fromNullable(connection.getCertSecretKey()).or(StringUtils.EMPTY); |
|
boolean rememberPwd = fromNullable(connection.isRememberPwd()).or(true); |
|
this.usernameInput.setText(username); |
|
this.passwordInput.setText(pwd); |
|
this.certPathInput.setText(certPath); |
|
this.certSecretKeyInput.setText(certSecretKey); |
|
this.rememberPwdCheckbox.setSelected(rememberPwd); |
|
this.newCreated = ob.isNewCreated(); |
|
} else { |
|
this.remoteWorkspaceURL = RemoteWorkspaceURL.createDefaultURL(); |
|
this.usernameInput.setText(StringUtils.EMPTY); |
|
this.passwordInput.setText(StringUtils.EMPTY); |
|
this.certPathInput.setText(StringUtils.EMPTY); |
|
this.certSecretKeyInput.setText(StringUtils.EMPTY); |
|
this.rememberPwdCheckbox.setSelected(true); |
|
this.newCreated = true; |
|
} |
|
|
|
fillRemoteEnvURLField(); |
|
fillIndividualField(); |
|
httpsCheckbox.setSelected(this.remoteWorkspaceURL.getHttps()); |
|
|
|
DesignerEnvManager.getEnvManager().setHttps(this.remoteWorkspaceURL.getHttps()); |
|
fileChooserButton.setEnabled(this.remoteWorkspaceURL.getHttps()); |
|
updateHttpsConfigPanel(); |
|
|
|
|
|
} |
|
|
|
@Override |
|
public RemoteDesignerWorkspaceInfo updateBean() { |
|
String url = removeSpaces(this.remoteWorkspaceURL.getURL()); |
|
String username = removeSpaces(this.usernameInput.getText()); |
|
String password = new String(this.passwordInput.getPassword()); |
|
boolean rememberPwd = this.rememberPwdCheckbox.isSelected(); |
|
DesignerEnvProcessor envProcessor = ExtraDesignClassManager.getInstance().getSingle(DesignerEnvProcessor.XML_TAG); |
|
if (envProcessor != null) { |
|
url = envProcessor.changeEnvPathBeforeConnect(username, password, url); |
|
} |
|
WorkspaceConnectionInfo connection = new WorkspaceConnectionInfo( |
|
url, |
|
username, |
|
password, |
|
this.certPathInput.getText(), |
|
new String(this.certSecretKeyInput.getPassword()), |
|
rememberPwd); |
|
|
|
RemoteDesignerWorkspaceInfo info = RemoteDesignerWorkspaceInfo.create(connection); |
|
info.setNewCreated(newCreated); |
|
return info; |
|
} |
|
|
|
private String removeSpaces(String str) { |
|
if (StringUtils.isNotEmpty(str)) { |
|
return str.trim(); |
|
} |
|
return str; |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return "Remote"; |
|
} |
|
|
|
|
|
private void packConfigPanel(JPanel configPanel) { |
|
// 主机名 |
|
UILabel hostNameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Host_IP")); |
|
hostNameLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
// 端口 |
|
UILabel portLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Port")); |
|
portLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
// web应用 |
|
UILabel webAppNameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Web_Name")); |
|
webAppNameLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
// servlet |
|
UILabel servletNameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Servlet_Name")); |
|
servletNameLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
// 主机位置 |
|
UILabel remoteEnvURLLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_URL")); |
|
remoteEnvURLLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
|
|
//远程服务器 |
|
UILabel remoteServerLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Server")); |
|
remoteServerLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
|
|
enableSubDocListener(); |
|
|
|
JPanel urlPanel = TableLayoutHelper.createGapTableLayoutPane( |
|
new Component[][]{ |
|
new Component[]{remoteServerLabel, hostNameLabel, hostNameInput}, |
|
new Component[]{new UILabel(), portLabel, portInput}, |
|
new Component[]{new UILabel(), webAppNameLabel, webAppNameInput}, |
|
new Component[]{new UILabel(), servletNameLabel, servletNameInput}, |
|
new Component[]{new UILabel(), remoteEnvURLLabel, remoteEnvURLInput} |
|
}, |
|
new double[]{PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED}, |
|
new double[]{FIRST_COL_WIDTH, SECOND_COL_WIDTH, FILL}, |
|
14, |
|
10 |
|
); |
|
|
|
JTextPane urlTipsPane = new JTextPane(); |
|
urlTipsPane.setEditable(false); |
|
urlTipsPane.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_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(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_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 UILabel()}, |
|
new Component[]{new UILabel(), certPathLabel, httpsCertFileInputPanel}, |
|
new Component[]{new UILabel(), certSecretKeyLabel, certSecretKeyInput} |
|
}, |
|
rows, |
|
new double[]{FIRST_COL_WIDTH, SECOND_COL_WIDTH, FILL}, |
|
14, |
|
10 |
|
); |
|
httpsConfigPanel.add(content, BorderLayout.CENTER); |
|
} |
|
|
|
|
|
private void packAccountPanel(JPanel accountPanel) { |
|
|
|
// 用户名 |
|
UILabel userNameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Account_Username")); |
|
userNameLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
// 密码 |
|
UILabel passwordLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Account_Password")); |
|
passwordLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
|
|
UILabel accountLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Platform_Account")); |
|
accountLabel.setHorizontalAlignment(SwingConstants.LEFT); |
|
|
|
//输入密码的时候检测下大写锁定 |
|
passwordInput.addMouseListener(new MouseAdapter() { |
|
@Override |
|
public void mouseEntered(MouseEvent e) { |
|
if (java.awt.Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) { |
|
passwordInput.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_CapsLock")); |
|
} else { |
|
passwordInput.setToolTipText(null); |
|
} |
|
ToolTipManager.sharedInstance().setInitialDelay(100); |
|
} |
|
}); |
|
|
|
Component[][] accountComponents = new Component[][]{ |
|
new Component[]{accountLabel, userNameLabel, usernameInput}, |
|
new Component[]{new UILabel(), passwordLabel, passwordInput}, |
|
new Component[]{new UILabel(), new UILabel(), rememberPwdCheckbox} |
|
}; |
|
|
|
JPanel content = TableLayoutHelper.createGapTableLayoutPane(accountComponents, |
|
new double[]{PREFERRED, PREFERRED, PREFERRED}, |
|
new double[]{FIRST_COL_WIDTH, SECOND_COL_WIDTH, FILL}, |
|
14, |
|
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.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent evt) { |
|
FileChooserProvider fileChooserProvider = FileChooserFactory.createFileChooser(FileChooserArgs.newBuilder(). |
|
setFileSelectionMode(FileSelectionMode.FILE).build()); |
|
int saveValue = fileChooserProvider.showDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this)); |
|
if (saveValue == JFileChooser.APPROVE_OPTION) { |
|
File selectedFile = fileChooserProvider.getSelectedFile(); |
|
certPathInput.setText(selectedFile.getAbsolutePath()); |
|
} |
|
} |
|
}); |
|
return inputPanel; |
|
} |
|
|
|
private void tryConnectRemoteEnv() { |
|
final RemoteDesignerWorkspaceInfo remoteEnv = updateBean(); |
|
WorkspaceConnectionInfo originalConnection = remoteEnv.getConnection(); |
|
final WorkspaceConnectionInfo connection; |
|
RemoteDesignerWorkspaceInfoProcessor processor = ExtraDesignClassManager.getInstance().getSingle(RemoteDesignerWorkspaceInfoProcessor.XML_TAG); |
|
if (processor != null) { |
|
connection = processor.customUserName(originalConnection); |
|
} else { |
|
connection = originalConnection; |
|
} |
|
final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() { |
|
|
|
@Override |
|
protected Boolean doInBackground() throws Exception { |
|
return WorkContext.getConnector().testConnection(connection); |
|
} |
|
|
|
@Override |
|
protected void done() { |
|
okButton.setEnabled(true); |
|
try { |
|
if (get()) { |
|
message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Successful")); |
|
uiLabel.setIcon(new LazyIcon("information", 20)); |
|
} |
|
} catch (Exception e) { |
|
dialog.dispose(); |
|
WorkspaceExceptionHandler.getInstance().handleInTest(e, remoteEnv); |
|
} |
|
} |
|
}; |
|
worker.execute(); |
|
initMessageDialog(); |
|
okButton.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
dialog.dispose(); |
|
} |
|
}); |
|
cancelButton.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
dialog.dispose(); |
|
worker.cancel(true); |
|
} |
|
}); |
|
|
|
dialog.addWindowListener(new WindowAdapter() { |
|
@Override |
|
public void windowClosed(WindowEvent e) { |
|
worker.cancel(true); |
|
} |
|
}); |
|
|
|
dialog.setVisible(true); |
|
dialog.dispose(); |
|
} |
|
|
|
private void initMessageDialog() { |
|
message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Try") + "..."); |
|
okButton.setEnabled(false); |
|
|
|
dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(RemoteEnvPane.this), Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"), true); |
|
|
|
dialog.setSize(FineUIScale.scale(DesignSizeI18nManager.getInstance().i18nDimension("com.fr.env.RemoteEnvPane.dialog"))); |
|
okButton.setEnabled(false); |
|
JPanel jp = new JPanel(); |
|
JPanel upPane = new JPanel(new BorderLayout()); |
|
dialogDownPane = new JPanel(); |
|
uiLabel = new UILabel(new LazyIcon("information", 20)); |
|
upPane.add(Layouts.row(10, Layouts.cell(uiLabel), Layouts.cell(message), Layouts.flex()).getComponent(), BorderLayout.NORTH); |
|
dialogDownPane.setLayout(new FlowLayout(FlowLayout.RIGHT, 8, 0)); |
|
dialogDownPane.add(okButton); |
|
dialogDownPane.add(cancelButton); |
|
jp.setLayout(new BorderLayout()); |
|
jp.setBorder(new ScaledEmptyBorder(10, 10, 10, 10)); |
|
jp.add(upPane, BorderLayout.CENTER); |
|
jp.add(dialogDownPane, BorderLayout.SOUTH); |
|
dialog.add(jp); |
|
dialog.setResizable(false); |
|
dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(RemoteEnvPane.this)); |
|
} |
|
|
|
/** |
|
* 自动填充主机位置输入框 |
|
*/ |
|
private void fillRemoteEnvURLField() { |
|
remoteEnvURLInput.getDocument().removeDocumentListener(overallDocListener); |
|
remoteEnvURLInput.setText(remoteWorkspaceURL.getURL()); |
|
remoteEnvURLInput.getDocument().addDocumentListener(overallDocListener); |
|
} |
|
|
|
/** |
|
* 自动填充子条目输入框 |
|
*/ |
|
private void fillIndividualField() { |
|
if (remoteWorkspaceURL == null) { |
|
return; |
|
} |
|
disableSubDocListener(); |
|
hostNameInput.setText(remoteWorkspaceURL.hasDefaultHostName() ? StringUtils.EMPTY : remoteWorkspaceURL.getHost()); |
|
portInput.setText(remoteWorkspaceURL.getPort()); |
|
webAppNameInput.setText(remoteWorkspaceURL.getWeb()); |
|
servletNameInput.setText(remoteWorkspaceURL.getServlet()); |
|
enableSubDocListener(); |
|
} |
|
|
|
private void updateHttpsConfigPanel() { |
|
httpsConfigPanel.removeAll(); |
|
packHttpsConfigPanel(); |
|
httpsConfigPanel.revalidate(); |
|
httpsConfigPanel.repaint(); |
|
} |
|
}
|
|
|