Begin of new Controller Generator.

This commit is contained in:
Daniel Ziltener 2017-07-28 18:57:11 +00:00
parent cd5d092ed3
commit 733dad8048
3 changed files with 28 additions and 14 deletions

View file

@ -4,6 +4,7 @@
:url "https://www.bitbucket.org/zilti/clojurefx" :url "https://www.bitbucket.org/zilti/clojurefx"
:dependencies [[org.clojure/clojure "1.8.0"] :dependencies [[org.clojure/clojure "1.8.0"]
[swiss-arrows "1.0.0"] [swiss-arrows "1.0.0"]
[org.controlsfx/controlsfx "8.40.13"]
[com.taoensso/timbre "4.7.4" :exclusions [com.taoensso/carmine]] [com.taoensso/timbre "4.7.4" :exclusions [com.taoensso/carmine]]
[clojure-jsr-223 "0.1.0"]] [clojure-jsr-223 "0.1.0"]]
;; :profiles {:uberjar {:aot :all}} ;; :profiles {:uberjar {:aot :all}}

View file

@ -35,26 +35,23 @@
~@code)))) ~@code))))
(defn branch? [obj] (defn branch? [obj]
(or (instance? javafx.scene.Parent obj) (or (and (instance? javafx.scene.Parent obj)
(not (instance? org.controlsfx.control.StatusBar obj)))
(instance? javafx.scene.control.MenuBar obj) (instance? javafx.scene.control.MenuBar obj)
(instance? javafx.scene.control.Menu obj))) (instance? javafx.scene.control.Menu obj)))
(defn make-node [node children] (defn make-node [node children]
nil) nil)
(defmulti down (fn [x] (class x))) (defn down [x]
(defmethod down javafx.scene.Parent [obj] (cond
(.getChildren obj)) (instance? javafx.scene.control.Label x) (.getGraphic x)
(defmethod down javafx.scene.control.MenuBar [obj] (instance? javafx.scene.control.ProgressIndicator x) (.getContextMenu x)
(.getMenus obj)) (instance? javafx.scene.control.ScrollPane x) (.getContent x)
(defmethod down javafx.scene.control.Menu [obj] (instance? javafx.scene.control.MenuBar x) (.getMenus x)
(.getItems obj)) (instance? javafx.scene.control.Menu x) (.getItems x)
(defmethod down javafx.scene.control.Label [obj] (instance? javafx.scene.Parent x) (.getChildren x)
[(.getGraphic obj)]) :else nil))
(defmethod down javafx.scene.control.ProgressIndicator [obj]
[(.getContextMenu obj)])
(defmethod down :default [obj]
nil)
(defn sgzipper [root] (defn sgzipper [root]
(zip/zipper branch? down make-node root)) (zip/zipper branch? down make-node root))

View file

@ -0,0 +1,16 @@
(ns clojurefx.controllergen
(:require [clojure.xml :as xml]
[clojure.zip :as zip]
[taoensso.timbre :as timbre]))
(timbre/refer-timbre)
(def xmlzip (zip/xml-zip (xml/parse "/Users/danielziltener/projects/lizenztool/resources/fxml/mainwindow.fxml")))
(defn get-fxid-elems
([ziptree] (get-fxid-elems ziptree []))
([ziptree elems]
(cond
(zip/end? ziptree) (do (debug "End reached, returning.") elems)
(contains? (:attrs (zip/node ziptree)) :fx:id) (do (debug "Found a match!\n" (zip/node ziptree))
(recur (zip/next ziptree) (conj elems (zip/node ziptree))))
:else (do (debug "No match, continuing:" (zip/node ziptree)) (recur (zip/next ziptree) elems)))))