source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/com/gs3/testGXT/client/tree/MyLocalFileSystemTree.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 3.2 KB
Line 
1package com.gs3.testGXT.client.tree;
2
3import java.util.ArrayList;
4import java.util.LinkedList;
5
6import com.google.gwt.core.client.GWT;
7import com.google.gwt.user.client.rpc.AsyncCallback;
8import com.gs3.testGXT.client.Keys.FileSystemKey;
9import com.gs3.testGXT.client.services.ListDirectoryService;
10import com.gs3.testGXT.client.services.ListDirectoryServiceAsync;
11import com.sencha.gxt.core.client.ValueProvider;
12import com.sencha.gxt.data.shared.TreeStore;
13import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
14import com.sencha.gxt.widget.core.client.event.BeforeExpandItemEvent;
15import com.sencha.gxt.widget.core.client.event.BeforeExpandItemEvent.BeforeExpandItemHandler;
16import com.sencha.gxt.widget.core.client.tree.Tree;
17
18public class MyLocalFileSystemTree extends Tree<FileSystemKey, FileSystemKey> {
19 protected ListDirectoryServiceAsync listDirService = null;
20 AsyncCallback<LinkedList<String[]>> callback = null;
21
22 public MyLocalFileSystemTree(MyTreeStoreExt store,
23 ValueProvider<? super FileSystemKey, FileSystemKey> valueProvider) {
24 super(store, valueProvider);
25 this.addBeforeExpandHandler(new myOtherBeforeExtendHandler(store));
26
27 listDirService = GWT.create(ListDirectoryService.class);
28 }
29
30 class myOtherBeforeExtendHandler implements BeforeExpandItemHandler<FileSystemKey> {
31 TreeStore<FileSystemKey> ts;
32 public myOtherBeforeExtendHandler(TreeStore<FileSystemKey> ts) {
33 this.ts = ts;
34 }
35
36 @Override
37 public void onBeforeExpand(BeforeExpandItemEvent<FileSystemKey> event) {
38 final FileSystemKey parent = event.getItem();
39 if(!parent.Walked()) {
40 final String key = parent.toKey();
41 final String path = parent.toPath();
42 ts.removeChildren(parent);
43
44 callback = new AsyncCallback<LinkedList<String[]>>() {
45 public void onFailure(Throwable caught) {
46 AlertMessageBox amb = new AlertMessageBox("Error", "Error: " + caught.getMessage()); //TODO: this is going to be messy - fix
47 amb.show();
48 }
49
50 public void onSuccess(LinkedList<String[]> result) {
51 updateStore(result, ts, parent, key, path);
52 parent.setWalked();
53 }
54 };
55
56 listDirService.getDirectoryContents(path, callback);
57 }
58 }
59 }
60
61 public void refreshTree(FileSystemKey k) {
62 if(store instanceof MyTreeStoreExt) {
63 ((MyTreeStoreExt)store).Refresh(k, this);
64 }
65 }
66
67 private void updateStore(LinkedList<String[]> result, TreeStore<FileSystemKey> ts, FileSystemKey parent, String key, String path) {
68 ArrayList<FileSystemKey> keylist = new ArrayList<FileSystemKey>(result.size());
69 for(String[] set : result) {
70 //structure:
71 // File/Folder
72 // Name
73 // Canonical Path
74 FileSystemKey child = null;
75 if(set[0].equals("File")) {
76 child = new FileSystemKey(key, set[1], false, true, set[2]); //key, name, file, realized, path
77 }
78 else if (set[0].equals("Folder")) {
79 child = new FileSystemKey(key, set[1], true, false, set[2]); //key, name, folder, not realized, path
80 }
81 keylist.add(child);
82 }
83 ts.add(parent, keylist);
84 //ts.update(parent);
85 }
86
87 @Override
88 protected boolean hasChildren(FileSystemKey model) {
89 // This will control the leaf behavior: true for looking like a folder and false to look like an item
90 return model.isFolder();
91 }
92}
Note: See TracBrowser for help on using the repository browser.