1 23 package com.sun.enterprise.tools.verifier.gui; 24 25 import javax.swing.JFrame ; 26 import javax.swing.JLabel ; 27 import javax.swing.JOptionPane ; 28 import javax.swing.JPanel ; 29 import javax.swing.SwingUtilities ; 30 31 import java.awt.BorderLayout ; 32 import java.awt.event.ActionEvent ; 33 import java.awt.event.ActionListener ; 34 import java.io.File ; 35 import java.util.Enumeration ; 36 import java.util.Iterator ; 37 import java.util.logging.LogRecord ; 38 39 import com.sun.enterprise.tools.verifier.ResultManager; 40 import com.sun.enterprise.tools.verifier.StringManagerHelper; 41 import com.sun.enterprise.tools.verifier.Verifier; 42 43 public class MainPanel extends JPanel implements Runnable { 44 45 static com.sun.enterprise.util.LocalStringManagerImpl smh = 46 StringManagerHelper.getLocalStringsManager(); 47 ResultsPanel resultsPanel = new ResultsPanel(); 48 ControlPanel verifierControls; 49 50 JLabel statusLabel = new JLabel ((smh.getLocalString 51 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".Status_Idle", "Idle"))); Verifier verifier; 55 Enumeration components; 56 Thread running = null; 57 58 61 public MainPanel(JFrame parent) { 62 this(parent, null, null); 63 } 64 65 public MainPanel(JFrame parent, String jarFileName, Verifier verifier) { 66 super(new BorderLayout (), true); 67 68 this.getAccessibleContext().setAccessibleName(smh.getLocalString 70 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".panelName", "Panel")); this.getAccessibleContext().setAccessibleDescription(smh.getLocalString 74 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".PanelDesc", "This is a panel")); statusLabel.getAccessibleContext().setAccessibleName(smh.getLocalString 78 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".labelName", "Label")); statusLabel.getAccessibleContext().setAccessibleDescription 82 (smh.getLocalString("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".labelDesc", "This is a label")); 86 verifierControls = new ControlPanel(parent); 88 setJarFilename(jarFileName); 90 this.verifier = verifier; 91 92 add("North", verifierControls); add("Center", resultsPanel); add("South", statusLabel); 96 97 verifierControls.okButton.addActionListener(new ActionListener () { 98 public void actionPerformed(ActionEvent e) { 99 if (getFileList().hasMoreElements()) { 100 resultsPanel.clearOldResults(); 101 start(); 102 } else { 103 JOptionPane.showMessageDialog(verifierControls, (smh.getLocalString 104 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".optionPane.okButtonNoFiles", "You must first select file to verify.")) + "\n" + (smh.getLocalString 109 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".optionPane.okButtonNoFiles2", "Use the Add button to select file to be verified," + " then click on OK button."))); } 114 } 115 }); 116 117 verifierControls.closeButton.addActionListener(new ActionListener () { 118 public void actionPerformed(ActionEvent e) { 119 if (MainFrame.getExitOnClose()) { 120 System.exit(0); 121 } else { 122 stop(); 123 enableOK(); 124 enableClose(); 125 reset(); 126 try { 127 Class cls = Class.forName("javax.swing.JFrame"); JFrame frame = (JFrame ) SwingUtilities.getAncestorOfClass(cls, resultsPanel); 129 frame.setVisible(false); 130 131 } catch (ClassNotFoundException ex) { 133 ex.getMessage(); 135 } 136 } 137 } 138 }); 139 } 140 141 144 public ControlPanel getVerifierControlPanel() { 145 return verifierControls; 146 } 147 148 public void setJarFilename(String jarFileName) { 149 if (jarFileName != null) { 151 File jarFile = new File (jarFileName); 152 if (jarFile.exists()) { 153 getVerifierControlPanel().addJarFile(jarFile); 154 } 155 } 156 } 157 158 private Verifier getVerifier() { 159 return verifier; 160 } 161 162 public void reset() { 163 resultsPanel.clearOldResults(); 164 resultsPanel.clearResults(); 165 verifierControls.removeAllJarFiles(); 166 } 167 168 public void setStatus(String stat) { 169 statusLabel.setText(stat); 170 } 171 172 public Enumeration getFileList() { 173 return verifierControls.listModel.elements(); 174 } 175 176 public void clearResults() { 177 resultsPanel.clearResults(); 178 } 179 180 void disableOK() { 181 verifierControls.okButton.setEnabled(false); 182 } 183 184 void enableOK() { 185 verifierControls.okButton.setEnabled(true); 186 } 187 188 void disableClose() { 189 verifierControls.closeButton.setEnabled(false); 190 } 191 192 void enableClose() { 193 verifierControls.closeButton.setEnabled(true); 194 } 195 196 public void start() { 197 198 if (running == null) { 199 components = getFileList(); 200 clearResults(); 201 running = new Thread (this); 202 running.setPriority(Thread.MIN_PRIORITY); 203 running.start(); 204 } 205 } 206 207 public void stop() { 208 if (running != null) { 209 running = null; 210 setStatus((smh.getLocalString 211 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".Status_Closed", "Closed"))); } 215 } 216 217 public void run() { 218 try { 219 disableOK(); 220 221 while (components.hasMoreElements() && running != null) { 222 File jarFile = ((File ) components.nextElement()); 223 String jarName = ((jarFile).getPath()); 224 try { 225 setStatus((smh.getLocalString 226 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".Status_Verifying", "Verifying archive {0}...", new Object []{jarName}))); 230 ResultManager resultManager = getVerifier().verify(jarName); 231 Iterator itr = resultManager.getError().iterator(); 232 while (itr.hasNext()) { 233 LogRecord log = (LogRecord ) itr.next(); 234 log.setLoggerName(jarFile.getName()); 235 resultsPanel.addError(log); 236 } 237 setStatus((smh.getLocalString 238 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".Status_WritingReport", "Writing report..."))); verifier.generateReports(); 242 243 if (resultManager.getFailedCount() + 244 resultManager.getErrorCount() == 245 0) { resultsPanel.addDetailText((smh.getLocalString 247 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".AllTestsPassed", "{0}: All tests passed.", new Object []{jarFile.getName()})) + 251 "\n"); } else { 253 resultsPanel.addDetailText((smh.getLocalString 254 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".SomeTestsFailed", "{0}: Some tests failed.", new Object []{jarFile.getName()})) + 258 "\n"); } 260 261 } catch (Throwable t) { 262 JOptionPane.showMessageDialog(this, 263 (smh.getLocalString 264 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".ErrorLoading", "Error verifying {0}: {1}", new Object []{jarName, t.getMessage()}))); 268 resultsPanel.addDetailText((smh.getLocalString 269 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".ErrorLoading", "Error verifying {0}: {1}", new Object []{jarName, t.getMessage()})) + 273 "\n"); } 275 } 276 277 setStatus((smh.getLocalString 278 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + ".Status_Idle", "Idle"))); enableOK(); 282 enableClose(); 283 } finally { 284 running = null; 285 } 286 } 287 } 288 | Popular Tags |