<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" pref="139" max="-2" attributes="0"/>
- <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
+ <EmptySpace max="32767" attributes="0"/>
</Group>
- <Group type="102" alignment="0" attributes="0">
- <Group type="103" groupAlignment="1" attributes="0">
- <Component id="txtDatabaseURL" min="-2" pref="231" max="-2" attributes="0"/>
- <Component id="buttonApply" min="-2" pref="92" max="-2" attributes="0"/>
+ <Group type="102" attributes="0">
+ <Component id="txtDatabaseURL" pref="255" max="32767" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" max="-2" attributes="0">
+ <Component id="buttonChooseFile" pref="109" max="32767" attributes="0"/>
+ <Component id="buttonApply" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
- <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="103" groupAlignment="0" max="-2" attributes="0">
+ <Component id="jButton1" pref="97" max="32767" attributes="0"/>
<Component id="buttonClose" max="32767" attributes="0"/>
- <Component id="buttonChooseFile" pref="93" max="32767" attributes="0"/>
</Group>
+ <EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
- <EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtDatabaseURL" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="buttonChooseFile" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
- <EmptySpace pref="29" max="32767" attributes="0"/>
+ <EmptySpace pref="22" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
- <Component id="buttonClose" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="buttonApply" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="buttonClose" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Component>
<Component class="javax.swing.JButton" name="buttonClose">
<Properties>
+ <Property name="mnemonic" type="int" value="67"/>
<Property name="text" type="java.lang.String" value="Close"/>
</Properties>
<Events>
</Component>
<Component class="javax.swing.JButton" name="buttonApply">
<Properties>
+ <Property name="mnemonic" type="int" value="97"/>
<Property name="text" type="java.lang.String" value="Apply"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonApplyActionPerformed"/>
</Events>
</Component>
+ <Component class="javax.swing.JButton" name="jButton1">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Create..."/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
+ </Events>
+ </Component>
</SubComponents>
</Form>
package habeas;
import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
/**
*
buttonChooseFile = new javax.swing.JButton();
buttonClose = new javax.swing.JButton();
buttonApply = new javax.swing.JButton();
+ jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Connection");
}
});
+ buttonClose.setMnemonic('C');
buttonClose.setText("Close");
buttonClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
+ buttonApply.setMnemonic('a');
buttonApply.setText("Apply");
buttonApply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
+ jButton1.setText("Create...");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(txtDatabaseURL, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(txtDatabaseURL, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(buttonClose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(buttonChooseFile, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))))
- .addContainerGap())
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(buttonChooseFile, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
+ .addComponent(buttonApply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
+ .addComponent(buttonClose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtDatabaseURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(buttonChooseFile))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
+ .addComponent(buttonChooseFile)
+ .addComponent(jButton1))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(buttonClose)
- .addComponent(buttonApply))
+ .addComponent(buttonApply)
+ .addComponent(buttonClose))
.addContainerGap())
);
private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
// TODO add your handling code here
- Utility.setConnectionURL (txtDatabaseURL.getText());
+ Utility.saveConnectionURL (txtDatabaseURL.getText());
}//GEN-LAST:event_buttonApplyActionPerformed
private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed
}
}//GEN-LAST:event_buttonChooseFileActionPerformed
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
+ // TODO add your handling code here:
+ JFileChooser chooser = new JFileChooser ();
+ int i = chooser.showSaveDialog(this);
+ if (i == JFileChooser.APPROVE_OPTION) {
+ String db_path = chooser.getSelectedFile().getAbsolutePath();
+ boolean rt = Utility.createDatabase (db_path);
+ if (rt == false)
+ JOptionPane.showMessageDialog(this, ERROR_CREATING_TABLE);
+ else
+ txtDatabaseURL.setText(db_path);
+ }
+ }//GEN-LAST:event_jButton1ActionPerformed
+ private static final String ERROR_CREATING_TABLE = "Error creating database. "
+ + "Please check connection settings and driver";
+
/**
* @param args the command line arguments
*/
private javax.swing.JButton buttonApply;
private javax.swing.JButton buttonChooseFile;
private javax.swing.JButton buttonClose;
+ private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField txtDatabaseURL;
// End of variables declaration//GEN-END:variables
*/
public class Utility {
- static void setConnectionURL(String text) {
+ static void saveConnectionURL(String text) {
connectionURL = text;
Preferences.userRoot().put("ConnectionURL", text);
}
return false;
}
+ }
+
+ static boolean createDatabase(String db_path) {
+ saveConnectionURL(db_path);
+ String tblClients = "CREATE TABLE IF NOT EXISTS \"clients\" (\n" +
+" \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
+" \"ClientName\" VARCHAR(255) NOT NULL UNIQUE,\n" +
+" \"ClientAddress\" TEXT,\n" +
+" \"ContactPerson\" TEXT,\n" +
+" \"MailID\" VARCHAR(255),\n" +
+" \"ContactNumber\" VARCHAR(30)\n" +
+" );";
+ String tblNotices = "CREATE TABLE IF NOT EXISTS \"legalnotices\" (\n" +
+ " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
+ " \"ReferenceNumber\" TEXT NOT NULL UNIQUE,\n" +
+ " \"Description\" TEXT NOT NULL,\n" +
+ " \"EntrustmentDate\" INTEGER NOT NULL,\n" +
+ " \"ClientId\" INTEGER,\n" +
+ " \"DraftCreated\" INTEGER DEFAULT 0,\n" +
+ " \"DraftApproved\" INTEGER DEFAULT 0 CHECK(DraftApproved<=DraftCreated),\n" +
+ " \"NoticeSent\" INTEGER DEFAULT 0 CHECK(NoticeSent<=DraftApproved),\n" +
+ " \"SentDate\" INTEGER CHECK(SentDate>=EntrustmentDate),\n" +
+ " \"RPADReference\" TEXT,\n" +
+ " \"NoticeDelivered\" INTEGER DEFAULT 0 CHECK(NoticeDelivered<=NoticeSent),\n" +
+ " \"DeliveryDate\" INTEGER CHECK(DeliveryDate>=SentDate),\n" +
+ " \"BillStatus\" TEXT DEFAULT 'PENDING',\n" +
+ " \"BillAmount\" INTEGER DEFAULT 1000 CHECK(BillAmount>0),\n" +
+ " \"BillDate\" INTEGER CHECK(BillDate>=DeliveryDate),\n" +
+ " \"ClarificationPending\" INTEGER DEFAULT 0,\n" +
+ " \"ClarificationRemarks\" TEXT\n" +
+ ");";
+ String tblSettings = "CREATE TABLE IF NOT EXISTS \"settings\" (\n" +
+" \"key\" TEXT UNIQUE,\n" +
+" \"value\" TEXT,\n" +
+" PRIMARY KEY(\"key\")\n" +
+ ");";
+ try {
+ Connection conn = DriverManager.getConnection(JDBC + connectionURL);
+ Statement st1 = conn.createStatement();
+ st1.execute(tblSettings);
+ st1.execute(tblClients);
+ st1.execute(tblNotices);
+ conn.close();
+ return true;
+ } catch (SQLException ex) {
+ Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+ return false;
+ }
+
}
public Utility () {
}
- public static void getConnectionURL () {
+ public static void retrieveConnectionURL () {
connectionURL = Preferences.userRoot().get("ConnectionURL", "legaldb");
}