X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/2d91458af2b258e9d9fa4d067d212f83a31e4d42..3601b11418d522e5f72e8102c7871fa05bcf4ca6:/src/gr/grnet/pithos/web/client/Pithos.java diff --git a/src/gr/grnet/pithos/web/client/Pithos.java b/src/gr/grnet/pithos/web/client/Pithos.java index 479aa7d..08d6261 100644 --- a/src/gr/grnet/pithos/web/client/Pithos.java +++ b/src/gr/grnet/pithos/web/client/Pithos.java @@ -58,6 +58,7 @@ import gr.grnet.pithos.web.client.tagtree.TagTreeView; import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -84,6 +85,7 @@ import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONString; import com.google.gwt.json.client.JSONValue; import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.resources.client.ImageResource.ImageOptions; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Cookies; import com.google.gwt.user.client.Event; @@ -91,11 +93,13 @@ 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.Button; +import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.HorizontalSplitPanel; +import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.view.client.SelectionChangeEvent; @@ -137,6 +141,10 @@ public class Pithos implements EntryPoint, ResizeHandler { groupTreeView.updateGroupNode(group); } + public void updateMySharedRoot() { + mysharedTreeView.updateRoot(); + } + public void updateSharedFolder(Folder f, boolean showfiles) { mysharedTreeView.updateFolder(f, showfiles); } @@ -169,9 +177,12 @@ public class Pithos implements EntryPoint, ResizeHandler { ImageResource folders(); @Source("gr/grnet/pithos/resources/advancedsettings.png") + @ImageOptions(width=32, height=32) ImageResource tools(); } + private Throwable error; + /** * The Application Clipboard implementation; */ @@ -185,7 +196,7 @@ public class Pithos implements EntryPoint, ResizeHandler { /** * The panel that contains the various system messages. */ - private MessagePanel messagePanel = new MessagePanel(Pithos.images); + private MessagePanel messagePanel = new MessagePanel(this, Pithos.images); /** * The bottom panel that contains the status bar. @@ -240,17 +251,17 @@ public class Pithos implements EntryPoint, ResizeHandler { GroupTreeViewModel groupTreeViewModel; private GroupTreeView groupTreeView; - private TreeView selectedTree; + TreeView selectedTree; protected AccountResource account; Folder trash; + + List treeViews = new ArrayList(); @SuppressWarnings("rawtypes") List selectionModels = new ArrayList(); Button upload; - private HTML totalFiles; - private HTML usedBytes; private HTML totalBytes; @@ -259,7 +270,9 @@ public class Pithos implements EntryPoint, ResizeHandler { private HTML numOfFiles; - private Button toolsButton; + private Image refreshButton; + + private Image toolsButton; @Override public void onModuleLoad() { @@ -284,16 +297,11 @@ public class Pithos implements EntryPoint, ResizeHandler { outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER); } - messagePanel.setWidth(contentWidth); - messagePanel.setVisible(false); - outer.add(messagePanel); - outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); - HorizontalPanel header = new HorizontalPanel(); header.addStyleName("pithos-header"); header.setWidth(contentWidth); - HorizontalPanel leftHeader = new HorizontalPanel(); - VerticalPanel uploadButtonPanel = new VerticalPanel(); + if (bareContent) + header.addStyleName("pithos-header-noframe"); upload = new Button("Upload File", new ClickHandler() { @Override public void onClick(@SuppressWarnings("unused") ClickEvent event) { @@ -301,20 +309,45 @@ public class Pithos implements EntryPoint, ResizeHandler { } }); upload.addStyleName("pithos-uploadButton"); - uploadButtonPanel.add(upload); - uploadButtonPanel.setWidth("100%"); - uploadButtonPanel.setHeight("60px"); - uploadButtonPanel.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT); - uploadButtonPanel.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE); - leftHeader.add(uploadButtonPanel); - header.add(leftHeader); - header.setCellWidth(leftHeader, "35%"); + header.add(upload); + header.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT); + header.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE); +// header.setCellWidth(upload, "146px"); + + messagePanel.setVisible(false); + header.add(messagePanel); + header.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); + header.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE); - HorizontalPanel rightHeader = new HorizontalPanel(); - rightHeader.addStyleName("pithos-rightSide"); - rightHeader.setSpacing(5); + refreshButton = new Image(images.refresh()); + refreshButton.addStyleName("pithos-toolsButton"); + refreshButton.setWidth("32px"); + refreshButton.setHeight("32px"); + refreshButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(@SuppressWarnings("unused") ClickEvent event) { + boolean isFolderTreeSelected = selectedTree.equals(getFolderTreeView()); + boolean otherSharedTreeSelected = selectedTree.equals(getOtherSharedTreeView()); + Folder folder = getSelectedTree().getSelection(); + + if (folder != null && (isFolderTreeSelected || otherSharedTreeSelected)) + updateFolder(folder, true, new Command() { + + @Override + public void execute() { + updateStatistics(); + } + }); + } + }); + header.add(refreshButton); + header.setCellHorizontalAlignment(refreshButton, HasHorizontalAlignment.ALIGN_CENTER); + header.setCellVerticalAlignment(refreshButton, HasVerticalAlignment.ALIGN_MIDDLE); + header.setCellWidth(refreshButton, "40px"); - toolsButton = new Button(AbstractImagePrototype.create(images.tools()).getHTML()); + toolsButton = new Image(images.tools()); + toolsButton.addStyleName("pithos-toolsButton"); toolsButton.addClickHandler(new ClickHandler() { @Override @@ -326,9 +359,11 @@ public class Pithos implements EntryPoint, ResizeHandler { } } }); - rightHeader.add(toolsButton); - rightHeader.setCellHorizontalAlignment(toolsButton, HasHorizontalAlignment.ALIGN_LEFT); - + header.add(toolsButton); + header.setCellHorizontalAlignment(toolsButton, HasHorizontalAlignment.ALIGN_CENTER); + header.setCellVerticalAlignment(toolsButton, HasVerticalAlignment.ALIGN_MIDDLE); + header.setCellWidth(toolsButton, "40px"); + HorizontalPanel folderStatistics = new HorizontalPanel(); folderStatistics.addStyleName("pithos-folderStatistics"); numOfFiles = new HTML(); @@ -337,11 +372,10 @@ public class Pithos implements EntryPoint, ResizeHandler { HTML numOfFilesLabel = new HTML(" Files"); folderStatistics.add(numOfFilesLabel); folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE); - rightHeader.add(folderStatistics); - rightHeader.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT); - header.add(rightHeader); - header.setCellVerticalAlignment(rightHeader, HasVerticalAlignment.ALIGN_MIDDLE); - header.setCellHeight(rightHeader, "60px"); + header.add(folderStatistics); + header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT); + header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE); + header.setCellWidth(folderStatistics, "40px"); outer.add(header); outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER); // Inner contains the various lists.nner @@ -355,25 +389,24 @@ public class Pithos implements EntryPoint, ResizeHandler { if (folderTreeSelectionModel.getSelectedObject() != null) { deselectOthers(folderTreeView, folderTreeSelectionModel); applyPermissions(folderTreeSelectionModel.getSelectedObject()); - folderTreeView.addStyleName("cellTreeWidget-selectedTree"); Folder f = folderTreeSelectionModel.getSelectedObject(); showFiles(f); } - else - folderTreeView.removeStyleName("cellTreeWidget-selectedTree"); } }); selectionModels.add(folderTreeSelectionModel); folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel); folderTreeView = new FolderTreeView(folderTreeViewModel); - + treeViews.add(folderTreeView); + fileList = new FileList(this, images, folderTreeView); inner.add(fileList); groupTreeViewModel = new GroupTreeViewModel(this); groupTreeView = new GroupTreeView(groupTreeViewModel); - + treeViews.add(groupTreeView); + trees = new VerticalPanel(); trees.setWidth("100%"); @@ -384,10 +417,7 @@ public class Pithos implements EntryPoint, ResizeHandler { treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); HorizontalPanel statistics = new HorizontalPanel(); statistics.addStyleName("pithos-statistics"); - statistics.add(new HTML("Total Objects: ")); - totalFiles = new HTML(); - statistics.add(totalFiles); - statistics.add(new HTML(" | Used: ")); + statistics.add(new HTML("Used: ")); usedBytes = new HTML(); statistics.add(usedBytes); statistics.add(new HTML(" of ")); @@ -419,6 +449,8 @@ public class Pithos implements EntryPoint, ResizeHandler { outer.add(statusPanel); outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER); } + else + splitPanel.addStyleName("pithos-splitPanel-noframe"); // Hook the window resize event, so that we can adjust the UI. Window.addResizeHandler(this); @@ -470,6 +502,15 @@ public class Pithos implements EntryPoint, ResizeHandler { }); } }); + +// Scheduler.get().scheduleDeferred(new Command() { +// +// @Override +// public void execute() { +// displayError("lalala"); +// +// } +// }); } public void applyPermissions(Folder f) { @@ -492,6 +533,13 @@ public class Pithos implements EntryPoint, ResizeHandler { @SuppressWarnings({ "rawtypes", "unchecked" }) public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) { selectedTree = _selectedTree; + + for (Composite c : treeViews) + if (c.equals(selectedTree)) + c.addStyleName("cellTreeWidget-selectedTree"); + else + c.removeStyleName("cellTreeWidget-selectedTree"); + for (SingleSelectionModel s : selectionModels) if (!s.equals(model)) s.setSelected(s.getSelectedObject(), false); @@ -521,6 +569,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("Error getting file", t); + setError(t); if (t instanceof RestException) displayError("Error getting file: " + ((RestException) t).getHttpStatusText()); else @@ -553,6 +602,10 @@ public class Pithos implements EntryPoint, ResizeHandler { authenticateUser(); return false; } + if (auth.startsWith("\"")) + auth = auth.substring(1); + if (auth.endsWith("\"")) + auth = auth.substring(0, auth.length() - 1); String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); if (authSplit.length != 2) { authenticateUser(); @@ -562,7 +615,8 @@ public class Pithos implements EntryPoint, ResizeHandler { token = authSplit[1]; return true; } - Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token); + + Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token, null, "", "/", false); return true; } @@ -588,6 +642,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("Error getting account", t); + setError(t); if (t instanceof RestException) displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); else @@ -614,6 +669,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("Error getting account", t); + setError(t); if (t instanceof RestException) displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); else @@ -630,7 +686,6 @@ public class Pithos implements EntryPoint, ResizeHandler { } protected void showStatistics() { - totalFiles.setHTML(String.valueOf(account.getNumberOfObjects())); usedBytes.setHTML(String.valueOf(account.getFileSizeAsString())); totalBytes.setHTML(String.valueOf(account.getQuotaAsString())); NumberFormat nf = NumberFormat.getPercentFormat(); @@ -651,6 +706,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("Error creating pithos", t); + setError(t); if (t instanceof RestException) displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText()); else @@ -677,6 +733,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("Error creating pithos", t); + setError(t); if (t instanceof RestException) displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText()); else @@ -708,19 +765,19 @@ public class Pithos implements EntryPoint, ResizeHandler { return captionHTML; } -// protected void onWindowResized(int height) { -// // Adjust the split panel to take up the available room in the window. -// int newHeight = height - splitPanel.getAbsoluteTop() - 60; -// if (newHeight < 1) -// newHeight = 1; -// splitPanel.setHeight("" + newHeight); -// inner.setHeight("" + newHeight); -// } + protected void onWindowResized(int height) { + // Adjust the split panel to take up the available room in the window. + int newHeight = height - splitPanel.getAbsoluteTop(); + if (newHeight < 1) + newHeight = 1; + splitPanel.setHeight("" + newHeight); + inner.setHeight("" + newHeight); + } @Override public void onResize(ResizeEvent event) { int height = event.getHeight(); -// onWindowResized(height); + onWindowResized(height); } /** @@ -836,6 +893,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(@SuppressWarnings("unused") Request request, Throwable exception) { + setError(exception); displayError("System error unable to delete folder: " + exception.getMessage()); } }); @@ -859,6 +917,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("", t); + setError(t); displayError("System error unable to delete folder: " + t.getMessage()); } @@ -895,6 +954,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(@SuppressWarnings("unused") Request request, Throwable exception) { + setError(exception); displayError("System error unable to delete folder: " + exception.getMessage()); } }); @@ -920,6 +980,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("", t); + setError(t); if (t instanceof RestException) { if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND) displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText()); @@ -957,6 +1018,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("", t); + setError(t); if (t instanceof RestException) { displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText()); } @@ -970,9 +1032,10 @@ public class Pithos implements EntryPoint, ResizeHandler { } }; copyFile.setHeader("X-Auth-Token", getToken()); - copyFile.setHeader("X-Copy-From", file.getUri()); + copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri())); if (!file.getOwner().equals(targetUsername)) - copyFile.setHeader("X-Source-Account", file.getOwner()); + copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner())); + copyFile.setHeader("Content-Type", file.getContentType()); Scheduler.get().scheduleDeferred(copyFile); } else if (callback != null) { @@ -1018,6 +1081,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("", t); + setError(t); if (t instanceof RestException) { displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText()); } @@ -1037,7 +1101,8 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("", t); - if (t instanceof RestException) { + setError(t); + if (t instanceof RestException) { displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText()); } else @@ -1117,7 +1182,7 @@ public class Pithos implements EntryPoint, ResizeHandler { upload.setEnabled(false); updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true); } - } + } }); selectionModels.add(mysharedTreeSelectionModel); mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel); @@ -1126,7 +1191,8 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void execute() { mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel); - trees.insert(mysharedTreeView, 3); + trees.insert(mysharedTreeView, 2); + treeViews.add(mysharedTreeView); createOtherSharedTree(); } }); @@ -1139,10 +1205,11 @@ public class Pithos implements EntryPoint, ResizeHandler { public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { if (otherSharedTreeSelectionModel.getSelectedObject() != null) { deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel); + otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree"); applyPermissions(otherSharedTreeSelectionModel.getSelectedObject()); updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true); } - } + } }); selectionModels.add(otherSharedTreeSelectionModel); otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel); @@ -1151,18 +1218,29 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void execute() { otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel); - trees.insert(otherSharedTreeView, 4); + trees.insert(otherSharedTreeView, 3); + treeViews.add(otherSharedTreeView); } }); } public void logoff() { Configuration conf = (Configuration) GWT.create(Configuration.class); - Cookies.removeCookie(conf.authCookie()); + Cookies.removeCookie(conf.authCookie(), "/"); Cookies.removeCookie(conf.authTokenCookie(), "/"); for (String s: Cookies.getCookieNames()) if (s.startsWith(conf.shibSessionCookiePrefix())) Cookies.removeCookie(s, "/"); Window.Location.assign(Window.Location.getPath()); } + + public String getErrorData() { + if (error != null) + return error.toString(); + return ""; + } + + public void setError(Throwable t) { + error = t; + } }