labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r795828 - in /labs/hupa/src/main/java/org/apache/hupa: client/mvp/ server/ server/guice/ shared/data/ shared/rpc/
Date Mon, 20 Jul 2009 13:29:41 GMT
Author: norman
Date: Mon Jul 20 13:29:40 2009
New Revision: 795828

URL: http://svn.apache.org/viewvc?rev=795828&view=rev
Log:
Add support for deleting messages
Some cleanup

Modified:
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
    labs/hupa/src/main/java/org/apache/hupa/server/DeleteMessageHandler.java
    labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java
    labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java
    labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java
    labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPFolder.java
    labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPMessage.java
    labs/hupa/src/main/java/org/apache/hupa/shared/rpc/DeleteMessageResult.java

Modified: labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java Mon Jul
20 13:29:40 2009
@@ -39,6 +39,8 @@
 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.rpc.DeleteMessage;
 import org.apache.hupa.shared.rpc.DeleteMessageResult;
 
@@ -56,12 +58,15 @@
 		public ArrayList<Integer> getSelectedMessagesUids();
 		public com.google.gwt.event.dom.client.HasClickHandlers getDeleteClick();
 		public void reloadData(IMAPUser user, IMAPFolder folder,String searchValue);
+		public void removeMessages(ArrayList<Integer> uids);
+		public void reset();
 	}
 
-	protected IMAPUser user;
-	protected IMAPFolder folder;
-	protected String searchValue;
+	private IMAPUser user;
+	private IMAPFolder folder;
+	private String searchValue;
 	private DispatchAsync dispatcher;
+	public final static Place PLACE = new Place("IMAPMessageList");
 	
 	@Inject
 	public IMAPMessageListPresenter(IMAPMessageListPresenter.Display display,EventBus bus,DispatchAsync
dispatcher) {
@@ -72,8 +77,7 @@
 	
 	@Override
 	public Place getPlace() {
-		// TODO Auto-generated method stub
-		return null;
+		return PLACE;
 	}
 
 	@Override
@@ -98,7 +102,14 @@
 
 			
 		});
-		
+		eventBus.addHandler(LogoutEvent.TYPE, new LogoutEventHandler() {
+
+			public void onLogout(LogoutEvent event) {
+				display.reset();
+			}
+
+			
+		});
 		display.getDataTableClick().addClickHandler(new ClickHandler<IMAPMessage>() {
 
 			public void onClick(ClickEvent<IMAPMessage> event) {
@@ -119,8 +130,7 @@
 					}
 
 					public void onSuccess(DeleteMessageResult result) {
-						// TODO Auto-generated method stub
-						
+						display.removeMessages(result.getMessageUids());
 					}
 					
 				});

Modified: labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java Mon Jul 20
13:29:40 2009
@@ -99,6 +99,8 @@
 	private MyFixedWidthGrid<IMAPMessage> dataTable = createDataTable();
 	private ArrayList<Integer> selectedUids = new ArrayList<Integer>();
 	private Button deleteMailButton = new Button(constants.deleteMailButton());
+	private ListBox pageBox = new ListBox();
+
 
 	
 	@Inject
@@ -195,6 +197,7 @@
 		navigatorBar.add(deleteMailButton);
 		
 		
+		// Add handler to get a list of selected rows
 		mailTable.getDataTable().addRowSelectionHandler(new RowSelectionHandler() {
 
 			public void onRowSelection(RowSelectionEvent event) {
@@ -203,18 +206,21 @@
 				} else {
 					deleteMailButton.setEnabled(true);
 				}
-				selectedUids.clear();
 				Iterator<Row> rowIt = event.getSelectedRows().iterator();
 				while(rowIt.hasNext()) {
 					int uid = mailTable.getRowValue(rowIt.next().getRowIndex()).getUid();
-					selectedUids.add(uid);
+					selectedUids.add(new Integer(uid));
+				}
+				Iterator<Row> deselectedRowIt = event.getDeselectedRows().iterator();
+				while(deselectedRowIt.hasNext()) {
+					int uid = mailTable.getRowValue(deselectedRowIt.next().getRowIndex()).getUid();
+					selectedUids.remove(new Integer(uid));
 				}
 				
 			}
 			
 		});
 		
-		final ListBox pageBox = new ListBox();
 		pageBox.addItem("20");
 		pageBox.addItem("50");
 		pageBox.addItem("100");
@@ -448,6 +454,13 @@
 		mailTable.getTableModel().setRowCount(0);
 		mailTable.reloadPage();
 	}
+	
+	public void reset() {
+		this.user = null;
+		this.folder = null;
+		pageBox.setSelectedIndex(0);
+		
+	}
 
 	public HasPageLoadHandlers getDataTableLoad() {
 		return mailTable;
@@ -478,5 +491,18 @@
 	public HasClickHandlers getDeleteClick() {
 		return deleteMailButton;
 	}
-	
+
+	public void removeMessages(ArrayList<Integer> uids) {
+		List<Integer> rows = new ArrayList<Integer>();
+		for (int a = 0; a < dataTable.getRowCount(); a++) {
+			IMAPMessage msg = mailTable.getRowValue(a);
+			if (uids.contains(msg.getUid())) {
+				rows.add(a);
+			}
+		}
+		// remove rows
+		for (int i = 0; i < rows.size(); i++) {
+			dataTable.removeRow(rows.get(i) -i);
+		}
+	}
 }

Modified: labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java Mon Jul 20
13:29:40 2009
@@ -19,6 +19,9 @@
 
 package org.apache.hupa.client.mvp;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+
 import net.customware.gwt.dispatch.client.DispatchAsync;
 import net.customware.gwt.presenter.client.EventBus;
 import net.customware.gwt.presenter.client.place.Place;
@@ -26,8 +29,18 @@
 import net.customware.gwt.presenter.client.widget.WidgetDisplay;
 import net.customware.gwt.presenter.client.widget.WidgetPresenter;
 
+import org.apache.hupa.shared.data.IMAPFolder;
 import org.apache.hupa.shared.data.IMAPMessage;
-
+import org.apache.hupa.shared.data.IMAPUser;
+import org.apache.hupa.shared.events.LoadMessagesEvent;
+import org.apache.hupa.shared.rpc.DeleteMessage;
+import org.apache.hupa.shared.rpc.DeleteMessageResult;
+import org.apache.hupa.shared.rpc.FetchMessages;
+
+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.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.HasHTML;
 import com.google.gwt.user.client.ui.HasText;
 import com.google.inject.Inject;
@@ -44,11 +57,15 @@
 		public HasText getSubject();
 
 		public HasHTML getContent();
+		
+		public HasClickHandlers getDeleteButtonClick();
 	}
 
 	public static final Place PLACE = new Place("IMAPMessage");
 	private IMAPMessage message;
 	private DispatchAsync dispatcher;
+	private IMAPFolder folder;
+	private IMAPUser user;
 
 	@Inject
 	private IMAPMessagePresenter(IMAPMessagePresenter.Display display,EventBus bus, DispatchAsync
dispatcher) {
@@ -58,8 +75,10 @@
 	}
 
 	
-	public void bind(IMAPMessage message) {
+	public void bind(IMAPUser user, IMAPFolder folder, IMAPMessage message) {
 		this.message = message;
+		this.folder = folder;
+		this.user = user;
 		updateDisplay();
 	}
 
@@ -77,6 +96,28 @@
 
 	@Override
 	protected void onBind() {
+		display.getDeleteButtonClick().addClickHandler(new ClickHandler() {
+
+			public void onClick(ClickEvent event) {
+				ArrayList<Integer> uidList = new ArrayList<Integer>();
+				uidList.add(message.getUid());
+				dispatcher.execute(new DeleteMessage(user,folder,uidList), new AsyncCallback<DeleteMessageResult>()
{
+
+					public void onFailure(Throwable caught) {
+						// TODO Auto-generated method stub
+						
+					}
+
+					public void onSuccess(DeleteMessageResult result) {
+						eventBus.fireEvent(new LoadMessagesEvent(user,folder));
+					}
+					
+				});
+			}
+			
+		});
+		
+		
 	}
 
 	@Override

Modified: labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java Mon Jul 20 13:29:40
2009
@@ -25,6 +25,7 @@
 import org.cobogw.gwt.user.client.ui.ButtonBar;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.HasClickHandlers;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.Grid;
 import com.google.gwt.user.client.ui.HTML;
@@ -136,4 +137,8 @@
 		
 	}
 
+	public HasClickHandlers getDeleteButtonClick() {
+		return deleteMsgButton;
+	}
+
 }

Modified: labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java Mon Jul 20 13:29:40
2009
@@ -66,7 +66,6 @@
 import com.google.gwt.user.client.ui.HasValue;
 import com.google.gwt.user.client.ui.TreeItem;
 import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.user.client.ui.HTMLTable.Cell;
 import com.google.inject.Inject;
 
 public class MainPresenter extends WidgetPresenter<MainPresenter.Display>{
@@ -86,11 +85,10 @@
 	private IMAPUser user;
 	private IMAPFolder folder;
 	
-	protected Cell cell;
 	private IMAPTreeItem tItem;
 	private IMAPMessageListPresenter messageListPresenter;
 	private IMAPMessagePresenter messagePresenter;
-	
+	public static final Place PLACE = new Place("Main");
 	
 	@Inject
 	public MainPresenter(MainPresenter.Display display, EventBus bus, DispatchAsync dispatcher,IMAPMessageListPresenter
messageListPresenter, IMAPMessagePresenter messagePresenter) {
@@ -182,7 +180,7 @@
 	}
 	
 	private void showMessage(IMAPMessage message) {
-		messagePresenter.bind(message);
+		messagePresenter.bind(user,folder,message);
 		display.setCenter(messagePresenter.getDisplay().asWidget());
 	}
 	
@@ -195,8 +193,7 @@
 
 	@Override
 	public Place getPlace() {
-		// TODO Auto-generated method stub
-		return null;
+		return PLACE;
 	}
 
 	@Override
@@ -220,7 +217,9 @@
 		eventBus.addHandler(MessagesReceivedEvent.TYPE, new MessagesReceivedEventHandler() {
 
 			public void onMessagesReceived(MessagesReceivedEvent event) {
+				// fill the oracle and display the messagetable
 				display.fillOracle(event.getMessages());
+				showMessageTable();
 			}
 			
 		});

Modified: labs/hupa/src/main/java/org/apache/hupa/server/DeleteMessageHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/DeleteMessageHandler.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/DeleteMessageHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/DeleteMessageHandler.java Mon Jul 20 13:29:40
2009
@@ -19,6 +19,8 @@
 
 package org.apache.hupa.server;
 
+import java.util.ArrayList;
+
 import net.customware.gwt.dispatch.server.ActionHandler;
 import net.customware.gwt.dispatch.server.ExecutionContext;
 import net.customware.gwt.dispatch.shared.ActionException;
@@ -44,25 +46,39 @@
 		this.logger = logger;
 	}
 
+	/*
+	 * (non-Javadoc)
+	 * @see net.customware.gwt.dispatch.server.ActionHandler#execute(net.customware.gwt.dispatch.shared.Action,
net.customware.gwt.dispatch.server.ExecutionContext)
+	 */
 	public DeleteMessageResult execute(DeleteMessage action, ExecutionContext context)
 			throws ActionException {
+		IMAPFolder folder = action.getFolder();
+		ArrayList<Integer> uids = action.getMessageUids();
+
+		logger.info("Deleting messages with uids "+ action.getMessageUids() + " for user " + action.getUser()
+ " in folder" + action.getFolder());
+
 		try {
 			IMAPProtocol protocol = cache.getProtocol(action.getUser());
-			IMAPFolder folder = action.getFolder();
+		
 			protocol.select(folder.getFullName());
 			
+			SequenceSet set = new SequenceSet(uids);
 			if (folder.getFullName().equalsIgnoreCase(IMAPFolder.DEFAULT_TRASH) == false) {
-				protocol.copy(new SequenceSet(action.getMessageUids()), IMAPFolder.DEFAULT_TRASH);
+				protocol.uidCopy(set, IMAPFolder.DEFAULT_TRASH);
 			} 
-			protocol.store(new SequenceSet(action.getMessageUids()), true, new IMAPFlags(IMAPFlags.DELETED));
+			protocol.uidStore(set, true, new IMAPFlags(IMAPFlags.DELETED));
 			protocol.expunge();
 		} catch (Exception e) {
-			logger.error("Error while deleting messages with uids + "+ action.getMessageUids() + "
for user " + action.getUser() + " in" + action.getFolder());
+			logger.error("Error while deleting messages with uids "+ action.getMessageUids() + " for
user " + action.getUser() + " in folder" + action.getFolder(),e);
 			throw new ActionException("Error while deleting messages",e);
 		}
-		return new DeleteMessageResult();
+		return new DeleteMessageResult(action.getUser(),folder,uids);
 	}
 
+	/*
+	 * (non-Javadoc)
+	 * @see net.customware.gwt.dispatch.server.ActionHandler#getActionType()
+	 */
 	public Class<DeleteMessage> getActionType() {
 		return DeleteMessage.class;
 	}

Modified: labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java Mon Jul 20 13:29:40
2009
@@ -106,7 +106,6 @@
 				}
 				sSet = new SequenceSet(matchedList);
 			}
-			
 			org.columba.ristretto.imap.IMAPHeader[] headers = proto
 					.fetchHeader(sSet);
 			IMAPFlags[] flags = proto.fetchFlags(sSet);

Modified: labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java Mon Jul 20 13:29:40
2009
@@ -47,9 +47,12 @@
 			throws ActionException {
 		IMAPUser user = action.getUser();
 		user.setAuthenticated(false);
-		
-		disconnect(user);
-		
+		try {
+			cache.getProtocol(user).expunge();
+		} catch (Exception e) {
+			logger.error("Error while expunge for user " + user);
+		} 
+		cache.deleteProcotol(user);
 		return new LogoutUserResult(user);
 	}
 
@@ -61,9 +64,4 @@
 			ExecutionContext arg2) throws ActionException {
 		
 	}
-	
-	protected void disconnect(IMAPUser user) {
-		cache.deleteProcotol(user);
-	}
-
 }

Modified: labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java Mon Jul 20 13:29:40
2009
@@ -22,6 +22,7 @@
 import net.customware.gwt.dispatch.server.guice.ActionHandlerModule;
 
 import org.apache.commons.logging.Log;
+import org.apache.hupa.server.DeleteMessageHandler;
 import org.apache.hupa.server.ExposeMessageHandler;
 import org.apache.hupa.server.FetchFoldersHandler;
 import org.apache.hupa.server.FetchMessagesHandler;
@@ -48,6 +49,7 @@
 		bindHandler(FetchMessagesHandler.class);
 		bindHandler(LogoutUserHandler.class);
 		bindHandler(ExposeMessageHandler.class);
+		bindHandler(DeleteMessageHandler.class);
 		bindHandler(NoopHandler.class);
 		
 		bind(IMAPProtocolCache.class).in(Singleton.class);

Modified: labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPFolder.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPFolder.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPFolder.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPFolder.java Mon Jul 20 13:29:40
2009
@@ -96,6 +96,11 @@
 	}
 
 	@Override
+	public String toString() {
+		return getFullName();
+	}
+	
+	@Override
 	public boolean equals(Object o) {
 		if (o instanceof IMAPFolder) {
 			if (((IMAPFolder) o).getFullName().equals(getFullName())) {

Modified: labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPMessage.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPMessage.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPMessage.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPMessage.java Mon Jul 20 13:29:40
2009
@@ -76,6 +76,7 @@
 		}
 	}
 
+
 	public String toString() {
 		return String.valueOf(getUid());
 	}

Modified: labs/hupa/src/main/java/org/apache/hupa/shared/rpc/DeleteMessageResult.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/rpc/DeleteMessageResult.java?rev=795828&r1=795827&r2=795828&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/rpc/DeleteMessageResult.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/rpc/DeleteMessageResult.java Mon Jul 20
13:29:40 2009
@@ -19,6 +19,11 @@
 
 package org.apache.hupa.shared.rpc;
 
+import java.util.ArrayList;
+
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.IMAPUser;
+
 import net.customware.gwt.dispatch.shared.Result;
 
 public class DeleteMessageResult implements Result{
@@ -27,8 +32,33 @@
 	 * 
 	 */
 	private static final long serialVersionUID = -5149203502019947912L;
+	private IMAPUser user;
+	private IMAPFolder folder;
+	private ArrayList<Integer> messageUids;
 
 
-	public DeleteMessageResult() {		
+	
+	@SuppressWarnings("unused")
+	private DeleteMessageResult() {
+		
+	}
+	
+	public DeleteMessageResult(IMAPUser user,IMAPFolder folder, ArrayList<Integer> messageUids)
{
+		this.user = user;
+		this.folder = folder;
+		this.messageUids = messageUids;
+	}
+	
+	public IMAPUser getUser() {
+		return user;
 	}
+	
+	public IMAPFolder getFolder() {
+		return folder;
+	}
+	
+	public ArrayList<Integer> getMessageUids() {
+		return messageUids;
+	}
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message