Revision: 1114
Author:   lstreepy
Date:     2006-05-06 11:46:41 -0700 (Sat, 06 May 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1114&view=rev

Log Message:
-----------
Properly use I18N messages for the status bar updates from the 
AbstractObjectTable

Modified Paths:
--------------
    
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/AbstractObjectTable.java
    
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactTable.java
    
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactView.java
    
trunk/spring-richclient/samples/simple/src/main/resources/org/springframework/richclient/samples/simple/ui/messages.properties
Modified: 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/AbstractObjectTable.java
===================================================================
--- 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/AbstractObjectTable.java
      2006-05-06 17:35:27 UTC (rev 1113)
+++ 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/AbstractObjectTable.java
      2006-05-06 18:46:41 UTC (rev 1114)
@@ -64,8 +64,51 @@
  * <li>Offers the selection model up as a ValueModel, using
  * [EMAIL PROTECTED] #getTableSelectionHolder()} so that Guards can be 
constructed based on the
  * selection contents.</li>
+ * <li>It can report on row counts (after filtering) and selection counts to a 
status bar</li>
  * </ol>
  * <p>
+ * Several I18N messages are needed for proper reporting to a configured 
status bar. The
+ * message keys used are:
+ * <p>
+ * <table border="1">
+ * <tr>
+ * <td><b>Message key </b></td>
+ * <td><b>Usage </b></td>
+ * </tr>
+ * <tr>
+ * <td><i>modelId</i>.objectName.singular</td>
+ * <td>The singular name of the objects in the table</td>
+ * </tr>
+ * <tr>
+ * <td><i>modelId</i>.objectName.plural</td>
+ * <td>The plural name of the objects in the table</td>
+ * </tr>
+ * <tr>
+ * <td><i>[modelId]</i>.objectTable.showingAll.message</td>
+ * <td>The message to show when all objects are being shown, that is no 
objects have been
+ * filtered. This is typically something like "Showing all nn contacts". The 
message takes
+ * the number of objects nd the object name (singular or plural) as 
parameters.</td>
+ * </tr>
+ * <tr>
+ * <td><i>[modelId]</i>.objectTable.showingN.message</td>
+ * <td>The message to show when some of the objects have been filtered from 
the display.
+ * This is typically something like "Showing nn contacts of nn". The message 
takes the
+ * shown count, the total count, and the object name (singular or plural) as 
parameters.</td>
+ * </tr>
+ * <tr>
+ * <td><i>[modelId]</i>.objectTable.selectedN.message</td>
+ * <td>The message to append to the filter message when the selection is not 
empty.
+ * Typically something like ", nn selected". The message takes the number of 
selected
+ * entries as a parameter.</td>
+ * </tr>
+ * </table>
+ * <p>
+ * Note that the message keys that show the model id in brackets, like this 
<i>[modelId]</i>,
+ * indicate that the model id is optional. If no message is found using the 
model id, then
+ * the key will be tried without the model id and the resulting string will be 
used. This
+ * makes it easy to construct one single message property that can be used on 
numerous
+ * tables.
+ * <p>
  * <em>Note:</em> If you are using application events to inform UI components 
of changes
  * to domain objects, then instances of this class have to be wired into the 
event
  * distribution. To do this, you should construct instances (of concrete 
subclasses) in
@@ -78,6 +121,9 @@
 
     private final Log _logger = LogFactory.getLog(getClass());
 
+    private String modelId;
+    private String objectSingularName;
+    private String objectPluralName;
     private Object[] initialData = null;
     private String[] columnPropertyNames;
     private GlazedTableModel model;
@@ -87,19 +133,34 @@
     private ActionCommandExecutor doubleClickHandler;
     private CommandGroup popupCommandGroup;
     private StatusBarCommandGroup statusBar;
-    private String singularName;
-    private String pluralName;
 
+    public static final String SHOWINGALL_MSG_KEY = 
"objectTable.showingAll.message";
+    public static final String SHOWINGN_MSG_KEY = 
"objectTable.showingN.message";
+    public static final String SELECTEDN_MSG_KEY = 
"objectTable.selectedN.message";
+
     /**
      * Constructor.
      * 
+     * @param modelId used for generating message keys
      * @param objectType The type of object held in the table
      */
-    public AbstractObjectTable( String[] columnPropertyNames ) {
+    public AbstractObjectTable( String modelId, String[] columnPropertyNames ) 
{
+        this.modelId = modelId;
         setColumnPropertyNames(columnPropertyNames);
+        init();
     }
 
     /**
+     * Initialize our internal values.
+     */
+    protected void init() {
+        // Get all our messages
+
+        objectSingularName = getMessage(modelId + ".objectName.singular");
+        objectPluralName = getMessage(modelId + ".objectName.plural");
+    }
+
+    /**
      * Set the initial data to display.
      * 
      * @param initialData Array of objects to display
@@ -237,12 +298,14 @@
             }
         });
 
-        // Keep our status line up to date with the selection
+        // Keep our status line up to date with the selections and filtering
         getSelectionModel().addListSelectionListener(new 
ListSelectionListener() {
             public void valueChanged( ListSelectionEvent e ) {
                 updateStatusBar();
             }
         });
+
+        getFinalEventList().addListEventListener(this);
     }
 
     /**
@@ -448,16 +511,9 @@
      * current object counts.
      * 
      * @param statusBar to update
-     * @param singular name of the objects being displayed
-     * @param plural name of the objects being displayed
      */
-    protected void reportToStatusBar( StatusBarCommandGroup statusBar, String 
singular, String plural ) {
+    protected void reportToStatusBar( StatusBarCommandGroup statusBar ) {
         this.statusBar = statusBar;
-        this.singularName = singular;
-        this.pluralName = plural;
-
-        // Make sure that we get notified when things change
-        getFinalEventList().addListEventListener(this);
     }
 
     /*
@@ -474,23 +530,29 @@
      * Update the status bar with the current display counts.
      */
     protected void updateStatusBar() {
-        int all = getBaseEventList().size();
-        int showing = getFinalEventList().size();
-        StringBuffer msg = new StringBuffer();
-        if( all == showing ) {
-            msg.append("Showing all ").append(all).append(" 
").append(pluralName);
-        } else {
-            String lbl = " " + ((showing > 1 || showing == 0) ? pluralName : 
singularName);
-            msg.append("Showing ").append(showing).append(lbl).append(" of 
").append(all);
-        }
+        if( statusBar != null ) {
+            int all = getBaseEventList().size();
+            int showing = getFinalEventList().size();
+            String msg;
+            if( all == showing ) {
+                String[] keys = new String[] { modelId + "." + 
SHOWINGALL_MSG_KEY, SHOWINGALL_MSG_KEY };
+                msg = getMessage(keys, new Object[] { ""+all, (all != 1) ? 
objectPluralName : objectSingularName } );
+            } else {
+                String[] keys = new String[] { modelId + "." + 
SHOWINGN_MSG_KEY, SHOWINGN_MSG_KEY };
 
-        // Now add the selection info
-        int nselected = table.getSelectedRowCount();
-        if( nselected > 0 ) {
-            msg.append(", ").append(nselected).append(" selected");
+                msg = getMessage(keys, new Object[] { ""+showing, (showing != 
1) ? objectPluralName : objectSingularName, ""+all } );
+            }
+
+            // Now add the selection info
+            int nselected = table.getSelectedRowCount();
+            if( nselected > 0 ) {
+                String[] keys = new String[] { modelId + "." + 
SELECTEDN_MSG_KEY, SELECTEDN_MSG_KEY };
+
+                msg += getMessage(keys, new Object[] { ""+nselected } );
+            }
+
+            statusBar.setMessage(msg.toString());
         }
-
-        statusBar.setMessage(msg.toString());
     }
 
     /**

Modified: 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactTable.java
===================================================================
--- 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactTable.java
     2006-05-06 17:35:27 UTC (rev 1113)
+++ 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactTable.java
     2006-05-06 18:46:41 UTC (rev 1114)
@@ -37,7 +37,7 @@
      * Default constructor.
      */
     public ContactTable() {
-        super(new String[] { "lastName", "firstName", "address.address1", 
"address.city", "address.state",
+        super("contacts", new String[] { "lastName", "firstName", 
"address.address1", "address.city", "address.state",
                 "address.zip" });
     }
 

Modified: 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactView.java
===================================================================
--- 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactView.java
      2006-05-06 17:35:27 UTC (rev 1113)
+++ 
trunk/spring-richclient/samples/simple/src/main/java/org/springframework/richclient/samples/simple/ui/ContactView.java
      2006-05-06 18:46:41 UTC (rev 1114)
@@ -233,7 +233,7 @@
         contactTable.setFinalEventList(filterList);
 
         // Register to get notified when the filtered list changes
-        contactTable.reportToStatusBar(getStatusBar(), "Contact", "Contacts");
+        contactTable.reportToStatusBar(getStatusBar());
 
         // Ensure our commands are only active when something is selected.
         // These guard objects operate by inspecting a list selection model

Modified: 
trunk/spring-richclient/samples/simple/src/main/resources/org/springframework/richclient/samples/simple/ui/messages.properties
===================================================================
--- 
trunk/spring-richclient/samples/simple/src/main/resources/org/springframework/richclient/samples/simple/ui/messages.properties
      2006-05-06 17:35:27 UTC (rev 1113)
+++ 
trunk/spring-richclient/samples/simple/src/main/resources/org/springframework/richclient/samples/simple/ui/messages.properties
      2006-05-06 18:46:41 UTC (rev 1114)
@@ -27,6 +27,13 @@
 contactView.title=Contact Summary
 contactView.caption=Manage contacts
 
+# Contact table status messages
+contacts.objectName.singular=Contact
+contacts.objectName.plural=Contacts
+objectTable.showingAll.message=Showing all {0} {1}
+objectTable.showingN.message=Showing {0} {1} of {2}
+objectTable.selectedN.message=, {0} selected
+
 # Contact table columns
 lastName=Last Name
 firstName=First Name


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to