-
- public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) {
- selectionModels.add(model);
- }
-
- public OtherSharedTreeView getOtherSharedTreeView() {
- return otherSharedTreeView;
- }
-
- public void updateTrash(boolean showFiles, Command callback) {
- updateFolder(trash, showFiles, callback, true);
- }
-
- public void updateGroupsNode() {
- groupTreeView.updateGroupNode(null);
- }
-
- public Group addGroup(String groupname) {
- Group newGroup = new Group(groupname);
- account.addGroup(newGroup);
- groupTreeView.updateGroupNode(null);
- return newGroup;
- }
-
- public void removeGroup(Group group) {
- account.removeGroup(group);
- updateGroupsNode();
- }
-
- public TreeView getSelectedTree() {
- return selectedTree;
- }
-
- public void setSelectedTree(TreeView selected) {
- selectedTree = selected;
- }
-
- public Folder getSelection() {
- if (selectedTree != null)
- return selectedTree.getSelection();
- return null;
- }
-
- public void showFolderStatistics(int folderFileCount) {
- numOfFiles.setHTML(String.valueOf(folderFileCount));
- }
-
- public GroupTreeView getGroupTreeView() {
- return groupTreeView;
- }
-
- public void sessionExpired() {
- new SessionExpiredDialog(this).center();
- }
-
- public void updateRootFolder(Command callback) {
- updateFolder(account.getPithos(), false, callback, true);
- }
-
- void createMySharedTree() {
- mysharedTreeSelectionModel = new SingleSelectionModel<Folder>();
- mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
- @Override
- public void onSelectionChange(SelectionChangeEvent event) {
- if (mysharedTreeSelectionModel.getSelectedObject() != null) {
- deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
- upload.setEnabled(false);
- hideUploadArea();
- updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
- showRelevantToolbarButtons();
- }
- else {
- if (getSelectedTree().equals(mysharedTreeView))
- setSelectedTree(null);
- if (getSelectedTree() == null)
- showRelevantToolbarButtons();
- }
- }
- });
- selectionModels.add(mysharedTreeSelectionModel);
- mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
- mysharedTreeViewModel.initialize(new Command() {
-
- @Override
- public void execute() {
- mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
- trees.insert(mysharedTreeView, 2);
- treeViews.add(mysharedTreeView);
- createOtherSharedTree();
- }
- });
- }
-
- void createOtherSharedTree() {
- otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>();
- otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
- @Override
- public void onSelectionChange(SelectionChangeEvent event) {
- if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
- deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
- applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
- updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
- showRelevantToolbarButtons();
- }
- else {
- if (getSelectedTree().equals(otherSharedTreeView))
- setSelectedTree(null);
- if (getSelectedTree() == null)
- showRelevantToolbarButtons();
- }
- }
- });
- selectionModels.add(otherSharedTreeSelectionModel);
- otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
- otherSharedTreeViewModel.initialize(new Command() {
-
- @Override
- public void execute() {
- otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
- trees.insert(otherSharedTreeView, 1);
- treeViews.add(otherSharedTreeView);
- }
- });
- }
-
- public native void log1(String message)/*-{
- $wnd.console.log(message);
- }-*/;
-
- public String getErrorData() {
- if (error != null)
- return error.toString();
- return "";
- }
-
- public void setError(Throwable t) {
- error = t;
- }
-
- public void showRelevantToolbarButtons() {
- toolbar.showRelevantButtons();
- }
-
- public FileUploadDialog getFileUploadDialog() {
- if (fileUploadDialog == null)
- fileUploadDialog = new FileUploadDialog(this);
- return fileUploadDialog;
- }
-
- public void hideUploadIndicator() {
- upload.removeStyleName("pithos-uploadButton-loading");
- upload.setTitle("");
- }
-
- public void showUploadIndicator() {
- upload.addStyleName("pithos-uploadButton-loading");
- upload.setTitle("Upload in progress. Click for details.");
- }
-
- public void scheduleFolderHeadCommand(final Folder folder, final Command callback) {
- if (folder == null) {
- if (callback != null)
- callback.execute();
- }
- else {
- HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwner(), folder.getUri(), folder) {
-
- @Override
- public void onSuccess(Folder _result) {
- if (callback != null)
- callback.execute();
- }
-
- @Override
- public void onError(Throwable t) {
- if (t instanceof RestException) {
- if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
- final String path = folder.getUri();
- PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwner(), path) {
- @Override
- public void onSuccess(Resource _result) {
- scheduleFolderHeadCommand(folder, callback);
- }
-
- @Override
- public void onError(Throwable _t) {
- GWT.log("", _t);
- setError(_t);
- if(_t instanceof RestException){
- displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
- }
- else
- displayError("System error creating folder: " + _t.getMessage());
- }
-
- @Override
- protected void onUnauthorized(Response response) {
- sessionExpired();
- }
- };
- newFolder.setHeader("X-Auth-Token", getToken());
- newFolder.setHeader("Content-Type", "application/folder");
- newFolder.setHeader("Accept", "*/*");
- newFolder.setHeader("Content-Length", "0");
- Scheduler.get().scheduleDeferred(newFolder);
- }
- else
- displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
- }
- else
- displayError("System error heading folder: " + t.getMessage());
-
- GWT.log("Error heading folder", t);
- setError(t);
- }
-
- @Override
- protected void onUnauthorized(Response response) {
- sessionExpired();
- }
- };
- headFolder.setHeader("X-Auth-Token", getToken());
- Scheduler.get().scheduleDeferred(headFolder);
- }
- }
-
- public void scheduleFileHeadCommand(File f, final Command callback) {
- HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwner(), f.getUri(), f) {
-
- @Override
- public void onSuccess(File _result) {
- if (callback != null)
- callback.execute();
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("Error heading file", t);
- setError(t);
- if (t instanceof RestException)
- displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
- else
- displayError("System error heading file: " + t.getMessage());
- }
-
- @Override
- protected void onUnauthorized(Response response) {
- sessionExpired();
- }
- };
- headFile.setHeader("X-Auth-Token", getToken());
- Scheduler.get().scheduleDeferred(headFile);
- }
-
- public boolean isMySharedSelected() {
- return getSelectedTree().equals(getMySharedTreeView());
- }
-
- private FlowPanel createUploadArea() {
- FlowPanel area = new FlowPanel();
- area.getElement().setId("container");
- HTML list = new HTML();
- list.getElement().setId("filelist");
- area.add(list);
- Scheduler.get().scheduleDeferred(new ScheduledCommand() {
-
- @Override
- public void execute() {
- setupUploadArea(Pithos.this, getToken());
- }
- });
-
- return area;
- }
-
- native void setupUploadArea(Pithos app, String token) /*-{
- $wnd.$("#container").pluploadQueue({
- // General settings
- runtimes : 'html5',
- unique_names : true,
- multiple_queues: true,
- drop_element: 'filelist',
-
- preinit: {
- Init: function(up, info) {
- if ($wnd.console && $wnd.console.log)
- $wnd.console.log("Init fired");
- up.settings.file_data_name = "X-Object-Data";
- }
- },
-
- init: {
- FilesAdded: function(up, files) {
- $wnd.$('#container').css('border', '');
- var api = app.@gr.grnet.pithos.web.client.Pithos::getApiPath()();
- var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
- var owner = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getOwner()();
- var uri = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getUri()();
- var path = api + owner + uri;
- for (var j=0; j<files.length; j++) {
- files[j].folder = folder;
- files[j].url = path + "/" + files[j].name + "?X-Auth-Token=" + encodeURIComponent(token);
- }
- up.start();
- },
-
- BeforeUpload: function(up, file) {
- if ($wnd.console && $wnd.console.log)
- $wnd.console.log('About to upload ' + file.url);
- up.settings.url = file.url;
- },
-
- FileUploaded: function(up, file, response) {
- if ($wnd.console && $wnd.console.log) {
- $wnd.console.log('File ' + file.name + ' uploaded');
- $wnd.console.log('Response: ' + response);
- }
- up.removeFile(file);
- var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
- if (folder == file.folder)
- app.@gr.grnet.pithos.web.client.Pithos::updateUploadFolder()();
- },
-
- UploadComplete: function(up, files) {
- if ($wnd.console && $wnd.console.log)
- $wnd.console.log('All files finished');
- },
-
- Error: function(up, error) {
- if ($wnd.console && $wnd.console.log)
- $wnd.console.log("Error occured:" + error);
- }
- }
- });
- var uploader = $wnd.$("#container").pluploadQueue();
- if (uploader.runtime != 'html5')
- $wnd.$("#container").hide();
- else {
- if ($wnd.console && $wnd.console.log) {
- $wnd.console.log(uploader);
- $wnd.console.log($wnd.plupload);
- }
- $wnd.$('.plupload_header').hide();
- $wnd.$('.plupload_filelist_header').hide();
- $wnd.$('#container_filelist').css('overflow-y', 'auto');
- $wnd.$('.plupload_filelist_footer').hide();
- $wnd.document.getElementById('container').addEventListener('dragenter', function(event) {
- $wnd.$('#container').css('border', '3px inset');
- }, false);
- $wnd.document.getElementById('container').addEventListener('dragleave', function(event) {
- $wnd.$('#container').css('border', '');
- }, false);
- }
- }-*/;
-
- private Folder getUploadFolder() {
- if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
- return getSelection();
- }
- return null;
- }
-
- private void updateUploadFolder() {
- if (folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
- Folder f = getSelection();
- if (getSelectedTree().equals(getFolderTreeView()))
- updateFolder(f, true, new Command() {
-
- @Override
- public void execute() {
- updateStatistics();
- }
- }, false);
- else
- updateOtherSharedFolder(f, true);
- }
- }
-
- public native void hideUploadArea() /*-{
- $wnd.$("#container").hide();
- }-*/;
-
- public native void showUploadArea() /*-{
- $wnd.$("#container").show();
- }-*/;