public ImageResource getIconForFile(FileSystemItem file) { if (file.isDirectory()) { if (file.isPublicFolder()) return ICONS.iconPublicFolder(); else return ICONS.iconFolder(); } return getIconForFilename(file.getName()); }
@Handler void onRenameFile() { // get currently selected files ArrayList<FileSystemItem> selectedFiles = view_.getSelectedFiles(); // validation: some selection exists if (selectedFiles.size() == 0) return; // validation: no more than one file selected if (selectedFiles.size() > 1) { globalDisplay_.showErrorMessage("Invalid Selection", "Please select only one file to rename"); return; } // prompt for new file name then execute the rename final FileSystemItem file = selectedFiles.get(0); globalDisplay_.promptForText( "Rename File", "Please enter the new file name:", file.getName(), 0, file.getStem().length(), null, new ProgressOperationWithInput<String>() { public void execute(String input, final ProgressIndicator progress) { progress.onProgress("Renaming file..."); String path = file.getParentPath().completePath(input); FileSystemItem target; if (file.isDirectory()) target = FileSystemItem.createDir(path); else target = FileSystemItem.createFile(path); // clear selection view_.selectNone(); // premptively rename in the UI then fallback to refreshing // the view if there is an error view_.renameFile(file, target); // execute on the server server_.renameFile( file, target, new VoidServerRequestCallback(progress) { @Override protected void onFailure() { onRefreshFiles(); } }); } }); }
public FileType getTypeForFile(FileSystemItem file, String defaultType) { if (file != null) { String filename = file.getName().toLowerCase(); FileType result = fileTypesByFilename_.get(filename); if (result != null) return result; String extension = FileSystemItem.getExtensionFromPath(filename); result = fileTypesByFileExtension_.get(extension); if (result != null) return result; if (defaultType != null) { String mimeType = file.mimeType(defaultType); if (mimeType.startsWith("text/")) return TEXT; } } return null; }
public FileType getTypeForFile(FileSystemItem file, boolean canUseDefault) { if (file != null) { String filename = file.getName().toLowerCase(); FileType result = fileTypesByFilename_.get(filename); if (result != null) return result; String extension = FileSystemItem.getExtensionFromPath(filename); result = fileTypesByFileExtension_.get(extension); if (result != null) return result; // last ditch -- see if this either a known text file type // or (for server mode) NOT a known binary type. the result of // this is that unknown files types are treated as text and // opened in the editor (we don't do this on desktop because // in that case users have the recourse of using a local editor) String defaultType = Desktop.isDesktop() ? "application/octet-stream" : "text/plain"; String mimeType = file.mimeType(defaultType); if (mimeType.startsWith("text/")) return TEXT; } if (canUseDefault) return defaultType_; else return null; }