Author: amarkhel
Date: 2009-01-23 08:28:09 -0500 (Fri, 23 Jan 2009)
New Revision: 12388
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java
Removed:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java
Log:
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/AlbumManager.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -20,30 +20,34 @@
*/
package org.richfaces.realworld.manager;
-import javax.faces.model.SelectItem;
+import java.util.ArrayList;
+import java.util.List;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.model.TreeNode;
import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.service.IAlbumAction;
import org.richfaces.realworld.tree.TreeAlbumItem;
-import org.richfaces.realworld.tree.TreeRootItem;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.tree.TreeMyAlbumsItem;
+import org.richfaces.realworld.ui.ConversationState;
@Name("albumManager")
@Scope(ScopeType.CONVERSATION)
public class AlbumManager {
+ private static final String SLASH = "/";
+
@In(create=true, required=true)
private IAlbumAction albumAction;
- @In(create=true) @Out TreeRootItem treeRoot;
+ @In(create=true) @Out TreeMyAlbumsItem treeMyAlbumsItem;
@In(create=true, required=true) @Out
private Album album;
@@ -55,52 +59,60 @@
FileManager fileManager;
@In @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
public void addAlbum(){
albumAction.addAlbum(album);
- treeRoot.getAvailableAlbums().add(new SelectItem(album.getName()));
- TreeAlbumItem albumItem = new TreeAlbumItem(album.getId(), treeRoot, album);
- treeRoot.addAlbumToTree(albumItem);
- fileManager.addDirectory(user.getLogin() + fileManager.getFileSeparator() +
album.getName());
- selectionHelper.setSelectedImage(null);
- selectionHelper.setSelectedAlbum(albumItem.getAlbum());
+ TreeNode parent = null;
+ if(null == album.getParent()){
+ parent = treeMyAlbumsItem;
+ }else{
+ parent = treeMyAlbumsItem.getParentItem(album.getParent().getName());
+ }
+ TreeAlbumItem albumItem = new TreeAlbumItem(album.getId(), parent, album,
treeMyAlbumsItem);
+ treeMyAlbumsItem.addAlbumToTree(parent, albumItem);
+ List<String> list = new ArrayList<String>();
+ String albumPath = album.getAlbumPathFromParents(album, list,
fileManager.getFileSeparator()) + album.getName();
+ fileManager.addDirectory(user.getLogin() + fileManager.getFileSeparator() +
albumPath);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedAlbum(albumItem.getAlbum());
}
public void editAlbum(Album album){
boolean nameChanged = !album.getName().equals(album.getChangedName());
if(nameChanged){
- String directoryOld = user.getLogin() + fileManager.getFileSeparator() +
album.getName();
- String directoryNew = user.getLogin() + fileManager.getFileSeparator() +
album.getChangedName();
+ String directoryOld = user.getLogin() + fileManager.getFileSeparator() +
album.getAlbumPathFromParents(album, new
ArrayList<String>(),fileManager.getFileSeparator() )+album.getName();
+ Album oldAlbum =
((TreeAlbumItem)treeMyAlbumsItem.getParentItem(album.getName())).getAlbum();
+ String directoryNew = user.getLogin() + fileManager.getFileSeparator() +
oldAlbum.getAlbumPathFromParents(oldAlbum, new
ArrayList<String>(),fileManager.getFileSeparator() )+album.getChangedName();
try {
fileManager.renameDirectory(directoryOld, directoryNew);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ String albumOld = user.getLogin() + SLASH + album.getAlbumPathFromParents(album, new
ArrayList<String>(),SLASH )+album.getName();
+ String albumNew = user.getLogin() + SLASH + oldAlbum.getAlbumPathFromParents(oldAlbum,
new ArrayList<String>(),SLASH )+album.getChangedName();
+ albumAction.renameAllImagesFromAlbumAndChilds(album, albumOld, albumNew);
album.setName(album.getChangedName());
album.setChangedName(null);
+
}
albumAction.editAlbum(album);
- treeRoot.updateChild(album);
+ treeMyAlbumsItem.updateChild(album);
}
public void deleteAlbum(Album album){
String albumName = album.getName();
albumAction.deleteAlbum(album);
- SelectItem item = treeRoot.getSelectItemByName(album.getName());
- treeRoot.getAvailableAlbums().remove(item);
- treeRoot.removeChild(album.getId());
+ TreeAlbumItem oldAlbum =
(TreeAlbumItem)treeMyAlbumsItem.getParentItem(album.getName());
+ oldAlbum.getParent().removeChild(album.getId());
fileManager.deleteDirectory(user.getLogin() + fileManager.getFileSeparator() +
albumName);
- selectionHelper.setSelectedAlbum(user.getChildAlbums().get(0));
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
}
public void updateSelectedAlbum(){
- selectionHelper.setSelectedAlbum(user.getAlbumByName(selectionHelper.getSelectedAlbum().getName()));
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
- selectionHelper.setSelectedImageIndex(1);
- selectionHelper.setUserAlbumSelected(true);
+ conversationState.setSelectedAlbum(user.getAlbumByName(conversationState.getSelectedAlbum().getName()));
}
+
+
}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/Authenticator.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -20,11 +20,9 @@
*/
package org.richfaces.realworld.manager;
-import java.io.IOException;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
@@ -40,17 +38,22 @@
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Identity;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.fileupload.AvatarUpload;
import org.richfaces.realworld.fileupload.FileManager;
import org.richfaces.realworld.navigation.NavigationEnum;
import org.richfaces.realworld.service.IUserAction;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.ui.ConversationState;
@Name("authenticator")
@Scope(ScopeType.CONVERSATION)
public class Authenticator implements Serializable
{
+ private static final String INVALID_LOGIN_OR_PASSWORD = "Invalid login or
password";
+
+ private static final String MAIN_OUTCOME = "main";
+
+ private static final String LOGIN_SUCCESS = "You are successfully
registered.";
+
@In("#{messages['user.exist']}") private String
USER_WITH_THIS_LOGIN_ALREADY_EXIST;
@In("#{messages['user.confirm.error']}") private String
CONFIRM_PASSWORD_NOT_EQUALS_PASSWORD;
@@ -70,7 +73,7 @@
private static final long serialVersionUID = -4585673256547342140L;
@Logger Log log;
-
+
@In Identity identity;
@In FacesMessages facesMessages;
@@ -81,11 +84,8 @@
@In(create = true)
FileManager fileManager;
- @In(create = true)
- AvatarUpload avatarUpload;
-
@In(create=true) @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
/* (non-Javadoc)
* @see org.richfaces.realworld.service.IAuthenticator#authenticate()
@@ -94,8 +94,8 @@
{
if(null == identity.getUsername() || identity.getUsername().equals("")){
identity.addRole(GUEST_ROLE);
+ userAction.loginAnonymous();
Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.SEARCH);
- userAction.loginAnonymous();
return true;
}
try{
@@ -105,17 +105,12 @@
if(!fileManager.isDirectoryPresent(identity.getUsername())){
fileManager.addDirectory(identity.getUsername());
}
- if(user.getChildAlbums().size() > 0){
- selectionHelper.setSelectedAlbum(user.getChildAlbums().get(0));
- //if(selectionHelper.getSelectedAlbum().getImages().size() > 0){
-
//selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
- //}
- }
+ conversationState.setSelectedUser(user);
Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT,
NavigationEnum.IMAGE_PREVIEW);
return true;
}
}catch(Exception nre){
- facesMessages.add("Invalid login or password");
+ facesMessages.add(INVALID_LOGIN_OR_PASSWORD);
return false;
}
return false;
@@ -142,20 +137,14 @@
return "";
}
userAction.register(user);
- if(avatarUpload.getAvatarItem() != null){
- user.setAvatarPath(avatarUpload.getAvatarItem().getImage().getName());
- fileManager.deleteDirectory(user.getLogin() + fileManager.getFileSeparator() +
"avatars");
- fileManager.addDirectory(user.getLogin() + fileManager.getFileSeparator() +
"avatars");
- try {
- fileManager.addImage(user.getLogin() + fileManager.getFileSeparator() +
"avatars" + fileManager.getFileSeparator() + user.getAvatarPath(),
avatarUpload.getAvatarItem().getData());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- String messageTemplate = "You are successfully registered.";
- facesMessages.add(messageTemplate);
+ facesMessages.add(LOGIN_SUCCESS);
return INDEX_OUTCOME;
}
+
+ public String loginAnonymous(){
+ identity.setUsername(null);
+ identity.setPassword(null);
+ this.authenticate();
+ return MAIN_OUTCOME;
+ }
}
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -0,0 +1,133 @@
+package org.richfaces.realworld.manager;
+
+import java.util.ArrayList;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.core.Events;
+import org.richfaces.component.Dropzone;
+import org.richfaces.event.DropEvent;
+import org.richfaces.event.DropListener;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.service.IAlbumAction;
+import org.richfaces.realworld.tree.TreeAlbumItem;
+import org.richfaces.realworld.tree.TreeMyAlbumsItem;
+
+@Name("dndManager")
+public class DnDManager implements DropListener {
+
+ private static final String SLASH = "/";
+
+ private static final String WRONG_DND = "That album isn't yours, so you
can't change it's location";
+
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
+
+ @In @Out TreeMyAlbumsItem treeMyAlbumsItem;
+
+ @In User user;
+ @In(create=true)
+ FileManager fileManager;
+ @In(create=true)
+ IAlbumAction albumAction;
+
+ public void processDrop(DropEvent dropEvent) {
+ Dropzone dropzone = (Dropzone) dropEvent.getComponent();
+ Object dragValue = dropEvent.getDragValue();
+ Object dropValue = dropzone.getDropValue();
+ if(dragValue instanceof Image){
+ handleImage((Image)dragValue, (Album)dropValue);
+ }else if(dragValue instanceof Album){
+ if(dropValue instanceof TreeMyAlbumsItem){
+ handleRoot((Album)dragValue);
+ }else{
+ handleAlbum((Album)dragValue, (Album)dropValue);
+ }
+ }
+ }
+
+ private void handleRoot(Album dragValue) {
+ TreeAlbumItem itemParent = null;
+ if(!dragValue.getOwner().equals(user)){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(WRONG_DND));
+ return;
+ }
+ if(dragValue.getParent() != null ){
+ itemParent = treeMyAlbumsItem.getAlbumByName(dragValue.getParent().getName());
+ dragValue.getParent().removeChildAlbum(dragValue);
+ }else{
+ return;
+ }
+ String directoryOld = user.getLogin() + fileManager.getFileSeparator() +
dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(),
fileManager.getFileSeparator() )+ dragValue.getName();
+ String directoryNew = user.getLogin() + fileManager.getFileSeparator() +
dragValue.getName();
+ fileManager.renameDirectory(directoryOld, directoryNew);
+ String albumOld = user.getLogin() + SLASH +
dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), SLASH );
+ String albumNew = user.getLogin() + SLASH;
+
+ TreeAlbumItem item = treeMyAlbumsItem.getAlbumByName(dragValue.getName());
+ itemParent.removeChild(item.getId());
+ treeMyAlbumsItem.addChild(item.getId(), item);
+ fileManager.renameDirectory(directoryOld, directoryNew);
+ albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+
+ }
+
+ private void handleAlbum(Album dragValue, Album dropValue) {
+ TreeNode itemParent = null;
+ if(!dragValue.getOwner().equals(user)){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(WRONG_DND));
+ return;
+ }
+ if(dragValue.getParent() != null ){
+ itemParent = treeMyAlbumsItem.getAlbumByName(dragValue.getParent().getName());
+ if(dragValue.getParent().equals(dropValue)){
+ return;
+ }
+ }else{
+ itemParent = treeMyAlbumsItem;
+ }
+ String directoryOld = user.getLogin() + fileManager.getFileSeparator() +
dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(),
fileManager.getFileSeparator() ) + dragValue.getName();
+ String directoryNew = user.getLogin() + fileManager.getFileSeparator() +
dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(),
fileManager.getFileSeparator()) + dragValue.getName();
+ String albumOld = user.getLogin() + SLASH +
dragValue.getAlbumPathFromParents(dragValue, new ArrayList<String>(), SLASH );
+ String albumNew = user.getLogin() + SLASH +
dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(), SLASH);
+ dropValue.addChildAlbum(dragValue);
+ TreeAlbumItem itemParentNew = treeMyAlbumsItem.getAlbumByName(dropValue.getName());
+ TreeAlbumItem item = treeMyAlbumsItem.getAlbumByName(dragValue.getName());
+ itemParent.removeChild(item.getId());
+ itemParentNew.addAlbum(item);
+ fileManager.renameDirectory(directoryOld, directoryNew);
+ albumAction.renameAllImagesFromAlbumAndChilds(dragValue, albumOld, albumNew);
+ try {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ AjaxContext ac = AjaxContext.getCurrentInstance();
+ UIComponent destTree = fc.getViewRoot().findComponent("tree");
+ ac.addComponentToAjaxRender(destTree);
+ } catch (Exception e) {
+ //System.err.print(e.getMessage());
+ }
+ }
+
+ private void handleImage(Image dragValue, Album dropValue) {
+ if(dragValue.getAlbum().equals(dropValue)){
+ return;
+ }
+ String fileNameOld = fileManager.transformToServerPath(dragValue.getPath());
+ int lastIndexOf = dragValue.getPath().lastIndexOf(SLASH);
+ String prevPathEnd = dragValue.getPath().substring(lastIndexOf);
+ String fileNameNew = user.getLogin() + fileManager.getFileSeparator() +
dropValue.getAlbumPathFromParents(dropValue, new ArrayList<String>(),
fileManager.getFileSeparator()) + prevPathEnd;
+ String newPath = user.getLogin() + SLASH + dropValue.getAlbumPathFromParents(dropValue,
new ArrayList<String>(), SLASH) + prevPathEnd;
+ dragValue.setPath(newPath);
+ dropValue.addImage(dragValue);
+ fileManager.renameImage(fileNameOld, fileNameNew);
+ albumAction.flush();
+ }
+
+}
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/DnDManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/ImageManager.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -20,6 +20,7 @@
*/
package org.richfaces.realworld.manager;
+import java.util.ArrayList;
import java.util.Date;
import org.jboss.seam.ScopeType;
@@ -28,32 +29,39 @@
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.core.Events;
+import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Comment;
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.navigation.NavigationEnum;
import org.richfaces.realworld.service.IImageAction;
import org.richfaces.realworld.tree.TreeAlbumItem;
-import org.richfaces.realworld.tree.TreeImageItem;
-import org.richfaces.realworld.tree.TreeRootItem;
-import org.richfaces.realworld.util.RatingBinder;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.tree.TreeMyAlbumsItem;
+import org.richfaces.realworld.ui.RatingBinder;
+import org.richfaces.realworld.ui.ConversationState;
@Name("imageManager")
@Scope(ScopeType.CONVERSATION)
public class ImageManager {
+ private static final String META_TAG_WRONG = "Meta-tag length should be great then
2 symbols";
+
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
+
@In(create=true, required=true)
private IImageAction imageAction;
+ private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
+
@In(create=true)
FileManager fileManager;
- @In(create=true) @Out TreeRootItem treeRoot;
+ @In(create=true) @Out TreeMyAlbumsItem treeMyAlbumsItem;
@In(create=true) @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
@In
private User user;
@@ -62,56 +70,43 @@
private RatingBinder ratingBinder;
public void deleteImage(Image image){
- int index = image.getAlbum().getIndex(image);
- String albumName = image.getAlbum().getName();
String imagePath = image.getPath();
- TreeAlbumItem parent = treeRoot.getAlbums().get(image.getAlbum().getId());
imageAction.deleteImage(image);
- parent.removeChild(image.getId());
fileManager.deleteImage(fileManager.transformToServerPath(imagePath));
- if(selectionHelper.getSelectedAlbum().getImages().size() > index){
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(index));
- }else{
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(index-1));
- }
}
public void editImage(Image image){
- TreeAlbumItem parent = treeRoot.getAlbums().get(image.getAlbum().getId());
+ TreeAlbumItem parent = treeMyAlbumsItem.getAlbumByName(image.getAlbum().getName());
boolean parentChanged = !parent.getAlbum().getName().equals(image.getAlbumName());
if(parentChanged){
- parent.removeChild(image.getId());
- TreeAlbumItem albumItem = treeRoot.getAlbumByName(image.getAlbumName());
- TreeImageItem imageItem = new TreeImageItem(image.getId(),albumItem,image);
- albumItem.addChild(image.getId(), imageItem);
+ TreeAlbumItem albumItem = treeMyAlbumsItem.getAlbumByName(image.getAlbumName());
String fileNameOld = fileManager.transformToServerPath(image.getPath());
int lastIndexOf = image.getPath().lastIndexOf("/");
String prevPathEnd = image.getPath().substring(lastIndexOf);
- String fileNameNew = user.getLogin() + fileManager.getFileSeparator() +
image.getAlbumName() + fileManager.getFileSeparator() + prevPathEnd;
- String newPath = user.getLogin() + "/" + image.getAlbumName() +
"/" + prevPathEnd;
+ Album dropValue = treeMyAlbumsItem.getAlbumByName(image.getAlbumName()).getAlbum();
+ String fileNameNew = user.getLogin() + fileManager.getFileSeparator() +
dropValue.getAlbumPathFromParents(dropValue , new ArrayList<String>(),
fileManager.getFileSeparator()) + prevPathEnd;
+ String newPath = user.getLogin() + "/" +
albumItem.getAlbum().getAlbumPathFromParents(albumItem.getAlbum(), new
ArrayList<String>(), "/") + prevPathEnd;
image.setPath(newPath);
fileManager.renameImage(fileNameOld, fileNameNew);
- selectionHelper.setSelectedImage(imageItem.getImage());
- selectionHelper.setSelectedAlbum(albumItem.getAlbum());
- }else{
- TreeImageItem imageItem = (TreeImageItem)parent.getChild(image.getId());
- imageItem.setImage(image);
+ conversationState.setSelectedImage(image);
+ conversationState.setSelectedAlbum(albumItem.getAlbum());
}
imageAction.editImage(image, parentChanged);
}
-
+
@Observer("addImage")
public void addImage(Image image) {
+ if(!image.validateTags()){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(META_TAG_WRONG));
+ return;
+ }
imageAction.addImage(image);
- TreeAlbumItem albumItem = treeRoot.getAlbumByName(image.getAlbumName());
- TreeImageItem imageItem = new TreeImageItem(image.getId(),albumItem,image);
- albumItem.addChild(image.getId(), imageItem);
- selectionHelper.setSelectedImage(imageItem.getImage());
- selectionHelper.setSelectedAlbum(albumItem.getAlbum());
+ TreeAlbumItem albumItem = treeMyAlbumsItem.getAlbumByName(image.getAlbumName());
+ conversationState.setSelectedAlbum(albumItem.getAlbum());
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
}
-
public void editComment(Comment comment) {
imageAction.editComment(comment);
}
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -0,0 +1,152 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.realworld.manager;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.faces.event.ActionEvent;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.core.Events;
+import org.richfaces.realworld.domain.Message;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.navigation.NavigationEnum;
+import org.richfaces.realworld.service.IMessageAction;
+import org.richfaces.realworld.service.MessageAction;
+import org.richfaces.realworld.ui.History;
+
+@Name("messageManager")
+(a)Scope(ScopeType.CONVERSATION)
+public class MessageManager implements Serializable{
+
+ private static final long serialVersionUID = 2561824019376412988L;
+
+ private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
+
+ @In
+ private User user;
+
+ private Message message;
+
+ private Message messageForSend;
+
+ private Long countUnreadedMessages;
+
+ @In(create=true) @Out(required=false)
+ private History history;
+
+ @In(create=true) IMessageAction messageAction;
+ public void closeMessage(){
+ this.message = null;
+ this.messageForSend = null;
+ }
+
+ public void showHistory(User u){
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.READ_MESSAGES);
+ history.setSelected(true);
+ history.setHistoryUser(u);
+ }
+
+ public void initMessage(Message message, User owner, String theme, String content,
boolean isFrRequest){
+ if(message == null){
+ this.message = null;
+ }else{
+ this.message=message;
+ this.message.setReaded(true);
+ this.setCountUnreadedMessages(null);
+ }
+ if(owner == null){
+ this.messageForSend = null;
+ }else{
+ this.messageForSend = new Message();
+ this.messageForSend.setAuthor(user);
+ if(theme.startsWith("Re:")){
+ this.messageForSend.setTheme(theme + this.message.getTheme());
+ }else{
+ this.messageForSend.setTheme(theme);
+ }
+ this.messageForSend.setOwner(owner);
+ this.messageForSend.setMessage(content);
+ this.messageForSend.setFriendshipRequest(isFrRequest);
+ }
+ Events.instance().raiseEvent("updateMainArea",
NavigationEnum.READ_MESSAGES);
+ }
+
+ public void initMessage(){
+ this.message = null;
+ this.messageForSend = new Message();
+ this.messageForSend.setAuthor(user);
+ this.messageForSend.setFriendshipRequest(false);
+ }
+
+ public void sendMessage(){
+ this.messageForSend.setDate(new Date());
+ messageAction.sendMessage(this.message);
+ this.message = null;
+ this.messageForSend = null;
+ }
+
+ public void markAsReaded(Message message){
+ messageAction.markAsReaded(message);
+ this.setCountUnreadedMessages(null);
+ }
+
+ public void deleteMessage(Message message){
+ messageAction.deleteMessage(message);
+ this.setCountUnreadedMessages(null);
+ }
+
+ public Long getCountUnreadedMessages() {
+ if(null == countUnreadedMessages){
+ countUnreadedMessages = messageAction.countNotReadedMessages(user);
+ }
+ return countUnreadedMessages != null ? countUnreadedMessages : 0;
+ }
+
+ public void setCountUnreadedMessages(Long count){
+ countUnreadedMessages = null;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public Message getMessageForSend() {
+ return messageForSend;
+ }
+
+ public void setMessageForSend(Message messageForSend) {
+ this.messageForSend = messageForSend;
+ }
+
+ public void sendMessage(Message message) {
+ messageAction.sendMessage(message);
+ }
+}
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/MessageManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/manager/UserManager.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -23,28 +23,42 @@
import java.io.Serializable;
import java.util.Date;
import java.util.List;
+import java.util.Map;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
+import org.richfaces.component.UIDatascroller;
import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Comment;
import org.richfaces.realworld.domain.FriendshipRequest;
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.Message;
import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.navigation.NavigationEnum;
import org.richfaces.realworld.service.IMessageAction;
import org.richfaces.realworld.service.IUserAction;
-import org.richfaces.realworld.util.SelectionHelper;
+import org.richfaces.realworld.tree.TreeFriendItem;
+import org.richfaces.realworld.tree.TreeFriendsItem;
+import org.richfaces.realworld.ui.History;
+import org.richfaces.realworld.ui.ConversationState;
@Name("userManager")
@Scope(ScopeType.CONVERSATION)
public class UserManager implements Serializable{
+ private static final String FRIEND_ERROR_MESSAGE = "This user won't be your
friend!";
+ private static final String SLASH = "/";
+ private static final String HAVENT_ACCESS = "You have no rights to view this
album";
+ private static final String ADD_ERROR_EVENT = "addErrorEvent";
+ private static final String SEND_MESSAGE = "sendMessage";
+ private static final String CLEAR_EDITOR = "clearEditor";
@In("#{messages['addedtofriends']}") private String
ADDED_TO_FRIENDS_MESSAGE_THEME;
@In("#{messages['addedtofriendsby']}") private String
ADDED_TO_FRIENDS_MESSAGE;
@In("#{messages['removedfromfriends']}") private String
REMOVED_FROM_FRIENDS_MESSAGE_THEME;
@@ -53,43 +67,49 @@
private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
private static final long serialVersionUID = 6027103521084558931L;
+
+ private static final String DATASCROLLER_ID = "mainform:imageScroller";
+ @In(create=true, required=true)
+ private ImageManager imageManager;
+
@In
private User user;
- private Long countUnreadedMessages;
+ @In(required=false) @Out(required=false)
+ TreeFriendsItem treeFriendsItem;
@In(create=true, required=true)
- private IMessageAction messageAction;
-
- @In(create=true, required=true)
private IUserAction userAction;
@In(create=true) @Out
- private SelectionHelper selectionHelper;
+ private ConversationState conversationState;
public List<String> availableUserLogins(Object suggest){
List<String> suggestions = userAction.getUsers((String)suggest);
return suggestions;
}
- public void sendMessage(Message message) {
- messageAction.sendMessage(message);
+ public void showUserProfile(){
+ conversationState.setSelectedUser(user);
+ conversationState.setSecondSelectedUser(null);
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
}
-
- public Long getCountUnreadedMessages() {
- if(null == countUnreadedMessages){
- countUnreadedMessages = userAction.countNotReadedMessages(user);
- }
- return countUnreadedMessages != null ? countUnreadedMessages : 0;
+
+ public void showUserProfile(User user){
+ conversationState.setSelectedUser(user);
+ conversationState.setSecondSelectedUser(null);
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
}
- public void setCountUnreadedMessages(Long count){
- countUnreadedMessages = null;
+ public void showSecondUserProfile(User user){
+ conversationState.setSecondSelectedUser(user);
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.USER_PREFS);
}
-
+
public void removeFromFriends(User owner, User removed){
userAction.removeFromFriends(owner, removed);
+ treeFriendsItem.removeChild(removed.getId());
Message message = new Message();
message.setAuthor(user);
message.setDate(new Date());
@@ -98,7 +118,7 @@
message.setReaded(false);
message.setMessage(YOU_ARE_WERE_REMOVED_FROM_FRIENDS_MESSAGE+ user.getLogin());
message.setTheme(REMOVED_FROM_FRIENDS_MESSAGE_THEME);
- messageAction.sendMessage(message);
+ Events.instance().raiseEvent(SEND_MESSAGE, message);
}
public void addToFriends(User friend){
@@ -106,6 +126,8 @@
if(request != null){
if(!userAction.friendExist(user, friend)){
userAction.addFriend(user, friend, request);
+ TreeFriendItem friendItem = new TreeFriendItem(friend.getId(), treeFriendsItem,
friend);
+ treeFriendsItem.addChild(friend.getId(), friendItem );
Message message = new Message();
message.setAuthor(user);
message.setDate(new Date());
@@ -114,36 +136,106 @@
message.setReaded(false);
message.setMessage(ADDED_TO_FRIENDS_MESSAGE+ user.getLogin());
message.setTheme(ADDED_TO_FRIENDS_MESSAGE_THEME);
- messageAction.sendMessage(message);
+ Events.instance().raiseEvent(SEND_MESSAGE, message);
}
- }/*else{
- throw new Exception("This user won't be your friend!");
- }*/
+ }else{
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(FRIEND_ERROR_MESSAGE));
+ return;
+ }
}
+ public void addComment(Image image, String message){
+ Comment comment= new Comment();
+ comment.setAuthor(user);
+ comment.setImage(image);
+ comment.setDate(new Date());
+ comment.setMessage(message);
+ imageManager.addComment(comment);
+ Events.instance().raiseEvent(CLEAR_EDITOR, "");
+ }
- public void addToSharedAlbums(Image image){
- userAction.addSharedAlbum(image.getAlbum());
+ public void addToFavoriteAlbums(Album album){
+ userAction.addFavoriteAlbum(album);
}
- public void removeFromSharedAlbums(Album album){
- userAction.removeFromSharedAlbums(user, album);
+ public void removeFromFavoriteAlbums(Album album){
+ userAction.removeFromFavoriteAlbums(user, album);
}
+
+ public void addToFavoriteImages(Image image){
+ userAction.addFavoriteImage(image);
+ }
+
+ public void removeFromFavoriteImages(Image image){
+ userAction.removeFromFavoriteImages(user, image);
+ }
- public void showSharedAlbum(Image image){
+ public void showImage(Image image){
+ if(!image.getAlbum().isShared() && !image.getAlbum().getOwner().equals(user)
&& !user.getFriends().contains(image.getAlbum().getOwner())){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(HAVENT_ACCESS));
+ return;
+ }
Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
- selectionHelper.setSelectedAlbum(image.getAlbum());
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(0));
- selectionHelper.setSelectedImageIndex(1);
- selectionHelper.setUserAlbumSelected(false);
+ conversationState.setSelectedAlbum(image.getAlbum());
+ conversationState.setSelectedImage(image);
+ setDataScrollerIndex(image.getAlbum().getIndex(image));
+ conversationState.setSelectedUser(image.getAlbum().getOwner());
}
- public void markAsReaded(Message message){
- messageAction.markAsReaded(message);
- this.setCountUnreadedMessages(null);
+ public void showUser(User u){
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(u);
}
- public void deleteMessage(Message message){
- messageAction.deleteMessage(message);
- this.setCountUnreadedMessages(null);
+ private void setDataScrollerIndex(int index) {
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+1);
+ conversationState.setSelectedImageIndex(index+1);
}
+
+ public void showAlbum(Album album){
+ if(!album.isShared() && !album.getOwner().equals(user) &&
!user.getFriends().contains(album.getOwner())){
+ Events.instance().raiseEvent(ADD_ERROR_EVENT, new Exception(HAVENT_ACCESS));
+ return;
+ }
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ conversationState.setSelectedAlbum(album);
+ conversationState.setSelectedUser(album.getOwner());
+ }
+
+ public List<Album> getRootAlbums(User user2) {
+ return userAction.getRootAlbums(user2);
+ }
+
+ public void selectMyAlbums(){
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(user);
+ }
+
+ public void selectMyFriends(){
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(null);
+ }
+
+ public void selectUser(User u){
+ conversationState.setSelectedAlbum(null);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(u);
+ }
+
+ public void selectAlbum(Album a){
+ conversationState.setSelectedAlbum(a);
+ conversationState.setSelectedImage(null);
+ conversationState.setSelectedUser(a.getOwner());
+ }
+
+ public String getPathOfImage(String path){
+ int i = path.lastIndexOf(SLASH);
+ return path.substring(i);
+ }
}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/search/SearchBean.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -28,17 +28,12 @@
import java.util.Map;
import javax.faces.model.SelectItem;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Image;
-import org.richfaces.realworld.domain.User;
-import org.richfaces.realworld.error.ErrorHandler;
import org.richfaces.realworld.service.ISearchService;
import org.richfaces.realworld.service.SearchService;
@@ -50,8 +45,6 @@
@In("#{messages['less']}") private String LESS_CHOICE;
@In("#{messages['more']}") private String MORE_CHOICE;
@In("#{messages['nomatter']}") private String NO_MATTER_CHOICE;
-
- private boolean collapsed;
private static final String EQUALS = "= ";
@@ -209,10 +202,6 @@
map.put(SearchService.CASE_SENSITIVE_PARAMETER, caseSensitive);
return map;
}
-
- public void collapse(){
- this.setCollapsed(!collapsed);
- }
private String populateAdditionalParams() {
StringBuilder additionalParams = new StringBuilder("");
@@ -409,14 +398,6 @@
this.heightChoice = heightChoice;
}
- public boolean isCollapsed() {
- return collapsed;
- }
-
- public void setCollapsed(boolean collapsed) {
- this.collapsed = collapsed;
- }
-
public boolean isCaseSensitive() {
return caseSensitive;
}
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/FileHelper.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -1,63 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.servlet;
-
-import java.io.File;
-
-public class FileHelper {
-
- private static final String FILE_SEPARATOR = "file.separator";
- private String uploadRoot;
-
- public String getUploadRoot() {
- return uploadRoot;
- }
-
- public void setUploadRoot(String uploadRoot) {
- this.uploadRoot = uploadRoot;
- }
-
- public FileHelper(String uploadRoot){
- this.setUploadRoot(uploadRoot);
- }
-
- public String getFileSeparator() {
- return System.getProperty(FILE_SEPARATOR);
- }
-
- public boolean isImagePresent(String fileName) {
- String fullPath = getAbsolutePath(fileName);
- File file = new File(fullPath);
- return file.exists() && !file.isDirectory();
- }
-
- public File getImage(String fileName){
- if(isImagePresent(fileName)){
- return new File(getAbsolutePath(fileName));
- }
- return null;
- }
-
- private String getAbsolutePath(String fileName) {
- return getUploadRoot() + fileName;
- }
-
-}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/servlet/PictureServlet.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -6,37 +6,59 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Date;
+import java.util.Map;
+import javax.persistence.EntityManager;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import com.drew.imaging.jpeg.JpegMetadataReader;
-import com.drew.imaging.jpeg.JpegProcessingException;
-import com.drew.metadata.Directory;
-import com.drew.metadata.Metadata;
-import com.drew.metadata.MetadataException;
-import com.drew.metadata.exif.ExifDirectory;
+import org.jboss.seam.Component;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.fileupload.FileManager;
public class PictureServlet extends javax.servlet.http.HttpServlet {
public static final long serialVersionUID = 596009789004L;
- private static final String UPLOAD_ROOT = "uploadRoot";
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String pathInfo = request.getPathInfo();
String fileName = WebUtil.getFileName(pathInfo);
+ Map req = request.getParameterMap();
+ String userId = request.getParameter("userId");
+ EntityManager em = (EntityManager)Component.getInstance("entityManager",
true);
+ FileManager fileManager = (FileManager)Component.getInstance("fileManager",
true);
+ User user = null;
+ if(userId != null){
+ user = em.find(User.class, Long.valueOf(userId));
+ }
+ Image i = (Image)em.createQuery("from Image i where
i.path=:path").setParameter("path",
pathInfo.substring(1)).getSingleResult();
+ if(!i.getAlbum().isShared()){
+ if(user != null){
+ if(i.getAlbum().getOwner().equals(user) ||
user.getFriends().contains(i.getAlbum().getOwner())){
+ //OK
+ }else{
+ String contextPath = request.getContextPath();
+ response.sendRedirect(contextPath + "/error.seam");
+ return;
+ }
+ }else{
+ String contextPath = request.getContextPath();
+ response.sendRedirect(contextPath + "/error.seam");
+ return;
+ }
+ }
if (fileName == null) {
String contextPath = request.getContextPath();
response.sendRedirect(contextPath + "/error.seam");
return;
}
ServletContext context = getServletContext();
- FileHelper helper = new FileHelper(context.getInitParameter(UPLOAD_ROOT));
- File file = helper.getImage(fileName);
+ //FileHelper helper = new FileHelper(context.getInitParameter(UPLOAD_ROOT));
+ File file = fileManager.getImage(fileName);
/*try {
Metadata metadata = JpegMetadataReader.readMetadata(file);
Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/slideshow/SlideshowBean.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -27,8 +27,7 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
-import org.richfaces.realworld.error.ErrorHandler;
-import org.richfaces.realworld.tree.TreeSelectionManager;
+import org.richfaces.realworld.tree.TreeManager;
@Name("slideshow")
@Scope(ScopeType.CONVERSATION)
@@ -43,9 +42,6 @@
@In(required=false) @Out(required=false)
SlideshowHelper slideshowHelper;
- @In
- TreeSelectionManager treeSelectionManager;
-
private boolean active;
private int interval = INITIAL_DELAY;
@@ -77,8 +73,4 @@
public void updateInterval(){
this.setInterval((int)(DELAY *
Long.valueOf(slideshowHelper.getInputSlider().getValue().toString())));
}
- @ErrorHandler
- public void incrementSlide() {
- treeSelectionManager.incrementSlideshowIndex();
- }
}
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeAlbumItem.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -26,52 +26,60 @@
import java.util.List;
import java.util.Map;
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Events;
import org.richfaces.model.TreeNode;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.manager.AlbumManager;
+import org.richfaces.realworld.manager.UserManager;
public class TreeAlbumItem implements TreeNode {
private static final String ALBUM_NODE_TYPE = "album";
-
+ TreeMyAlbumsItem treeMyAlbumsItem;
private static final long serialVersionUID = 6514596192023597908L;
private long id;
- private Map<Object, TreeNode> images = new LinkedHashMap<Object,
TreeNode>();
+ private Map<Object, TreeNode> childs = new LinkedHashMap<Object,
TreeNode>();
private Album album;
TreeNode parent;
- public TreeAlbumItem(long id, TreeRootItem parent, Album album) {
+ public TreeAlbumItem(long id, TreeNode parent, Album album, TreeMyAlbumsItem
treeMyAlbumsItem) {
this.id = id;
this.parent = parent;
this.album = album;
- for(Image image:album.getImages()){
- TreeImageItem node = new TreeImageItem(image.getId(), this, image);
- addImage(node);
+ this.treeMyAlbumsItem = treeMyAlbumsItem;
+ for(Album alb:album.getChildAlbums()){
+ TreeAlbumItem node = new TreeAlbumItem(alb.getId(), this, alb ,
this.treeMyAlbumsItem);
+ addAlbum(node);
}
}
- public void addImage(TreeImageItem image) {
- addChild(image.getId(), image);
- image.setParent(this);
+ public void addAlbum(TreeAlbumItem alb) {
+ addChild(alb.getId(), alb);
+ alb.setParent(this);
}
public void addChild(Object identifier, TreeNode child) {
- images.put(identifier, child);
+ childs.put(identifier, child);
}
public TreeNode getChild(Object id) {
- return (TreeNode) images.get(id);
+ return (TreeNode) childs.get(id);
}
public Iterator<Map.Entry<Object, TreeNode>> getChildren() {
- return images.entrySet().iterator();
+ return childs.entrySet().iterator();
}
- public List<TreeNode> getImages() {
- List<TreeNode> imageCollection = new ArrayList<TreeNode>();
- imageCollection.addAll(images.values());
- return imageCollection;
+ public List<TreeNode> getAlbums() {
+ List<TreeNode> childCollection = new ArrayList<TreeNode>();
+ childCollection.addAll(childs.values());
+ return childCollection;
}
public Object getData() {
@@ -83,11 +91,11 @@
}
public boolean isLeaf() {
- return images.isEmpty();
+ return childs.isEmpty();
}
public void removeChild(Object id) {
- images.remove(id);
+ childs.remove(id);
}
public void setData(Object data) {
@@ -102,6 +110,9 @@
}
public Album getAlbum() {
+ if(album == null){
+ System.out.println();
+ }
return album;
}
@@ -116,4 +127,42 @@
public String toString(){
return this.getAlbum().getName();
}
+
+ public boolean containAlbum(Album selectedAlbum) {
+ for(TreeNode item : this.childs.values()){
+ TreeAlbumItem node = (TreeAlbumItem)item;
+ if(node.getAlbum().equals(selectedAlbum)){
+ return true;
+ }
+ if(node.getAlbums().size() > 0){
+ for(TreeNode a : node.getAlbums()){
+ TreeAlbumItem temp = (TreeAlbumItem)a;
+ return temp.containAlbum(selectedAlbum);
+ }
+ }
+ }
+ return false;
+ }
+
+ public List<SelectItem> getArrayOfChildsAlbumsNames() {
+ List<SelectItem> items = new ArrayList<SelectItem>();
+ for(TreeNode item: this.getAlbums()){
+ TreeAlbumItem a = (TreeAlbumItem)item;
+ String pathFromParents = a.getAlbum().getAlbumPathFromParents(a.getAlbum(), new
ArrayList<String>(), "/");
+ SelectItem e = new SelectItem(pathFromParents);
+ items.add(e);
+ a.getArrayOfChildsAlbumsNames(items);
+ }
+ return items;
+ }
+
+ public void getArrayOfChildsAlbumsNames(List<SelectItem> list) {
+ for(TreeNode item: this.getAlbums()){
+ TreeAlbumItem a = (TreeAlbumItem)item;
+ String pathFromParents = this.getAlbum().getAlbumPathFromParents(this.getAlbum(), new
ArrayList<String>(), "/");
+ SelectItem e = new SelectItem(pathFromParents);
+ list.add(e);
+ a.getArrayOfChildsAlbumsNames(list);
+ }
+ }
}
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -0,0 +1,116 @@
+package org.richfaces.realworld.tree;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.manager.UserManager;
+import org.richfaces.realworld.service.IUserAction;
+
+@Name("treeFriendAlbum")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeFriendItem implements TreeNode{
+
+ private static final String TYPE = "treeFriendAlbum";
+
+ private long id;
+
+ private User friend;
+
+ public TreeFriendItem(long id, TreeNode parent, User friend){
+ this.id = id;
+ this.parent = parent;
+ this.friend = friend;
+ }
+
+ public UserManager getUserManager() {
+ return (UserManager) Contexts.getConversationContext().get("userManager");
+ }
+
+ private TreeNode parent;
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeAlbumItem> albums = null;
+
+ public Map<Long, TreeAlbumItem> getAlbums() {
+ if (this.albums==null) {
+ initData();
+ }
+ return this.albums;
+ }
+
+ public void addChild(Object identifier, TreeNode child) {
+ getAlbums().put((Long)identifier, (TreeAlbumItem)child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return (TreeNode) albums.get(id);
+ }
+
+ public Iterator getChildren() {
+ return getAlbums().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public boolean isLeaf() {
+ return getAlbums().isEmpty();
+ }
+
+ public void removeChild(Object id) {
+ albums.remove(id);
+ }
+
+ public void setData(Object data) {
+ this.friend = (User)data;
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ public String getType() {
+ return TYPE;
+ }
+
+ private void initData() {
+ albums = new HashMap<Long, TreeAlbumItem>();
+ for(Album a: getUserManager().getRootAlbums(friend)){
+ TreeAlbumItem item = new TreeAlbumItem(a.getId(), this, a, null);
+ albums.put(item.getId(), item);
+ }
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public User getFriend() {
+ return friend;
+ }
+
+ public void setFriend(User friend) {
+ this.friend = friend;
+ }
+}
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -0,0 +1,114 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.realworld.tree;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.IUserAction;
+
+@Name("treeFriendRoot")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeFriendRootItem implements TreeNode {
+
+ @In(create=true, required=true)
+ IUserAction userAction;
+
+ private static final String TREE_ROOT_NODE_TYPE = "treeRootFriend";
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeNode> childs;
+
+ public void addChild(Object identifier, TreeNode child) {
+ getChilds().put((Long)identifier, child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return getChilds().get(id);
+ }
+
+ public Iterator getChildren() {
+ return getChilds().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return null;
+ }
+
+ public boolean isLeaf() {
+ return false;
+ }
+
+ public void removeChild(Object id) {
+ getChilds().remove(id);
+ }
+
+ public void setData(Object data) {
+ }
+
+ public void setParent(TreeNode parent) {
+ }
+
+ public String getType() {
+ return TREE_ROOT_NODE_TYPE;
+ }
+
+ public Map<Long, TreeNode> getChilds() {
+ if (this.childs==null) {
+ initialise();
+ }
+ return this.childs;
+ }
+
+ private void initialise() {
+ childs = new HashMap<Long, TreeNode>();
+ //TreeMyAlbumsItem item = new TreeMyAlbumsItem(1L, this);
+ //childs.put(item.getId(), item);
+ TreeFriendsItem friendsItem = new TreeFriendsItem(2L, this);
+ childs.put(friendsItem.getId(), friendsItem);
+ //Contexts.getConversationContext().set("treeMyAlbumsItem", item);
+ Contexts.getConversationContext().set("treeFriendsItem", friendsItem);
+ }
+
+ public void setChilds(Map<Long, TreeNode> childs) {
+ this.childs = childs;
+ }
+}
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendRootItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -0,0 +1,115 @@
+package org.richfaces.realworld.tree;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.IUserAction;
+@Name("treeFriendsAlbums")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeFriendsItem implements TreeNode{
+
+ private static final String TYPE = "treeFriendsAlbums";
+
+ private long id;
+
+ private User user;
+
+ public TreeFriendsItem(long id, TreeNode parent){
+ this.id = id;
+ this.parent = parent;
+ }
+
+ private TreeNode parent;
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeFriendItem> friends = null;
+
+ public Map<Long, TreeFriendItem> getFriends() {
+ if (this.friends==null) {
+ initData();
+ }
+ return this.friends;
+ }
+
+ public void addAlbumToTree(TreeFriendItem friend) {
+ addChild(friend.getId(), friend);
+ }
+
+ public void addChild(Object identifier, TreeNode child) {
+ getFriends().put((Long)identifier, (TreeFriendItem)child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return (TreeNode) friends.get(id);
+ }
+
+ public Iterator getChildren() {
+ return getFriends().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public boolean isLeaf() {
+ return getFriends().isEmpty();
+ }
+
+ public void removeChild(Object id) {
+ friends.remove(id);
+ }
+
+ public void setData(Object data) {
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ public String getType() {
+ return TYPE;
+ }
+
+ private void initData() {
+ friends = new HashMap<Long, TreeFriendItem>();
+ if(null == getUser().getFriends()){
+ return;
+ }
+ for(User u: getUser().getFriends()){
+ TreeFriendItem item = new TreeFriendItem(u.getId(), this, u);
+ friends.put(item.getId(), item);
+ }
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public User getUser() {
+ return (User) Contexts.getConversationContext().get("user");
+ }
+}
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeFriendsItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeImageItem.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -1,94 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.tree;
-
-import java.util.Iterator;
-
-import org.richfaces.model.TreeNode;
-import org.richfaces.realworld.domain.Image;
-
-public class TreeImageItem implements TreeNode {
-
- private static final String IMAGE_NODE_TYPE = "image";
- private static final long serialVersionUID = 6514596192023597908L;
- private long id;
- private Image image;
-
- private TreeAlbumItem album;
-
- public TreeImageItem(long id, TreeAlbumItem album, Image image) {
- this.id = id;
- this.album = album;
- this.image = image;
- }
-
- public void addChild(Object identifier, TreeNode child) {
-
- }
-
- public TreeNode getChild(Object id) {
- return null;
- }
-
- public Iterator getChildren() {
- return null;
- }
-
- public Object getData() {
- return this;
- }
-
- public TreeNode getParent() {
- return album;
- }
-
- public boolean isLeaf() {
- return true;
- }
-
- public void removeChild(Object id) {
-
- }
-
- public void setData(Object data) {
- }
-
- public void setParent(TreeNode parent) {
- this.album = (TreeAlbumItem) parent;
- }
-
- public long getId() {
- return id;
- }
-
- public String getType() {
- return IMAGE_NODE_TYPE;
- }
-
- public Image getImage() {
- return image;
- }
-
- public void setImage(Image image) {
- this.image = image;
- }
-
-}
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -0,0 +1,246 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.realworld.tree;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.model.SelectItem;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
+import org.jboss.seam.annotations.Out;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Synchronized;
+import org.jboss.seam.core.Events;
+import org.richfaces.component.UIDatascroller;
+import org.richfaces.component.UITree;
+import org.richfaces.component.html.HtmlTree;
+import org.richfaces.event.DataScrollerEvent;
+import org.richfaces.event.NodeSelectedEvent;
+import org.richfaces.model.TreeNode;
+import org.richfaces.model.TreeRowKey;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.fileupload.FileManager;
+import org.richfaces.realworld.manager.ImageManager;
+import org.richfaces.realworld.navigation.NavigationEnum;
+import org.richfaces.realworld.ui.ConversationState;
+
+@Name("treeManager")
+(a)Scope(ScopeType.CONVERSATION)
+@Synchronized(timeout=200000)
+public class TreeManager implements Serializable{
+
+ private static final String DATASCROLLER_ID = "mainform:imageScroller";
+
+ private static final String IMAGE_DATATABLE_ID = "mainform:mainImage";
+
+ private static final String FIRST = "first";
+
+ private static final String NEXT = "next";
+
+ private static final String LAST = "last";
+
+ private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
+
+ private static final String PREVIOUS = "previous";
+
+ private static final long serialVersionUID = -6072049677194472463L;
+
+ private NavigationEnum mainArea;
+
+ @In(required=false) @Out(required=false)
+ private ConversationState conversationState;
+
+ @In(create=true)
+ FileManager fileManager;
+
+ @In User user;
+
+ @In(required=false)
+ ImageManager imageManager;
+
+ public void showFileUpload(TreeAlbumItem item, boolean singleMode){
+ String i;
+ if(singleMode){
+ i="single";
+ }else{
+ i="multy";
+ }
+ Events.instance().raiseEvent("changeMode", i);
+ Events.instance().raiseEvent("fileUploadClear");
+ conversationState.setSelectedAlbum(item.getAlbum());
+ this.setMainArea(NavigationEnum.FILE_UPLOAD);
+ }
+
+ public void showFileUpload(Album item, boolean singleMode){
+ String i;
+ if(singleMode){
+ i="single";
+ }else{
+ i="multy";
+ }
+ Events.instance().raiseEvent("changeMode", i);
+ Events.instance().raiseEvent("fileUploadClear");
+ conversationState.setSelectedAlbum(item);
+ this.setMainArea(NavigationEnum.FILE_UPLOAD);
+ }
+
+ public void scrollerListener(DataScrollerEvent event) {
+ List<Image> images = conversationState.getSelectedAlbum().getImages();
+ if (event.getNewScrolVal().equals(PREVIOUS)) {
+ for(int index = 0 ; index < images.size(); index++){
+ if(images.get(index) == conversationState.getSelectedImage()){
+ conversationState.setSelectedImage(images.get(index - 1));
+ conversationState.setSelectedImageIndex(index);
+ }
+ }
+ } else if (event.getNewScrolVal().equals(LAST)) {
+ conversationState.setSelectedImage(images.get(images.size() - 1));
+ conversationState.setSelectedImageIndex(images.size());
+ } else if (event.getNewScrolVal().equals(NEXT)) {
+ for(int index = 0 ; index < images.size(); index++){
+ if(images.get(index) == conversationState.getSelectedImage()){
+ conversationState.setSelectedImage(images.get(index + 1));
+ conversationState.setSelectedImageIndex(index + 2);
+ return;
+ }
+ }
+ } else if (event.getNewScrolVal().equals(FIRST)) {
+ conversationState.setSelectedImage(images.get(0));
+ conversationState.setSelectedImageIndex(1);
+ }
+
+ }
+
+ public Boolean adviseNodeSelected(UITree tree) {
+ TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
+ TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
+ if (treeNode instanceof TreeAlbumItem) {
+ TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
+ boolean selected = currentNode.getAlbum() == conversationState.getSelectedAlbum() ||
currentNode.containAlbum(conversationState.getSelectedAlbum());
+ return selected;
+ }
+ return null;
+ }
+
+ public Boolean adviseNodeOpened(UITree tree) {
+ TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
+ TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
+ if (treeNode instanceof TreeAlbumItem) {
+ TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
+ boolean selected = currentNode.getAlbum() == conversationState.getSelectedAlbum() ||
currentNode.containAlbum(conversationState.getSelectedAlbum());
+ return selected;
+ }
+ return null;
+ }
+
+ public void processSelection(NodeSelectedEvent event) {
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ HtmlTree tree = (HtmlTree) event.getComponent();
+ TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
+ if(currentNode instanceof TreeAlbumItem){
+ TreeAlbumItem node = (TreeAlbumItem)currentNode;
+ Album album = node.getAlbum();
+ conversationState.setSelectedAlbum(album);
+ }else if(currentNode instanceof TreeMyAlbumsItem){
+ conversationState.setSelectedAlbum(null);
+ }
+ conversationState.setSelectedUser(user);
+ conversationState.setSelectedImage(null);
+ }
+
+ public void processSelectionFriends(NodeSelectedEvent event) {
+ Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
+ HtmlTree tree = (HtmlTree) event.getComponent();
+ TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
+ if(currentNode instanceof TreeAlbumItem){
+ TreeAlbumItem node = (TreeAlbumItem)currentNode;
+ conversationState.setSelectedUser(((TreeAlbumItem)currentNode).getAlbum().getOwner());
+ Album album = node.getAlbum();
+ conversationState.setSelectedAlbum(album);
+ }else if(currentNode instanceof TreeFriendsItem){
+ conversationState.setSelectedUser(null);
+ conversationState.setSelectedAlbum(null);
+ }else if(currentNode instanceof TreeFriendItem){
+ conversationState.setSelectedUser(((TreeFriendItem)currentNode).getFriend());
+ conversationState.setSelectedAlbum(null);
+ }
+ conversationState.setSelectedImage(null);
+ }
+
+ private void setDataScrollerIndex(int index) {
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+1);
+ conversationState.setSelectedImageIndex(index+1);
+ }
+
+
+ public void incrementSlideshowIndex() {
+ int index =
conversationState.getSelectedAlbum().getIndex(conversationState.getSelectedImage());
+ if(conversationState.getSelectedAlbum().getImages().size() == index +1){
+ index = -1;
+ }
+ conversationState.setSelectedImage(conversationState.getSelectedAlbum().getImages().get(index
+1));
+ UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+ UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
+ Map<String, Object> attributes = scroller.getDataTable().getAttributes();
+ attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+2);
+ conversationState.setSelectedImageIndex(index+2);
+ }
+
+ public NavigationEnum getMainArea() {
+ return mainArea;
+ }
+
+ @Observer("updateMainArea")
+ public void setMainArea(NavigationEnum mainArea) {
+ this.mainArea = mainArea;
+ if(mainArea.equals(NavigationEnum.FILE_UPLOAD)){
+ Events.instance().raiseEvent("showFileUpload", true);
+ }
+ }
+
+ public SelectItem[] getAvailableIndexOfImages(){
+ SelectItem[] group = new
SelectItem[conversationState.getSelectedAlbum().getImages().size()];
+ for(int i = 0; i < conversationState.getSelectedAlbum().getImages().size(); i++){
+ group[i] = new SelectItem(i+1);
+ }
+ return group;
+ }
+
+ public void updateSelectedItems(Image image){
+ conversationState.setSelectedImage(image);
+ Integer index =
conversationState.getSelectedAlbum().getIndex(conversationState.getSelectedImage());
+ setDataScrollerIndex(index);
+ }
+}
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java
(rev 0)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -0,0 +1,231 @@
+package org.richfaces.realworld.tree;
+
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.model.SelectItem;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.richfaces.model.TreeNode;
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.manager.UserManager;
+
+@Name("treeMyAlbumsItem")
+(a)Scope(ScopeType.CONVERSATION)
+public class TreeMyAlbumsItem implements TreeNode {
+
+ private static final String TYPE = "treeMyAlbums";
+
+ private long id;
+
+ UserManager userManager;
+
+ public TreeMyAlbumsItem(){
+
+ }
+ public TreeMyAlbumsItem(long id, TreeNode parent){
+ this.id = id;
+ this.parent = parent;
+ }
+
+ private List<SelectItem> availableAlbums;
+
+ private TreeNode parent;
+
+ private static final long serialVersionUID = -3530085227471752526L;
+
+ private Map<Long, TreeAlbumItem> albums = null;
+
+ public Map<Long, TreeAlbumItem> getAlbums() {
+ if (this.albums==null) {
+ initData();
+ }
+ return this.albums;
+ }
+
+ public void addAlbumToTree(TreeNode parent, TreeAlbumItem album) {
+ parent.addChild(album.getId(), album);
+ }
+
+ public void addChild(Object identifier, TreeNode child) {
+ getAlbums().put((Long)identifier, (TreeAlbumItem)child);
+ child.setParent(this);
+ }
+
+ public TreeNode getChild(Object id) {
+ return (TreeNode) albums.get(id);
+ }
+
+ public Iterator getChildren() {
+ return getAlbums().entrySet().iterator();
+ }
+
+ public Object getData() {
+ return this;
+ }
+
+ public TreeNode getParent() {
+ return parent;
+ }
+
+ public boolean isLeaf() {
+ return getAlbums().isEmpty();
+ }
+
+ public void removeChild(Object id) {
+ albums.remove(id);
+ }
+
+ public void setData(Object data) {
+ }
+
+ public void setParent(TreeNode parent) {
+ this.parent = parent;
+ }
+
+ public String getType() {
+ return TYPE;
+ }
+
+ private void initData() {
+ transformAlbumsToMap();
+ }
+
+ private void transformAlbumsToMap() {
+ albums = new HashMap<Long, TreeAlbumItem>();
+ availableAlbums = new ArrayList<SelectItem>();
+ for(Album album:getUserManager().getRootAlbums(getUser())){
+ TreeAlbumItem albumNode = new TreeAlbumItem(album.getId(), this, album, this);
+ availableAlbums.add(new SelectItem(album.getName()+"/"));
+ addAlbumToTree(this, albumNode);
+ }
+ }
+
+ public void updateChild(Album album) {
+ TreeAlbumItem albumItem = getAlbums().get(album.getId());
+ albumItem.setAlbum(album);
+ }
+
+ public SelectItem getSelectItemByName(String name) {
+ for(SelectItem item : availableAlbums){
+ if(item.getValue().toString().equals(name)){
+ return item;
+ }
+ }
+ return null;
+ }
+
+ public TreeAlbumItem getAlbumByName(String albumName) {
+ Object album = getParentItem(albumName);
+ return album != null ? (TreeAlbumItem)album : null;
+ }
+
+ public TreeNode getParentItem(String albumName){
+ for(Map.Entry<Long, TreeAlbumItem> entry : getAlbums().entrySet()){
+ if(entry.getValue().getAlbum().getName().equals(albumName)){
+ return entry.getValue();
+ }else{
+ if(entry.getValue() instanceof TreeAlbumItem){
+ TreeAlbumItem value = (TreeAlbumItem)entry.getValue();
+ if(value.getAlbums().size() >0){
+ TreeNode parentItem = getParentItem(value, albumName);
+ if(parentItem != null){
+ return parentItem;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public TreeNode getParentItem(TreeAlbumItem item, String albumName){
+ for(TreeNode entry : item.getAlbums()){
+ if(((TreeAlbumItem)entry).getAlbum().getName().equals(albumName)){
+ return (TreeAlbumItem)entry;
+ }else{
+ if(((TreeAlbumItem)entry).getAlbums().size() >0){
+ getParentItem((TreeAlbumItem)entry, albumName);
+ }
+ }
+ }
+ return null;
+ }
+
+ public List<SelectItem> getAvailableAlbums() {
+ List<SelectItem> availableAlbums = new ArrayList<SelectItem>();
+ for(TreeAlbumItem item :this.getAlbums().values()){
+ SelectItem e = new SelectItem(item.getAlbum().getName() + "/");
+ availableAlbums.add(e);
+ List<SelectItem> availableChildAlbums = item.getArrayOfChildsAlbumsNames();
+ availableAlbums.addAll(availableChildAlbums);
+ }
+ return availableAlbums;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public User getUser() {
+ return (User) Contexts.getConversationContext().get("user");
+ }
+
+ public String getAlbumPathFromParents(Album album2, List<String> list, String
delimiter) {
+ if(album2.getParent() == null){
+ list.add(album2.getName() + delimiter);
+ return "";
+ }else{
+ getAlbumPathFromParents(album2.getParent(), list, delimiter);
+ }
+ list.add(album2.getName()+delimiter);
+ String path = "";
+ for(int i =0; i < list.size(); i++){
+ path += list.get(i);
+ }
+ return path;
+}
+
+ public UserManager getUserManager() {
+ UserManager userManager2 = (UserManager)
Contexts.getConversationContext().get("userManager");
+ if(userManager2 != null){
+ return userManager2;
+ }
+ else return (UserManager)Component.getInstance("userManager", true);
+ }
+}
+
Property changes on:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeMyAlbumsItem.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeRootItem.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -33,47 +33,36 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
import org.richfaces.model.TreeNode;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.User;
+import org.richfaces.realworld.service.IUserAction;
@Name("treeRoot")
@Scope(ScopeType.CONVERSATION)
public class TreeRootItem implements TreeNode {
+ @In(create=true, required=true)
+ IUserAction userAction;
+
private static final String TREE_ROOT_NODE_TYPE = "treeRoot";
-
- @In @Out
- private User user;
- private List<SelectItem> availableAlbums;
-
private static final long serialVersionUID = -3530085227471752526L;
- private Map<Long, TreeAlbumItem> albums = null;
-
- public Map<Long, TreeAlbumItem> getAlbums() {
- if (this.albums==null) {
- initData();
- }
- return this.albums;
- }
+ private Map<Long, TreeNode> childs;
- public void addAlbumToTree(TreeAlbumItem album) {
- addChild(album.getId(), album);
- }
-
public void addChild(Object identifier, TreeNode child) {
- getAlbums().put((Long)identifier, (TreeAlbumItem)child);
+ getChilds().put((Long)identifier, child);
child.setParent(this);
}
public TreeNode getChild(Object id) {
- return (TreeNode) albums.get(id);
+ return getChilds().get(id);
}
public Iterator getChildren() {
- return getAlbums().entrySet().iterator();
+ return getChilds().entrySet().iterator();
}
public Object getData() {
@@ -85,11 +74,11 @@
}
public boolean isLeaf() {
- return getAlbums().isEmpty();
+ return false;
}
public void removeChild(Object id) {
- albums.remove(id);
+ getChilds().remove(id);
}
public void setData(Object data) {
@@ -101,45 +90,22 @@
public String getType() {
return TREE_ROOT_NODE_TYPE;
}
-
- private void initData() {
- transformAlbumsToMap();
- }
- private void transformAlbumsToMap() {
- albums = new HashMap<Long, TreeAlbumItem>();
- availableAlbums = new ArrayList<SelectItem>();
- for(Album album:user.getChildAlbums()){
- TreeAlbumItem albumNode = new TreeAlbumItem(album.getId(), this, album);
- availableAlbums.add(new SelectItem(album.getName()));
- addAlbumToTree(albumNode);
+ public Map<Long, TreeNode> getChilds() {
+ if (this.childs==null) {
+ initialise();
}
+ return this.childs;
}
-
- public void updateChild(Album album) {
- TreeAlbumItem albumItem = getAlbums().get(album.getId());
- albumItem.setAlbum(album);
- }
-
- public SelectItem getSelectItemByName(String name) {
- for(SelectItem item : availableAlbums){
- if(item.getValue().toString().equals(name)){
- return item;
- }
- }
- return null;
+
+ private void initialise() {
+ childs = new HashMap<Long, TreeNode>();
+ TreeMyAlbumsItem item = new TreeMyAlbumsItem(1L, this);
+ childs.put(item.getId(), item);
+ Contexts.getConversationContext().set("treeMyAlbumsItem", item);
}
-
- public TreeAlbumItem getAlbumByName(String albumName) {
- for(Map.Entry<Long, TreeAlbumItem> entry : getAlbums().entrySet()){
- if(entry.getValue().getAlbum().getName().equals(albumName)){
- return entry.getValue();
- }
- }
- return null;
- }
- public List<SelectItem> getAvailableAlbums() {
- return availableAlbums;
+ public void setChilds(Map<Long, TreeNode> childs) {
+ this.childs = childs;
}
}
Deleted:
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java
===================================================================
---
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java 2009-01-23
13:27:29 UTC (rev 12387)
+++
trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java 2009-01-23
13:28:09 UTC (rev 12388)
@@ -1,348 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.realworld.tree;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.model.SelectItem;
-
-import org.ajax4jsf.context.AjaxContext;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Observer;
-import org.jboss.seam.annotations.Out;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Synchronized;
-import org.jboss.seam.core.Events;
-import org.richfaces.component.UIDatascroller;
-import org.richfaces.component.UIDragSupport;
-import org.richfaces.component.UITree;
-import org.richfaces.component.UITreeNode;
-import org.richfaces.component.html.HtmlTree;
-import org.richfaces.event.DataScrollerEvent;
-import org.richfaces.event.DropEvent;
-import org.richfaces.event.NodeSelectedEvent;
-import org.richfaces.model.TreeNode;
-import org.richfaces.model.TreeRowKey;
-import org.richfaces.realworld.domain.Album;
-import org.richfaces.realworld.domain.Image;
-import org.richfaces.realworld.error.ErrorHandler;
-import org.richfaces.realworld.fileupload.FileManager;
-import org.richfaces.realworld.manager.ImageManager;
-import org.richfaces.realworld.navigation.NavigationEnum;
-import org.richfaces.realworld.util.SelectionHelper;
-
-@Name("treeSelectionManager")
-(a)Scope(ScopeType.CONVERSATION)
-@Synchronized(timeout=200000)
-public class TreeSelectionManager implements Serializable{
-
- private static final String DATASCROLLER_ID = "mainform:imageScroller";
-
- private static final String IMAGE_DATATABLE_ID = "mainform:mainImage";
-
- private static final String FIRST = "first";
-
- private static final String NEXT = "next";
-
- private static final String LAST = "last";
-
- private static final String UPDATE_MAIN_AREA_EVENT = "updateMainArea";
-
- private static final String PREVIOUS = "previous";
-
- private static final long serialVersionUID = -6072049677194472463L;
-
- private NavigationEnum mainArea;
-
- @In(required=false) @Out(required=false)
- private SelectionHelper selectionHelper;
-
- @In(create=true)
- FileManager fileManager;
-
- @In(required=false)
- ImageManager imageManager;
-
- private String nodeTitle;
-
- public void showFileUpload(TreeAlbumItem item){
- selectionHelper.setSelectedAlbum(item.getAlbum());
- if(item.isLeaf()){
- selectionHelper.setSelectedImage(null);
- }else{
- selectionHelper.setSelectedImage(((TreeImageItem)(item.getImages().get(0))).getImage());
- }
- this.setMainArea(NavigationEnum.FILE_UPLOAD);
- }
-
- @Observer("updateMainArea")
- public void updateMainArea(NavigationEnum mainArea) {
- this.setMainArea(mainArea);
- }
-
- public void scrollerListener(DataScrollerEvent event) {
- List<Image> images = selectionHelper.getSelectedAlbum().getImages();
- if (event.getNewScrolVal().equals(PREVIOUS)) {
- for(int index = 0 ; index < images.size(); index++){
- if(images.get(index) == selectionHelper.getSelectedImage()){
- selectionHelper.setSelectedImage(images.get(index - 1));
- selectionHelper.setSelectedImageIndex(index);
- }
- }
- } else if (event.getNewScrolVal().equals(LAST)) {
- selectionHelper.setSelectedImage(images.get(images.size() - 1));
- selectionHelper.setSelectedImageIndex(images.size());
- } else if (event.getNewScrolVal().equals(NEXT)) {
- for(int index = 0 ; index < images.size(); index++){
- if(images.get(index) == selectionHelper.getSelectedImage()){
- selectionHelper.setSelectedImage(images.get(index + 1));
- selectionHelper.setSelectedImageIndex(index + 2);
- return;
- }
- }
- } else if (event.getNewScrolVal().equals(FIRST)) {
- selectionHelper.setSelectedImage(images.get(0));
- selectionHelper.setSelectedImageIndex(1);
- }
-
- }
-
- public void dropListener(DropEvent dropEvent) {
-
- // resolve drag destination attributes
- UITreeNode destNode = (dropEvent.getSource() instanceof UITreeNode) ? (UITreeNode)
dropEvent.getSource() : null;
- UITree destTree = destNode != null ? destNode.getUITree() : null;
- TreeRowKey dropNodeKey = (dropEvent.getDropValue() instanceof TreeRowKey) ?
(TreeRowKey) dropEvent.getDropValue() : null;
- TreeNode droppedInNode = dropNodeKey != null ? destTree.getTreeNode(dropNodeKey) :
null;
-
- // resolve drag source attributes
- UITreeNode srcNode = (dropEvent.getDraggableSource() instanceof UITreeNode) ?
(UITreeNode) dropEvent.getDraggableSource() : null;
- UITree srcTree = srcNode != null ? srcNode.getUITree() : null;
- TreeRowKey dragNodeKey = (dropEvent.getDragValue() instanceof TreeRowKey) ?
(TreeRowKey) dropEvent.getDragValue() : null;
- TreeNode draggedNode = dragNodeKey != null ? srcTree.getTreeNode(dragNodeKey) : null;
- if (dropEvent.getDraggableSource() instanceof UIDragSupport && srcTree == null
&& draggedNode == null && dropEvent.getDragValue() instanceof TreeNode) {
- srcTree = destTree;
- draggedNode = (TreeNode) dropEvent.getDragValue();
- dragNodeKey = srcTree.getTreeNodeRowKey(draggedNode) instanceof TreeRowKey ?
(TreeRowKey) srcTree.getTreeNodeRowKey(draggedNode) : null;
- }
-
- // Note: check if we dropped node on to itself or to item instead of
- // folder here
- if (droppedInNode != null && (droppedInNode.equals(draggedNode) ||
droppedInNode.getParent().getParent() != null || draggedNode.getParent().getParent() ==
null)) {
- //Warning: Can't drop on itself or to pic itself! Also can't move folders
- return;
- }
-
- if (dropNodeKey != null) {
- // add destination node for rerender
- destTree.addRequestKey(dropNodeKey);
-
- Object state = null;
- if (dragNodeKey != null) { // Drag from this or other tree
- TreeNode parentNode = draggedNode.getParent();
- // 1. remove node from tree
- state = srcTree.removeNode(dragNodeKey);
- // 2. add parent for rerender
- Object rowKey = srcTree.getTreeNodeRowKey(parentNode);
- srcTree.addRequestKey(rowKey);
- //TODO refactor this code
- if (dropEvent.getDraggableSource() instanceof UIDragSupport) {
- // if node was gragged in it's parent place dragged node to
- // the end of selected nodes in grid
- if (droppedInNode.equals(parentNode)) {
- }
- }
- } else if (dropEvent.getDragValue() != null) { // Drag from some
- // drag source
- draggedNode.setData(dropEvent.getDragValue().toString());
- }
-
- // generate new node id
- Object id = getNewId(destTree.getTreeNode(dropNodeKey));
- destTree.addNode(dropNodeKey, draggedNode, id, state);
- }
-
- AjaxContext ac = AjaxContext.getCurrentInstance();
- ac.addRenderedArea(IMAGE_DATATABLE_ID);
- Image draggedImage = ((TreeImageItem)draggedNode).getImage();
- draggedImage.setAlbumName(((TreeAlbumItem)droppedInNode).getAlbum().getName());
- imageManager.editImage(draggedImage);
- // Add destination tree to reRender
- try {
- ac.addComponentToAjaxRender(destTree);
- } catch (Exception e) {
- //System.err.print(e.getMessage());
- }
-
- }
-
- private Object getNewId(TreeNode parentNode) {
- Map<Object, TreeNode> childs = new HashMap<Object, TreeNode>();
- Iterator<Map.Entry<Object, TreeNode>> iter = parentNode.getChildren();
- while (iter != null && iter.hasNext()) {
- Map.Entry<Object, TreeNode> entry = iter.next();
- childs.put(entry.getKey(), entry.getValue());
- }
-
- Integer index = 1;
- while (childs.containsKey(index)) {
- index++;
- }
- return index;
- }
-
- public Boolean adviseNodeSelected(UITree tree) {
- TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
- TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
- if (treeNode instanceof TreeAlbumItem) {
- TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
- return currentNode.getAlbum() == selectionHelper.getSelectedAlbum();
- } else if (treeNode instanceof TreeImageItem) {
- return ((TreeImageItem) treeNode).getImage() == selectionHelper.getSelectedImage();
- }
- return null;
- }
-
- public Boolean adviseNodeOpened(UITree tree) {
- TreeRowKey treeRowKey = (TreeRowKey) tree.getRowKey();
- TreeNode treeNode = (TreeNode) tree.getRowData(treeRowKey);
- if (treeNode instanceof TreeAlbumItem) {
- TreeAlbumItem currentNode = (TreeAlbumItem) treeNode;
- return currentNode.getAlbum() == selectionHelper.getSelectedAlbum();
- }
- return null;
- }
-
- public void processSelection(NodeSelectedEvent event) {
- try{
- HtmlTree tree = (HtmlTree) event.getComponent();
- if (tree.getRowData() instanceof TreeImageItem) {
- nodeTitle = ((TreeImageItem) (tree.getRowData())).getImage()
- .getName();
- } else if (tree.getRowData() instanceof TreeAlbumItem) {
- nodeTitle = ((TreeAlbumItem) (tree.getRowData())).getAlbum()
- .getName();
- }
- Events.instance().raiseEvent(UPDATE_MAIN_AREA_EVENT, NavigationEnum.IMAGE_PREVIEW);
- TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
- selectionHelper.setUserAlbumSelected(true);
- if(currentNode instanceof TreeImageItem){
- Image image = ((TreeImageItem)currentNode).getImage();
- selectionHelper.setSelectedImage(image);
- Album album = ((TreeAlbumItem)currentNode.getParent()).getAlbum();
- if(album != selectionHelper.getSelectedAlbum()){
- selectionHelper.setSelectedAlbum(album);
- }
- int index = album.getIndex(image);
- setDataScrollerIndex(index);
- return;
- }else if(currentNode instanceof TreeAlbumItem){
- TreeAlbumItem node = (TreeAlbumItem)currentNode;
- selectionHelper.setSelectedImage(null);
- setDataScrollerIndex(0);
- if (node.isLeaf()) {
- //selectionHelper.setSelectedImage(null);
- Album album = node.getAlbum();
- selectionHelper.setSelectedAlbum(album);
- }else{
- if(node.getAlbum() == selectionHelper.getSelectedAlbum()){
- return;
- }else{
- selectionHelper.setSelectedAlbum(node.getAlbum());
- //selectionHelper.setSelectedImage(node.getAlbum().getImages().get(0));
- }
- }
- }
- }
- catch(Exception e){
- //Bla-bla-bla
- }
- }
-
- //public void updateScroller(ActionEvent event){
- //this.setDataScrollerIndex(selectionHelper.getSelectedImageIndex()- 1);
- //}
-
- private void setDataScrollerIndex(int index) {
- UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
- UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
- Map<String, Object> attributes = scroller.getDataTable().getAttributes();
- attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+1);
- selectionHelper.setSelectedImageIndex(index+1);
- }
-
-
- public void incrementSlideshowIndex() {
- if(null == selectionHelper.getSelectedAlbum()){
- //Events.instance().raiseEvent("addErrorEvent", new
RealworldException("You have no albums and images"));
- return;
- }
- int index =
selectionHelper.getSelectedAlbum().getIndex(selectionHelper.getSelectedImage());
- if(selectionHelper.getSelectedAlbum().getImages().size() == index +1){
- index = -1;
- }
- selectionHelper.setSelectedImage(selectionHelper.getSelectedAlbum().getImages().get(index
+1));
- UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
- UIDatascroller scroller = (UIDatascroller)component.findComponent(DATASCROLLER_ID);
- Map<String, Object> attributes = scroller.getDataTable().getAttributes();
- attributes.put(UIDatascroller.SCROLLER_STATE_ATTRIBUTE, index+2);
- selectionHelper.setSelectedImageIndex(index+2);
- }
-
- public String getNodeTitle() {
- return nodeTitle;
- }
-
- public void setNodeTitle(String nodeTitle) {
- this.nodeTitle = nodeTitle;
- }
-
- public NavigationEnum getMainArea() {
- return mainArea;
- }
-
- public void setMainArea(NavigationEnum mainArea) {
- this.mainArea = mainArea;
- }
-
- public SelectItem[] getAvailableIndexOfImages(){
- SelectItem[] group = new
SelectItem[selectionHelper.getSelectedAlbum().getImages().size()];
- for(int i = 0; i < selectionHelper.getSelectedAlbum().getImages().size(); i++){
- group[i] = new SelectItem(i+1);
- }
- return group;
- }
-
- @ErrorHandler
- public void updateSelectedItems(Image image){
- selectionHelper.setSelectedImage(image);
- Integer index =
selectionHelper.getSelectedAlbum().getIndex(selectionHelper.getSelectedImage());
- setDataScrollerIndex(index);
- }
-}