1 ;;; jde-widgets.el -- Custom-style widgets used by the JDE
2 ;; $Revision: 1.26 $ $Date: 2004/06/03 02:21:13 $
4 ;; Author: Paul Kinnucan <paulk@mathworks.com>
5 ;; Maintainer: Paul Kinnucan
6 ;; Keywords: java, tools
8 ;; Copyright (C) 1997-2004 Paul Kinnucan.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This is one of a set of packages that make up the
28 ;; Java Development Environment (JDE) for Emacs. See the
29 ;; JDE User's Guide for more information.
31 ;; The latest version of the JDE is available at
32 ;; <URL:http://sunsite.auc.dk/jde/>
33 ;; <URL:http://www.geocities.com/SiliconValley/Lakes/1506/>
35 ;; Please send any comments, bugs, or upgrade requests to
36 ;; Paul Kinnucan at paulk@mathworks.com.
44 (jde-require 'tree-widget)
47 ;; ----------------------------------------------------------------------
48 ;; The Tree Widget Code:
51 ;;; The `tree' Widget.
53 (define-widget 'jde-widget-tree-open-button 'item
54 "Open node in `jde-tree' widget."
58 :action 'jde-widget-tree-open-button-callback
59 :help-echo "Show subtree."
62 (defun jde-widget-tree-open-button-callback (widget &optional event)
63 ;; Set parent state to open.
64 (widget-value-set (widget-get widget :parent) t))
66 (define-widget 'jde-widget-tree-close-button 'item
67 "Close node in `tree' widget."
71 :action 'jde-widget-tree-close-button-callback
72 :help-echo "Hide subtree."
75 (defun jde-widget-tree-close-button-callback (widget &optional event)
76 ;; Set parent state to closed.
77 (let* ((parent (widget-get widget :parent))
78 (entries (widget-get parent :args))
79 (children (widget-get parent :children)))
80 (while (and entries children)
81 (widget-put (car entries) :value (widget-value (car children)))
82 (setq entries (cdr entries)
83 children (cdr children)))
84 (widget-value-set parent nil)))
86 (define-widget 'jde-widget-tree 'default
87 "A tree structure widget."
88 :convert-widget 'widget-types-convert-widget
92 :prefix-empty " |--- "
93 :value-get 'widget-value-value-get
94 :value-create 'jde-widget-tree-value-create-callback
95 :value-delete 'widget-children-value-delete)
97 (defun jde-widget-tree-value-create-callback (widget)
99 (let ((open (widget-value widget))
100 (tag (widget-get widget :tag))
101 (entries (widget-get widget :args))
103 (cond ((null entries)
105 (insert (widget-get widget :prefix-empty) tag "\n"))
109 (widget-create-child-and-convert widget 'jde-widget-tree-close-button)
111 (insert "-\\ " tag "\n")
112 (let ((prefix (concat (widget-get widget :prefix)
113 (widget-get widget :prefix-extra)))
116 (setq entry (car entries)
117 entries (cdr entries))
120 (widget-create-child-and-convert widget entry
123 ;; Last entry uses a different prefix.
124 (widget-create-child-and-convert
127 :prefix-empty " `--- "))
131 (push (widget-create-child-and-convert widget 'jde-widget-tree-open-button)
133 (insert "-- " tag "\n")))
134 (widget-put widget :children children)
135 (widget-put widget :buttons buttons)))
137 ;;----------------------------------------------------------------------
138 ;; Eval this to create a small tree.
142 (switch-to-buffer "*Tree Example*")
143 (kill-all-local-variables)
144 ;; (make-local-variable 'widget-example-repeat)
145 (let ((inhibit-read-only t))
147 (let ((all (overlay-lists)))
148 (mapcar 'delete-overlay (car all)) (mapcar 'delete-overlay (cdr all)))
150 (widget-insert "Test tree widget. \n\n")
152 ; (setq tree (widget-create 'tree
154 ; '(tree :tag "First")
155 ; '(tree :tag "Second"
157 ; (tree :tag "Nested"))
158 ; '(tree :tag "Third")))
160 (setq tree (widget-create 'jde-widget-tree
161 :tag "<test.Foo:139>"
162 '(jde-widget-tree :tag "n int 0")
163 ;; '(jde-widget-tree :tag '(jde-widget-tree :tag "n int 0"))
164 '(jde-widget-tree :tag "a double 5.5")
165 '(jde-widget-tree :tag "s S <test.S:145>"
166 (jde-widget-tree :tag "b boolean true"))))
170 ; (list "ThreadGroup" 189 "system"
172 ; (list "Thread" 190 "Signal dispatcher" "runnable" "suspended by debugger")
173 ; (list "Thread" 191 "Reference Handler" "waiting" "suspended by debugger")
174 ; (list "Thread" 192 "Finalizer" "waiting" "suspended by debugger")))
175 ; (list "ThreadGroup" 193 "main"
177 ; (list "Thread" 1 "main" "runnable" "suspended at breakpoint"))
179 ; (tree (jde-dbs-map-threads-to-tree threads)))
182 ; (apply 'widget-create tree))
184 (use-local-map widget-keymap)
189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
191 ;; Dynamic tree widget ;;
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 (define-widget 'jde-widget-dtree 'default
196 "A widget whose nodes are generated on demand.
197 The first time the user expands the tree, the tree invokes a function that
198 generates the nodes. The tree then caches the nodes.
199 Thereafter, the node uses the cached nodes when the
200 user closes and then reopens the tree. Use the syntax
201 (widget-create 'jde-widget-dtree :tag NAME :node-fcn NODE-FUNCTION)
202 to create the widget where NAME is the tree name and NODE-FUNCTION
203 is a function that takes one argument, the tree itself, and
204 returns a list of widgets that are the nodes of the expanded
208 :value-get 'widget-value-value-get
209 :value-create 'jde-widget-dtree-create-callback
210 :value-delete 'widget-children-value-delete
213 (defun jde-widget-dtree-create-callback (widget)
214 (let ((open (widget-value widget))
215 (tag (widget-get widget :tag))
219 (push (widget-create-child-and-convert widget 'jde-widget-tree-close-button)
221 (insert "-\\ " tag "\n")
222 (let ((prefix (concat (widget-get widget :prefix)
223 (widget-get widget :prefix-extra)))
224 (nodes (widget-get widget :nodes))
227 (when (and (widget-get widget :has-nodes)
230 (funcall (widget-get widget :node-fcn) widget))
232 (widget-put widget :nodes nodes)
233 (widget-put widget :has-nodes nil)))
236 (setq node (car nodes)
241 (widget-create-child-and-convert widget node
244 (widget-create-child-and-convert
247 :prefix-empty " `--- "))
251 (push (widget-create-child-and-convert widget 'jde-widget-tree-open-button)
253 (insert "-- " tag "\n")))
254 (widget-put widget :children children)
255 (widget-put widget :buttons buttons)))
258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260 ;; Java object widget ;;
262 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 (defun jde-test-get-fields (process object-id)
266 (cons (list "sum" "double") (list "double" 0.0))
267 (cons (list "r" "int") (list "int" 1))
268 (cons (list "z" "java.lang.String") (list "java.lang.String" 229 nil))
269 (cons (list "B" "double[]") (list "double[]" 228 nil))
270 (cons (list "A" "double[][]") (list "double[][]" 227 nil))
271 (cons (list "args" "java.lang.String[]") (list "java.lang.String[]" 226 nil))))
273 (defun jde-widget-java-var-to-tree (process var)
274 (let* ((var-name (oref var name))
275 (var-type (oref var jtype))
276 (var-value (oref var value))
277 (var-tag (format "%s %s" var-type var-name)))
279 ((typep var-value 'jde-dbs-java-udci)
280 (setq var-tag (format "%s [id: %d]" var-tag (oref var-value :id)))
281 (if (string= (oref var-value :jtype) "java.lang.String")
282 (let* ((cmd (jde-dbs-get-string
285 :object-id (oref var-value id)))
286 (str-val (jde-dbs-cmd-exec cmd)))
290 :open (jde-dbo-locals-open-p var-tag)
292 (list 'tree-widget :tag str-val)))
293 (list 'jde-widget-java-obj
296 :open (jde-dbo-locals-open-p var-tag)
298 :object-id (oref var-value :id))))
299 ((typep var-value 'jde-dbs-java-array)
300 (setq var-tag (format "%s [id: %d]" var-tag (oref var-value :id)))
301 (list 'jde-widget-java-array
304 :open (jde-dbo-locals-open-p var-tag)
305 :process process :object var-value))
306 ((typep var-value 'jde-dbs-java-primitive)
310 :open (jde-dbo-locals-open-p var-tag)
313 :tag (format "%s" (oref var-value value)))))
314 ((typep var-value 'jde-dbs-java-null)
318 :open (jde-dbo-locals-open-p var-tag)
320 (list 'tree-widget :tag "null")))
322 (error "Unidentified type of local variable: %s" var-tag)))))
324 (defun jde-widget-java-obj-get-fields (obj-widget)
325 (if (widget-get obj-widget :args)
326 (widget-get obj-widget :args)
327 (let* ((process (widget-get obj-widget :process))
328 (object-id (widget-get obj-widget :object-id))
331 (format "get_object %d" object-id)
333 :object-id object-id))
335 (jde-dbs-cmd-exec cmd))
336 (fields (oref object fields))
340 (setq field (car fields) fields (cdr fields))
341 (setq field (cdr field))
343 (jde-widget-java-var-to-tree process field)
347 (define-widget 'jde-widget-java-obj 'tree-widget
348 "A widget that represents a Java object.
349 This widget is essentially a tree node whose entries are the fields
350 of the corresponding object. The first time the user expands the node,
351 the node retrieves the fields of the object from the debugger and
352 caches them. Thereafter, the node uses the cached values when the
353 user closes and then reopens the node. Use the syntax
354 (widget-create 'jde-widget-java-obj
355 :tag NAME :process PROCESS :object-id OBJ-ID) to create the widget where
356 NAME is the object's name, PROCESS is the process in which
357 the object exists, and ID is the debugger id for the object."
358 :dynargs 'jde-widget-java-obj-get-fields
362 (defun jde-widget-java-array-element-to-tree (process element index)
364 ((typep element 'jde-dbs-java-udci)
365 (if (string= (oref element :jtype) "java.lang.String")
366 (let* ((cmd (jde-dbs-get-string
369 :object-id (oref element id)))
370 (str-val (jde-dbs-cmd-exec cmd)))
372 :tag (format "[%d] %s" index str-val)
373 :node-name (format "[%d] %s" index str-val)
374 :open (jde-dbo-locals-open-p (format "[%d] %s" index str-val))
376 (list 'jde-widget-java-obj
377 :tag (format "[%d] %s" index (oref element jtype))
378 :node-name (format "[%d] %s" index (oref element jtype))
379 :open (jde-dbo-locals-open-p (format "[%d] %s" index (oref element jtype)))
381 :object-id (oref element id))))
382 ((typep element 'jde-dbs-java-array)
383 (list 'jde-widget-java-array
384 :tag (format "[%d] %s" index (oref element jtype))
385 :node-name (format "[%d] %s" index (oref element jtype))
386 :open (jde-dbo-locals-open-p (format "[%d] %s" index (oref element jtype)))
389 ((typep element 'jde-dbs-java-primitive)
390 (list 'tree-widget :tag (format "[%d] %s" index (oref element value))))
391 ((typep element 'jde-dbs-java-null)
392 (list 'tree-widget :tag (format "[%d] null" index)))
394 (error "Unidentified type of object: <%s|%s>" (oref element jtype)
395 (oref element id)))))
397 (defun jde-widget-java-array-get-elements (array-widget)
398 (if (widget-get array-widget :args)
399 (widget-get array-widget :args)
400 (let* ((process (widget-get array-widget :process))
401 (array (widget-get array-widget :object))
406 (format "get_array_length %d" (oref array id))
409 (jde-dbs-cmd-exec cmd)
412 (if (slot-boundp array 'length)
416 (when (> array-length 0)
419 (format "get_array_elements %d" (oref array id))
423 :length array-length))
424 (jde-dbs-cmd-exec cmd)
425 (let ((elements (oref array elements))
430 (setq element (car elements) elements (cdr elements))
433 (list (jde-widget-java-array-element-to-tree process element index))))
434 (setq index (1+ index)))
437 (define-widget 'jde-widget-java-array 'tree-widget
438 "A widget that represents a Java array. Clicking on the widget's
439 expand button causes the widget to display the values of the array."
440 :dynargs 'jde-widget-java-array-get-elements
445 (switch-to-buffer "*Java Object Example*")
446 (kill-all-local-variables)
447 ;; (make-local-variable 'widget-example-repeat)
448 (let ((inhibit-read-only t))
450 (let ((all (overlay-lists)))
451 (mapcar 'delete-overlay (car all)) (mapcar 'delete-overlay (cdr all)))
453 (widget-insert "Test object tree. \n\n")
455 (widget-create 'jde-widget-java-obj :tag "jmath.System s" :process "process" :object-id 1)
456 (widget-create 'jde-widget-java-obj :tag "java.awt.Frame frame1" :process "process" :object-id 1)
458 (use-local-map widget-keymap)
463 ;; ----------------------------------------------------------------------
464 ;; Option Tree Widget
466 (defun jde-widget-option-tree-open-button-callback (widget &optional event)
467 ;; Set parent state to open.
468 (widget-value-set (widget-get widget :parent) t)
471 (define-widget 'jde-widget-option-tree-open-button 'item
472 "Button to open an option tree."
476 :action 'jde-widget-option-tree-open-button-callback
477 :help-echo "Show option tree."
480 (define-widget 'jde-widget-option-tree-close-button 'item
481 "Close node in `jde-widget-option-tree' widget."
485 :action 'jde-widget-option-tree-close-button-callback
486 :help-echo "Hide panel."
489 (defun jde-widget-option-tree-close-button-callback (widget &optional event)
490 ;; Set parent state to closed.
491 (let* ((parent (widget-get widget :parent))
492 (entries (widget-get parent :args))
493 (group (car (widget-get parent :children)))
494 (children (widget-get group :children)))
495 ;; Get values entered by user from children and
496 ;; insert them in the corresponding widget definitions
497 ;; so that they appear the next time the user expands
499 (while (and entries children)
500 (widget-put (car entries) :value (widget-value (car children)))
501 (setq entries (cdr entries)
502 children (cdr children)))
503 (widget-value-set parent nil)))
505 (defun jde-widget-option-tree-value-create-callback (widget)
506 (let ((open-widget-p (widget-value widget))
507 (tag (widget-get widget :tag))
508 (entries (widget-get widget :args))
509 entry children buttons)
511 ;; Wrap widgets in this tree in a group widget
512 ;; to ensure proper formatting.
514 (list 'group :args entries))
517 (widget-create-child-and-convert
519 'jde-widget-option-tree-close-button)
521 (insert "-\\ " tag "\n")
522 (push (widget-create-child-and-convert widget group-type) children)))
524 (push (widget-create 'jde-widget-option-tree-open-button
527 (insert "-- " tag "\n")))
528 (widget-put widget :children children)
529 (widget-put widget :buttons buttons)))
532 (define-widget 'jde-widget-option-tree 'default
533 "A panel containing widgets."
534 :convert-widget 'widget-types-convert-widget
536 :value-get 'widget-value-value-get
537 :value-create 'jde-widget-option-tree-value-create-callback
538 :value-delete 'widget-children-value-delete)
541 (defun test-option-tree ()
543 (switch-to-buffer "*Panel Example*")
544 (kill-all-local-variables)
545 (let ((inhibit-read-only t))
547 (let ((all (overlay-lists)))
548 (mapcar 'delete-overlay (car all))
549 (mapcar 'delete-overlay (cdr all)))
551 (widget-insert "Test panel widget. \n\n")
553 (let ((panel (widget-create
554 'jde-widget-option-tree
555 :tag "Compile Options"
556 '(cons :tag "Debugger Options"
557 (radio-button-choice :format "%t \n%v"
563 (cons :tag "Other Debugger Info"
565 (radio-button-choice :format "%t \n%v"
569 '(repeat (string :tag "Path"))
570 '(editable-field :tag "classpath"
571 :format " %t: %v\n %h \n\n"
573 :doc "Name of project.")
574 '(editable-field :tag "compiler"
575 :format " %t: %v\n %h \n\n"
577 :doc "Name of project.")
578 '(jde-widget-option-tree :tag "Debugger Options"
579 (repeat (string :tag "Path"))))))
580 (use-local-map widget-keymap)
585 (provide 'jde-widgets)
587 ;; $Log: jde-widgets.el,v $
588 ;; Revision 1.26 2004/06/03 02:21:13 paulk
589 ;; jde-require tree-widget.
591 ;; Revision 1.25 2003/01/12 23:34:51 jslopez
592 ;; Small, patch to reduce the amount of cases that cause infinite recursion.
594 ;; Revision 1.24 2001/12/04 05:27:26 paulk
595 ;; Moved dialog classes to the efc (Emacs Foundation Classes) package.
597 ;; Revision 1.23 2001/11/29 11:41:18 paulk
598 ;; Option dialog now positions cursor over OK button.
600 ;; Revision 1.22 2001/11/28 16:50:28 jslopez
601 ;; Fixes bug, that would not keep the state
602 ;; of nodes created by jde-widget-java-array-element-to-tree.
604 ;; Revision 1.21 2001/11/28 08:38:02 paulk
605 ;; Added note about fix for Emacs 21.1 bug.
607 ;; Revision 1.20 2001/11/27 21:04:05 jslopez
608 ;; Modifies jde-widget-java-var-to-tree to keep nodes the states of nodes.(open/close)
610 ;; Revision 1.19 2001/11/24 15:23:11 paulk
611 ;; The jde-option-dialog versions of jde-dialog-ok and jde-dialog-cancel
612 ;; now delete the other window ony if the current version of Emacs is not
613 ;; XEmacs and is less than major version 21.
615 ;; Revision 1.18 2001/11/24 07:31:56 paulk
616 ;; The jde-option-dialog version of jde-dialog-ok now deletes the other windows,
617 ;; if the current version of Emacs is not 21.1.
619 ;; Revision 1.17 2001/11/24 07:23:54 paulk
620 ;; Changed the jde-dialog-ok method of jde-option-dialog to not delete
621 ;; other windows. This is necessary to avoid a bug in the Emacs 21.1.1
622 ;; version of exit-recursive-edit. This line should be restored when
625 ;; Revision 1.16 2001/10/26 06:36:07 paulk
626 ;; Changed jde-option-dialog to use recursive-edit mode to emulate a
627 ;; modal dialog. Now the show dialog method enters recursive edit mode
628 ;; thereby suspending the currently executing command until the user
629 ;; selects the OK or Cancel button on the dialog. Selecting the OK button
630 ;; on the dialog causes the dialog to update its :selection field to the
631 ;; option chosen by the user. Selecting the Cancel button sets the
632 ;; :selection field to nil.
634 ;; Revision 1.15 2001/08/09 03:37:11 paulk
635 ;; Fixed error caused by missing :documentatation keyword in jde-option-dialog. Thanks to David Ponce.
637 ;; Revision 1.14 2001/08/07 05:31:26 paulk
638 ;; Added ok-action-args field to jde-option-dialog.
640 ;; Revision 1.13 2001/07/31 05:11:52 paulk
643 ;; Revision 1.12 2001/05/21 06:44:29 paulk
644 ;; Added jde-option-dialog class.
646 ;; Revision 1.11 2001/04/19 04:37:14 paulk
647 ;; Converted array and object trees to derive from David Ponce's tree widget.
649 ;; Revision 1.10 2001/02/16 04:38:52 paulk
650 ;; Added (require 'cl) to enable batch compile.
652 ;; Revision 1.9 2000/12/18 05:22:46 paulk
653 ;; *** empty log message ***
655 ;; Revision 1.8 2000/11/27 06:15:02 paulk
656 ;; Added an experimental jde-widget-option-tree widget.
658 ;; Revision 1.7 2000/08/31 05:22:17 paulk
659 ;; Fixed bug on XEmacs where the Cancel button overwrote the OK button in the standard dialog class.
661 ;; Revision 1.6 2000/02/01 04:11:57 paulk
664 ;; Revision 1.5 2000/01/17 09:36:41 paulk
665 ;; Implemented array and object inspectors.
667 ;; Revision 1.4 2000/01/15 08:05:10 paulk
668 ;; Implemented dynamic tree widget.
670 ;; Revision 1.3 1999/11/16 05:58:18 paulk
671 ;; Added trace method commands and skeletons for trace class and cancel
674 ;; Revision 1.2 1999/10/13 06:19:57 paulk
675 ;; Add JDEBug->Threads->Show Threads command
677 ;; Revision 1.1 1999/09/28 04:39:42 paulk
681 ;; End of jde-widgets.el