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

📄 eventmanagerregister.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002, 2004                                        *//*                                                                           *//* 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 javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import com.ibm.staf.*;import com.ibm.staf.service.*;public class EventManagerRegister extends JFrame implements ActionListener{    JTextField eventManagerServiceMachineTF;    JTextField eventManagerServiceNameTF;    JTextField machineTF;    JCheckBox pythonMachine;    JTextField serviceTF;    JCheckBox pythonService;    JTextField requestTF;    JCheckBox pythonRequest;    JTextField typeTF;    JTextField subtypeTF;    JTextArea prepareTA;    JTextField descriptionTF;    JButton registerButton;    STAFHandle fHandle;    public EventManagerRegister()    {        try        {            fHandle = new STAFHandle("STAF/EventManager/Register");        }        catch (STAFException e)        {            System.out.println("STAF must be running to execute " +                               "EventManagerRegister");            System.exit(0);        }        JPanel optionsPanel = new JPanel();        GridBagLayout gbl = new GridBagLayout();        GridBagConstraints gbc = new GridBagConstraints();        optionsPanel.setLayout(gbl);        JLabel eventManagerServiceMachineLabel =            new JLabel("EventManager Service Machine:");        eventManagerServiceMachineLabel.setOpaque(true);        eventManagerServiceMachineLabel.setForeground(Color.black);        gbc.anchor = GridBagConstraints.NORTHWEST;        optionsPanel.add(eventManagerServiceMachineLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        eventManagerServiceMachineTF = new JTextField(20);        eventManagerServiceMachineTF.setText("local");        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(eventManagerServiceMachineTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel eventManagerServiceNameLabel =            new JLabel("EventManager Service Name:");        eventManagerServiceNameLabel.setOpaque(true);        eventManagerServiceNameLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(eventManagerServiceNameLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        eventManagerServiceNameTF = new JTextField(20);        eventManagerServiceNameTF.setText("EventManager");        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(eventManagerServiceNameTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel machineLabel = new JLabel("Target Machine:");        machineLabel.setOpaque(true);        machineLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(machineLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        pythonMachine = new JCheckBox("Python", false);        gbc.gridwidth = 1;        optionsPanel.add(pythonMachine, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        machineTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(machineTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel serviceLabel = new JLabel("Target Service:");        serviceLabel.setOpaque(true);        serviceLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(serviceLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        pythonService = new JCheckBox("Python", false);        gbc.gridwidth = 1;        optionsPanel.add(pythonService, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        serviceTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(serviceTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel requestLabel = new JLabel("Target Request:");        requestLabel.setOpaque(true);        requestLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(requestLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        pythonRequest = new JCheckBox("Python", false);        gbc.gridwidth = 1;        optionsPanel.add(pythonRequest, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        requestTF = new JTextField(40);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(requestTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel typeLabel = new JLabel("Event Type:");        typeLabel.setOpaque(true);        typeLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(typeLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        typeTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(typeTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel subtypeLabel = new JLabel("Event SubType:");        subtypeLabel.setOpaque(true);        subtypeLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(subtypeLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        subtypeTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(subtypeTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel prepareLabel = new JLabel("Prepare Script:");        prepareLabel.setOpaque(true);        prepareLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(prepareLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        prepareTA = new JTextArea(5, 40);        prepareTA.setBorder(new BevelBorder(BevelBorder.LOWERED));        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(prepareTA, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(6), gbc);                JLabel descriptionLabel = new JLabel("Description:");        descriptionLabel.setOpaque(true);        descriptionLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(descriptionLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        descriptionTF = new JTextField(45);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(descriptionTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);                JPanel outerPanel = new JPanel();        outerPanel.setLayout(new BorderLayout());        outerPanel.setBorder(new TitledBorder("EventManager Register options"));        outerPanel.add(BorderLayout.CENTER, new JScrollPane(optionsPanel));        JPanel buttonPanel = new JPanel();        buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));        registerButton = new JButton("Register");        registerButton.addActionListener(this);        buttonPanel.add(registerButton);        outerPanel.add(BorderLayout.SOUTH, buttonPanel);        getContentPane().add(outerPanel);        setTitle("EventManager Register");        pack();        setSize(new Dimension(730, 400));        show();        addWindowListener(new WindowAdapter()        {            public void windowClosing(WindowEvent e)            {                System.exit(0);            }        });    }    public static void main(String argv[])    {        new EventManagerRegister();    }    public void actionPerformed(ActionEvent e)    {        if (e.getSource() == registerButton)        {            String machine = eventManagerServiceMachineTF.getText();            String service = eventManagerServiceNameTF.getText();            String request = "register ";            if (machineTF.getText().equals(""))            {                JOptionPane.showMessageDialog(this,                    "You must specify a value for Target Machine",                    "Target Machine not specified", JOptionPane.ERROR_MESSAGE);                return;            }            if (serviceTF.getText().equals(""))            {                JOptionPane.showMessageDialog(this,                    "You must specify a value for Target Service",                    "Target Service not specified", JOptionPane.ERROR_MESSAGE);                return;            }            if (requestTF.getText().equals(""))            {                JOptionPane.showMessageDialog(this,                    "You must specify a value for Target Request",                    "Target Request not specified", JOptionPane.ERROR_MESSAGE);                return;            }            if (typeTF.getText().equals(""))            {                JOptionPane.showMessageDialog(this,                    "You must specify a value for Event Type",                    "Event Type not specified", JOptionPane.ERROR_MESSAGE);                return;            }            if (pythonMachine.isSelected())            {                request += "pythonmachine " +                    STAFUtil.wrapData(machineTF.getText()) + " ";            }            else            {                request += "machine " +                    STAFUtil.wrapData(machineTF.getText()) + " ";            }            if (pythonService.isSelected())            {                request += "pythonservice " +                    STAFUtil.wrapData(serviceTF.getText()) + " ";            }            else            {                request += "service " +                    STAFUtil.wrapData(serviceTF.getText()) + " ";            }            if (pythonRequest.isSelected())            {                request += "pythonrequest " +                    STAFUtil.wrapData(requestTF.getText()) + " ";            }            else            {                request += "request " +                    STAFUtil.wrapData(requestTF.getText()) + " ";            }            request += "type " + STAFUtil.wrapData(typeTF.getText()) + " ";            if (!subtypeTF.getText().equals(""))            {                request += "subtype " + STAFUtil.wrapData(subtypeTF.getText());            }            if (!descriptionTF.getText().equals(""))            {                request += "description " +                    STAFUtil.wrapData(descriptionTF.getText());            }            if (!(prepareTA.getText().equals("")))            {                request += " prepare " +                    STAFUtil.wrapData(prepareTA.getText());            }            STAFResult result =                fHandle.submit2(machine, service, request);            if (result.rc != 0)            {                showErrorDialog("An error was encountered while "                                + "attempting to register"                                + " rc=" + result.rc                                + " result=" + result.result);            }            else            {                JOptionPane.showMessageDialog(this,                    "Sucessfully registered.  ID = " + result.result,                    "Sucessfully registerd",                    JOptionPane.INFORMATION_MESSAGE);            }        }    }    public void showErrorDialog(String message)    {        JTextPane messagePane = new JTextPane();        messagePane.setFont(new Font("Dialog", Font.BOLD, 12));        messagePane.setEditable(false);        messagePane.setText(message);        messagePane.select(0,0);        JScrollPane scrollPane = new JScrollPane(messagePane);        scrollPane.setPreferredSize(new Dimension(400, 100));        JOptionPane.showMessageDialog(this, scrollPane,                                      "EventManager Error",                                      JOptionPane.ERROR_MESSAGE);    }}

⌨️ 快捷键说明

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