From 59c0b2af0a509f6de7de84723b03b15c3ecd52b8 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Wed, 5 Mar 2014 16:45:33 +0000 Subject: [PATCH] added handler to special folder git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@92699 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../workspace/client/ConstantsExplorer.java | 4 +- .../workspace/client/model/FileModel.java | 45 ++++--- .../workspace/client/resources/Icons.java | 5 +- .../workspace/client/resources/Resources.java | 5 + .../client/resources/icons/specialfolder.png | Bin 0 -> 900 bytes .../client/resources/icons/specialfolder2.png | Bin 0 -> 910 bytes .../client/view/tree/AsyncTreePanel.java | 15 ++- .../client/view/tree/ContextMenuTree.java | 4 +- .../server/GWTWorkspaceServiceImpl.java | 111 ++++++++++++++++-- .../PropertyFileReadingErrorException.java | 8 ++ .../resource/PropertySpecialFolderReader.java | 69 +++++++++++ .../resource/specialfoldername.properties | 3 + 12 files changed, 238 insertions(+), 31 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/specialfolder.png create mode 100644 src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/specialfolder2.png create mode 100644 src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertyFileReadingErrorException.java create mode 100644 src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertySpecialFolderReader.java create mode 100644 src/main/java/org/gcube/portlets/user/workspace/server/util/resource/specialfoldername.properties diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java index 058cf16..0737b95 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java @@ -211,5 +211,7 @@ public class ConstantsExplorer { public static final String ID_FOLDER = "idFolder"; public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement"; - + //PROPERTY + public static final String SPECIALFOLDERNAME = "SPECIALFOLDERNAME"; + public static final String SPECIALFOLDERNAMEPROPERTIESFILE = "specialfoldername.properties"; } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/model/FileModel.java b/src/main/java/org/gcube/portlets/user/workspace/client/model/FileModel.java index 5819d14..35e9294 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/model/FileModel.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/model/FileModel.java @@ -26,6 +26,7 @@ public class FileModel extends BaseModelData implements Serializable { protected InfoContactModel infoContacts; protected boolean isRoot = false; protected boolean isVreFolder; + protected boolean isSpecialFolder = false; protected FileModel(){ } @@ -219,8 +220,12 @@ public class FileModel extends BaseModelData implements Serializable { }else if(this.getStatus() == ConstantsExplorer.FOLDERNOTLOAD){ //IS A FOLDER IN LOADING absImgPr = Resources.getIconLoading2(); - }else{//SIMPLE FOLDER - absImgPr = Resources.getIconFolder(); + }else{ + //SPECIAL FOLDER? + if(this.isSpecialFolder()) + absImgPr = Resources.getIconSpecialFolder(); + else //SIMPLE FOLDER + absImgPr = Resources.getIconFolder(); } return absImgPr; @@ -265,7 +270,7 @@ public class FileModel extends BaseModelData implements Serializable { } - private void setName(String name) { + public void setName(String name) { set(ConstantsExplorer.NAME, name); } @@ -324,22 +329,32 @@ public class FileModel extends BaseModelData implements Serializable { public void setVreFolder(boolean isVreFolder) { this.isVreFolder = isVreFolder; } + + /** + * @param b + */ + public void setSpecialFolder(boolean bool) { + this.isSpecialFolder = bool; + + } + + public boolean isSpecialFolder() { + return isSpecialFolder; + } @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("FileModel [isShareable()="); - builder.append(isShareable()); - builder.append(", isShared()="); - builder.append(isShared()); - builder.append(", getIdentifier()="); - builder.append(getIdentifier()); - builder.append(", getName()="); - builder.append(getName()); - builder.append(", isDirectory()="); - builder.append(isDirectory()); - builder.append(", isRoot()="); - builder.append(isRoot()); + builder.append("FileModel [test="); + builder.append(test); + builder.append(", infoContacts="); + builder.append(infoContacts); + builder.append(", isRoot="); + builder.append(isRoot); + builder.append(", isVreFolder="); + builder.append(isVreFolder); + builder.append(", isSpecialFolder="); + builder.append(isSpecialFolder); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java index 996c6b1..5d42b54 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Icons.java @@ -299,10 +299,13 @@ public interface Icons extends ClientBundle { @Source("icons/writeall.png") ImageResource writeall(); - @Source("icons/vreShare.png") + @Source("icons/specialfolder2.png") ImageResource vreFolder(); @Source("icons/admin.png") ImageResource administrator(); + + @Source("icons/specialfolder2.png") + ImageResource specialFolder(); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java index 3db27e7..2b74e7a 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/resources/Resources.java @@ -80,6 +80,11 @@ public class Resources { return AbstractImagePrototype.create(ICONS.users()); } + public static AbstractImagePrototype getIconSpecialFolder(){ + + return AbstractImagePrototype.create(ICONS.specialFolder()); + } + public static AbstractImagePrototype getIconAdministrator(){ return AbstractImagePrototype.create(ICONS.administrator()); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/specialfolder.png b/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/specialfolder.png new file mode 100644 index 0000000000000000000000000000000000000000..c07db8a5d73b9a9c3b07ae5d6866c2c1f2f9c9d8 GIT binary patch literal 900 zcmV-~1AF|5P)I1FG3iY}! z$w04=43f#DOe&R*3EvlgYeCI-S8Dn;RW24xL^B$2|hRn&ffR9YCAY_hw*h zCaSD8-33)kd*$ltDzZ}o_6)k-@pm7K0dXEf(FF401)L4dbwK@o7*chnN@sl_uyhOjfv$ITv$qBY$1ukf5jXb%>-lU4Mfo8pF_Kg%d#_~NDY33 z+9qA4NEgREJcj3&P>d~7>LLas2^2^in2XElGs1rc!xR4O@B}CPp)wzWn#MN8YpU<1 zYEp`iE^=ZVg@}}%AOosTXJ2q0y?hkivvWAa&Sswuy19B|{}!lLYZbkAFOJekHkLyN z4K+R$qPIq5p&*%r*G!}q(svu{&uTmE)0#*9AHhvklcJkOb4&_2LSh<+Qo=aJ$Iu^& zBS#JR$eM|d&K@!tnwZVj>HDmjb_>9-H)|B8UMJe!JdRDRiKnG!kT6JFh|(@ZD7r)@ z3Hd2wUOs!JTCc9E)&P`#S9Yn@JR~<@eRGr?C2<@>G-f2ejIqTek-{kb6*0CXH*xvI z?2*%FujLi)`vf+8x+$liZIXttja3k95JYO#J_sVBMM0?ueem5kK_3(Z-~0=F@lmMyWUC@pt1VkFiH&K} zluQjtyV*_lNA}mu+94{lLbn$piehM5QYs``BS{h{rO*o_@M^7o{+-ue{*)2JAj;K!eEY-CpFF$prd_0x);;F_ZQcMF`EN|K~SmqZ8^Y5 z#)rf0{=cbTQy!Zvq*S6WU%I;bB{v%eys=e9dGFv~0wEL3A0LNB)hf-Xg%g{vf~8;B%<~t9 zgqXU+jV1L~4_T5L67vI@Kz(Nei(h|^L%xT0c@4E-3I519+LZuYhq&|87rt}s)s~eI zVz1GLKjfkv#^kLa`3jYl?~#%f%uiZ)t37*C8_aZO&yLp<8j^&Qdo;>wd0yk?0QL}^{xv>8F+#}gStazjt zZD}yh6}z=jOU~RSt8NMT+2v}x)e?1f{=N6%`@UsU getFolderChildrenForFileGrid(FileModel folder) throws Exception, SessionExpiredException { @@ -283,21 +327,43 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT List listFileGridModels = new ArrayList(); WorkspaceFolder wsFolder = (WorkspaceFolder) workspace.getItem(folder.getIdentifier()); - - GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); - - Long startTime = System.currentTimeMillis(); + GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); + +// Long startTime = System.currentTimeMillis(); List listItems = (List) wsFolder.getChildren(); - Long endTime = System.currentTimeMillis() - startTime; - String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime)); - workspaceLogger.debug("##HL FILLING: grid getChildren() returning "+listItems.size()+" elements in " + time); +// Long endTime = System.currentTimeMillis() - startTime; +// String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime)); +// workspaceLogger.debug("##HL FILLING: grid getChildren() returning "+listItems.size()+" elements in " + time); listFileGridModels = builder.buildGXTListFileGridModelItem(listItems, folder); + //ADDING SPECIAL FOLDER? + if(wsFolder.isRoot()){ + //TODO + //ADD SPECIAL FOLDER + try{ + workspaceLogger.info("Folder is root, loading special folders.."); + WorkspaceFolder specialFolder = workspace.getMySpecialFolders(); + FileGridModel specialFolderModel = builder.buildGXTFileGridModelItem(specialFolder, folder); + specialFolderModel.setSpecialFolder(true); + String newName = getNameForSpecialFolder(); + + if(!newName.isEmpty()){ + workspaceLogger.info("Special folder name updated as: "+newName); + specialFolderModel.setName(newName); + }else + workspaceLogger.info("Special folder name is empty, skipping"); + + listFileGridModels.add(specialFolderModel); + }catch (Exception e) { + workspaceLogger.warn("An error occurred on retrieving special folders for folder id: "+folder.getIdentifier(), e); + } + } + return listFileGridModels; } catch (Exception e) { @@ -1510,11 +1576,20 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } @Override + @Deprecated + /** + * use WsMailWidget + */ public boolean sentToByMessageModel(MessageModel message) throws Exception { return false; } + @Override + @Deprecated + /** + * use WsMailWidget + */ public boolean saveAttachments(String messageIdentifier, String messageType) throws Exception { try { @@ -1538,6 +1613,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } @Override + @Deprecated + /** + * use WsMailWidget + */ public boolean saveAttach(String attachId) throws Exception { // TODO NOT USED return false; @@ -1594,6 +1673,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } @Override + @Deprecated + /** + * use WsMailWidget + */ public boolean deleteMessage(String messageIdentifier, String messageType) throws Exception { try { @@ -1617,7 +1700,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } - + @Override + @Deprecated + /** + * use WsMailWidget + */ public List getNewMessagesReceived() throws Exception { try { @@ -1644,6 +1731,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT @Override + @Deprecated + /** + * use WsMailWidget + */ public List searchInSentMessagesByText(String text) throws Exception { try { @@ -1666,6 +1757,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT @Override + @Deprecated + /** + * use WsMailWidget + */ public List searchInReceivedMessagesByText(String text) throws Exception { try { diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertyFileReadingErrorException.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertyFileReadingErrorException.java new file mode 100644 index 0000000..3687699 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertyFileReadingErrorException.java @@ -0,0 +1,8 @@ +package org.gcube.portlets.user.workspace.server.util.resource; + +@SuppressWarnings("serial") +public class PropertyFileReadingErrorException extends Exception { + public PropertyFileReadingErrorException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertySpecialFolderReader.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertySpecialFolderReader.java new file mode 100644 index 0000000..e257fdc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/PropertySpecialFolderReader.java @@ -0,0 +1,69 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.server.util.resource; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.gcube.portlets.user.workspace.client.ConstantsExplorer; + +/** + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * @Mar 5, 2014 + * + */ +public class PropertySpecialFolderReader { + + + protected static Logger logger = Logger.getLogger(PropertySpecialFolderReader.class); + protected String specialFolderName = ""; + + public PropertySpecialFolderReader() throws PropertyFileReadingErrorException { + + try{ + logger.info("Instancing new PropertySpecialFolderReader.."); +// URL resource = PropertySpecialFolderReader.class.getResource(ConstantsExplorer.SPECIALFOLDERNAMEPROPERTIESFILE); +// File file = new File(resource.toURI()); +// FileInputStream input = new FileInputStream(file); + + InputStream input = PropertySpecialFolderReader.class.getResourceAsStream(ConstantsExplorer.SPECIALFOLDERNAMEPROPERTIESFILE); + + Properties properties = new Properties(); + properties.load(input); + specialFolderName = properties.getProperty(ConstantsExplorer.SPECIALFOLDERNAME); + + logger.info("PropertySpecialFolderReader read for key: "+ConstantsExplorer.SPECIALFOLDERNAME + " value: "+specialFolderName); + + }catch (Exception e) { + logger.error("Error on loading property to read special folder name: ",e); + throw new PropertyFileReadingErrorException("Error on reading property file: "+ConstantsExplorer.SPECIALFOLDERNAMEPROPERTIESFILE); + } + } + + + public String getSpecialFolderName() { + return specialFolderName; + } + + public void setSpecialFolderName(String specialFolderName) { + this.specialFolderName = specialFolderName; + } + + + public static void main(String[] args) { + + try { + new PropertySpecialFolderReader(); + + } catch (PropertyFileReadingErrorException e) { + e.printStackTrace(); + } + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/specialfoldername.properties b/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/specialfoldername.properties new file mode 100644 index 0000000..205d234 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/resource/specialfoldername.properties @@ -0,0 +1,3 @@ +#Property file - Special Folder Name +#2014-05-03 +SPECIALFOLDERNAME=myspecialfolder \ No newline at end of file