Example #1
0
  /** Creating the configuration form */
  private void init() {
    ResourceManagementService resources = LoggingUtilsActivator.getResourceService();

    enableCheckBox =
        new SIPCommCheckBox(resources.getI18NString("plugin.loggingutils.ENABLE_DISABLE"));
    enableCheckBox.addActionListener(this);

    sipProtocolCheckBox =
        new SIPCommCheckBox(resources.getI18NString("plugin.sipaccregwizz.PROTOCOL_NAME"));
    sipProtocolCheckBox.addActionListener(this);

    jabberProtocolCheckBox =
        new SIPCommCheckBox(resources.getI18NString("plugin.jabberaccregwizz.PROTOCOL_NAME"));
    jabberProtocolCheckBox.addActionListener(this);

    String rtpDescription =
        resources.getI18NString("plugin.loggingutils.PACKET_LOGGING_RTP_DESCRIPTION");
    rtpProtocolCheckBox =
        new SIPCommCheckBox(
            resources.getI18NString("plugin.loggingutils.PACKET_LOGGING_RTP")
                + " "
                + rtpDescription);
    rtpProtocolCheckBox.addActionListener(this);
    rtpProtocolCheckBox.setToolTipText(rtpDescription);

    ice4jProtocolCheckBox =
        new SIPCommCheckBox(resources.getI18NString("plugin.loggingutils.PACKET_LOGGING_ICE4J"));
    ice4jProtocolCheckBox.addActionListener(this);

    JPanel mainPanel = new TransparentPanel();

    add(mainPanel, BorderLayout.NORTH);

    mainPanel.setLayout(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();

    enableCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.gridx = 0;
    c.gridy = 0;
    mainPanel.add(enableCheckBox, c);

    String label = resources.getI18NString("plugin.loggingutils.PACKET_LOGGING_DESCRIPTION");
    JLabel descriptionLabel = new JLabel(label);
    descriptionLabel.setToolTipText(label);
    enableCheckBox.setToolTipText(label);
    descriptionLabel.setForeground(Color.GRAY);
    descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(8));
    c.gridy = 1;
    c.insets = new Insets(0, 25, 10, 0);
    mainPanel.add(descriptionLabel, c);

    final JPanel loggersButtonPanel = new TransparentPanel(new GridLayout(0, 1));

    loggersButtonPanel.setBorder(
        BorderFactory.createTitledBorder(resources.getI18NString("service.gui.PROTOCOL")));

    loggersButtonPanel.add(sipProtocolCheckBox);
    loggersButtonPanel.add(jabberProtocolCheckBox);
    loggersButtonPanel.add(rtpProtocolCheckBox);
    loggersButtonPanel.add(ice4jProtocolCheckBox);

    c.insets = new Insets(0, 20, 10, 0);
    c.gridy = 2;
    mainPanel.add(loggersButtonPanel, c);

    final JPanel advancedPanel = new TransparentPanel(new GridLayout(0, 2));

    advancedPanel.setBorder(
        BorderFactory.createTitledBorder(resources.getI18NString("service.gui.ADVANCED")));

    fileCountField.getDocument().addDocumentListener(this);
    fileSizeField.getDocument().addDocumentListener(this);

    fileCountLabel =
        new JLabel(resources.getI18NString("plugin.loggingutils.PACKET_LOGGING_FILE_COUNT"));
    advancedPanel.add(fileCountLabel);
    advancedPanel.add(fileCountField);
    fileSizeLabel =
        new JLabel(resources.getI18NString("plugin.loggingutils.PACKET_LOGGING_FILE_SIZE"));
    advancedPanel.add(fileSizeLabel);
    advancedPanel.add(fileSizeField);

    c.gridy = 3;
    mainPanel.add(advancedPanel, c);

    archiveButton = new JButton(resources.getI18NString("plugin.loggingutils.ARCHIVE_BUTTON"));
    archiveButton.addActionListener(this);

    c = new GridBagConstraints();
    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 4;
    mainPanel.add(archiveButton, c);

    if (!StringUtils.isNullOrEmpty(getUploadLocation())) {
      uploadLogsButton =
          new JButton(resources.getI18NString("plugin.loggingutils.UPLOAD_LOGS_BUTTON"));
      uploadLogsButton.addActionListener(this);

      c.insets = new Insets(10, 0, 0, 0);
      c.gridy = 5;
      mainPanel.add(uploadLogsButton, c);
    }
  }
Example #2
0
  /** Shows a dialog with input for logs description. */
  private void uploadLogs() {
    ResourceManagementService resources = LoggingUtilsActivator.getResourceService();

    final SIPCommDialog dialog =
        new SIPCommDialog(false) {
          /** Serial version UID. */
          private static final long serialVersionUID = 0L;

          /**
           * Dialog is closed. Do nothing.
           *
           * @param escaped <tt>true</tt> if this dialog has been closed by pressing
           */
          @Override
          protected void close(boolean escaped) {}
        };

    dialog.setModal(true);
    dialog.setTitle(resources.getI18NString("plugin.loggingutils.UPLOAD_LOGS_BUTTON"));

    Container container = dialog.getContentPane();
    container.setLayout(new GridBagLayout());

    JLabel descriptionLabel = new JLabel("Add a comment:");
    final JTextArea commentTextArea = new JTextArea();
    commentTextArea.setRows(4);
    final JButton uploadButton =
        new JButton(resources.getI18NString("plugin.loggingutils.UPLOAD_BUTTON"));
    final SIPCommTextField emailField =
        new SIPCommTextField(resources.getI18NString("plugin.loggingutils.ARCHIVE_UPREPORT_EMAIL"));
    final JCheckBox emailCheckBox =
        new SIPCommCheckBox("Email me when more information is available");
    emailCheckBox.setSelected(true);
    emailCheckBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!emailCheckBox.isSelected()) {
              uploadButton.setEnabled(true);
              emailField.setEnabled(false);
            } else {
              emailField.setEnabled(true);

              if (emailField.getText() != null && emailField.getText().trim().length() > 0)
                uploadButton.setEnabled(true);
              else uploadButton.setEnabled(false);
            }
          }
        });

    emailField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void insertUpdate(DocumentEvent e) {
                updateButtonsState();
              }

              public void removeUpdate(DocumentEvent e) {
                updateButtonsState();
              }

              public void changedUpdate(DocumentEvent e) {}

              /** Check whether we should enable upload button. */
              private void updateButtonsState() {
                if (emailCheckBox.isSelected()
                    && emailField.getText() != null
                    && emailField.getText().trim().length() > 0) uploadButton.setEnabled(true);
                else uploadButton.setEnabled(false);
              }
            });

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(10, 10, 3, 10);
    c.weightx = 1.0;
    c.gridx = 0;
    c.gridy = 0;

    container.add(descriptionLabel, c);

    c.insets = new Insets(0, 10, 10, 10);
    c.gridy = 1;
    container.add(new JScrollPane(commentTextArea), c);

    c.insets = new Insets(0, 10, 0, 10);
    c.gridy = 2;
    container.add(emailCheckBox, c);

    c.insets = new Insets(0, 10, 10, 10);
    c.gridy = 3;
    container.add(emailField, c);

    JButton cancelButton = new JButton(resources.getI18NString("service.gui.CANCEL"));
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dialog.dispose();
          }
        });

    uploadButton.setEnabled(false);
    uploadButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              final ArrayList<String> paramNames = new ArrayList<String>();
              final ArrayList<String> paramValues = new ArrayList<String>();

              if (emailCheckBox.isSelected()) {
                paramNames.add("Email");
                paramValues.add(emailField.getText());
              }

              paramNames.add("Description");
              paramValues.add(commentTextArea.getText());

              // don't block the UI thread we may need to show
              // some ui for password input if protected area on the way
              new Thread(
                      new Runnable() {
                        public void run() {
                          uploadLogs(
                              getUploadLocation(),
                              LogsCollector.getDefaultFileName(),
                              paramNames.toArray(new String[] {}),
                              paramValues.toArray(new String[] {}));
                        }
                      })
                  .start();
            } finally {
              dialog.dispose();
            }
          }
        });
    JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonsPanel.add(uploadButton);
    buttonsPanel.add(cancelButton);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 0;
    c.gridy = 4;
    container.add(buttonsPanel, c);

    dialog.setVisible(true);
  }