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

📄 cronregister.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.cron;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 CronRegister extends JFrame implements ActionListener{    JTextField cronServiceMachineTF;    JTextField cronServiceNameTF;    JTextField machineTF;    JCheckBox pythonMachine;    JTextField serviceTF;    JCheckBox pythonService;    JTextField requestTF;    JCheckBox pythonRequest;    JTextArea prepareTA;    JTextField minuteTF;    JTextField hourTF;    JTextField dayTF;    JTextField monthTF;    JTextField weekdayTF;    JButton registerButton;    STAFHandle fHandle;    public CronRegister()    {        try        {            fHandle = new STAFHandle("STAF/Cron/Register");        }        catch (STAFException e)        {            System.out.println("STAF must be running to execute " +                               "CronRegister");            System.exit(0);        }        JPanel optionsPanel = new JPanel();        GridBagLayout gbl = new GridBagLayout();        GridBagConstraints gbc = new GridBagConstraints();        optionsPanel.setLayout(gbl);        JLabel cronServiceMachineLabel = new JLabel("Cron Service Machine:");        cronServiceMachineLabel.setOpaque(true);        cronServiceMachineLabel.setForeground(Color.black);        gbc.anchor = GridBagConstraints.NORTHWEST;        optionsPanel.add(cronServiceMachineLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        cronServiceMachineTF = new JTextField(20);        cronServiceMachineTF.setText("local");        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(cronServiceMachineTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel cronServiceNameLabel = new JLabel("Cron Service Name:");        cronServiceNameLabel.setOpaque(true);        cronServiceNameLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(cronServiceNameLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        cronServiceNameTF = new JTextField(20);        cronServiceNameTF.setText("Cron");        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(cronServiceNameTF, 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 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(3), gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel minuteLabel = new JLabel("Minute:");        minuteLabel.setOpaque(true);        minuteLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(minuteLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        minuteTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(minuteTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel hourLabel = new JLabel("Hour:");        hourLabel.setOpaque(true);        hourLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(hourLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        hourTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(hourTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel dayLabel = new JLabel("Day:");        dayLabel.setOpaque(true);        dayLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(dayLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        dayTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(dayTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel monthLabel = new JLabel("Month:");        monthLabel.setOpaque(true);        monthLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(monthLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        monthTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(monthTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JLabel weekdayLabel = new JLabel("Weekday:");        weekdayLabel.setOpaque(true);        weekdayLabel.setForeground(Color.black);        gbc.gridwidth = 1;        optionsPanel.add(weekdayLabel, gbc);        optionsPanel.add(Box.createHorizontalStrut(10), gbc);        weekdayTF = new JTextField(20);        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.weightx = 1.0;        optionsPanel.add(weekdayTF, gbc);        gbc.weightx = 0;        optionsPanel.add(Box.createVerticalStrut(3), gbc);        JPanel outerPanel = new JPanel();        outerPanel.setLayout(new BorderLayout());        outerPanel.setBorder(new TitledBorder("Cron 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("Cron Register");        pack();        setSize(new Dimension(730, 440));        show();        addWindowListener(new WindowAdapter()        {            public void windowClosing(WindowEvent e)            {                System.exit(0);            }        });    }    public static void main(String argv[])    {        new CronRegister();    }    public void actionPerformed(ActionEvent e)    {        if (e.getSource() == registerButton)        {            String machine = cronServiceMachineTF.getText();            String service = cronServiceNameTF.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 (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()) + " ";            }            if (!(prepareTA.getText().equals("")))            {                request += "prepare " + STAFUtil.wrapData(prepareTA.getText());            }            if (!(minuteTF.getText().equals("")))            {                request += "minute " + STAFUtil.wrapData(minuteTF.getText());            }            if (!(hourTF.getText().equals("")))            {                request += "hour " + STAFUtil.wrapData(hourTF.getText());            }            if (!(dayTF.getText().equals("")))            {                request += "day " + STAFUtil.wrapData(dayTF.getText());            }            if (!(monthTF.getText().equals("")))            {                request += "month " + STAFUtil.wrapData(monthTF.getText());            }            if (!(weekdayTF.getText().equals("")))            {                request += "weekday " + STAFUtil.wrapData(weekdayTF.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,                                      "Cron Error",                                      JOptionPane.ERROR_MESSAGE);    }}

⌨️ 快捷键说明

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