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.migration.oldinst;
025:
026: import java.awt.Frame;
027: import java.awt.event.ActionEvent;
028: import java.io.File;
029: import javax.swing.JButton;
030: import javax.swing.JComponent;
031: import javax.swing.JFileChooser;
032: import javax.swing.JLabel;
033: import javax.swing.JPanel;
034: import javax.swing.JTextField;
035: import org.dlib.gui.FlexLayout;
036: import org.dlib.gui.GuiUtil;
037: import org.dlib.gui.ProgressDialog;
038: import org.fao.gast.gui.panels.FormPanel;
039:
040: //==============================================================================
041:
042: public class MainPanel extends FormPanel {
043: //---------------------------------------------------------------------------
044: //---
045: //--- Constructor
046: //---
047: //---------------------------------------------------------------------------
048:
049: public MainPanel() {
050: jfcBrowser.setDialogTitle("Choose input folder");
051: jfcBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
052: }
053:
054: //---------------------------------------------------------------------------
055: //---
056: //--- ActionListener
057: //---
058: //---------------------------------------------------------------------------
059:
060: public void actionPerformed(ActionEvent e) {
061: String cmd = e.getActionCommand();
062:
063: if (cmd.equals("browse"))
064: browse();
065:
066: else if (cmd.equals("migrate"))
067: migrate();
068: }
069:
070: //---------------------------------------------------------------------------
071:
072: private void browse() {
073: jfcBrowser.setSelectedFile(new File(txtOldDir.getText()));
074:
075: int res = jfcBrowser.showDialog(this , "Choose");
076:
077: if (res == JFileChooser.APPROVE_OPTION)
078: txtOldDir.setText(jfcBrowser.getSelectedFile()
079: .getAbsolutePath());
080: }
081:
082: //---------------------------------------------------------------------------
083:
084: private void migrate() {
085: Frame owner = GuiUtil.getFrame(this );
086: ProgressDialog dialog = new ProgressDialog(owner,
087: "Migrating data");
088: Worker worker = new Worker(dialog);
089:
090: worker.setOldDir(txtOldDir.getText());
091: dialog.run(worker);
092: }
093:
094: //---------------------------------------------------------------------------
095: //---
096: //--- Protected methods
097: //---
098: //---------------------------------------------------------------------------
099:
100: protected JComponent buildInnerPanel() {
101: JPanel p = new JPanel();
102:
103: FlexLayout fl = new FlexLayout(3, 1);
104: fl.setColProp(1, FlexLayout.EXPAND);
105: p.setLayout(fl);
106:
107: p.add("0,0", new JLabel("Old GeoNetwork"));
108: p.add("1,0,x", txtOldDir);
109: p.add("2,0", btnBrowse);
110:
111: btnBrowse.addActionListener(this );
112: btnBrowse.setActionCommand("browse");
113:
114: return p;
115: }
116:
117: //---------------------------------------------------------------------------
118: //---
119: //--- Variables
120: //---
121: //---------------------------------------------------------------------------
122:
123: private JTextField txtOldDir = new JTextField(20);
124: private JButton btnBrowse = new JButton("Browse");
125: private JFileChooser jfcBrowser = new JFileChooser();
126: }
127:
128: //==============================================================================
|