Skip to content

Commit

Permalink
Fix for issue #90. 'hidden' table columns are no longer lost when `up…
Browse files Browse the repository at this point in the history
…date-at!` is called with partial data.
  • Loading branch information
daveray committed May 18, 2012
1 parent 3651568 commit 2b267b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/seesaw/table.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
(swap! full-values remove-at row)
(let [^javax.swing.table.DefaultTableModel this this]
(proxy-super removeRow row)))
; TODO this stuff is an awful hack and now that I'm wiser, I should fix it.
(getValueAt [row col]
(if (= -1 row col)
column-key-map
Expand Down Expand Up @@ -217,7 +218,10 @@
; TODO this precludes setting a cell to nil. Do we care?
(when-let [v (aget row-values i)]
(.setValueAt target (aget row-values i) row i)))
(.setValueAt target (last row-values) row -1))
; merge with current full-map value so that extra fields aren't lost.
(.setValueAt target
(merge (.getValueAt target row -1)
(last row-values)) row -1))
target)
([target row value & more]
(if more
Expand Down
11 changes: 11 additions & 0 deletions test/seesaw/test/table.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@
r (update-at! t 0 {:a "A0"})]
(expect (= t r))
(expect (= {:a "A0" :b "b0"} (value-at t 0)))))
(it "preserves the values of unspecified 'hidden' columns"
(let [t (table-model :columns [:name :phone :email]
:rows [{:name "S"
:phone 12345
:email "s@email.com"
:twitter "@s"}])]
; :twitter should survive the update even though it's not a column
; in the table model
(update-at! t 0 {:email "s@snailmail.com"})
(expect (= {:name "S" :phone 12345 :email "s@snailmail.com" :twitter "@s"}
(value-at t 0)))))
(it "updates multiple rows with the same format as :rows option of (table-model)"
(let [t (table-model :columns [:a :b] :rows [["a0" "b0"] ["a1" "b1"]])
r (update-at! t 1 ["A1" "B1"] 0 {:a "A0" :b "B0"})]
Expand Down

0 comments on commit 2b267b5

Please sign in to comment.