You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2010/01/19 19:57:29 UTC
svn commit: r900907 - in /james/hupa/trunk: client/
client/src/main/java/org/apache/hupa/client/mvp/
client/src/main/java/org/apache/hupa/client/validation/
client/src/main/java/org/apache/hupa/client/widgets/ client/src/test/
client/src/test/java/ cli...
Author: manolo
Date: Tue Jan 19 18:57:27 2010
New Revision: 900907
URL: http://svn.apache.org/viewvc?rev=900907&view=rev
Log:
Implemented selection of multiple e-mails from suggestion list in the to, cc, and bcc fields.
Changed text-boxes by text-areas in to, cc and bcc to fit more addresses.
Hide cc, bcc and attachments, when they are empty to save visual space.
Fixed a bug in the client email validator
Added:
james/hupa/trunk/client/src/test/
james/hupa/trunk/client/src/test/java/
james/hupa/trunk/client/src/test/java/org/
james/hupa/trunk/client/src/test/java/org/apache/
james/hupa/trunk/client/src/test/java/org/apache/hupa/
james/hupa/trunk/client/src/test/java/org/apache/hupa/HupaTest.gwt.xml
james/hupa/trunk/client/src/test/java/org/apache/hupa/client/
james/hupa/trunk/client/src/test/java/org/apache/hupa/client/validation/
james/hupa/trunk/client/src/test/java/org/apache/hupa/client/validation/EmailListValidatorTest.java
james/hupa/trunk/client/war/WEB-INF/classes/
james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/MultiValueSuggestArea.java
Modified:
james/hupa/trunk/client/pom.xml
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/MessageSendPresenter.java
james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java
james/hupa/trunk/client/src/main/java/org/apache/hupa/client/validation/EmailListValidator.java
james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/MessageHeaders.java
james/hupa/trunk/client/war/Hupa.css
james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/EnableHyperlink.java
Modified: james/hupa/trunk/client/pom.xml
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/pom.xml?rev=900907&r1=900906&r2=900907&view=diff
==============================================================================
--- james/hupa/trunk/client/pom.xml (original)
+++ james/hupa/trunk/client/pom.xml Tue Jan 19 18:57:27 2010
@@ -113,5 +113,10 @@
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
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=900907&r1=900906&r2=900907&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 Tue Jan 19 18:57:27 2010
@@ -195,7 +195,6 @@
pageBox.addItem("" + (DEFAULT_MSG_PAGE_SIZE * 4));
pageBox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
- System.out.println(pageBox.getSelectedIndex());
if (pageBox.getSelectedIndex() > 0)
mailTable.setPageSize(Integer.parseInt(pageBox.getItemText(pageBox.getSelectedIndex())));
}
Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java?rev=900907&r1=900906&r2=900907&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java Tue Jan 19 18:57:27 2010
@@ -373,7 +373,7 @@
oldmessage.getTo().remove(user.getName());
display.getToText().setText(Util.listToString(oldmessage.getTo()));
}
- }
+ }
display.getMessageHTML().setHTML(wrapMessage(oldmessage, oldDetails, type));
Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java?rev=900907&r1=900906&r2=900907&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java Tue Jan 19 18:57:27 2010
@@ -26,8 +26,6 @@
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
-import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
@@ -49,6 +47,7 @@
import org.apache.hupa.widgets.ui.EnableHyperlink;
import org.apache.hupa.widgets.ui.HasEnable;
import org.apache.hupa.widgets.ui.Loading;
+import org.apache.hupa.widgets.ui.MultiValueSuggestArea;
/**
* View which displays a form which handle sending of mails
@@ -64,12 +63,13 @@
private Editor editor;
private CommandsBar buttonsBar = new CommandsBar();
- private MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(" ,@<>");
-
private Label from = new Label();
- private SuggestBox to = new SuggestBox(oracle);
- private SuggestBox cc = new SuggestBox(oracle);
- private SuggestBox bcc = new SuggestBox(oracle);
+
+ private MultiValueSuggestArea to = new MultiValueSuggestArea(" ,@<>");
+ // we only need one instance for all suggestion-boxes
+ private MultiValueSuggestArea cc = new MultiValueSuggestArea(to.getOracle());
+ private MultiValueSuggestArea bcc = new MultiValueSuggestArea(to.getOracle());
+
private TextBox subject = new TextBox();
private MultiUploader uploader = null;
@@ -227,21 +227,20 @@
* @see org.apache.hupa.client.mvp.MessageSendPresenter.Display#getEditorFocus()
*/
public Focusable getEditorFocus() {
- return to;
+ return editor;
}
/* (non-Javadoc)
* @see org.apache.hupa.client.mvp.MessageSendPresenter.Display#refresh()
*/
public void refresh() {
+ if (to.getText().isEmpty())
+ to.setText(" ");
headers.setValues(from, to, cc, bcc, subject, uploader);
}
public void fillContactList(Contact[] contacts){
- oracle.clear();
- for (Contact c: contacts) {
- oracle.add(c.toString());
- }
+ to.fillOracle(contacts);
}
}
Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/validation/EmailListValidator.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/validation/EmailListValidator.java?rev=900907&r1=900906&r2=900907&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/validation/EmailListValidator.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/validation/EmailListValidator.java Tue Jan 19 18:57:27 2010
@@ -33,8 +33,9 @@
*
*/
public class EmailListValidator extends Validator<EmailListValidator>{
+ private static final String emailRegex = "^(.*<)?[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}(>)?\\s*$";
+
private HasText text;
- private String emailRegex = "^(.+<)?[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}(>)?$";
public EmailListValidator(HasText text) {
this.text = text;
}
@@ -60,14 +61,16 @@
* @param text
* @return isValid
*/
- private boolean isValidAddressList(String text) {
+ public static boolean isValidAddressList(String text) {
if (text.length() > 0) {
- String[] addresses = text.split(",");
+ if (text.replaceAll("[,:\\s]+", "").isEmpty())
+ return false;
+ String[] addresses = text.split("[,;]+");
if (addresses == null || addresses.length == 0) {
- return isValidAddress(text);
+ return isValidAddress(text.trim());
} else {
for (int i = 0; i < addresses.length; i++) {
- if (isValidAddress(addresses[i]) == false) {
+ if (!addresses[i].trim().isEmpty() && isValidAddress(addresses[i]) == false) {
return false;
}
}
@@ -82,7 +85,7 @@
* @param email
* @return isValid
*/
- private boolean isValidAddress(String email) {
+ public static boolean isValidAddress(String email) {
return email.matches(emailRegex);
}
}
Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/MessageHeaders.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/MessageHeaders.java?rev=900907&r1=900906&r2=900907&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/MessageHeaders.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/MessageHeaders.java Tue Jan 19 18:57:27 2010
@@ -1,16 +1,22 @@
package org.apache.hupa.client.widgets;
-import org.apache.hupa.client.HupaCSS;
-import org.apache.hupa.client.HupaConstants;
-
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.gen2.table.override.client.FlexTable;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
+import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
+import gwtupload.client.IUploader;
+
+import org.apache.hupa.client.HupaCSS;
+import org.apache.hupa.client.HupaConstants;
+import org.apache.hupa.widgets.ui.EnableHyperlink;
+import org.apache.hupa.widgets.ui.MultiValueSuggestArea;
+
/**
* A panel which displays the headers of a message.
*/
@@ -46,23 +52,44 @@
addRow(headerNames[i], widgets[i]);
}
- private void addRow(String name, Widget widget) {
+ private Widget createLinkToShow(String name, final Widget widget) {
+ final EnableHyperlink link = new EnableHyperlink(name + ":");
+ link.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ widget.setVisible(true);
+ link.setEnabled(false);
+ }
+ });
+ widget.setVisible(false);
+ return link;
+ }
+
+ private void addRow(String name, final Widget widget) {
if (widget == null)
return;
-
- if (widget instanceof TextBox || widget instanceof SuggestBox){
+
+ Widget label = new Label(name + ":");
+ if (widget instanceof MultiValueSuggestArea){
+ widget.setWidth("100%");
+ if (((HasText)widget).getText().isEmpty())
+ label = createLinkToShow(name, widget);
+ } else if (widget instanceof TextBox) {
widget.setWidth("100%");
} else if (widget instanceof HasText) {
if (((HasText)widget).getText().isEmpty())
return;
+ } else if (widget instanceof IUploader) {
+ label = createLinkToShow(name, widget);
} else if (widget instanceof Panel) {
if (((Panel)widget).iterator().hasNext() == false)
return;
}
- detailGrid.setText(rowCounter, 0, name + ":");
+
+ detailGrid.setWidget(rowCounter, 0, label);
detailGrid.setWidget(rowCounter, 1, widget);
detailGrid.getCellFormatter().setStyleName(rowCounter, 0, "label");
detailGrid.getCellFormatter().setStyleName(rowCounter, 1, "value");
rowCounter ++;
}
+
}
Added: james/hupa/trunk/client/src/test/java/org/apache/hupa/HupaTest.gwt.xml
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/HupaTest.gwt.xml?rev=900907&view=auto
==============================================================================
--- james/hupa/trunk/client/src/test/java/org/apache/hupa/HupaTest.gwt.xml (added)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/HupaTest.gwt.xml Tue Jan 19 18:57:27 2010
@@ -0,0 +1,3 @@
+<module rename-to='hupa'>
+ <inherits name='com.google.gwt.user.User'/>
+</module>
Added: james/hupa/trunk/client/src/test/java/org/apache/hupa/client/validation/EmailListValidatorTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/client/validation/EmailListValidatorTest.java?rev=900907&view=auto
==============================================================================
--- james/hupa/trunk/client/src/test/java/org/apache/hupa/client/validation/EmailListValidatorTest.java (added)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/client/validation/EmailListValidatorTest.java Tue Jan 19 18:57:27 2010
@@ -0,0 +1,17 @@
+package org.apache.hupa.client.validation;
+
+import junit.framework.TestCase;
+
+
+public class EmailListValidatorTest extends TestCase{
+
+ public void testEmailValidator() {
+ assertTrue(EmailListValidator.isValidAddressList("abc@abc.def"));
+ assertTrue(EmailListValidator.isValidAddressList("<ab...@abc.def>"));
+ assertTrue(EmailListValidator.isValidAddressList(" AAA <ab...@abc.def> "));
+ assertFalse(EmailListValidator.isValidAddressList(", , ,"));
+ assertFalse(EmailListValidator.isValidAddressList("abc@abc.def ; ; MMM <mc...@aa>;;;"));
+ assertTrue(EmailListValidator.isValidAddressList("abc@abc.def ; ; MMM <mc...@aa.co>;;;"));
+ }
+
+}
Modified: james/hupa/trunk/client/war/Hupa.css
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/war/Hupa.css?rev=900907&r1=900906&r2=900907&view=diff
==============================================================================
--- james/hupa/trunk/client/war/Hupa.css (original)
+++ james/hupa/trunk/client/war/Hupa.css Tue Jan 19 18:57:27 2010
@@ -208,7 +208,7 @@
width: 150px;
}
-input[type=text], input[type=file] {
+input[type=text], input[type=file], textarea {
background-color: #d8ecfd;
border: 1px solid #7FAAFF;
}
Modified: james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/EnableHyperlink.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/EnableHyperlink.java?rev=900907&r1=900906&r2=900907&view=diff
==============================================================================
--- james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/EnableHyperlink.java (original)
+++ james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/EnableHyperlink.java Tue Jan 19 18:57:27 2010
@@ -20,17 +20,19 @@
package org.apache.hupa.widgets.ui;
-import org.apache.hupa.widgets.WidgetsCSS;
-
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.user.client.ui.Widget;
+
+import org.apache.hupa.widgets.WidgetsCSS;
/**
* Hyperlink which can get enabled/disabled.
@@ -50,15 +52,20 @@
public class EnableHyperlink extends Composite implements HasClickHandlers,HasHTML,HasText, HasEnable{
private SimplePanel panel = new SimplePanel();
- private Hyperlink link;
+ private Widget link;
private HTML html;
+
+ public EnableHyperlink(String text) {
+ this(text, false, null);
+ }
+
public EnableHyperlink(String text, String historyToken) {
- this(text,false,historyToken);
+ this(text, false, historyToken);
}
public EnableHyperlink(String text, boolean asHTML, String historyToken) {
- link = new Hyperlink(text,asHTML,historyToken);
+ link = historyToken != null ? new Hyperlink(text, asHTML, historyToken) : new Anchor(text);
html = new HTML();
panel.setStyleName(WidgetsCSS.C_hyperlink);
@@ -79,7 +86,7 @@
* @see com.google.gwt.event.dom.client.HasClickHandlers#addClickHandler(com.google.gwt.event.dom.client.ClickHandler)
*/
public HandlerRegistration addClickHandler(ClickHandler handler) {
- return link.addClickHandler(handler);
+ return ((HasClickHandlers)link).addClickHandler(handler);
}
/*
@@ -87,7 +94,7 @@
* @see com.google.gwt.user.client.ui.HasText#getText()
*/
public String getText() {
- return link.getText();
+ return ((HasHTML)link).getText();
}
/*
@@ -95,7 +102,7 @@
* @see com.google.gwt.user.client.ui.HasText#setText(java.lang.String)
*/
public void setText(String text) {
- link.setText(text);
+ ((HasHTML)link).setText(text);
html.setText(text);
}
@@ -104,7 +111,7 @@
* @see com.google.gwt.user.client.ui.HasHTML#getHTML()
*/
public String getHTML() {
- return link.getHTML();
+ return ((HasHTML)link).getHTML();
}
/*
Added: james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/MultiValueSuggestArea.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/MultiValueSuggestArea.java?rev=900907&view=auto
==============================================================================
--- james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/MultiValueSuggestArea.java (added)
+++ james/hupa/trunk/widgets/src/main/java/org/apache/hupa/widgets/ui/MultiValueSuggestArea.java Tue Jan 19 18:57:27 2010
@@ -0,0 +1,116 @@
+/****************************************************************
+ * 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.widgets.ui;
+
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.HasText;
+import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
+import com.google.gwt.user.client.ui.SuggestBox;
+import com.google.gwt.user.client.ui.SuggestOracle;
+import com.google.gwt.user.client.ui.TextArea;
+
+/**
+ * A text-area which shows a pop-up with suggestions.
+ * Different values in the text area are separated by comma.
+ *
+ * @author manolo
+ */
+public class MultiValueSuggestArea extends Composite implements HasText {
+
+ /**
+ * It is necessary to modify the behavior of the default SuggestBox, because
+ * it look for items which match the entire text in the box.
+ *
+ * @author manolo
+ */
+ private class CustomSuggestBox extends SuggestBox {
+
+ public CustomSuggestBox(SuggestOracle oracle) {
+ // this is a hack, It is necessary to override the TextBoxBase passed to the constructor
+ // instead of override getText and setText from SuggestBox because a bug in the implementation
+ // I've sent a patch to gwt.
+ super(oracle, new TextArea() {
+ @Override
+ public String getText() {
+ return super.getText().replaceAll("^.*[,; \r\n]+", "");
+ }
+
+ @Override
+ public void setText(String text) {
+ String actual = super.getText().replaceFirst("[\r\n]+", "").replaceFirst(".$", "").replaceFirst("[,; \r\n]+[^,; \r\n]*$", "");
+ super.setText(actual + (actual.isEmpty() ? "" : ", ") + text + (text.isEmpty() ? "" : ", "));
+ }
+ });
+ }
+
+ // We have to use getValue and setValue to get/set the entire text of the textarea
+ // because setText and getText have different behavior since we have modified
+ // this methods in the the box implementation
+ @Override
+ public String getValue() {
+ return DOM.getElementProperty(getTextBox().getElement(), "value");
+ }
+
+ @Override
+ public void setValue(String text) {
+ DOM.setElementProperty(getTextBox().getElement(), "value", text);
+ }
+ }
+
+ private SuggestBox box;
+
+ private MultiWordSuggestOracle oracle;
+
+ public MultiValueSuggestArea(SuggestOracle oracle) {
+ box = new CustomSuggestBox(oracle);
+ initWidget(box);
+ }
+
+ public MultiValueSuggestArea(String separators) {
+ this(null, separators);
+ }
+
+ public MultiValueSuggestArea(Object[] list, String separators) {
+ oracle = new MultiWordSuggestOracle(separators);
+ box = new CustomSuggestBox(oracle);
+ initWidget(box);
+ fillOracle(list);
+ }
+
+ public String getText() {
+ return box.getValue();
+ }
+
+ public void setText(String text) {
+ box.setValue(text);
+ }
+
+ public void fillOracle(Object[] list) {
+ oracle.clear();
+ if (list != null)
+ for (Object o : list)
+ oracle.add(o.toString());
+ }
+
+ public SuggestOracle getOracle() {
+ return oracle;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org