1 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 33 public class TranslationDialog extends CPanel 34 implements FormPanel, ActionListener 35 { 36 40 public TranslationDialog() 41 { 42 } 44 45 private int m_WindowNo = 0; 46 47 private FormFrame m_frame; 48 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 private StatusBar statusBar = new StatusBar(); 58 private JLabel lClient = new JLabel(); 59 private JComboBox cbClient = new JComboBox(); 60 61 62 66 private void jbInit() throws Exception 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 bExport.setText(Msg.getMsg(Env.getCtx(), "Export")); 75 bExport.addActionListener(this); 76 bImport.setText(Msg.getMsg(Env.getCtx(), "Import")); 77 bImport.addActionListener(this); 78 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 } 97 101 private void dynInit() 102 { 103 cbClient.addItem(new KeyNamePair (-1, "")); 105 String 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 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 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 statusBar.setStatusLine(" "); 173 statusBar.setStatusDB(" "); 174 } 176 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 ex) 195 { 196 Log.error("TranslationDialog.init", ex); 197 } 198 } 200 203 public void dispose() 204 { 205 m_frame.dispose(); 206 } 208 209 210 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 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 directory = chooser.getSelectedFile().getAbsolutePath(); 239 statusBar.setStatusLine(directory); 241 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 242 Translation t = new Translation(); 243 String 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 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 { 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 this.setCursor(Cursor.getDefaultCursor()); 274 } 276 } | Popular Tags |