[Schmitzm-commits] r2201 - in trunk/schmitzm-core/src/main: java/de/schmitzm/net/mail java/de/schmitzm/swing resources/de/schmitzm/swing/resource/locales

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sat Jan 26 19:32:59 CET 2013


Author: mojays
Date: 2013-01-26 19:32:59 +0100 (Sat, 26 Jan 2013)
New Revision: 2201

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Pop3Client.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
Log:
Pop3Client improved
SwingUtil: new methods to create InputOptions for POP3 settings dialog

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Pop3Client.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Pop3Client.java	2013-01-26 17:34:11 UTC (rev 2200)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Pop3Client.java	2013-01-26 18:32:59 UTC (rev 2201)
@@ -50,6 +50,7 @@
 
   protected Store pop3store = null;
   protected Folder inboxFolder = null;
+  protected int inboxFolderMode = -1;
   
   
   /**
@@ -101,6 +102,7 @@
    * @param mode indicates whether to open folder {@link Folder#READ_ONLY} or {@link Folder#READ_WRITE}
    */
   public void connect(String user, String pw, int mode) throws MessagingException  {
+    disconnect();
     try {
       // Get system properties
       Properties properties = System.getProperties();
@@ -112,9 +114,8 @@
       pop3store.connect(getServer(), getPort(), user, pw);
   
       // Create a Folder object corresponding to the given name.
-      inboxFolder = pop3store.getFolder("inbox");
-      // Open the Folder.
-      inboxFolder.open(mode);
+      inboxFolderMode = mode;
+      updateInboxFolder();
     } catch (MessagingException err) {
       disconnect();
       throw err;
@@ -137,6 +138,23 @@
   }
   
   /**
+   * Updates the inbox folder from server.
+   */
+  public void updateInboxFolder() throws MessagingException {
+    if ( pop3store == null || !pop3store.isConnected() )
+      throw new UnsupportedOperationException("POP3 server is not connected!");
+    // if current folder is still open, close it first
+    if ( inboxFolder != null && inboxFolder.isOpen() )
+      inboxFolder.close(true);
+    
+    // Create a Folder object corresponding to the given name.
+    inboxFolder = pop3store.getFolder("inbox");
+    // Open the Folder.
+    inboxFolder.open(inboxFolderMode);
+
+  }
+  
+  /**
    * Checks whether connection to POP3 server is established and
    * "inbox" folder is opened. 
    */
@@ -146,6 +164,14 @@
   }
 
   /**
+   * Returns the inbox folder.
+   * @return {@code null} if connection is closed.
+   */
+  public Folder getInboxFolder() {
+    return inboxFolder;
+  }
+  
+  /**
    * Returns the total number of messages in "inbox" folder.
    */
   public int getMessageCount() throws MessagingException {
@@ -189,14 +215,8 @@
     return messages;
   }
   
-  /**
-   * Returns the inbox folder.
-   * @return {@code null} if connection is closed.
-   */
-  public Folder getInboxFolder() {
-    return inboxFolder;
-  }
 
+
 }
 
 

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2013-01-26 17:34:11 UTC (rev 2200)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2013-01-26 18:32:59 UTC (rev 2201)
@@ -1226,7 +1226,79 @@
                                              "",
                                              inclSender ? "" : null);
     }
-    
+
+    /**
+     * Erzeugt (bis zu) 4 {@link InputOption} fuer ein {@link MultipleOptionPane} zur
+     * Abfrage von POP3-Einstellungen.
+     * <ol>
+     *   <li>{@linkplain BooleanInputOption Eingabe-Feld} ob POP3-Einstellungen verwendet werden sollen (optional)</li>
+     *   <li>{@linkplain ManualInputOption.Text Eingabe-Feld} fuer Servernamen</li>
+     *   <li>{@linkplain ManualInputOption.Text Eingabe-Feld} fuer Benutzername</li>
+     *   <li>{@linkplain ManualInputOption.Password Eingabe-Feld} fuer Passwort</li>
+     * </ol>
+     * @param createLabels wenn {@code false} werden die {@link InputOption} ohne
+     *                     Labels erzeugt
+     * @param used Standard-Wert ob POP3-Settings verwendet werden sollen; wenn {@code null}
+     *             wird diese {@link InputOption} NICHT erzeugt!
+     * @param server Standard-Wert fuer Servernamen
+     * @param user Standard-Wert fuer User
+     * @param pw Standard-Wert fuer Passwort
+     */
+    public static List<InputOption<?>> createPOP3SettingsDialogOptions(boolean createLabels, Boolean used, String server, String user, String pw) {
+      List<InputOption<?>> inputOptions = new ArrayList<InputOption<?>>();
+      
+      BooleanInputOption pop3Used = new BooleanInputOption(createLabels ? R("POP3Settings.pop3.used") : null,false);
+      InputOption pop3Server      = new ManualInputOption.Text(createLabels ? R("POP3Settings.pop3.server") : null,false);
+      InputOption authUser        = new ManualInputOption.Text(createLabels ? R("POP3Settings.auth.user") : null,false);
+      InputOption authPW          = new ManualInputOption.PasswordViewable(createLabels ? R("POP3Settings.auth.pw") : null,false);
+      
+      if ( used != null)
+        inputOptions.add(pop3Used);
+      inputOptions.add(pop3Server);
+      inputOptions.add(authUser);
+      inputOptions.add(authPW);
+
+      // Connect all options with "Use POP3-Mail", so that
+      // all of these are disabled when "POP3-Mail verwenden" is unselected
+      if ( pop3Used != null )
+        for (int i=1; i<inputOptions.size();i++)
+          pop3Used.connectInputOptions(true,inputOptions.get(i));  
+
+      // Set inital values
+      pop3Server.setValue(server);
+      authUser.setValue(user);
+      authPW.setValue(pw);
+      // Important to set the "Use POP3" at last, because its selection
+      // state has higher priority for the enabled/disabled-state of
+      // the connected options (than "Authentication required")!
+      if ( used != null )
+        pop3Used.setValue(used);
+      
+      return inputOptions;
+    }
+
+    /**
+     * Erzeugt (bis zu) 4 {@link InputOption} fuer ein {@link MultipleOptionPane} zur
+     * Abfrage von POP3-Einstellungen.
+     * <ol>
+     *   <li>{@linkplain BooleanInputOption Eingabe-Feld} ob POP3-Einstellungen verwendet werden sollen (optional)</li>
+     *   <li>{@linkplain ManualInputOption.Text Eingabe-Feld} fuer Servernamen</li>
+     *   <li>{@linkplain ManualInputOption.Text Eingabe-Feld} fuer Benutzername</li>
+     *   <li>{@linkplain ManualInputOption.Password Eingabe-Feld} fuer Passwort</li>
+     * </ol>
+     * @param createLabels wenn {@code false} werden die {@link InputOption} ohne
+     *                     Labels erzeugt
+     * @param inclUsed gibt an, ob eine {@link InputOption} fuer "SMTP-Settings verwenden"
+     *                 erzeugt werden sollt
+     */
+    public static List<InputOption<?>> createPOP3SettingsDialogOptions(boolean createLabels, boolean inclUsed) {
+      return createPOP3SettingsDialogOptions(createLabels,
+                                             inclUsed ? Boolean.TRUE : null,
+                                             "",
+                                             "",
+                                             "");
+    }
+
 	/**
 	 * Erzeugt 5 {@link InputOption} fuer ein {@link MultipleOptionPane} zur
 	 * Datenbank-Anmeldung.

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2013-01-26 17:34:11 UTC (rev 2200)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2013-01-26 18:32:59 UTC (rev 2201)
@@ -313,5 +313,10 @@
 SMTPSettings.auth.pw=Password
 SMTPSettings.sender.addr=Sender mail address
 
+POP3Settings.pop3.used=Use POP3-Mail
+POP3Settings.pop3.server=POP3 server name
+POP3Settings.auth.user=User name
+POP3Settings.auth.pw=Password
+
 DirectoryChooser.title=Choose directory
 DirectoryChooser.DirectoryRoot=Computer
\ No newline at end of file

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2013-01-26 17:34:11 UTC (rev 2200)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2013-01-26 18:32:59 UTC (rev 2201)
@@ -285,3 +285,11 @@
 SMTPSettings.auth.user=Benutzer
 SMTPSettings.auth.pw=Passwort
 SMTPSettings.sender.addr=Absender-Mailadresse
+
+POP3Settings.pop3.used=POP3-Mail verwenden
+POP3Settings.pop3.server=POP3-Server
+POP3Settings.auth.user=Benutzer
+POP3Settings.auth.pw=Passwort
+
+DirectoryChooser.title=Choose directory
+DirectoryChooser.DirectoryRoot=Computer
\ No newline at end of file



More information about the Schmitzm-commits mailing list