Listener to OK

9 views
Skip to first unread message

Scott

unread,
Aug 12, 2010, 1:07:50 PM8/12/10
to Deducer
Ian and others:

When building dialogs in R for Deducer, is there a way to have a
listener respond to the OK in a subdialog and as a result activate the
Run on the parent dialog?

It seems that something like this has already been done for the
Deducer software, but using a Java program. For example in the Linear
Regression Model Explorer in the Options subdialog if you click on
Parameter Correlations and click on OK, then immediately you get the
parameter correlations in the Preview window, which I imagine came
about by activating the Run on the Linear Regession Model Explorer
using the parameters clicked on in the Options subdialog. For this
purpose this procedure is of course more convenient to the user than
having to press Run manually after clicking on the Okay in the
subdialog.

Thanks for any help that can be given!

/Scott

Ian Fellows

unread,
Aug 12, 2010, 2:10:05 PM8/12/10
to ded...@googlegroups.com
Scott,

sure, any dialog extending RDialog has a method getOkayCanel(), which
returns the OkayCancel buttons at the bottom. you can then get the OK
button with getApproveButton(). You can see what methods are available
with .jmethods(subDialog).

#make dialog
subDialog <- new(SimpleRSubDialog,.jnull(),"sub dialog")
setSize(subDialog,250,300)


#make action listener
ActionListener <- J("org.rosuda.deducer.widgets.event.RActionListener")
actionFunction <- function(cmd,ActionEvent){
cat("hi there")
}
listener <- new(ActionListener)
listener$setFunction(toJava(actionFunction))

#get button and add action listener
okButton <- subDialog$getOkayCancel()$getApproveButton()
okButton$addActionListener(listener)


subDialog$setVisible(T)

Scott

unread,
Aug 14, 2010, 2:15:27 PM8/14/10
to Deducer
Ian,

Thanks for the rapid reply.

Your example did not address the issue of how to activate the run on
the parent dialog,
but I figured it out with inspiration provided by your answer. I'll
try to provide a runnable example of what I did when I find time, but
briefly, I did the following:

With a parent dialog defined as, say, parentDialog, within the action
function for pressing OK on the subDialog, I put in

okButtonParent <- parentDialog$getOkayCancel()$getApproveButton()
okButtonParent$doClick()

/Scott
> > /Scott- Dölj citerad text -
>
> - Visa citerad text -
Reply all
Reply to author
Forward
0 new messages