From 9e8e14e4a114c044294514347503f3cb0428aa3d Mon Sep 17 00:00:00 2001 From: Christos Stathis Date: Fri, 17 Jun 2011 19:39:25 +0300 Subject: [PATCH] First version of client that displays first level containers --- web_client/build.xml | 9 +- .../gr/grnet/pithos/web/client/CellTreeView.java | 1 - .../gr/grnet/pithos/web/client/Configuration.java | 2 +- .../pithos/web/client/Configuration.properties | 2 +- .../grnet/pithos/web/client/DeleteGroupDialog.java | 141 ---- .../grnet/pithos/web/client/DeleteUserDialog.java | 143 ---- .../src/gr/grnet/pithos/web/client/EditMenu.java | 4 - .../grnet/pithos/web/client/FileContextMenu.java | 2 - web_client/src/gr/grnet/pithos/web/client/GSS.java | 368 +++------ .../grnet/pithos/web/client/GroupContextMenu.java | 90 --- .../src/gr/grnet/pithos/web/client/GroupMenu.java | 79 -- .../pithos/web/client/GroupPropertiesDialog.java | 165 ---- .../src/gr/grnet/pithos/web/client/Groups.java | 345 -------- .../src/gr/grnet/pithos/web/client/Search.java | 13 +- .../gr/grnet/pithos/web/client/SearchResults.java | 853 -------------------- .../src/gr/grnet/pithos/web/client/TopPanel.java | 15 +- .../gr/grnet/pithos/web/client/UserAddDialog.java | 230 ------ .../pithos/web/client/commands/DeleteCommand.java | 7 +- .../client/commands/DeleteUserOrGroupCommand.java | 51 -- .../web/client/commands/NewGroupCommand.java | 33 - .../pithos/web/client/commands/NewUserCommand.java | 33 - .../pithos/web/client/commands/PasteCommand.java | 37 - .../web/client/foldertree/AccountResource.java | 32 + .../web/client/foldertree/ContainerResource.java | 83 ++ .../grnet/pithos/web/client/foldertree/File.java | 8 + .../grnet/pithos/web/client/foldertree/Folder.java | 36 + .../web/client/foldertree/FolderTreeView.java | 121 +++ .../web/client/foldertree/FolderTreeViewModel.java | 85 ++ .../web/client/foldertree/GssCellTreeBasic.css | 78 ++ .../web/client/foldertree/ObjectResource.java | 8 + .../pithos/web/client/foldertree/Resource.java | 106 +++ .../web/client/foldertree/SubDirResource.java | 8 + .../web/client/foldertree/cellTreeClosedItem.gif | Bin 0 -> 198 bytes .../web/client/foldertree/cellTreeLoadingBasic.gif | Bin 0 -> 1737 bytes .../web/client/foldertree/cellTreeOpenItem.gif | Bin 0 -> 197 bytes .../grnet/pithos/web/client/rest/GetRequest.java | 82 ++ .../pithos/web/client/rest/RestException.java | 2 +- .../web/client/rest/RestRequestCallback.java | 56 ++ .../web/client/rest/resource/RestResource.java | 1 - 39 files changed, 841 insertions(+), 2488 deletions(-) delete mode 100644 web_client/src/gr/grnet/pithos/web/client/DeleteGroupDialog.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/DeleteUserDialog.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/GroupContextMenu.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/GroupMenu.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/GroupPropertiesDialog.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/Groups.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/SearchResults.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/UserAddDialog.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/commands/DeleteUserOrGroupCommand.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/commands/NewGroupCommand.java delete mode 100644 web_client/src/gr/grnet/pithos/web/client/commands/NewUserCommand.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/ContainerResource.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/File.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/GssCellTreeBasic.css create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/ObjectResource.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/Resource.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/SubDirResource.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/cellTreeClosedItem.gif create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/cellTreeLoadingBasic.gif create mode 100644 web_client/src/gr/grnet/pithos/web/client/foldertree/cellTreeOpenItem.gif create mode 100644 web_client/src/gr/grnet/pithos/web/client/rest/GetRequest.java create mode 100644 web_client/src/gr/grnet/pithos/web/client/rest/RestRequestCallback.java diff --git a/web_client/build.xml b/web_client/build.xml index fcc2b16..73234a9 100644 --- a/web_client/build.xml +++ b/web_client/build.xml @@ -102,6 +102,12 @@ + + + + + + @@ -128,8 +134,9 @@ + - + diff --git a/web_client/src/gr/grnet/pithos/web/client/CellTreeView.java b/web_client/src/gr/grnet/pithos/web/client/CellTreeView.java index 6bf1775..c91abe1 100644 --- a/web_client/src/gr/grnet/pithos/web/client/CellTreeView.java +++ b/web_client/src/gr/grnet/pithos/web/client/CellTreeView.java @@ -375,7 +375,6 @@ public class CellTreeView extends Composite{ @Override public void onComplete() { others = getResult(); - GSS.get().removeGlassPanel(); } @Override diff --git a/web_client/src/gr/grnet/pithos/web/client/Configuration.java b/web_client/src/gr/grnet/pithos/web/client/Configuration.java index 5da52b4..003d80a 100644 --- a/web_client/src/gr/grnet/pithos/web/client/Configuration.java +++ b/web_client/src/gr/grnet/pithos/web/client/Configuration.java @@ -46,7 +46,7 @@ public interface Configuration extends Constants { /** * @return the relative path of the API root URL */ - @DefaultStringValue("rest/") + @DefaultStringValue("/v1/") String apiPath(); /** diff --git a/web_client/src/gr/grnet/pithos/web/client/Configuration.properties b/web_client/src/gr/grnet/pithos/web/client/Configuration.properties index a230d37..437de88 100644 --- a/web_client/src/gr/grnet/pithos/web/client/Configuration.properties +++ b/web_client/src/gr/grnet/pithos/web/client/Configuration.properties @@ -7,5 +7,5 @@ loginUrl=pithos/login logoutUrl=/Shibboleth.sso/Logout authCookie=_pithos_a cookieSeparator=| -apiPath=v1/ +apiPath=/v1/ version=2.0 \ No newline at end of file diff --git a/web_client/src/gr/grnet/pithos/web/client/DeleteGroupDialog.java b/web_client/src/gr/grnet/pithos/web/client/DeleteGroupDialog.java deleted file mode 100644 index 6238381..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/DeleteGroupDialog.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - -import gr.grnet.pithos.web.client.MessagePanel.Images; -import gr.grnet.pithos.web.client.rest.DeleteCommand; -import gr.grnet.pithos.web.client.rest.RestException; -import gr.grnet.pithos.web.client.rest.resource.GroupResource; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.user.client.DeferredCommand; -import com.google.gwt.user.client.Event.NativePreviewEvent; -import com.google.gwt.user.client.ui.AbstractImagePrototype; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.DialogBox; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.TreeItem; -import com.google.gwt.user.client.ui.VerticalPanel; - -/** - * The 'delete group' dialog box. - */ -public class DeleteGroupDialog extends DialogBox { - - /** - * The widget's constructor. - * @param images the supplied images - */ - public DeleteGroupDialog(final Images images) { - // Use this opportunity to set the dialog's caption. - setText("Delete group"); - setAnimationEnabled(true); - final GroupResource group = (GroupResource) GSS.get().getCurrentSelection(); - // Create a VerticalPanel to contain the 'about' label and the 'OK' - // button. - final VerticalPanel outer = new VerticalPanel(); - final HorizontalPanel buttons = new HorizontalPanel(); - - // Create the 'about' text and set a style name so we can style it with - // CSS. - final HTML text = new HTML("
" + AbstractImagePrototype.create(images.warn()).getHTML() + "" + "Are you sure you want to delete group '" + group.getName() + "'?
"); - text.setStyleName("pithos-warnMessage"); - outer.add(text); - - // Create the 'Quit' button, along with a listener that hides the dialog - // when the button is clicked and quits the application. - final Button ok = new Button("OK", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - deleteGroup(); - hide(); - } - }); - ok.getElement().setId("deleteGroup.button.ok"); - buttons.add(ok); - buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); - // Create the 'Cancel' button, along with a listener that hides the - // dialog - // when the button is clicked. - final Button cancel = new Button("Cancel", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - hide(); - } - }); - cancel.getElement().setId("deleteGroup.button.cancel"); - buttons.add(cancel); - buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - buttons.setSpacing(8); - buttons.setStyleName("pithos-warnMessage"); - outer.setStyleName("pithos-warnMessage"); - outer.add(buttons); - outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); - outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); - setWidget(outer); - } - - /** - * Generate an RPC request to delete a group. - * - * @param userId the ID of the current user - */ - private void deleteGroup() { - final TreeItem group = GSS.get().getGroups().getCurrent(); - if (group == null) { - GSS.get().displayError("No group was selected!"); - return; - } - DeleteCommand dg = new DeleteCommand(((GroupResource)group.getUserObject()).getUri()){ - @Override - public void onComplete() { - GSS.get().getGroups().updateGroups(); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if(t instanceof RestException){ - int statusCode = ((RestException)t).getHttpStatusCode(); - if(statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if(statusCode == 404) - GSS.get().displayError("Group not found"); - else - GSS.get().displayError("Unable to delete group:"+((RestException)t).getHttpStatusText()); - } - else - GSS.get().displayError("System error unable to delete group:"+t.getMessage()); - } - }; - DeferredCommand.addCommand(dg); - } - - - @Override - protected void onPreviewNativeEvent(NativePreviewEvent preview) { - super.onPreviewNativeEvent(preview); - - NativeEvent evt = preview.getNativeEvent(); - if (evt.getType().equals("keydown")) - // Use the popup's key preview hooks to close the dialog when either - // enter or escape is pressed. - switch (evt.getKeyCode()) { - case KeyCodes.KEY_ENTER: - hide(); - deleteGroup(); - break; - case KeyCodes.KEY_ESCAPE: - hide(); - break; - } - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/DeleteUserDialog.java b/web_client/src/gr/grnet/pithos/web/client/DeleteUserDialog.java deleted file mode 100644 index bca5f4a..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/DeleteUserDialog.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - -import gr.grnet.pithos.web.client.MessagePanel.Images; -import gr.grnet.pithos.web.client.rest.DeleteCommand; -import gr.grnet.pithos.web.client.rest.RestException; -import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.user.client.DeferredCommand; -import com.google.gwt.user.client.Event.NativePreviewEvent; -import com.google.gwt.user.client.ui.AbstractImagePrototype; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.DialogBox; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.TreeItem; -import com.google.gwt.user.client.ui.VerticalPanel; - - -public class DeleteUserDialog extends DialogBox { - - /** - * The widget's constructor. - * @param images the supplied images - */ - public DeleteUserDialog(final Images images) { - // Use this opportunity to set the dialog's caption. - setText("Delete user"); - setAnimationEnabled(true); - final GroupUserResource group = (GroupUserResource) GSS.get().getCurrentSelection(); - // Create a VerticalPanel to contain the 'about' label and the 'OK' - // button. - final VerticalPanel outer = new VerticalPanel(); - final HorizontalPanel buttons = new HorizontalPanel(); - - // Create the 'about' text and set a style name so we can style it with - // CSS. - final HTML text = new HTML("
" + AbstractImagePrototype.create(images.warn()).getHTML() + "" + "Are you sure you want to remove user '" + group.getName() + "'?
"); - text.setStyleName("pithos-warnMessage"); - outer.add(text); - - // Create the 'Quit' button, along with a listener that hides the dialog - // when the button is clicked and quits the application. - final Button ok = new Button("OK", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - deleteUser(); - hide(); - } - }); - ok.getElement().setId("deleteUser.button.ok"); - buttons.add(ok); - buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); - // Create the 'Cancel' button, along with a listener that hides the - // dialog - // when the button is clicked. - final Button cancel = new Button("Cancel", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - hide(); - } - }); - cancel.getElement().setId("confirmation.button.cancel"); - buttons.add(cancel); - buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - buttons.setSpacing(8); - buttons.setStyleName("pithos-warnMessage"); - outer.setStyleName("pithos-warnMessage"); - outer.add(buttons); - outer.setCellHorizontalAlignment(text, HasHorizontalAlignment.ALIGN_CENTER); - outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); - setWidget(outer); - } - - /** - * Generate an RPC request to delete a group. - * - * @param userId the ID of the current user - */ - private void deleteUser() { - final TreeItem user = GSS.get().getGroups().getCurrent(); - final TreeItem group = user.getParentItem(); - if (group == null) { - GSS.get().displayError("No user was selected!"); - return; - } - final GroupUserResource memberR = (GroupUserResource) user.getUserObject(); - DeleteCommand du = new DeleteCommand(memberR.getUri()){ - - @Override - public void onComplete() { - GSS.get().getGroups().updateGroups(); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if(t instanceof RestException){ - int statusCode = ((RestException)t).getHttpStatusCode(); - if(statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if(statusCode == 404) - GSS.get().displayError("User not found"); - else - GSS.get().displayError("Unable to delete user:"+((RestException)t).getHttpStatusText()); - } - else - GSS.get().displayError("System error unable to delete user:"+t.getMessage()); - } - }; - DeferredCommand.addCommand(du); - - } - - @Override - protected void onPreviewNativeEvent(NativePreviewEvent preview) { - super.onPreviewNativeEvent(preview); - - NativeEvent evt = preview.getNativeEvent(); - if (evt.getType().equals("keydown")) - // Use the popup's key preview hooks to close the dialog when either - // enter or escape is pressed. - switch (evt.getKeyCode()) { - case KeyCodes.KEY_ENTER: - hide(); - deleteUser(); - break; - case KeyCodes.KEY_ESCAPE: - hide(); - break; - } - } - -} - diff --git a/web_client/src/gr/grnet/pithos/web/client/EditMenu.java b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java index 71355a3..d45428f 100644 --- a/web_client/src/gr/grnet/pithos/web/client/EditMenu.java +++ b/web_client/src/gr/grnet/pithos/web/client/EditMenu.java @@ -133,8 +133,6 @@ public class EditMenu extends PopupPanel implements ClickHandler { hide(); if(GSS.get().isFileListShowing()) GSS.get().getFileList().selectAllRows(); - else if(GSS.get().isSearchResultsShowing()) - GSS.get().getSearchResults().selectAllRows(); } }; final Command unselectAllCommand = new Command() { @@ -144,8 +142,6 @@ public class EditMenu extends PopupPanel implements ClickHandler { hide(); if(GSS.get().isFileListShowing()) GSS.get().getFileList().clearSelectedRows(); - else if(GSS.get().isSearchResultsShowing()) - GSS.get().getSearchResults().clearSelectedRows(); } }; diff --git a/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java index 5b32aad..db883ed 100644 --- a/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java +++ b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java @@ -156,8 +156,6 @@ public class FileContextMenu extends PopupPanel implements ClickHandler { hide(); if(GSS.get().isFileListShowing()) GSS.get().getFileList().clearSelectedRows(); - else if(GSS.get().isSearchResultsShowing()) - GSS.get().getSearchResults().clearSelectedRows(); } }; cutItem = new MenuItem("" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut", true, new CutCommand(this)); diff --git a/web_client/src/gr/grnet/pithos/web/client/GSS.java b/web_client/src/gr/grnet/pithos/web/client/GSS.java index bd1e28a..db35fd4 100644 --- a/web_client/src/gr/grnet/pithos/web/client/GSS.java +++ b/web_client/src/gr/grnet/pithos/web/client/GSS.java @@ -3,9 +3,15 @@ */ package gr.grnet.pithos.web.client; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.user.client.ui.DockPanel; +import com.google.gwt.user.client.ui.HasVerticalAlignment; import gr.grnet.pithos.web.client.clipboard.Clipboard; import gr.grnet.pithos.web.client.commands.GetUserCommand; -import gr.grnet.pithos.web.client.rest.GetCommand; +import gr.grnet.pithos.web.client.foldertree.AccountResource; +import gr.grnet.pithos.web.client.foldertree.FolderTreeView; +import gr.grnet.pithos.web.client.rest.GetRequest; import gr.grnet.pithos.web.client.rest.RestException; import gr.grnet.pithos.web.client.rest.resource.FileResource; import gr.grnet.pithos.web.client.rest.resource.OtherUserResource; @@ -27,8 +33,6 @@ import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; -import com.google.gwt.event.logical.shared.ValueChangeEvent; -import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.http.client.URL; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.resources.client.ClientBundle; @@ -42,13 +46,12 @@ import com.google.gwt.user.client.History; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.google.gwt.user.client.ui.DecoratedTabPanel; -import com.google.gwt.user.client.ui.DockPanel; import com.google.gwt.user.client.ui.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HorizontalSplitPanel; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.TabPanel; import com.google.gwt.user.client.ui.VerticalPanel; + /** * Entry point classes define onModuleLoad(). */ @@ -67,13 +70,15 @@ public class GSS implements EntryPoint, ResizeHandler { */ private static Images images = (Images) GWT.create(Images.class); - private GlassPanel glassPanel = new GlassPanel(); + public String getUsername() { + return username; + } - /** + /** * An aggregate image bundle that pulls together all the images for this * application into a single bundle. */ - public interface Images extends ClientBundle, TopPanel.Images, StatusPanel.Images, FileMenu.Images, EditMenu.Images, SettingsMenu.Images, GroupMenu.Images, FilePropertiesDialog.Images, MessagePanel.Images, FileList.Images, SearchResults.Images, Search.Images, Groups.Images, CellTreeView.Images { + public interface Images extends ClientBundle, TopPanel.Images, StatusPanel.Images, FileMenu.Images, EditMenu.Images, SettingsMenu.Images, FilePropertiesDialog.Images, MessagePanel.Images, FileList.Images, Search.Images, CellTreeView.Images { @Source("gr/grnet/pithos/resources/document.png") ImageResource folders(); @@ -134,16 +139,6 @@ public class GSS implements EntryPoint, ResizeHandler { private FileList fileList; /** - * The group list widget. - */ - private Groups groups = new Groups(images); - - /** - * The search result widget. - */ - private SearchResults searchResults; - - /** * The tab panel that occupies the right side of the screen. */ private TabPanel inner = new DecoratedTabPanel(){ @@ -153,10 +148,6 @@ public class GSS implements EntryPoint, ResizeHandler { if(isFileListShowing()){ getFileList().showContextMenu(event); } - else if(isUserListVisible()){ - getGroups().setCurrent(null); - getGroups().showPopup(event.getClientX(),event.getClientY()); - } } }; }; @@ -187,33 +178,38 @@ public class GSS implements EntryPoint, ResizeHandler { */ private Object currentSelection; - /** - * The authentication token of the current user. - */ - private String token; /** * The WebDAV password of the current user */ private String webDAVPassword; - - public HashMap userFullNameMap = new HashMap(); + private String username = null; + + /** + * The authentication token of the current user. + */ + private String token; + + private FolderTreeView folderTreeView = new FolderTreeView(); + @Override public void onModuleLoad() { // Initialize the singleton before calling the constructors of the // various widgets that might call GSS.get(). singleton = this; - RootPanel.get().add(glassPanel, 0, 0); - parseUserCredentials(); - - topPanel = new TopPanel(GSS.images); - topPanel.setWidth("100%"); + if (parseUserCredentials()) + initialize(); + } - messagePanel.setWidth("100%"); - messagePanel.setVisible(false); + private void initialize() { + topPanel = new TopPanel(GSS.images); + topPanel.setWidth("100%"); + + messagePanel.setWidth("100%"); + messagePanel.setVisible(false); search = new Search(images); searchStatus.add(search, DockPanel.WEST); @@ -223,191 +219,106 @@ public class GSS implements EntryPoint, ResizeHandler { searchStatus.setCellVerticalAlignment(userDetailsPanel, HasVerticalAlignment.ALIGN_MIDDLE); searchStatus.setWidth("100%"); - fileList = new FileList(images); - - searchResults = new SearchResults(images); - - // Inner contains the various lists. - inner.sinkEvents(Event.ONCONTEXTMENU); - inner.setAnimationEnabled(true); - inner.getTabBar().addStyleName("pithos-MainTabBar"); - inner.getDeckPanel().addStyleName("pithos-MainTabPanelBottom"); - inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true); - - inner.add(groups, createHeaderHTML(AbstractImagePrototype.create(images.groups()), "Groups"), true); - inner.add(searchResults, createHeaderHTML(AbstractImagePrototype.create(images.search()), "Search Results"), true); - //inner.add(new CellTreeView(images), createHeaderHTML(AbstractImagePrototype.create(images.search()), "Cell tree sample"), true); - inner.setWidth("100%"); - inner.selectTab(0); - - inner.addSelectionHandler(new SelectionHandler() { - - @Override - public void onSelection(SelectionEvent event) { - int tabIndex = event.getSelectedItem(); -// TreeItem treeItem = GSS.get().getFolders().getCurrent(); - switch (tabIndex) { - case 0: -// Files tab selected - //fileList.clearSelectedRows(); - fileList.updateCurrentlyShowingStats(); - break; - case 1: -// Groups tab selected - groups.updateCurrentlyShowingStats(); - updateHistory("Groups"); - break; - case 2: -// Search tab selected - searchResults.clearSelectedRows(); - searchResults.updateCurrentlyShowingStats(); - updateHistory("Search"); - break; - } - } - }); -// If the application starts with no history token, redirect to a new "Files" state - String initToken = History.getToken(); - if(initToken.length() == 0) - History.newItem("Files"); -// Add history listener to handle any history events - History.addValueChangeHandler(new ValueChangeHandler() { - @Override - public void onValueChange(ValueChangeEvent event) { - String tokenInput = event.getValue(); - String historyToken = handleSpecialFolderNames(tokenInput); - try { - if(historyToken.equals("Search")) - inner.selectTab(2); - else if(historyToken.equals("Groups")) - inner.selectTab(1); - else if(historyToken.equals("Files")|| historyToken.length()==0) - inner.selectTab(0); - else { - /*TODO: CELLTREE - PopupTree popupTree = GSS.get().getFolders().getPopupTree(); - TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken); - SelectionEvent.fire(popupTree, treeObj); - */ - } - } catch (IndexOutOfBoundsException e) { - inner.selectTab(0); - } - } - }); - - // Add the left and right panels to the split panel. - splitPanel.setLeftWidget(treeView); - splitPanel.setRightWidget(inner); - splitPanel.setSplitPosition("25%"); - splitPanel.setSize("100%", "100%"); - splitPanel.addStyleName("pithos-splitPanel"); - - // Create a dock panel that will contain the menu bar at the top, - // the shortcuts to the left, the status bar at the bottom and the - // right panel taking the rest. - VerticalPanel outer = new VerticalPanel(); - outer.add(topPanel); + fileList = new FileList(images); + + // Inner contains the various lists. + inner.sinkEvents(Event.ONCONTEXTMENU); + inner.setAnimationEnabled(true); + inner.getTabBar().addStyleName("pithos-MainTabBar"); + inner.getDeckPanel().addStyleName("pithos-MainTabPanelBottom"); + inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true); + + inner.setWidth("100%"); + inner.selectTab(0); + + inner.addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + int tabIndex = event.getSelectedItem(); + switch (tabIndex) { + case 0: + fileList.updateCurrentlyShowingStats(); + break; + } + } + }); + + // Add the left and right panels to the split panel. + splitPanel.setLeftWidget(folderTreeView); + splitPanel.setRightWidget(inner); + splitPanel.setSplitPosition("25%"); + splitPanel.setSize("100%", "100%"); + splitPanel.addStyleName("pithos-splitPanel"); + + // Create a dock panel that will contain the menu bar at the top, + // the shortcuts to the left, the status bar at the bottom and the + // right panel taking the rest. + VerticalPanel outer = new VerticalPanel(); + outer.add(topPanel); outer.add(searchStatus); - outer.add(messagePanel); - outer.add(splitPanel); - outer.add(statusPanel); - outer.setWidth("100%"); - outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); - - outer.setSpacing(4); - - // Hook the window resize event, so that we can adjust the UI. - Window.addResizeHandler(this); - // Clear out the window's built-in margin, because we want to take - // advantage of the entire client area. - Window.setMargin("0px"); - // Finally, add the outer panel to the RootPanel, so that it will be - // displayed. - RootPanel.get().add(outer); - // Call the window resized handler to get the initial sizes setup. Doing - // this in a deferred command causes it to occur after all widgets' - // sizes have been computed by the browser. - DeferredCommand.addCommand(new Command() { - - @Override - public void execute() { - onWindowResized(Window.getClientHeight()); - } - }); - } - - /** - * Fetches the User object for the specified username. - * - * @param username the username of the user - */ - private void fetchUser(final String username) { - String path = getApiPath() + username + "/"; - GetCommand getUserCommand = new GetCommand(UserResource.class, username, path, null) { - - @Override - public void onComplete() { - - currentUserResource = getResult(); - } - - @Override - public void onError(Throwable t) { - GWT.log("Fetching user error", t); - if (t instanceof RestException) - GSS.get().displayError("No user found:" + ((RestException) t).getHttpStatusText()); - else - GSS.get().displayError("System error fetching user data:" + t.getMessage()); - authenticateUser(); - } - }; - DeferredCommand.addCommand(getUserCommand); - } + outer.add(messagePanel); + outer.add(splitPanel); + outer.add(statusPanel); + outer.setWidth("100%"); + outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); + + outer.setSpacing(4); + + // Hook the window resize event, so that we can adjust the UI. + Window.addResizeHandler(this); + // Clear out the window's built-in margin, because we want to take + // advantage of the entire client area. + Window.setMargin("0px"); + // Finally, add the outer panel to the RootPanel, so that it will be + // displayed. + RootPanel.get().add(outer); + // Call the window resized handler to get the initial sizes setup. Doing + // this in a deferred command causes it to occur after all widgets' + // sizes have been computed by the browser. + DeferredCommand.addCommand(new Command() { + + @Override + public void execute() { + onWindowResized(Window.getClientHeight()); + } + }); + } /** * Parse and store the user credentials to the appropriate fields. */ - private void parseUserCredentials() { -// Configuration conf = (Configuration) GWT.create(Configuration.class); -// String cookie = conf.authCookie(); -// String auth = Cookies.getCookie(cookie); -// if (auth == null) { -// authenticateUser(); -// // Redundant, but silences warnings about possible auth NPE, below. -// return; -// } -// int sepIndex = auth.indexOf(conf.cookieSeparator()); -// if (sepIndex == -1) -// authenticateUser(); -// token = auth.substring(sepIndex + 1); -// final String username = auth.substring(0, sepIndex); -// if (username == null) -// authenticateUser(); -// -// refreshWebDAVPassword(); - - final String username = "test"; - DeferredCommand.addCommand(new Command() { - - @Override - public void execute() { - fetchUser(username); - } - }); + private boolean parseUserCredentials() { + Configuration conf = (Configuration) GWT.create(Configuration.class); + String cookie = conf.authCookie(); + String auth = Cookies.getCookie(cookie); + if (auth == null) { + authenticateUser(); + return false; + } + else { + String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); + if (authSplit.length != 2) { + authenticateUser(); + return false; + } + else { + username = authSplit[0]; + token = authSplit[1]; + return true; + } + } } - /** + /** * Redirect the user to the login page for authentication. */ protected void authenticateUser() { -// Configuration conf = (Configuration) GWT.create(Configuration.class); - //IMPORTANT: Temporary circumvention of the Shiboleth login process for development and testing - //Some time in the future the comment line will be restored - + Configuration conf = (Configuration) GWT.create(Configuration.class); + // Window.Location.assign(GWT.getModuleBaseURL() + conf.loginUrl() + "?next=" + Window.Location.getHref()); -// Cookies.setCookie(conf.authCookie(), "chstath@ebs.gr" + conf.cookieSeparator() + "triapoulakiakathontan"); -// Window.Location.assign(GWT.getModuleBaseURL()); + Cookies.setCookie(conf.authCookie(), "demo" + conf.cookieSeparator() + "0000"); + Window.Location.assign(GWT.getModuleBaseURL() + "GSS.html"); } /** @@ -447,9 +358,6 @@ public class GSS implements EntryPoint, ResizeHandler { newHeight = 1; splitPanel.setHeight("" + newHeight); inner.setHeight("" + newHeight); - /*if(isFileListShowing()){ - getFileList().setHeight("" + (newHeight-50)); - }*/ } @Override @@ -500,9 +408,9 @@ public class GSS implements EntryPoint, ResizeHandler { RestResource currentFolder = getTreeView().getSelection(); if(currentFolder!=null){ showFileList(currentFolder); - } } - + } + } public void showFileList(RestResource r) { @@ -538,17 +446,6 @@ public class GSS implements EntryPoint, ResizeHandler { } /** - * Make the search results visible. - * - * @param query the search query string - */ - public void showSearchResults(String query) { - searchResults.updateFileCache(query); - searchResults.updateCurrentlyShowingStats(); - inner.selectTab(2); - } - - /** * Display the 'loading' indicator. */ public void showLoadingIndicator(String message, String path) { @@ -651,15 +548,6 @@ public class GSS implements EntryPoint, ResizeHandler { } /** - * Retrieve the groups. - * - * @return the groups - */ - public Groups getGroups() { - return groups; - } - - /** * Retrieve the fileList. * * @return the fileList @@ -668,10 +556,6 @@ public class GSS implements EntryPoint, ResizeHandler { return fileList; } - public SearchResults getSearchResults() { - return searchResults; - } - /** * Retrieve the topPanel. * @@ -713,10 +597,6 @@ public class GSS implements EntryPoint, ResizeHandler { return webDAVPassword; } - public void removeGlassPanel() { - glassPanel.removeFromParent(); - } - /** * Retrieve the currentUserResource. * @@ -749,7 +629,7 @@ public class GSS implements EntryPoint, ResizeHandler { */ public String getApiPath() { Configuration conf = (Configuration) GWT.create(Configuration.class); - return GWT.getModuleBaseURL() + conf.apiPath(); + return conf.apiPath(); } /** @@ -846,6 +726,4 @@ public class GSS implements EntryPoint, ResizeHandler { } } - - } diff --git a/web_client/src/gr/grnet/pithos/web/client/GroupContextMenu.java b/web_client/src/gr/grnet/pithos/web/client/GroupContextMenu.java deleted file mode 100644 index 7a7feb3..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/GroupContextMenu.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - -import gr.grnet.pithos.web.client.Groups.Images; -import gr.grnet.pithos.web.client.commands.CopyCommand; -import gr.grnet.pithos.web.client.commands.DeleteUserOrGroupCommand; -import gr.grnet.pithos.web.client.commands.NewGroupCommand; -import gr.grnet.pithos.web.client.commands.NewUserCommand; -import gr.grnet.pithos.web.client.commands.PasteCommand; -import gr.grnet.pithos.web.client.rest.resource.GroupResource; -import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; - -import com.google.gwt.user.client.ui.AbstractImagePrototype; -import com.google.gwt.user.client.ui.MenuBar; -import com.google.gwt.user.client.ui.MenuItem; -import com.google.gwt.user.client.ui.PopupPanel; -import com.google.gwt.user.client.ui.TreeItem; - - -public class GroupContextMenu extends PopupPanel { - - /** - * The widget's images. - */ - private final Images images; - private MenuItem copy; - private MenuItem paste; - private MenuItem newGroup; - private MenuItem addUser; - private MenuItem delete; - public GroupContextMenu(final Images newImages) { - // The popup's constructor's argument is a boolean specifying that it - // auto-close itself when the user clicks outside of it. - super(true); - images=newImages; - setAnimationEnabled(true); - final MenuBar contextMenu = new MenuBar(true); - newGroup = new MenuItem("" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + " New Group", true, new NewGroupCommand(this)); - newGroup.getElement().setId("groupContextMenu.newGroup"); - contextMenu.addItem(newGroup); - - addUser = new MenuItem("" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + " Add User", true, new NewUserCommand(this)); - addUser.getElement().setId("groupContextMenu.addUser"); - contextMenu.addItem(addUser); - - copy = new MenuItem("" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy User", true, new CopyCommand(this)); - copy.getElement().setId("groupContextMenu.copyUser"); - contextMenu.addItem(copy); - - paste = new MenuItem("" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste User", true, new PasteCommand(this)); - paste.getElement().setId("groupContextMenu.pasteUser"); - contextMenu.addItem(paste); - - delete = new MenuItem("" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete", true, new DeleteUserOrGroupCommand(this,images)); - delete.getElement().setId("groupContextMenu.delete"); - contextMenu.addItem(delete); - - add(contextMenu); - - } - - /* (non-Javadoc) - * @see com.google.gwt.user.client.ui.PopupPanel#show() - */ - @Override - public void show() { - TreeItem current = GSS.get().getGroups().getCurrent(); - if(current==null){ - copy.setVisible(false); - paste.setVisible(false); - addUser.setVisible(false); - delete.setVisible(false); - } - else{ - newGroup.setVisible(false); - if(current.getUserObject() instanceof GroupUserResource && GSS.get().getCurrentSelection() instanceof GroupUserResource) - copy.setVisible(true); - else - copy.setVisible(false); - if(current.getUserObject() instanceof GroupResource && GSS.get().getCurrentSelection() instanceof GroupResource && GSS.get().getClipboard().hasUserItem()) - paste.setVisible(true); - else - paste.setVisible(false); - } - super.show(); - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/GroupMenu.java b/web_client/src/gr/grnet/pithos/web/client/GroupMenu.java deleted file mode 100644 index c8ff109..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/GroupMenu.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - -import gr.grnet.pithos.web.client.commands.NewGroupCommand; - -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.ImageResource; -import com.google.gwt.user.client.ui.AbstractImagePrototype; -import com.google.gwt.user.client.ui.MenuBar; -import com.google.gwt.user.client.ui.MenuItem; -import com.google.gwt.user.client.ui.PopupPanel; - -/** - * The 'Group' menu implementation. - */ -public class GroupMenu extends PopupPanel implements ClickHandler { - /** - * The widget's images. - */ - private Images images; - private final MenuBar contextMenu; - - /** - * An image bundle for this widgets images. - */ - public interface Images extends ClientBundle { - @Source("gr/grnet/pithos/resources/groupevent.png") - ImageResource groupNew(); - - @Source("gr/grnet/pithos/resources/view_text.png") - ImageResource viewText(); - - } - - /** - * The widget's constructor. - * - * @param newImages the image bundle passed on by the parent object - */ - public GroupMenu(final Images newImages) { - // The popup's constructor's argument is a boolean specifying that it - // auto-close itself when the user clicks outside of it. - super(true); - setAnimationEnabled(true); - images = newImages; - - contextMenu = new MenuBar(true); - MenuItem newGroupItem = new MenuItem("" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + " New Group", true, new NewGroupCommand(this)); - newGroupItem.getElement().setId("topMenu.group.newGroup"); - contextMenu.addItem(newGroupItem); - - add(contextMenu); - } - - @Override - public void onClick(ClickEvent event) { - GroupMenu menu = new GroupMenu(images); - int left = event.getRelativeElement().getAbsoluteLeft(); - int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); - menu.setPopupPosition(left, top); - - menu.show(); - } - - /** - * Retrieve the contextMenu. - * - * @return the contextMenu - */ - public MenuBar getContextMenu() { - contextMenu.setAutoOpen(false); - return contextMenu; - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/GroupPropertiesDialog.java b/web_client/src/gr/grnet/pithos/web/client/GroupPropertiesDialog.java deleted file mode 100644 index a74f43e..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/GroupPropertiesDialog.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - -import gr.grnet.pithos.web.client.rest.PostCommand; -import gr.grnet.pithos.web.client.rest.RestException; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.http.client.URL; -import com.google.gwt.user.client.DeferredCommand; -import com.google.gwt.user.client.Event.NativePreviewEvent; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.DialogBox; -import com.google.gwt.user.client.ui.Grid; -import com.google.gwt.user.client.ui.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.TextBox; -import com.google.gwt.user.client.ui.VerticalPanel; - -public class GroupPropertiesDialog extends DialogBox { - - /** - * The widget that holds the folderName of the folder. - */ - private TextBox groupName = new TextBox(); - - /** - * A flag that denotes whether the dialog will be used to create or modify a - * folder. - */ - private final boolean create; - - /** - * The widget's constructor. - * - * @param _create true if the dialog is displayed for creating a new - * sub-folder of the selected folder, false if it is displayed - * for modifying the selected folder - */ - public GroupPropertiesDialog(final boolean _create) { - setAnimationEnabled(true); - create = _create; - // Use this opportunity to set the dialog's caption. - if (create) - setText("Create Group"); - else - setText("Group properties"); - final VerticalPanel panel = new VerticalPanel(); - setWidget(panel); - groupName.getElement().setId("groupDialog.textBox.name"); - final Grid generalTable = new Grid(1, 2); - generalTable.setText(0, 0, "Group Name"); - generalTable.setWidget(0, 1, groupName); - generalTable.getCellFormatter().setStyleName(0, 0, "props-labels"); - generalTable.getCellFormatter().setStyleName(0, 1, "props-values"); - generalTable.setCellSpacing(4); - - panel.add(generalTable); - final HorizontalPanel buttons = new HorizontalPanel(); - final Button ok = new Button("OK", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - createGroup(groupName.getText()); - hide(); - } - }); - ok.getElement().setId("groupDialog.button.ok"); - buttons.add(ok); - buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); - // Create the 'Cancel' button, along with a listener that hides the - // dialog - // when the button is clicked. - final Button cancel = new Button("Cancel", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - hide(); - } - }); - cancel.getElement().setId("groupDialog.button.cancel"); - buttons.add(cancel); - buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - buttons.setSpacing(8); - buttons.addStyleName("pithos-TabPanelBottom"); - panel.add(buttons); - panel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); - //panel.addStyleName("pithos-DialogBox"); - panel.addStyleName("pithos-TabPanelBottom"); - } - @Override - public void center() { - super.center(); - groupName.setFocus(true); - } - - @Override - protected void onPreviewNativeEvent(NativePreviewEvent preview) { - super.onPreviewNativeEvent(preview); - - NativeEvent evt = preview.getNativeEvent(); - if (evt.getType().equals("keydown")) - // Use the popup's key preview hooks to close the dialog when either - // enter or escape is pressed. - switch (evt.getKeyCode()) { - case KeyCodes.KEY_ENTER: - hide(); - createGroup( groupName.getText()); - break; - case KeyCodes.KEY_ESCAPE: - hide(); - break; - } - } - - - /** - * Generate an RPC request to create a new group. - * - * @param userId the ID of the user whose namespace will be searched for - * groups - * @param aGroupName the name of the group to create - */ - private void createGroup(String aGroupName) { - - if (aGroupName == null || aGroupName.length() == 0) { - GSS.get().displayError("Empty group name!"); - return; - } - GWT.log("createGroup(" + aGroupName + ")", null); - PostCommand cg = new PostCommand(GSS.get().getCurrentUserResource().getGroupsPath()+"?name="+URL.encodeComponent(aGroupName), "", 201){ - - @Override - public void onComplete() { - GSS.get().getGroups().updateGroups(); - GSS.get().showUserList(); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if(t instanceof RestException){ - int statusCode = ((RestException)t).getHttpStatusCode(); - if(statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if(statusCode == 404) - GSS.get().displayError("Resource does not exist"); - else if(statusCode == 409) - GSS.get().displayError("A group with the same name already exists"); - else if(statusCode == 413) - GSS.get().displayError("Your quota has been exceeded"); - else - GSS.get().displayError("Unable to create group:"+((RestException)t).getHttpStatusText()); - } - else - GSS.get().displayError("System error creating group:"+t.getMessage()); - } - }; - DeferredCommand.addCommand(cg); - - } -} diff --git a/web_client/src/gr/grnet/pithos/web/client/Groups.java b/web_client/src/gr/grnet/pithos/web/client/Groups.java deleted file mode 100644 index 732418e..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/Groups.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - -import gr.grnet.pithos.web.client.rest.GetCommand; -import gr.grnet.pithos.web.client.rest.MultipleGetCommand; -import gr.grnet.pithos.web.client.rest.resource.GroupResource; -import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; -import gr.grnet.pithos.web.client.rest.resource.GroupsResource; - -import java.util.List; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.event.dom.client.ContextMenuEvent; -import com.google.gwt.event.dom.client.ContextMenuHandler; -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.resources.client.ClientBundle; -import com.google.gwt.resources.client.ImageResource; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.DeferredCommand; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.ui.AbstractImagePrototype; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.Tree; -import com.google.gwt.user.client.ui.TreeItem; - -/** - * A component that displays a list of the user's groups. - */ -public class Groups extends Composite implements SelectionHandler, OpenHandler { - - /** - * An image bundle for this widget. - */ - public interface Images extends Tree.Resources, ClientBundle, FileMenu.Images, EditMenu.Images, GroupMenu.Images, MessagePanel.Images { - - /** - * Will bundle the file 'groupevent.png' residing in the package - * 'gr.grnet.pithos.web.resources'. - * - * @return the image prototype - */ - @Source("gr/grnet/pithos/resources/groupevent.png") - ImageResource groupImage(); - - @Override - @Source("gr/grnet/pithos/resources/editdelete.png") - ImageResource delete(); - - } - - /** - * cached latest group selection (for selecting and expanding on refresh) - */ - private String selectedGroup = null; - - /** - * The tree widget that displays the groups. - */ - private Tree tree; - - /** - * A cached copy of the currently selected group widget. - */ - private TreeItem current; - - /** - * A cached copy of the previously selected group widget. - */ - private TreeItem previous; - - /** - * The widget's image bundle. - */ - private final Images images; - - private GroupContextMenu menu; - - /** - * Constructs a new groups widget with a bundle of images. - * - * @param newImages a bundle that provides the images for this widget - */ - public Groups(final Images newImages) { - - images = newImages; - menu = new GroupContextMenu(images); - tree = new Tree(newImages); - this.addHandler(new ContextMenuHandler() { - - @Override - public void onContextMenu(ContextMenuEvent event) { - if(current==null) return; - int left = current.getAbsoluteLeft() + 40; - int top = current.getAbsoluteTop() + 20; - showPopup(left, top); - - } - }, ContextMenuEvent.getType()); - tree.getElement().setId("groupsList.tree"); - tree.addSelectionHandler(this); - tree.addOpenHandler(this); - tree.setAnimationEnabled(true); - initWidget(tree); - this.getElement().setAttribute("id", "CreativeFilesPanel"); - setStylePrimaryName("pithos-Groups"); - sinkEvents(Event.ONCONTEXTMENU); - sinkEvents(Event.ONMOUSEUP); - sinkEvents(Event.ONDBLCLICK); - sinkEvents(Event.KEYEVENTS); - } - - - /** - * Make an RPC call to retrieve the groups that belong to the specified - * user. - */ - public void updateGroups() { - GetCommand gg = new GetCommand(GroupsResource.class, GSS.get().getCurrentUserResource().getGroupsPath(),null){ - - @Override - public void onComplete() { - GroupsResource res = getResult(); - MultipleGetCommand ga = new MultipleGetCommand(GroupResource.class, res.getGroupPaths().toArray(new String[]{}), null){ - - @Override - public void onComplete() { - List groupList = getResult(); - tree.clear(); - for (int i = 0; i < groupList.size(); i++) { - final TreeItem item = new TreeItem(); - item.setWidget(imageItemHTML(images.groupImage(), groupList.get(i).getName(),item)); - item.setUserObject(groupList.get(i)); - tree.addItem(item); - updateUsers(item); - } - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - } - - @Override - public void onError(String p, Throwable throwable) { - GWT.log("Path:"+p, throwable); - } - }; - DeferredCommand.addCommand(ga); - } - - @Override - public void onError(Throwable t) { - - } - }; - DeferredCommand.addCommand(gg); - } - - /** - * update status panel with currently showing file stats - */ - public void updateCurrentlyShowingStats() { - GSS.get().getStatusPanel().updateCurrentlyShowing(null); //clear stats - nothing to show for the groups tab - } - - /** - * A helper method to simplify adding tree items that have attached images. - * - * @param parent the tree item to which the new item will be added. - * @param title the text associated with this item. - * @param imageProto - * @return the new tree item - */ - private TreeItem addImageItem(final TreeItem parent, final String title, final ImageResource imageProto) { - final TreeItem item = new TreeItem(); - item.setWidget(imageItemHTML(imageProto, title,item)); - parent.addItem(item); - return item; - } - - /** - * Generates HTML for a tree item with an attached icon. - * - * @param imageProto the icon image - * @param title the title of the item - * @return the resultant HTML - */ - private HTML imageItemHTML(final ImageResource imageProto, final String title,final TreeItem item) { - final HTML link = new HTML("" + "" + AbstractImagePrototype.create(imageProto).getHTML() + " " + title + "" + ""){ - @Override - public void onBrowserEvent(Event event) { - switch (DOM.eventGetType(event)) { - case Event.ONMOUSEDOWN: - if (DOM.eventGetButton(event) == NativeEvent.BUTTON_RIGHT || DOM.eventGetButton(event) == NativeEvent.BUTTON_LEFT) - onSelection(item); - break; - case Event.ONCONTEXTMENU: - showPopup(event.getClientX(), event.getClientY()); - event.preventDefault(); - event.stopPropagation(); - break; - } - super.onBrowserEvent(event); - - } - }; - link.sinkEvents(Event.ONMOUSEDOWN); - link.sinkEvents(Event.ONCONTEXTMENU); - link.sinkEvents(Event.ONCLICK); - link.sinkEvents(Event.ONKEYDOWN); - return link; - } - - - - protected void showPopup(final int x, final int y) { - menu.hide(); - menu = new GroupContextMenu(images); - menu.setPopupPosition(x, y); - menu.show(); - } - - - - /** - * Generate an RPC request to retrieve the users of the specified group for - * display. - * - * @param groupItem the TreeItem widget that corresponds to the requested - * group - */ - void updateUsers(final TreeItem groupItem) { - if(groupItem.getUserObject() instanceof GroupResource){ - GroupResource res = (GroupResource) groupItem.getUserObject(); - MultipleGetCommand gu = new MultipleGetCommand(GroupUserResource.class, res.getUserPaths().toArray(new String[]{}), null){ - @Override - public void onComplete() { - List users = getResult(); - groupItem.removeItems(); - for (int i = 0; i < users.size(); i++) { - final TreeItem userItem = addImageItem(groupItem, users.get(i).getName() + " <" + users.get(i).getUsername() + ">", images.permUser()); - userItem.setUserObject(users.get(i)); - } - if (selectedGroup != null && groupItem.getText().equals(selectedGroup)) { - //SelectionEvent.fire(tree, groupItem);; - onSelection(groupItem); - groupItem.setState(true); - } - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - } - - @Override - public void onError(String p, Throwable throwable) { - GWT.log("Path:"+p, throwable); - } - }; - DeferredCommand.addCommand(gu); - } - - } - - /** - * Retrieve the current. - * - * @return the current - */ - TreeItem getCurrent() { - return current; - } - - /** - * Modify the current. - * - * @param newCurrent the current to set - */ - void setCurrent(final TreeItem newCurrent) { - current = newCurrent; - } - - /** - * Retrieve the previous. - * - * @return the previous - */ - private TreeItem getPrevious() { - return previous; - } - - /** - * Modify the previous. - * - * @param newPrevious the previous to set - */ - private void setPrevious(final TreeItem newPrevious) { - previous = newPrevious; - } - - @Override - public void setVisible(final boolean visible) { - super.setVisible(visible); - if (visible) - updateGroups(); - } - - @Override - public void onSelection(SelectionEvent event) { - final TreeItem item = (TreeItem)event.getSelectedItem(); - onSelection(item); - - } - - private void onSelection(TreeItem item){ - final Object selected = item.getUserObject(); - // Preserve the previously selected item, so that the current's - // onClick() method gets a chance to find it. - if (getPrevious() != null) - getPrevious().getWidget().removeStyleName("pithos-SelectedRow"); - setCurrent(item); - getCurrent().getWidget().addStyleName("pithos-SelectedRow"); - setPrevious(getCurrent()); - GSS.get().setCurrentSelection(selected); - //cache the latest top level node (group) for selecting and expanding on refresh - if (item.getParentItem() == null) - selectedGroup = item.getText(); - else - selectedGroup = item.getParentItem().getText(); - } - - @Override - public void onOpen(OpenEvent event) { - final TreeItem item = (TreeItem) event.getTarget(); - updateUsers(item); - } -} diff --git a/web_client/src/gr/grnet/pithos/web/client/Search.java b/web_client/src/gr/grnet/pithos/web/client/Search.java index 381851d..0b48efb 100644 --- a/web_client/src/gr/grnet/pithos/web/client/Search.java +++ b/web_client/src/gr/grnet/pithos/web/client/Search.java @@ -63,9 +63,7 @@ public class Search extends Composite implements FocusHandler,BlurHandler { @Override public void onKeyPress(KeyPressEvent event) { char keyCode = event.getCharCode(); - if (keyCode == '\r') - GSS.get().showSearchResults(tb.getText()); - else if (keyCode == 27) { + if (keyCode == 27) { // Simulate the proper behavior for the escape key // (27 == ESC). onLostFocus((Widget)event.getSource()); @@ -74,19 +72,10 @@ public class Search extends Composite implements FocusHandler,BlurHandler { } }); - Button b = new Button(createHeaderHTML(images.searchButton(), "Search"), new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - GSS.get().showSearchResults(tb.getText()); - } - }); - b.getElement().setId("button.search"); - HorizontalPanel panel = new HorizontalPanel(); panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); panel.add(tb); - panel.add(b); initWidget(panel); } diff --git a/web_client/src/gr/grnet/pithos/web/client/SearchResults.java b/web_client/src/gr/grnet/pithos/web/client/SearchResults.java deleted file mode 100644 index d576c2d..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/SearchResults.java +++ /dev/null @@ -1,853 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - - -import static com.google.gwt.query.client.GQuery.$; - -import gr.grnet.pithos.web.client.rest.GetCommand; -import gr.grnet.pithos.web.client.rest.RestCommand; -import gr.grnet.pithos.web.client.rest.RestException; -import gr.grnet.pithos.web.client.rest.resource.FileResource; -import gr.grnet.pithos.web.client.rest.resource.SearchResource; -import gr.grnet.pithos.web.client.rest.resource.TrashResource; -import gr.grnet.pithos.web.client.rest.resource.UserResource; -import gr.grnet.pithos.web.client.rest.resource.UserSearchResource; -import gwtquery.plugins.draggable.client.DraggableOptions; -import gwtquery.plugins.draggable.client.StopDragException; -import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction; -import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption; -import gwtquery.plugins.draggable.client.events.DragContext; -import gwtquery.plugins.draggable.client.events.DragStartEvent; -import gwtquery.plugins.draggable.client.events.DragStopEvent; -import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler; -import gwtquery.plugins.draggable.client.events.DragStopEvent.DragStopEventHandler; -import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable; -import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - -import com.google.gwt.cell.client.AbstractCell; -import com.google.gwt.cell.client.ImageResourceCell; -import com.google.gwt.cell.client.SafeHtmlCell; -import com.google.gwt.cell.client.TextCell; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.RepeatingCommand; -import com.google.gwt.dom.client.Style.Cursor; -import com.google.gwt.http.client.URL; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.ImageResource; -import com.google.gwt.safehtml.shared.SafeHtml; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; -import com.google.gwt.user.cellview.client.CellTable; -import com.google.gwt.user.cellview.client.GssSimplePager; -import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.DeferredCommand; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.AbstractImagePrototype; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.VerticalPanel; -import com.google.gwt.view.client.AsyncDataProvider; -import com.google.gwt.view.client.HasData; -import com.google.gwt.view.client.MultiSelectionModel; -import com.google.gwt.view.client.ProvidesKey; -import com.google.gwt.view.client.SelectionChangeEvent; -import com.google.gwt.view.client.SelectionChangeEvent.Handler; - -/** - * A composite that displays a list of search results for a particular query on - * files. - */ -public class SearchResults extends Composite{ - private HTML searchResults = new HTML("Results for search:"); - private String lastQuery; - SearchDataProvider provider = new SearchDataProvider(); - /** - * Specifies that the images available for this composite will be the ones - * available in FileContextMenu. - */ - public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images, FileList.Images { - - @Source("gr/grnet/pithos/resources/blank.gif") - ImageResource blank(); - - @Source("gr/grnet/pithos/resources/asc.png") - ImageResource asc(); - - @Source("gr/grnet/pithos/resources/desc.png") - ImageResource desc(); - } - - - interface TableResources extends DragAndDropCellTable.Resources { - @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"}) - TableStyle cellTableStyle(); - } - - /** - * The styles applied to the table. - */ - interface TableStyle extends CellTable.Style { - } - - private String showingStats = ""; - - private int startIndex = 0; - - /** - * A constant that denotes the completion of an IncrementalCommand. - */ - public static final boolean DONE = false; - - - - private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); - - - - DragStopEventHandler dragStop = new DragStopEventHandler() { - - @Override - public void onDragStop(DragStopEvent event) { - GWT.log("DRAG STOPPED"); - - } - }; - - private static class ContactCell extends AbstractCell { - - /** - * The html of the image used for contacts. - * - */ - private final String imageHtml; - - public ContactCell(ImageResource image) { - this.imageHtml = AbstractImagePrototype.create(image).getHTML(); - } - - - - - - @Override - public void render(Context context, FileResource value, SafeHtmlBuilder sb) { - // Value can be null, so do a null check.. - if (value == null) { - return; - } - - sb.append(FileList.Templates.INSTANCE.rendelContactCell(imageHtml, value.getName(), value.getFileSizeAsString())); - } - - - } - /** - * Retrieve the celltable. - * - * @return the celltable - */ - public DragAndDropCellTable getCelltable() { - return celltable; - } - - - - /** - * The number of files in this folder. - */ - int folderFileCount; - - /** - * Total folder size - */ - long folderTotalSize; - - /** - * A cache of the files in the list. - */ - private List files; - - /** - * The widget's image bundle. - */ - private final Images images; - - private FileContextMenu menuShowing; - private DragAndDropCellTable celltable; - private final MultiSelectionModel selectionModel; - - GssSimplePager pager; - GssSimplePager pagerTop; - /** - * Construct the file list widget. This entails setting up the widget - * layout, fetching the number of files in the current folder from the - * server and filling the local file cache of displayed files with data from - * the server, as well. - * - * @param _images - */ - public SearchResults(Images _images) { - images = _images; - DragAndDropCellTable.Resources resources = GWT.create(TableResources.class); - ProvidesKey keyProvider = new ProvidesKey(){ - - @Override - public Object getKey(FileResource item) { - return item.getUri(); - } - - }; - - celltable = new DragAndDropCellTable(GSS.VISIBLE_FILE_COUNT,resources,keyProvider){ - @Override - protected void onBrowserEvent2(Event event) { - /*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){ - fireClickEvent((Element) event.getEventTarget().cast()); - }*/ - super.onBrowserEvent2(event); - } - }; - provider.addDataDisplay(celltable); - celltable.addDragStopHandler(dragStop); - celltable.addDragStartHandler(new DragStartEventHandler() { - - public void onDragStart(DragStartEvent event) { - FileResource value = event.getDraggableData(); - - com.google.gwt.dom.client.Element helper = event.getHelper(); - SafeHtmlBuilder sb = new SafeHtmlBuilder(); - sb.appendHtmlConstant(""); - DisplayHelper.log(value.getName()); - if(getSelectedFiles().size()==1) - sb.appendEscaped(value.getName()); - else - sb.appendEscaped(getSelectedFiles().size()+" files"); - sb.appendHtmlConstant(""); - helper.setInnerHTML(sb.toSafeHtml().asString()); - - } - }); - DragAndDropColumn status = new DragAndDropColumn(new ImageResourceCell(){ - @Override - public boolean handlesSelection() { - return false; - } - }) { - @Override - public ImageResource getValue(FileResource entity) { - return getFileIcon(entity); - } - - }; - celltable.addColumn(status,""); - - initDragOperation(status); - final DragAndDropColumn nameColumn = new DragAndDropColumn(new SafeHtmlCell()) { - - - @Override - public SafeHtml getValue(FileResource object) { - SafeHtmlBuilder sb = new SafeHtmlBuilder(); - sb.append(FileList.Templates.INSTANCE.filenameSpan(object.getName())); - if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg") ){ - sb.appendHtmlConstant(" ").append(FileList.Templates.INSTANCE.viewLink(GSS.get().getTopPanel().getFileMenu().getDownloadURL(object), object.getOwner() + " : " + object.getPath() + object.getName())); - } - - return sb.toSafeHtml(); - } - - }; - initDragOperation(nameColumn); - celltable.addColumn(nameColumn,"Name"); - - DragAndDropColumn aColumn; - celltable.addColumn(aColumn=new DragAndDropColumn(new TextCell()) { - @Override - public String getValue(FileResource object) { - return GSS.get().findUserFullName(object.getOwner()); - } - },"Owner"); - initDragOperation(aColumn); - - celltable.addColumn(aColumn=new DragAndDropColumn(new TextCell()) { - @Override - public String getValue(FileResource object) { - if(object.isDeleted()) - return object.getPath()+" (In Trash)"; - return object.getPath(); - } - },"Path"); - initDragOperation(aColumn); - - - - celltable.addColumn(aColumn=new DragAndDropColumn(new TextCell()) { - @Override - public String getValue(FileResource object) { - return object.getVersion().toString(); - } - },"Version"); - initDragOperation(aColumn); - - - celltable.addColumn(aColumn=new DragAndDropColumn(new TextCell()) { - @Override - public String getValue(FileResource object) { - // TODO Auto-generated method stub - return object.getFileSizeAsString(); - } - },"Size"); - initDragOperation(aColumn); - - celltable.addColumn(aColumn=new DragAndDropColumn(new TextCell()) { - @Override - public String getValue(FileResource object) { - return formatter.format(object.getModificationDate()); - } - },"Last Modified"); - - - - - VerticalPanel vp = new VerticalPanel(); - vp.setWidth("100%"); - celltable.setWidth("100%"); - vp.add(searchResults); - searchResults.addStyleName("pithos-searchLabel"); - pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER); - pagerTop.setDisplay(celltable); - vp.add(pagerTop); - vp.add(celltable); - pager = new GssSimplePager(GssSimplePager.TextLocation.CENTER); - pager.setDisplay(celltable); - //celltable.setPageSize(2); - - vp.add(pager); - vp.setCellWidth(celltable, "100%"); - - initWidget(vp); - - //initWidget(celltable); - celltable.setStyleName("pithos-List"); - selectionModel = new MultiSelectionModel(); - - - Handler selectionHandler = new SelectionChangeEvent.Handler() { - @Override - public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) { - if(getSelectedFiles().size()==1) - GSS.get().setCurrentSelection(getSelectedFiles().get(0)); - else - GSS.get().setCurrentSelection(getSelectedFiles()); - //contextMenu.setFiles(getSelectedFiles()); - } - }; - selectionModel.addSelectionChangeHandler(selectionHandler); - - celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.createDefaultManager()); - celltable.setPageSize(GSS.VISIBLE_FILE_COUNT); - celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); - Scheduler.get().scheduleIncremental(new RepeatingCommand() { - - @Override - public boolean execute() { - return fetchRootFolder(); - } - }); - sinkEvents(Event.ONCONTEXTMENU); - sinkEvents(Event.ONMOUSEUP); - sinkEvents(Event.ONMOUSEDOWN); - sinkEvents(Event.ONCLICK); - sinkEvents(Event.ONKEYDOWN); - sinkEvents(Event.ONDBLCLICK); - GSS.preventIESelection(); - } - - //public native void fireClickEvent(Element element) /*-{ - // var evObj = $doc.createEvent('MouseEvents'); - //evObj.initEvent('click', true, true); - //element.dispatchEvent(evObj); - //}-*/; - - public List getSelectedFiles() { - return new ArrayList(selectionModel.getSelectedSet()); - } - - private void initDragOperation(DragAndDropColumn column) { - - // retrieve draggableOptions on the column - DraggableOptions draggableOptions = column.getDraggableOptions(); - // use template to construct the helper. The content of the div will be set - // after - draggableOptions.setHelper($(FileList.Templates.INSTANCE.outerHelper().asString())); - //draggableOptions.setZIndex(100); - // opacity of the helper - draggableOptions.setAppendTo("body"); - //draggableOptions.setOpacity((float) 0.8); - draggableOptions.setContainment("document"); - // cursor to use during the drag operation - draggableOptions.setCursor(Cursor.MOVE); - // set the revert option - draggableOptions.setRevert(RevertOption.ON_INVALID_DROP); - // prevents dragging when user click on the category drop-down list - draggableOptions.setCancel("select"); - - draggableOptions.setOnBeforeDragStart(new DragFunction() { - - @Override - public void f(DragContext context) { - FileResource value = context.getDraggableData(); - if(!selectionModel.isSelected(value)){ - throw new StopDragException(); - } - - } - }); - } - - public void showContextMenu(Event event){ - menuShowing = new FileContextMenu(images, false, true); - menuShowing=menuShowing.onEmptyEvent(event); - } - @Override - public void onBrowserEvent(Event event) { - - if (files == null || files.size() == 0) { - if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) { - menuShowing = new FileContextMenu(images, false, true); - menuShowing=menuShowing.onEmptyEvent(event); - event.preventDefault(); - event.cancelBubble(true); - } - return; - } - if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) { - GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null); - menuShowing = new FileContextMenu(images, false, false); - menuShowing=menuShowing.onEvent(event); - event.cancelBubble(true); - event.preventDefault(); - } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) { - menuShowing = new FileContextMenu(images, false, true); - menuShowing=menuShowing.onEmptyEvent(event); - event.cancelBubble(true); - event.preventDefault(); - } else if (DOM.eventGetType(event) == Event.ONDBLCLICK) - if (getSelectedFiles().size() == 1) { - GSS app = GSS.get(); - FileResource file = getSelectedFiles().get(0); - String dateString = RestCommand.getDate(); - String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length()); - String sig = app.getCurrentUserResource().getUsername() + " " + - RestCommand.calculateSig("GET", dateString, resource, - RestCommand.base64decode(app.getToken())); - if(!file.isDeleted()){ - Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", ""); - } - event.preventDefault(); - return; - } - super.onBrowserEvent(event); - } - - /** - * Retrieve the root folder for the current user. - * - * @return true if the retrieval was successful - */ - protected boolean fetchRootFolder() { - UserResource user = GSS.get().getCurrentUserResource(); - if (user == null) - return !DONE; - // Update cache and clear selection. - updateFileCache(null); - return DONE; - } - - - /** - * Update the display of the file list. - */ - void update(boolean sort) { - int count = folderFileCount; - int max = startIndex + GSS.VISIBLE_FILE_COUNT; - if (max > count) - max = count; - folderTotalSize = 0; - - copyListAndContinue(files); - for(FileResource f : files){ - folderTotalSize += f.getContentLength(); - } - if (folderFileCount == 0) { - showingStats = "no files"; - } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) { - if (folderFileCount == 1) - showingStats = "1 file"; - else - showingStats = folderFileCount + " files"; - showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; - } else { - showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")"; - } - updateCurrentlyShowingStats(); - - } - - /** - * Return the proper icon based on the MIME type of the file. - * - * @param file - * @return the icon - */ - private ImageResource getFileIcon(FileResource file) { - String mimetype = file.getContentType(); - boolean shared = file.isShared(); - if (mimetype == null) - return shared ? images.documentShared() : images.document(); - mimetype = mimetype.toLowerCase(); - if (mimetype.startsWith("application/pdf")) - return shared ? images.pdfShared() : images.pdf(); - else if (mimetype.endsWith("excel")) - return shared ? images.spreadsheetShared() : images.spreadsheet(); - else if (mimetype.endsWith("msword")) - return shared ? images.wordprocessorShared() : images.wordprocessor(); - else if (mimetype.endsWith("powerpoint")) - return shared ? images.presentationShared() : images.presentation(); - else if (mimetype.startsWith("application/zip") || - mimetype.startsWith("application/gzip") || - mimetype.startsWith("application/x-gzip") || - mimetype.startsWith("application/x-tar") || - mimetype.startsWith("application/x-gtar")) - return shared ? images.zipShared() : images.zip(); - else if (mimetype.startsWith("text/html")) - return shared ? images.htmlShared() : images.html(); - else if (mimetype.startsWith("text/plain")) - return shared ? images.txtShared() : images.txt(); - else if (mimetype.startsWith("image/")) - return shared ? images.imageShared() : images.image(); - else if (mimetype.startsWith("video/")) - return shared ? images.videoShared() : images.video(); - else if (mimetype.startsWith("audio/")) - return shared ? images.audioShared() : images.audio(); - return shared ? images.documentShared() : images.document(); - } - - /** - * Update status panel with currently showing file stats. - */ - public void updateCurrentlyShowingStats() { - GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats); - } - - public void updateFileCache(String query) { - final GSS app = GSS.get(); - setLastQuery(query); - clearSelectedRows(); - //clearLabels(); - startIndex = 0; - app.showLoadingIndicator("Getting Search Results",null); - if (query == null || query.trim().equals("")) { - searchResults.setHTML("You must specify a query."); - setFiles(new ArrayList()); - update(true); - app.hideLoadingIndicator(); - } else if (!GSS.isValidResourceName(query)) { - searchResults.setHTML("The query was invalid. Try to use words that appear in the file's name, contents or tags."); - setFiles(new ArrayList()); - update(true); - app.hideLoadingIndicator(); - } else{ - searchResults.setHTML("Search results for " + query); - showCellTable(true); - - } - } - - /** - * Fill the file cache with data. - */ - public void setFiles(final List _files) { - if (_files.size() > 0 && ! (GSS.get().getTreeView().getSelection() instanceof TrashResource)) { - files = new ArrayList(); - for (FileResource fres : _files) - files.add(fres); - } - else - files = _files; - Collections.sort(files, new Comparator() { - - @Override - public int compare(FileResource arg0, FileResource arg1) { - return arg0.getName().compareTo(arg1.getName()); - } - - }); - folderFileCount = files.size(); - } - - - - - /** - * Does the list contains the requested filename - * - * @param fileName - * @return true/false - */ - public boolean contains(String fileName) { - for (int i = 0; i < files.size(); i++) - if (files.get(i).getName().equals(fileName)) - return true; - return false; - } - - public void clearSelectedRows() { - Iterator it = selectionModel.getSelectedSet().iterator(); - while(it.hasNext()){ - selectionModel.setSelected(it.next(),false); - } - } - - /** - * - */ - public void selectAllRows() { - Iterator it = selectionModel.getSelectedSet().iterator(); - while(it.hasNext()){ - selectionModel.setSelected(it.next(),true); - } - - - } - - - private void sortFiles(final String sortingProperty, final boolean sortingType){ - Collections.sort(files, new Comparator() { - - @Override - public int compare(FileResource arg0, FileResource arg1) { - AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc()); - AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc()); - if (sortingType){ - if (sortingProperty.equals("version")) { - return arg0.getVersion().compareTo(arg1.getVersion()); - } else if (sortingProperty.equals("owner")) { - return arg0.getOwner().compareTo(arg1.getOwner()); - } else if (sortingProperty.equals("date")) { - return arg0.getModificationDate().compareTo(arg1.getModificationDate()); - } else if (sortingProperty.equals("size")) { - return arg0.getContentLength().compareTo(arg1.getContentLength()); - } else if (sortingProperty.equals("name")) { - return arg0.getName().compareTo(arg1.getName()); - } else if (sortingProperty.equals("path")) { - return arg0.getUri().compareTo(arg1.getUri()); - } else { - return arg0.getName().compareTo(arg1.getName()); - } - } - else if (sortingProperty.equals("version")) { - - return arg1.getVersion().compareTo(arg0.getVersion()); - } else if (sortingProperty.equals("owner")) { - - return arg1.getOwner().compareTo(arg0.getOwner()); - } else if (sortingProperty.equals("date")) { - - return arg1.getModificationDate().compareTo(arg0.getModificationDate()); - } else if (sortingProperty.equals("size")) { - - return arg1.getContentLength().compareTo(arg0.getContentLength()); - } else if (sortingProperty.equals("name")) { - - return arg1.getName().compareTo(arg0.getName()); - } else if (sortingProperty.equals("path")) { - - return arg1.getUri().compareTo(arg0.getUri()); - } else { - - return arg1.getName().compareTo(arg0.getName()); - } - } - - }); - } - - - /** - * Creates a new ArrayList from the given files ArrayList - * in order that the input files remain untouched - * and continues to find user's full names of each FileResource element - * in the new ArrayList - * - * @param filesInput - */ - private void copyListAndContinue(List filesInput){ - List copiedFiles = new ArrayList(); - for(FileResource file : filesInput) { - copiedFiles.add(file); - } - handleFullNames(copiedFiles); - } - - /** - * Examines whether or not the user's full name exists in the - * userFullNameMap in the GSS.java for every element of the input list. - * If the user's full name does not exist in the map then a command is being made. - * - * @param filesInput - */ - private void handleFullNames(List filesInput){ - if(filesInput.size() == 0){ - showCellTable(false); - return; - } - - if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){ - findFullNameAndUpdate(filesInput); - return; - } - - if(filesInput.size() >= 1){ - filesInput.remove(filesInput.get(0)); - if(filesInput.isEmpty()){ - showCellTable(false); - }else{ - handleFullNames(filesInput); - } - } - } - - /** - * Makes a command to search for full name from a given username. - * Only after the completion of the command the celltable is shown - * or the search for the next full name continues. - * - * @param filesInput - */ - private void findFullNameAndUpdate(final List filesInput){ - String aUserName = filesInput.get(0).getOwner(); - String path = GSS.get().getApiPath() + "users/" + aUserName; - - GetCommand gg = new GetCommand(UserSearchResource.class, path, false,null) { - @Override - public void onComplete() { - final UserSearchResource result = getResult(); - for (UserResource user : result.getUsers()){ - String username = user.getUsername(); - String userFullName = user.getName(); - GSS.get().putUserToMap(username, userFullName); - if(filesInput.size() >= 1){ - filesInput.remove(filesInput.get(0)); - if(filesInput.isEmpty()){ - showCellTable(false); - }else{ - handleFullNames(filesInput); - } - } - } - } - @Override - public void onError(Throwable t) { - GWT.log("", t); - GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner()); - if(filesInput.size() >= 1){ - filesInput.remove(filesInput.get(0)); - handleFullNames(filesInput); - } - } - }; - DeferredCommand.addCommand(gg); - - } - /** - * Shows the files in the cellTable - */ - - private void showCellTable(boolean update){ - if(celltable.getRowCount()>GSS.VISIBLE_FILE_COUNT){ - pager.setVisible(true); - pagerTop.setVisible(true); - } - else{ - pager.setVisible(false); - pagerTop.setVisible(false); - } - if(update) - provider.onRangeChanged(celltable); - celltable.redrawHeaders(); - } - - - /** - * Retrieve the lastQuery. - * - * @return the lastQuery - */ - public String getLastQuery() { - return lastQuery; - } - - - /** - * Modify the lastQuery. - * - * @param lastQuery the lastQuery to set - */ - public void setLastQuery(String lastQuery) { - this.lastQuery = lastQuery; - } - - class SearchDataProvider extends AsyncDataProvider{ - - @Override - protected void onRangeChanged(final HasData display) { - final int start = display.getVisibleRange().getStart(); - final GSS app = GSS.get(); - if(getLastQuery()==null||getLastQuery().equals("")){ - display.setRowCount(0,true); - return; - - } - GetCommand eg = new GetCommand(SearchResource.class, - app.getApiPath() + "search/" +URL.encodeComponent(getLastQuery())+"?start="+start, null) { - - @Override - public void onComplete() { - SearchResource s = getResult(); - display.setRowCount(s.getSize(),true); - display.setRowData(start, s.getFiles()); - setFiles(s.getFiles()); - update(true); - - } - - @Override - public void onError(Throwable t) { - if(t instanceof RestException) - app.displayError("Unable to perform search:"+((RestException)t).getHttpStatusText()); - else - app.displayError("System error performing search:"+t.getMessage()); - GWT.log("",t); - updateFileCache(""); - } - - }; - DeferredCommand.addCommand(eg); - - } - - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/TopPanel.java b/web_client/src/gr/grnet/pithos/web/client/TopPanel.java index fea03dc..b10d5fd 100644 --- a/web_client/src/gr/grnet/pithos/web/client/TopPanel.java +++ b/web_client/src/gr/grnet/pithos/web/client/TopPanel.java @@ -31,7 +31,7 @@ public class TopPanel extends Composite { * An image bundle for this widgets images. */ public interface Images extends ClientBundle, FileMenu.Images, EditMenu.Images, - SettingsMenu.Images, GroupMenu.Images, FilePropertiesDialog.Images, + SettingsMenu.Images, FilePropertiesDialog.Images, HelpMenu.Images, LoadingIndicator.Images { @Source("gr/grnet/pithos/resources/exit.png") @@ -75,11 +75,6 @@ public class TopPanel extends Composite { private EditMenu editMenu; /** - * The group menu widget. - */ - private GroupMenu groupMenu; - - /** * The settings menu widget. */ private SettingsMenu settingsMenu; @@ -103,10 +98,10 @@ public class TopPanel extends Composite { public TopPanel(Images images) { fileMenu = new FileMenu(images); editMenu = new EditMenu(images); - groupMenu = new GroupMenu(images); settingsMenu = new SettingsMenu(images); helpMenu = new HelpMenu(images); loading = new LoadingIndicator(images); + loading.hide(); HorizontalPanel outer = new HorizontalPanel(); outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); @@ -146,11 +141,6 @@ public class TopPanel extends Composite { }; editItem.getElement().setId("topMenu.edit"); - MenuItem groupItem = new MenuItem("
" + - AbstractImagePrototype.create(images.group()).getHTML() + "Group
", true, - groupMenu.getContextMenu()); - groupItem.getElement().setId("topMenu.group"); - MenuItem configureItem = new MenuItem("
" + AbstractImagePrototype.create(images.configure()).getHTML() + "Settings
", true,settingsMenu.getContextMenu()); @@ -168,7 +158,6 @@ public class TopPanel extends Composite { menu.addItem(quitItem); menu.addItem(fileItem); menu.addItem(editItem); - menu.addItem(groupItem); menu.addItem(configureItem); menu.addItem(helpItem); diff --git a/web_client/src/gr/grnet/pithos/web/client/UserAddDialog.java b/web_client/src/gr/grnet/pithos/web/client/UserAddDialog.java deleted file mode 100644 index 0cd8b52..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/UserAddDialog.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client; - -import gr.grnet.pithos.web.client.rest.GetCommand; -import gr.grnet.pithos.web.client.rest.PostCommand; -import gr.grnet.pithos.web.client.rest.RestException; -import gr.grnet.pithos.web.client.rest.resource.GroupResource; -import gr.grnet.pithos.web.client.rest.resource.UserResource; -import gr.grnet.pithos.web.client.rest.resource.UserSearchResource; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.FocusEvent; -import com.google.gwt.event.dom.client.FocusHandler; -import com.google.gwt.event.dom.client.KeyCodes; -import com.google.gwt.event.dom.client.KeyUpEvent; -import com.google.gwt.event.dom.client.KeyUpHandler; -import com.google.gwt.http.client.URL; -import com.google.gwt.user.client.DeferredCommand; -import com.google.gwt.user.client.Event.NativePreviewEvent; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.DialogBox; -import com.google.gwt.user.client.ui.FlexTable; -import com.google.gwt.user.client.ui.HasHorizontalAlignment; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.MultiWordSuggestOracle; -import com.google.gwt.user.client.ui.SuggestBox; -import com.google.gwt.user.client.ui.VerticalPanel; - -public class UserAddDialog extends DialogBox { - - private MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); - private SuggestBox suggestBox = new SuggestBox(oracle); - - String selectedUser=null; - FlexTable userTable = new FlexTable(); - - /** - * The widget's constructor. - */ - public UserAddDialog() { - setAnimationEnabled(true); - setText("Add User"); - VerticalPanel panel = new VerticalPanel(); - setWidget(panel); - panel.addStyleName("pithos-TabPanelBottom"); - userTable.addStyleName("pithos-permList"); - userTable.setWidget(0, 0, new Label("Username:")); - userTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); - suggestBox.getTextBox().addFocusHandler(new FocusHandler() { - - @Override - public void onFocus(FocusEvent event) { - if (selectedUser != null && selectedUser.endsWith("@")) - updateSuggestions(); - } - }); - - suggestBox.addKeyUpHandler(new KeyUpHandler() { - - @Override - public void onKeyUp(KeyUpEvent event) { - // Ignore the arrow keys. - int keyCode=event.getNativeKeyCode(); - if(keyCode == KeyCodes.KEY_UP || - keyCode == KeyCodes.KEY_DOWN || - keyCode == KeyCodes.KEY_LEFT || - keyCode == KeyCodes.KEY_RIGHT) - return; - if (keyCode==KeyCodes.KEY_ESCAPE) { - suggestBox.hideSuggestionList(); - return; - } - String text = suggestBox.getText().trim(); - // Avoid useless queries for keystrokes that do not modify the - // text. - if (text.equals(selectedUser)) - return; - selectedUser = text; - // Go to the server only if the user typed the @ character. - if (selectedUser.endsWith("@")) - updateSuggestions(); - } - }); - suggestBox.getElement().setId("addUser.textBox"); - userTable.setWidget(0, 1, suggestBox); - panel.add(userTable); - HorizontalPanel buttons = new HorizontalPanel(); - Button ok = new Button("OK", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - addUser(); - hide(); - } - }); - ok.getElement().setId("addUser.button.ok"); - buttons.add(ok); - buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER); - // Create the 'Cancel' button, along with a listener that hides the - // dialog when the button is clicked. - Button cancel = new Button("Cancel", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - hide(); - } - }); - cancel.getElement().setId("addUser.button.cancel"); - buttons.add(cancel); - buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); - buttons.setSpacing(8); - buttons.addStyleName("pithos-TabPanelBottom"); - panel.add(buttons); - panel.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); - panel.addStyleName("pithos-DialogBox"); - } - - @Override - public void center() { - super.center(); - suggestBox.setFocus(true); - } - - @Override - protected void onPreviewNativeEvent(NativePreviewEvent preview) { - super.onPreviewNativeEvent(preview); - - NativeEvent evt = preview.getNativeEvent(); - if (evt.getType().equals("keydown")) - // Use the popup's key preview hooks to close the dialog when either - // enter or escape is pressed. - switch (evt.getKeyCode()) { - case KeyCodes.KEY_ENTER: - addUser(); - hide(); - break; - case KeyCodes.KEY_ESCAPE: - hide(); - break; - } - } - - /** - * Generate a request to add a user to a group. - * - * @param groupName the name of the group to create - */ - private void addUser() { - GroupResource group = (GroupResource) GSS.get().getCurrentSelection(); - selectedUser = suggestBox.getText(); - if ( group == null ) { - GSS.get().displayError("Empty group name!"); - return; - } - if ( selectedUser == null ) { - GSS.get().displayError("No User Selected!"); - return; - } - PostCommand cg = new PostCommand(group.getUri()+"?name="+selectedUser, "", 201){ - @Override - public void onComplete() { - GSS.get().getGroups().updateGroups(); - GSS.get().showUserList(); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if(t instanceof RestException){ - int statusCode = ((RestException)t).getHttpStatusCode(); - if(statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if(statusCode == 404) - GSS.get().displayError("User does not exist"); - else if(statusCode == 409) - GSS.get().displayError("A user with the same name already exists"); - else if(statusCode == 413) - GSS.get().displayError("Your quota has been exceeded"); - else - GSS.get().displayError("Unable to add user: "+((RestException)t).getHttpStatusText()); - } - else - GSS.get().displayError("System error adding user: "+t.getMessage()); - } - }; - DeferredCommand.addCommand(cg); - } - - /** - * Update the list of suggestions. - */ - protected void updateSuggestions() { - final GSS app = GSS.get(); - String query = selectedUser.substring(0, selectedUser.length()-1); - GWT.log("Searching for " + query, null); - - GetCommand eg = new GetCommand(UserSearchResource.class, - app.getApiPath() + "users/" + URL.encodeComponent(query), false, null) { - - @Override - public void onComplete() { - suggestBox.hideSuggestionList(); - oracle.clear(); - UserSearchResource s = getResult(); - for (UserResource user : s.getUsers()) { - GWT.log("Found " + user.getUsername(), null); - oracle.add(user.getUsername()); - } - suggestBox.showSuggestionList(); - } - - @Override - public void onError(Throwable t) { - if(t instanceof RestException) - app.displayError("Unable to perform search: "+((RestException)t).getHttpStatusText()); - else - app.displayError("System error while searching for users: "+t.getMessage()); - GWT.log("", t); - DisplayHelper.log(t.getMessage()); - } - - }; - DeferredCommand.addCommand(eg); - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java index 4ab4191..cc73ab8 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteCommand.java @@ -5,11 +5,9 @@ package gr.grnet.pithos.web.client.commands; import gr.grnet.pithos.web.client.DeleteFileDialog; import gr.grnet.pithos.web.client.DeleteFolderDialog; -import gr.grnet.pithos.web.client.DeleteGroupDialog; import gr.grnet.pithos.web.client.EditMenu.Images; import gr.grnet.pithos.web.client.GSS; import gr.grnet.pithos.web.client.rest.resource.FileResource; -import gr.grnet.pithos.web.client.rest.resource.GroupResource; import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; @@ -60,9 +58,6 @@ public class DeleteCommand implements Command{ dlg.center(); } else if (selection instanceof GroupUserResource) { // TODO implement user deletion - } else if (selection instanceof GroupResource) { - DeleteGroupDialog dlg = new DeleteGroupDialog(newImages); - dlg.center(); } - } + } } diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/DeleteUserOrGroupCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/DeleteUserOrGroupCommand.java deleted file mode 100644 index 5cd3551..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/commands/DeleteUserOrGroupCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client.commands; - -import gr.grnet.pithos.web.client.DeleteGroupDialog; -import gr.grnet.pithos.web.client.DeleteUserDialog; -import gr.grnet.pithos.web.client.GSS; -import gr.grnet.pithos.web.client.Groups.Images; -import gr.grnet.pithos.web.client.rest.resource.GroupResource; -import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; - -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.ui.PopupPanel; - - -public class DeleteUserOrGroupCommand implements Command{ - private PopupPanel containerPanel; - final Images images; - - /** - * @param aContainerPanel - * @param newImages the images of the new folder dialog - */ - public DeleteUserOrGroupCommand(PopupPanel aContainerPanel, final Images newImages){ - containerPanel = aContainerPanel; - images = newImages; - } - - @Override - public void execute() { - containerPanel.hide(); - if(GSS.get().getCurrentSelection() instanceof GroupResource) - displayNewGroup(); - else if(GSS.get().getCurrentSelection() instanceof GroupUserResource) - displayNewUser(); - else - GSS.get().displayError("No user or group selected"); - } - - void displayNewGroup() { - DeleteGroupDialog dlg = new DeleteGroupDialog(images); - dlg.center(); - } - - void displayNewUser() { - DeleteUserDialog dlg = new DeleteUserDialog(images); - dlg.center(); - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/NewGroupCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/NewGroupCommand.java deleted file mode 100644 index 59a2c81..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/commands/NewGroupCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client.commands; - -import gr.grnet.pithos.web.client.GroupPropertiesDialog; - -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.ui.PopupPanel; - - -public class NewGroupCommand implements Command{ - private PopupPanel containerPanel; - - /** - * @param _containerPanel - */ - public NewGroupCommand(PopupPanel _containerPanel){ - containerPanel = _containerPanel; - } - - @Override - public void execute() { - containerPanel.hide(); - displayNewGroup(); - } - - void displayNewGroup() { - GroupPropertiesDialog dlg = new GroupPropertiesDialog(true); - dlg.center(); - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/NewUserCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/NewUserCommand.java deleted file mode 100644 index bb149b4..0000000 --- a/web_client/src/gr/grnet/pithos/web/client/commands/NewUserCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2011 Greek Research and Technology Network - */ -package gr.grnet.pithos.web.client.commands; - -import gr.grnet.pithos.web.client.UserAddDialog; - -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.ui.PopupPanel; - - -public class NewUserCommand implements Command { - private PopupPanel containerPanel; - - /** - * @param _containerPanel - */ - public NewUserCommand(PopupPanel _containerPanel){ - containerPanel = _containerPanel; - } - - @Override - public void execute() { - containerPanel.hide(); - displayNewUser(); - } - - private void displayNewUser() { - UserAddDialog dlg = new UserAddDialog(); - dlg.center(); - } - -} diff --git a/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java b/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java index d25019a..602b6d9 100644 --- a/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java +++ b/web_client/src/gr/grnet/pithos/web/client/commands/PasteCommand.java @@ -34,43 +34,6 @@ public class PasteCommand implements Command { public void execute() { containerPanel.hide(); Object selection = GSS.get().getCurrentSelection(); - if(selection != null && selection instanceof GroupResource){ - final ClipboardItem citem = GSS.get().getClipboard().getItem(); - GroupResource group = (GroupResource) GSS.get().getCurrentSelection(); - if(citem.getUser() != null){ - PostCommand cg = new PostCommand(group.getUri()+"?name="+citem.getUser().getUsername(), "", 201){ - - @Override - public void onComplete() { - GSS.get().getGroups().updateGroups(); - GSS.get().showUserList(); - GSS.get().getClipboard().setItem(null); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if(t instanceof RestException){ - int statusCode = ((RestException)t).getHttpStatusCode(); - if(statusCode == 405) - GSS.get().displayError("You don't have the necessary permissions"); - else if(statusCode == 404) - GSS.get().displayError("User does not exist"); - else if(statusCode == 409) - GSS.get().displayError("A user with the same name already exists"); - else if(statusCode == 413) - GSS.get().displayError("Your quota has been exceeded"); - else - GSS.get().displayError("Unable to add user:"+((RestException)t).getHttpStatusText()); - } - else - GSS.get().displayError("System error adding user:"+t.getMessage()); - } - }; - DeferredCommand.addCommand(cg); - return; - } - } FolderResource selectedFolder = null; if(selection != null && selection instanceof RestResourceWrapper) selectedFolder = ((RestResourceWrapper)selection).getResource(); diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java new file mode 100644 index 0000000..13b4c56 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +import com.google.gwt.http.client.Header; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONValue; +import gr.grnet.pithos.web.client.rest.resource.RestResource; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by IntelliJ IDEA. User: chstath Date: 5/19/11 Time: 2:55 PM To change this template use File | Settings | + * File Templates. + */ +public class AccountResource extends Resource { + + private List containers = new ArrayList(); + + @Override + public String getLastModifiedSince() { + return null; + } + + public List getContainers() { + return containers; + } +} diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/ContainerResource.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/ContainerResource.java new file mode 100644 index 0000000..324aee8 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/ContainerResource.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +import com.google.gwt.http.client.Header; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONParser; +import gr.grnet.pithos.web.client.foldertree.Resource; +import java.util.Date; + +public class ContainerResource extends Resource { + /* + * The name of the container + */ + private String name; + + /* + * The number of objects inside the container + */ + private long count; + + /* + * The total size of the objects inside the container + */ + private long bytes; + + /* + * The last object modification date + */ + private Date lastModified; + + /* + * The date the container was created + */ + private Date created; + + @Override + public String getLastModifiedSince() { + return ""; + } + + public String getName() { + return name; + } + + public long getBytes() { + return bytes; + } + + public long getCount() { + return count; + } + + public Date getCreated() { + return created; + } + + public Date getLastModified() { + return lastModified; + } + + public void setBytes(long bytes) { + this.bytes = bytes; + } + + public void setCount(long count) { + this.count = count; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setLastModified(Date lastModified) { + this.lastModified = lastModified; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java new file mode 100644 index 0000000..8894514 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +public class File { +} diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java new file mode 100644 index 0000000..2e23484 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +import java.util.ArrayList; +import java.util.List; + +public class Folder { + private String uri; + + private String name; + + private List subfolders = new ArrayList(); + + public Folder(String name) { + this.name = name; + } + + public String getUri() { + return uri; + } + + public String getName() { + return name; + } + + public List getSubfolders() { + return subfolders; + } + + public void setSubfolders(List subfolders) { + this.subfolders = subfolders; + } +} diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java new file mode 100644 index 0000000..152faf7 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeView.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +import com.google.gwt.cell.client.AbstractCell; +import com.google.gwt.cell.client.Cell; +import com.google.gwt.core.client.GWT; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.resources.client.ImageResource.ImageOptions; +import com.google.gwt.safehtml.client.SafeHtmlTemplates; +import com.google.gwt.safehtml.shared.SafeHtml; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.cellview.client.CellTree; +import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; +import com.google.gwt.user.client.DeferredCommand; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.IncrementalCommand; +import com.google.gwt.user.client.ui.AbstractImagePrototype; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Tree; +import com.google.gwt.view.client.ListDataProvider; +import com.google.gwt.view.client.SelectionChangeEvent; +import com.google.gwt.view.client.SelectionChangeEvent.Handler; +import com.google.gwt.view.client.SingleSelectionModel; +import com.google.gwt.view.client.TreeViewModel; +import com.google.gwt.view.client.TreeViewModel.NodeInfo; +import gr.grnet.pithos.web.client.CellTreeViewModel; +import gr.grnet.pithos.web.client.CellTreeViewUtils; +import gr.grnet.pithos.web.client.FolderContextMenu; +import gr.grnet.pithos.web.client.GSS; +import gr.grnet.pithos.web.client.rest.resource.FolderResource; +import gr.grnet.pithos.web.client.rest.resource.RestResource; +import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; +import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTree; +import java.util.Arrays; + +public class FolderTreeView extends Composite { + + static interface BasicResources extends CellTree.Resources { + + @ImageOptions(flipRtl = true) + @Source("cellTreeClosedItem.gif") + ImageResource cellTreeClosedItem(); + + @ImageOptions(flipRtl = true) + @Source("cellTreeLoadingBasic.gif") + ImageResource cellTreeLoading(); + + @ImageOptions(flipRtl = true) + @Source("cellTreeOpenItem.gif") + ImageResource cellTreeOpenItem(); + + @Source({"GssCellTreeBasic.css"}) + CellTree.Style cellTreeStyle(); + } + + static interface Images extends ClientBundle,Tree.Resources, FolderContextMenu.Images { + + @Source("gr/grnet/pithos/resources/folder_home.png") + ImageResource home(); + + @Source("gr/grnet/pithos/resources/folder_yellow.png") + ImageResource folderYellow(); + } + + private static Images images = GWT.create(Images.class); + + static interface Templates extends SafeHtmlTemplates { + Templates INSTANCE = GWT.create(Templates.class); + + @Template("{0}") + public SafeHtml nameSpan(String name); + } + + static class FolderCell extends AbstractCell { + + @Override + public void render(Context context, Folder folder, SafeHtmlBuilder safeHtmlBuilder) { + String html = AbstractImagePrototype.create(images.folderYellow()).getHTML(); + safeHtmlBuilder.appendHtmlConstant(html); + safeHtmlBuilder.append(Templates.INSTANCE.nameSpan(folder.getName())); + } + } + + private SingleSelectionModel selectionModel = new SingleSelectionModel(); + + public FolderTreeView() { + final FolderTreeViewModel model = new FolderTreeViewModel(selectionModel); + /* + * Create the tree using the model. We use null as the default + * value of the root node. The default value will be passed to + * CustomTreeModel#getNodeInfo(); + */ + CellTree.Resources res = GWT.create(BasicResources.class); + DragAndDropCellTree tree = new DragAndDropCellTree(model,null, res); + + tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); + + Handler selectionHandler = new SelectionChangeEvent.Handler() { + @Override + public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) { + NodeInfo nodeInfo = (NodeInfo) model.getNodeInfo(selectionModel.getSelectedObject()); + if(nodeInfo == null || nodeInfo.getValueUpdater() == null) { + //GSS.get().showFileList(selectionModel.getSelectedObject()); + } + else + nodeInfo.getValueUpdater().update(selectionModel.getSelectedObject()); + GSS.get().setCurrentSelection(selectionModel.getSelectedObject()); + + + } + }; + selectionModel.addSelectionChangeHandler(selectionHandler); + sinkEvents(Event.ONCONTEXTMENU); + sinkEvents(Event.ONMOUSEUP); + initWidget(tree); + } +} diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java new file mode 100644 index 0000000..9384e1b --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +import com.google.gwt.cell.client.AbstractCell; +import com.google.gwt.cell.client.Cell; +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.client.ui.AbstractImagePrototype; +import com.google.gwt.view.client.ListDataProvider; +import com.google.gwt.view.client.SingleSelectionModel; +import com.google.gwt.view.client.TreeViewModel; +import gr.grnet.pithos.web.client.GSS; +import gr.grnet.pithos.web.client.foldertree.FolderTreeView.FolderCell; +import gr.grnet.pithos.web.client.rest.GetRequest; +import gr.grnet.pithos.web.client.rest.RestException; +import gwtquery.plugins.droppable.client.gwt.DragAndDropNodeInfo; + +public class FolderTreeViewModel implements TreeViewModel { + + private SingleSelectionModel selectionModel; + + public FolderTreeViewModel(SingleSelectionModel selectionModel) { + this.selectionModel = selectionModel; + } + + @Override + public NodeInfo getNodeInfo(T value) { + if (value == null) { + final ListDataProvider dataProvider = new ListDataProvider(); + Folder f = new Folder("Loading ..."); + dataProvider.getList().add(f); + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + fetchAccount(dataProvider); + } + }); + return new DragAndDropNodeInfo(dataProvider, new FolderCell(), selectionModel, null); + } + else { + final ListDataProvider dataProvider = new ListDataProvider(); + return new DragAndDropNodeInfo(dataProvider, new FolderCell(), selectionModel, null); + } + } + + @Override + public boolean isLeaf(Object o) { + if (o instanceof Folder) { + Folder f = (Folder) o; + return f.getSubfolders().isEmpty(); + } + return false; + } + + public void fetchAccount(final ListDataProvider dataProvider) { + GSS app = GSS.get(); + String path = app.getApiPath() + app.getUsername() + "?format=json"; + + GetRequest getAccount = new GetRequest(AccountResource.class, path) { + @Override + public void onSuccess(AccountResource result) { + dataProvider.getList().clear(); + for (ContainerResource c : result.getContainers()) { + dataProvider.getList().add(new Folder(c.getName())); + } + } + + @Override + public void onError(Throwable t) { + GWT.log("Error getting account", t); + if (t instanceof RestException) + GSS.get().displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); + else + GSS.get().displayError("System error fetching user data: " + t.getMessage()); + } + }; + + Scheduler.get().scheduleDeferred(getAccount); + } +} diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/GssCellTreeBasic.css b/web_client/src/gr/grnet/pithos/web/client/foldertree/GssCellTreeBasic.css new file mode 100644 index 0000000..b37b22e --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/GssCellTreeBasic.css @@ -0,0 +1,78 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +.cellTreeWidget { + +} + +.cellTreeEmptyMessage { + padding-left: 16px; + font-style: italic; +} + +.cellTreeItem { + padding-top: 4px; + padding-bottom: 4px; + cursor: hand; + cursor: pointer; + zoom: 1; +} + +.cellTreeItemImage { + +} + +.cellTreeItemImageValue { + zoom: 1; +} + +.cellTreeItemValue { + padding-left: 3px; + padding-right: 3px; + outline: none; +} + +.cellTreeOpenItem { + +} + +.cellTreeTopItem { + +} + +.cellTreeTopItemImage { + +} + +.cellTreeTopItemImageValue { + +} + +.cellTreeKeyboardSelectedItem { + background-color: #ffc; + outline: none; +} + +.cellTreeSelectedItem { + background-color: #628cd5; + color: white; + height: auto; + overflow: visible; +} + +.cellTreeShowMoreButton { + padding-left: 16px; + outline: none; +} \ No newline at end of file diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/ObjectResource.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/ObjectResource.java new file mode 100644 index 0000000..aae7e76 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/ObjectResource.java @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +public class ObjectResource { +} diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/Resource.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/Resource.java new file mode 100644 index 0000000..314ac24 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/Resource.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.foldertree; + +import com.google.gwt.http.client.Header; +import com.google.gwt.http.client.Response; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; +import java.util.Date; + +public abstract class Resource { + + String uri; + + public String getUri() { + return uri; + } + + protected static String unmarshallString(JSONObject obj, String key){ + if(obj.get(key) != null) { + JSONString s = obj.get(key).isString(); + if(s != null) + return s.stringValue(); + } + return null; + } + + protected static int unmarshallInt(JSONObject obj, String key){ + if(obj.get(key) != null) + if(obj.get(key).isNumber() != null) + return (int) obj.get(key).isNumber().getValue(); + return -1; + } + + protected static long unmarshallLong(JSONObject obj, String key){ + if(obj.get(key) != null) { + JSONNumber value = obj.get(key).isNumber(); + if(value != null) + return (long) value.doubleValue(); + } + return -1; + } + + protected static boolean unmarshallBoolean(JSONObject obj, String key){ + if(obj.get(key) != null) + if(obj.get(key).isBoolean() != null) + return obj.get(key).isBoolean().booleanValue(); + return false; + } + + protected static Date unmarshallTimestamp(JSONObject obj, String key){ + if(obj.get(key) != null) { + JSONString s = obj.get(key).isString(); + if (s != null) + return new Date(Long.valueOf(s.stringValue()).longValue()); + } + return null; + } + + protected static Date unmarshallDate(JSONObject obj, String key){ + if(obj.get(key) != null) { + JSONString s = obj.get(key).isString(); + if (s != null) + return DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ss").parse(s.stringValue()); + } + return null; + } + + public static native String getDate(Long ms)/*-{ + return (new Date(ms)).toUTCString(); + }-*/; + + public abstract String getLastModifiedSince(); + + public static T createFromResponse(Class aClass, Response response) { + JSONValue json = JSONParser.parseStrict(response.getText()); + T result = null; + if (aClass.equals(AccountResource.class)) { + AccountResource a = new AccountResource(); + JSONArray array = json.isArray(); + if (array != null) { + for (int i=0; i(`&N7j90ReR$@gW8c32$g13) zT(o)L(FZBToA2CvlwGwWwRH3Oi#Nm4*Tv;+2+vq|`ReV@U%tP6_wnhoS7GUE|NsBb zz;Fgg!hzyX7DfgJc?KN@AOP9P!0P-!y)PwmUWS)eheV=$Ihr{m{v1;m5`OA* uM?n9e5bNelGeb$mv|Tfud>PrVO6mFvOzgT*Fk_Cwx-jRXdAr>e8LR=;7G!?_ literal 0 HcmV?d00001 diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/cellTreeLoadingBasic.gif b/web_client/src/gr/grnet/pithos/web/client/foldertree/cellTreeLoadingBasic.gif new file mode 100644 index 0000000000000000000000000000000000000000..c5fedc3add6133f6452d1355c03bf3e325d04a07 GIT binary patch literal 1737 zcmaLXYfw{X8o=?_KyxEP0w)O)8$zHVLI^RTCm}a-l5i3NhKr{Z5mN#LF{Yp_QrC4l z_C1_4ZkLraj_ZfE)3KdSr_)+iq-#1Z>unv|=^{{3L_~@d?^h_LNa?zD*M4L6`S{K= z@BC)|GmobTH{}O~KnUgmc>44y0R0y){&?WPo!Z(7hhx<3zS7)${lgFMjgSBI(MR_) zGKSUaVV&+0ijLUrqv7!6@#BwIul}~Rb?W~8#fJ|U&zzZk`|Vq0Wmf}%i4!MghKA}%0!`nHj~{4intboQyN!*L$BsS1@hg1(`6EXj9z1v_ zIeCc9K7af6lexL2ojbqp=(sUIzXaipPd<6DxcJM`(l4h@&3yCC4+{%RBO~+O-47o> z{`ta%AE&1mCMJFw7??YEZnm#)W^!_2baZ}p_UEy&`CYrFzxd+O(W8$_O2#TG#;dEZ z)zy9HbdFlBm(QM^ZEycxufKHn?qXKf#eMs3RaITnXfDd--yS-2&+osQm^iq1@6CpW z@AC3SzW(}${{Fd}H=lg@<>NQsoZi3x_WSSOtE?PnnA<+znAba|R9^V_VBH@37jDT3kP&PYqJLA#~7u?3_(iRJNs-O@b!;aNn$ z`STtC$qtH=rLW1MDemfwEG(qdmK|ZPe}M0+J(I|0Ehp@JF0{nFS|!-HNk#)}@+)y0a%wVOQ&GOs z^b z;W!Nnq!lT2F3bH7n6J+(;+f64g|)I_5>r)bs#ATgAi)s%Md8E3{ebQ!0c*u_z&}0* z^7u(x*Z~cT1};u9J0X6hARM7gfz3_jVzH}YtAI-?8~j$fDW^;Z>xGRB5Wc<%YLe_x zUvn7hy}Br&&4KbfLzH@1>KW>&4Y{JInM6_>Pf}*vAnAEI6(fvB9g-_XDThn#a$*)o z?l_I}WUUK|#J^Vm&9R)W>$$E#Ef@OJA|4v#OF5aVHg633eH51NjmU7Db5la8l_XSp z6W#b)i3R3Ysu|!F#6X{h7Zq)N6-FA(Q6%vd*b@1QAzo~S5^G)5_j)n(sO?dIRyxFM zO-g3lN{q~{%~$H6aSm*!kU|zuN!Sc%^PNKqT<}8jik3C25$-bfR1_@140`k&~754&hQQxbQ+`LgyKHz zD@Gj8?q%tsuJ!;F^G-55T4NwuS8$1vZ&<@34FqB!von7e$EQ$SXNKD5Hg2@pWYC=% z`J9CRKe5h{ug(@>2n`6#RPRgWZs*%6v8>iZpk`%CWhF+U4tp-`%nQ{)8}Dp14IqO%%*UJG+w1t34RY9n@te)YuA_h==L|7 zYjQTUCR-USeM_8R;J}rc&n6Eon|SZ@#70|z#comRXkaGXJQn6Ol`AP!oGUf}qu8P@ za&+iyX4;eL6GNlnFjL-$9Yq=F)>!)}gFJM)!;mM3Z0#wAwN?f7S%JQ4jtI))YoxT* zzx!QSy)|cNJtCG=?h2SFZt3q^+v5|$e{c(`&N7j90ReR$@gW8c32$g13) zT(o)L(FZBToA2CvlwGwWwRH3Oi#Nm4*Tv;+2+vq|`ReV@U%tP6_wnhoS7GUE|NsBb zz;Fgg!hzyX7DfgJc?KN@AOP9P!0Plsy)PwmUWS)eheV=$Ihr{m{v1^o5`OBW t6W655m3BBK$;heai&E_@roK$ks96e1Q#U*`uyl-B+m>}UuiuHm8UTgKWgq|m literal 0 HcmV?d00001 diff --git a/web_client/src/gr/grnet/pithos/web/client/rest/GetRequest.java b/web_client/src/gr/grnet/pithos/web/client/rest/GetRequest.java new file mode 100644 index 0000000..4ae9e21 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/rest/GetRequest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.rest; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestBuilder; +import com.google.gwt.http.client.RequestException; +import com.google.gwt.http.client.Response; +import gr.grnet.pithos.web.client.foldertree.Resource; +import java.util.HashMap; +import java.util.Map; + +public abstract class GetRequest implements ScheduledCommand { + + private Class aClass; + + private String path; + + private int okCode; + + private String username; + + private T cached; + + private Map headers = new HashMap(); + + public abstract void onSuccess(T result); + + public abstract void onError(Throwable t); + + public GetRequest(Class aClass, String path, int okCode) { + this.aClass = aClass; + this.path = path; + this.okCode = okCode; + } + + public GetRequest(Class aClass, String path) { + this(aClass, path, -1); + } + + @Override + public void execute() { + RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path); + for (String header : headers.keySet()) + builder.setHeader(header, headers.get(header)); + try { + builder.sendRequest("", new RestRequestCallback(path, okCode) { + @Override + public void onSuccess(T object) { + GetRequest.this.onSuccess(object); + } + + @Override + public T deserialize(Response response) { + return Resource.createFromResponse(aClass, response); + } + + @Override + public void onError(Request request, Throwable throwable) { + if (throwable instanceof RestException) { + if (((RestException) throwable).getHttpStatusCode() == 304 && cached != null){ + GWT.log("Using cache: " + cached.getUri(), null); + onSuccess(cached); + return; + } + } + GetRequest.this.onError(throwable); + } + }); + } + catch (RequestException e) { + } + } + + public void setHeader(String header, String value) { + headers.put(header, value); + } +} diff --git a/web_client/src/gr/grnet/pithos/web/client/rest/RestException.java b/web_client/src/gr/grnet/pithos/web/client/rest/RestException.java index 97d73a6..9db1080 100644 --- a/web_client/src/gr/grnet/pithos/web/client/rest/RestException.java +++ b/web_client/src/gr/grnet/pithos/web/client/rest/RestException.java @@ -26,7 +26,7 @@ public class RestException extends Throwable { } public RestException(String aPath, int aStatusCode, String aStatusText, String aText) { - super("HTTP error: " + aStatusCode+"\nPapth:"+aPath + "\nStatus text:" + aStatusText + "\nText:" + aText); + super("HTTP error: " + aStatusCode+"\nPath:"+aPath + "\nStatus text:" + aStatusText + "\nText:" + aText); httpStatusCode = aStatusCode; httpStatusText = aStatusText; text = aText; diff --git a/web_client/src/gr/grnet/pithos/web/client/rest/RestRequestCallback.java b/web_client/src/gr/grnet/pithos/web/client/rest/RestRequestCallback.java new file mode 100644 index 0000000..0f5e370 --- /dev/null +++ b/web_client/src/gr/grnet/pithos/web/client/rest/RestRequestCallback.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2011 Greek Research and Technology Network + */ + +package gr.grnet.pithos.web.client.rest; + +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestCallback; +import com.google.gwt.http.client.Response; +import gr.grnet.pithos.web.client.foldertree.Resource; + +public abstract class RestRequestCallback implements RequestCallback { + + private static final int HTTP_OK = 200; + private int okcode = -1; + private String path; + + public RestRequestCallback(String path, int okCode) { + this.path = path; + this.okcode = okCode; + } + + public RestRequestCallback(String path) { + this(path, -1); + } + + @Override + public void onResponseReceived(Request request, Response response) { + try { + if (response.getStatusCode() == HTTP_OK || (okcode !=-1 && response.getStatusCode() == okcode)) + onSuccess(deserialize(response)); + else { + String statusText = ""; + String text = ""; + // Ignore JavaScript errors caused by non-existent text. + try { + statusText = response.getStatusText(); + } + catch (Exception e) {} + + try { + text = response.getText(); + } + catch (Exception e) {} + + onError(request, new RestException(path, response.getStatusCode(), statusText, text)); + } + } catch (Exception e) { + onError(request, e); + } + } + + public abstract void onSuccess(T result); + + public abstract T deserialize(Response response); +} diff --git a/web_client/src/gr/grnet/pithos/web/client/rest/resource/RestResource.java b/web_client/src/gr/grnet/pithos/web/client/rest/resource/RestResource.java index 6bb8f2f..c939847 100644 --- a/web_client/src/gr/grnet/pithos/web/client/rest/resource/RestResource.java +++ b/web_client/src/gr/grnet/pithos/web/client/rest/resource/RestResource.java @@ -8,7 +8,6 @@ import java.io.Serializable; import com.google.gwt.json.client.JSONObject; import com.google.gwt.user.client.ui.TreeItem; - public abstract class RestResource implements Serializable{ String uri; -- 1.7.10.4