 (defn- unlock! [{app-state :state}]
   (swap! app-state unlock))
 
-(defmulti on-action {:private true} (fn [action & _] action))
-
 (defn- run-task [{worker :worker :as app} task & args]
   (send-off worker 
             (fn [_ &]

                nil
                (finally (unlock! app))))))

(defn- open-config [app file]
  (println (config/read-config-file file)))

(defmethod on-action :open-config [_ app & args]
  (if-let [file (gui/choose-file (-> args first :widget) :title "Open Config")]
    (run-task app open-config file)
    (unlock! app)))  

(defmethod on-action :default [action app & args]
  (println (format "on-action{action: %s args: %s}" action args))
  (unlock! app))

(defmulti on-event {:private true} (fn [_ event-id & _] event-id))

(defn- dispatch-action [action app args]
  (when (lock! app)
    (apply on-action action app args)))

(defmethod on-event :action-performed [app _ & args]
  (dispatch-action (-> args first meta :action) app args))

(defmethod on-event :default [app event-id & args]
  (println (format "on-event{id: %s args: %s}" event-id args)))

    [fm.simrunner (config :as config)]
    [fm.simrunner.gui (core :as gui) 
                      (view :as view) 
                      (wiring :as wiring)])
  (:import 
    (javax.swing JOptionPane)))

(defn- lock [app-state]
  (update-in app-state [:ui :model :locked] inc))
