KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > utilities > postinstall > Backup


1 /*
2  * Backup.java
3  *
4  * Created on November 7, 2003, 7:06 AM
5  */

6
7 package com.quikj.application.utilities.postinstall;
8
9 import java.io.*;
10 import java.awt.*;
11
12 /**
13  *
14  * @author amit
15  */

16 public class Backup extends java.awt.Frame JavaDoc implements ScreenPrinterInterface
17 {
18     private String JavaDoc home;
19     
20     /** Creates new form Backup */
21     public Backup(String JavaDoc home)
22     {
23         this.home = home;
24         initComponents();
25     }
26     
27     /** This method is called from within the constructor to
28      * initialize the form.
29      * WARNING: Do NOT modify this code. The content of this method is
30      * always regenerated by the Form Editor.
31      */

32     private void initComponents()//GEN-BEGIN:initComponents
33
{
34         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
35
36         statusTextArea = new java.awt.TextArea JavaDoc ("", 10, 60, java.awt.TextArea.SCROLLBARS_VERTICAL_ONLY);
37         actionButton = new java.awt.Button JavaDoc();
38         statusBar = new java.awt.TextField JavaDoc();
39
40         setLayout(new java.awt.GridBagLayout JavaDoc());
41
42         setTitle("Ace Pre-Upgrade Backup");
43         addWindowListener(new java.awt.event.WindowAdapter JavaDoc()
44         {
45             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt)
46             {
47                 exitForm(evt);
48             }
49         });
50
51         statusTextArea.setText("Welcome to the Backup utility. This utility will backup essential files that needs to be saved prior to upgradng to a new version of Ace Operator. Click on the \"Start\" button to continue.");
52         statusTextArea.setEditable(false);
53         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
54         gridBagConstraints.gridx = 0;
55         gridBagConstraints.gridy = 0;
56         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
57         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 5);
58         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
59         gridBagConstraints.weightx = 100.0;
60         gridBagConstraints.weighty = 100.0;
61         add(statusTextArea, gridBagConstraints);
62
63         actionButton.setForeground(new java.awt.Color JavaDoc(0, 0, 0));
64         actionButton.setLabel("Start");
65         actionButton.setName("null");
66         actionButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
67         {
68             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
69             {
70                 actionButtonActionPerformed(evt);
71             }
72         });
73
74         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
75         gridBagConstraints.gridx = 0;
76         gridBagConstraints.gridy = 1;
77         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
78         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 5, 5);
79         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
80         gridBagConstraints.weightx = 100.0;
81         add(actionButton, gridBagConstraints);
82
83         statusBar.setBackground(new java.awt.Color JavaDoc(204, 204, 204));
84         statusBar.setEnabled(false);
85         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
86         gridBagConstraints.gridx = 0;
87         gridBagConstraints.gridy = 2;
88         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
89         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
90         gridBagConstraints.weightx = 100.0;
91         add(statusBar, gridBagConstraints);
92
93         pack();
94     }//GEN-END:initComponents
95

96     private void actionButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_actionButtonActionPerformed
97
{//GEN-HEADEREND:event_actionButtonActionPerformed
98
// Add your handling code here:
99
if (actionButton.getLabel().startsWith ("Start") == true)
100         {
101             actionButton.setLabel("Exit");
102             actionButton.setEnabled(false);
103             
104             File f = null;
105             if (home == null)
106             {
107                 f = new File(".");
108             }
109             else
110             {
111                 f = new File (home);
112             }
113             String JavaDoc abs_path = f.getAbsolutePath();
114             if (abs_path.endsWith(File.separator + ".") == true)
115             {
116                 abs_path = abs_path.substring(0, abs_path.length() - 2);
117             }
118             
119             // check if this is indeed ACE_HOME
120
f = new File (abs_path, "sql/init_ace.sql.orig");
121             if (f.exists() == false)
122             {
123                 Toolkit.getDefaultToolkit().beep();
124                 statusBar.setForeground(Color.red);
125                 statusBar.setText("An error occured");
126                 statusTextArea.setText("You are not running this utility from the Ace home folder. Backup operation not performed.");
127                 actionButton.setEnabled(true);
128                 return;
129             }
130             
131             // start the backup process.
132
BackupFiles backup = new BackupFiles();
133             String JavaDoc error = backup.backup(abs_path, this);
134             if (error != null)
135             {
136                 statusBar.setForeground(Color.red);
137                 statusBar.setText(error);
138             }
139             else
140             {
141                 statusBar.setForeground(Color.black);
142                 statusBar.setText("Backup completed. Click on the \"Exit\" button");
143             }
144             actionButton.setEnabled(true);
145         }
146         else if (actionButton.getLabel().startsWith ("Exit") == true)
147         {
148             System.exit(0);
149         }
150     }//GEN-LAST:event_actionButtonActionPerformed
151

152     /** Exit the Application */
153     private void exitForm(java.awt.event.WindowEvent JavaDoc evt)
154     {//GEN-FIRST:event_exitForm
155

156     }//GEN-LAST:event_exitForm
157

158     public void print(String JavaDoc message)
159     {
160         statusTextArea.append(message);
161     }
162     
163     public void println(String JavaDoc message)
164     {
165         statusTextArea.append (message + '\n');
166     }
167     
168     // Variables declaration - do not modify//GEN-BEGIN:variables
169
private java.awt.Button JavaDoc actionButton;
170     private java.awt.TextArea JavaDoc statusTextArea;
171     private java.awt.TextField JavaDoc statusBar;
172     // End of variables declaration//GEN-END:variables
173

174 }
175
Popular Tags