Permalink
Browse files

New GWT FileBrowser Revision #1 (Replaces SWT FileDialog)

  • Loading branch information...
1 parent 0291795 commit 7e824e6f53324eb9f18677b94f7bec0d2afff10e @willscott willscott committed with DaemonF May 1, 2012
Showing with 347 additions and 989 deletions.
  1. +1 −1 oneswarm_f2f/src/edu/washington/cs/oneswarm/f2f/datagram/DatagramConnection.java
  2. +1 −0 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/OneSwarmGWT.gwt.xml
  3. +174 −0 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/fileDialog/FileBrowser.java
  4. +37 −0 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/fileDialog/FileTreeItem.java
  5. +16 −6 ...warm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/filebrowser/TorrentDownloaderDialog.java
  6. +10 −0 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/i18n/OSMessages.properties
  7. +4 −1 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/newui/SwarmsBrowser.java
  8. +4 −1 ...warm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/newui/creation/CreateSwarmDialogBox.java
  9. +4 −1 ...warm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/newui/publish/PublishSwarmInfoPanel.java
  10. +4 −1 ...t_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/newui/settings/MagicDirectorySettingsPanel.java
  11. +4 −1 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/newui/settings/SaveLocationPanel.java
  12. +4 −1 ...arm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/client/newui/settings/Sha1Ed2kSettingsPanel.java
  13. +5 −0 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/public/OneSwarm.css
  14. +35 −0 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/rpc/FileInfo.java
  15. +2 −2 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/rpc/OneSwarmUIService.java
  16. +3 −3 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/rpc/OneSwarmUIServiceAsync.java
  17. +39 −100 oneswarm_gwt_ui/src/edu/washington/cs/oneswarm/ui/gwt/server/OneSwarmUIServiceImpl.java
  18. +0 −871 oneswarm_gwt_ui/war/OneSwarm.css
@@ -557,7 +557,7 @@ public void run() {
packetNum, datagramSize, message.getDescription()));
}
// This is going to get sent, update the queue size
- queueLength -= datagramSize;
+ queueLength -= messageSize + OSF2FMessage.MESSAGE_HEADER_LEN;
// Check if we can fit more packets in there.
} while ((message = messageQueue.peek()) != null
&& datagramSize + message.getMessageSize() <= MAX_DATAGRAM_PAYLOAD_SIZE
@@ -43,6 +43,7 @@
<!-- <source path="embedded"/> -->
<source path="rpc" />
<source path="client" />
+
<!-- speed up compilation during development -->
<set-property name="user.agent" value="safari,gecko1_8" />
@@ -0,0 +1,174 @@
+package edu.washington.cs.oneswarm.ui.gwt.client.fileDialog;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+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.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.HasTreeItems;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.PopupPanel;
+import com.google.gwt.user.client.ui.ScrollPanel;
+import com.google.gwt.user.client.ui.Tree;
+import com.google.gwt.user.client.ui.TreeItem;
+import com.google.gwt.user.client.ui.VerticalPanel;
+
+import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmGWT;
+import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmRPCClient;
+import edu.washington.cs.oneswarm.ui.gwt.client.ReportableErrorDialogBox;
+import edu.washington.cs.oneswarm.ui.gwt.client.i18n.OSMessages;
+import edu.washington.cs.oneswarm.ui.gwt.rpc.FileInfo;
+import edu.washington.cs.oneswarm.ui.gwt.rpc.OneSwarmUIServiceAsync;
+
+public class FileBrowser {
+ private String session;
+ private boolean directoryOk;
+ private AsyncCallback<String> callback;
+ protected static OSMessages msg;
+
+ private OneSwarmUIServiceAsync fileSystem;
+ private PopupPanel popup;
+
+ private Queue<FileTreeItem> openItems;
+
+
+ // Will be appended to directories for display
+ static final String DIRECTORY_IDENTIFIER = " [...]";
+
+ public FileBrowser(String session, boolean directoryOk, final AsyncCallback<String> callback) {
+ this.session = session;
+ this.callback = callback;
+ this.directoryOk = directoryOk;
+ msg = OneSwarmGWT.msg;
+ }
+
+ private void createPopup() {
+ openItems = new LinkedList<FileTreeItem>();
+
+ final Tree fileTree = new Tree();
+ growTree(fileTree,"");
+
+ fileTree.addOpenHandler(new OpenHandler<TreeItem>() {
+ public void onOpen(OpenEvent<TreeItem> event) {
+ FileTreeItem item = (FileTreeItem) event.getTarget();
+ if (item.isDirectory()) {
+ if (!item.hasBeenExpanded){
+ growTree(item);
+ }
+ }
+ closeItems(item.filePath());
+ openItems.add(item);
+ }
+
+ });
+
+ Button selectButton = new Button(msg.file_browser_button_select());
+ selectButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ FileTreeItem item = (FileTreeItem) fileTree.getSelectedItem();
+ if(item.fileStatus() == FileInfo.FileStatusFlag.NO_READ_PERMISSION)
+ new ReportableErrorDialogBox(msg.file_browser_error_permission_denied(),false).show();
+ else if(!directoryOk && item.isDirectory())
+ new ReportableErrorDialogBox(msg.file_browser_error_directory_selected(),false).show();
+ else{
+ callback.onSuccess(item.filePath());
+ popup.hide();
+ }
+ }
+ });
+
+ Button closeButton = new Button(msg.file_browser_button_cancel());
+ closeButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ callback.onFailure(new Exception("No file Selected"));
+ popup.hide();
+ }
+ });
+
+ HorizontalPanel footer = new HorizontalPanel();
+ footer.add(closeButton);
+ footer.add(selectButton);
+
+ ScrollPanel scrollArea = new ScrollPanel(fileTree);
+ scrollArea.setHeight("400px");
+ scrollArea.setWidth("450px");
+
+ VerticalPanel contents = new VerticalPanel();
+ contents.add(scrollArea);
+ contents.add(footer);
+
+ popup = new PopupPanel(false);
+ popup.setStylePrimaryName("fileBrowserPopup");
+ popup.setStyleName("gwt-DialogBox", true);
+ popup.setStyleName("Top", true);
+ popup.setGlassEnabled(true);
+ popup.setTitle(msg.file_browser_title());
+ popup.setWidget(contents);
+ }
+
+ private void closeItems(String exceptThis) {
+ int size = openItems.size();
+ for (int i = 0; i < size; i++) {
+ FileTreeItem current = openItems.remove();
+ if (!exceptThis.startsWith(current.filePath()))
+ current.setState(false);
+ else
+ openItems.add(current);
+ }
+ }
+
+ private void growTree(final FileTreeItem item){
+ growTree(item, item.filePath());
+ item.hasBeenExpanded = true;
+ }
+
+ private void growTree(final HasTreeItems root, String filePath) {
+ if (fileSystem == null) {
+ fileSystem = OneSwarmRPCClient.getService();
+ }
+
+ root.removeItems();
+
+ if(root instanceof FileTreeItem)
+ if(((FileTreeItem) root).fileStatus() == FileInfo.FileStatusFlag.NO_READ_PERMISSION){
+ root.addItem(new FileTreeItem(msg.file_browser_label_unreadable_directory()));
+ ((FileTreeItem) root).setState(true);
+ }
+
+ fileSystem.listFiles(session, filePath, new AsyncCallback<FileInfo[]>() {
+ public void onFailure(Throwable caught) {
+ callback.onFailure(caught);
+ }
+
+ public void onSuccess(FileInfo[] result) {
+ if (result != null) {
+ if(result.length == 0)
+ root.addItem(new FileTreeItem(msg.file_browser_label_empty_directory()));
+ else{
+ for (int i = 0; i < result.length; i++) {
+ FileTreeItem temp = new FileTreeItem(result[i]);
+ if (temp.isDirectory())
+ temp.addItem(new FileTreeItem(msg.file_browser_label_loading_directory()));
+ root.addItem(temp);
+
+ }
+ }
+ if(root instanceof FileTreeItem)
+ ((FileTreeItem) root).setState(true);
+ }
+ }
+ });
+ }
+
+ public void show() {
+ if (popup == null)
+ createPopup();
+ popup.center();
+ }
+}
@@ -0,0 +1,37 @@
+package edu.washington.cs.oneswarm.ui.gwt.client.fileDialog;
+
+import com.google.gwt.user.client.ui.TreeItem;
+
+import edu.washington.cs.oneswarm.ui.gwt.rpc.FileInfo;
+
+public class FileTreeItem extends TreeItem {
+ private FileInfo file;
+ public boolean hasBeenExpanded;
+
+ public FileTreeItem(String labelText){
+ super(labelText);
+ file = new FileInfo("", labelText, false, false);
+ hasBeenExpanded = false;
+ }
+
+ public FileTreeItem(FileInfo file) {
+ super(file.name);
+ this.file = file;
+ }
+
+ public String fileName() {
+ return file.name;
+ }
+
+ public String filePath() {
+ return file.filePath;
+ }
+
+ public boolean isDirectory() {
+ return file.isDirectory;
+ }
+
+ public FileInfo.FileStatusFlag fileStatus(){
+ return file.statusFlag;
+ }
+}
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.Set;
+
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.gen2.table.client.FixedWidthFlexTable;
@@ -34,6 +35,7 @@
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmGWT;
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmRPCClient;
import edu.washington.cs.oneswarm.ui.gwt.client.Updateable;
+import edu.washington.cs.oneswarm.ui.gwt.client.fileDialog.FileBrowser;
import edu.washington.cs.oneswarm.ui.gwt.client.newui.EntireUIRoot;
import edu.washington.cs.oneswarm.ui.gwt.client.newui.HelpButton;
import edu.washington.cs.oneswarm.ui.gwt.client.newui.OneSwarmCss;
@@ -793,10 +795,14 @@ public void onClick(Widget sender) {
if (OneSwarmGWT.isRemoteAccess()) {
locationButton.setEnabled(false);
}
- locationButton.addClickListener(new ClickListener() {
- public void onClick(Widget sender) {
- locationButton.setEnabled(false);
- OneSwarmRPCClient.getService().selectFileOrDirectory(
+
+ locationButton.addClickHandler(new ClickHandler(){
+
+ @Override
+ public void onClick(ClickEvent event) {
+ locationButton.setEnabled(false);
+
+ FileBrowser dialog = new FileBrowser(
OneSwarmRPCClient.getSessionID(), true, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
System.err.println(caught.toString());
@@ -810,9 +816,13 @@ public void onSuccess(String result) {
.truncate(result, 50, true));
}
}
- });
- }
+ }
+ );
+ dialog.show();
+ }
+
});
+
locationButton.addStyleName(OneSwarmCss.SMALL_BUTTON);
locationPanel.add(locationButton);
locationPanel.setCellVerticalAlignment(locationLabel, VerticalPanel.ALIGN_MIDDLE);
@@ -532,3 +532,13 @@ chat_no_access_yours=This friend does not have access to your file list, and so
chat_no_access_friends=Your friend may not have permission to access the selected files of your friends.
chat_user_offline=Disconnected. Pending messages will be sent when you connect to this person again.
chat_pending=Pending
+
+file_browser_title=File Browser
+file_browser_button_cancel=Cancel
+file_browser_button_select=Select
+file_browser_label_empty_directory=-Empty Directory-
+file_browser_label_loading_directory=Loading...
+file_browser_label_unreadable_directory=-Permission Denied-
+file_browser_error_directory_selected=You have selected a directory. Please choose a file.
+file_browser_error_permission_denied=The selected file could not be found or does not have read permission. Please choose another file.
+
@@ -7,6 +7,7 @@
import java.util.List;
import java.util.Map;
+
import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
@@ -51,6 +52,7 @@
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmRPCClient;
import edu.washington.cs.oneswarm.ui.gwt.client.ReportableErrorDialogBox;
import edu.washington.cs.oneswarm.ui.gwt.client.Updateable;
+import edu.washington.cs.oneswarm.ui.gwt.client.fileDialog.FileBrowser;
import edu.washington.cs.oneswarm.ui.gwt.client.filebrowser.TorrentDownloaderDialog;
import edu.washington.cs.oneswarm.ui.gwt.client.filebrowser.UpdateSkippedFilesDialog;
import edu.washington.cs.oneswarm.ui.gwt.client.i18n.OSMessages;
@@ -700,7 +702,7 @@ public void onSuccess(String success) {
} else if (inActionKey.equals(Strings.ADD_SWARM_FILE)) {
- OneSwarmRPCClient.getService().selectFileOrDirectory(OneSwarmRPCClient.getSessionID(),
+ FileBrowser dialog = new FileBrowser(OneSwarmRPCClient.getSessionID(),
false, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
@@ -745,6 +747,7 @@ public void onSuccess(Void result) {
});
}
});
+ dialog.show();
} else if (inActionKey.equals(Strings.SWARM_DELETE)) {
@@ -2,6 +2,7 @@
import java.util.ArrayList;
+
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.event.dom.client.ChangeEvent;
@@ -28,6 +29,7 @@
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmDialogBox;
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmGWT;
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmRPCClient;
+import edu.washington.cs.oneswarm.ui.gwt.client.fileDialog.FileBrowser;
import edu.washington.cs.oneswarm.ui.gwt.client.filebrowser.TorrentDownloaderDialog;
import edu.washington.cs.oneswarm.ui.gwt.client.newui.EntireUIRoot;
import edu.washington.cs.oneswarm.ui.gwt.client.newui.HelpButton;
@@ -518,7 +520,7 @@ public void onClick(ClickEvent event) {
* directory dialog box in GWT or HTML in general.
*/
OneSwarmGWT.log("select file/dir called");
- OneSwarmRPCClient.getService().selectFileOrDirectory(OneSwarmRPCClient.getSessionID(),
+ FileBrowser dialog = new FileBrowser(OneSwarmRPCClient.getSessionID(),
useDirChooser, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
caught.printStackTrace();
@@ -559,6 +561,7 @@ public void onTreeItemStateChanged(TreeItem item) {
}
}
});
+ dialog.show();
} else {
super.onClick(event);
}
@@ -2,6 +2,7 @@
import java.util.List;
+
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@@ -20,6 +21,7 @@
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmGWT;
import edu.washington.cs.oneswarm.ui.gwt.client.OneSwarmRPCClient;
+import edu.washington.cs.oneswarm.ui.gwt.client.fileDialog.FileBrowser;
import edu.washington.cs.oneswarm.ui.gwt.client.i18n.OSMessages;
import edu.washington.cs.oneswarm.ui.gwt.client.newui.OneSwarmCss;
import edu.washington.cs.oneswarm.ui.gwt.rpc.StringTools;
@@ -56,7 +58,7 @@ public void onError(ErrorEvent event) {
includePreview.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
- OneSwarmRPCClient.getService().selectFileOrDirectory(
+ FileBrowser dialog = new FileBrowser(
OneSwarmRPCClient.getSessionID(), false, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
caught.printStackTrace();
@@ -73,6 +75,7 @@ public void onSuccess(String result) {
previewImage.setVisible(true);
}
});
+ dialog.show();
}
});
lhs.add(previewImage);
Oops, something went wrong.

0 comments on commit 7e824e6

Please sign in to comment.