 
 (defn update-groups []
   (reset! groups (vec (seq (core getAvailableConfigGroups))))
-  (update-group-data)
+  (redraw-data)
+  (update-all-properties)
   (-> @widgets :groups-table update-table)
   @group-data)
 

                       (do (println "duplicate") false)
                       true))))
                               
(defn used-properties-table-model []
  (proxy [AbstractTableModel] []
    (getColumnName [col] (["Use?" "Property" "Current Value"] col))
    (getColumnCount [] 3)
    (getColumnClass [col] ([Boolean String String] col))
    (getRowCount [] (count @all-properties))
    (isCellEditable [_ col] (zero? col))
    (getValueAt [row column]
                (let [prop (@all-properties row)]
                  ([(not (nil? ((set (properties @group-data))
                          (first (@all-properties row)))))
                    (property-name (first prop))
                    (second prop)]
                    column)))
    (setValueAt [val row column]
                (let [[[dev prop] _] (@all-properties row)
                      group (get-selected-group)]
                  (println val row column)
                (if val
                  (add-property group dev prop)
                  (remove-property group dev prop))))))

(defn group-table-model []
  (proxy [AbstractTableModel] []
    (getColumnName [_] "Groups")
    (getColumnCount [] 1)
    (getRowCount [] (count @groups))
    (isCellEditable [_ _] true)
    (getValueAt [row column] (nth @groups row))
    (setValueAt [val row column]
      (let [old-val (nth @groups row)]
        (core renameConfigGroup old-val val)
        (update-groups)
        ))))

(defn preset-names-table-model []
  (proxy [AbstractTableModel] []
    (getColumnName [_] "Presets")
    (getColumnCount [] 1)
    (getRowCount [] (count (keys @group-data)))
    (isCellEditable [_ _] true)
    (getValueAt [row column] (nth (keys @group-data) row))
    (setValueAt [val row column]
      (let [old-val (.getValueAt this row column)]
        (core renameConfig (get-selected-group) old-val val)
        (update-group-data)))))

(defn presets-table-model []
  (proxy [AbstractTableModel] []
    (getColumnName [column] (property-name (nth (properties @group-data) column)))
    (getColumnCount [] (count (properties @group-data)))
    (getRowCount [] (count (keys @group-data)))
    (isCellEditable [_ _] false) ;; will be true
    (getValueAt [row column] (get (nth (vals @group-data) row)
                                  (nth (properties @group-data) column)))
    (setValueAt [val row column]
                ;(let [old-val (.getValueAt this row column)]
        ;TODO: finish
        )))

;; table row selection rules


(defn redraw-data []
  (update-group-data)
  (let [preset-names-table (@widgets :preset-names-table)
        presets-table (@widgets :presets-table)
        used-properties-table (@widgets :used-properties-table)]
    (update-table preset-names-table)
    (update-table used-properties-table)
    (cancel-cell-editing preset-names-table)
    (cancel-cell-editing presets-table)
    (update-table presets-table)
    (set-preferred-column-width presets-table)))

(defn new-group-name []
  (loop [index 1]
