From c1e2016c6e97460ac13c893bfd48644dbadfeb96 Mon Sep 17 00:00:00 2001 From: xiqiu Date: Tue, 11 Jan 2022 16:25:58 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-64012=20=20ssh=E4=B8=8Essl=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datapane/connect/AdvancePane.java | 14 +- .../connect/DatabaseConnectionPane.java | 44 ++- .../data/datapane/connect/JDBCDefPane.java | 13 +- .../design/data/datapane/connect/SshPane.java | 275 ++++++++++++++++++ .../design/data/datapane/connect/SslPane.java | 170 +++++++++++ .../editor/NotNegativeIntegerEditor.java | 28 ++ .../java/com/fr/file/FILEChooserPane.java | 89 +++++- 7 files changed, 609 insertions(+), 24 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/connect/SshPane.java create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/connect/SslPane.java create mode 100644 designer-base/src/main/java/com/fr/design/editor/editor/NotNegativeIntegerEditor.java diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java index 204123095..683437b18 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java @@ -15,9 +15,9 @@ import com.fr.stable.StringUtils; import javax.swing.JPanel; import javax.swing.SwingConstants; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; -import java.awt.Dimension; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; @@ -34,13 +34,12 @@ public class AdvancePane extends BasicPane { public AdvancePane() { - + JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); DBCP_VALIDATION_QUERY.addFocusListener(new JTextFieldHintListener(DBCP_VALIDATION_QUERY)); - ; double p = TableLayout.PREFERRED; - DBCP_VALIDATION_QUERY.setColumns(15); + DBCP_VALIDATION_QUERY.setColumns(20); double[] rowSizeDbcp = {p, p, p, p}; - double[] columnDbcp = {p, p}; + double[] columnDbcp = {200, p}; Component[][] comps = { {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE}, {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY}, @@ -49,9 +48,8 @@ public class AdvancePane extends BasicPane { }; JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSizeDbcp, columnDbcp, 11, 11); - this.add(contextPane); - this.setPreferredSize(new Dimension(630, 120)); - this.setLayout(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout()); + jPanel.add(contextPane, BorderLayout.CENTER); + this.add(jPanel); } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java index 91e8006d1..4d5556ef9 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java @@ -7,6 +7,7 @@ import com.fr.data.impl.Connection; import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JNDIDatabaseConnection; import com.fr.data.operator.DataOperatorProvider; +import com.fr.data.security.ssl.impl.NormalSsl; import com.fr.data.solution.ExceptionSolutionSelector; import com.fr.data.solution.entity.DriverPage; import com.fr.data.solution.processor.ClassNotFoundExceptionSolutionProcessor; @@ -61,7 +62,7 @@ import java.util.concurrent.ExecutionException; * Database Connection pane. */ public abstract class DatabaseConnectionPane extends BasicBeanPane { - private static int MAX_MAIN_PANEL_HEIGHT = 430; + private static int MAX_MAIN_PANEL_HEIGHT = 410; private static int MAX_MAIN_PANEL_WIDTH = 675; private UILabel message; @@ -312,6 +313,15 @@ public abstract class DatabaseConnectionPane jdbcMap = new HashMap(); + private JPanel linkPanel; static { jdbcMap.put(OTHER_DB, new DriverURLName[]{new DriverURLName("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:"), @@ -477,11 +479,16 @@ public class JDBCDefPane extends JPanel { } ActionListener driverListener = new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { + linkPanel.setVisible(DriverClasses.MYSQL.toString().equalsIgnoreCase((String) dbtypeComboBox.getSelectedItem()) + && driverComboBox.getSelectedItem() != null + && ComparatorUtils.equals(DriverClasses.MYSQL.getDriverClass(), driverComboBox.getSelectedItem().toString().trim())); + odbcTipsLink.setVisible(driverComboBox.getSelectedItem() != null + && ComparatorUtils.equals("sun.jdbc.odbc.JdbcOdbcDriver", driverComboBox.getSelectedItem().toString().trim())); // 选择的如果是ODBC就显示提示 if (driverComboBox.getSelectedItem() == null || ComparatorUtils.equals(driverComboBox.getSelectedItem(), StringUtils.EMPTY)) { return; } - odbcTipsLink.setVisible(ComparatorUtils.equals("sun.jdbc.odbc.JdbcOdbcDriver", driverComboBox.getSelectedItem())); // 选择的如果是ODBC就显示提示 Iterator> jdbc = jdbcMap.entrySet().iterator(); while (jdbc.hasNext()) { Entry entry = jdbc.next(); @@ -494,7 +501,6 @@ public class JDBCDefPane extends JPanel { } } } - }; ActionListener dbtypeButtonActionListener = new ActionListener() { @@ -738,4 +744,7 @@ public class JDBCDefPane extends JPanel { } + public void addLinkPane(JPanel panel) { + linkPanel = panel; + } } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/SshPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/SshPane.java new file mode 100644 index 000000000..6baec5bbb --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/SshPane.java @@ -0,0 +1,275 @@ +package com.fr.design.data.datapane.connect; + +import com.fr.data.impl.JDBCDatabaseConnection; +import com.fr.data.security.ssh.BaseSsh; +import com.fr.data.security.ssh.Ssh; +import com.fr.data.security.ssh.SshException; +import com.fr.data.security.ssh.SshType; +import com.fr.data.security.ssh.impl.KeyVerifySsh; +import com.fr.data.security.ssh.impl.NormalSsh; +import com.fr.data.security.ssl.SslUtils; +import com.fr.design.border.UITitledBorder; +import com.fr.design.dialog.BasicPane; +import com.fr.design.editor.editor.NotNegativeIntegerEditor; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.file.FILE; +import com.fr.file.FILEChooserPane; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.stable.StringUtils; +import com.fr.stable.project.ProjectConstants; +import com.fr.third.guava.collect.HashBiMap; + +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.SwingConstants; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; + +import static com.fr.design.i18n.Toolkit.i18nText; + +/** + * @author xiqiu + * @date 2021/12/23 + * @description + */ +public class SshPane extends BasicPane { + private static HashBiMap typeMap; + + static { + typeMap = HashBiMap.create(); + typeMap.put(Toolkit.i18nText("Fine-Design_Basic_Password"), SshType.NORMAL); + typeMap.put(Toolkit.i18nText("Fine-Design_Basic_Ssh_Public_Key"), SshType.KEY); + } + + private UICheckBox usingSsh = new UICheckBox(i18nText("Fine-Design_Basic_Ssh_Using")); + private NotNegativeIntegerEditor port = new NotNegativeIntegerEditor(); + private UITextField ip = new UITextField(); + private UIComboBox type = new UIComboBox(); + private UITextField user = new UITextField(); + private JPasswordField password = new UIPasswordFieldWithFixedLength(20); + private JPasswordField secret = new UIPasswordFieldWithFixedLength(20); + private KeyFileUITextField keyPath = new KeyFileUITextField(); + private JPanel contextPane; + private Component[][] passwordComps; + private Component[][] keyComps; + private double p = TableLayout.PREFERRED; + private double f = TableLayout.FILL; + private JPanel jPanel; + private UIButton fileChooserButton = new UIButton("..."); + private double[] columnSize = new double[]{208, p}; + + public SshPane() { + this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Basic_Ssh_Settings"))); + this.setLayout(FRGUIPaneFactory.createLabelFlowLayout()); + typeMap.keySet().forEach(key -> type.addItem(key)); + type.setSelectedItem(typeMap.inverse().get(SshType.KEY)); + jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + keyPath.setColumns(18); + fileChooserButton.setPreferredSize(new Dimension(20, 20)); + type.setEditable(false); + type.setSelectedItem(Toolkit.i18nText("Fine-Design_Basic_Ssh_Private_Key")); + JPanel filePanel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + filePanel.add(keyPath); + filePanel.add(fileChooserButton); + Component[] compIp = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Host") + ":", SwingConstants.RIGHT), ip}; + Component[] compPort = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Port") + ":", SwingConstants.RIGHT), port}; + Component[] compUserName = {new UILabel(Toolkit.i18nText("Fine-Design_Report_UserName") + ":", SwingConstants.RIGHT), user}; + Component[] compMethod = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssh_Verify_Method") + ":", SwingConstants.RIGHT), type}; + Component[] compPassword = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Password") + ":", SwingConstants.RIGHT), password}; + Component[] compKey = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssh_Private_Key") + ":", SwingConstants.RIGHT), filePanel}; + Component[] comSecret = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssh_Secret") + ":", SwingConstants.RIGHT), secret}; + + passwordComps = new Component[][]{ + compIp, + compPort, + compUserName, + compMethod, + compPassword + }; + keyComps = new Component[][]{ + compIp, + compPort, + compUserName, + compMethod, + compKey, + comSecret + }; + usingSsh.setSelected(true); + contextPane = TableLayoutHelper.createGapTableLayoutPane(keyComps, new double[]{p, p, p, p, p, p}, columnSize, 11, 11); + jPanel.add(usingSsh, BorderLayout.NORTH); + jPanel.add(contextPane, BorderLayout.CENTER); + this.add(jPanel); + + usingSsh.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + changePane(); + } + }); + + type.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + changePaneForType(); + } + }); + fileChooserButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + FILEChooserPane fileChooser = FILEChooserPane.getInstanceWithDesignatePath(ProjectConstants.RESOURCES_NAME, new ChooseFileFilter(SslUtils.KEY_FILE_EXTENSION)); + int type = fileChooser.showOpenDialog(SshPane.this); + if (type == FILEChooserPane.OK_OPTION) { + final FILE file = fileChooser.getSelectedFILE(); + if (file == null) { + keyPath.setText(StringUtils.EMPTY); + } else { + keyPath.setText(file.getPath()); + } + } + fileChooser.removeAllFilter(); + } + }); + } + + + private void changePane() { + contextPane.setVisible(usingSsh.isSelected()); + } + + private void changePaneForType() { + contextPane.removeAll(); + switch (typeMap.get(type.getSelectedItem())) { + case NORMAL: + TableLayoutHelper.addComponent2ResultPane(passwordComps, new double[]{p, p, p, p, p}, columnSize, contextPane); + break; + case KEY: + TableLayoutHelper.addComponent2ResultPane(keyComps, new double[]{p, p, p, p, p, p}, columnSize, contextPane); + break; + default: + throw new SshException("un support ssh type"); + } + jPanel.revalidate(); + jPanel.repaint(); + } + + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Basic_Ssh_Settings"); + } + + + public void populate(JDBCDatabaseConnection jdbcDatabase) { + if (jdbcDatabase.getSsh() == null) { + jdbcDatabase.setSsh(new NormalSsh()); + } + Ssh ssh = jdbcDatabase.getSsh(); + switch (ssh.getSshType()) { + case KEY: + type.setSelectedItem(typeMap.inverse().get(ssh.getSshType())); + KeyVerifySsh keyVerifySsh = (KeyVerifySsh) ssh; + keyPath.setText(keyVerifySsh.getPrivateKeyPath()); + secret.setText(keyVerifySsh.getSecret()); + password.setText(StringUtils.EMPTY); + setCommonConfig(keyVerifySsh); + break; + case NORMAL: + type.setSelectedItem(typeMap.inverse().get(ssh.getSshType())); + NormalSsh normalSsh = (NormalSsh) ssh; + password.setText(normalSsh.getSecret()); + keyPath.setText(StringUtils.EMPTY); + secret.setText(StringUtils.EMPTY); + setCommonConfig(normalSsh); + break; + default: + throw new SshException("un support ssh type"); + } + usingSsh.setSelected(ssh.isUsingSsh()); + changePane(); + } + + private void setCommonConfig(BaseSsh baseSsh) { + ip.setText(baseSsh.getIp()); + port.setValue(baseSsh.getPort()); + user.setText(baseSsh.getUser()); + } + + public void update(JDBCDatabaseConnection jdbcDatabase) { + Ssh ssh; + switch (typeMap.get(type.getSelectedItem())) { + case NORMAL: + NormalSsh normalSsh = new NormalSsh(); + normalSsh.setSecret(new String(password.getPassword()).trim()); + getCommonConfig(normalSsh); + ssh = normalSsh; + break; + case KEY: + KeyVerifySsh keyVerifySsh = new KeyVerifySsh(); + keyVerifySsh.setPrivateKeyPath(keyPath.getText().trim()); + keyVerifySsh.setSecret(new String(secret.getPassword()).trim()); + getCommonConfig(keyVerifySsh); + ssh = keyVerifySsh; + break; + default: + throw new SshException("un support ssh type"); + } + jdbcDatabase.setSsh(ssh); + } + + private void getCommonConfig(BaseSsh baseSsh) { + baseSsh.setUsingSsh(usingSsh.isSelected()); + baseSsh.setIp(ip.getText().trim()); + baseSsh.setPort(port.getValue()); + baseSsh.setUser(user.getText().trim()); + } + + public static class KeyFileUITextField extends UITextField { + private static final String PREFIX = ProjectConstants.RESOURCES_NAME + "/"; + private static final String UPPER = ".."; + + public KeyFileUITextField() { + super(); + this.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + String text = KeyFileUITextField.this.getText(); + if (text != null && text.contains(UPPER)) { + KeyFileUITextField.this.setText(text.replace(UPPER, ".")); + } + } + }); + } + + + @Override + public String getText() { + // 获取的时候,不为空,给他加上前缀就好了,否则还是空 + if (!StringUtils.isEmpty(super.getText())) { + return PREFIX + super.getText(); + } + return StringUtils.EMPTY; + } + + @Override + public void setText(String text) { + // 设置的时候,不为空,说明文件指定了(文件需要是resource下),替换掉前缀 + if (!StringUtils.isEmpty(text)) { + super.setText(text.replace(PREFIX, "")); + } + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/SslPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/SslPane.java new file mode 100644 index 000000000..1749e2efb --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/SslPane.java @@ -0,0 +1,170 @@ +package com.fr.design.data.datapane.connect; + +import com.fr.data.impl.JDBCDatabaseConnection; +import com.fr.data.security.ssl.Ssl; +import com.fr.data.security.ssl.SslException; +import com.fr.data.security.ssl.SslType; +import com.fr.data.security.ssl.SslUtils; +import com.fr.data.security.ssl.impl.NormalSsl; +import com.fr.design.border.UITitledBorder; +import com.fr.design.data.datapane.connect.SshPane.KeyFileUITextField; +import com.fr.design.dialog.BasicPane; +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.itextfield.UITextField; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.file.FILE; +import com.fr.file.FILEChooserPane; +import com.fr.file.filter.ChooseFileFilter; +import com.fr.stable.StringUtils; +import com.fr.stable.project.ProjectConstants; + +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import static com.fr.design.i18n.Toolkit.i18nText; + +/** + * @author xiqiu + * @date 2022/1/4 + * @description + */ +public class SslPane extends BasicPane { + UICheckBox usingSsl = new UICheckBox(i18nText("Fine-Design_Basic_Ssl_Using")); + private KeyFileUITextField keyPathCa = new KeyFileUITextField(); + private UIButton fileChooserButtonCa = new UIButton("..."); + private KeyFileUITextField keyPathClientCert = new KeyFileUITextField(); + private UIButton fileChooserButtonClientCert = new UIButton("..."); + private KeyFileUITextField keyPathClientKey = new KeyFileUITextField(); + private UIButton fileChooserButtonClientKey = new UIButton("..."); + private UICheckBox verifyCa = new UICheckBox(i18nText("Fine-Design_Basic_Ssl_Verify_Ca")); + private UITextField cipher = new UITextField(); + private JPanel jPanel; + private Component[][] usingComps; + private double p = TableLayout.PREFERRED; + private double f = TableLayout.FILL; + private JPanel contextPane; + private double[] columnSize = new double[]{208, p}; + + public SslPane() { + this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Basic_Ssl_Settings"))); + this.setLayout(FRGUIPaneFactory.createLabelFlowLayout()); + jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + Dimension dimension = new Dimension(20, 20); + int columns = 18; + keyPathCa.setColumns(columns); + fileChooserButtonCa.setPreferredSize(dimension); + keyPathClientCert.setColumns(columns); + fileChooserButtonClientCert.setPreferredSize(dimension); + fileChooserButtonClientKey.setPreferredSize(dimension); + keyPathClientKey.setColumns(columns); + JPanel filePanelCa = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + filePanelCa.add(keyPathCa); + filePanelCa.add(fileChooserButtonCa); + Component[] compCa = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Ca") + ":", SwingConstants.RIGHT), filePanelCa}; + Component[] compVerifyCa = {null, verifyCa}; + JPanel filePanelClientCert = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + filePanelClientCert.add(keyPathClientCert); + filePanelClientCert.add(fileChooserButtonClientCert); + Component[] compClientCert = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Client_Cert") + ":", SwingConstants.RIGHT), filePanelClientCert}; + JPanel filePanelClientKey = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + filePanelClientKey.add(keyPathClientKey); + filePanelClientKey.add(fileChooserButtonClientKey); + Component[] compClientKey = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Client_Key") + ":", SwingConstants.RIGHT), filePanelClientKey}; + Component[] comCipher = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Cipher") + ":", SwingConstants.RIGHT), cipher}; + usingComps = new Component[][]{ + compCa, + compVerifyCa, + compClientCert, + compClientKey, + comCipher + }; + usingSsl.setSelected(true); + contextPane = TableLayoutHelper.createGapTableLayoutPane(usingComps, new double[]{p, p, p, p, p, p}, columnSize, 11, 11); + jPanel.add(usingSsl, BorderLayout.NORTH); + jPanel.add(contextPane, BorderLayout.CENTER); + this.add(jPanel); + usingSsl.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + changePane(); + } + }); + fileChooserButtonCa.addActionListener(new TextFieldActionListener(keyPathCa)); + fileChooserButtonClientCert.addActionListener(new TextFieldActionListener(keyPathClientCert)); + fileChooserButtonClientKey.addActionListener(new TextFieldActionListener(keyPathClientKey)); + } + + private void changePane() { + contextPane.setVisible(usingSsl.isSelected()); + } + + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Basic_Ssl_Settings"); + } + + public void populate(JDBCDatabaseConnection jdbcDatabase) { + Ssl ssl = jdbcDatabase.getSsl(); + if (ssl == null) { + ssl = new NormalSsl(); + jdbcDatabase.setSsl(ssl); + } + if (ssl.getSslType() == SslType.NORMAL) { + NormalSsl normalSsl = (NormalSsl) ssl; + keyPathCa.setText(normalSsl.getCaCertificate()); + keyPathClientCert.setText(normalSsl.getClientCertificate()); + keyPathClientKey.setText(normalSsl.getClientPrivateKey()); + verifyCa.setSelected(normalSsl.isVerifyCa()); + cipher.setText(normalSsl.getCipher()); + } else { + throw new SslException("un support ssl type"); + } + usingSsl.setSelected(ssl.isUsingSsl()); + changePane(); + } + + public void update(JDBCDatabaseConnection jdbcDatabase) { + NormalSsl normalSsl = new NormalSsl(); + normalSsl.setCipher(cipher.getText().trim()); + normalSsl.setVerifyCa(verifyCa.isSelected()); + normalSsl.setCaCertificate(keyPathCa.getText().trim()); + normalSsl.setClientCertificate(keyPathClientCert.getText().trim()); + normalSsl.setClientPrivateKey(keyPathClientKey.getText().trim()); + normalSsl.setUsingSsl(usingSsl.isSelected()); + jdbcDatabase.setSsl(normalSsl); + } + + private class TextFieldActionListener implements ActionListener { + private UITextField textField; + + public TextFieldActionListener(UITextField textField) { + this.textField = textField; + } + + @Override + public void actionPerformed(ActionEvent e) { + FILEChooserPane fileChooser = FILEChooserPane.getInstanceWithDesignatePath(ProjectConstants.RESOURCES_NAME, new ChooseFileFilter(SslUtils.KEY_FILE_EXTENSION)); + int type = fileChooser.showOpenDialog(SslPane.this); + if (type == FILEChooserPane.OK_OPTION) { + final FILE file = fileChooser.getSelectedFILE(); + if (file == null) { + textField.setText(StringUtils.EMPTY); + } else { + textField.setText(file.getPath()); + } + } + fileChooser.removeAllFilter(); + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/editor/editor/NotNegativeIntegerEditor.java b/designer-base/src/main/java/com/fr/design/editor/editor/NotNegativeIntegerEditor.java new file mode 100644 index 000000000..7d24a2277 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/editor/editor/NotNegativeIntegerEditor.java @@ -0,0 +1,28 @@ +package com.fr.design.editor.editor; + +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; + +/** + * @author xiqiu + * @date 2022/1/10 + * @description 一个简单的非负整数框 + */ +public class NotNegativeIntegerEditor extends IntegerEditor { + private static final String NEG = "-"; + + public NotNegativeIntegerEditor() { + super(); + this.numberField.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent evt) { + char keyChar = evt.getKeyChar(); + if (NEG.equals(keyChar + "")) { + numberField.setText(numberField.getTextValue().replace(NEG, "")); + } + } + }); + } +} + diff --git a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java index 426fd18e2..2eeb27a5d 100644 --- a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java +++ b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java @@ -47,9 +47,9 @@ import com.fr.stable.StringUtils; import com.fr.stable.os.windows.WindowsDetector; import com.fr.stable.project.ProjectConstants; import com.fr.workspace.WorkContext; - import com.fr.workspace.Workspace; import com.fr.workspace.WorkspaceEvent; + import javax.swing.AbstractAction; import javax.swing.AbstractListModel; import javax.swing.ActionMap; @@ -202,6 +202,13 @@ public class FILEChooserPane extends BasicPane { return INSTANCE; } + public static FILEChooserPane getInstanceWithDesignatePath(String path, FILEFilter filter) { + INSTANCE.setDesignateModel(path); + INSTANCE.removeAllFilter(); + INSTANCE.addChooseFILEFilter(filter, 0); + return INSTANCE; + } + public static FILEChooserPane getMultiEnvInstance(boolean showLoc, boolean showWebReport) { INSTANCE.showEnv = true; INSTANCE.showLoc = showLoc; @@ -499,7 +506,7 @@ public class FILEChooserPane extends BasicPane { } private String calProperFileName(String fileName, ChooseFileFilter fileFilter) { - if(fileFilter == null){ + if (fileFilter == null) { return fileName; } String filterExtension = fileFilter.getExtensionString(); @@ -516,10 +523,10 @@ public class FILEChooserPane extends BasicPane { return fileNameWithOutExtension + filterExtension; } - private boolean isMapping(String fromExtension, String toExtension){ - if(FileExtension.CPTX.matchExtension(fromExtension)){ + private boolean isMapping(String fromExtension, String toExtension) { + if (FileExtension.CPTX.matchExtension(fromExtension)) { return FileExtension.CPT.matchExtension(toExtension); - }else if(FileExtension.CPT.matchExtension(fromExtension)){ + } else if (FileExtension.CPT.matchExtension(fromExtension)) { return FileExtension.CPTX.matchExtension(toExtension); } return false; @@ -678,7 +685,7 @@ public class FILEChooserPane extends BasicPane { * 移除文件后缀的方法 * 解决cptx文件的另存为操作默认会出现双后缀的bug(xxx.cptx.cpt) **/ - private String removeSuffix(String text){ + private String removeSuffix(String text) { return FileExtension.CPTX.matchExtension(text) ? text.substring(0, text.length() - FileExtension.CPTX.getSuffix().length()) : text; } @@ -783,7 +790,7 @@ public class FILEChooserPane extends BasicPane { ChooseFileFilter supportedTypes = new ChooseFileFilter(FRContext.getFileNodes().getSupportedTypes(), appName + Toolkit.i18nText("Fine-Design_Report_Template_File")); Set providers = ExtraReportClassManager.getInstance().getArray(ReportSupportedFileProvider.XML_TAG); for (ReportSupportedFileProvider provider : providers) { - for (FileExtension fileExtension : provider.getFileExtensions()){ + for (FileExtension fileExtension : provider.getFileExtensions()) { supportedTypes.addExtension(fileExtension.getExtension()); } } @@ -915,7 +922,7 @@ public class FILEChooserPane extends BasicPane { if (access(selectedFile) && access(currentDirectory)) { if (selectedFile.exists()) { int selVal = FineJOptionPane.showConfirmDialog(dialog, Toolkit.i18nText("Fine-Design_Basic_Utils_Would_You_Like_To_Cover_The_Current_File") + " ?", - Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (selVal == JOptionPane.YES_OPTION) { option = JOPTIONPANE_OK_OPTION; saveDictionary(); @@ -1031,6 +1038,14 @@ public class FILEChooserPane extends BasicPane { setPlaceListModel(new PlaceListModel()); } + private void setDesignateModel(String path) { + if (placesList == null) { + return; + } + setPlaceListModel(new DesignateRemotePlaceListModel(path)); + } + + private void setMultiPlaceListModel() { if (placesList == null) { return; @@ -1125,6 +1140,7 @@ public class FILEChooserPane extends BasicPane { private abstract class AbstractPlaceListModel extends AbstractListModel { + private static final long serialVersionUID = 8473695327688235386L; protected List filesOfSystem = new ArrayList(); protected void processSystemFile() { @@ -1157,7 +1173,8 @@ public class FILEChooserPane extends BasicPane { protected void setCD(final FILE lastDirectory) { for (int i = 0; i < this.getSize(); i++) { FILE file = this.getElementAt(i); - if (ComparatorUtils.equals(lastDirectory.prefix(), file.prefix())) { + //前缀相同不代表能用啊,比如说 repolets 和 resource ,都是 env下的,但就不该去显示resource下的文件呀 + if (ComparatorUtils.equals(lastDirectory.prefix(), file.prefix()) && lastDirectory.getPath() != null && lastDirectory.getPath().startsWith(file.getPath())) { setCurrentDirectory(lastDirectory); return; } @@ -1166,7 +1183,60 @@ public class FILEChooserPane extends BasicPane { } } + /** + * 一个简单的指定远程目录的 placelistmodel + */ + private class DesignateRemotePlaceListModel extends AbstractPlaceListModel { + private static final long serialVersionUID = -6340666958714469249L; + + private FileNodeFILE envFILE; + + public DesignateRemotePlaceListModel(String path) { + envFILE = new DesignateFileNodeFILE(new FileNode(path, true)) { + @Override + public String getName() { + return Toolkit.i18nText("Fine-Design_Basic_Utils_Report_Env_Directory_Designate"); + } + }; + } + + @Override + public FILE getElementAt(int index) { + if (index < 1) { + return envFILE; + } + throw new IndexOutOfBoundsException(); + } + + @Override + public int getSize() { + return 1; + } + + @Override + protected void setCD(FILE lastDirectory) { + setCurrentDirectory(envFILE); + } + + /** + * 简单的重写了标签的FileNodeFILE + */ + private class DesignateFileNodeFILE extends FileNodeFILE { + + public DesignateFileNodeFILE(FileNode node) { + super(node); + } + + @Override + public Icon getIcon() { + return BaseUtils.readIcon("/com/fr/base/images/oem/logo.png"); + } + } + } + + private class PlaceListModel extends AbstractPlaceListModel { + private static final long serialVersionUID = 6138969918807381364L; private FileNodeFILE envFILE; private FileNodeFILE webReportFILE; @@ -1217,6 +1287,7 @@ public class FILEChooserPane extends BasicPane { private class MultiLocalEnvPlaceListModel extends AbstractPlaceListModel { + private static final long serialVersionUID = 6300018896958532154L; private List envFiles = new ArrayList(); private FileNodeFILE webReportFILE;