001: //==============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.gast.gui.panels.config.dbms;
025:
026: import javax.swing.JLabel;
027: import javax.swing.JTextField;
028: import org.dlib.gui.FlexLayout;
029: import org.fao.gast.lib.Lib;
030:
031: //==============================================================================
032:
033: public class EmbeddedPanel extends DbmsPanel {
034: //---------------------------------------------------------------------------
035: //---
036: //--- Constructor
037: //---
038: //---------------------------------------------------------------------------
039:
040: public EmbeddedPanel() {
041: FlexLayout fl = new FlexLayout(3, 1);
042: fl.setColProp(1, FlexLayout.EXPAND);
043: setLayout(fl);
044:
045: add("0,0", new JLabel("Port"));
046: add("1,0", txtPort);
047: add("2,0", new JLabel("<html><font color='red'>(REQ)</font>"));
048:
049: txtPort.setText("9157");
050: txtPort.setToolTipText("The default port is 9157");
051: }
052:
053: //---------------------------------------------------------------------------
054: //---
055: //--- DbmsPanel methods
056: //---
057: //---------------------------------------------------------------------------
058:
059: public String getLabel() {
060: return "Embedded";
061: }
062:
063: //---------------------------------------------------------------------------
064:
065: public boolean matches(String url) {
066: return url.startsWith("jdbc:mckoi:");
067: }
068:
069: //---------------------------------------------------------------------------
070:
071: public void retrieve() {
072: txtPort.setText(Lib.embeddedDB.getPort());
073: }
074:
075: //---------------------------------------------------------------------------
076:
077: public void save() throws Exception {
078: String port = txtPort.getText();
079: String user = Lib.embeddedDB.getUser();
080: String pass = Lib.embeddedDB.getPassword();
081:
082: if (!Lib.type.isInteger(port))
083: throw new Exception("The port must be an integer");
084:
085: Lib.config.setDbmsDriver("com.mckoi.JDBCDriver");
086: Lib.config.setDbmsURL("jdbc:mckoi://localhost:" + port + "/");
087: Lib.config.setDbmsUser(user);
088: Lib.config.setDbmsPassword(pass);
089: Lib.config.addActivator();
090: Lib.config.save();
091:
092: Lib.embeddedDB.setPort(port);
093: Lib.embeddedDB.save();
094: }
095:
096: //---------------------------------------------------------------------------
097: //---
098: //--- Variables
099: //---
100: //---------------------------------------------------------------------------
101:
102: private JTextField txtPort = new JTextField(6);
103: }
104:
105: //==============================================================================
|