private var _reports : SortedMap[Calendar, Report] = TreeMap()
   private var _dirty = false
 
-  _file match {
-    case Some(file) => load(file)
-    case None =>
-  }
+  _file.foreach { file => load(file) }
 
   def load(file: File) {
     var reports = _reports.empty
   def file  = _file
   def dirty = _dirty
 
+  def apply(n: Int) : Report =
+    // THINKME: Any better way than this?
+    _reports.values.toIndexedSeq(n)
+
   def save(file: File) {
     _file = Some(file); save
   }
   }
 
   def getValueAt(row: Int, column: Int) : Object = {
-    // THINKME: Any better way than this?
-    val report = _reports.values.toIndexedSeq(row)
     column match {
-      case 0 => report.dateString
-      case 1 => report.size : Integer
+      case 0 => this(row).dateString
+      case 1 => this(row).size : Integer
     }
   }
 }
 
 import scala.swing.event._
 
 class MainFrame(reportFile: Option[File]) extends Frame {
+  frame =>
+
   private val reportSet = new ReportSet(reportFile)
 
   title         = "Task Reporter " + Main.getVersion
   preferredSize = Preferences.mainFrameSize()
 
+  case class FileOpened(file: File)         extends Event
+  case class ReportSelected(report: Report) extends Event
+  case class ReportDeselected()             extends Event
+  case class TaskSelected(task: Task)       extends Event
+  case class TaskDeselected()               extends Event
+
   peer.addComponentListener(new ComponentAdapter() {
     override def componentResized(e: ComponentEvent) {
       Preferences.mainFrameSize() = size
       mnemonic = Key.F
 
       val miOpen = new MenuItem(new Action("Open...") {
-        accelerator = Some(KeyStroke.getKeyStroke("control O"))
+        accelerator = Some(KeyStroke getKeyStroke "control O")
         def apply {
           val chooser = new FileChooser(Preferences.lastChosenDir()) {
             fileSelectionMode = FileChooser.SelectionMode.FilesOnly
           }
           val r = chooser.showOpenDialog(null)
           if (r == FileChooser.Result.Approve) {
-            Preferences.lastChosenDir() = chooser.selectedFile.getParentFile
-            reportSet.load(chooser.selectedFile)
-            // FIXME: select the last report
+            val file = chooser.selectedFile
+            Preferences.lastChosenDir() = file.getParentFile
+            reportSet load file
+            frame publish FileOpened(file)
           }
         }
       })
 
       leftComponent = new ScrollPane(
         new Table() {
-          peer.setModel(new Report()) // Empty report
+          peer setFillsViewportHeight true
+          listenTo(frame)
+
+          override def model : Report = super.model.asInstanceOf[Report]
+
+          reactions += {
+            case ReportSelected(report) =>
+              model = report
+              if (rowCount > 0) {
+                selection.rows += rowCount - 1 // Select the last report
+              }
+            case ReportDeselected() =>
+              model = new Report() // Empty report
+          }
+
+          selection.reactions += {
+            case TableRowsSelected(_, _, false) =>
+              selection.rows.size match {
+                case 1 =>
+                  val task = model(selection.rows.head)
+                  frame publish TaskSelected(task)
+                case _ =>
+                  frame publish TaskDeselected()
+              }
+          }
         })
     }
 
 
       val reportsScroll = new ScrollPane(
         new Table() {
-          peer.setModel(reportSet)
-          if (rowCount > 0) {
-            selection.rows += rowCount - 1 // Select the last report
+          peer setFillsViewportHeight true
+          peer setModel reportSet
+          listenTo(frame)
+          reactions += {
+            case FileOpened(f) =>
+              if (rowCount > 0) {
+                selection.rows += rowCount - 1 // Select the last report
+              }
           }
           selection.reactions += {
             case TableRowsSelected(_, _, false) =>
-              // FIXME
+              selection.rows.size match {
+                case 1 =>
+                  val report = reportSet(selection.rows.head)
+                  frame publish ReportSelected(report)
+                case _ =>
+                  frame publish ReportDeselected()
+              }
           }
         })
       layout(reportsScroll) = BorderPanel.Position.Center
     }
   }
 
+  reportSet.file match {
+    case Some(file) => frame publish FileOpened(file)
+    case None       => frame publish ReportDeselected()
+  }
+
   centerOnScreen
   visible = true