Skip to main content



      Home
Home » Eclipse Projects » JFace » [Esc]-, [Enter]- and Close functions for a Dialog class
[Esc]-, [Enter]- and Close functions for a Dialog class [message #18586] Fri, 03 July 2009 08:41 Go to next message
Eclipse UserFriend
Hello,

in a subclass of org.eclipse.jface.dialogs.Dialog I've 2 buttons MyButton1
and MyButton2.

I'd like that
- MyButton1 is triggered by pressing [Enter] and
- MyButton2 is triggered by pressing [Esc] or by clicking the X
[Close]-IconButton right above the dialog
besides their usual behaviour on mouse clicks.

How can this behaviour be implemented for the 2 buttons in Dialog?

And by the way:
Where can a find a comprehensive online description/manual for the features
and implementation of org.eclipse.jface.dialogs.Dialog?

Thomas Wiedmann
Re: [Esc]-, [Enter]- and Close functions for a Dialog class [message #18594 is a reply to message #18586] Mon, 06 July 2009 13:15 Go to previous messageGo to next message
Eclipse UserFriend
Thomas Wiedmann wrote:
> Hello,
>
> in a subclass of org.eclipse.jface.dialogs.Dialog I've 2 buttons
> MyButton1 and MyButton2.
>
> I'd like that
> - MyButton1 is triggered by pressing [Enter] and
> - MyButton2 is triggered by pressing [Esc] or by clicking the X
> [Close]-IconButton right above the dialog
> besides their usual behaviour on mouse clicks.
>
> How can this behaviour be implemented for the 2 buttons in Dialog?

The [Enter] behaviour is the default button behaviour. There can be one
per dialog, and there is support code for it:
org.eclipse.jface.dialogs.Dialog.createButton(Composite, int, String,
boolean)

[Esc] is a window manager default that will close the shell. You get
the same behaviour by having your
org.eclipse.swt.events.ShellListener.shellClosed(ShellEvent) and your
button selection listener call the same method.

The documentation is mostly javadocs (also available from the help
link),
http://wiki.eclipse.org/JFaceSnippets#Snippet012DialogWithIm ageButtons
and
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/dialogs.htm

PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: [Esc]-, [Enter]- and Close functions for a Dialog class [message #19370 is a reply to message #18594] Wed, 08 July 2009 01:56 Go to previous messageGo to next message
Eclipse UserFriend
"Paul Webster" <pwebster@ca.ibm.com> schrieb im Newsbeitrag
news:h2tbfv$7q9$1@build.eclipse.org...
> Thomas Wiedmann wrote:
>> Hello,
>>
>> in a subclass of org.eclipse.jface.dialogs.Dialog I've 2 buttons
>> MyButton1 and MyButton2.
>>
>> I'd like that
>> - MyButton1 is triggered by pressing [Enter] and
>> - MyButton2 is triggered by pressing [Esc] or by clicking the X
>> [Close]-IconButton right above the dialog
>> besides their usual behaviour on mouse clicks.
>>
>> How can this behaviour be implemented for the 2 buttons in Dialog?

> ....
> [Esc] is a window manager default that will close the shell. You get the
> same behaviour by having your
> org.eclipse.swt.events.ShellListener.shellClosed(ShellEvent) and your
> button selection listener call the same method.

The 2nd info concerning the [Esc] function I couldn't yet realize, because I
didn't understand it in detail.
How can a button, e. g. myButton2 as instance of
org.eclipse.swt.widgets.Button, be combined with the [Esc], that it's
action[s] are triggered after pressing [Esc]?

Furthermore the method
org.eclipse.swt.events.ShellListener.shellClosed(ShellEvent) was not
triggered when I pressed the x (Close) button right above the dialog.
I tried with:

System.out.println("### 1");
view.getShell().addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent ev) {
System.out.println("### 2");
}
});

view.getShell() really addressed the Shell.
I saw ### 1 in the output, but not ### 2 after clicking on X. What is
missing or wrong?


Thomas Wiedmann
Re: [Esc]-, [Enter]- and Close functions for a Dialog class [message #19462 is a reply to message #19370] Wed, 08 July 2009 08:27 Go to previous messageGo to next message
Eclipse UserFriend
Thomas Wiedmann wrote:
> Furthermore the method
> org.eclipse.swt.events.ShellListener.shellClosed(ShellEvent) was not
> triggered when I pressed the x (Close) button right above the dialog.
> I tried with:
>
> System.out.println("### 1");
> view.getShell().addShellListener(new ShellAdapter() {
> public void shellClosed(ShellEvent ev) {
> System.out.println("### 2");
> }
> });
>
> view.getShell() really addressed the Shell.
> I saw ### 1 in the output, but not ### 2 after clicking on X. What is
> missing or wrong?
>
>
> Thomas Wiedmann

I think Paul meant attaching the listener to your dialog's shell, and
not your view. Something close to this:
myButton2.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
myMethod();
}
});
dialog.getShell().addShellListener(new ShellAdapter()
{
@Override
public void shellClosed(ShellEvent ev)
{
myMethod();
}
});

private void myMethod()
{
System.out.println("### 2");
}

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: [Esc]-, [Enter]- and Close functions for a Dialog class [message #19597 is a reply to message #19462] Thu, 09 July 2009 03:05 Go to previous message
Eclipse UserFriend
> myButton2.addSelectionListener(new SelectionAdapter()
> {
> @Override
> public void widgetSelected(SelectionEvent e)
> {
> myMethod();
> }
> });
> dialog.getShell().addShellListener(new ShellAdapter()
> {
> @Override
> public void shellClosed(ShellEvent ev)
> {
> myMethod();
> }
> });
>
> private void myMethod()
> {
> System.out.println("### 2");
> }

No, it didn't work for me. The method shellClosed(ShellEvent ev)
is not called, when I close the dialog. Is there any other listener
suitable for catching the event of closing a dialog?

Thomas Wiedmann
Previous Topic:Changing the expand and collapse icon for TreeViewer
Next Topic:How to implement a on-the-fly compiler?
Goto Forum:
  


Current Time: Sun May 11 22:46:33 EDT 2025

Powered by FUDForum. Page generated in 0.13610 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top