FileDocCategorySizeDatePackage
MainPanel.javaAPI DocGlassfish v2 API12268Fri May 04 22:33:26 BST 2007com.sun.enterprise.tools.verifier.gui

MainPanel

public class MainPanel extends JPanel implements Runnable

Fields Summary
static com.sun.enterprise.util.LocalStringManagerImpl
smh
ResultsPanel
resultsPanel
ControlPanel
verifierControls
JLabel
statusLabel
com.sun.enterprise.tools.verifier.Verifier
verifier
Enumeration
components
Thread
running
Constructors Summary
public MainPanel(JFrame parent)
This is the top-level panel of the Verifier GUI


                  
       
        this(parent, null, null);
    
public MainPanel(JFrame parent, String jarFileName, com.sun.enterprise.tools.verifier.Verifier verifier)

        super(new BorderLayout(), true);

        // 508 compliance
        this.getAccessibleContext().setAccessibleName(smh.getLocalString
                ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                ".panelName", // NOI18N
                        "Panel")); // NOI18N
        this.getAccessibleContext().setAccessibleDescription(smh.getLocalString
                ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                ".PanelDesc", // NOI18N
                        "This is a panel")); // NOI18N
        statusLabel.getAccessibleContext().setAccessibleName(smh.getLocalString
                ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                ".labelName", // NOI18N
                        "Label")); // NOI18N
        statusLabel.getAccessibleContext().setAccessibleDescription
                (smh.getLocalString("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                ".labelDesc", // NOI18N
                        "This is a label")); // NOI18N

        //verifier.setFrame(parent);
        verifierControls = new ControlPanel(parent);
        // set the initial jar in file list
        setJarFilename(jarFileName);
        this.verifier = verifier;

        add("North", verifierControls); // NOI18N
        add("Center", resultsPanel); // NOI18N
        add("South", statusLabel); // NOI18N


        verifierControls.okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (getFileList().hasMoreElements()) {
                    resultsPanel.clearOldResults();
                    start();
                } else {
                    JOptionPane.showMessageDialog(verifierControls, (smh.getLocalString
                            ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                            ".optionPane.okButtonNoFiles", // NOI18N
                                    "You must first select file to verify.")) + // NOI18N
                            "\n" + // NOI18N
                            (smh.getLocalString
                            ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                            ".optionPane.okButtonNoFiles2", // NOI18N
                                    "Use the Add button to select file to be verified," + // NOI18N
                            " then click on OK button."))); // NOI18N
                }
            }
        });

        verifierControls.closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (MainFrame.getExitOnClose()) {
                    System.exit(0);
                } else {
                    stop();
                    enableOK();
                    enableClose();
                    reset();
                    try {
                        Class cls = Class.forName("javax.swing.JFrame"); // NOI18N
                        JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(cls, resultsPanel);
                        frame.setVisible(false);

                        //frame.dispose();
                    } catch (ClassNotFoundException ex) {
                        // ??can this happen
                        ex.getMessage();
                    }
                }
            }
        });
    
Methods Summary
public voidclearResults()

        resultsPanel.clearResults();
    
voiddisableClose()

        verifierControls.closeButton.setEnabled(false);
    
voiddisableOK()

        verifierControls.okButton.setEnabled(false);
    
voidenableClose()

        verifierControls.closeButton.setEnabled(true);
    
voidenableOK()

        verifierControls.okButton.setEnabled(true);
    
public java.util.EnumerationgetFileList()

        return verifierControls.listModel.elements();
    
private com.sun.enterprise.tools.verifier.VerifiergetVerifier()

        return verifier;
    
public ControlPanelgetVerifierControlPanel()
Retrieve the verifierControls panel of the Verifier GUI

        return verifierControls;
    
public voidreset()

        resultsPanel.clearOldResults();
        resultsPanel.clearResults();
        verifierControls.removeAllJarFiles();
    
public voidrun()

        try {
            disableOK();

            while (components.hasMoreElements() && running != null) {
                File jarFile = ((File) components.nextElement());
                String jarName = ((jarFile).getPath());
                try {
                    setStatus((smh.getLocalString
                            ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                            ".Status_Verifying", // NOI18N
                                    "Verifying archive {0}...", // NOI18N
                                    new Object[]{jarName})));
                    ResultManager resultManager = getVerifier().verify(jarName);
                    Iterator itr = resultManager.getError().iterator();
                    while (itr.hasNext()) {
                        LogRecord log = (LogRecord) itr.next();
                        log.setLoggerName(jarFile.getName());
                        resultsPanel.addError(log);
                    }
                    setStatus((smh.getLocalString
                            ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                            ".Status_WritingReport", // NOI18N
                                    "Writing report..."))); // NOI18N
                    verifier.generateReports();

                    if (resultManager.getFailedCount() +
                            resultManager.getErrorCount() ==
                            0) { // this code might not be called
                        resultsPanel.addDetailText((smh.getLocalString
                                ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                                ".AllTestsPassed", // NOI18N
                                        "{0}: All tests passed.", // NOI18N
                                        new Object[]{jarFile.getName()})) +
                                "\n"); // NOI18N
                    } else {
                        resultsPanel.addDetailText((smh.getLocalString
                                ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                                ".SomeTestsFailed", // NOI18N
                                        "{0}: Some tests failed.", // NOI18N
                                        new Object[]{jarFile.getName()})) +
                                "\n"); // NOI18N
                    }

                } catch (Throwable t) {
                    JOptionPane.showMessageDialog(this,
                            (smh.getLocalString
                            ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                            ".ErrorLoading", // NOI18N
                                    "Error verifying {0}: {1}", // NOI18N
                                    new Object[]{jarName, t.getMessage()})));
                    resultsPanel.addDetailText((smh.getLocalString
                            ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                            ".ErrorLoading", // NOI18N
                                    "Error verifying {0}: {1}", // NOI18N
                                    new Object[]{jarName, t.getMessage()})) +
                            "\n"); // NOI18N
                }
            }

            setStatus((smh.getLocalString
                    ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                    ".Status_Idle", // NOI18N
                            "Idle"))); // NOI18N
            enableOK();
            enableClose();
        } finally {
            running = null;
        }
    
public voidsetJarFilename(java.lang.String jarFileName)

        // set the initial jar in file list
        if (jarFileName != null) {
            File jarFile = new File(jarFileName);
            if (jarFile.exists()) {
                getVerifierControlPanel().addJarFile(jarFile);
            }
        }
    
public voidsetStatus(java.lang.String stat)

        statusLabel.setText(stat);
    
public voidstart()


        if (running == null) {
            components = getFileList();
            clearResults();
            running = new Thread(this);
            running.setPriority(Thread.MIN_PRIORITY);
            running.start();
        }
    
public voidstop()

        if (running != null) {
            running = null;
            setStatus((smh.getLocalString
                    ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
                    ".Status_Closed", // NOI18N
                            "Closed"))); // NOI18N
        }