⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventmanagerui.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2006                                              *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf.service.eventmanager;import java.awt.*;import java.awt.event.*;import java.util.*;import java.io.*;import javax.swing.*;import javax.swing.table.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.plaf.metal.*;import com.ibm.staf.*;import com.ibm.staf.service.*;public class EventManagerUI extends JFrame implements ActionListener,                                                         MouseListener,                                                         KeyListener{    JMenuBar fMenuBar;    JMenu fFileMenu;    JMenuItem fFileExit;    JMenuItem fFileNew;    JMenu fViewMenu;    JMenuItem fViewRefresh;    JMenuItem fViewServiceLogLast100;    JMenuItem fViewServiceLogForID;    JMenuItem fViewServiceLogForSubmittedCommand;    JMenuItem fViewEntireServiceLog;    JMenuItem fViewDeleteServiceLog;    JMenu fSelectedMenu;    JMenuItem fSelectedEdit;    JMenuItem fSelectedTrigger;    JMenuItem fSelectedTriggerWithScript;    JMenuItem fSelectedCopyToNewRegistration;    JMenuItem fSelectedUnregister;    JMenu fHelpMenu;    JMenuItem fHelpAbout;    JLabel fInstructionLabel;    JLabel fRegistrationIDLabel;    JTextField fServiceMachineTF = new JTextField(15);    JTextField fServiceNameTF = new JTextField(8);    JTextField fDescriptionTF;    JTextField fMachineTF;    JCheckBox fPythonMachine;    JTextField fServiceTF;    JCheckBox fPythonService;    JTextField fRequestTF;    JCheckBox fPythonRequest;    JTextArea fPrepareTA;    JTextField fTypeTF;    JTextField fSubtypeTF;    JButton fRegisterButton;    JButton fCancelButton;    JDialog fRegistrationDialog;    java.util.List fEntryList;    JTable fIDTable;    Vector fColumnNames;    STAFHandle fHandle;    JPopupMenu fPopupMenu = new JPopupMenu();    JMenuItem fPopupMenuEdit = new JMenuItem("Edit");    JMenuItem fPopupMenuTrigger = new JMenuItem("Trigger");    JMenuItem fPopupMenuTriggerWithScript =        new JMenuItem("Trigger with script...");    JMenuItem fPopupMenuCopyToNewRegistration =        new JMenuItem("Copy to new registration");    JMenuItem fPopupMenuUnregister = new JMenuItem("Unregister");    JTextArea fScriptTextArea;    JButton fScriptTriggerButton;    JButton fScriptCancelButton;    JDialog fScriptDialog;    JDialog fStafCommandsDialog;    JComboBox fStafCommands;    JButton fStafCommandsOkButton;    JButton fStafCommandsCancelButton;    public EventManagerUI()    {        try        {            fHandle = new STAFHandle("STAF/EventManager/UI");        }        catch (STAFException e)        {            System.out.println("STAF must be running to execute " +                               "EventManagerUI");            System.exit(0);        }        UIManager.put("Table.focusCellHighlightBorder", "none");        fServiceMachineTF.setText("local");        fServiceNameTF.setText("EventManager");        Vector idData = getRegistrationTable();        JPanel idPanel = new JPanel();        idPanel.setLayout(new BorderLayout());        fMenuBar = new JMenuBar();        fFileMenu = new JMenu("File");        fFileNew = new JMenuItem("New Registration...");        fFileMenu.add(fFileNew);        fFileNew.addActionListener(this);        fFileExit = new JMenuItem("Exit");        fFileMenu.add(fFileExit);        fFileExit.addActionListener(this);        fMenuBar.add(fFileMenu);        fViewMenu = new JMenu("View");        fViewRefresh = new JMenuItem("Refresh");        fViewMenu.add(fViewRefresh);        fViewRefresh.addActionListener(this);        fViewMenu.insertSeparator(3);        fViewServiceLogForID = new JMenuItem("Service Log for ID...");        fViewMenu.add(fViewServiceLogForID);        fViewServiceLogForID.addActionListener(this);        fViewServiceLogLast100 = new JMenuItem("Service Log last 100 records");        fViewMenu.add(fViewServiceLogLast100);        fViewServiceLogLast100.addActionListener(this);        fViewServiceLogForSubmittedCommand = new            JMenuItem("Service Log for submitted STAF command...");        fViewMenu.add(fViewServiceLogForSubmittedCommand);        fViewServiceLogForSubmittedCommand.addActionListener(this);        fViewEntireServiceLog = new JMenuItem("Entire Service Log");        fViewMenu.add(fViewEntireServiceLog);        fViewEntireServiceLog.addActionListener(this);        fViewDeleteServiceLog = new JMenuItem("Delete Service Log");        fViewMenu.add(fViewDeleteServiceLog);        fViewDeleteServiceLog.addActionListener(this);        fMenuBar.add(fViewMenu);        fSelectedMenu = new JMenu("Selected");        fSelectedMenu.setEnabled(false);        fSelectedEdit = new JMenuItem("Edit");        fSelectedMenu.add(fSelectedEdit);        fSelectedEdit.addActionListener(this);        fSelectedTrigger = new JMenuItem("Trigger");        fSelectedMenu.add(fSelectedTrigger);        fSelectedTrigger.addActionListener(this);        fSelectedTriggerWithScript = new JMenuItem("Trigger with script...");        fSelectedMenu.add(fSelectedTriggerWithScript);        fSelectedTriggerWithScript.addActionListener(this);        fSelectedCopyToNewRegistration =            new JMenuItem("Copy to new registration");        fSelectedMenu.add(fSelectedCopyToNewRegistration);        fSelectedCopyToNewRegistration.addActionListener(this);        fSelectedUnregister = new JMenuItem("Unregister");        fSelectedMenu.add(fSelectedUnregister);        fSelectedUnregister.addActionListener(this);        fMenuBar.add(fSelectedMenu);        fHelpMenu = new JMenu("Help");        fHelpAbout = new JMenuItem("About");        fHelpMenu.add(fHelpAbout);        fHelpAbout.addActionListener(this);        fMenuBar.add(fHelpMenu);        JPanel servicePanel = new JPanel();        servicePanel.setLayout(new FlowLayout(FlowLayout.LEFT));        JLabel serviceMachineLabel = new JLabel("Service Machine:");        serviceMachineLabel.setOpaque(true);        serviceMachineLabel.setForeground(Color.black);        servicePanel.add(serviceMachineLabel);        servicePanel.add(fServiceMachineTF);        fServiceMachineTF.addKeyListener(this);        JLabel serviceNameLabel = new JLabel("Service Name:");        serviceNameLabel.setOpaque(true);        serviceNameLabel.setForeground(Color.black);        servicePanel.add(serviceNameLabel);        servicePanel.add(fServiceNameTF);        fServiceNameTF.addKeyListener(this);        idPanel.add(BorderLayout.NORTH, servicePanel);        this.setJMenuBar(fMenuBar);        fColumnNames = new Vector();        fColumnNames.add("ID");        fColumnNames.add("Description");        fColumnNames.add("Machine");        fColumnNames.add("Service");        fColumnNames.add("Request");        RegisterModel regModel = new RegisterModel(idData, fColumnNames);        fIDTable = new JTable();        fIDTable.setModel(regModel);        fIDTable.setCellSelectionEnabled(false);        fIDTable.setRowSelectionAllowed(true);        fIDTable.addMouseListener(this);        fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);        fIDTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);        fIDTable.getColumnModel().getColumn(1).setPreferredWidth(150);        fIDTable.getColumnModel().getColumn(2).setPreferredWidth(30);        fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);        fIDTable.getColumnModel().getColumn(4).setPreferredWidth(265);        fPopupMenu.add(fPopupMenuEdit);        fPopupMenuEdit.addActionListener(this);        fPopupMenu.add(fPopupMenuTrigger);        fPopupMenuTrigger.addActionListener(this);        fPopupMenu.add(fPopupMenuTriggerWithScript);        fPopupMenuTriggerWithScript.addActionListener(this);        fPopupMenu.add(fPopupMenuCopyToNewRegistration);        fPopupMenuCopyToNewRegistration.addActionListener(this);        fPopupMenu.add(fPopupMenuUnregister);        fPopupMenuUnregister.addActionListener(this);        idPanel.add(BorderLayout.CENTER, new JScrollPane(fIDTable));        fInstructionLabel = new JLabel();        setInstructionLabel(idData);        idPanel.add(BorderLayout.SOUTH, fInstructionLabel);        getContentPane().add(idPanel);        setTitle("EventManagerUI");        pack();        setSize(new Dimension(750, 450));        show();        addWindowListener(new WindowAdapter()        {            public void windowClosing(WindowEvent e)            {                System.exit(0);            }        });    }    public void setInstructionLabel(Vector idData)    {        if (idData == null)        {            fInstructionLabel.setText("Enter a valid Service Machine" +                " and Service Name");        }        else if (idData.size() == 0)        {            fInstructionLabel.setText("Click on File -> New Registration..." +                " in the menu bar to register a new STAF command");        }        else        {            fInstructionLabel.setText("Double click on an existing " +                "registration to edit");        }    }    public static void main(String argv[])    {        new EventManagerUI();    }    public void actionPerformed(ActionEvent e)    {        if (e.getSource() == fFileExit)        {            System.exit(0);        }        else if (e.getSource() == fFileNew)        {            displayfRegistrationDialog();            fRegistrationDialog.show();        }        else if (e.getSource() == fHelpAbout)        {            String machine = fServiceMachineTF.getText();            String service = fServiceNameTF.getText();            STAFResult res = fHandle.submit2(machine,                                             service.toUpperCase(),                                             "VERSION");            if (res.rc == 0)            {                JOptionPane.showMessageDialog(this, service + " version " +                    res.result, service.toUpperCase() + " VERSION " +                    res.result, JOptionPane.INFORMATION_MESSAGE);            }            else            {                System.out.println(                    "Error service version " +                    "on machine " + machine + ".  RC=" + res.rc +                    ", Result=" + res.result);            }        }        else if (e.getSource() == fViewRefresh)        {            Vector idData = getRegistrationTable();            setInstructionLabel(idData);            ((RegisterModel)(fIDTable.getModel())).setDataVector(idData,                                                                fColumnNames);            fIDTable.getColumnModel().getColumn(0).setMaxWidth(40);            fIDTable.getColumnModel().getColumn(0).setPreferredWidth(40);            fIDTable.getColumnModel().getColumn(1).setPreferredWidth(150);            fIDTable.getColumnModel().getColumn(2).setPreferredWidth(30);            fIDTable.getColumnModel().getColumn(3).setPreferredWidth(30);            fIDTable.getColumnModel().getColumn(4).setPreferredWidth(265);            fSelectedMenu.setEnabled(false);        }        else if (e.getSource() == fViewServiceLogForID)        {            String id = JOptionPane.showInputDialog(this,                "Enter the registration ID", "View Service log for ID",                JOptionPane.QUESTION_MESSAGE);            if (id == null) return;            String machine = fServiceMachineTF.getText();            String service = fServiceNameTF.getText();            String serviceMachineNickname = "";            // Get EventManager Machine nickname            STAFResult res = fHandle.submit2(machine, "VAR",                "RESOLVE STRING {STAF/Config/MachineNickname}");            if (res.rc == 0)            {                serviceMachineNickname = res.result;            }            else            {                System.out.println(                    "Error resolving string {STAF/Config/MachineNickname} " +                    "on machine " + serviceMachineNickname + ".  RC=" + res.rc +                    ", Result=" + res.result);            }            String queryRequest = " QUERY MACHINE " + serviceMachineNickname +                " LOGNAME " + service + " CONTAINS " +                STAFUtil.wrapData("[ID=" + id + "]");            STAFLogViewer logViewer = new STAFLogViewer(this,                                                        fHandle,                                                        machine,                                                        "LOG",                                                        queryRequest,                                                        "",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -