Ejemplo n.º 1
0
  /**
   * Displays a notification dialog about the server being shut down regardless of whether the edit
   * contractor dialog itself is currently visible or not.
   */
  public final void deactivate() {
    // Disable everything
    nameField.setEnabled(false);
    locationField.setEnabled(false);
    specialtiesField.setEnabled(false);
    sizeField.setEnabled(false);
    rateField.setEnabled(false);
    ownerField.setEnabled(false);
    okButton.setEnabled(false);
    cancelButton.setEnabled(false);

    // Display notification about server going down
    JOptionPane.showMessageDialog(
        isVisible() ? this : getParent(),
        Text.SERVER_IS_GOING_DOWN,
        Text.SERVER_TERMINATION_NOTIFICATION,
        JOptionPane.WARNING_MESSAGE);

    if (isVisible()) {
      setVisible(false);
    }
  }
Ejemplo n.º 2
0
  /**
   * Configures the dialog as a book contractor dialog and displays it. Returns when the dialog has
   * been made invisible after confirmation or cancellation.
   *
   * @param recNo the number of the contractor record to book
   * @param contractor the contractor object corresponding to the given <code>recNo</code>
   * @param businessServices an object implementing the <code>BusinessServices</code> interface for
   *     the <code>book</code> request to the model
   * @return a <code>BookResult</code> with <code>BookStatus</code> and <code>Contractor</code> if
   *     booking was actually attempted (OK button pressed), otherwise (Cancel button pressed)
   *     <code>null</code>.
   */
  public final BookResult bookContractor(
      final long recNo, final Contractor contractor, final BusinessServices businessServices) {
    validOwner = false;

    BookActionHandler bookActionHandler = new BookActionHandler(recNo, businessServices);
    okButton.addActionListener(bookActionHandler);

    okButton.setEnabled(validOwner);
    // Activate the cancel button (possibly still deactivated from previous
    // invocation).
    cancelButton.setEnabled(true);

    nameField.setText(contractor.getName());
    nameField.setEnabled(false);

    locationField.setText(contractor.getLocation());
    locationField.setEnabled(false);

    specialtiesField.setText(contractor.getSpecialties());
    specialtiesField.setEnabled(false);

    sizeField.setText(contractor.getSize());
    sizeField.setEnabled(false);

    rateField.setText(contractor.getRate());
    rateField.setEnabled(false);

    // To validate the initial text, it is crucial that the validity
    // listener be added before setting the text.
    ownerField.addValidityChangeListener(
        new ValidityChangeListener() {
          @Override
          public void validityGained(final ValidityChangeEvent ve) {
            validOwner = true;
            okButton.setEnabled(validOwner);
          }

          @Override
          public void validityLost(final ValidityChangeEvent ve) {
            validOwner = false;
            okButton.setEnabled(validOwner);
          }
        });
    ownerField.setText(contractor.getOwner());
    ownerField.setEnabled(true);
    ownerField.addKeyListener(textFieldEnterKeyHandler);

    setTitle(Text.BOOK_CONTRACTOR_TITLE);
    setLocationRelativeTo(getParent());

    ownerField.requestFocusInWindow();

    setVisible(true);

    okButton.removeActionListener(bookActionHandler);

    // Return true if OK button has been pushed.
    JOptionPane optionPane = (JOptionPane) getContentPane();
    if (optionPane.getValue() instanceof Integer) {
      int status = ((Integer) (optionPane.getValue())).intValue();
      if (status == JOptionPane.OK_OPTION) {
        return bookActionHandler.bookResult;
      }
    }
    return null;
  }