1 6 7 package com.quikj.application.utilities.postinstall; 8 9 import java.io.*; 10 import java.awt.*; 11 12 16 public class Backup extends java.awt.Frame implements ScreenPrinterInterface 17 { 18 private String home; 19 20 21 public Backup(String home) 22 { 23 this.home = home; 24 initComponents(); 25 } 26 27 32 private void initComponents() { 34 java.awt.GridBagConstraints gridBagConstraints; 35 36 statusTextArea = new java.awt.TextArea ("", 10, 60, java.awt.TextArea.SCROLLBARS_VERTICAL_ONLY); 37 actionButton = new java.awt.Button (); 38 statusBar = new java.awt.TextField (); 39 40 setLayout(new java.awt.GridBagLayout ()); 41 42 setTitle("Ace Pre-Upgrade Backup"); 43 addWindowListener(new java.awt.event.WindowAdapter () 44 { 45 public void windowClosing(java.awt.event.WindowEvent 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 (); 54 gridBagConstraints.gridx = 0; 55 gridBagConstraints.gridy = 0; 56 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 57 gridBagConstraints.insets = new java.awt.Insets (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 (0, 0, 0)); 64 actionButton.setLabel("Start"); 65 actionButton.setName("null"); 66 actionButton.addActionListener(new java.awt.event.ActionListener () 67 { 68 public void actionPerformed(java.awt.event.ActionEvent evt) 69 { 70 actionButtonActionPerformed(evt); 71 } 72 }); 73 74 gridBagConstraints = new java.awt.GridBagConstraints (); 75 gridBagConstraints.gridx = 0; 76 gridBagConstraints.gridy = 1; 77 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 78 gridBagConstraints.insets = new java.awt.Insets (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 (204, 204, 204)); 84 statusBar.setEnabled(false); 85 gridBagConstraints = new java.awt.GridBagConstraints (); 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 } 96 private void actionButtonActionPerformed(java.awt.event.ActionEvent evt) { 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 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 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 BackupFiles backup = new BackupFiles(); 133 String 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 } 152 153 private void exitForm(java.awt.event.WindowEvent evt) 154 { 156 } 158 public void print(String message) 159 { 160 statusTextArea.append(message); 161 } 162 163 public void println(String message) 164 { 165 statusTextArea.append (message + '\n'); 166 } 167 168 private java.awt.Button actionButton; 170 private java.awt.TextArea statusTextArea; 171 private java.awt.TextField statusBar; 172 174 } 175 | Popular Tags |