1 ;;; jde-widgets.el -- Custom-style widgets used by the JDE
2 ;; $Revision: 1.1 $ $Date: 2007-11-26 15:16:50 $
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.
43 (jde-require 'tree-widget)
46 ;; ----------------------------------------------------------------------
47 ;; The Tree Widget Code:
50 ;;; The `tree' Widget.
52 (define-widget 'jde-widget-tree-open-button 'item
53 "Open node in `jde-tree' widget."
57 :action 'jde-widget-tree-open-button-callback
58 :help-echo "Show subtree."
61 (defun jde-widget-tree-open-button-callback (widget &optional event)
62 ;; Set parent state to open.
63 (widget-value-set (widget-get widget :parent) t))
65 (define-widget 'jde-widget-tree-close-button 'item
66 "Close node in `tree' widget."
70 :action 'jde-widget-tree-close-button-callback
71 :help-echo "Hide subtree."
74 (defun jde-widget-tree-close-button-callback (widget &optional event)
75 ;; Set parent state to closed.
76 (let* ((parent (widget-get widget :parent))
77 (entries (widget-get parent :args))
78 (children (widget-get parent :children)))
79 (while (and entries children)
80 (widget-put (car entries) :value (widget-value (car children)))
81 (setq entries (cdr entries)
82 children (cdr children)))
83 (widget-value-set parent nil)))
85 (define-widget 'jde-widget-tree 'default
86 "A tree structure widget."
87 :convert-widget 'widget-types-convert-widget
91 :prefix-empty " |--- "
92 :value-get 'widget-value-value-get
93 :value-create 'jde-widget-tree-value-create-callback
94 :value-delete 'widget-children-value-delete)
96 (defun jde-widget-tree-value-create-callback (widget)
98 (let ((open (widget-value widget))
99 (tag (widget-get widget :tag))
100 (entries (widget-get widget :args))
102 (cond ((null entries)
104 (insert (widget-get widget :prefix-empty) tag "\n"))
108 (widget-create-child-and-convert widget 'jde-widget-tree-close-button)
110 (insert "-\\ " tag "\n")
111 (let ((prefix (concat (widget-get widget :prefix)
112 (widget-get widget :prefix-extra)))
115 (setq entry (car entries)
116 entries (cdr entries))
119 (widget-create-child-and-convert widget entry
122 ;; Last entry uses a different prefix.
123 (widget-create-child-and-convert
126 :prefix-empty " `--- "))
130 (push (widget-create-child-and-convert widget 'jde-widget-tree-open-button)
132 (insert "-- " tag "\n")))
133 (widget-put widget :children children)
134 (widget-put widget :buttons buttons)))
136 ;;----------------------------------------------------------------------
137 ;; Eval this to create a small tree.
141 (switch-to-buffer "*Tree Example*")
142 (kill-all-local-variables)
143 ;; (make-local-variable 'widget-example-repeat)
144 (let ((inhibit-read-only t))
146 (let ((all (overlay-lists)))
147 (mapcar 'delete-overlay (car all)) (mapcar 'delete-overlay (cdr all)))
149 (widget-insert "Test tree widget. \n\n")
151 ; (setq tree (widget-create 'tree
153 ; '(tree :tag "First")
154 ; '(tree :tag "Second"
156 ; (tree :tag "Nested"))
157 ; '(tree :tag "Third")))
159 (setq tree (widget-create 'jde-widget-tree
160 :tag "<test.Foo:139>"
161 '(jde-widget-tree :tag "n int 0")
162 ;; '(jde-widget-tree :tag '(jde-widget-tree :tag "n int 0"))
163 '(jde-widget-tree :tag "a double 5.5")
164 '(jde-widget-tree :tag "s S <test.S:145>"
165 (jde-widget-tree :tag "b boolean true"))))
169 ; (list "ThreadGroup" 189 "system"
171 ; (list "Thread" 190 "Signal dispatcher" "runnable" "suspended by debugger")
172 ; (list "Thread" 191 "Reference Handler" "waiting" "suspended by debugger")
173 ; (list "Thread" 192 "Finalizer" "waiting" "suspended by debugger")))
174 ; (list "ThreadGroup" 193 "main"
176 ; (list "Thread" 1 "main" "runnable" "suspended at breakpoint"))
178 ; (tree (jde-dbs-map-threads-to-tree threads)))
181 ; (apply 'widget-create tree))
183 (use-local-map widget-keymap)
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
190 ;; Dynamic tree widget ;;
192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
194 (define-widget 'jde-widget-dtree 'default
195 "A widget whose nodes are generated on demand.
196 The first time the user expands the tree, the tree invokes a function that
197 generates the nodes. The tree then caches the nodes.
198 Thereafter, the node uses the cached nodes when the
199 user closes and then reopens the tree. Use the syntax
200 (widget-create 'jde-widget-dtree :tag NAME :node-fcn NODE-FUNCTION)
201 to create the widget where NAME is the tree name and NODE-FUNCTION
202 is a function that takes one argument, the tree itself, and
203 returns a list of widgets that are the nodes of the expanded
207 :value-get 'widget-value-value-get
208 :value-create 'jde-widget-dtree-create-callback
209 :value-delete 'widget-children-value-delete
212 (defun jde-widget-dtree-create-callback (widget)
213 (let ((open (widget-value widget))
214 (tag (widget-get widget :tag))
218 (push (widget-create-child-and-convert widget 'jde-widget-tree-close-button)
220 (insert "-\\ " tag "\n")
221 (let ((prefix (concat (widget-get widget :prefix)
222 (widget-get widget :prefix-extra)))
223 (nodes (widget-get widget :nodes))
226 (when (and (widget-get widget :has-nodes)
229 (funcall (widget-get widget :node-fcn) widget))
231 (widget-put widget :nodes nodes)
232 (widget-put widget :has-nodes nil)))
235 (setq node (car nodes)
240 (widget-create-child-and-convert widget node
243 (widget-create-child-and-convert
246 :prefix-empty " `--- "))
250 (push (widget-create-child-and-convert widget 'jde-widget-tree-open-button)
252 (insert "-- " tag "\n")))
253 (widget-put widget :children children)
254 (widget-put widget :buttons buttons)))
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259 ;; Java object widget ;;
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
263 (defun jde-test-get-fields (process object-id)
265 (cons (list "sum" "double") (list "double" 0.0))
266 (cons (list "r" "int") (list "int" 1))
267 (cons (list "z" "java.lang.String") (list "java.lang.String" 229 nil))
268 (cons (list "B" "double[]") (list "double[]" 228 nil))
269 (cons (list "A" "double[][]") (list "double[][]" 227 nil))
270 (cons (list "args" "java.lang.String[]") (list "java.lang.String[]" 226 nil))))
272 (defun jde-widget-java-var-to-tree (process var)
273 (let* ((var-name (oref var name))
274 (var-type (oref var jtype))
275 (var-value (oref var value))
276 (var-tag (format "%s %s" var-type var-name)))
278 ((typep var-value 'jde-dbs-java-udci)
279 (setq var-tag (format "%s [id: %d]" var-tag (oref var-value :id)))
280 (if (string= (oref var-value :jtype) "java.lang.String")
281 (let* ((cmd (jde-dbs-get-string
284 :object-id (oref var-value id)))
285 (str-val (jde-dbs-cmd-exec cmd)))
289 :open (jde-dbo-locals-open-p var-tag)
291 (list 'tree-widget :tag str-val)))
292 (list 'jde-widget-java-obj
295 :open (jde-dbo-locals-open-p var-tag)
297 :object-id (oref var-value :id))))
298 ((typep var-value 'jde-dbs-java-array)
299 (setq var-tag (format "%s [id: %d]" var-tag (oref var-value :id)))
300 (list 'jde-widget-java-array
303 :open (jde-dbo-locals-open-p var-tag)
304 :process process :object var-value))
305 ((typep var-value 'jde-dbs-java-primitive)
309 :open (jde-dbo-locals-open-p var-tag)
312 :tag (format "%s" (oref var-value value)))))
313 ((typep var-value 'jde-dbs-java-null)
317 :open (jde-dbo-locals-open-p var-tag)
319 (list 'tree-widget :tag "null")))
321 (error "Unidentified type of local variable: %s" var-tag)))))
323 (defun jde-widget-java-obj-get-fields (obj-widget)
324 (if (widget-get obj-widget :args)
325 (widget-get obj-widget :args)
326 (let* ((process (widget-get obj-widget :process))
327 (object-id (widget-get obj-widget :object-id))
330 (format "get_object %d" object-id)
332 :object-id object-id))
334 (jde-dbs-cmd-exec cmd))
335 (fields (oref object fields))
339 (setq field (car fields) fields (cdr fields))
340 (setq field (cdr field))
342 (jde-widget-java-var-to-tree process field)
346 (define-widget 'jde-widget-java-obj 'tree-widget
347 "A widget that represents a Java object.
348 This widget is essentially a tree node whose entries are the fields
349 of the corresponding object. The first time the user expands the node,
350 the node retrieves the fields of the object from the debugger and
351 caches them. Thereafter, the node uses the cached values when the
352 user closes and then reopens the node. Use the syntax
353 (widget-create 'jde-widget-java-obj
354 :tag NAME :process PROCESS :object-id OBJ-ID) to create the widget where
355 NAME is the object's name, PROCESS is the process in which
356 the object exists, and ID is the debugger id for the object."
357 :dynargs 'jde-widget-java-obj-get-fields
361 (defun jde-widget-java-array-element-to-tree (process element index)
363 ((typep element 'jde-dbs-java-udci)
364 (if (string= (oref element :jtype) "java.lang.String")
365 (let* ((cmd (jde-dbs-get-string
368 :object-id (oref element id)))
369 (str-val (jde-dbs-cmd-exec cmd)))
371 :tag (format "[%d] %s" index str-val)
372 :node-name (format "[%d] %s" index str-val)
373 :open (jde-dbo-locals-open-p (format "[%d] %s" index str-val))
375 (list 'jde-widget-java-obj
376 :tag (format "[%d] %s" index (oref element jtype))
377 :node-name (format "[%d] %s" index (oref element jtype))
378 :open (jde-dbo-locals-open-p (format "[%d] %s" index (oref element jtype)))
380 :object-id (oref element id))))
381 ((typep element 'jde-dbs-java-array)
382 (list 'jde-widget-java-array
383 :tag (format "[%d] %s" index (oref element jtype))
384 :node-name (format "[%d] %s" index (oref element jtype))
385 :open (jde-dbo-locals-open-p (format "[%d] %s" index (oref element jtype)))
388 ((typep element 'jde-dbs-java-primitive)
389 (list 'tree-widget :tag (format "[%d] %s" index (oref element value))))
390 ((typep element 'jde-dbs-java-null)
391 (list 'tree-widget :tag (format "[%d] null" index)))
393 (error "Unidentified type of object: <%s|%s>" (oref element jtype)
394 (oref element id)))))
396 (defun jde-widget-java-array-get-elements (array-widget)
397 (if (widget-get array-widget :args)
398 (widget-get array-widget :args)
399 (let* ((process (widget-get array-widget :process))
400 (array (widget-get array-widget :object))
405 (format "get_array_length %d" (oref array id))
408 (jde-dbs-cmd-exec cmd)
411 (if (slot-boundp array 'length)
415 (when (> array-length 0)
418 (format "get_array_elements %d" (oref array id))
422 :length array-length))
423 (jde-dbs-cmd-exec cmd)
424 (let ((elements (oref array elements))
429 (setq element (car elements) elements (cdr elements))
432 (list (jde-widget-java-array-element-to-tree process element index))))
433 (setq index (1+ index)))
436 (define-widget 'jde-widget-java-array 'tree-widget
437 "A widget that represents a Java array. Clicking on the widget's
438 expand button causes the widget to display the values of the array."
439 :dynargs 'jde-widget-java-array-get-elements
444 (switch-to-buffer "*Java Object Example*")
445 (kill-all-local-variables)
446 ;; (make-local-variable 'widget-example-repeat)
447 (let ((inhibit-read-only t))
449 (let ((all (overlay-lists)))
450 (mapcar 'delete-overlay (car all)) (mapcar 'delete-overlay (cdr all)))
452 (widget-insert "Test object tree. \n\n")
454 (widget-create 'jde-widget-java-obj :tag "jmath.System s" :process "process" :object-id 1)
455 (widget-create 'jde-widget-java-obj :tag "java.awt.Frame frame1" :process "process" :object-id 1)
457 (use-local-map widget-keymap)
462 ;; ----------------------------------------------------------------------
463 ;; Option Tree Widget
465 (defun jde-widget-option-tree-open-button-callback (widget &optional event)
466 ;; Set parent state to open.
467 (widget-value-set (widget-get widget :parent) t)
470 (define-widget 'jde-widget-option-tree-open-button 'item
471 "Button to open an option tree."
475 :action 'jde-widget-option-tree-open-button-callback
476 :help-echo "Show option tree."
479 (define-widget 'jde-widget-option-tree-close-button 'item
480 "Close node in `jde-widget-option-tree' widget."
484 :action 'jde-widget-option-tree-close-button-callback
485 :help-echo "Hide panel."
488 (defun jde-widget-option-tree-close-button-callback (widget &optional event)
489 ;; Set parent state to closed.
490 (let* ((parent (widget-get widget :parent))
491 (entries (widget-get parent :args))
492 (group (car (widget-get parent :children)))
493 (children (widget-get group :children)))
494 ;; Get values entered by user from children and
495 ;; insert them in the corresponding widget definitions
496 ;; so that they appear the next time the user expands
498 (while (and entries children)
499 (widget-put (car entries) :value (widget-value (car children)))
500 (setq entries (cdr entries)
501 children (cdr children)))
502 (widget-value-set parent nil)))
504 (defun jde-widget-option-tree-value-create-callback (widget)
505 (let ((open-widget-p (widget-value widget))
506 (tag (widget-get widget :tag))
507 (entries (widget-get widget :args))
508 entry children buttons)
510 ;; Wrap widgets in this tree in a group widget
511 ;; to ensure proper formatting.
513 (list 'group :args entries))
516 (widget-create-child-and-convert
518 'jde-widget-option-tree-close-button)
520 (insert "-\\ " tag "\n")
521 (push (widget-create-child-and-convert widget group-type) children)))
523 (push (widget-create 'jde-widget-option-tree-open-button
526 (insert "-- " tag "\n")))
527 (widget-put widget :children children)
528 (widget-put widget :buttons buttons)))
531 (define-widget 'jde-widget-option-tree 'default
532 "A panel containing widgets."
533 :convert-widget 'widget-types-convert-widget
535 :value-get 'widget-value-value-get
536 :value-create 'jde-widget-option-tree-value-create-callback
537 :value-delete 'widget-children-value-delete)
540 (defun test-option-tree ()
542 (switch-to-buffer "*Panel Example*")
543 (kill-all-local-variables)
544 (let ((inhibit-read-only t))
546 (let ((all (overlay-lists)))
547 (mapcar 'delete-overlay (car all))
548 (mapcar 'delete-overlay (cdr all)))
550 (widget-insert "Test panel widget. \n\n")
552 (let ((panel (widget-create
553 'jde-widget-option-tree
554 :tag "Compile Options"
555 '(cons :tag "Debugger Options"
556 (radio-button-choice :format "%t \n%v"
562 (cons :tag "Other Debugger Info"
564 (radio-button-choice :format "%t \n%v"
568 '(repeat (string :tag "Path"))
569 '(editable-field :tag "classpath"
570 :format " %t: %v\n %h \n\n"
572 :doc "Name of project.")
573 '(editable-field :tag "compiler"
574 :format " %t: %v\n %h \n\n"
576 :doc "Name of project.")
577 '(jde-widget-option-tree :tag "Debugger Options"
578 (repeat (string :tag "Path"))))))
579 (use-local-map widget-keymap)
584 (provide 'jde-widgets)
586 ;; $Log: jde-widgets.el.upstream,v $
587 ;; Revision 1.1 2007-11-26 15:16:50 michaels
588 ;; Update jde to author version 2.3.5.1.
590 ;; Revision 1.26 2004/06/03 02:21:13 paulk
591 ;; jde-require tree-widget.
593 ;; Revision 1.25 2003/01/12 23:34:51 jslopez
594 ;; Small, patch to reduce the amount of cases that cause infinite recursion.
596 ;; Revision 1.24 2001/12/04 05:27:26 paulk
597 ;; Moved dialog classes to the efc (Emacs Foundation Classes) package.
599 ;; Revision 1.23 2001/11/29 11:41:18 paulk
600 ;; Option dialog now positions cursor over OK button.
602 ;; Revision 1.22 2001/11/28 16:50:28 jslopez
603 ;; Fixes bug, that would not keep the state
604 ;; of nodes created by jde-widget-java-array-element-to-tree.
606 ;; Revision 1.21 2001/11/28 08:38:02 paulk
607 ;; Added note about fix for Emacs 21.1 bug.
609 ;; Revision 1.20 2001/11/27 21:04:05 jslopez
610 ;; Modifies jde-widget-java-var-to-tree to keep nodes the states of nodes.(open/close)
612 ;; Revision 1.19 2001/11/24 15:23:11 paulk
613 ;; The jde-option-dialog versions of jde-dialog-ok and jde-dialog-cancel
614 ;; now delete the other window ony if the current version of Emacs is not
615 ;; XEmacs and is less than major version 21.
617 ;; Revision 1.18 2001/11/24 07:31:56 paulk
618 ;; The jde-option-dialog version of jde-dialog-ok now deletes the other windows,
619 ;; if the current version of Emacs is not 21.1.
621 ;; Revision 1.17 2001/11/24 07:23:54 paulk
622 ;; Changed the jde-dialog-ok method of jde-option-dialog to not delete
623 ;; other windows. This is necessary to avoid a bug in the Emacs 21.1.1
624 ;; version of exit-recursive-edit. This line should be restored when
627 ;; Revision 1.16 2001/10/26 06:36:07 paulk
628 ;; Changed jde-option-dialog to use recursive-edit mode to emulate a
629 ;; modal dialog. Now the show dialog method enters recursive edit mode
630 ;; thereby suspending the currently executing command until the user
631 ;; selects the OK or Cancel button on the dialog. Selecting the OK button
632 ;; on the dialog causes the dialog to update its :selection field to the
633 ;; option chosen by the user. Selecting the Cancel button sets the
634 ;; :selection field to nil.
636 ;; Revision 1.15 2001/08/09 03:37:11 paulk
637 ;; Fixed error caused by missing :documentatation keyword in jde-option-dialog. Thanks to David Ponce.
639 ;; Revision 1.14 2001/08/07 05:31:26 paulk
640 ;; Added ok-action-args field to jde-option-dialog.
642 ;; Revision 1.13 2001/07/31 05:11:52 paulk
645 ;; Revision 1.12 2001/05/21 06:44:29 paulk
646 ;; Added jde-option-dialog class.
648 ;; Revision 1.11 2001/04/19 04:37:14 paulk
649 ;; Converted array and object trees to derive from David Ponce's tree widget.
651 ;; Revision 1.10 2001/02/16 04:38:52 paulk
652 ;; Added (require 'cl) to enable batch compile.
654 ;; Revision 1.9 2000/12/18 05:22:46 paulk
655 ;; *** empty log message ***
657 ;; Revision 1.8 2000/11/27 06:15:02 paulk
658 ;; Added an experimental jde-widget-option-tree widget.
660 ;; Revision 1.7 2000/08/31 05:22:17 paulk
661 ;; Fixed bug on XEmacs where the Cancel button overwrote the OK button in the standard dialog class.
663 ;; Revision 1.6 2000/02/01 04:11:57 paulk
666 ;; Revision 1.5 2000/01/17 09:36:41 paulk
667 ;; Implemented array and object inspectors.
669 ;; Revision 1.4 2000/01/15 08:05:10 paulk
670 ;; Implemented dynamic tree widget.
672 ;; Revision 1.3 1999/11/16 05:58:18 paulk
673 ;; Added trace method commands and skeletons for trace class and cancel
676 ;; Revision 1.2 1999/10/13 06:19:57 paulk
677 ;; Add JDEBug->Threads->Show Threads command
679 ;; Revision 1.1 1999/09/28 04:39:42 paulk
683 ;; End of jde-widgets.el