home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / platsdk / inetwork.exe / TAPI-S.cab / 92newdlg.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  12.9 KB  |  377 lines

  1. /************************************************************************
  2.  * NewDlg (by John W. Gibbs)
  3.  *
  4.  * Copyright (c) 1997 Microsoft Corporation, All Rights Reserved.
  5.  ***********************************************************************/
  6.  
  7. import java.awt.*;
  8. import java.util.*;
  9. import com.ms.com.*;
  10. import com.ms.ui.*;
  11. import rend.*;
  12. import sdpblb.*;
  13. import NewCtrls;
  14.  
  15.  
  16. /////////////////////////////////////////////////////////////////////////
  17. //  CLASS: NewDlg
  18. //
  19. //  PURPOSE: Supporting class to JT3Conf
  20. //  DATE:    July 24, 1997
  21. //
  22. //  DESCRIPTION:
  23. //      Dialog that allows the user to enter specifications for a
  24. //      conference and then create it using the Rendezvous Controls.
  25. //
  26. /////////////////////////////////////////////////////////////////////////
  27.  
  28. public class NewDlg extends Dialog
  29. {
  30.     // Dialog title.
  31.     public static final String DLG_TITLE = "New Conference";
  32.  
  33.     // Button ids.
  34.     public static final int NONE   = 0;
  35.     public static final int CREATE = 1;
  36.     public static final int CANCEL = 2;
  37.  
  38.     // Resource Wizard generated UI.
  39.     private final NewCtrls ctrls = new NewCtrls(this);
  40.  
  41.     // Parent frame of the dlg.
  42.     private Frame m_ParentFrame = null;
  43.  
  44.     // The conference directory component.
  45.     private ITConferenceDirectory m_Directory = null;
  46.  
  47.     // The conference that is created.
  48.     private ITConference m_Conference = null;
  49.  
  50.     // The button that was use to close the dialog.
  51.     private int m_ButtonId = NONE;
  52.  
  53.     // Conference data fields.
  54.     public String m_strConfName = "";
  55.     public String m_strDesc = "";
  56.     public String m_strUserName = "";
  57.  
  58.     public short  m_nStartYear = 1997;
  59.     public byte   m_nStartMonth = 7;
  60.     public byte   m_nStartDay = 1;
  61.     public byte   m_nStartHour = 8;
  62.     public byte   m_nStartMinute = 0;
  63.  
  64.     public short  m_nStopYear = 2000;
  65.     public byte   m_nStopMonth = 7;
  66.     public byte   m_nStopDay = 1;
  67.     public byte   m_nStopHour = 8;
  68.     public byte   m_nStopMinute= 0;
  69.  
  70.  
  71.     /////////////////////////////////////////////////////////////////////
  72.     // Constructor
  73.     /////////////////////////////////////////////////////////////////////
  74.     public NewDlg(Frame parent, ITConferenceDirectory directory)
  75.     {
  76.         super(parent, DLG_TITLE, true);
  77.  
  78.         // select a font to use (ctrls needs this)
  79.         Font font = new Font("Dialog", Font.PLAIN, 8);
  80.         this.setFont(font);
  81.  
  82.         // create the UI generated by the Resource Wizard
  83.         ctrls.CreateControls();
  84.  
  85.         // initialize controls
  86.         ctrls.cmbStartMonth.addItem("January");
  87.         ctrls.cmbStartMonth.addItem("February");
  88.         ctrls.cmbStartMonth.addItem("March");
  89.         ctrls.cmbStartMonth.addItem("April");
  90.         ctrls.cmbStartMonth.addItem("May");
  91.         ctrls.cmbStartMonth.addItem("June");
  92.         ctrls.cmbStartMonth.addItem("July");
  93.         ctrls.cmbStartMonth.addItem("August");
  94.         ctrls.cmbStartMonth.addItem("September");
  95.         ctrls.cmbStartMonth.addItem("October");
  96.         ctrls.cmbStartMonth.addItem("November");
  97.         ctrls.cmbStartMonth.addItem("December");
  98.  
  99.         ctrls.cmbStopMonth.addItem("January");
  100.         ctrls.cmbStopMonth.addItem("February");
  101.         ctrls.cmbStopMonth.addItem("March");
  102.         ctrls.cmbStopMonth.addItem("April");
  103.         ctrls.cmbStopMonth.addItem("May");
  104.         ctrls.cmbStopMonth.addItem("June");
  105.         ctrls.cmbStopMonth.addItem("July");
  106.         ctrls.cmbStopMonth.addItem("August");
  107.         ctrls.cmbStopMonth.addItem("September");
  108.         ctrls.cmbStopMonth.addItem("October");
  109.         ctrls.cmbStopMonth.addItem("November");
  110.         ctrls.cmbStopMonth.addItem("December");
  111.  
  112.         UpdateData(true);
  113.  
  114.         // get parent frame to use for message boxes
  115.         m_ParentFrame = parent;
  116.  
  117.         // save conference directory
  118.         m_Directory = directory;
  119.     }
  120.  
  121.     /////////////////////////////////////////////////////////////////////
  122.     // action
  123.     //
  124.     // Event.ACTION_EVENT event handler.
  125.     /////////////////////////////////////////////////////////////////////
  126.     public boolean action(Event evt, Object arg)
  127.     {
  128.         if (arg.equals("Create")) {
  129.             // create button pressed
  130.             UpdateData(false);
  131.             if (ValidateData()) {
  132.                 m_Conference = CreateTheConference();
  133.                 m_ButtonId = CREATE;
  134.                 this.dispose();
  135.             }
  136.         }
  137.         else if (arg.equals("Cancel")) {
  138.             // cancel button pressed
  139.             m_ButtonId = CANCEL;
  140.             this.dispose();
  141.         }
  142.         else
  143.             return super.action(evt, arg);
  144.         return true;
  145.     }
  146.  
  147.     /////////////////////////////////////////////////////////////////////
  148.     // GetConference
  149.     //
  150.     // Returns the conference that was created or null if a conference
  151.     // was not created.
  152.     /////////////////////////////////////////////////////////////////////
  153.     public ITConference GetConference()
  154.     {
  155.         if (m_ButtonId == CREATE)
  156.             return m_Conference;
  157.         else
  158.             return null;
  159.     }
  160.  
  161.     /////////////////////////////////////////////////////////////////////
  162.     // GetButtonId
  163.     //
  164.     // Returns the id of the button that was used to close the dialog.
  165.     // May be NONE if the dialog is closed using the system menu, etc.
  166.     /////////////////////////////////////////////////////////////////////
  167.     public int GetButtonId()
  168.     {
  169.         return m_ButtonId;
  170.     }
  171.  
  172.     /////////////////////////////////////////////////////////////////////
  173.     // UpdateData
  174.     //
  175.     // If toControls is true, the values in the conference data fields
  176.     // are put into the UI controls.  If toControls is false, data from
  177.     // the dialog controls is collected and stored into the conference
  178.     // data fields.
  179.     /////////////////////////////////////////////////////////////////////
  180.     public void UpdateData(boolean toControls)
  181.     {
  182.         if (toControls) {
  183.             ctrls.tfConfName.setText(m_strConfName);
  184.             ctrls.taDesc.setText(m_strDesc);
  185.             ctrls.tfUserName.setText(m_strUserName);
  186.  
  187.             ctrls.tfStartYear.setText(m_nStartYear + "");
  188.             ctrls.cmbStartMonth.select(m_nStartMonth - 1);
  189.             ctrls.tfStartDay.setText(m_nStartDay + "");
  190.             ctrls.tfStartHour.setText(m_nStartHour + "");
  191.             ctrls.tfStartMinute.setText(m_nStartMinute + "");
  192.  
  193.             ctrls.tfStopYear.setText(m_nStopYear + "");
  194.             ctrls.cmbStopMonth.select(m_nStopMonth - 1);
  195.             ctrls.tfStopDay.setText(m_nStopDay + "");
  196.             ctrls.tfStopHour.setText(m_nStopHour + "");
  197.             ctrls.tfStopMinute.setText(m_nStopMinute + "");
  198.         }
  199.         else {
  200.             m_strConfName = ctrls.tfConfName.getText().trim();
  201.             m_strDesc = ctrls.taDesc.getText().trim();
  202.             m_strUserName = ctrls.tfUserName.getText().trim();
  203.  
  204.             m_nStartYear = Short.parseShort(ctrls.tfStartYear.getText().trim());
  205.             m_nStartMonth = (byte) (ctrls.cmbStartMonth.getSelectedIndex() + 1);
  206.             m_nStartDay = Byte.parseByte(ctrls.tfStartDay.getText().trim());
  207.             m_nStartHour = Byte.parseByte(ctrls.tfStartHour.getText().trim());
  208.             m_nStartMinute = Byte.parseByte(ctrls.tfStartMinute.getText().trim());
  209.  
  210.             m_nStopYear = Short.parseShort(ctrls.tfStopYear.getText().trim());
  211.             m_nStopMonth = (byte) (ctrls.cmbStopMonth.getSelectedIndex() + 1);
  212.             m_nStopDay = Byte.parseByte(ctrls.tfStopDay.getText().trim());
  213.             m_nStopHour = Byte.parseByte(ctrls.tfStopHour.getText().trim());
  214.             m_nStopMinute = Byte.parseByte(ctrls.tfStopMinute.getText().trim());
  215.         }
  216.     }
  217.  
  218.     /////////////////////////////////////////////////////////////////////
  219.     // ValidateData
  220.     //
  221.     // Returns true if the conference data fields contain valid data.
  222.     // If any of the fields are incorrect, a message is displayed to the
  223.     // user.
  224.     /////////////////////////////////////////////////////////////////////
  225.     public boolean ValidateData()
  226.     {
  227.         if (m_strConfName.equals("")) {
  228.             DoMessage("The Conference Name field may not be blank");
  229.             return false;
  230.         }
  231.  
  232.         if (m_strDesc.equals("")) {
  233.             DoMessage("The Description field may not be blank");
  234.             return false;
  235.         }
  236.  
  237.         if (m_strUserName.equals("")) {
  238.             DoMessage("The User Name field may not be blank");
  239.             return false;
  240.         }
  241.  
  242.         if (m_nStartYear < 1970 || m_nStartYear > 3000) {
  243.             DoMessage("The Start Year field must be from 1970 to 3000");
  244.             return false;
  245.         }
  246.  
  247.         if (m_nStartDay < 1 || m_nStartDay > DaysInMonth(m_nStartMonth)) {
  248.             DoMessage("The Start Day field must be from 1 to " + DaysInMonth(m_nStartMonth));
  249.             return false;
  250.         }
  251.  
  252.         if (m_nStartHour < 1 || m_nStartHour > 23) {
  253.             DoMessage("The Start Hour field must be from 1 to 23");
  254.             return false;
  255.         }
  256.  
  257.         if (m_nStartMinute < 0 || m_nStartMinute > 59) {
  258.             DoMessage("The Start Minutes field must be from 0 to 59");
  259.             return false;
  260.         }
  261.  
  262.         if (m_nStopYear < 1970 || m_nStopYear > 3000) {
  263.             DoMessage("The Stop Year field must be from 1900 to 3000");
  264.             return false;
  265.         }
  266.  
  267.         if (m_nStopDay < 1 || m_nStopDay > DaysInMonth(m_nStopMonth)) {
  268.             DoMessage("The Stop Day field must be from 1 to " + DaysInMonth(m_nStopMonth));
  269.             return false;
  270.         }
  271.  
  272.         if (m_nStopHour < 1 || m_nStopHour > 23) {
  273.             DoMessage("The Stop Hour field must be from 1 to 23");
  274.             return false;
  275.         }
  276.  
  277.         if (m_nStopMinute < 0 || m_nStopMinute > 59) {
  278.             DoMessage("The Stop Minutes field must be from 0 to 59");
  279.             return false;
  280.         }
  281.  
  282.         return true;
  283.     }
  284.  
  285.     /////////////////////////////////////////////////////////////////////
  286.     // CreateTheConference
  287.     //
  288.     // Creates a conference using the data entered into the conference
  289.     // data fields.  Returns the created conference or null if there
  290.     // was an error.
  291.     /////////////////////////////////////////////////////////////////////
  292.     private ITConference CreateTheConference()
  293.     {
  294.         ITConference     conf;
  295.         ITConferenceBlob confBlob;
  296.  
  297.         try {
  298.             // create the conference
  299.             conf = m_Directory.CreateConference(m_strConfName);
  300.  
  301.             // modify its attributes
  302.             conf.putOriginator(m_strUserName);
  303.             conf.putDescription(m_strDesc);
  304.             conf.SetStartTime(
  305.                             m_nStartYear,
  306.                             m_nStartMonth,
  307.                             m_nStartDay,
  308.                             m_nStartHour,
  309.                             m_nStartMinute
  310.                             );
  311.             conf.SetStopTime(
  312.                             m_nStopYear,
  313.                             m_nStopMonth,
  314.                             m_nStopDay,
  315.                             m_nStopHour,
  316.                             m_nStopMinute
  317.                             );
  318.  
  319.             // commit the conference info to the ILS server
  320.             confBlob = (ITConferenceBlob) conf;
  321.             confBlob.CommitBlob();
  322.  
  323.             return conf;
  324.         }
  325.         catch (ComException e) {
  326.             e.printStackTrace();
  327.             return null;
  328.         }
  329.     }
  330.  
  331.     /////////////////////////////////////////////////////////////////////
  332.     // DaysInMonth
  333.     //
  334.     // Returns the number of days in the given month, where January is
  335.     // month 0 and so on.  Does not account for leap-years.
  336.     /////////////////////////////////////////////////////////////////////
  337.     private int DaysInMonth(int month)
  338.     {
  339.         switch (month)
  340.         {
  341.         case 0:
  342.         case 2:
  343.         case 4:
  344.         case 6:
  345.         case 7:
  346.         case 9:
  347.         case 11:
  348.             return 31;
  349.         case 1:
  350.             return 28;  // leap-years not included!
  351.         case 3:
  352.         case 5:
  353.         case 8:
  354.         case 10:
  355.             return 30;
  356.         default:
  357.             return 0;
  358.         }
  359.     }
  360.  
  361.     /////////////////////////////////////////////////////////////////////
  362.     // DoMessage
  363.     //
  364.     // Displays messages in a message box.
  365.     /////////////////////////////////////////////////////////////////////
  366.     private void DoMessage(String msg)
  367.     {
  368.         AwtUIMessageBox msgbox = new AwtUIMessageBox(
  369.                                             m_ParentFrame,
  370.                                             DLG_TITLE,
  371.                                             msg,
  372.                                             AwtUIMessageBox.EXCLAMATION,
  373.                                             UIButtonBar.OK
  374.                                             );
  375.         msgbox.doModal();
  376.     }
  377. }