KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > install > TranslationDialog


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.install;
15
16 import java.awt.*;
17 import javax.swing.*;
18 import java.awt.event.*;
19 import java.sql.*;
20 import java.io.*;
21
22 import org.compiere.util.*;
23 import org.compiere.swing.*;
24 import org.compiere.apps.*;
25 import org.compiere.apps.form.*;
26
27 /**
28  * Translation Dialog Import + Export.
29  *
30  * @author Jorg Janke
31  * @version $Id: TranslationDialog.java,v 1.5 2003/10/09 15:01:44 jjanke Exp $
32  */

33 public class TranslationDialog extends CPanel
34     implements FormPanel, ActionListener
35 {
36     /**
37      * TranslationDialog Constructor.
38      * (Initiated via init())
39      */

40     public TranslationDialog()
41     {
42     } // TranslationDialog
43

44     /** Window No */
45     private int m_WindowNo = 0;
46     /** FormFrame */
47     private FormFrame m_frame;
48     //
49
private GridBagLayout mainLayout = new GridBagLayout();
50     private JComboBox cbLanguage = new JComboBox();
51     private JLabel lLanguage = new JLabel();
52     private JLabel lTable = new JLabel();
53     private JComboBox cbTable = new JComboBox();
54     private JButton bExport = new JButton();
55     private JButton bImport = new JButton();
56     //
57
private StatusBar statusBar = new StatusBar();
58     private JLabel lClient = new JLabel();
59     private JComboBox cbClient = new JComboBox();
60
61
62     /**
63      * Static Init
64      * @throws Exception
65      */

66     private void jbInit() throws Exception JavaDoc
67     {
68         this.setLayout(mainLayout);
69         lClient.setText(Msg.translate(Env.getCtx(), "AD_Client_ID"));
70         lLanguage.setText(Msg.translate(Env.getCtx(), "AD_Language"));
71         lLanguage.setToolTipText(Msg.translate(Env.getCtx(), "IsSystemLanguage"));
72         lTable.setText(Msg.translate(Env.getCtx(), "AD_Table_ID"));
73         //
74
bExport.setText(Msg.getMsg(Env.getCtx(), "Export"));
75         bExport.addActionListener(this);
76         bImport.setText(Msg.getMsg(Env.getCtx(), "Import"));
77         bImport.addActionListener(this);
78         //
79
this.add(cbLanguage, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
80             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
81         this.add(lLanguage, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
82             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
83         this.add(lTable, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
84             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
85         this.add(cbTable, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
86             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
87         this.add(bExport, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
88             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
89         this.add(bImport, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
90             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
91         this.add(lClient, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
92             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
93         this.add(cbClient, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
94             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
95     } // jbInit
96

97     /**
98      * Dynamic Init.
99      * - fill Language & Table
100      */

101     private void dynInit()
102     {
103         // Fill Client
104
cbClient.addItem(new KeyNamePair (-1, ""));
105         String JavaDoc sql = "SELECT Name, AD_Client_ID "
106             + "FROM AD_Client "
107             + "WHERE IsActive='Y' "
108             + "ORDER BY 2";
109         try
110         {
111             PreparedStatement pstmt = DB.prepareStatement(sql);
112             ResultSet rs = pstmt.executeQuery();
113             while (rs.next())
114             {
115                 KeyNamePair kp = new KeyNamePair (rs.getInt(2), rs.getString(1));
116                 cbClient.addItem(kp);
117             }
118             rs.close();
119             pstmt.close();
120         }
121         catch (SQLException e)
122         {
123             Log.error("TranslationDialog.dynInit (Client)", e);
124         }
125
126         // Fill Language
127
sql = "SELECT Name, AD_Language "
128             + "FROM AD_Language "
129             + "WHERE IsActive='Y' AND IsSystemLanguage='Y' "
130             + "ORDER BY 1";
131         try
132         {
133             PreparedStatement pstmt = DB.prepareStatement(sql);
134             ResultSet rs = pstmt.executeQuery();
135             while (rs.next())
136             {
137                 ValueNamePair vp = new ValueNamePair (rs.getString(2), rs.getString(1));
138                 cbLanguage.addItem(vp);
139             }
140             rs.close();
141             pstmt.close();
142         }
143         catch (SQLException e)
144         {
145             Log.error("TranslationDialog.dynInit (Language)", e);
146         }
147
148         // Fill Table
149
cbTable.addItem(new ValueNamePair ("", ""));
150         sql = "SELECT Name, TableName "
151             + "FROM AD_Table "
152             + "WHERE TableName LIKE '%_Trl' "
153             + "ORDER BY 1";
154         try
155         {
156             PreparedStatement pstmt = DB.prepareStatement(sql);
157             ResultSet rs = pstmt.executeQuery();
158             while (rs.next())
159             {
160                 ValueNamePair vp = new ValueNamePair (rs.getString(2), rs.getString(1));
161                 cbTable.addItem(vp);
162             }
163             rs.close();
164             pstmt.close();
165         }
166         catch (SQLException e)
167         {
168             Log.error("TranslationDialog.dynInit (Table)", e);
169         }
170
171         // Info
172
statusBar.setStatusLine(" ");
173         statusBar.setStatusDB(" ");
174     } // dynInit
175

176     /**
177      * Initialize Panel
178      * @param WindowNo window
179      * @param frame frame
180      */

181     public void init (int WindowNo, FormFrame frame)
182     {
183         Log.trace(Log.l1_User, "TranslationDialog.init");
184         m_WindowNo = WindowNo;
185         m_frame = frame;
186         Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "Y");
187         try
188         {
189             jbInit();
190             dynInit();
191             frame.getContentPane().add(this, BorderLayout.CENTER);
192             frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
193         }
194         catch(Exception JavaDoc ex)
195         {
196             Log.error("TranslationDialog.init", ex);
197         }
198     } // init
199

200     /**
201      * Dispose
202      */

203     public void dispose()
204     {
205         m_frame.dispose();
206     } // dispose
207

208     /*************************************************************************/
209
210     /**
211      * Action Listener
212      * @param e event
213      */

214     public void actionPerformed(ActionEvent e)
215     {
216         ValueNamePair AD_Language = (ValueNamePair)cbLanguage.getSelectedItem();
217         if (AD_Language == null)
218         {
219             statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "LanguageSetupError"), true);
220             return;
221         }
222         ValueNamePair AD_Table = (ValueNamePair)cbTable.getSelectedItem();
223         if (AD_Table == null)
224             return;
225         boolean imp = (e.getSource() == bImport);
226         KeyNamePair AD_Client = (KeyNamePair)cbClient.getSelectedItem();
227         int AD_Client_ID = -1;
228         if (AD_Client != null)
229             AD_Client_ID = AD_Client.getKey();
230
231         String JavaDoc startDir = Ini.getCompiereHome() + File.separator + "data";
232         JFileChooser chooser = new JFileChooser(startDir);
233         chooser.setMultiSelectionEnabled(false);
234         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
235         int returnVal = imp ? chooser.showOpenDialog(this) : chooser.showSaveDialog(this);
236         if (returnVal != JFileChooser.APPROVE_OPTION)
237             return;
238         String JavaDoc directory = chooser.getSelectedFile().getAbsolutePath();
239         //
240
statusBar.setStatusLine(directory);
241         this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
242         Translation t = new Translation();
243         String JavaDoc msg = t.validateLanguage(AD_Language.getValue());
244         if (msg.length() > 0)
245         {
246             ADialog.error(m_WindowNo, this, "LanguageSetupError", msg);
247             return;
248         }
249
250         // All Tables
251
if (AD_Table.getValue().equals(""))
252         {
253             for (int i = 1; i < cbTable.getItemCount(); i++)
254             {
255                 AD_Table = (ValueNamePair)cbTable.getItemAt(i);
256                 msg = null;
257                 msg = imp
258                     ? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue())
259                     : t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue());
260                 statusBar.setStatusLine(msg);
261             }
262             statusBar.setStatusLine(directory);
263         }
264         else // single table
265
{
266             msg = null;
267             msg = imp
268                 ? t.importTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue())
269                 : t.exportTrl (directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue());
270             statusBar.setStatusLine(msg);
271         }
272         //
273
this.setCursor(Cursor.getDefaultCursor());
274     } // actionPerformed
275

276 } // Translation
Popular Tags