Today I thought I would walk you through 2 features I pushed into the repository last night. The first is the ability to download an entire directory by right clicking on it. The other was a naming issue with the zip file download so we are going to change how that works.
We will start with the ability to download an entire directory. Right now if you clicked on a directory and selected every single file in the directory you are essentially downloading that directory. The selected files are passed to a download method and if its more than one we pass an array of file paths to our download zip method. What we want to do is add a right clicking menu to our tree to download directory menu item. To do that we are going to update our Tree Item Renderer (com.rocketfm.customTreeItemRenderer). The only addition is the new download menu item and when its clicked we are going to dispatch a custom event named download directory that will pass the data for that tree item with it. Now that we are dispatching our new custom event let's take a look at that event. This event will pass along all of the information about the tree item that was clicked. This way back in our main application we will know what directory to serve up. It's also important to note that the second parameter of the call to the super constructor is set to true. This means that this event will bubble up. Go ahead and try setting that to false to see why this is important.
Back in our main application we need start listening for that event. When the event is caught it will call our downloadDirectory method and pass our data to it. In our method we are not going to re write any logic for downloading files. If you remember our download method works off of the selected files in the data grid. An easy way to make use of existing code is to just select all of the files in the directory and call our downloadFiles method.
The other feature I added had to do with a client request. When you select multiple files and click download we wrap all of the files up in a zip file and present the file to you for download. The name of that file has been download but the client suggested that we make the name of the download the directory name + .zip. I thought this was a great idea so I went ahead and made the small change. We know that when a user either clicks on or right clicks on a directory it is selected, so to get the name of the directory we can use the selectedItem property of the tree.
