001: /*
002: * GeneralImportOptionsPanel.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.dialogs.dataimport;
013:
014: import workbench.resource.ResourceMgr;
015: import workbench.resource.Settings;
016:
017: /**
018: *
019: * @author support@sql-workbench.net
020: */
021: public class GeneralImportOptionsPanel extends javax.swing.JPanel
022: implements ImportOptions {
023: /** Creates new form GeneralExportOptionsPanel */
024: public GeneralImportOptionsPanel() {
025: initComponents();
026: }
027:
028: public void setEncodingVisible(boolean flag) {
029: this .encodingPanel.setEnabled(false);
030: this .encodingPanel.setVisible(false);
031: }
032:
033: public void setModeSelectorEnabled(boolean flag) {
034: this .modeComboBox.setEnabled(flag);
035: this .modeComboBox.setSelectedIndex(0);
036: this .modeComboBox.setVisible(flag);
037: }
038:
039: public void saveSettings() {
040: saveSettings("general");
041: }
042:
043: public void saveSettings(String key) {
044: Settings s = Settings.getInstance();
045: s.setProperty("workbench.import." + key + ".dateformat", this
046: .getDateFormat());
047: s.setProperty("workbench.import." + key + ".timestampformat",
048: this .getTimestampFormat());
049: s.setProperty("workbench.import." + key + ".encoding", this
050: .getEncoding());
051: s.setProperty("workbench.import." + key + ".mode", this
052: .getMode());
053: }
054:
055: public void restoreSettings() {
056: restoreSettings("general");
057: }
058:
059: public void restoreSettings(String key) {
060: Settings s = Settings.getInstance();
061: this .setDateFormat(s.getProperty("workbench.import." + key
062: + ".dateformat", s.getDefaultDateFormat()));
063: this .setTimestampFormat(s.getProperty("workbench.import." + key
064: + ".timestampformat", s.getDefaultTimestampFormat()));
065: this .setEncoding(s.getProperty("workbench.export." + key
066: + ".encoding", s.getDefaultDataEncoding()));
067: this .setMode(s.getProperty("workbench.import." + key + ".mode",
068: "insert"));
069: }
070:
071: public String getMode() {
072: return (String) this .modeComboBox.getSelectedItem();
073: }
074:
075: public void setMode(String mode) {
076: this .modeComboBox.setSelectedItem(mode);
077: }
078:
079: public String getDateFormat() {
080: return this .dateFormat.getText();
081: }
082:
083: public String getEncoding() {
084: return encodingPanel.getEncoding();
085: }
086:
087: public String getTimestampFormat() {
088: return this .timestampFormat.getText();
089: }
090:
091: public void setDateFormat(String format) {
092: dateFormat.setText(format);
093: }
094:
095: public void setEncoding(String enc) {
096: encodingPanel.setEncoding(enc);
097: }
098:
099: public void setTimestampFormat(String format) {
100: timestampFormat.setText(format);
101: }
102:
103: /** This method is called from within the constructor to
104: * initialize the form.
105: * WARNING: Do NOT modify this code. The content of this method is
106: * always regenerated by the Form Editor.
107: */
108: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
109: private void initComponents() {
110: java.awt.GridBagConstraints gridBagConstraints;
111:
112: encodingPanel = new workbench.gui.components.EncodingPanel();
113: dateFormatLabel = new javax.swing.JLabel();
114: dateFormat = new javax.swing.JTextField();
115: timestampFormatLabel = new javax.swing.JLabel();
116: timestampFormat = new javax.swing.JTextField();
117: jPanel1 = new javax.swing.JPanel();
118: modeLabel = new javax.swing.JLabel();
119: modeComboBox = new javax.swing.JComboBox();
120:
121: setLayout(new java.awt.GridBagLayout());
122: gridBagConstraints = new java.awt.GridBagConstraints();
123: gridBagConstraints.gridx = 0;
124: gridBagConstraints.gridy = 0;
125: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
126: gridBagConstraints.weightx = 1.0;
127: add(encodingPanel, gridBagConstraints);
128:
129: dateFormatLabel.setText(ResourceMgr.getString("LblDateFormat"));
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridx = 0;
132: gridBagConstraints.gridy = 1;
133: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
136: add(dateFormatLabel, gridBagConstraints);
137: gridBagConstraints = new java.awt.GridBagConstraints();
138: gridBagConstraints.gridx = 0;
139: gridBagConstraints.gridy = 2;
140: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
141: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
142: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
143: add(dateFormat, gridBagConstraints);
144:
145: timestampFormatLabel.setText(ResourceMgr
146: .getString("LblTimestampFormat"));
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.gridx = 0;
149: gridBagConstraints.gridy = 3;
150: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
152: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
153: add(timestampFormatLabel, gridBagConstraints);
154: gridBagConstraints = new java.awt.GridBagConstraints();
155: gridBagConstraints.gridx = 0;
156: gridBagConstraints.gridy = 4;
157: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
159: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
160: add(timestampFormat, gridBagConstraints);
161: gridBagConstraints = new java.awt.GridBagConstraints();
162: gridBagConstraints.gridx = 0;
163: gridBagConstraints.gridy = 7;
164: gridBagConstraints.weightx = 1.0;
165: gridBagConstraints.weighty = 1.0;
166: add(jPanel1, gridBagConstraints);
167:
168: modeLabel.setText(ResourceMgr.getString("LblImportMode"));
169: modeLabel.setToolTipText(ResourceMgr
170: .getDescription("LblImportMode"));
171: gridBagConstraints = new java.awt.GridBagConstraints();
172: gridBagConstraints.gridx = 0;
173: gridBagConstraints.gridy = 5;
174: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
175: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
176: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
177: add(modeLabel, gridBagConstraints);
178:
179: modeComboBox.setModel(new javax.swing.DefaultComboBoxModel(
180: new String[] { "insert", "update", "insert,update",
181: "update,insert" }));
182: gridBagConstraints = new java.awt.GridBagConstraints();
183: gridBagConstraints.gridx = 0;
184: gridBagConstraints.gridy = 6;
185: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
186: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
187: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
188: add(modeComboBox, gridBagConstraints);
189: }// </editor-fold>//GEN-END:initComponents
190:
191: // Variables declaration - do not modify//GEN-BEGIN:variables
192: private javax.swing.JTextField dateFormat;
193: private javax.swing.JLabel dateFormatLabel;
194: private workbench.gui.components.EncodingPanel encodingPanel;
195: private javax.swing.JPanel jPanel1;
196: private javax.swing.JComboBox modeComboBox;
197: private javax.swing.JLabel modeLabel;
198: private javax.swing.JTextField timestampFormat;
199: private javax.swing.JLabel timestampFormatLabel;
200: // End of variables declaration//GEN-END:variables
201:
202: }
|