                      "Please add a location to scan for files")]
     (add-location (.getAbsolutePath loc))))
 
+(defn get-display-index [table index]
+  (let [column-model (.getColumnModel table)]
+    (first
+      (for [i (range (.getColumnCount column-model))
+        :when (= index (.getModelIndex (.getColumn column-model i)))]
+          i))))
+
+(defn update-column [tags-model col]
+  (when (:table @browser)
+    (let [on (.getValueAt tags-model col 0)
+          tag (.getValueAt tags-model col 1)
+          table (:table @browser)
+          column-model (.getColumnModel table)
+          model-index (get-model-column-index table tag)
+          display-index (get-display-index table model-index)]
+      (when (<= 0 model-index)
+        (when (and (not on) display-index)
+          (.removeColumn column-model (.getColumn column-model display-index)))
+        (when (and on (not display-index))
+          (println model-index)
+          (.addColumn column-model
+            (doto (TableColumn. model-index)
+              (.setHeaderValue tag))))))))
+
+(defn update-all-columns [tags-model]
+  (dorun (map #(update-column tags-model %) (range (.getRowCount tags-model)))))
+
 (defn create-column-table []
-  (let [table (proxy [JTable] [0 2]
+  (let [table (proxy [JTable] []
                 (isCellEditable [_ i] (get [true false] i)))
         model (proxy [DefaultTableModel] [0 2]
                 (getColumnClass [i]

        (when (= 2 (.getClickCount e)) ; double click
          (open-selected-files table))))))

(defn open-selected-files [table]
  (let [path-column (get-column-index table "Path")]
    (doseq [i (.getSelectedRows table)]
      (.openAcquisitionData gui
        (.getValueAt table i path-column)))))

(defn remove-locations [] 
  (let [location-table (get-in @settings-window [:locations :table])
        selected-rows (.getSelectedRows location-table)
        location-model (.getModel location-table)
        browser-table (:table @browser)
        browser-model (.getModel browser-table)
        location-column (get-column-index browser-table "Location")]
    (println browser-model "," location-model "," location-column)
    (doseq [location-row (reverse selected-rows)]
      (when-let [loc (.getValueAt location-model location-row 0)]

        (changedUpdate [_ _] (f))
        (removeUpdate [_ _] (f))))))

(defn get-model-column-index [table text]
  (let [table-model (.getModel table)]
    (-> (vec
      (for [i (range (.getColumnCount table-model))]
        (.getColumnName table-model i)))
      (.indexOf text))))

(defn open-selected-files [table]
  (let [path-column (get-model-column-index table "Path")]
    (doseq [i (.getSelectedRows table)]
      (.openAcquisitionData gui
        (.getValueAt table i path-column)))))

(defn listen-to-open [table]
  (.addMouseListener table
