james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r831874 - in /james/hupa/trunk: client/src/main/java/org/apache/hupa/client/gin/ client/src/main/java/org/apache/hupa/client/mvp/ server/src/main/java/org/apache/hupa/server/handler/
Date Mon, 02 Nov 2009 12:21:53 GMT
Author: norman
Date: Mon Nov  2 12:21:53 2009
New Revision: 831874

URL: http://svn.apache.org/viewvc?rev=831874&view=rev
Log:
Inject the TableModel. Thats better in terms of MVP.

Added:
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageTableModel.java
Modified:
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/gin/HupaClientModule.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/gin/HupaClientModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/gin/HupaClientModule.java?rev=831874&r1=831873&r2=831874&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/gin/HupaClientModule.java
(original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/gin/HupaClientModule.java
Mon Nov  2 12:21:53 2009
@@ -38,6 +38,7 @@
 import org.apache.hupa.client.mvp.LoginView;
 import org.apache.hupa.client.mvp.MainPresenter;
 import org.apache.hupa.client.mvp.MainView;
+import org.apache.hupa.client.mvp.MessageTableModel;
 
 import com.google.inject.Singleton;
 
@@ -55,6 +56,7 @@
         bindPresenter(AppPresenter.class, AppPresenter.Display.class, AppView.class);
         bind(CachingDispatchAsync.class);
         bind(PagingScrollTableRowDragController.class).in(Singleton.class);
+        bind(MessageTableModel.class).in(Singleton.class);
     }
 
 }

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java?rev=831874&r1=831873&r2=831874&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
(original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
Mon Nov  2 12:21:53 2009
@@ -296,10 +296,9 @@
         }); 
     }
     
-    public void bind(User user, IMAPFolder folder, String searchValue) {
+    public void bind(User user, IMAPFolder folder) {
         this.user = user;
         this.folder = folder;
-        this.searchValue  = searchValue;
         display.setPostFetchMessageCount(user.getSettings().getPostFetchMessageCount());
         // workaround
         if (isBound == false) {
@@ -371,5 +370,7 @@
         }
 
     };
+    
+  
 
 }

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java?rev=831874&r1=831873&r2=831874&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
(original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
Mon Nov  2 12:21:53 2009
@@ -21,13 +21,8 @@
 
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
 
-import net.customware.gwt.dispatch.client.DispatchAsync;
-import net.customware.gwt.presenter.client.EventBus;
-
-import org.apache.hupa.client.HupaCallback;
 import org.apache.hupa.client.HupaConstants;
 import org.apache.hupa.client.HupaMessages;
 import org.apache.hupa.client.bundles.HupaImageBundle;
@@ -43,9 +38,6 @@
 import org.apache.hupa.shared.data.Message;
 import org.apache.hupa.shared.data.User;
 import org.apache.hupa.shared.data.Message.IMAPFlag;
-import org.apache.hupa.shared.events.MessagesReceivedEvent;
-import org.apache.hupa.shared.rpc.FetchMessages;
-import org.apache.hupa.shared.rpc.FetchMessagesResult;
 import org.apache.hupa.widgets.ui.HasEnable;
 import org.cobogw.gwt.user.client.ui.Button;
 import org.cobogw.gwt.user.client.ui.ButtonBar;
@@ -65,18 +57,18 @@
 import com.google.gwt.gen2.table.client.FixedWidthGrid;
 import com.google.gwt.gen2.table.client.FixedWidthGridBulkRenderer;
 import com.google.gwt.gen2.table.client.MutableTableModel;
-import com.google.gwt.gen2.table.client.TableModelHelper;
 import com.google.gwt.gen2.table.client.AbstractScrollTable.ColumnResizePolicy;
 import com.google.gwt.gen2.table.client.AbstractScrollTable.ResizePolicy;
 import com.google.gwt.gen2.table.client.AbstractScrollTable.ScrollPolicy;
 import com.google.gwt.gen2.table.client.AbstractScrollTable.SortPolicy;
 import com.google.gwt.gen2.table.client.SelectionGrid.SelectionPolicy;
 import com.google.gwt.gen2.table.client.TableDefinition.AbstractCellView;
-import com.google.gwt.gen2.table.client.TableModelHelper.Request;
 import com.google.gwt.gen2.table.event.client.HasPageLoadHandlers;
 import com.google.gwt.gen2.table.event.client.HasRowSelectionHandlers;
 import com.google.gwt.gen2.table.event.client.PageLoadEvent;
 import com.google.gwt.gen2.table.event.client.PageLoadHandler;
+import com.google.gwt.gen2.table.event.client.RowCountChangeEvent;
+import com.google.gwt.gen2.table.event.client.RowCountChangeHandler;
 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Composite;
@@ -96,15 +88,11 @@
     private HupaConstants constants = GWT.create(HupaConstants.class);
     private HupaMessages messages = GWT.create(HupaMessages.class);
     private HupaImageBundle imageBundle = GWT.create(HupaImageBundle.class);
-    private DispatchAsync dispatcher;
-    private User user;
-    private IMAPFolder folder;
-    private String searchValue;
+
     private PagingOptions options;
     private DragRefetchPagingScrollTable<Message> mailTable;
-    private CachedTableModel<Message> cTableModel = new CachedTableModel<Message>(new
IMAPMessageTableModel());
+    private CachedTableModel<Message> cTableModel;
 
-    private EventBus eventBus;
     private FixedWidthGrid dataTable = createDataTable();
     private MyButton deleteMailButton = new MyButton(constants.deleteMailButton());
     private    Button newMailButton = new Button(constants.newMailButton());
@@ -120,13 +108,16 @@
 
     
     @Inject
-    public IMAPMessageListView(DispatchAsync dispatcher,EventBus bus, PagingScrollTableRowDragController
controller) {
-        this.eventBus = bus;
-        this.dispatcher = dispatcher;
-        
-        VerticalPanel vPanel = new VerticalPanel();
-
+    public IMAPMessageListView(PagingScrollTableRowDragController controller, MessageTableModel
mTableModel) {
+    	this.cTableModel = new CachedTableModel<Message>(mTableModel);
         cTableModel.setRowCount(MutableTableModel.UNKNOWN_ROW_COUNT);
+        mTableModel.addRowCountChangeHandler(new RowCountChangeHandler() {
+			
+			public void onRowCountChange(RowCountChangeEvent event) {
+				cTableModel.setRowCount(event.getNewRowCount());
+			}
+		});
+        VerticalPanel vPanel = new VerticalPanel();
         mailTable = new DragRefetchPagingScrollTable<Message>(
                 cTableModel, dataTable, new FixedWidthFlexTable(),
                 createTableDefinitation(),controller,1);
@@ -351,64 +342,7 @@
         return cList;
     }
     
-    /**
-     * TableModel which retrieve the messages for the user
-     *
-     */
-    private final class IMAPMessageTableModel extends MutableTableModel<Message> {
-
-        @Override
-        public void requestRows(
-                final Request request,
-                final com.google.gwt.gen2.table.client.TableModel.Callback<Message>
callback) {
-            
-            // if the given user or folder is null, its safe to return an empty list
-            if (user == null || folder == null) {
-                callback.onRowsReady(request, new TableModelHelper.Response<Message>()
{
-
-                    @Override
-                    public Iterator<Message> getRowValues() {
-                        return new ArrayList<Message>().iterator();
-                    }
-                    
-                });
-            }
-            
-            dispatcher.execute(new FetchMessages(folder, request.getStartRow(), request.getNumRows(),searchValue),new
HupaCallback<FetchMessagesResult>(dispatcher, eventBus) {
-                public void callback(final FetchMessagesResult result) {
-                	// Update folder information before notifying presenter
-                	folder.setMessageCount(result.getRealCount());
-                	folder.setUnseenMessageCount(result.getRealUnreadCount());
-                	// Notify presenter to update folder tree view
-                    eventBus.fireEvent(new MessagesReceivedEvent(folder, result.getMessages()));
-                    TableModelHelper.Response<Message> response = new TableModelHelper.Response<Message>()
{
-                        @Override
-                        public Iterator<Message> getRowValues() {
-                            return result.getMessages().iterator();
-                        }
-                    };
-                    cTableModel.setRowCount(result.getRealCount());
-                    callback.onRowsReady(request,response);
-                }
-            }); 
-        }
-
-        @Override
-        protected boolean onRowInserted(int beforeRow) {
-            return true;
-        }
-
-        @Override
-        protected boolean onRowRemoved(int row) {    
-            return true;
-        }
-
-        @Override
-        protected boolean onSetRowValue(int row, Message rowValue) {
-            return true;
-        }
-        
-    }
+   
 
     
     /**
@@ -497,9 +431,6 @@
      * @see org.apache.hupa.client.mvp.IMAPMessageListPresenter.Display#reloadData(org.apache.hupa.shared.data.User,
org.apache.hupa.shared.data.IMAPFolder, java.lang.String)
      */
     public void reloadData(User user, IMAPFolder folder,String searchValue) {
-        this.user = user;
-        this.folder = folder;
-        this.searchValue = searchValue;
         cTableModel.clearCache();
         mailTable.getTableModel().setRowCount(MutableTableModel.UNKNOWN_ROW_COUNT);
         mailTable.reloadPage();
@@ -510,8 +441,6 @@
      * @see org.apache.hupa.client.mvp.IMAPMessageListPresenter.Display#reset()
      */
     public void reset() {
-        this.user = null;
-        this.folder = null;
         pageBox.setSelectedIndex(0);
         cTableModel.clearCache();
         cTableModel.setRowCount(0);

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java?rev=831874&r1=831873&r2=831874&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
(original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
Mon Nov  2 12:21:53 2009
@@ -48,7 +48,6 @@
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.event.dom.client.HasClickHandlers;
-import com.google.gwt.user.client.ui.Frame;
 import com.google.gwt.user.client.ui.HasHTML;
 import com.google.gwt.user.client.ui.HasText;
 import com.google.inject.Inject;

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java?rev=831874&r1=831873&r2=831874&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java Mon
Nov  2 12:21:53 2009
@@ -233,7 +233,7 @@
         messagePresenter.unbind();
         sendPresenter.unbind();
 
-        messageListPresenter.bind(user, folder, searchValue);
+        messageListPresenter.bind(user, folder);
         if (refresh) {
             messageListPresenter.refreshDisplay();
         }

Added: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageTableModel.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageTableModel.java?rev=831874&view=auto
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageTableModel.java
(added)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageTableModel.java
Mon Nov  2 12:21:53 2009
@@ -0,0 +1,152 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.hupa.client.mvp;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import net.customware.gwt.dispatch.client.DispatchAsync;
+import net.customware.gwt.presenter.client.EventBus;
+
+import org.apache.hupa.client.HupaCallback;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.Message;
+import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.events.FolderSelectionEvent;
+import org.apache.hupa.shared.events.FolderSelectionEventHandler;
+import org.apache.hupa.shared.events.LoadMessagesEvent;
+import org.apache.hupa.shared.events.LoadMessagesEventHandler;
+import org.apache.hupa.shared.events.LoginEvent;
+import org.apache.hupa.shared.events.LoginEventHandler;
+import org.apache.hupa.shared.events.LogoutEvent;
+import org.apache.hupa.shared.events.LogoutEventHandler;
+import org.apache.hupa.shared.events.MessagesReceivedEvent;
+import org.apache.hupa.shared.rpc.FetchMessages;
+import org.apache.hupa.shared.rpc.FetchMessagesResult;
+
+import com.google.gwt.gen2.table.client.MutableTableModel;
+import com.google.gwt.gen2.table.client.TableModelHelper;
+import com.google.gwt.gen2.table.client.TableModelHelper.Request;
+import com.google.inject.Inject;
+
+/**
+ * TableModel which retrieve the messages for the user
+ *
+ */
+public class MessageTableModel extends MutableTableModel<Message> {
+
+	private EventBus eventBus;
+	private DispatchAsync dispatcher;
+	private User user;
+	private IMAPFolder folder;
+	private String searchValue;
+
+	@Inject
+	public MessageTableModel(EventBus eventBus, DispatchAsync dispatcher){
+		
+		this.eventBus = eventBus;
+		this.dispatcher = dispatcher;
+
+		eventBus.addHandler(LoadMessagesEvent.TYPE, new LoadMessagesEventHandler() {
+			
+			public void onLoadMessagesEvent(LoadMessagesEvent loadMessagesEvent) {
+				user = loadMessagesEvent.getUser();
+				folder = loadMessagesEvent.getFolder();
+				searchValue = loadMessagesEvent.getSearchValue();
+			}
+		});
+		eventBus.addHandler(FolderSelectionEvent.TYPE, new FolderSelectionEventHandler() {
+			
+			public void onFolderSelectionEvent(FolderSelectionEvent event) {
+				user = event.getUser();
+				folder = event.getFolder();
+				searchValue = null;
+			}
+		});
+		eventBus.addHandler(LoginEvent.TYPE, new LoginEventHandler() {
+			
+			public void onLogin(LoginEvent event) {
+				user = event.getUser();
+				folder = null;
+				searchValue = null;
+			}
+		});
+		eventBus.addHandler(LogoutEvent.TYPE, new LogoutEventHandler() {
+			
+			public void onLogout(LogoutEvent logoutEvent) {
+				user = null;
+				folder = null;
+				searchValue = null;
+			}
+		});
+		
+		
+	}
+
+	@Override 
+    public void requestRows(
+            final Request request,
+            final com.google.gwt.gen2.table.client.TableModel.Callback<Message> callback)
{
+        
+        // if the given user or folder is null, its safe to return an empty list
+        if (user == null || folder == null) {
+            callback.onRowsReady(request, new TableModelHelper.Response<Message>()
{
+
+                @Override
+                public Iterator<Message> getRowValues() {
+                    return new ArrayList<Message>().iterator();
+                }
+                
+            });
+        }
+        
+        dispatcher.execute(new FetchMessages(folder, request.getStartRow(), request.getNumRows(),
searchValue),new HupaCallback<FetchMessagesResult>(dispatcher, eventBus) {
+            public void callback(final FetchMessagesResult result) {
+            	// Update folder information before notifying presenter
+            	folder.setMessageCount(result.getRealCount());
+            	folder.setUnseenMessageCount(result.getRealUnreadCount());
+            	// Notify presenter to update folder tree view
+                eventBus.fireEvent(new MessagesReceivedEvent(folder, result.getMessages()));
+                TableModelHelper.Response<Message> response = new TableModelHelper.Response<Message>()
{
+                    @Override
+                    public Iterator<Message> getRowValues() {
+                        return result.getMessages().iterator();
+                    }
+                };
+                setRowCount(result.getRealCount());
+                callback.onRowsReady(request,response);
+            }
+        }); 
+    }
+
+    @Override
+    protected boolean onRowInserted(int beforeRow) {
+        return true;
+    }
+
+    @Override
+    protected boolean onRowRemoved(int row) {    
+        return true;
+    }
+
+    @Override
+    protected boolean onSetRowValue(int row, Message rowValue) {
+        return true;
+    }
+}

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java?rev=831874&r1=831873&r2=831874&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java
(original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java
Mon Nov  2 12:21:53 2009
@@ -60,6 +60,9 @@
             ExecutionContext context) throws ActionException {
         User user = getUser();
         IMAPFolder folder = action.getFolder();
+        if (folder == null) {
+        	folder = new IMAPFolder(user.getSettings().getInboxFolderName());
+        }
         com.sun.mail.imap.IMAPFolder f = null;
         try {
             IMAPStore store = cache.get(user);



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message