View Javadoc
1   /*******************************************************************************
2    * Copyhacked (H) 2012-2020.
3    * This program and the accompanying materials
4    * are made available under no term at all, use it like
5    * you want, but share and discuss about it
6    * every time possible with every body.
7    * 
8    * Contributors:
9    *      ron190 at ymail dot com - initial implementation
10   ******************************************************************************/
11  package com.jsql.view.swing.manager;
12  
13  import com.jsql.model.exception.JSqlException;
14  import com.jsql.util.I18nUtil;
15  import com.jsql.view.swing.text.JPopupTextField;
16  import com.jsql.view.swing.util.MediatorHelper;
17  import com.jsql.view.swing.util.UiUtil;
18  
19  import javax.swing.*;
20  import java.awt.*;
21  
22  /**
23   * Manager for uploading PHP SQL shell to the host and send queries.
24   */
25  public class ManagerSqlShell extends AbstractManagerShell {
26      
27      private final JTextField username = new JPopupTextField(I18nUtil.valueByKey("SQL_SHELL_USERNAME_LABEL")).getProxy();
28      private final JTextField password = new JPopupTextField(I18nUtil.valueByKey("SQL_SHELL_PASSWORD_LABEL")).getProxy();
29      
30      /**
31       * Build the manager panel.
32       */
33      public ManagerSqlShell() {
34  
35          this.run.setText("Create SQL shell(s)");
36          
37          var userPassPanel = new JPanel();
38          
39          var layout = new GroupLayout(userPassPanel);
40          userPassPanel.setLayout(layout);
41          userPassPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
42          userPassPanel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
43          
44          this.username.setToolTipText(I18nUtil.valueByKey("SQL_SHELL_USERNAME_TOOLTIP"));
45          this.password.setToolTipText(I18nUtil.valueByKey("SQL_SHELL_PASSWORD_TOOLTIP"));
46          
47          this.username.setBorder(UiUtil.BORDER_BLU);
48          this.password.setBorder(UiUtil.BORDER_BLU);
49          
50          var panelPassword = new JPanel(new BorderLayout());
51          panelPassword.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));
52          panelPassword.add(this.password);
53          
54          layout.setHorizontalGroup(
55              layout
56              .createSequentialGroup()
57              .addGroup(
58                  layout
59                  .createParallelGroup(GroupLayout.Alignment.TRAILING, false)
60              )
61              .addGroup(
62                  layout.createParallelGroup()
63                  .addComponent(this.username)
64                  .addComponent(panelPassword)
65              )
66          );
67  
68          layout.setVerticalGroup(
69              layout
70              .createSequentialGroup()
71              .addGroup(
72                  layout
73                  .createParallelGroup(GroupLayout.Alignment.BASELINE)
74                  .addComponent(this.username)
75              )
76              .addGroup(
77                  layout
78                  .createParallelGroup(GroupLayout.Alignment.BASELINE)
79                  .addComponent(panelPassword)
80              )
81          );
82          
83          this.add(userPassPanel, BorderLayout.NORTH);
84      }
85  
86      @Override
87      protected void createPayload(String shellPath, String shellURL) throws JSqlException {
88          MediatorHelper.model().getResourceAccess().createSqlShell(shellPath, shellURL, this.username.getText(), this.password.getText());
89      }
90  }