Reputation: 2777
I'm doing some JavaFX stuff, following the TableView example. In the original java the author @Override
s several of the TableCell
class methods which he's deriving directly from, but also @Override
s the updateItem
method which is 2 levels up in the class hierarchy and belongs to the Cell
class.
Is there any way to do this easily in Clojure? Currently I'm just doing proxy
but I'm okay using :gen-class
if necessary. I thought I read somewhere you can only override the immediate base class in Clojure.
(defn make-editing-cell []
(let [textField (atom nil)]
(proxy [TableCell] []
(startEdit []
(proxy-super startEdit)
(println "start editing"))
(cancelEdit []
(proxy-super cancelEdit)
(println "cancel editing"))
(updateItem [item empty]
;(proxy-super updateItem ) ;; This causes runtime error No Matching Field Found
(if empty
(do (println "empty!")
(doto this
(.setText nil)
(.setGraphic nil)))
(do (println "not empty!")
(if (.isEditing this)
(do (println "editing")
(if (not @textField)
(.setText @textField (.toString (.getItem this))))
(doto this
(.setGraphic @textField)
(.setContentDisplay ContentDisplay/GRAPHIC_ONLY)))
(do (println "not editing")
(println this)
(println (.getItem this))
(comment
(doto this
(.setText (.toString (.getItem this)))
(.setContentDisplay ContentDisplay/GRAPHIC_ONLY)))))))
(println "updating item" item empty)))))
Upvotes: 2
Views: 426
Reputation: 2777
I needed to pass the arguments item
and empty
to the proxy-super
call... so (proxy-super updateItem item empty)
Upvotes: 1