concept file in category griffon

appears as: files, file, files, file
Griffon in Action

This is an excerpt from Manning's book Griffon in Action.

Take careful note of the values you’re passing to the filePanel MVC group. For example, the file that has been opened is one of these values, as well as its name. Within the controller of the filePanel MVC group, you’ll use these values to initialize the model you’ll create there. That will expose these values to the rest of the MVC group in a neat and consistent manner. Remember the tabGroup and tabName variables in FilePanelView.groovy? Now you know where their values come from.

Because the implementation of selectFile() doesn’t display any special thread-handling code, it’s safe to assume that it will be executed in the same thread that called it. This method will call readFile() if the user has selected a file to read. If there were any special code to properly handle threading, this would be it. Sadly, that code isn’t there. The implementation will read the file’s contents in a buffer and update the textArea, text, and caretPosition properties.

Figure 7.1. A threading-aware FileViewer application displaying a file using the first technique (Test #1) for reading a file’s contents. The other file-loading techniques (Test #2, #3, and Test #4) depend on the threading options employed.
  • Technique 1, readFileNoThreading, will read the file and update the textArea in the current executing thread—in other words, you won’t use a threading facility. This will demonstrate what will happen if threading isn’t taken into account. Considering that each controller action is executed outside the UI thread by default, you must explicitly mark this one with @Threading.Policy.SKIP.
  • Technique 2, readFileWithThreading, will use doOutside{} to read the file’s contents in a different thread other than the EDT. Then it’s back into the EDT with doLater{} to update the textArea.
  • Listing 14.1. A default Gradle build file created by the Griffon command
    buildscript { repositories { mavenCentral() mavenRepo url: 'http://repository.codehaus.org/' mavenRepo url: 'http://repo.grails.org/grails/core/' mavenRepo url: 'http://repository.springsource.com/maven/bundles/ release' mavenRepo url: 'http://download.java.net/maven/2/' } dependencies { classpath('org.codehaus.griffon:griffon-gradle-plugin:1.1.0') classpath('org.codehaus.griffon:griffon-scripts:0.9.5') } } griffonVersion = '0.9.5' version = '0.1' apply plugin: 'griffon' repositories { mavenCentral() mavenRepo url: 'http://repository.codehaus.org/' } dependencies { compile "org.codehaus.griffon:griffon-rt:$griffonVersion" }