001: package org.netbeans.modules.mashup.db.wizard;
002:
003: import java.awt.Color;
004: import java.awt.event.KeyAdapter;
005: import java.awt.event.KeyEvent;
006: import java.io.File;
007: import java.io.FileInputStream;
008: import java.io.FileNotFoundException;
009: import java.io.IOException;
010: import java.util.Properties;
011: import javax.swing.JPanel;
012: import org.netbeans.modules.etl.ui.ETLEditorSupport;
013: import org.netbeans.modules.mashup.db.ui.AxionDBConfiguration;
014: import org.netbeans.modules.mashup.tables.wizard.MashupTableWizardIterator;
015: import net.java.hulp.i18n.Logger;
016: import org.netbeans.modules.etl.logger.Localizer;
017: import org.netbeans.modules.etl.logger.LogUtil;
018:
019: public final class NewFlatfileDatabaseVisualPanel extends JPanel {
020: private static transient final Logger mLogger = LogUtil
021: .getLogger(NewFFDBAction.class.getName());
022: private static transient final Localizer mLoc = Localizer.get();
023: public String nbBundle1 = mLoc.t("PRSR001: Create Mashup Database");
024:
025: class NameFieldKeyAdapter extends KeyAdapter {
026:
027: /**
028: * Overrides default implementation to notify listeners of new flat file database
029: * definition name value in associated textfield.
030: *
031: * @param e KeyEvent to be handled
032: */
033: @Override
034: public void keyReleased(KeyEvent e) {
035: checkDBName();
036: NewFlatfileDatabaseVisualPanel.this .owner.fireChangeEvent();
037: }
038: }
039:
040: private boolean canProceed = false;
041: private NewFlatfileDatabaseWizardPanel owner;
042:
043: /**
044: * Creates new form NewFlatfileDatabaseVisualPanel
045: */
046: public NewFlatfileDatabaseVisualPanel() {
047: initComponents();
048: errorMsg.setForeground(Color.RED);
049: dbLoc.setForeground(Color.BLUE);
050: driverClass.setForeground(Color.BLUE);
051: dbName.setText("");
052: errorMsg.setText("");
053: dbName.addKeyListener(new NameFieldKeyAdapter());
054: }
055:
056: public NewFlatfileDatabaseVisualPanel(
057: NewFlatfileDatabaseWizardPanel panel) {
058: this ();
059: this .owner = panel;
060: }
061:
062: @Override
063: public String getName() {
064: return Localizer.parse(nbBundle1);
065: }
066:
067: public void clearText() {
068: dbName.setText("");
069: }
070:
071: public boolean canProceed() {
072: checkDBName();
073: return this .canProceed;
074: }
075:
076: private String getDefaultWorkingFolder() {
077: File conf = AxionDBConfiguration.getConfigFile();
078: Properties prop = new Properties();
079: try {
080: FileInputStream in = new FileInputStream(conf);
081: prop.load(in);
082: } catch (FileNotFoundException ex) {
083: //ignore
084: } catch (IOException ex) {
085: //ignore
086: }
087: String defaultDir = prop
088: .getProperty(AxionDBConfiguration.PROP_DB_LOC);
089: defaultDir = defaultDir.replace('/', '\\');
090: if (!defaultDir.endsWith("\\")) {
091: defaultDir = defaultDir + "\\";
092: }
093: return defaultDir;
094: }
095:
096: public String getDBName() {
097: return dbName.getText().trim();
098: }
099:
100: public void setDBName(String name) {
101: dbName.setText(name.trim());
102: }
103:
104: public void setErrorMsg(String msg) {
105: errorMsg.setText(msg);
106: }
107:
108: public String getErrorMsg() {
109: return errorMsg.getText();
110: }
111:
112: /** This method is called from within the constructor to
113: * initialize the form.
114: */
115: private void initComponents() {
116: jLabel1 = new javax.swing.JLabel();
117: dbName = new javax.swing.JTextField();
118: jLabel2 = new javax.swing.JLabel();
119: dbLoc = new javax.swing.JLabel();
120: driver = new javax.swing.JLabel();
121: driverClass = new javax.swing.JLabel();
122: errorMsg = new javax.swing.JLabel();
123:
124: setMaximumSize(new java.awt.Dimension(10000, 4000));
125: setPreferredSize(new java.awt.Dimension(10, 4));
126: String nbBundle7 = mLoc.t("PRSR001: Database Name");
127: jLabel1.setDisplayedMnemonic(Localizer.parse(nbBundle7).charAt(
128: 0));
129: jLabel1.getAccessibleContext().setAccessibleName(
130: Localizer.parse(nbBundle7));
131:
132: String nbBundle2 = mLoc
133: .t("PRSR001: Database name should start with an alphabet.");
134: dbName.setToolTipText(Localizer.parse(nbBundle2));
135: dbName.addKeyListener(new NameFieldKeyAdapter());
136: String nbBundle3 = mLoc.t("PRSR001: Location");
137: String nbBundle4 = mLoc.t("PRSR001: Driver Class");
138: jLabel2.setDisplayedMnemonic(Localizer.parse(nbBundle3).charAt(
139: 0));
140: jLabel2.getAccessibleContext().setAccessibleName(
141: Localizer.parse(nbBundle3));
142: org.openide.awt.Mnemonics.setLocalizedText(jLabel2, Localizer
143: .parse(nbBundle3));
144: driver.getAccessibleContext().setAccessibleName(
145: Localizer.parse(nbBundle4));
146: org.openide.awt.Mnemonics.setLocalizedText(driver, Localizer
147: .parse(nbBundle4));
148: org.openide.awt.Mnemonics.setLocalizedText(driverClass,
149: "org.axiondb.jdbc.AxionDriver");
150:
151: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
152: this );
153: this .setLayout(layout);
154: layout
155: .setHorizontalGroup(layout
156: .createParallelGroup(
157: org.jdesktop.layout.GroupLayout.LEADING)
158: .add(
159: layout
160: .createSequentialGroup()
161: .addContainerGap()
162: .add(
163: layout
164: .createParallelGroup(
165: org.jdesktop.layout.GroupLayout.LEADING)
166: .add(
167: layout
168: .createSequentialGroup()
169: .add(
170: jLabel2,
171: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
172: 111,
173: Short.MAX_VALUE)
174: .addPreferredGap(
175: org.jdesktop.layout.LayoutStyle.RELATED,
176: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
177: Short.MAX_VALUE))
178: .add(jLabel1)
179: .add(
180: layout
181: .createSequentialGroup()
182: .add(
183: driver)
184: .addPreferredGap(
185: org.jdesktop.layout.LayoutStyle.RELATED)))
186: .addPreferredGap(
187: org.jdesktop.layout.LayoutStyle.RELATED)
188: .add(
189: layout
190: .createParallelGroup(
191: org.jdesktop.layout.GroupLayout.LEADING)
192: .add(
193: layout
194: .createSequentialGroup()
195: .add(
196: driverClass)
197: .addContainerGap())
198: .add(
199: layout
200: .createParallelGroup(
201: org.jdesktop.layout.GroupLayout.LEADING)
202: .add(
203: layout
204: .createSequentialGroup()
205: .add(
206: dbName,
207: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
208: 161,
209: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
210: .add(
211: 190,
212: 190,
213: 190))
214: .add(
215: org.jdesktop.layout.GroupLayout.TRAILING,
216: layout
217: .createSequentialGroup()
218: .add(
219: layout
220: .createParallelGroup(
221: org.jdesktop.layout.GroupLayout.TRAILING)
222: .add(
223: org.jdesktop.layout.GroupLayout.LEADING,
224: dbLoc,
225: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
226: 412,
227: Short.MAX_VALUE)
228: .add(
229: errorMsg,
230: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
231: 412,
232: Short.MAX_VALUE))
233: .addContainerGap())))));
234: layout
235: .setVerticalGroup(layout
236: .createParallelGroup(
237: org.jdesktop.layout.GroupLayout.LEADING)
238: .add(
239: layout
240: .createSequentialGroup()
241: .add(40, 40, 40)
242: .add(
243: layout
244: .createParallelGroup(
245: org.jdesktop.layout.GroupLayout.BASELINE)
246: .add(
247: jLabel1,
248: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
249: 25,
250: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
251: .add(
252: dbName,
253: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
254: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
255: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
256: .addPreferredGap(
257: org.jdesktop.layout.LayoutStyle.RELATED)
258: .add(
259: errorMsg,
260: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
261: 18,
262: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
263: .add(14, 14, 14)
264: .add(
265: layout
266: .createParallelGroup(
267: org.jdesktop.layout.GroupLayout.BASELINE)
268: .add(
269: jLabel2,
270: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
271: 17,
272: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
273: .add(
274: dbLoc,
275: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
276: 19,
277: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
278: .add(32, 32, 32)
279: .add(
280: layout
281: .createParallelGroup(
282: org.jdesktop.layout.GroupLayout.BASELINE)
283: .add(driver)
284: .add(
285: driverClass,
286: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
287: 23,
288: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
289: .addContainerGap(
290: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
291: Short.MAX_VALUE)));
292: }
293:
294: private void checkDBName() {
295: String name = dbName.getText().trim();
296: String location = null;
297:
298: if (MashupTableWizardIterator.IS_PROJECT_CALL) {
299: location = ETLEditorSupport.PRJ_PATH
300: + "\\nbproject\\private\\databases";
301: dbLoc.setText("${project.home}"
302: + "\\nbproject\\private\\databases");
303: } else {
304: location = getDefaultWorkingFolder();
305: dbLoc.setText(location);
306: }
307:
308: File f = new File(location + "\\" + name);
309: char[] ch = name.toCharArray();
310: if (ch.length != 0) {
311: if (f.exists()) {
312: String nbBundle5 = mLoc.t(
313: "PRSR001: Database {0} already exists. ", name);
314: errorMsg.setText(Localizer.parse(nbBundle5));
315: canProceed = false;
316: } else if (Character.isDigit(ch[0])) {
317: String nbBundle6 = mLoc
318: .t("PRSR001: Database name should start with an alphabet.");
319: errorMsg.setText(Localizer.parse(nbBundle6));
320: canProceed = false;
321: } else {
322: errorMsg.setText("");
323: canProceed = true;
324: }
325: } else {
326: errorMsg.setText("");
327: canProceed = false;
328: }
329: }
330:
331: private javax.swing.JLabel dbLoc;
332: private javax.swing.JTextField dbName;
333: private javax.swing.JLabel driver;
334: private javax.swing.JLabel driverClass;
335: private javax.swing.JLabel errorMsg;
336: private javax.swing.JLabel jLabel1;
337: private javax.swing.JLabel jLabel2;
338: }
|