From c24efcc90a5f19527adda88aeca794553e45ddc1 Mon Sep 17 00:00:00 2001 From: Natasa Kapravelou Date: Wed, 19 May 2010 12:22:29 +0300 Subject: [PATCH] New javascript method Trim added in DisplayHelper that trim not only whitespaces but also nbsp. Continue modifying the PopupTree in order to show the correct URI in browsers address bar. Not completed yet since the encoding need revision and history hasnot implemented yet. Add a new condition check in FileMenu.java that checks when the Upload option should be available (related to Issue 9 bug), no completed since in Trash/foo_folder the option of New Folder/Upload should not be available --- .classpath | 1 + .hgignore | 1 + src/gr/ebs/gss/client/DisplayHelper.java | 19 ++++- src/gr/ebs/gss/client/FileMenu.java | 6 +- src/gr/ebs/gss/client/PopupTree.java | 113 ++++++++++++++++++++++++------ test/gr/ebs/gss/client/TestUri.java | 36 ---------- 6 files changed, 116 insertions(+), 60 deletions(-) delete mode 100644 test/gr/ebs/gss/client/TestUri.java diff --git a/.classpath b/.classpath index 5602f3e..d2aa75a 100644 --- a/.classpath +++ b/.classpath @@ -27,5 +27,6 @@ + diff --git a/.hgignore b/.hgignore index 6d95710..e6342f5 100644 --- a/.hgignore +++ b/.hgignore @@ -3,3 +3,4 @@ syntax: regexp ^www$ ^bin$ .DS_Store$ +^tomcat diff --git a/src/gr/ebs/gss/client/DisplayHelper.java b/src/gr/ebs/gss/client/DisplayHelper.java index f72d757..6ad59a8 100644 --- a/src/gr/ebs/gss/client/DisplayHelper.java +++ b/src/gr/ebs/gss/client/DisplayHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2009 Electronic Business Systems Ltd. + * Copyright 2009, 2010 Electronic Business Systems Ltd. * * This file is part of GSS. * @@ -118,5 +118,22 @@ public class DisplayHelper { styleRow(table, row, true, styleName); return row; } + /** + * The implementation of this trim method also checks for + * no brake space characters (nbsp) = '\00A0' + * and removes them + * + * @param input + * @return the new trimmed string without whitespace or no brake space + */ + public static native String trim(String input) /*-{ + if(input.length == 0) + return input; + if((input[0]||input[input.length-1]) != '\u0020' && (input[0]||input[input.length-1]) != '\u00A0') + return input; + var r1 = input.replace(/^(\s*)/, ''); + var r2 = r1.replace(/\s*$/, ''); + return r2; + }-*/; } diff --git a/src/gr/ebs/gss/client/FileMenu.java b/src/gr/ebs/gss/client/FileMenu.java index e6af528..f552c40 100644 --- a/src/gr/ebs/gss/client/FileMenu.java +++ b/src/gr/ebs/gss/client/FileMenu.java @@ -1,5 +1,5 @@ /* - * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd. + * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd. * * This file is part of GSS. * @@ -171,9 +171,11 @@ public class FileMenu extends PopupPanel implements ClickHandler { boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource; boolean propertiesVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource || GSS.get().getCurrentSelection() instanceof List)); boolean newFolderVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem))); + boolean uploadVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem))); if(newFolderVisible) contextMenu.addItem("" + AbstractImagePrototype.create(images.folderNew()).getHTML() + " New Folder", true, new NewFolderCommand(this, images)); - contextMenu.addItem("" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this)); + if(uploadVisible) + contextMenu.addItem("" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this)); if (downloadVisible) { String[] link = {"", ""}; createDownloadLink(link, false); diff --git a/src/gr/ebs/gss/client/PopupTree.java b/src/gr/ebs/gss/client/PopupTree.java index 94ecfca..7e37111 100644 --- a/src/gr/ebs/gss/client/PopupTree.java +++ b/src/gr/ebs/gss/client/PopupTree.java @@ -34,6 +34,7 @@ import com.google.gwt.event.logical.shared.OpenEvent; import com.google.gwt.event.logical.shared.OpenHandler; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.http.client.URL; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.History; @@ -71,37 +72,62 @@ public class PopupTree extends Tree { TreeItem item = event.getSelectedItem(); processItemSelected(item, true); - String path = GSS.get().getApiPath() + GSS.get().getCurrentUserResource().getUsername()+ "/"; -// Trash is selected + String path = GSS.get().getApiPath() + GSS.get().getCurrentUserResource().getUsername()+ "/"; + +// case: Trash is selected if(GSS.get().getFolders().isTrash(item)){ TrashResource currentObject = (TrashResource) GSS.get().getFolders().getCurrent().getUserObject(); - History.newItem("Trash"+currentObject.getUri().substring(path.lastIndexOf("/"))); + String finalUri = currentObject.getUri().substring(path.lastIndexOf("/")+1); + History.newItem("Files/"+finalUri); + } +// case: Other's shared option is selected + else if (GSS.get().getFolders().getCurrent().getUserObject() instanceof OthersResource){ + String currentPartTrimmed = DisplayHelper.trim(item.getText()); + String finalUri = URL.encodeComponent("Files/"+path.substring(path.lastIndexOf("/")+1) + currentPartTrimmed); + + History.newItem(finalUri); } -// other's shared is selected - else if (GSS.get().getFolders().isOthersShared(item)){ - OthersResource currentObject = (OthersResource) GSS.get().getFolders().getCurrent().getUserObject(); - History.newItem(currentObject.getUri().substring(path.lastIndexOf("/")) - + GSS.get().getFolders().getCurrent().getText()); +// case: expand Other's shared to folder below + else if(GSS.get().getFolders().getCurrent().getUserObject() instanceof OtherUserResource){ + OtherUserResource currentObject = (OtherUserResource) GSS.get().getFolders().getCurrent().getUserObject(); + String finalUri = URL.encodeComponent("others/"+ currentObject.getName()); + History.newItem(finalUri); } -// my shared is selected - else if(GSS.get().getFolders().isMySharedItem(item)){ +// case: my shared is selected + else if(GSS.get().getFolders().getCurrent().getUserObject() instanceof SharedResource){ SharedResource currentObject = (SharedResource) GSS.get().getFolders().getCurrent().getUserObject(); - History.newItem(currentObject.getUri().substring(path.lastIndexOf("/")) - + GSS.get().getFolders().getCurrent().getText()); + String finalUri = currentObject.getUri().substring(path.lastIndexOf("/")+1); + History.newItem("Files/"+finalUri); } -// home folders are selected + +// case: home folders are selected else{ FolderResource currentObject = (FolderResource) GSS.get().getFolders().getCurrent().getUserObject(); - int index = path.lastIndexOf("/"); - String uri = currentObject.getParentURI(); - String res = null; - if(uri == null) - History.newItem("Files" + currentObject.getParentName()); - else - History.newItem("Files"+ uri.substring(path.lastIndexOf("/")) + currentObject.getName()); + String parentUri = currentObject.getParentURI(); + if(parentUri == null){ + if(containsTrash(GSS.get().getFolders().getCurrent())){ + String finalUri = constructPartialPath(GSS.get().getFolders().getCurrent()); + History.newItem("trash/"+finalUri); + }else{ + String nonEncodedUri = "Files/" + currentObject.getName(); + + History.newItem(URL.encode(nonEncodedUri)); + } + } else if(containsSharedFolder(GSS.get().getFolders().getCurrent())){ + String finalUri = constructPartialPath(GSS.get().getFolders().getCurrent()); + History.newItem("shared/"+finalUri); + }else if(containsSharedFolder(GSS.get().getFolders().getCurrent())){ + String finalUri = constructPartialPath(GSS.get().getFolders().getCurrent()); + History.newItem("other's/"+finalUri); + } + else{ + String uri = "Files"+ parentUri.substring(path.lastIndexOf("/")) + URL.encode(currentObject.getName()); + History.newItem(uri); + } } - } + + }); addOpenHandler(new OpenHandler() { @@ -263,4 +289,49 @@ public class PopupTree extends Tree { treeSelectedItem = newSelectedItem; } + /** + * examine whether there is "My Shared" inside path + * + * @param selectedItem the selectedItem to check + */ + + public boolean containsSharedFolder(TreeItem selectedItem){ + TreeItem parent = selectedItem.getParentItem(); + while (parent != null){ + String parentItemText = parent.getText(); + String parentItemTextTr = DisplayHelper.trim(parentItemText); + if(parentItemTextTr.equals("My Shared")||parentItemTextTr.equals("Other's Shared")) return true; + parent = parent.getParentItem(); + } + return false; + } + public boolean containsTrash(TreeItem selectedItem){ + TreeItem parent = selectedItem.getParentItem(); + while (parent != null){ + String parentItemText = parent.getText(); + String parentItemTextTr = DisplayHelper.trim(parentItemText); + if(parentItemTextTr.equals("Trash")) return true; + parent = parent.getParentItem(); + } + return false; + } + + /** + * construct the partial path of the selected TreeItem + * + * @param selectedItem the selectedItem to check + */ + public String constructPartialPath(TreeItem selectedItem){ + String result = DisplayHelper.trim(selectedItem.getText()); + TreeItem parent = selectedItem.getParentItem(); + while (!(DisplayHelper.trim(parent.getText()).equals("My Shared") || DisplayHelper.trim(parent.getText()).equals("Other's Shared")||DisplayHelper.trim(parent.getText()).equals("Trash"))){ + result = DisplayHelper.trim(parent.getText()) + "/" + result; + if(result.equals("My Shared")||result.equals("Other's Shared")) return result; + parent = parent.getParentItem(); + } + + return result; + } + + } diff --git a/test/gr/ebs/gss/client/TestUri.java b/test/gr/ebs/gss/client/TestUri.java deleted file mode 100644 index 83e2f2a..0000000 --- a/test/gr/ebs/gss/client/TestUri.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010 Electronic Business Systems Ltd. - * - * This file is part of GSS. - * - * GSS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GSS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GSS. If not, see . - */ -package gr.ebs.gss.client; - -import junit.framework.TestCase; - - -/** - * @author natasa - * - */ -public class TestUri extends TestCase { - public void testUri(){ - String currentURI = "#http://127.0.0.1:8080/pithos/rest/past@ebs.gr/files/.sync/ Downloads"; - String path = "#http://127.0.0.1:8080/pithos/rest/past@ebs.gr/"; - System.out.println(path.lastIndexOf("/")); - System.out.println(currentURI.substring(46)); - } - -} -- 1.7.10.4