   ([]
     (start nil))
   ([group]
-    (let [components (show)]
-      (update-groups)
-      (activate-groups-table components)
-      components)))
+    (reset! widgets (show))
+    (update-groups)
+    (activate-groups-table @widgets)))

     :presets-table presets-table
     :preset-names-table preset-names-table}))

(defn set-table-data [table body header]
  (.setDataVector
    (.getModel table)
    (into-2d-array String body)
    (into-1d-array String header)))

(defn update-presets-table [components group]
  (let [preset-names-table (components :preset-names-table)
        presets-table (components :presets-table)
        group-data (group-data group)
        body (table-data group-data)
        header (map list (keys group-data))
        prop-names (map property-name (properties group-data))]
    (edt (set-table-data presets-table body prop-names)
         (when-let [column-objects (.getColumns (.getColumnModel presets-table))]
           (doseq [column (enumeration-seq column-objects)]
             (.setPreferredWidth column 120)))
         (set-table-data preset-names-table header (list ""))
         (.. preset-names-table getColumnModel (getColumn 0) (setMaxWidth 150)))))

(defn activate-groups-table [components]
  (attach-selection-listener
    (components :groups-table)
    #(update-presets-table components
                           (try (.getValueAt (components :groups-table) % 0)
                                (catch Exception _ nil)))))


;; test/run


(load-mm)


(defn presets [group]
  (when-not (empty? group)
    (sort (seq (core getAvailableConfigs group)))))

(def group-data (atom nil))

(defn update-tables []
  (doall (map #(.. % getModel fireTableDataChanged) (vals @widgets))))

(defn update-group-data []
    (reset! group-data 
            (when-let [group (get-selected-group)]
              (into (sorted-map)
                    (map #(vector % (get-config group %))
                         (presets group))))))

(def groups (atom nil))

(defn update-groups []
  (reset! groups (seq (core getAvailableConfigGroups)))
  (update-group-data))

(defn properties [group-data]
  (sort (set (apply concat (map keys (vals group-data))))))
