[richfaces-svn-commits] JBoss Rich Faces SVN: r11460 - in trunk/test-applications/realworld: ejb/src/main/java/org/richfaces/realworld/service and 7 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Dec 1 11:45:23 EST 2008


Author: amarkhel
Date: 2008-12-01 11:45:22 -0500 (Mon, 01 Dec 2008)
New Revision: 11460

Modified:
   trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
   trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java
   trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java
   trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
   trunk/test-applications/realworld/ejb/src/main/resources/import.sql
   trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeActionManager.java
   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/util/ModalPanelHelper.java
   trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/albumModalPanel-taglib.xml
   trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/addComment.xhtml
   trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/imagePrefs.xhtml
   trunk/test-applications/realworld/web/src/main/webapp/imagePreview.xhtml
   trunk/test-applications/realworld/web/src/main/webapp/layout/menu.xhtml
   trunk/test-applications/realworld/web/src/main/webapp/main.xhtml
   trunk/test-applications/realworld/web/src/main/webapp/navigation.xhtml
   trunk/test-applications/realworld/web/src/main/webapp/tree.xhtml
   trunk/test-applications/realworld/web/src/main/webapp/userPrefs.xhtml
Log:


Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Album.java	2008-12-01 16:45:22 UTC (rev 11460)
@@ -278,4 +278,13 @@
 	public void setSharedOwners(List<User> sharedOwners) {
 		this.sharedOwners = sharedOwners;
 	}
+
+	public int getIndex(Image image) {
+		for(int i =0; i < this.images.size(); i++){
+			if(this.images.get(i).equals(image)){
+				return i;
+			}
+		}
+		return -1;
+	}
 }

Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/domain/Comment.java	2008-12-01 16:45:22 UTC (rev 11460)
@@ -18,10 +18,13 @@
 import org.hibernate.validator.Length;
 import org.hibernate.validator.NotEmpty;
 import org.hibernate.validator.NotNull;
+import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
 
 @Entity
 @Name("comment")
+ at Scope(ScopeType.PAGE)
 @Table(name = "comments")
 public class Comment implements Serializable{
 

Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java	2008-12-01 16:45:22 UTC (rev 11460)
@@ -36,4 +36,6 @@
 	
 	public void addComment(Comment comment);
 
+	public abstract void editComment(Comment comment);
+
 }
\ No newline at end of file

Modified: trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java	2008-12-01 16:45:22 UTC (rev 11460)
@@ -67,7 +67,7 @@
 		em.merge(image);
 		if(parentChanged){
 			image.getAlbum().removeImage(image);
-			Album album = (Album)em.createQuery("from Album a where a.name=:albumName").setParameter("albumName", image.getAlbumName()).getSingleResult();
+			Album album = (Album)em.createQuery("from Album a where a.name=:albumName and a.owner = : owner").setParameter("albumName", image.getAlbumName()).setParameter("owner", image.getAlbum().getOwner().getLogin()).getSingleResult();
 			album.addImage(image);
 			em.merge(album);
 		}
@@ -85,6 +85,12 @@
 	}
 	
 	public void addComment(Comment comment){
-		
+		comment.getImage().addComment(comment);
+		em.flush();
 	}
+
+	public void editComment(Comment comment) {
+		em.merge(comment);
+		em.flush();
+	}
 }

Modified: trunk/test-applications/realworld/ejb/src/main/resources/import.sql
===================================================================
--- trunk/test-applications/realworld/ejb/src/main/resources/import.sql	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/ejb/src/main/resources/import.sql	2008-12-01 16:45:22 UTC (rev 11460)
@@ -1,6 +1,6 @@
-INSERT INTO Users(user_id, obj_version, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (1, 0, 'Andrey', 'Markhel', 'amarkhel at exadel.com', 'avatar.gif', 'amarkhel', '12345',  '1985-01-08');
-INSERT INTO Users(user_id, obj_version, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (2, 0, 'Andrey', 'Markhel', 'amarkhel at exadel.com', 'avatar.gif', 'root', '12345',  '1985-01-08');
-INSERT INTO Users(user_id, obj_version, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (3, 0, 'Andrey', 'Markhel', 'amarkhel at exadel.com', 'avatar.gif', 'qqqq', '12345',  '1985-01-08');
+INSERT INTO Users(user_id, obj_version, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (1, 0, 'Andrey', 'Markhel', 'amarkhel at exadel.com', 'avatar.jpg', 'amarkhel', '12345',  '1985-01-08');
+INSERT INTO Users(user_id, obj_version, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (2, 0, 'Andrey', 'Markhel', 'amarkhel at exadel.com', 'avatar.jpg', 'root', '12345',  '1985-01-08');
+INSERT INTO Users(user_id, obj_version, firstname, secondname, email, avatarpath, login, password, birthdate) VALUES (3, 0, 'Andrey', 'Markhel', 'amarkhel at exadel.com', 'avatar.jpg', 'qqqq', '12345',  '1985-01-08');
 INSERT INTO albums(album_id, obj_version, name, description, shared, album_user_id) VALUES (1, 0, 'Album 1', 'Simple Album', true, 1);
 INSERT INTO albums(album_id, obj_version, name, description, shared, album_user_id) VALUES (2, 0, 'Album 2', 'Simple Album 2', false, 1);
 INSERT INTO albums(album_id, obj_version, name, description, shared, album_user_id) VALUES (3, 0, 'Album 3', 'Simple Album 3', false, 1);

Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeActionManager.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeActionManager.java	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeActionManager.java	2008-12-01 16:45:22 UTC (rev 11460)
@@ -1,5 +1,7 @@
 package org.richfaces.realworld.tree;
 
+import java.util.Date;
+
 import javax.faces.model.SelectItem;
 
 import org.jboss.seam.ScopeType;
@@ -8,6 +10,7 @@
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
 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.fileupload.FileManager;
@@ -118,4 +121,21 @@
 		treeSelectionManager.setSelectedImage(imageItem.getImage());
 		treeSelectionManager.setSelectedAlbum(albumItem.getAlbum());
 	}
+
+	public void editComment(Comment comment) {
+		imageAction.editComment(comment);
+	}
+	
+	public void addComment(Comment comment) {
+		imageAction.addComment(comment);
+	}
+	
+	public void addAutoComment(User user, Image image) {
+		Comment comment = new Comment();
+		comment.setAuthor(user);
+		comment.setDate(new Date());
+		comment.setImage(image);
+		comment.setMessage("+1");
+		imageAction.addComment(comment);
+	}
 }

Modified: 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	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/tree/TreeSelectionManager.java	2008-12-01 16:45:22 UTC (rev 11460)
@@ -12,6 +12,11 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+import javax.faces.model.SelectItem;
+import javax.faces.model.SelectItemGroup;
 import javax.imageio.ImageIO;
 
 import org.ajax4jsf.context.AjaxContext;
@@ -21,6 +26,8 @@
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.Synchronized;
+import org.richfaces.component.UIDataTable;
+import org.richfaces.component.UIDatascroller;
 import org.richfaces.component.UIDragSupport;
 import org.richfaces.component.UITree;
 import org.richfaces.component.UITreeNode;
@@ -41,6 +48,8 @@
 @Scope(ScopeType.SESSION)
 public class TreeSelectionManager {
 
+	private static final FacesContext FacesContext = null;
+
 	@In
 	private User user;
 	
@@ -50,8 +59,13 @@
 
 	private Album selectedAlbum;
 	
+	private int selectedImageIndex = 1;
+	
 	@In(create=true)
 	FileManager fileManager;
+	
+	@In(create=true)
+	TreeActionManager treeActionManager;
 
 	private String nodeTitle;
 
@@ -75,19 +89,23 @@
 			for(int index = 0 ; index < images.size(); index++){
 				if(images.get(index) == this.getSelectedImage()){
 					this.setSelectedImage(images.get(index - 1));
+					this.setSelectedImageIndex(index);
 				}
 			}
 		} else if (event.getNewScrolVal().equals("last")) {
 			this.setSelectedImage(images.get(images.size() - 1));
+			this.setSelectedImageIndex(images.size());
 		} else if (event.getNewScrolVal().equals("next")) {
 			for(int index = 0 ; index < images.size(); index++){
 				if(images.get(index) == this.getSelectedImage()){
 						this.setSelectedImage(images.get(index + 1));
+						this.setSelectedImageIndex(index + 2);
 						return;
 				}
 			}
 		} else if (event.getNewScrolVal().equals("first")) {
 			this.setSelectedImage(images.get(0));
+			this.setSelectedImageIndex(1);
 		}
 
 	}
@@ -118,6 +136,60 @@
 		}
 	}
 	
+	public synchronized void paintAvatar(OutputStream out, Object data) throws IOException{
+		if (null == data) {
+			return;
+		}
+		File imageResource = fileManager.getImage(user.getLogin() + fileManager.getFileSeparator() + "avatars" + fileManager.getFileSeparator() + data.toString());
+		if (imageResource != null) {
+			FileInputStream fileInputStream = new FileInputStream(imageResource);
+			BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
+			InputStream paintData = bufferedInputStream;
+			if (null == paintData) {
+				// throw new Exception("");
+				// TODO
+			}
+			try{
+			BufferedImage image = ImageIO.read(paintData);
+			ImageIO.write(image, "jpeg", out);
+			}catch(Exception e){
+				
+			}finally{
+				fileInputStream.close();
+				bufferedInputStream.close();
+				paintData.close();
+			}
+		}
+	}
+	
+	public synchronized void paintFriendAvatar(OutputStream out, Object data) throws IOException{
+		if (null == data) {
+			return;
+		}
+		String temp = data.toString();
+		String[] array = temp.split(":");
+		File imageResource = fileManager.getImage(array[0] + fileManager.getFileSeparator() + "avatars" + fileManager.getFileSeparator() + array[1]);
+		if (imageResource != null) {
+			FileInputStream fileInputStream = new FileInputStream(imageResource);
+			BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
+			InputStream paintData = bufferedInputStream;
+			if (null == paintData) {
+				// throw new Exception("");
+				// TODO
+			}
+			try{
+			BufferedImage image = ImageIO.read(paintData);
+			ImageIO.write(image, "jpeg", out);
+			}catch(Exception e){
+				
+			}finally{
+				fileInputStream.close();
+				bufferedInputStream.close();
+				paintData.close();
+			}
+		}
+	}
+	
 	public void dropListener(DropEvent dropEvent) {
 		
 		// resolve drag destination attributes
@@ -125,7 +197,7 @@
 		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;
@@ -175,6 +247,9 @@
 
 		AjaxContext ac = AjaxContext.getCurrentInstance();
 		ac.addRenderedArea("mainform:imageList");
+		Image draggedImage = ((TreeImageItem)draggedNode).getImage();
+		draggedImage.setAlbumName(((TreeAlbumItem)droppedInNode).getAlbum().getName());
+		treeActionManager.editImage(draggedImage);
 		// Add destination tree to reRender
 		try {
 		    ac.addComponentToAjaxRender(destTree);
@@ -263,13 +338,18 @@
 		}
 		TreeNode<String> currentNode = tree.getModelTreeNode(tree.getRowKey());
 		if(currentNode instanceof TreeImageItem){
-				this.setSelectedImage(((TreeImageItem)currentNode).getImage());
-				if(((TreeAlbumItem)currentNode.getParent()).getAlbum() != this.getSelectedAlbum()){
-					this.setSelectedAlbum(((TreeAlbumItem)currentNode.getParent()).getAlbum());
+				Image image = ((TreeImageItem)currentNode).getImage();
+				this.setSelectedImage(image);
+				Album album = ((TreeAlbumItem)currentNode.getParent()).getAlbum();
+				if(album != this.getSelectedAlbum()){
+					this.setSelectedAlbum(album);
 				}
+				int index = album.getIndex(image);
+				setDataScrollerIndex(index);
 				return;
 		}else if(currentNode instanceof TreeAlbumItem){
 			TreeAlbumItem node = (TreeAlbumItem)currentNode;
+			setDataScrollerIndex(0);
 			if (node.isLeaf()) {
 				this.setSelectedImage(null);
 				Album album = node.getAlbum();
@@ -285,6 +365,17 @@
 		}
 	}
 
+	public void updateScroller(ActionEvent event){
+		this.setDataScrollerIndex(this.selectedImageIndex - 1);
+	}
+	
+	private void setDataScrollerIndex(int index) {
+		UIComponent component = FacesContext.getCurrentInstance().getViewRoot();
+		UIDatascroller scroller = (UIDatascroller)component.findComponent("mainform:sc1");
+		scroller.setPage(index+1);
+		this.setSelectedImageIndex(index+1);
+	}
+
 	public String getNodeTitle() {
 		return nodeTitle;
 	}
@@ -300,4 +391,20 @@
 	public void setMainArea(NavigationEnum mainArea) {
 		this.mainArea = mainArea;
 	}
+
+	public int getSelectedImageIndex() {
+		return selectedImageIndex;
+	}
+
+	public void setSelectedImageIndex(int selectedImageIndex) {
+		this.selectedImageIndex = selectedImageIndex;
+	}
+	
+	public SelectItem[] getAvailableIndexOfImages(){
+		SelectItem[] group = new SelectItem[this.getSelectedAlbum().getImages().size()];
+		for(int i = 0; i < this.getSelectedAlbum().getImages().size(); i++){
+			group[i] = new SelectItem(i+1);
+		}
+		return group;
+	}
 }

Modified: trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ModalPanelHelper.java
===================================================================
--- trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ModalPanelHelper.java	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/web/src/main/java/org/richfaces/realworld/util/ModalPanelHelper.java	2008-12-01 16:45:22 UTC (rev 11460)
@@ -1,5 +1,7 @@
 package org.richfaces.realworld.util;
 
+import java.util.Date;
+
 import javax.faces.event.ActionEvent;
 
 import org.jboss.seam.ScopeType;
@@ -8,7 +10,9 @@
 import org.jboss.seam.annotations.Out;
 import org.jboss.seam.annotations.Scope;
 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.tree.TreeActionManager;
 
 @Name("modalPanelHelper")
@@ -28,6 +32,9 @@
 	@In(create=true, required=true)
 	private TreeActionManager treeActionManager;
 
+	@In(create=true, required=true) @Out
+	private Comment comment;
+
 	public String getCaption() {
 		return caption;
 	}
@@ -64,6 +71,19 @@
 		}
 	}
 	
+	public void initModalPanelData( String actionName, String caption, Comment comment, User user, Image image){
+		this.caption = caption;
+		this.actionName = actionName;
+		if(null != comment){
+			this.comment = comment;
+		}else{
+			this.comment = new Comment();
+			this.comment.setAuthor(user);
+			this.comment.setImage(image);
+			this.comment.setDate(new Date());
+		}
+	}
+	
 	public void addAlbum(ActionEvent event){
 		treeActionManager.addAlbum();
 	}
@@ -80,6 +100,14 @@
 		treeActionManager.deleteImage(this.image);
 	}
 	
+	public void editComment(ActionEvent event){
+		treeActionManager.editComment(this.comment);
+	}
+	
+	public void addComment(ActionEvent event){
+		treeActionManager.addComment(this.comment);
+	}
+	
 	public void editImage(ActionEvent event){
 		treeActionManager.editImage(this.image);
 	}

Modified: trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/albumModalPanel-taglib.xml
===================================================================
--- trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/albumModalPanel-taglib.xml	2008-12-01 16:44:45 UTC (rev 11459)
+++ trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/albumModalPanel-taglib.xml	2008-12-01 16:45:22 UTC (rev 11460)
@@ -16,4 +16,8 @@
 	   <tag-name>imagePrefs</tag-name>
 	   <source>templates/imagePrefs.xhtml</source>
 	</tag>
+	<tag>
+	   <tag-name>comment</tag-name>
+	   <source>templates/addComment.xhtml</source>
+	</tag>
 </facelet-taglib>
\ No newline at end of file

Modified: trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/addComment.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/realworld/web/src/main/webapp/WEB-INF/tags/templates/imagePrefs.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/realworld/web/src/main/webapp/imagePreview.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/realworld/web/src/main/webapp/layout/menu.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/realworld/web/src/main/webapp/main.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/realworld/web/src/main/webapp/navigation.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/realworld/web/src/main/webapp/tree.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/realworld/web/src/main/webapp/userPrefs.xhtml
===================================================================
(Binary files differ)




More information about the richfaces-svn-commits mailing list