 (defn redraw-data []
   (update-group-data)
   (let [preset-names-table (@widgets :preset-names-table)
-        presets-table (@widgets :presets-table)]
+        presets-table (@widgets :presets-table)
+        used-properties-table (@widgets :used-properties-table)]
     (update-table preset-names-table)
-         (cancel-cell-editing preset-names-table)
-         (cancel-cell-editing presets-table)
-         (update-table presets-table)
-         (set-preferred-column-width presets-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]

      (.setAutoResizeMode presets-table JTable/AUTO_RESIZE_OFF)
      (doto cp
        (.setLayout (SpringLayout.))
        (add-component groups-sp :n 5 :w 5 :n 150 :w 150)
        (add-component use-properties-sp :n 5 :w 155 :n 150 :w 500)
        (add-component presets-sp :n 155 :w 5 :s -5 :e -5))
        (.setBounds f 100 100 800 500)
        (.show f))
    (.setCellEditor groups-table (group-table-cell-editor))
    {:frame f
     :groups-table groups-table

                       (do (println "duplicate") false)
                       true))))
                               
(defn used-properties-table []
  (JTable.
    (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)]
                    (if val
                      (add-property group dev prop)
                      (remove-property group dev prop)))))))

(defn groups-table []
  (JTable.
    (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 []
  (JTable.
    (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 []
  (JTable.
    (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

