예제 #1
0
 public void show() throws RaplaException {
   createPanel();
   config = preferences.getEntry(MailPlugin.MAILSERVER_CONFIG, null);
   if (config == null) {
     config = configService.getConfig();
   }
   readConfig(config);
   defaultSender.setText(
       preferences.getEntryAsString(MailPlugin.DEFAULT_SENDER_ENTRY, "rapla@domainname"));
 }
예제 #2
0
  protected void createPanel() throws RaplaException {

    externalConfigEnabled = configService.isExternalConfigEnabled();
    mailServer = textFieldFactory.create();
    smtpPortField = new RaplaNumber(new Integer(25), new Integer(0), null, false);
    defaultSender = new JTextField();
    username = new JTextField();
    password = new JPasswordField();
    send = new RaplaButton();
    password.setEchoChar('*');

    content = new JPanel();
    // addCopyPaste( mailServer);
    addCopyPaste(defaultSender, getI18n(), getRaplaLocale(), ioInterface, getLogger());
    addCopyPaste(username, getI18n(), getRaplaLocale(), ioInterface, getLogger());
    addCopyPaste(password, getI18n(), getRaplaLocale(), ioInterface, getLogger());
    double[][] sizes =
        new double[][] {
          {5, TableLayout.PREFERRED, 5, TableLayout.FILL, 5},
          {
            TableLayout.PREFERRED,
            5,
            TableLayout.PREFERRED,
            5,
            TableLayout.PREFERRED,
            5,
            TableLayout.PREFERRED,
            5,
            TableLayout.PREFERRED,
            5,
            TableLayout.PREFERRED,
            5,
            TableLayout.PREFERRED,
            5,
            TableLayout.PREFERRED
          }
        };
    TableLayout tableLayout = new TableLayout(sizes);
    content.setLayout(tableLayout);
    if (externalConfigEnabled) {
      JLabel info = new JLabel("Mail config is provided by servlet container.");
      content.add(info, "3,0");
    } else {
      content.add(new JLabel("Mail Server"), "1,0");
      content.add(mailServer.getComponent(), "3,0");
      content.add(new JLabel("Use SSL*"), "1,2");
      content.add(useSsl, "3,2");
      content.add(new JLabel("Mail Port"), "1,4");
      content.add(smtpPortField, "3,4");
      content.add(new JLabel("Username"), "1,6");
      content.add(username, "3,6");
      content.add(new JLabel("Password"), "1,8");
      JPanel passwordPanel = new JPanel();
      passwordPanel.setLayout(new BorderLayout());
      content.add(passwordPanel, "3,8");
      passwordPanel.add(password, BorderLayout.CENTER);
      final JCheckBox showPassword = new JCheckBox("show password");
      passwordPanel.add(showPassword, BorderLayout.EAST);
      showPassword.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              boolean show = showPassword.isSelected();
              password.setEchoChar(show ? ((char) 0) : '*');
            }
          });
      content.add(new JLabel("Default Sender"), "1,10");
      content.add(defaultSender, "3,10");
    }

    content.add(new JLabel("Test Mail"), "1,12");
    content.add(send, "3,12");
    String mailid = getUser().getEmail();
    if (mailid.length() == 0) {
      send.setText("Send to " + getUser() + " : Provide email in user profile");
      send.setEnabled(false);
      // java.awt.Font font = send.getFont();
      // send.setFont( font.deriveFont( Font.BOLD));

    } else {
      send.setText("Send to " + getUser() + " : " + mailid);
      send.setEnabled(true);
      // send.setBackground(Color.GREEN);
    }
    useSsl.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            if (listenersEnabled) {
              int port = useSsl.isSelected() ? 465 : 25;
              smtpPortField.setNumber(new Integer(port));
            }
          }
        });
    send.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            try {
              DefaultConfiguration newConfig = new DefaultConfiguration(config);
              Configuration[] children = newConfig.getChildren();
              for (Configuration child : children) {
                newConfig.removeChild(child);
              }
              //					if ( !activate.isSelected())
              //					{
              //						throw new RaplaException("You need to activate MailPlugin " +
              // getString("restart_options"));
              //					}
              if (!externalConfigEnabled) {
                addChildren(newConfig);
                //						if ( !newConfig.equals( config))
                //						{
                //							getLogger().info("old config" + config );
                //							getLogger().info("new config" + newConfig);
                //							throw new RaplaException(getString("restart_options"));
                //						}
              } else {
                String attribute = config.getAttribute("enabled", null);
                if (attribute == null || !attribute.equalsIgnoreCase("true")) {
                  throw new RaplaException(getString("restart_options"));
                }
              }
              // String senderMail = defaultSender.getText();
              String recipient = getUser().getEmail();
              if (recipient == null || recipient.trim().length() == 0) {
                throw new RaplaException("You need to set an email address in your user settings.");
              }

              try {
                send.setBackground(new Color(255, 100, 100, 255));
                configService.testMail(newConfig, defaultSender.getText());
                send.setBackground(Color.GREEN);
                send.setText("Please check your mailbox.");
              } catch (UnsupportedOperationException ex) {
                JComponent component = getComponent();
                dialogUiFactory.showException(
                    new RaplaException(getString("restart_options")),
                    new SwingPopupContext(component, null));
              }
            } catch (RaplaException ex) {
              JComponent component = getComponent();
              dialogUiFactory.showException(ex, new SwingPopupContext(component, null));

              //				} catch (ConfigurationException ex) {
              //					JComponent component = getComponent();
              //					showException( ex, component);
            }
          }
        });
  }