@@ -51,8 +51,8 @@ public class CreateBsimServerInfoDialog extends DialogComponentProvider {
5151
5252 private JPanel cardPanel ;
5353
54- private PostgresPanel postgresPanel ;
55- private ElasticPanel elasticPanel ;
54+ private DbPanel postgresPanel ;
55+ private DbPanel elasticPanel ;
5656 private FilePanel filePanel ;
5757
5858 private ServerPanel activePanel ;
@@ -65,12 +65,13 @@ public CreateBsimServerInfoDialog() {
6565 addOKButton ();
6666 addCancelButton ();
6767 setOkEnabled (false );
68- setHelpLocation (new HelpLocation ("BSimSearchPlugin" ,"Add_Server_Definition_Dialog" ));
68+ setHelpLocation (new HelpLocation ("BSimSearchPlugin" , "Add_Server_Definition_Dialog" ));
6969 }
7070
7171 public BSimServerInfo getBsimServerInfo () {
7272 return result ;
7373 }
74+
7475 @ Override
7576 public void setHelpLocation (HelpLocation helpLocation ) {
7677 // TODO Auto-generated method stub
@@ -101,7 +102,8 @@ public boolean acceptServer(BSimServerInfo serverInfo) {
101102 errorMessage = e .getMessage ();
102103 }
103104 int answer = OptionDialog .showYesNoDialog (null , "Connection Test Failed!" ,
104- "Can't connect to server: " + errorMessage + "\n Do you want to proceed with creation anyway?" );
105+ "Can't connect to server: " + errorMessage +
106+ "\n Do you want to proceed with creation anyway?" );
105107 return answer == OptionDialog .YES_OPTION ;
106108 }
107109
@@ -113,8 +115,8 @@ private JComponent buildMainPanel() {
113115 }
114116
115117 private Component buildCardPanel () {
116- postgresPanel = new PostgresPanel ( );
117- elasticPanel = new ElasticPanel ( );
118+ postgresPanel = new DbPanel ( DBType . postgres );
119+ elasticPanel = new DbPanel ( DBType . elastic );
118120 filePanel = new FilePanel ();
119121
120122 cardPanel = new JPanel (new CardLayout ());
@@ -193,55 +195,33 @@ private void checkForValidDialog() {
193195 setOkEnabled (serverInfo != null );
194196 }
195197
196- private class PostgresPanel extends ServerPanel {
197-
198+ private class DbPanel extends ServerPanel {
198199 private JTextField nameField ;
199200 private JTextField hostField ;
200201 private JTextField portField ;
202+ private DBType type ;
201203
202- PostgresPanel ( ) {
204+ private DbPanel ( DBType type ) {
203205 super (new PairLayout (10 , 10 ));
206+ this .type = type ;
207+
204208 nameField = new NotifyingTextField ();
205209 hostField = new NotifyingTextField ();
206210 portField =
207211 new NotifyingTextField (Integer .toString (BSimServerInfo .DEFAULT_POSTGRES_PORT ));
208- add (new JLabel ("DB Name:" , SwingConstants .RIGHT ));
209- add (nameField );
210- add (new JLabel ("Host:" , SwingConstants .RIGHT ));
211- add (hostField );
212- add (new JLabel ("Port:" , SwingConstants .RIGHT ));
213- add (portField );
214- }
215212
216- @ Override
217- BSimServerInfo getServerInfo () {
218- String name = nameField .getText ().trim ();
219- String host = hostField .getText ().trim ();
220- int port = getPort (portField .getText ().trim ());
221- if (name .isBlank () || host .isBlank () || port < 0 ) {
222- return null ;
223- }
224- return new BSimServerInfo (DBType .postgres , host , port , name );
225- }
226- }
227-
228- private class ElasticPanel extends ServerPanel {
213+ JLabel nameLabel = new JLabel ("DB Name:" , SwingConstants .RIGHT );
214+ JLabel hostLabel = new JLabel ("Host:" , SwingConstants .RIGHT );
215+ JLabel portLabel = new JLabel ("Port:" , SwingConstants .RIGHT );
216+ nameLabel .setLabelFor (nameField );
217+ hostLabel .setLabelFor (hostField );
218+ portLabel .setLabelFor (portField );
229219
230- private JTextField nameField ;
231- private JTextField hostField ;
232- private JTextField portField ;
233-
234- ElasticPanel () {
235- super (new PairLayout (10 , 10 ));
236- nameField = new NotifyingTextField ();
237- hostField = new NotifyingTextField ();
238- portField =
239- new NotifyingTextField (Integer .toString (BSimServerInfo .DEFAULT_ELASTIC_PORT ));
240- add (new JLabel ("DB Name:" , SwingConstants .RIGHT ));
220+ add (nameLabel );
241221 add (nameField );
242- add (new JLabel ( "Host:" , SwingConstants . RIGHT ) );
222+ add (hostLabel );
243223 add (hostField );
244- add (new JLabel ( "Port:" , SwingConstants . RIGHT ) );
224+ add (portLabel );
245225 add (portField );
246226 }
247227
@@ -253,9 +233,8 @@ BSimServerInfo getServerInfo() {
253233 if (name .isBlank () || host .isBlank () || port < 0 ) {
254234 return null ;
255235 }
256- return new BSimServerInfo (DBType . elastic , host , port , name );
236+ return new BSimServerInfo (type , host , port , name );
257237 }
258-
259238 }
260239
261240 private class FilePanel extends ServerPanel {
0 commit comments