1 31 32 package org.opencms.workplace.tools.accounts; 33 34 import org.opencms.file.CmsGroup; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsException; 37 import org.opencms.main.CmsRuntimeException; 38 import org.opencms.workplace.list.A_CmsListDialog; 39 import org.opencms.workplace.list.CmsHtmlList; 40 import org.opencms.workplace.list.CmsListColumnAlignEnum; 41 import org.opencms.workplace.list.CmsListColumnDefinition; 42 import org.opencms.workplace.list.CmsListDirectAction; 43 import org.opencms.workplace.list.CmsListItem; 44 import org.opencms.workplace.list.CmsListItemActionIconComparator; 45 import org.opencms.workplace.list.CmsListMetadata; 46 import org.opencms.workplace.list.CmsListMultiAction; 47 import org.opencms.workplace.list.I_CmsListDirectAction; 48 49 import java.util.HashSet ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Set ; 53 54 import javax.servlet.http.HttpServletRequest ; 55 import javax.servlet.http.HttpServletResponse ; 56 import javax.servlet.jsp.PageContext ; 57 58 67 public class CmsUserGroupsList extends A_CmsUserGroupsList { 68 69 70 public static final String LIST_ACTION_REMOVE = "ar"; 71 72 73 public static final String LIST_DEFACTION_REMOVE = "dr"; 74 75 76 public static final String LIST_ID = "lug"; 77 78 79 public static final String LIST_MACTION_REMOVE = "mr"; 80 81 82 protected static Set m_removeActionIds = new HashSet (); 83 84 89 public CmsUserGroupsList(CmsJspActionElement jsp) { 90 91 this(jsp, LIST_ID); 92 } 93 94 101 public CmsUserGroupsList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 102 103 this(new CmsJspActionElement(context, req, res)); 104 } 105 106 112 protected CmsUserGroupsList(CmsJspActionElement jsp, String listId) { 113 114 super(jsp, listId, Messages.get().container(Messages.GUI_USERGROUPS_LIST_NAME_0), true); 115 } 116 117 120 public void executeListMultiActions() throws CmsRuntimeException { 121 122 if (getParamListAction().equals(LIST_MACTION_REMOVE)) { 123 Iterator itItems = getSelectedItems().iterator(); 125 while (itItems.hasNext()) { 126 CmsListItem listItem = (CmsListItem)itItems.next(); 127 String groupName = (String )listItem.get(LIST_COLUMN_NAME); 128 boolean directGroup = false; 129 try { 130 Iterator it = getCms().getDirectGroupsOfUser(getParamUsername()).iterator(); 131 while (it.hasNext()) { 132 CmsGroup group = (CmsGroup)it.next(); 133 if (group.getName().equals(groupName)) { 134 directGroup = true; 135 break; 136 } 137 } 138 if (directGroup) { 139 getCms().removeUserFromGroup(getParamUsername(), groupName); 140 } 141 } catch (CmsException e) { 142 } 144 } 145 } else { 146 throwListUnsupportedActionException(); 147 } 148 listSave(); 149 } 150 151 154 public void executeListSingleActions() throws CmsRuntimeException { 155 156 if (m_removeActionIds.contains(getParamListAction())) { 157 CmsListItem listItem = getSelectedItem(); 158 try { 159 getCms().removeUserFromGroup(getParamUsername(), (String )listItem.get(LIST_COLUMN_NAME)); 160 } catch (CmsException e) { 161 throw new CmsRuntimeException(Messages.get().container(Messages.ERR_REMOVE_SELECTED_GROUP_0), e); 163 } 164 } else { 165 throwListUnsupportedActionException(); 166 } 167 listSave(); 168 } 169 170 173 public CmsHtmlList getList() { 174 175 CmsHtmlList list = super.getList(); 177 if (list != null) { 178 CmsListColumnDefinition col = list.getMetadata().getColumnDefinition(LIST_COLUMN_STATE); 179 if (col != null) { 180 Iterator itDirectActions = col.getDirectActions().iterator(); 181 while (itDirectActions.hasNext()) { 182 I_CmsListDirectAction action = (I_CmsListDirectAction)itDirectActions.next(); 183 if (action != null && action instanceof CmsGroupRemoveAction) { 184 ((CmsGroupRemoveAction)action).setUserName(getParamUsername()); 185 } 186 } 187 } 188 CmsListColumnDefinition col2 = list.getMetadata().getColumnDefinition(LIST_COLUMN_NAME); 189 if (col2 != null) { 190 Iterator itDefaultActions = col2.getDefaultActions().iterator(); 191 while (itDefaultActions.hasNext()) { 192 I_CmsListDirectAction action = (I_CmsListDirectAction)itDefaultActions.next(); 193 if (action != null && action instanceof CmsGroupRemoveAction) { 194 ((CmsGroupRemoveAction)action).setUserName(getParamUsername()); 195 } 196 } 197 } 198 } 199 return list; 200 } 201 202 205 protected List getGroups() throws CmsException { 206 207 return getCms().getGroupsOfUser(getParamUsername()); 208 } 209 210 213 protected void setDefaultAction(CmsListColumnDefinition nameCol) { 214 215 CmsGroupRemoveAction removeAction = new CmsGroupRemoveAction(LIST_DEFACTION_REMOVE, getCms(), true); 217 removeAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_NAME_0)); 218 removeAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_HELP_0)); 219 nameCol.addDefaultAction(removeAction); 220 221 CmsGroupRemoveAction indirRemoveAction = new CmsGroupRemoveAction(LIST_DEFACTION_REMOVE + "i", getCms(), false); 223 indirRemoveAction.setName(Messages.get().container(Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_NAME_0)); 224 indirRemoveAction.setHelpText(Messages.get().container( 225 Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_HELP_0)); 226 indirRemoveAction.setEnabled(false); 227 nameCol.addDefaultAction(indirRemoveAction); 228 229 m_removeActionIds.add(removeAction.getId()); 231 m_removeActionIds.add(indirRemoveAction.getId()); 232 } 233 234 237 protected void setIconAction(CmsListColumnDefinition iconCol) { 238 239 CmsListDirectAction dirAction = new CmsGroupStateAction(LIST_ACTION_ICON_DIRECT, getCms(), true); 241 dirAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DIRECT_NAME_0)); 242 dirAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DIRECT_HELP_0)); 243 dirAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "group.png"); 244 dirAction.setEnabled(false); 245 iconCol.addDirectAction(dirAction); 246 247 CmsListDirectAction indirAction = new CmsGroupStateAction(LIST_ACTION_ICON_INDIRECT, getCms(), false); 249 indirAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_INDIRECT_NAME_0)); 250 indirAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_INDIRECT_HELP_0)); 251 indirAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "group_indirect.png"); 252 indirAction.setEnabled(false); 253 iconCol.addDirectAction(indirAction); 254 255 iconCol.setListItemComparator(new CmsListItemActionIconComparator()); 256 } 257 258 261 protected void setMultiActions(CmsListMetadata metadata) { 262 263 CmsListMultiAction removeMultiAction = new CmsListMultiAction(LIST_MACTION_REMOVE); 265 removeMultiAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_MACTION_REMOVE_NAME_0)); 266 removeMultiAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_MACTION_REMOVE_HELP_0)); 267 removeMultiAction.setConfirmationMessage(Messages.get().container( 268 Messages.GUI_GROUPS_LIST_MACTION_REMOVE_CONF_0)); 269 removeMultiAction.setIconPath(ICON_MULTI_MINUS); 270 metadata.addMultiAction(removeMultiAction); 271 } 272 273 276 protected void setStateActionCol(CmsListMetadata metadata) { 277 278 CmsListColumnDefinition stateCol = new CmsListColumnDefinition(LIST_COLUMN_STATE); 280 stateCol.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_STATE_0)); 281 stateCol.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_STATE_HELP_0)); 282 stateCol.setWidth("20"); 283 stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 284 stateCol.setSorteable(false); 285 metadata.addColumn(stateCol); 287 288 CmsGroupRemoveAction dirStateAction = new CmsGroupRemoveAction(LIST_ACTION_REMOVE, getCms(), true); 290 dirStateAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_NAME_0)); 291 dirStateAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_HELP_0)); 292 dirStateAction.setIconPath(ICON_MINUS); 293 stateCol.addDirectAction(dirStateAction); 294 295 CmsGroupRemoveAction indirStateAction = new CmsGroupRemoveAction(LIST_ACTION_REMOVE + "i", getCms(), false); 297 indirStateAction.setName(Messages.get().container(Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_NAME_0)); 298 indirStateAction.setHelpText(Messages.get().container(Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_HELP_0)); 299 indirStateAction.setIconPath(A_CmsListDialog.ICON_DISABLED); 300 indirStateAction.setEnabled(false); 301 stateCol.addDirectAction(indirStateAction); 302 303 stateCol.setListItemComparator(new CmsListItemActionIconComparator()); 304 305 metadata.addColumn(stateCol); 307 m_removeActionIds.add(dirStateAction.getId()); 309 m_removeActionIds.add(indirStateAction.getId()); 310 } 311 } 312 | Popular Tags |