-
- 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 void addGroup(String groupname) {
- Group newGroup = new Group(groupname);
- account.addGroup(newGroup);
- groupTreeView.updateGroupNode(null);
- }
-
- 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);
- 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);
- otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree");
- 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());
- }