Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update table.clj #150

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/seesaw/table.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
(vec (concat head tail))))

(defn- ^javax.swing.table.DefaultTableModel proxy-table-model
[column-names column-key-map]
[column-names column-key-map column-classes]
(let [full-values (atom [])]
(proxy [javax.swing.table.DefaultTableModel] [(object-array column-names) 0]
(isCellEditable [row col] false)
Expand Down Expand Up @@ -76,7 +76,11 @@
(if (= -1 col)
(swap! full-values assoc row value)
(let [^javax.swing.table.DefaultTableModel this this]
(proxy-super setValueAt value row col)))))))
(proxy-super setValueAt value row col))))
(getColumnClass [col]
(if-let [cls (column-classes col)]
cls
(proxy-super getColumnClass col))))))

(defn- get-full-value [^javax.swing.table.TableModel model row]
(try
Expand Down Expand Up @@ -113,7 +117,7 @@
Example:

(table-model :columns [:name
{:key :age :text \"Age\"}]
{:key :age :text \"Age\" :class Integer}]
:rows [ [\"Jim\" 65]
{:age 75 :name \"Doris\"}])

Expand All @@ -128,7 +132,8 @@
(let [norm-cols (map normalize-column columns)
col-names (map :text norm-cols)
col-key-map (reduce (fn [m [k v]] (assoc m k v)) {} (map-indexed #(vector (:key %2) %1) norm-cols))
model (proxy-table-model col-names col-key-map)]
col-classes (vec (map :class norm-cols))
model (proxy-table-model col-names col-key-map col-classes)]
(doseq [row rows]
(.addRow model ^objects (unpack-row col-key-map row)))
model))
Expand Down