Review Board 1.7.22


Implement wave-317: Allow adding (copy/pasting) multiple participants into a wave

Review Request #3882 - Created Feb. 13, 2012 and submitted

rocklund
trunk
wave-317
Reviewers
wave
wave
Implemented as suggested in the jira-issue as a client side implementation in ParticipantController.java. I selected the separator for the multiple participant list to be comma (,) as stated in the jira issue.
Compiled and run.

* Tested to add single as well as multiple participants
* Tested to add participants both with and without @localhost
* Tested to add invalid participants

Diff revision 4

This is not the most recent revision of the diff. The latest diff is revision 6. See what's changed.

1 2 3 4 5 6
1 2 3 4 5 6

  1. src/org/waveprotocol/wave/client/wavepanel/impl/edit/ParticipantController.java: Loading...
  2. test/org/waveprotocol/wave/client/wavepanel/impl/edit/ParticipantControllerTest.java: Loading...
src/org/waveprotocol/wave/client/wavepanel/impl/edit/ParticipantController.java
Revision ec9e25a New Change
[20] 13 lines
[+20]
14
 * limitations under the License.
14
 * limitations under the License.
15
 *
15
 *
16
 */
16
 */
17
package org.waveprotocol.wave.client.wavepanel.impl.edit;
17
package org.waveprotocol.wave.client.wavepanel.impl.edit;
18

    
   
18

   

    
   
19
import javax.annotation.Nullable;

    
   
20

   
19
import com.google.gwt.dom.client.Element;
21
import com.google.gwt.dom.client.Element;
20
import com.google.gwt.event.dom.client.ClickEvent;
22
import com.google.gwt.event.dom.client.ClickEvent;
21
import com.google.gwt.event.dom.client.ClickHandler;
23
import com.google.gwt.event.dom.client.ClickHandler;
22
import com.google.gwt.user.client.Window;
24
import com.google.gwt.user.client.Window;
23

    
   
25

   
[+20] [20] 11 lines
[+20]
35
import org.waveprotocol.wave.client.wavepanel.view.dom.full.TypeCodes;
37
import org.waveprotocol.wave.client.wavepanel.view.dom.full.TypeCodes;
36
import org.waveprotocol.wave.client.widget.profile.ProfilePopupPresenter;
38
import org.waveprotocol.wave.client.widget.profile.ProfilePopupPresenter;
37
import org.waveprotocol.wave.client.widget.profile.ProfilePopupView;
39
import org.waveprotocol.wave.client.widget.profile.ProfilePopupView;
38
import org.waveprotocol.wave.model.conversation.Conversation;
40
import org.waveprotocol.wave.model.conversation.Conversation;
39
import org.waveprotocol.wave.model.util.Pair;
41
import org.waveprotocol.wave.model.util.Pair;

    
   
42
import org.waveprotocol.wave.model.util.Preconditions;
40
import org.waveprotocol.wave.model.wave.InvalidParticipantAddress;
43
import org.waveprotocol.wave.model.wave.InvalidParticipantAddress;
41
import org.waveprotocol.wave.model.wave.ParticipantId;
44
import org.waveprotocol.wave.model.wave.ParticipantId;
42

    
   
45

   
43
/**
46
/**
44
 * Installs the add/remove participant controls.
47
 * Installs the add/remove participant controls.
[+20] [20] 43 lines
[+20] [+] public boolean onClick(ClickEvent event, Element context) {
88
      }
91
      }
89
    });
92
    });
90
  }
93
  }
91

    
   
94

   
92
  /**
95
  /**
93
   * Shows an add-participant popup.
96
   * Constructs a list of {@link ParticipantId} with the supplied string with comma
94
   */
97
   * separated participant addresses. The method will only succeed if all addresses
95
  private void handleAddButtonClicked(Element context) {
98
   * is valid.
96
    ParticipantId p;
99
   *
97
    String address = Window.prompt("Add a participant: ", "");
100
   * @param localDomain if provided, automatic suffixing will occur.
98
    if (address == null) {
101
   * @param addresses string with comma separated participant addresses
99
      return;
102
   * @return the array of {@link ParticipantId} instances constructed using the given
100
    }
103
   *         addresses string
101
    address = address.trim();
104
   * @throws InvalidParticipantAddress if at least one of the addresses failed validation.

    
   
105
   */

    
   
106
  public static ParticipantId[] buildParticipantList(

    
   
107
      @Nullable String localDomain, String addresses) throws InvalidParticipantAddress {

    
   
108
    Preconditions.checkNotNull(addresses, "Expected non-null address");

    
   
109

   

    
   
110
    String[] addressList = addresses.split(",");

    
   
111
    ParticipantId[] participantList = new ParticipantId[addressList.length];

    
   
112

   

    
   
113
    for (int i = 0; i < addressList.length; i++) {

    
   
114
      String address = addressList[i].trim();

    
   
115

   
102
    if (localDomain != null) {
116
      if (localDomain != null) {
103
      if (!address.isEmpty() &&  address.indexOf("@") == -1) {
117
        if (!address.isEmpty() && address.indexOf("@") == -1) {
104
        // If no domain was specified, assume that the participant is from the local domain.
118
          // If no domain was specified, assume that the participant is from the local domain.
105
        address = address + "@" + localDomain;
119
          address = address + "@" + localDomain;
106
      } else if (address.equals("@")) {
120
        } else if (address.equals("@")) {
107
        // "@" is a shortcut for the shared domain participant.
121
          // "@" is a shortcut for the shared domain participant.
108
        address = address + localDomain;
122
          address = address + localDomain;
109
      }
123
        }
110
    }
124
      }
111

    
   
125

   

    
   
126
      // Will throw InvalidParticipantAddress if address is not valid

    
   
127
      participantList[i] = ParticipantId.of(address);

    
   
128
    }

    
   
129
    return participantList;

    
   
130
  }

    
   
131

   

    
   
132
  /**

    
   
133
   * Shows an add-participant popup.

    
   
134
   */

    
   
135
  private void handleAddButtonClicked(Element context) {

    
   
136
    String addressString = Window.prompt("Add a participant(s) (separate with comma ','): ", "");

    
   
137
    if (addressString == null) {

    
   
138
      return;

    
   
139
    }

    
   
140

   

    
   
141
    ParticipantId[] participantList;

    
   
142

   
112
    try {
143
    try {
113
      p = ParticipantId.of(address);
144
      participantList = buildParticipantList(localDomain, addressString);
114
    } catch (InvalidParticipantAddress e) {
145
    } catch (InvalidParticipantAddress e) {
115
      Window.alert("Invalid address: " + address);
146
      Window.alert(e.getMessage());
116
      return;
147
      return;
117
    }
148
    }
118

    
   
149

   
119
    ParticipantsView participantsUi = views.fromAddButton(context);
150
    ParticipantsView participantsUi = views.fromAddButton(context);
120
    Conversation conversation = models.getParticipants(participantsUi);
151
    Conversation conversation = models.getParticipants(participantsUi);
121
    conversation.addParticipant(p);
152
    for (int i = 0; i < participantList.length; i++) {

    
   
153
      conversation.addParticipant(participantList[i]);

    
   
154
    }
122
  }
155
  }
123

    
   
156

   
124
  /**
157
  /**
125
   * Shows a participation popup for the clicked participant.
158
   * Shows a participation popup for the clicked participant.
126
   */
159
   */
[+20] [20] 20 lines
test/org/waveprotocol/wave/client/wavepanel/impl/edit/ParticipantControllerTest.java
New File
 
  1. src/org/waveprotocol/wave/client/wavepanel/impl/edit/ParticipantController.java: Loading...
  2. test/org/waveprotocol/wave/client/wavepanel/impl/edit/ParticipantControllerTest.java: Loading...