Author: ndkhoiits
Date: 2010-10-26 10:34:32 -0400 (Tue, 26 Oct 2010)
New Revision: 4846
Modified:
portal/branches/branch-GTNPORTAL-1592/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java
portal/branches/branch-GTNPORTAL-1592/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java
Log:
GTNPORTAL-1577 Persist user selection state when adding users to group or change to other
page
Modified:
portal/branches/branch-GTNPORTAL-1592/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1592/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java 2010-10-26
12:06:39 UTC (rev 4845)
+++
portal/branches/branch-GTNPORTAL-1592/webui/core/src/main/java/org/exoplatform/webui/core/UIPageIterator.java 2010-10-26
14:34:32 UTC (rev 4846)
@@ -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:
portal/branches/branch-GTNPORTAL-1592/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1592/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java 2010-10-26
12:06:39 UTC (rev 4845)
+++
portal/branches/branch-GTNPORTAL-1592/webui/eXo/src/main/java/org/exoplatform/webui/organization/account/UIUserSelector.java 2010-10-26
14:34:32 UTC (rev 4846)
@@ -41,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;
/**
@@ -119,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);
@@ -138,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());
@@ -315,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());
}
@@ -379,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>
{
@@ -457,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);
Show replies by date