Author: ndkhoiits
Date: 2010-11-17 23:16:14 -0500 (Wed, 17 Nov 2010)
New Revision: 5146
Modified:
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java
Log:
EXOGTN-143 User selection is removed when adding users to group
Modified:
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java
===================================================================
---
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java 2010-11-18
03:55:40 UTC (rev 5145)
+++
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java 2010-11-18
04:16:14 UTC (rev 5146)
@@ -19,15 +19,17 @@
package org.exoplatform.webui.core;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.commons.utils.EmptySerializablePageList;
import org.exoplatform.commons.utils.PageList;
-import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.event.Event;
import org.exoplatform.webui.event.EventListener;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* A component that allows pagination, with an iterator to change pages
@@ -42,6 +44,8 @@
*/
private PageList pageList_ = EmptySerializablePageList.get();
+ private Set<String> selectedItems = new HashSet<String>();
+
public UIPageIterator()
{
}
@@ -95,6 +99,28 @@
{
pageList_.getPage(page);
}
+
+ public void setSelectedItem(String key, boolean value)
+ {
+ if (value == false && this.selectedItems.contains(key))
+ {
+ selectedItems.remove(key);
+ }
+ else if (value)
+ {
+ selectedItems.add(key);
+ }
+ }
+
+ public Set<String> getSelectedItems()
+ {
+ return selectedItems;
+ }
+
+ public boolean isSelectedItem(String key)
+ {
+ return selectedItems.contains(key);
+ }
@SuppressWarnings("unused")
static public class ShowPageActionListener extends
EventListener<UIPageIterator>
Modified:
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java
===================================================================
---
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java 2010-11-18
03:55:40 UTC (rev 5145)
+++
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java 2010-11-18
04:16:14 UTC (rev 5146)
@@ -19,8 +19,11 @@
package org.exoplatform.webui.organization.account;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.commons.utils.ListAccessImpl;
import org.exoplatform.commons.utils.ObjectPageList;
import org.exoplatform.commons.utils.PageList;
+import org.exoplatform.commons.utils.SerializablePageList;
import org.exoplatform.services.organization.MembershipHandler;
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.organization.Query;
@@ -38,18 +41,20 @@
import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
import org.exoplatform.webui.core.model.SelectItemOption;
import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.Event.Phase;
import org.exoplatform.webui.event.EventListener;
-import org.exoplatform.webui.event.Event.Phase;
import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormCheckBoxInput;
import org.exoplatform.webui.form.UIFormSelectBox;
import org.exoplatform.webui.form.UIFormStringInput;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
/**
@@ -70,6 +75,7 @@
@EventConfig(listeners = UIUserSelector.FindGroupActionListener.class, phase =
Phase.DECODE),
@EventConfig(listeners = UIUserSelector.ShowPageActionListener.class, phase =
Phase.DECODE),
@EventConfig(listeners = UIUserSelector.CloseActionListener.class, phase =
Phase.DECODE)})
+@Serialized
public class UIUserSelector extends UIForm implements UIPopupComponent
{
final public static String FIELD_KEYWORD = "Quick Search".intern();
@@ -115,7 +121,7 @@
uiIterator_ = new UIPageIterator();
uiIterator_.setPageList(objPageList);
uiIterator_.setId("UISelectUserPage");
-
+
// create group selector
UIPopupWindow uiPopup = addChild(UIPopupWindow.class, null,
"UIPopupGroupSelector");
uiPopup.setWindowSize(540, 0);
@@ -134,8 +140,14 @@
for (Object obj : uiIterator_.getCurrentPageData())
{
User user = (User)obj;
- if (getUIFormCheckBoxInput(user.getUserName()) == null)
- addUIFormInput(new UIFormCheckBoxInput<Boolean>(user.getUserName(),
user.getUserName(), false));
+ UIFormCheckBoxInput<Boolean> uiFormCheckBoxInput =
getUIFormCheckBoxInput(user.getUserName());
+ if (uiFormCheckBoxInput == null)
+ {
+ uiFormCheckBoxInput = new
UIFormCheckBoxInput<Boolean>(user.getUserName(), user.getUserName(), false);
+ addUIFormInput(uiFormCheckBoxInput);
+ }
+
+
uiFormCheckBoxInput.setChecked(uiIterator_.isSelectedItem(user.getUserName()));
}
}
return new ArrayList<User>(uiIterator_.getCurrentPageData());
@@ -290,7 +302,7 @@
}
}
}
- ObjectPageList objPageList = new ObjectPageList(results, 10);
+ PageList objPageList = new SerializablePageList(new ListAccessImpl(User.class,
results), 10);
uiIterator_.setPageList(objPageList);
}
@@ -311,31 +323,32 @@
static public class AddActionListener extends EventListener<UIUserSelector>
{
- @SuppressWarnings("unchecked")
public void execute(Event<UIUserSelector> event) throws Exception
{
UIUserSelector uiForm = event.getSource();
StringBuilder sb = new StringBuilder();
- int count = 0;
- for (Object o : uiForm.uiIterator_.getCurrentPageData())
+
+ uiForm.setSelectedItem();
+
+ // get item from selected item map
+ Set<String> items = uiForm.uiIterator_.getSelectedItems();
+ if (items.size() == 0)
{
- User u = (User)o;
- UIFormCheckBoxInput input = uiForm.getUIFormCheckBoxInput(u.getUserName());
- if (input != null && input.isChecked())
- {
- count++;
- if (sb.toString() != null && sb.toString().trim().length() != 0)
- sb.append(",");
- sb.append(u.getUserName());
- }
- }
- if (count == 0)
- {
UIApplication uiApp = uiForm.getAncestorOfType(UIApplication.class);
uiApp.addMessage(new
ApplicationMessage("UIUserSelector.msg.user-required", null));
event.getRequestContext().addUIComponentToUpdateByAjax(uiApp.getUIPopupMessages());
return;
}
+ String[] arrItems = items.toArray(new String[items.size()]);
+ Arrays.sort(arrItems);
+
+ for (String key : arrItems)
+ {
+ if (sb.toString() != null && sb.toString().trim().length() != 0)
+ sb.append(",");
+ sb.append(key);
+ }
+
uiForm.setSelectedUsers(sb.toString());
uiForm.<UIComponent> getParent().broadcast(event,
event.getExecutionPhase());
}
@@ -375,6 +388,19 @@
{
getUIStringInput(FIELD_KEYWORD).setValue(value);
}
+
+ private void setSelectedItem() throws Exception
+ {
+ for (Object o : this.uiIterator_.getCurrentPageData())
+ {
+ User u = (User) o;
+ UIFormCheckBoxInput input = this.getUIFormCheckBoxInput(u.getUserName());
+ if (input != null)
+ {
+ this.uiIterator_.setSelectedItem(u.getUserName(), input.isChecked());
+ }
+ }
+ }
static public class SelectGroupActionListener extends
EventListener<UIGroupSelector>
{
@@ -386,9 +412,7 @@
uiSelectUserForm.setSelectedGroup(groupId);
OrganizationService service =
uiSelectGroupForm.getApplicationComponent(OrganizationService.class);
PageList users =
uiSelectUserForm.removeDuplicate(service.getUserHandler().findUsersByGroup(groupId));
- users.setPageSize(10);
uiSelectUserForm.uiIterator_.setPageList(users);
- uiSelectUserForm.setKeyword(null);
event.getRequestContext().addUIComponentToUpdateByAjax(uiSelectUserForm);
}
}
@@ -399,23 +423,17 @@
{
UIUserSelector uiSelectUserForm = event.getSource();
String groupId = uiSelectUserForm.getSelectedGroup();
+ uiSelectUserForm.setSelectedGroup(groupId);
OrganizationService service =
uiSelectUserForm.getApplicationComponent(OrganizationService.class);
-
- PageList users = PageList.EMPTY_LIST;
if (groupId != null && groupId.trim().length() != 0)
{
- if (service.getGroupHandler().findGroupById(groupId) != null)
- {
- users =
uiSelectUserForm.removeDuplicate(service.getUserHandler().findUsersByGroup(groupId));
- }
+ PageList users =
uiSelectUserForm.removeDuplicate(service.getUserHandler().findUsersByGroup(groupId));
+ uiSelectUserForm.uiIterator_.setPageList(users);
}
else
{
- users = service.getUserHandler().findUsers(new Query());
+
uiSelectUserForm.uiIterator_.setPageList(service.getUserHandler().findUsers(new
Query()));
}
- users.setPageSize(10);
- uiSelectUserForm.uiIterator_.setPageList(users);
- uiSelectUserForm.setKeyword(null);
event.getRequestContext().addUIComponentToUpdateByAjax(uiSelectUserForm);
}
}
@@ -461,6 +479,8 @@
public void execute(Event<UIUserSelector> event) throws Exception
{
UIUserSelector uiSelectUserForm = event.getSource();
+ uiSelectUserForm.setSelectedItem();
+
int page =
Integer.parseInt(event.getRequestContext().getRequestParameter(OBJECTID));
uiSelectUserForm.updateCurrentPage(page);
event.getRequestContext().addUIComponentToUpdateByAjax(uiSelectUserForm);