Skip to content

Instantly share code, notes, and snippets.

Created April 13, 2010 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/365234 to your computer and use it in GitHub Desktop.
Save anonymous/365234 to your computer and use it in GitHub Desktop.
(defn make-pricelist-view [data-ref]
(let [price-vector #(@data-ref :price-vector)
currency-cell-renderer (make-currency-cell-renderer (@data-ref :pricer))
model (proxy [AbstractTableModel] []
(getColumnCount [] 6)
(getColumnName [#^Integer col] (lgstr (*pricelist-columns* col)))
(getRowCount [] (count (price-vector)))
(getValueAt [#^Integer row #^Integer col]
(try
(let [price ((price-vector) row)]
(price (*pricelist-columns* col)))
(catch Exception e
(println (str "--->" e))))))
table (JTable. model)
scroll-pane (JScrollPane. table)]
(dosync
(alter data-ref assoc :table table)
(alter data-ref assoc :table-model model))
(doseq [column (map #(-> table .getColumnModel (.getColumn %)) '(3 4 5))]
(.setCellRenderer #^javax.swing.table.TableColumn column currency-cell-renderer))
(.setAutoCreateRowSorter table true)
(-> table .getRowSorter (.setSortKeys (doto (new java.util.ArrayList)
(.add (new javax.swing.RowSorter$SortKey 0 javax.swing.SortOrder/ASCENDING)))))
(doto (#^JPanel combobox (lgstr :pricelist))
(.add scroll-pane "grow"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment