Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to get a notification when a composite has been clicked
How to get a notification when a composite has been clicked [message #466112] Mon, 02 January 2006 15:36 Go to next message
Eclipse UserFriend
Originally posted by: john.obyrne.gmail.com

Hi,

I have a parent Composite which may have many children covering partially or
completely all the available area (maybe Trees, buttons, or anything else).

Knowing only the parent composite, is there a way to get notified if either
one of the children or the composite itself has been clicked?

I obviously tried:

parentComposite.addMouseListener(new MouseAdapter() {

public void mouseDown(MouseEvent e) {
System.out.println("Mouse down");
}
});

I receive notifications when the composite is clicked, but I receive nothing
when one of the composite's children is clicked.
I know there is a way to achieve this because, when you click on a SWT
control in an Eclipse view (or editor), the view is automatically activated.

Thanks for any hint,
John.
Re: How to get a notification when a composite has been clicked [message #466114 is a reply to message #466112] Mon, 02 January 2006 18:57 Go to previous messageGo to next message
Haris Peco is currently offline Haris PecoFriend
Messages: 1072
Registered: July 2009
Senior Member
John,
you have to catch untyped event
see
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet46.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup
John O'Byrne wrote:

> Hi,
>
> I have a parent Composite which may have many children covering partially
> or completely all the available area (maybe Trees, buttons, or anything
> else).
>
> Knowing only the parent composite, is there a way to get notified if
> either
> one of the children or the composite itself has been clicked?
>
> I obviously tried:
>
> parentComposite.addMouseListener(new MouseAdapter() {
>
> public void mouseDown(MouseEvent e) {
> System.out.println("Mouse down");
> }
> });
>
> I receive notifications when the composite is clicked, but I receive
> nothing when one of the composite's children is clicked.
> I know there is a way to achieve this because, when you click on a SWT
> control in an Eclipse view (or editor), the view is automatically
> activated.
>
> Thanks for any hint,
> John.
Re: How to get a notification when a composite has been clicked [message #466118 is a reply to message #466114] Tue, 03 January 2006 09:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.obyrne.gmail.com

Thanks for your answer,
I tried that, the snippet works fine but if I remove the
composite.setEnabled (false) line (because I don't want my main composite to
be disabled), I don't receive mouse events any more when I click on a
composite's child.

I want to reproduce exactly the same effect as Eclipse: when you click
anywhere inside a Workbench part (even on widgets), the part gets activated.

thanks for any other hints ;),

John O'Byrne


"Haris Peco" <snpe@snpe.co.yu> wrote in message
news:dpbphr$i36$1@utils.eclipse.org...
> John,
> you have to catch untyped event
> see
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet46.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup
> John O'Byrne wrote:
>
>> Hi,
>>
>> I have a parent Composite which may have many children covering partially
>> or completely all the available area (maybe Trees, buttons, or anything
>> else).
>>
>> Knowing only the parent composite, is there a way to get notified if
>> either
>> one of the children or the composite itself has been clicked?
>>
>> I obviously tried:
>>
>> parentComposite.addMouseListener(new MouseAdapter() {
>>
>> public void mouseDown(MouseEvent e) {
>> System.out.println("Mouse down");
>> }
>> });
>>
>> I receive notifications when the composite is clicked, but I receive
>> nothing when one of the composite's children is clicked.
>> I know there is a way to achieve this because, when you click on a SWT
>> control in an Eclipse view (or editor), the view is automatically
>> activated.
>>
>> Thanks for any hint,
>> John.
>
Re: How to get a notification when a composite has been clicked [message #466124 is a reply to message #466118] Tue, 03 January 2006 12:25 Go to previous message
Eclipse UserFriend
Originally posted by: john.obyrne.gmail.com

I finally found a way (if there is a better way, please tell me ;) ) using
the Display.addFilter method:

// This hack is needed to be notified when a panel is clicked (the panel
itself or one of its children)
displayListener = new Listener() {
public void handleEvent(Event event) {
if (isExpanded() && isVisible()) {
// We convert the mouse widget relative coordinates to display
coordinates
Point clickedPoint = ((Control) event.widget).toDisplay(event.x,
event.y);

// We convert the panel bounds to display coordinates
Rectangle panelBounds = getClientArea();
Point location = toDisplay(panelBounds.x, panelBounds.y);
panelBounds.x = location.x;
panelBounds.y = location.y;

if (panelBounds.contains(clickedPoint)) {
System.out.println("Widget:" + event.widget.toString() + " x:" +
clickedPoint.x + ", y:" + clickedPoint.y + ", rect:" + panelBounds);
// We notify the listeners of the panelActivated Event
for (ExpandablePanelListener listener : listeners)
listener.panelActivated(ExpandablePanel.this);
}
}
}
};
// We add the previously created listener to the display
getDisplay().addFilter(SWT.MouseDown, displayListener);

"John O'Byrne" <john.obyrne@gmail.com> wrote in message
news:dpdg9t$h5q$1@utils.eclipse.org...
> Thanks for your answer,
> I tried that, the snippet works fine but if I remove the
> composite.setEnabled (false) line (because I don't want my main composite
> to be disabled), I don't receive mouse events any more when I click on a
> composite's child.
>
> I want to reproduce exactly the same effect as Eclipse: when you click
> anywhere inside a Workbench part (even on widgets), the part gets
> activated.
>
> thanks for any other hints ;),
>
> John O'Byrne
>
>
> "Haris Peco" <snpe@snpe.co.yu> wrote in message
> news:dpbphr$i36$1@utils.eclipse.org...
>> John,
>> you have to catch untyped event
>> see
>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet46.java?rev=HEAD&a mp;content-type=text/vnd.viewcvs-markup
>> John O'Byrne wrote:
>>
>>> Hi,
>>>
>>> I have a parent Composite which may have many children covering
>>> partially
>>> or completely all the available area (maybe Trees, buttons, or anything
>>> else).
>>>
>>> Knowing only the parent composite, is there a way to get notified if
>>> either
>>> one of the children or the composite itself has been clicked?
>>>
>>> I obviously tried:
>>>
>>> parentComposite.addMouseListener(new MouseAdapter() {
>>>
>>> public void mouseDown(MouseEvent e) {
>>> System.out.println("Mouse down");
>>> }
>>> });
>>>
>>> I receive notifications when the composite is clicked, but I receive
>>> nothing when one of the composite's children is clicked.
>>> I know there is a way to achieve this because, when you click on a SWT
>>> control in an Eclipse view (or editor), the view is automatically
>>> activated.
>>>
>>> Thanks for any hint,
>>> John.
>>
>
>
Previous Topic:is this a tableTree bug?
Next Topic:StyledText with right-alignment?
Goto Forum:
  


Current Time: Thu Dec 05 17:27:10 GMT 2024

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

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

Back to the top