View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.database;
17  
18  import javax.swing.JPasswordField;
19  import javax.swing.JTextField;
20  
21  import org.jamesii.core.data.DBConnectionData;
22  import org.jamesii.core.util.misc.Pair;
23  
24  import p3j.gui.panels.PropertiesShowPanelFactory;
25  import p3j.misc.Misc;
26  
27  /**
28   * Created on 28.10.2012
29   * 
30   * @author Christina Bohk
31   * @author Roland Ewald
32   */
33  public class GenericPreferencesUIProvider implements IPreferencesUIProvider {
34  
35    final JTextField dbURL = new JTextField();
36  
37    final JTextField dbUserName = new JTextField();
38  
39    final JTextField dbPassword = new JPasswordField();
40  
41    final JTextField jdbcDriver = new JTextField();
42  
43    final JTextField dialect = new JTextField();
44  
45    @Override
46    public int getHeight() {
47      return 110;
48    }
49  
50    @Override
51    public void addUIElements(PropertiesShowPanelFactory pspf,
52        Pair<DBConnectionData, String> connData) {
53      setDBPreferences(connData);
54      pspf.app(Misc.PREF_DB_URL + ":", dbURL);
55      pspf.app(Misc.PREF_DB_USER + ":", dbUserName);
56      pspf.app(Misc.PREF_DB_PWD + ":", dbPassword);
57      pspf.app(Misc.GUI_LABEL_DB_DRIVER_CLASS + ":", jdbcDriver);
58      pspf.app(Misc.GUI_LABEL_HIBERNATE_DIALECT + ":", dialect);
59    }
60  
61    @Override
62    public Pair<DBConnectionData, String> getDBPreferences() {
63      return new Pair<>(new DBConnectionData(dbURL.getText(),
64          dbUserName.getText(), dbPassword.getText(), jdbcDriver.getText()),
65          dialect.getText());
66    }
67  
68    @Override
69    public void setDBPreferences(Pair<DBConnectionData, String> connData) {
70      dbURL.setText(connData.getFirstValue().getURL());
71      dbUserName.setText(connData.getFirstValue().getUser());
72      dbPassword.setText(connData.getFirstValue().getPassword());
73      jdbcDriver.setText(connData.getFirstValue().getDriver());
74      dialect.setText(connData.getSecondValue());
75    }
76  
77  }