Author: fdesbois Date: 2010-05-19 15:25:45 +0200 (Wed, 19 May 2010) New Revision: 3002 Url: http://chorem.org/repositories/revision/pollen/3002 Log: - Move models in a new package 'models'. - Add poll instantiation in PollFormModel - Add javadoc Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java Removed: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/UserListsUpdate.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -1,4 +1,3 @@ - package org.chorem.pollen.ui.components; import org.apache.tapestry5.annotations.InjectComponent; @@ -15,7 +14,7 @@ import org.chorem.pollen.entity.FavoriteParticipant; import org.chorem.pollen.service.ServiceFavorite; import org.chorem.pollen.ui.data.EvenOdd; -import org.chorem.pollen.ui.data.FavoriteParticipantDataSource; +import org.chorem.pollen.ui.models.FavoriteParticipantDataSource; import org.chorem.pollen.ui.services.PollenManager; import org.nuiton.web.tapestry5.components.FeedBack; import org.slf4j.Logger; @@ -27,7 +26,7 @@ * participant in the Grid and one to edit a participant directly in the grid. * Each action will return the {@code updateZone} to refresh data loaded by * {@link #getParticipants()} method. - * + * <p/> * Created: 27 avr. 2010 * * @author fdesbois <fdesbois@codelutin.com> @@ -35,11 +34,11 @@ */ public class UserListsUpdate { - /** Parameters of the component **/ + /** Parameters of the component * */ @Parameter(required = true) private FavoriteList source; - /** Services injected **/ + /** Services injected * */ @Inject private Logger logger; @@ -52,7 +51,7 @@ @Inject private Messages messages; - /** Main properties for Grid **/ + /** Main properties for Grid * */ private EvenOdd evenOdd; private FavoriteParticipantDataSource participants; @@ -75,11 +74,11 @@ } /** - * Load participants data from serviceFavorite in a - * {@link FavoriteParticipantDataSource} to manage pagination and order. - * The filter added contains data for serviceFavorite (startIndex, endIndex, - * orderBy and referenceId). The reference is set to the source FavoriteList - * of the component, i.e. all FavoriteParticipants need to be part of the + * Load participants data from serviceFavorite in a {@link + * FavoriteParticipantDataSource} to manage pagination and order. The filter + * added contains data for serviceFavorite (startIndex, endIndex, orderBy + * and referenceId). The reference is set to the source FavoriteList of the + * component, i.e. all FavoriteParticipants need to be part of the * FavoriteList source. * * @return the DataSource that contains participants. @@ -100,20 +99,13 @@ /***************************** EDIT PARTICIPANT FORM **********************/ /** - * FORM EVENTS ORDER -> RENDER : - * load size of participants dataSource - * call prepareForRender - * load participants data - * - * FORM EVENTS ORDER -> SUBMIT : - * call prepareForSubmit - * load size of participants dataSource - * load participants data - * load participantEdited to push form data (hidden fields in first) - * call selected on submit button - * call validateForm - * call success or failure - * call submit + * FORM EVENTS ORDER -> RENDER : load size of participants dataSource call + * prepareForRender load participants data + * <p/> + * FORM EVENTS ORDER -> SUBMIT : call prepareForSubmit load size of + * participants dataSource load participants data load participantEdited to + * push form data (hidden fields in first) call selected on submit button + * call validateForm call success or failure call submit */ @InjectComponent @@ -131,7 +123,7 @@ * Test if the edited participant is the current one in the Grid. * * @return true if the participantEdited is defined and correspond to the - * current participant in the Grid + * current participant in the Grid */ public boolean isEditionMode() { // The current participant in the loop is equals to the edited one @@ -140,8 +132,8 @@ } /** - * ON_ACTION :: Handler method for action on editParticipant actionLink. - * The participantEdited will be set to the participant selected in the Grid + * ON_ACTION :: Handler method for action on editParticipant actionLink. The + * participantEdited will be set to the participant selected in the Grid * with {@code id}. * * @param id key of the participant from the Grid @@ -181,15 +173,13 @@ } /** - * Getter to retrieve participantEdited. - * <br \> - * The participantEditedId is needed and was provided for render by the - * {@link #onActionFromEditParticipant(String)} method and for submit by - * the hidden field in the form that keep the id after rendering the form. - * The participantEdited is loaded from the participants dataSource that - * contains all FavoriteParticipant displayed in the Grid. The submit will - * reload the participants dataSource before saving modification on the - * FavoriteParticipant edited. + * Getter to retrieve participantEdited. <br \> The participantEditedId is + * needed and was provided for render by the {@link #onActionFromEditParticipant(String)} + * method and for submit by the hidden field in the form that keep the id + * after rendering the form. The participantEdited is loaded from the + * participants dataSource that contains all FavoriteParticipant displayed + * in the Grid. The submit will reload the participants dataSource before + * saving modification on the FavoriteParticipant edited. * * @return the FavoriteParticipant in edition */ @@ -202,7 +192,7 @@ participantEdited = participants.get(participantEditedId); } return participantEdited; - } + } /** * ON_VALIDATE_FORM :: Handler method for validateForm event of the @@ -227,9 +217,9 @@ /** * ON_SUCCESS :: Handler method for success event of the participantsForm. - * Clean form data (participantEdited) and display a success message. - * {@link #onSubmitFromParticipantsForm()} will be called after it to - * refresh the updateZone. + * Clean form data (participantEdited) and display a success message. {@link + * #onSubmitFromParticipantsForm()} will be called after it to refresh the + * updateZone. */ void onSuccessFromParticipantsForm() { participantsFeedback.addInfo( @@ -239,8 +229,8 @@ } /** - * Clean the form content, i.e. the favorite participant in edition and - * its id. + * Clean the form content, i.e. the favorite participant in edition and its + * id. */ protected void cleanFormData() { participantEditedId = null; @@ -258,7 +248,7 @@ return updateZone; } - /***************************** NEW PARTICIPANT FORM ***********************/ + /** ************************** NEW PARTICIPANT FORM ********************** */ @Property private FavoriteParticipant newParticipant; @@ -276,7 +266,7 @@ void onPrepareFromAddParticipant() { if (newParticipant == null) { newParticipant = - serviceFavorite.getNewFavoriteParticipant(source); + serviceFavorite.getNewFavoriteParticipant(source); } } @@ -301,14 +291,14 @@ } /** - * ON_SUCCESS :: Handler method for success event of the addParticipant form. - * Will display a success message. {@link #onSubmitFromAddParticipant()} + * ON_SUCCESS :: Handler method for success event of the addParticipant + * form. Will display a success message. {@link #onSubmitFromAddParticipant()} * will be called after it to refresh the updateZone. */ void onSuccessFromAddParticipant() { participantsFeedback.addInfo( messages.format("pollen.ui.list.update.addParticipant.success", - newParticipant.getName())); + newParticipant.getName())); } /** Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/FavoriteParticipantDataSource.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -1,68 +0,0 @@ - -package org.chorem.pollen.ui.data; - -import java.util.Map; -import org.apache.tapestry5.grid.SortConstraint; -import org.chorem.pollen.PollenException; -import org.chorem.pollen.bean.Filter; -import org.chorem.pollen.entity.FavoriteParticipant; -import org.chorem.pollen.service.ServiceFavorite; -import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * UserAccountDataSource - * - * Created: 23 avr. 2010 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class FavoriteParticipantDataSource extends - AbstractMappedGridDataSource<String, FavoriteParticipant> { - - private static final Logger logger = - LoggerFactory.getLogger(FavoriteParticipantDataSource.class); - - private ServiceFavorite service; - - private Filter filter; - - public FavoriteParticipantDataSource(ServiceFavorite service, - Filter filter) { - this.service = service; - this.filter = filter; - } - - @Override - protected Map<String, FavoriteParticipant> execute( - int startIndex, int endIndex, SortConstraint orderBy) - throws PollenException { - filter.setStartIndex(startIndex); - filter.setEndIndex(endIndex); - filter.setOrderBy(resolveOrderBy(orderBy)); - if (logger.isDebugEnabled()) { - logger.debug("LOAD DATA"); - } - return service.getFavoriteParticipants(filter); - } - - @Override - protected int count() throws PollenException { - int count = service.getNbFavoriteParticipants(filter); - if (logger.isDebugEnabled()) { - logger.debug("Nb elements : " + count); - } - return count; - } - - @Override - public Class<?> getRowType() { - return FavoriteParticipant.class; - } - -} Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/GenericSelectModel.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -1,129 +0,0 @@ -/* *##% Pollen - * Copyright (C) 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/ - -package org.chorem.pollen.ui.data; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tapestry5.OptionGroupModel; -import org.apache.tapestry5.OptionModel; -import org.apache.tapestry5.ValueEncoder; -import org.apache.tapestry5.corelib.components.Select; -import org.apache.tapestry5.internal.OptionModelImpl; -import org.apache.tapestry5.ioc.services.PropertyAccess; -import org.apache.tapestry5.ioc.services.PropertyAdapter; -import org.apache.tapestry5.util.AbstractSelectModel; - -/** - * Generic selection model for a list of Objects. Adadpted from - * http://wiki.apache.org/tapestry/Tapestry5HowtoSelectWithObjects - * - * use: - * - * <pre> - * @Inject - * private PropertyAccess _access; - * </pre> - * - * in your page to ge the {@link PropertyAccess} service.<br> - * !Notice: you must set the created instance both as model and encoder - * parameter for the {@link Select} component. - * @param <T> - */ -public class GenericSelectModel<T> extends AbstractSelectModel implements - ValueEncoder<T> { - - private PropertyAdapter labelFieldAdapter; - private PropertyAdapter idFieldAdapter; - private List<T> list; - - public GenericSelectModel(List<T> list, Class<T> clazz, String labelField, - String idField, PropertyAccess access) { - this.list = list; - if (idField != null) { - this.idFieldAdapter = - access.getAdapter(clazz).getPropertyAdapter(idField); - } - if (labelField != null) { - this.labelFieldAdapter = - access.getAdapter(clazz).getPropertyAdapter(labelField); - } - } - - @Override - public List<OptionGroupModel> getOptionGroups() { - return null; - } - - @Override - public List<OptionModel> getOptions() { - List<OptionModel> optionModelList = new ArrayList<OptionModel>(); - if (labelFieldAdapter == null) { - for (T obj : list) { - optionModelList.add(new OptionModelImpl(nvl(obj), obj)); - } - } else { - for (T obj : list) { - optionModelList.add(new OptionModelImpl(nvl(labelFieldAdapter - .get(obj)), obj)); - } - } - return optionModelList; - } - - public List<T> getList() { - return list; - } - - // ValueEncoder methods - - @Override - public String toClient(T obj) { - if (idFieldAdapter == null) { - return obj + ""; - } else { - return idFieldAdapter.get(obj) + ""; - } - } - - @Override - public T toValue(String string) { - if (idFieldAdapter == null) { - for (T obj : list) { - if (nvl(obj).equals(string)) { - return obj; - } - } - } else { - for (T obj : list) { - if (nvl(idFieldAdapter.get(obj)).equals(string)) { - return obj; - } - } - } - return null; - } - - private String nvl(Object o) { - if (o == null) { - return ""; - } - else { - return o.toString(); - } - } -} Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ParticipantListModel.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -1,160 +0,0 @@ -package org.chorem.pollen.ui.data; - -import org.apache.tapestry5.ValueEncoder; -import org.chorem.pollen.PollenBusinessException; -import org.chorem.pollen.entity.Participant; -import org.chorem.pollen.entity.ParticipantList; -import org.chorem.pollen.service.ServicePoll; -import org.chorem.pollen.ui.services.PollenManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Created: 18 mai 2010 - * - * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ - */ -public class ParticipantListModel implements ValueEncoder<Participant> { - - private static final Logger logger = - LoggerFactory.getLogger(ParticipantListModel.class); - - protected ServicePoll service; - - protected PollenManager manager; - - protected ParticipantList list; - - protected ParticipantMap participants; - - public ParticipantListModel(ServicePoll service, PollenManager manager) { - this.service = service; - this.manager = manager; - participants = new ParticipantMap(); - } - - public Participant addNewParticipant() { - Participant newParticipant = service.getNewPollParticipant(); - String id = manager.createPollenId(); - participants.put(id, newParticipant); - return newParticipant; - } - - public void removeParticipant(Participant participant) { - if (logger.isDebugEnabled()) { - logger.debug("Remove participant : " + participant); - } - participants.remove(participant); - } - - public Collection<Participant> getParticipants() { - return participants.values(); - } - - public void setList(ParticipantList participantList) { - if (logger.isDebugEnabled()) { - logger.debug("Set current list : " + participantList.getName()); - } - list = participantList; - participants.clear(); - for (Participant participant : participantList.getParticipants()) { - String id = participant.getId() != null ? participant.getId() : - manager.createPollenId(); - if (logger.isTraceEnabled()) { - logger.trace("Push participant : " + - participant.getName() + - " (" + participant.getEmail() + ")" + - " ID = " + id); - } - participants.put(id, participant); - } - } - - public ParticipantList getList() { - return list; - } - - public void reset() { - if (logger.isDebugEnabled()) { - logger.debug("Reset current list"); - } - list = null; - participants.clear(); - } - - public void persistParticipants() throws PollenBusinessException { - if (logger.isDebugEnabled()) { - logger.debug("Save current list : " + list.getName()); - } - list.setParticipants(getParticipants()); - } - - @Override - public String toClient(Participant value) { - String key = participants.getKey(value); - if (logger.isTraceEnabled()) { - logger.trace("toClient key = " + key); - } - return key; - } - - @Override - public Participant toValue(String key) { - Participant value = participants.getValue(key); - if (logger.isTraceEnabled()) { - logger.trace("toValue from : " + key + " = " + value.getName() + - " (" + value.getEmail() + ")"); - } - return value; - } - - /** - * Participant map is a BidiMap ordered on values inserted using a {@link - * LinkedHashMap}. - */ - protected class ParticipantMap { - - protected Map<String, Participant> participants; - - protected Map<Participant, String> keys; - - public ParticipantMap() { - participants = new LinkedHashMap<String, Participant>(); - keys = new HashMap<Participant, String>(); - } - - public void put(String id, Participant participant) { - participants.put(id, participant); - keys.put(participant, id); - } - - public String getKey(Participant participant) { - return keys.get(participant); - } - - public Participant getValue(String id) { - return participants.get(id); - } - - public void clear() { - keys.clear(); - participants.clear(); - } - - public void remove(Participant participant) { - String id = keys.remove(participant); - participants.remove(id); - } - - public Collection<Participant> values() { - return participants.values(); - } - - } -} Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollFormModel.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -1,241 +0,0 @@ -package org.chorem.pollen.ui.data; - -import org.apache.commons.lang.StringUtils; -import org.apache.tapestry5.ValueEncoder; -import org.chorem.pollen.PollenBusinessException; -import org.chorem.pollen.common.PollType; -import org.chorem.pollen.entity.ParticipantList; -import org.chorem.pollen.entity.Poll; -import org.chorem.pollen.service.ServicePoll; -import org.chorem.pollen.ui.pages.poll.PollForm; -import org.chorem.pollen.ui.services.PollenManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Model for PollForm page. Contains the current {@code poll} and its - * participant {@code lists}. Use {@link ParticipantListModel} to manage current - * edited list for restricted or group Poll. Implement a {@link ValueEncoder} to - * manage ParticipantList client conversion in PollForm page. - * <p/> - * Created: 18 mai 2010 - * - * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ - * @see PollForm - * @see ValueEncoder - */ -public class PollFormModel implements ValueEncoder<ParticipantList> { - - private static final Logger logger = - LoggerFactory.getLogger(PollFormModel.class); - - /** Default listName for Restricted Poll */ - private static final String DEFAULT_LIST_NAME = "LIST"; - - /** Service to manage poll */ - protected ServicePoll service; - - /** Current poll in edition */ - protected Poll poll; - - /** Current lists in edition */ - protected Map<String, ParticipantList> lists; - - /** Current listModel that contains current edited list and its participants */ - protected ParticipantListModel listModel; - - /** - * Constructor of PollFormModel. Initialize with edited {@code poll}. Need - * services {@code servicePoll} and {@code manager} to manage the {@code - * poll}. - * - * @param poll Current poll in edition - * @param servicePoll ServicePoll to manage poll - * @param manager PollenManager to manage ids - */ - public PollFormModel(Poll poll, - ServicePoll servicePoll, - PollenManager manager) { - this.poll = poll; - this.service = servicePoll; - lists = new LinkedHashMap<String, ParticipantList>(); - this.listModel = new ParticipantListModel(service, manager); - } - - /** - * Change the poll type to {@code type}. The lists managment will depends on - * poll type. For a {@link PollType#RESTRICTED} poll, a new list will be - * automatically added and set for current usage. For a {@link - * PollType#GROUP} poll, the listModel is simply reset. - * - * @param type PollType to change - */ - public void setPollType(PollType type) { - lists.clear(); - if (type.isRestricted()) { - addNewList(DEFAULT_LIST_NAME); - // Set automatically the current list to the unique one - listModel.setList(lists.get(DEFAULT_LIST_NAME)); - } else if (type.isGroup()) { - listModel.reset(); - } - poll.setPollType(type); - } - - /** - * Retrieve a collection of {@link ParticipantList} of current lists. - * - * @return a Collection<ParticipantList> - */ - public Collection<ParticipantList> getLists() { - return lists.values(); - } - - /** - * Add a new list to the poll using the {@code listName}. The list will not - * be added if the {@code listName} is empty or if a list with this {@code - * listName} already exists. - * - * @param listName for the new list to add - * @return true if the list has been added, false otherwise - * @see #addList(ParticipantList) - */ - public boolean addNewList(String listName) { - boolean result = false; - if (StringUtils.isNotEmpty(listName)) { - ParticipantList newList = service.getNewPollList(); - newList.setName(listName); - return addList(newList); - } - return result; - } - - /** - * Add a {@code list} to the poll. The {@code list} will not be added if its - * name already reference an exising list. - * - * @param list ParticipantList to add - * @return true if the list has been added, false otherwise - */ - public boolean addList(ParticipantList list) { - boolean result = false; - if (list != null) { - String listName = list.getName(); - if (!lists.containsKey(listName)) { - if (logger.isDebugEnabled()) { - logger.debug("Add list : " + listName); - } - lists.put(listName, list); - result = true; - } else if (logger.isDebugEnabled()) { - logger.debug("Refuse adding list : " + listName); - } - } - return result; - } - - /** - * Give the current {@link ParticipantListModel} that references the list - * currently edited. - * - * @return the current listModel - */ - public ParticipantListModel getListModel() { - return listModel; - } - - /** - * Set the current list using its {@code listName}. The previous current - * list will be automatically saved. If error occurs during save, the - * previous list will be refresh (no list change will be done). - * - * @param listName name of the list to set (empty name will be ignored) - * @throws PollenBusinessException for saving error (doubloons) - * @see #saveCurrentList() - */ - public void setCurrentList(String listName) throws PollenBusinessException { - if (StringUtils.isNotEmpty(listName)) { - ParticipantList list = getCurrentList(); - try { - // Save previous list if not null - if (list != null) { - saveCurrentList(); - } - // Change list - list = lists.get(listName); - } finally { - // Previous list will be keeped if error occurs during save. - // Apply change in listModel - listModel.setList(list); - } - } - } - - /** - * Get the current list. - * - * @return the current list in edition. - */ - public ParticipantList getCurrentList() { - return listModel.getList(); - } - - /** Remove the current list. */ - public void removeCurrentList() { - if (logger.isDebugEnabled()) { - logger.debug("Remove list : " + listModel.getList().getName()); - } - - getLists().remove(listModel.getList()); - listModel.reset(); - } - - /** - * Save the current participants from current list. - * - * @throws PollenBusinessException for saving errors (doubloons) - * @see ParticipantListModel#persistParticipants() - */ - public void saveCurrentList() throws PollenBusinessException { - listModel.persistParticipants(); - } - - public void create() throws PollenBusinessException { - service.createPoll(poll, getLists()); - } - - /** - * ValueEncoder toClient is used to convert {@code value} to the list name. - * - * @param value ParticipantList to convert toClient - * @return the list name as a unique key for the list - * @see ValueEncoder#toClient(Object) - */ - @Override - public String toClient(ParticipantList value) { - return value.getName(); - } - - /** - * ValueEncoder toClient is used to convert {@code clientValue} key to the - * list object. - * - * @param clientValue List name of the ParticipantList to retrieve. - * @return the ParticipantList corresponding to its name in argument - * @see ValueEncoder#toValue(String) - */ - @Override - public ParticipantList toValue(String clientValue) { - for (ParticipantList curr : lists.values()) { - if (clientValue.equals(curr.getName())) { - return curr; - } - } - return null; - } -} Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/UserAccountDataSource.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -1,53 +0,0 @@ - -package org.chorem.pollen.ui.data; - -import java.util.Map; -import org.apache.tapestry5.grid.SortConstraint; -import org.chorem.pollen.PollenException; -import org.chorem.pollen.bean.Filter; -import org.chorem.pollen.entity.UserAccount; -import org.chorem.pollen.service.ServiceUser; -import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource; - -/** - * UserAccountDataSource - * - * Created: 23 avr. 2010 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class UserAccountDataSource extends AbstractMappedGridDataSource<String, UserAccount> { - - private ServiceUser service; - - private Filter filter; - - public UserAccountDataSource(ServiceUser service, Filter filter) { - this.service = service; - this.filter = filter; - } - - @Override - protected Map<String, UserAccount> execute(int startIndex, int endIndex, - SortConstraint orderBy) throws PollenException { - filter.setStartIndex(startIndex); - filter.setEndIndex(endIndex); - filter.setOrderBy(resolveOrderBy(orderBy)); - return service.getUsers(filter); - } - - @Override - protected int count() throws PollenException { - return service.getNbUsers(filter); - } - - @Override - public Class<?> getRowType() { - return UserAccount.class; - } - -} Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -0,0 +1,68 @@ +package org.chorem.pollen.ui.models; + +import org.apache.tapestry5.grid.SortConstraint; +import org.chorem.pollen.PollenException; +import org.chorem.pollen.bean.Filter; +import org.chorem.pollen.entity.FavoriteParticipant; +import org.chorem.pollen.service.ServiceFavorite; +import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + * UserAccountDataSource + * <p/> + * Created: 23 avr. 2010 + * + * @author fdesbois + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ + * par : $Author$ + */ +public class FavoriteParticipantDataSource extends + AbstractMappedGridDataSource<String, FavoriteParticipant> { + + private static final Logger logger = + LoggerFactory.getLogger(FavoriteParticipantDataSource.class); + + private ServiceFavorite service; + + private Filter filter; + + public FavoriteParticipantDataSource(ServiceFavorite service, + Filter filter) { + this.service = service; + this.filter = filter; + } + + @Override + protected Map<String, FavoriteParticipant> execute( + int startIndex, int endIndex, SortConstraint orderBy) + throws PollenException { + filter.setStartIndex(startIndex); + filter.setEndIndex(endIndex); + filter.setOrderBy(resolveOrderBy(orderBy)); + if (logger.isDebugEnabled()) { + logger.debug("LOAD DATA"); + } + return service.getFavoriteParticipants(filter); + } + + @Override + protected int count() throws PollenException { + int count = service.getNbFavoriteParticipants(filter); + if (logger.isDebugEnabled()) { + logger.debug("Nb elements : " + count); + } + return count; + } + + @Override + public Class<?> getRowType() { + return FavoriteParticipant.class; + } + +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/FavoriteParticipantDataSource.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -0,0 +1,131 @@ +/* *##% Pollen + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/ + +package org.chorem.pollen.ui.models; + +import org.apache.tapestry5.OptionGroupModel; +import org.apache.tapestry5.OptionModel; +import org.apache.tapestry5.ValueEncoder; +import org.apache.tapestry5.corelib.components.Select; +import org.apache.tapestry5.internal.OptionModelImpl; +import org.apache.tapestry5.ioc.services.PropertyAccess; +import org.apache.tapestry5.ioc.services.PropertyAdapter; +import org.apache.tapestry5.util.AbstractSelectModel; + +import java.util.ArrayList; +import java.util.List; + +/** + * Generic selection model for a list of Objects. Adadpted from + * http://wiki.apache.org/tapestry/Tapestry5HowtoSelectWithObjects + * <p/> + * use: + * <p/> + * <pre> + * @Inject + * private PropertyAccess _access; + * </pre> + * <p/> + * in your page to ge the {@link PropertyAccess} service.<br> !Notice: you must + * set the created instance both as model and encoder parameter for the {@link + * Select} component. + * + * @param <T> + */ +public class GenericSelectModel<T> extends AbstractSelectModel implements + ValueEncoder<T> { + + private PropertyAdapter labelFieldAdapter; + + private PropertyAdapter idFieldAdapter; + + private List<T> list; + + public GenericSelectModel(List<T> list, Class<T> clazz, String labelField, + String idField, PropertyAccess access) { + this.list = list; + if (idField != null) { + this.idFieldAdapter = + access.getAdapter(clazz).getPropertyAdapter(idField); + } + if (labelField != null) { + this.labelFieldAdapter = + access.getAdapter(clazz).getPropertyAdapter(labelField); + } + } + + @Override + public List<OptionGroupModel> getOptionGroups() { + return null; + } + + @Override + public List<OptionModel> getOptions() { + List<OptionModel> optionModelList = new ArrayList<OptionModel>(); + if (labelFieldAdapter == null) { + for (T obj : list) { + optionModelList.add(new OptionModelImpl(nvl(obj), obj)); + } + } else { + for (T obj : list) { + optionModelList.add(new OptionModelImpl(nvl(labelFieldAdapter + .get(obj)), obj)); + } + } + return optionModelList; + } + + public List<T> getList() { + return list; + } + + // ValueEncoder methods + + @Override + public String toClient(T obj) { + if (idFieldAdapter == null) { + return obj + ""; + } else { + return idFieldAdapter.get(obj) + ""; + } + } + + @Override + public T toValue(String string) { + if (idFieldAdapter == null) { + for (T obj : list) { + if (nvl(obj).equals(string)) { + return obj; + } + } + } else { + for (T obj : list) { + if (nvl(idFieldAdapter.get(obj)).equals(string)) { + return obj; + } + } + } + return null; + } + + private String nvl(Object o) { + if (o == null) { + return ""; + } else { + return o.toString(); + } + } +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/GenericSelectModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -0,0 +1,160 @@ +package org.chorem.pollen.ui.models; + +import org.apache.tapestry5.ValueEncoder; +import org.chorem.pollen.PollenBusinessException; +import org.chorem.pollen.entity.Participant; +import org.chorem.pollen.entity.ParticipantList; +import org.chorem.pollen.service.ServicePoll; +import org.chorem.pollen.ui.services.PollenManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Created: 18 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + */ +public class ParticipantListModel implements ValueEncoder<Participant> { + + private static final Logger logger = + LoggerFactory.getLogger(ParticipantListModel.class); + + protected ServicePoll service; + + protected PollenManager manager; + + protected ParticipantList list; + + protected ParticipantMap participants; + + public ParticipantListModel(ServicePoll service, PollenManager manager) { + this.service = service; + this.manager = manager; + participants = new ParticipantMap(); + } + + public Participant addNewParticipant() { + Participant newParticipant = service.getNewPollParticipant(); + String id = manager.createPollenId(); + participants.put(id, newParticipant); + return newParticipant; + } + + public void removeParticipant(Participant participant) { + if (logger.isDebugEnabled()) { + logger.debug("Remove participant : " + participant); + } + participants.remove(participant); + } + + public Collection<Participant> getParticipants() { + return participants.values(); + } + + public void setList(ParticipantList participantList) { + if (logger.isDebugEnabled()) { + logger.debug("Set current list : " + participantList.getName()); + } + list = participantList; + participants.clear(); + for (Participant participant : participantList.getParticipants()) { + String id = participant.getId() != null ? participant.getId() : + manager.createPollenId(); + if (logger.isTraceEnabled()) { + logger.trace("Push participant : " + + participant.getName() + + " (" + participant.getEmail() + ")" + + " ID = " + id); + } + participants.put(id, participant); + } + } + + public ParticipantList getList() { + return list; + } + + public void reset() { + if (logger.isDebugEnabled()) { + logger.debug("Reset current list"); + } + list = null; + participants.clear(); + } + + public void persistParticipants() throws PollenBusinessException { + if (logger.isDebugEnabled()) { + logger.debug("Save current list : " + list.getName()); + } + list.setParticipants(getParticipants()); + } + + @Override + public String toClient(Participant value) { + String key = participants.getKey(value); + if (logger.isTraceEnabled()) { + logger.trace("toClient key = " + key); + } + return key; + } + + @Override + public Participant toValue(String key) { + Participant value = participants.getValue(key); + if (logger.isTraceEnabled()) { + logger.trace("toValue from : " + key + " = " + value.getName() + + " (" + value.getEmail() + ")"); + } + return value; + } + + /** + * Participant map is a BidiMap ordered on values inserted using a {@link + * LinkedHashMap}. + */ + protected class ParticipantMap { + + protected Map<String, Participant> participants; + + protected Map<Participant, String> keys; + + public ParticipantMap() { + participants = new LinkedHashMap<String, Participant>(); + keys = new HashMap<Participant, String>(); + } + + public void put(String id, Participant participant) { + participants.put(id, participant); + keys.put(participant, id); + } + + public String getKey(Participant participant) { + return keys.get(participant); + } + + public Participant getValue(String id) { + return participants.get(id); + } + + public void clear() { + keys.clear(); + participants.clear(); + } + + public void remove(Participant participant) { + String id = keys.remove(participant); + participants.remove(id); + } + + public Collection<Participant> values() { + return participants.values(); + } + + } +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/ParticipantListModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -0,0 +1,286 @@ +package org.chorem.pollen.ui.models; + +import org.apache.commons.lang.StringUtils; +import org.apache.tapestry5.ValueEncoder; +import org.chorem.pollen.PollenBusinessException; +import org.chorem.pollen.common.PollType; +import org.chorem.pollen.entity.ParticipantList; +import org.chorem.pollen.entity.Poll; +import org.chorem.pollen.entity.UserAccount; +import org.chorem.pollen.service.ServicePoll; +import org.chorem.pollen.ui.pages.poll.PollForm; +import org.chorem.pollen.ui.services.PollenManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Model for PollForm page. Contains the current {@code poll} and its + * participant {@code lists}. Use {@link ParticipantListModel} to manage current + * edited list for restricted or group Poll. Implement a {@link ValueEncoder} to + * manage ParticipantList client conversion in PollForm page. + * <p/> + * Created: 18 mai 2010 + * + * @author fdesbois <fdesbois@codelutin.com> + * @version $Id$ + * @see PollForm + * @see ValueEncoder + */ +public class PollFormModel implements ValueEncoder<ParticipantList> { + + private static final Logger logger = + LoggerFactory.getLogger(PollFormModel.class); + + /** Default listName for Restricted Poll */ + private static final String DEFAULT_LIST_NAME = "LIST"; + + /** Service to manage poll */ + protected ServicePoll service; + + /** Current poll in edition */ + protected Poll poll; + + /** Current lists in edition */ + protected Map<String, ParticipantList> lists; + + /** Current listModel that contains current edited list and its participants */ + protected ParticipantListModel listModel; + + protected boolean createMode; + + /** + * Constructor of PollFormModel. Need services {@code servicePoll} and + * {@code manager} to manage the current edited poll. Use {@link + * #initPoll(String, UserAccount)} to initialize the poll. + * + * @param servicePoll ServicePoll to manage poll + * @param manager PollenManager to manage ids + */ + public PollFormModel(ServicePoll servicePoll, + PollenManager manager) { + this.service = servicePoll; + lists = new LinkedHashMap<String, ParticipantList>(); + this.listModel = new ParticipantListModel(service, manager); + } + + /** + * Initialize the poll using an {@code uid} for an existing poll or the + * current {@code user} connected if he exists as the creator of a new + * poll. + * + * @param uid Unique id of an existing poll (can be null for a new poll) + * @param user Connected user as creator of a new poll (can be null if no + * user is connected). + */ + public void initPoll(String uid, UserAccount user) { + if (StringUtils.isNotEmpty(uid)) { + if (logger.isDebugEnabled()) { + logger.debug("Get existing poll with pollUID = " + uid); + } + poll = service.getPollForUpdate(uid); + // TODO : init advancedOptions + // TODO-fdesbois-2010-05-19 : exception need to be throw if uid not correspond to an existing poll + } else { + if (logger.isDebugEnabled()) { + logger.debug("Init new poll"); + } + poll = service.getNewPoll(user); + createMode = true; + } + } + + /** + * Get the current poll. Will be null if initializion with {@link + * #initPoll(String, UserAccount)} has not been called. + * + * @return the current poll. + */ + public Poll getPoll() { + return poll; + } + + /** + * Check if the current poll is in creation mode. + * + * @return true for create mode or false. + */ + public boolean isCreateMode() { + return createMode; + } + + /** + * Change the poll type to {@code type}. The lists managment will depends on + * poll type. For a {@link PollType#RESTRICTED} poll, a new list will be + * automatically added and set for current usage. For a {@link + * PollType#GROUP} poll, the listModel is simply reset. + * + * @param type PollType to change + */ + public void setPollType(PollType type) { + lists.clear(); + if (type.isRestricted()) { + addNewList(DEFAULT_LIST_NAME); + // Set automatically the current list to the unique one + listModel.setList(lists.get(DEFAULT_LIST_NAME)); + } else if (type.isGroup()) { + listModel.reset(); + } + poll.setPollType(type); + } + + /** + * Retrieve a collection of {@link ParticipantList} of current lists. + * + * @return a Collection<ParticipantList> + */ + public Collection<ParticipantList> getLists() { + return lists.values(); + } + + /** + * Add a new list to the poll using the {@code listName}. The list will not + * be added if the {@code listName} is empty or if a list with this {@code + * listName} already exists. + * + * @param listName for the new list to add + * @return true if the list has been added, false otherwise + * @see #addList(ParticipantList) + */ + public boolean addNewList(String listName) { + boolean result = false; + if (StringUtils.isNotEmpty(listName)) { + ParticipantList newList = service.getNewPollList(); + newList.setName(listName); + return addList(newList); + } + return result; + } + + /** + * Add a {@code list} to the poll. The {@code list} will not be added if its + * name already reference an exising list. + * + * @param list ParticipantList to add + * @return true if the list has been added, false otherwise + */ + public boolean addList(ParticipantList list) { + boolean result = false; + if (list != null) { + String listName = list.getName(); + if (!lists.containsKey(listName)) { + if (logger.isDebugEnabled()) { + logger.debug("Add list : " + listName); + } + lists.put(listName, list); + result = true; + } else if (logger.isDebugEnabled()) { + logger.debug("Refuse adding list : " + listName); + } + } + return result; + } + + /** + * Give the current {@link ParticipantListModel} that references the list + * currently edited. + * + * @return the current listModel + */ + public ParticipantListModel getListModel() { + return listModel; + } + + /** + * Set the current list using its {@code listName}. The previous current + * list will be automatically saved. If error occurs during save, the + * previous list will be refresh (no list change will be done). + * + * @param listName name of the list to set (empty name will be ignored) + * @throws PollenBusinessException for saving error (doubloons) + * @see #saveCurrentList() + */ + public void setCurrentList(String listName) throws PollenBusinessException { + if (StringUtils.isNotEmpty(listName)) { + ParticipantList list = getCurrentList(); + try { + // Save previous list if not null + if (list != null) { + saveCurrentList(); + } + // Change list + list = lists.get(listName); + } finally { + // Previous list will be keeped if error occurs during save. + // Apply change in listModel + listModel.setList(list); + } + } + } + + /** + * Get the current list. + * + * @return the current list in edition. + */ + public ParticipantList getCurrentList() { + return listModel.getList(); + } + + /** Remove the current list. */ + public void removeCurrentList() { + if (logger.isDebugEnabled()) { + logger.debug("Remove list : " + listModel.getList().getName()); + } + + getLists().remove(listModel.getList()); + listModel.reset(); + } + + /** + * Save the current participants from current list. + * + * @throws PollenBusinessException for saving errors (doubloons) + * @see ParticipantListModel#persistParticipants() + */ + public void saveCurrentList() throws PollenBusinessException { + listModel.persistParticipants(); + } + + public void create() throws PollenBusinessException { + service.createPoll(poll, getLists()); + } + + /** + * ValueEncoder toClient is used to convert {@code value} to the list name. + * + * @param value ParticipantList to convert toClient + * @return the list name as a unique key for the list + * @see ValueEncoder#toClient(Object) + */ + @Override + public String toClient(ParticipantList value) { + return value.getName(); + } + + /** + * ValueEncoder toClient is used to convert {@code clientValue} key to the + * list object. + * + * @param clientValue List name of the ParticipantList to retrieve. + * @return the ParticipantList corresponding to its name in argument + * @see ValueEncoder#toValue(String) + */ + @Override + public ParticipantList toValue(String clientValue) { + for (ParticipantList curr : lists.values()) { + if (clientValue.equals(curr.getName())) { + return curr; + } + } + return null; + } +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/PollFormModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -0,0 +1,53 @@ +package org.chorem.pollen.ui.models; + +import org.apache.tapestry5.grid.SortConstraint; +import org.chorem.pollen.PollenException; +import org.chorem.pollen.bean.Filter; +import org.chorem.pollen.entity.UserAccount; +import org.chorem.pollen.service.ServiceUser; +import org.nuiton.web.tapestry5.data.AbstractMappedGridDataSource; + +import java.util.Map; + +/** + * UserAccountDataSource + * <p/> + * Created: 23 avr. 2010 + * + * @author fdesbois + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ + * par : $Author$ + */ +public class UserAccountDataSource extends AbstractMappedGridDataSource<String, UserAccount> { + + private ServiceUser service; + + private Filter filter; + + public UserAccountDataSource(ServiceUser service, Filter filter) { + this.service = service; + this.filter = filter; + } + + @Override + protected Map<String, UserAccount> execute(int startIndex, int endIndex, + SortConstraint orderBy) throws PollenException { + filter.setStartIndex(startIndex); + filter.setEndIndex(endIndex); + filter.setOrderBy(resolveOrderBy(orderBy)); + return service.getUsers(filter); + } + + @Override + protected int count() throws PollenException { + return service.getNbUsers(filter); + } + + @Override + public Class<?> getRowType() { + return UserAccount.class; + } + +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/models/UserAccountDataSource.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/AdminUsers.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -40,12 +40,12 @@ import org.chorem.pollen.ui.components.Border; import org.chorem.pollen.ui.data.AddressBar; import org.chorem.pollen.ui.data.PollenRequiresAuthentication; -import org.chorem.pollen.ui.data.UserAccountDataSource; +import org.chorem.pollen.ui.models.UserAccountDataSource; import org.chorem.pollen.ui.services.PollenManager; import org.slf4j.Logger; /** - * Management of users by an admin. + * Management of users by an admin. * * @author fdesbois <fdesbois@codelutin.com> * @version $Id$ @@ -57,9 +57,9 @@ @InjectComponent private Border border; - /** Page title from Messages **/ - @Parameter(defaultPrefix = BindingConstants.MESSAGE, - value = "pollen.page.AdminUsers.title") + /** Page title from Messages * */ + @Parameter(defaultPrefix = BindingConstants.MESSAGE, + value = "pollen.page.AdminUsers.title") @Property private String title; @@ -72,13 +72,13 @@ return AddressBar.newBar().appendCurrent(title); } - /** Services used by the page **/ + /** Services used by the page * */ @Inject private Logger logger; @Inject private ComponentResources resources; - + @Inject private Messages messages; @@ -93,25 +93,25 @@ /***************************** USERS GRID/FORM ****************************/ - /** Components of the page **/ + /** Components of the page * */ @InjectComponent private Form usersForm; - /** + /** * Users list : the {@link Persist} is used to keep current page and order * from dataSource. */ @Persist private UserAccountDataSource accounts; - /** Current user from iteration on accounts **/ + /** Current user from iteration on accounts * */ @Property private UserAccount account; - /** Edited user **/ + /** Edited user * */ @Property private UserAccount accountEdited; - + /** * Use the {@link UserAccountDataSource} to retrieve existing user accounts. * This will manage pagination and order of the grid. @@ -129,7 +129,7 @@ * Test if the edited account is the current one in the Grid. * * @return true if the accountEdited is defined and correspond to the - * current account in the Grid + * current account in the Grid */ public boolean isEditionMode() { // The current account in the loop is equals to the edited one @@ -147,9 +147,9 @@ } /** - * ON_ACTION :: Handler method for action on editAccount actionLink. - * The accountEdited will be set to the user selected in the Grid with - * {@code login}. + * ON_ACTION :: Handler method for action on editAccount actionLink. The + * accountEdited will be set to the user selected in the Grid with {@code + * login}. * * @param login key of the user from the Grid * @return the usersForm to display form with accountEdited @@ -163,8 +163,8 @@ } /** - * ON_ACTION :: Handler method for action on deletedAccount actionLink. - * The selected login from the Grid will be used to delete the user. + * ON_ACTION :: Handler method for action on deletedAccount actionLink. The + * selected login from the Grid will be used to delete the user. * * @param login used to delete the user * @see ServiceUser#deleteUser(String) @@ -188,7 +188,7 @@ * ON_VALIDATE_FORM :: Handler method for validateForm event of the * usersForm. The accountEdited will be updated using serviceUser. Errors * from service will be recorded into the usersForm. - * + * * @see ServiceUser#updateUser(UserAccount, boolean) */ public void onValidateFormFromUsersForm() { @@ -201,20 +201,20 @@ } /** - * ON_SUCCESS :: Handler method for success event of the usersForm. - * No error occurs from validation, a message will be displayed to client. + * ON_SUCCESS :: Handler method for success event of the usersForm. No error + * occurs from validation, a message will be displayed to client. * * @return the current page to refresh */ - public Object onSuccessFromUsersForm() { + public Object onSuccessFromUsersForm() { addInfo(messages.get("pollen.ui.user.update.success")); return this; } /** - * ON_FAILURE :: Handler method for failure event of the usersForm. - * Errors were recorded into the usersForm. The usersForm will be refresh - * to display error messages. + * ON_FAILURE :: Handler method for failure event of the usersForm. Errors + * were recorded into the usersForm. The usersForm will be refresh to + * display error messages. * * @return the usersForm to refresh (in the usersZone) */ @@ -224,11 +224,11 @@ /***************************** NEW USER FORM ******************************/ - /** newUser to create from newUserForm **/ + /** newUser to create from newUserForm * */ @Property private UserAccount newUser; - /** Components used for refresh or validations **/ + /** Components used for refresh or validations * */ @InjectComponent private Form newUserForm; @@ -238,13 +238,12 @@ @InjectComponent private Field newEmail; - /** newPassword created for the newUser **/ + /** newPassword created for the newUser * */ private String newPassword; /** - * ON_PREPARE :: Handler method for prepare events of the newUserForm. - * The newUser will be initialized if needed before render and before - * submit. + * ON_PREPARE :: Handler method for prepare events of the newUserForm. The + * newUser will be initialized if needed before render and before submit. */ public void onPrepareFromNewUserForm() { if (newUser == null) { @@ -254,10 +253,10 @@ /** * ON_VALIDATE_FORM :: Handler method for validateForm event of the - * newUserForm. The newUser will be created using serviceUser. Errors - * from service will be recorded into the newUserForm. The password will - * be generated if an email is set into the form. Otherwise the password - * will be the same as the newUser login. + * newUserForm. The newUser will be created using serviceUser. Errors from + * service will be recorded into the newUserForm. The password will be + * generated if an email is set into the form. Otherwise the password will + * be the same as the newUser login. * * @see ServiceUser#createUser(UserAccount) */ @@ -268,12 +267,12 @@ // Generate new password newPassword = RandomStringUtils.randomAlphanumeric(8); passwordInfo = - messages.get("pollen.ui.user.create.passwordGenerated"); + messages.get("pollen.ui.user.create.passwordGenerated"); } else { // Password will be the same as the login newPassword = newUser.getLogin(); passwordInfo = - messages.get("pollen.ui.user.create.passwordSameAsLogin"); + messages.get("pollen.ui.user.create.passwordSameAsLogin"); } newUser.setNewPassword(newPassword); @@ -283,7 +282,8 @@ String message = manager.getErrorMessage(eee, messages, logger); switch (eee.getType()) { case USER_EMAIL_EXIST: - newUserForm.recordError(newEmail, message); break; + newUserForm.recordError(newEmail, message); + break; case USER_LOGIN_EXIST: newUserForm.recordError(newLogin, message); } @@ -291,11 +291,11 @@ } /** - * ON_SUCCESS :: Handler method for success event of the newUserForm. - * No error occurs from validation, success message is displayed to client - * and an email is sent to the newUser created if it's defined. - * The persist fields of the page will be discarded to refresh the grid with - * no order or page filter. + * ON_SUCCESS :: Handler method for success event of the newUserForm. No + * error occurs from validation, success message is displayed to client and + * an email is sent to the newUser created if it's defined. The persist + * fields of the page will be discarded to refresh the grid with no order or + * page filter. * * @return the current page to refresh * @see ServiceEmail#sendEmail(PollenEmail) @@ -309,12 +309,12 @@ PollenEmail email = serviceEmail.getNewEmail(newUser); email.setSubject( messages.format("pollen.email.userRegister.subject", - newUser.getLogin())); + newUser.getLogin())); email.setContent( messages.format("pollen.email.userRegister.content", - newUser.getDisplayName(), newUser.getLogin(), - newPassword, getUrl())); - + newUser.getDisplayName(), newUser.getLogin(), + newPassword, getUrl())); + serviceEmail.sendEmail(email); addInfo(messages.format("pollen.ui.user.create.sendEmail", newUser.getLogin(), newUser.getEmail())); @@ -334,9 +334,9 @@ } /** - * ON_FAILURE :: Handler method for failure event of the newUserForm. - * Errors were recorded into the newUserForm. The newUserForm will be - * refresh to display error messages. + * ON_FAILURE :: Handler method for failure event of the newUserForm. Errors + * were recorded into the newUserForm. The newUserForm will be refresh to + * display error messages. * * @return the newUserForm to refresh (in the newUserZone) */ Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -27,8 +27,8 @@ import org.chorem.pollen.ui.base.AbstractPollenPage; import org.chorem.pollen.ui.components.Border; import org.chorem.pollen.ui.data.AddressBar; -import org.chorem.pollen.ui.data.ParticipantListModel; -import org.chorem.pollen.ui.data.PollFormModel; +import org.chorem.pollen.ui.models.ParticipantListModel; +import org.chorem.pollen.ui.models.PollFormModel; import org.chorem.pollen.ui.services.PollenManager; import org.nuiton.web.tapestry5.components.FeedBack; import org.slf4j.Logger; @@ -79,6 +79,7 @@ return border; } + /** Services injected */ @Inject private Logger log; @@ -91,11 +92,17 @@ @Inject private PollenManager manager; + /** Main page context */ private String pollUID; + /** Main page model */ @Persist - private Poll poll; + private PollFormModel model; + /** Main page form component */ + @InjectComponent + private Form mainForm; + void onActivate(String id) { pollUID = id; } @@ -105,10 +112,8 @@ } void setupRender() { - poll = null; - initMainInfos(); - initOptions(); model = null; + initOptions(); listsFeedback.clearErrors(); } @@ -116,25 +121,30 @@ * Get the main poll used in the form. The existing poll is loaded if the * pollUID exist. * - * @return poll existing or a new one - * @throws PollenBusinessException + * @return the current poll in edition + * @see #getModel() */ public Poll getPoll() { - if (poll == null) { - if (StringUtils.isNotEmpty(pollUID)) { - if (log.isDebugEnabled()) { - log.debug("Get existing poll with pollUID = " + pollUID); - } - poll = servicePoll.getPollForUpdate(pollUID); - // TODO : init advancedOptions - } else { - if (log.isDebugEnabled()) { - log.debug("Init new poll"); - } - poll = servicePoll.getNewPoll(getUserConnected()); + return getModel().getPoll(); + } + + /** + * Retrieve the current model for the PollForm or create a new one. The poll + * will be initialized depends on {@code pollUID} context : the existing + * poll corresponding will be retrieve or a new one will be instantiate with + * connected user as the creator. + * + * @return the model of this page + */ + public PollFormModel getModel() { + if (model == null) { + if (log.isDebugEnabled()) { + log.debug("-------- NEW POLL FORM MODEL --------"); } + model = new PollFormModel(servicePoll, manager); + model.initPoll(pollUID, getUserConnected()); } - return poll; + return model; } /** @@ -144,7 +154,7 @@ * @throws PollenBusinessException */ public boolean isCreateMode() { - return StringUtils.isEmpty(getPoll().getId()); + return getModel().isCreateMode(); } /** @@ -173,10 +183,6 @@ return AddressBar.newBar().appendCurrent(getPageTitle()); } - public void setPollCopyFromPoll(Poll poll) { - this.poll = servicePoll.getNewPoll(poll); - } - public Date getCurrentDate() { return new Date(); } @@ -188,19 +194,15 @@ @Environmental private RenderSupport renderSupport; -// @InjectComponent -// private FormFragment optionsFragment; - /** * Action when rendering form. A script is added to manage form - * interactions + * interactions. */ @Log void onPrepareForRender() { String formId = mainForm.getClientId(); if (log.isDebugEnabled()) { log.debug("form id : " + formId); -// log.debug("options fragment id : " + optionsFragment.getClientId()); } if (formId != null) { // Script for form interactions : see "webapp/js/pollForm.js" @@ -214,17 +216,15 @@ /** *********************** MAIN INFOS ********************************* */ - @InjectComponent - private Form mainForm; - @Persist - @Property - private boolean advancedOptions; +// @Persist +// @Property +// private boolean advancedOptions; +// +// protected void initMainInfos() { +// advancedOptions = false; +// } - protected void initMainInfos() { - advancedOptions = false; - } - /************************** CHOIX *****************************************/ // @Property @@ -397,57 +397,38 @@ return getPoll().getPollType().isFree(); } - /** ********************* LISTS **************************************** */ + /** ******************** LISTS **************************************** */ - @Persist - private PollFormModel model; + @Inject + private ComponentResources resources; -// @Persist -// private Map<String, ParticipantList> lists; + @InjectComponent + private Zone listsZone; + @InjectComponent + private FeedBack listsFeedback; + + /** Current list for loop (GROUP type) */ @Property private ParticipantList list; -// @Persist -// private String listSelectedName; - -// @Persist -// private ParticipantList listSelected; -// -// private Map<String, Participant> selectedParticipants; - + /** Current participant for ajaxFormLoop (GROUP or RESTRICTED) types */ @Property private Participant participant; - @InjectComponent - private Zone listsZone; - + /** Field to add a new list */ @Property private String listName; - @Inject - private ComponentResources resources; - + /** Flag for subForm used for lists managment */ @Property private boolean formActivate; - @InjectComponent - private FeedBack listsFeedback; - + /** Flag if submit comes from lists edition */ private boolean editLists; /** DATA ** */ - public PollFormModel getModel() { - if (model == null) { - if (log.isDebugEnabled()) { - log.debug("-------- NEW MODEL --------"); - } - model = new PollFormModel(getPoll(), servicePoll, manager); - } - return model; - } - public ParticipantListModel getListModel() { return getModel().getListModel(); } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-19 12:59:57 UTC (rev 3001) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-05-19 13:25:45 UTC (rev 3002) @@ -15,8 +15,6 @@ package org.chorem.pollen.ui.pages.user; -import java.util.List; - import org.apache.tapestry5.BindingConstants; import org.apache.tapestry5.annotations.IncludeStylesheet; import org.apache.tapestry5.annotations.InjectComponent; @@ -33,18 +31,20 @@ import org.chorem.pollen.ui.components.UserListsCreate; import org.chorem.pollen.ui.components.UserListsUpdate; import org.chorem.pollen.ui.data.AddressBar; -import org.chorem.pollen.ui.data.GenericSelectModel; import org.chorem.pollen.ui.data.PollenRequiresAuthentication; +import org.chorem.pollen.ui.models.GenericSelectModel; +import java.util.List; + /** * Page to manage favorite lists of the connected user only (managed thanks to * {@link PollenRequiresAuthentication} annotation). This page use two main * components, {@link UserListsCreate} to create a FavoriteList (from import - * csv, ldap or an empty one) and {@link UserListsUpdate} to manage content - * of the FavoriteList. This page will provide {@code favoriteListSelected} - * from a form with only a SelectModel loaded by {@link #getFavoriteLists()} - * with {@link #getFavoriteListModel()} as model. The delete action is also - * manage by the page using {@code serviceFavorite}. + * csv, ldap or an empty one) and {@link UserListsUpdate} to manage content of + * the FavoriteList. This page will provide {@code favoriteListSelected} from a + * form with only a SelectModel loaded by {@link #getFavoriteLists()} with + * {@link #getFavoriteListModel()} as model. The delete action is also manage by + * the page using {@code serviceFavorite}. * * @author rannou * @author fdesbois <fdesbois@codelutin.com> @@ -56,7 +56,7 @@ /************************** PAGE CONFIGURATION ****************************/ - /** Border layout **/ + /** Border layout * */ @InjectComponent private Border border; @@ -65,13 +65,13 @@ return border; } - /** Page title from Messages **/ + /** Page title from Messages * */ @Parameter(defaultPrefix = BindingConstants.MESSAGE, - value = "pollen.page.UserLists.title") + value = "pollen.page.UserLists.title") @Property private String title; - /** + /** * AddressBar for {@code border} component. * * @return a new AddressBar for the page. @@ -80,7 +80,7 @@ return AddressBar.newBar().appendCurrent(title); } - /** Services injected **/ + /** Services injected * */ @Inject private ServiceFavorite serviceFavorite; @@ -90,15 +90,16 @@ @Inject private Messages messages; - /************************** SELECT FAVORITE LIST **************************/ + /** *********************** SELECT FAVORITE LIST ************************* */ private List<FavoriteList> favoriteLists; + private GenericSelectModel<FavoriteList> favoriteListModel; /** - * Main property favoriteListSelected is keeped in Session and was - * used as parameter for UserListsUpdate component. - **/ + * Main property favoriteListSelected is keeped in Session and was used as + * parameter for UserListsUpdate component. + */ @Persist @Property private FavoriteList favoriteListSelected; @@ -113,10 +114,10 @@ if (favoriteListModel == null) { favoriteListModel = new GenericSelectModel<FavoriteList>(getFavoriteLists(), - FavoriteList.class, - FavoriteList.NAME, - FavoriteList.NAME, - propertyAccess); + FavoriteList.class, + FavoriteList.NAME, + FavoriteList.NAME, + propertyAccess); } return favoriteListModel; } @@ -137,28 +138,28 @@ /************************** SELECT FAVORITE LIST **************************/ /** - * Used to verify if the {@code favoriteListSelected} is set and ready - * to be deleted using {@code deleteList} actionLink. + * Used to verify if the {@code favoriteListSelected} is set and ready to be + * deleted using {@code deleteList} actionLink. * * @return true if the {@code favoriteListSelected} is not null. */ public boolean canDeleteList() { - return favoriteListSelected != null; + return favoriteListSelected != null; } /** * ON_ACTION :: Handler method for action on {@code deleteList} actionLink. - * Check is done using {@link #canDeleteList()}, then the - * {@code serviceFavorite} is called to execute the delete on - * {@code favoriteListSelected}. - * + * Check is done using {@link #canDeleteList()}, then the {@code + * serviceFavorite} is called to execute the delete on {@code + * favoriteListSelected}. + * * @see ServiceFavorite#deleteFavoriteList(FavoriteList) */ void onActionFromDeleteList() { if (canDeleteList()) { serviceFavorite.deleteFavoriteList(favoriteListSelected); addInfo( - messages.get("pollen.ui.list.delete.success")); + messages.get("pollen.ui.list.delete.success")); } } } \ No newline at end of file