[Bese-devel] container.lisp refactor

Evrim ULU evrim at core.gen.tr
Sat Mar 18 16:04:58 UTC 2006


Dear Atilla,

This is what i've built. There is class named navigable-content-mixin we
use but you may replace it with any component since it's nothing
special. I didn't like the idea of static container so i've built a
dynamic observer patterned one. Since my components are in memory and
number of component are low, i didn't built it on a hash-table, it's
already fast enough.

ps: portal-widget is nothing special, you may also discard it.

Kind regards,
Evrim.

(defcomponent content-container-widget (portal-widget)
  ((components :accessor container.components
           :initarg :components
           :documentation "Component list to hold."
           :initform nil)
   (current-component :accessor container.current-component
              :initarg :current-component
              :documentation "Current Component"
              :initform nil)
   (label-func :accessor container.label-func
           :initarg :label-func
           :documentation "Label gathering function"
           :initform #'(lambda (item) (title item))))
  (:default-initargs :css-class "content" :css-id "content")
  (:documentation "Primitive content widget"))

(defmethod render ((c content-container-widget))
  (when (container.current-component c)
    (render (container.current-component c))))

(defmethod shared-initialize :after ((c content-container-widget) slot-names
                                     &rest initargs
                                     &key contents)
  (declare (ignorable contents initargs))
  (when (null (container.current-component c))
    (switch-to-first-component c)))

(defmethod valid-component ((c content-container-widget) component)
  (if (member component (container.components c))
      t))

(defmethod find-component ((c content-container-widget) label)
    (dolist (item (container.components c))
      (if (equal (funcall (container.label-func c) item) label)
      (return item))))

(defmethod append-component ((c content-container-widget) (nav
navigable-content-mixin))
  (setf (container.components c) (nreverse (cons nav (nreverse
(container.components c))))))

(defaction switch-component ((c content-container-widget)
component-or-label)
  (if (stringp component-or-label)
    (let ((comp (find-component c component-or-label)))
      (if (not (null comp))
        (setf (container.current-component c) comp)))
    (when (valid-component c component-or-label)
      (setf (container.current-component c) component-or-label))))

(defmethod switch-to-first-component ((c content-container-widget))
  (when (slot-value c 'components)
    (setf (slot-value c 'current-component) (first (slot-value c
'components)))))




More information about the bese-devel mailing list