-
- /**
- * Adjust the height of the table by adding and removing rows as necessary.
- *
- * @param newHeight the new height to reach
- */
- void resizeTableHeight(final int newHeight) {
- GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null);
- // Fill the rest with empty slots.
- if (newHeight > table.getOffsetHeight())
- while (newHeight > table.getOffsetHeight()) {
- table.resizeRows(table.getRowCount() + 1);
- GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
- }
- else
- while (newHeight < table.getOffsetHeight()) {
- table.resizeRows(table.getRowCount() - 1);
- GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
- }
- }
-
- public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection) {
- updateFileCache(updateSelectedFolder, clearSelection, null);
- }
-
- public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection, final String newFilename) {
- if (!updateSelectedFolder && !GSS.get().getFolders().getTrashItem().equals(GSS.get().getFolders().getCurrent()))
- updateFileCache(clearSelection);
- else if (GSS.get().getFolders().getCurrent() != null) {
- final DnDTreeItem folderItem = (DnDTreeItem) GSS.get().getFolders().getCurrent();
- if( folderItem.getFolderResource()!= null){
- if(GSS.get().getFolders().isFileItem(folderItem) || GSS.get().getFolders().isMySharedItem(folderItem) || GSS.get().getFolders().isOthersSharedItem(folderItem) ){
- update(true);
- GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, folderItem.getFolderResource().getUri(),folderItem.getFolderResource()) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- if(GSS.get().getFolders().isFileItem(folderItem)){
- String[] filePaths = new String[folderItem.getFolderResource().getFilePaths().size()];
- int c=0;
- for(String fpath : folderItem.getFolderResource().getFilePaths()){
- filePaths[c] = fpath + "?" + Math.random();
- c++;
- }
- MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths, folderItem.getFolderResource().getFileCache()){
-
- @Override
- public void onComplete(){
- List<FileResource> result = getResult();
- //remove random from path
- for(FileResource r : result){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getFolderResource().setFiles(result);
- folderItem.getFolderResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(String p, Throwable throwable) {
- if(throwable instanceof RestException)
- GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
- }
-
- };
- DeferredCommand.addCommand(getFiles);
- }
- else
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch folder " + folderItem.getFolderResource().getName());
- }
- };
- DeferredCommand.addCommand(gf);
- }
- }
- else if (folderItem.getTrashResource() != null) {
- GetCommand<TrashResource> gt = new GetCommand<TrashResource>(TrashResource.class, folderItem.getTrashResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- updateFileCache(clearSelection);
- }
-
- @Override
- public void onError(Throwable t) {
- if (t instanceof RestException && (((RestException) t).getHttpStatusCode() == 204 || ((RestException) t).getHttpStatusCode() == 1223)) {
- folderItem.setUserObject(new TrashResource(folderItem.getTrashResource().getUri()));
- updateFileCache(clearSelection);
- } else {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch trash resource");
- }
- }
- };
- DeferredCommand.addCommand(gt);
- } else if (folderItem.getSharedResource() != null) {
- GetCommand<SharedResource> gt = new GetCommand<SharedResource>(SharedResource.class, folderItem.getSharedResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- updateFileCache(clearSelection, newFilename);
- String[] filePaths = new String[folderItem.getSharedResource().getFilePaths().size()];
- int c=0;
- for(String fpath : folderItem.getSharedResource().getFilePaths()){
- filePaths[c] = fpath + "?" + Math.random();
- c++;
- }
- MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths, folderItem.getSharedResource().getFileCache()){
-
- @Override
- public void onComplete(){
- List<FileResource> result = getResult();
- //remove random from path
- for(FileResource r : result){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getSharedResource().setFiles(result);
- folderItem.getSharedResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(String p, Throwable throwable) {
- if(throwable instanceof RestException)
- GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
- }
-
- };
- DeferredCommand.addCommand(getFiles);
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch My Shares resource");
- }
- };
- DeferredCommand.addCommand(gt);
- } else if (folderItem.getOtherUserResource() != null) {
- GetCommand<OtherUserResource> gt = new GetCommand<OtherUserResource>(OtherUserResource.class, folderItem.getOtherUserResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- updateFileCache(clearSelection, newFilename);
- String[] filePaths = new String[folderItem.getOtherUserResource().getFilePaths().size()];
- int c=0;
- for(String fpath : folderItem.getOtherUserResource().getFilePaths()){
- filePaths[c] = fpath + "?" + Math.random();
- c++;
- }
- MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths, folderItem.getOtherUserResource().getFileCache()){
-
- @Override
- public void onComplete(){
- List<FileResource> result = getResult();
- //remove random from path
- for(FileResource r : result){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getOtherUserResource().setFiles(result);
- folderItem.getOtherUserResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(String p, Throwable throwable) {
- if(throwable instanceof RestException)
- GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
- }
-
- };
- DeferredCommand.addCommand(getFiles);
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch My Shares resource");
- }
- };
- DeferredCommand.addCommand(gt);
- }
- } else
- updateFileCache(clearSelection);
- }
-
- private void updateFileCache(boolean clearSelection) {
- updateFileCache(clearSelection, null);
- }
-
- /**
- * Update the file cache with data from the server.
- *
- * @param userId the ID of the current user
- * @param newFilename the new name of the previously selected file,
- * if a rename operation has taken place
- */
- private void updateFileCache(boolean clearSelection, String newFilename) {
- if (clearSelection)