001: package net.sourceforge.squirrel_sql.fw.gui.action;
002:
003: import net.sourceforge.squirrel_sql.fw.util.StringManager;
004: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
005: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
006: import net.sourceforge.squirrel_sql.fw.resources.LibraryResources;
007:
008: import javax.swing.*;
009: import java.awt.*;
010: import java.nio.charset.Charset;
011:
012: public class TableExportCsvDlg extends JDialog {
013: private static final StringManager s_stringMgr = StringManagerFactory
014: .getStringManager(TableExportCsvDlg.class);
015:
016: JTextField txtFile;
017: JButton btnFile;
018: JCheckBox chkWithHeaders;
019: JRadioButton radFormatXLS;
020: JRadioButton radFormatCSV;
021: JLabel lblSeparator;
022: JLabel lblCharset;
023: JTextField txtSeparatorChar;
024: JCheckBox chkSeparatorTab;
025: JRadioButton radComplete;
026: JRadioButton radSelection;
027: JRadioButton radUseGlobalPrefsFormating;
028: JRadioButton radUseDefaultFormating;
029: JCheckBox chkExecCommand;
030: JTextField txtCommand;
031: JButton btnCommandFile;
032: JButton btnOk;
033: JButton btnCancel;
034: JComboBox charsets;
035:
036: public TableExportCsvDlg() {
037: super (GUIUtils.getMainFrame(), true);
038:
039: // i18n[TableExportCSVDlg.exportTitleNew=CSV / MS Excel export]
040: setTitle(s_stringMgr
041: .getString("TableExportCSVDlg.exportTitleNew"));
042:
043: getContentPane().setLayout(new GridBagLayout());
044: GridBagConstraints gbc;
045:
046: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
047: GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
048: new Insets(5, 5, 5, 5), 0, 0);
049: // i18n[TableExportCsvDlg.exportCsvFile=Export to file:]
050: getContentPane().add(
051: new JLabel(s_stringMgr
052: .getString("TableExportCsvDlg.exportCsvFile")),
053: gbc);
054:
055: gbc = new GridBagConstraints(0, 2, 1, 1, 0, 0,
056: GridBagConstraints.NORTHWEST,
057: GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5),
058: 0, 0);
059: getContentPane().add(getFilePanel(), gbc);
060:
061: // i18n[TableExportCsvDlg.withHeaders=Include column headers]
062: chkWithHeaders = new JCheckBox(s_stringMgr
063: .getString("TableExportCsvDlg.withHeaders"));
064: gbc = new GridBagConstraints(0, 3, 1, 1, 0, 0,
065: GridBagConstraints.NORTHWEST,
066: GridBagConstraints.HORIZONTAL, new Insets(15, 5, 5, 5),
067: 0, 0);
068: getContentPane().add(chkWithHeaders, gbc);
069:
070: gbc = new GridBagConstraints(0, 4, 1, 1, 0, 0,
071: GridBagConstraints.NORTHWEST,
072: GridBagConstraints.HORIZONTAL, new Insets(15, 5, 5, 5),
073: 0, 0);
074: getContentPane().add(getExportFormatPanel(), gbc);
075:
076: gbc = new GridBagConstraints(0, 5, 1, 1, 0, 0,
077: GridBagConstraints.NORTHWEST,
078: GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
079: 0, 0);
080: getContentPane().add(getSeparatorPanel(), gbc);
081:
082: gbc = new GridBagConstraints(0, 6, 1, 1, 0, 0,
083: GridBagConstraints.NORTHWEST,
084: GridBagConstraints.HORIZONTAL, new Insets(15, 5, 5, 5),
085: 0, 0);
086: getContentPane().add(getSelelectionPanel(), gbc);
087:
088: gbc = new GridBagConstraints(0, 7, 1, 1, 0, 0,
089: GridBagConstraints.NORTHWEST,
090: GridBagConstraints.HORIZONTAL, new Insets(15, 5, 5, 5),
091: 0, 0);
092: getContentPane().add(getFormatingPanel(), gbc);
093:
094: // i18n[TableExportCsvDlg.executeCommand=Execute command (%file will be replaced by export file name)]
095: chkExecCommand = new JCheckBox(s_stringMgr
096: .getString("TableExportCsvDlg.executeCommand"));
097: gbc = new GridBagConstraints(0, 8, 1, 1, 0, 0,
098: GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
099: new Insets(15, 5, 5, 5), 0, 0);
100: getContentPane().add(chkExecCommand, gbc);
101:
102: gbc = new GridBagConstraints(0, 9, 1, 1, 0, 0,
103: GridBagConstraints.NORTHWEST,
104: GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5),
105: 0, 0);
106: getContentPane().add(getCommandPanel(), gbc);
107:
108: gbc = new GridBagConstraints(0, 10, 1, 1, 0, 0,
109: GridBagConstraints.NORTHWEST,
110: GridBagConstraints.HORIZONTAL, new Insets(15, 5, 5, 5),
111: 0, 0);
112: getContentPane().add(getButtonPanel(), gbc);
113:
114: gbc = new GridBagConstraints(0, 11, 1, 1, 1, 1,
115: GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
116: new Insets(5, 5, 5, 5), 0, 0);
117: getContentPane().add(new JPanel(), gbc);
118: }
119:
120: private JPanel getExportFormatPanel() {
121: JPanel ret = new JPanel(new GridBagLayout());
122:
123: GridBagConstraints gbc;
124:
125: // i18n[TableExportCsvDlg.formatCSV=Export CSV file]
126: radFormatCSV = new JRadioButton(s_stringMgr
127: .getString("TableExportCsvDlg.formatCSV"));
128: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
129: GridBagConstraints.WEST, GridBagConstraints.NONE,
130: new Insets(0, 0, 0, 5), 0, 0);
131: ret.add(radFormatCSV, gbc);
132:
133: // i18n[TableExportCsvDlg.formatXLS=Export MS Excel (XLS) file]
134: radFormatXLS = new JRadioButton(s_stringMgr
135: .getString("TableExportCsvDlg.formatXLS"));
136: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
137: GridBagConstraints.WEST, GridBagConstraints.NONE,
138: new Insets(0, 0, 0, 0), 0, 0);
139: ret.add(radFormatXLS, gbc);
140:
141: gbc = new GridBagConstraints(1, 0, 1, 1, 1, 0,
142: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
143: new Insets(0, 0, 0, 0), 0, 0);
144: ret.add(new JPanel(), gbc);
145:
146: ButtonGroup bg = new ButtonGroup();
147: bg.add(radFormatCSV);
148: bg.add(radFormatXLS);
149:
150: return ret;
151: }
152:
153: private Component getFormatingPanel() {
154: JPanel ret = new JPanel(new GridBagLayout());
155:
156: GridBagConstraints gbc;
157:
158: // i18n[TableExportCsvDlg.useGlobalPrefsFormatingExcel=Use formating as configured in Global Prefs (recommended for MS Excel)]
159: radUseGlobalPrefsFormating = new JRadioButton(
160: s_stringMgr
161: .getString("TableExportCsvDlg.useGlobalPrefsFormatingExcel"));
162: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
163: GridBagConstraints.WEST, GridBagConstraints.NONE,
164: new Insets(0, 0, 2, 0), 0, 0);
165: ret.add(radUseGlobalPrefsFormating, gbc);
166:
167: // i18n[TableExportCsvDlg.useDefaultFormating=Use default formating]
168: radUseDefaultFormating = new JRadioButton(s_stringMgr
169: .getString("TableExportCsvDlg.useDefaultFormating"));
170: gbc = new GridBagConstraints(0, 1, 1, 1, 0, 0,
171: GridBagConstraints.WEST, GridBagConstraints.NONE,
172: new Insets(0, 0, 0, 0), 0, 0);
173: ret.add(radUseDefaultFormating, gbc);
174:
175: gbc = new GridBagConstraints(1, 0, 1, 2, 1, 0,
176: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
177: new Insets(0, 0, 0, 0), 0, 0);
178: ret.add(new JPanel(), gbc);
179:
180: ButtonGroup bg = new ButtonGroup();
181: bg.add(radUseGlobalPrefsFormating);
182: bg.add(radUseDefaultFormating);
183:
184: return ret;
185:
186: }
187:
188: private Component getButtonPanel() {
189: JPanel ret = new JPanel(new GridBagLayout());
190:
191: GridBagConstraints gbc;
192:
193: // i18n[TableExportCsvDlg.OK=OK]
194: btnOk = new JButton(s_stringMgr
195: .getString("TableExportCsvDlg.OK"));
196: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
197: GridBagConstraints.WEST, GridBagConstraints.NONE,
198: new Insets(0, 0, 0, 5), 0, 0);
199: ret.add(btnOk, gbc);
200:
201: // i18n[TableExportCsvDlg.Cancel=Cancel]
202: btnCancel = new JButton(s_stringMgr
203: .getString("TableExportCsvDlg.Cancel"));
204: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
205: GridBagConstraints.WEST, GridBagConstraints.NONE,
206: new Insets(0, 0, 0, 0), 0, 0);
207: ret.add(btnCancel, gbc);
208:
209: gbc = new GridBagConstraints(2, 0, 1, 1, 1, 0,
210: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
211: new Insets(0, 5, 0, 5), 0, 0);
212: ret.add(new JPanel(), gbc);
213:
214: return ret;
215: }
216:
217: private Component getCommandPanel() {
218: JPanel ret = new JPanel(new GridBagLayout());
219:
220: GridBagConstraints gbc;
221:
222: txtCommand = new JTextField();
223: gbc = new GridBagConstraints(0, 0, 1, 1, 1, 0,
224: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
225: new Insets(0, 0, 0, 5), 0, 0);
226: ret.add(txtCommand, gbc);
227:
228: LibraryResources rsrc = new LibraryResources();
229: btnCommandFile = new JButton(rsrc
230: .getIcon(LibraryResources.IImageNames.OPEN));
231: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
232: GridBagConstraints.WEST, GridBagConstraints.NONE,
233: new Insets(0, 0, 0, 0), 0, 0);
234: ret.add(btnCommandFile, gbc);
235:
236: return ret;
237: }
238:
239: private Component getSelelectionPanel() {
240: JPanel ret = new JPanel(new GridBagLayout());
241:
242: GridBagConstraints gbc;
243:
244: // i18n[TableExportCsvDlg.exportCompleteTable=Export complete table]
245: radComplete = new JRadioButton(s_stringMgr
246: .getString("TableExportCsvDlg.exportCompleteTable"));
247: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
248: GridBagConstraints.WEST, GridBagConstraints.NONE,
249: new Insets(0, 0, 0, 5), 0, 0);
250: ret.add(radComplete, gbc);
251:
252: // i18n[TableExportCsvDlg.exportSelection=Export selection]
253: radSelection = new JRadioButton(s_stringMgr
254: .getString("TableExportCsvDlg.exportSelection"));
255: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
256: GridBagConstraints.WEST, GridBagConstraints.NONE,
257: new Insets(0, 0, 0, 0), 0, 0);
258: ret.add(radSelection, gbc);
259:
260: gbc = new GridBagConstraints(1, 0, 1, 1, 1, 0,
261: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
262: new Insets(0, 0, 0, 0), 0, 0);
263: ret.add(new JPanel(), gbc);
264:
265: ButtonGroup bg = new ButtonGroup();
266: bg.add(radComplete);
267: bg.add(radSelection);
268:
269: return ret;
270: }
271:
272: private Component getSeparatorPanel() {
273: JPanel ret = new JPanel(new GridBagLayout());
274:
275: GridBagConstraints gbc;
276:
277: gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0,
278: GridBagConstraints.WEST, GridBagConstraints.NONE,
279: new Insets(0, 0, 0, 5), 0, 0);
280: // i18n[TableExportCsvDlg.separator=Separator:]
281: lblSeparator = new JLabel(s_stringMgr
282: .getString("TableExportCsvDlg.separator"));
283: ret.add(lblSeparator, gbc);
284:
285: txtSeparatorChar = new JTextField(1);
286: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
287: GridBagConstraints.WEST, GridBagConstraints.NONE,
288: new Insets(0, 0, 0, 20), 0, 0);
289: ret.add(txtSeparatorChar, gbc);
290:
291: // i18n[TableExportCsvDlg.sepeartorTab=Use tab character]
292: chkSeparatorTab = new JCheckBox(s_stringMgr
293: .getString("TableExportCsvDlg.sepeartorTab"));
294: gbc = new GridBagConstraints(2, 0, 1, 1, 0, 0,
295: GridBagConstraints.WEST, GridBagConstraints.NONE,
296: new Insets(0, 0, 0, 0), 0, 0);
297: ret.add(chkSeparatorTab, gbc);
298:
299: gbc = new GridBagConstraints(3, 0, 1, 1, 1, 0,
300: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
301: new Insets(0, 0, 0, 0), 0, 0);
302: ret.add(new JPanel(), gbc);
303:
304: charsets = new JComboBox();
305: for (String s : Charset.availableCharsets().keySet()) {
306: charsets.addItem(s);
307: }
308:
309: gbc = new GridBagConstraints(0, 1, 2, 1, 0, 0,
310: GridBagConstraints.WEST, GridBagConstraints.NONE,
311: new Insets(0, 0, 0, 0), 0, 0);
312: // i18n[TableExportCsvDlg.charset=Charset:]
313: lblCharset = new JLabel(s_stringMgr
314: .getString("TableExportCsvDlg.charset"));
315: ret.add(lblCharset, gbc);
316:
317: gbc = new GridBagConstraints(2, 1, 1, 1, 0, 0,
318: GridBagConstraints.WEST, GridBagConstraints.NONE,
319: new Insets(0, 0, 0, 0), 0, 0);
320: ret.add(charsets, gbc);
321:
322: gbc = new GridBagConstraints(3, 1, 1, 1, 1, 0,
323: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
324: new Insets(0, 0, 0, 0), 0, 0);
325: ret.add(new JPanel(), gbc);
326:
327: return ret;
328: }
329:
330: private Component getFilePanel() {
331: JPanel ret = new JPanel(new GridBagLayout());
332:
333: GridBagConstraints gbc;
334:
335: txtFile = new JTextField();
336: gbc = new GridBagConstraints(0, 0, 1, 1, 1, 0,
337: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
338: new Insets(0, 0, 0, 5), 0, 0);
339: ret.add(txtFile, gbc);
340:
341: LibraryResources rsrc = new LibraryResources();
342:
343: btnFile = new JButton(rsrc
344: .getIcon(LibraryResources.IImageNames.OPEN));
345: gbc = new GridBagConstraints(1, 0, 1, 1, 0, 0,
346: GridBagConstraints.WEST, GridBagConstraints.NONE,
347: new Insets(0, 0, 0, 0), 0, 0);
348: ret.add(btnFile, gbc);
349:
350: return ret;
351: }
352: }
|