Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » TreeItem Listener
TreeItem Listener [message #453811] Sun, 10 April 2005 21:40 Go to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi,

What is the secret with TreeItem listener?. Whatever i try, i cannot seem to
get them going. I know it is me and that frustrates me more. Been spending
some time searching but can not find an answer, nore a snippet that
implements the treeitem listener.

Thanks for your help,

Wim Jongman


// Applications filter
TreeItem appFilterNode = new TreeItem(appNode, SWT.MULTI | SWT.CHECK);
appFilterNode.setText("Select Applications");
appFilterNode.setImage(new Image(shell.getDisplay(), this.getClass()
.getResourceAsStream("filter.gif")));
appFilterNode.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
System.out.println("Boem");
}
});
Re: TreeItem Listener [message #453833 is a reply to message #453811] Mon, 11 April 2005 17:53 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
The only event that TreeItem fires is Dispose; other types of listeners must
be hooked to the parent Tree (hint: see a widget class's javadoc for a list
of the events that it fires). Example snippet:

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
Tree tree = new Tree(shell, SWT.NONE);
tree.setBounds(10,10,150,150);
tree.addTreeListener(new TreeListener() {
public void treeExpanded(TreeEvent e) {
System.out.println("expanded: " + ((TreeItem)e.item).getText());
}
public void treeCollapsed(TreeEvent e) {
System.out.println("collapsed: " +
((TreeItem)e.item).getText());
}
});
tree.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e) {
System.out.println("selected: " + ((TreeItem)e.item).getText());
}
public void widgetDefaultSelected(SelectionEvent e) {
System.out.println("default selected: " +
((TreeItem)e.item).getText());
}
});
TreeItem rootItem = new TreeItem(tree, SWT.NONE);
rootItem.setText("root item");
new TreeItem(rootItem, SWT.NONE).setText("child item");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant

"Wim Jongman" <wim@nospam.org> wrote in message
news:d3c6o6$mss$1@news.eclipse.org...
> Hi,
>
> What is the secret with TreeItem listener?. Whatever i try, i cannot seem
to
> get them going. I know it is me and that frustrates me more. Been spending
> some time searching but can not find an answer, nore a snippet that
> implements the treeitem listener.
>
> Thanks for your help,
>
> Wim Jongman
>
>
> // Applications filter
> TreeItem appFilterNode = new TreeItem(appNode, SWT.MULTI | SWT.CHECK);
> appFilterNode.setText("Select Applications");
> appFilterNode.setImage(new Image(shell.getDisplay(), this.getClass()
> .getResourceAsStream("filter.gif")));
> appFilterNode.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event e) {
> System.out.println("Boem");
> }
> });
>
>
Re: TreeItem Listener [message #453836 is a reply to message #453833] Mon, 11 April 2005 19:39 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi Grant,

Thanks for your response, however, it still bothers me.

First i tried to look up te latest copy of the javadoc that you have but i
have not (which in itself is extremely difficult to find (supposedly, the
location of the javadoc is in the faq, but where is the faq. In general it
is difficult to find basic info like javadocs on the eclipse site but i will
save this for later)) I cannot find it.

There is no mention at-all in the widget on the type of event that is fired.
Supposedly, the addListener method is inherited from Item. TreeItem also
inherits addDisposeListener. Now, why would there be two methods for just
dispose?

Further more, the documentation as you suggest does not mention the event
that triggers the listener.

So, who can back Grant and/or point me to the correct javadoc for SWT where
eventType is explained for addListener

Regards,

Wim

javadoc for Item:
addListener
public void addListener(int eventType,
Listener listener)Adds the listener to the
collection of listeners who will be notifed when an event of the given type
occurs. When the event does occur in the widget, the listener is notified by
sending it the handleEvent() message.

Parameters:
eventType - the type of event to listen for
listener - the listener which should be notified when the event occurs
Throws:
IllegalArgumentException -
a.. ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
a.. ERROR_WIDGET_DISPOSED - if the receiver has been disposed
b.. ERROR_THREAD_INVALID_ACCESS - if not called from the thread that
created the receiver
See Also:
Listener, removeListener(int, org.eclipse.swt.widgets.Listener)

------------------------------------------------------------ --------------------




"Grant Gayed" <grant_gayed@ca.ibm.com> wrote in message
news:d3edtn$i5k$1@news.eclipse.org...
> The only event that TreeItem fires is Dispose; other types of listeners
> must
> be hooked to the parent Tree (hint: see a widget class's javadoc for a
> list
> of the events that it fires). Example snippet:
>
> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setBounds(10,10,200,200);
> Tree tree = new Tree(shell, SWT.NONE);
> tree.setBounds(10,10,150,150);
> tree.addTreeListener(new TreeListener() {
> public void treeExpanded(TreeEvent e) {
> System.out.println("expanded: " +
> ((TreeItem)e.item).getText());
> }
> public void treeCollapsed(TreeEvent e) {
> System.out.println("collapsed: " +
> ((TreeItem)e.item).getText());
> }
> });
> tree.addSelectionListener(new SelectionAdapter(){
> public void widgetSelected(SelectionEvent e) {
> System.out.println("selected: " +
> ((TreeItem)e.item).getText());
> }
> public void widgetDefaultSelected(SelectionEvent e) {
> System.out.println("default selected: " +
> ((TreeItem)e.item).getText());
> }
> });
> TreeItem rootItem = new TreeItem(tree, SWT.NONE);
> rootItem.setText("root item");
> new TreeItem(rootItem, SWT.NONE).setText("child item");
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
> Grant
>
> "Wim Jongman" <wim@nospam.org> wrote in message
> news:d3c6o6$mss$1@news.eclipse.org...
>> Hi,
>>
>> What is the secret with TreeItem listener?. Whatever i try, i cannot seem
> to
>> get them going. I know it is me and that frustrates me more. Been
>> spending
>> some time searching but can not find an answer, nore a snippet that
>> implements the treeitem listener.
>>
>> Thanks for your help,
>>
>> Wim Jongman
>>
>>
>> // Applications filter
>> TreeItem appFilterNode = new TreeItem(appNode, SWT.MULTI | SWT.CHECK);
>> appFilterNode.setText("Select Applications");
>> appFilterNode.setImage(new Image(shell.getDisplay(), this.getClass()
>> .getResourceAsStream("filter.gif")));
>> appFilterNode.addListener(SWT.Selection, new Listener() {
>> public void handleEvent(Event e) {
>> System.out.println("Boem");
>> }
>> });
>>
>>
>
>
Re: TreeItem Listener [message #453845 is a reply to message #453836] Mon, 11 April 2005 22:12 Go to previous message
Eclipse UserFriend
Originally posted by: bob.objfac.com

If Grant says so, it's so.

The javadoc is part of Help. Platform Plug-in Developer Guide >
Reference > API Reference.

There are two different types of events in SWT, low-level and
high-level, and two different types of listeners. High-level listeners
are set using addXXXListener() where XXX is, e.g., Dispose, Selection,
Tree, etc. These are the listeners you are intended to use. Low-level
events are used to implement high-level events; they are intended for
internal use. addListener() is the man behind the curtain you are
supposed to ignore.

If you look at the javadoc or the code you will see that TreeItem
inherits only addDisposeListener() and defines no additional high-level
events. Tree, on the other hand, inherits addDisposeListener() and
defines two more: addTreeListener() and addSelectionListener().

Bob


Wim Jongman wrote:
> Hi Grant,
>
> Thanks for your response, however, it still bothers me.
>
> First i tried to look up te latest copy of the javadoc that you have but i
> have not (which in itself is extremely difficult to find (supposedly, the
> location of the javadoc is in the faq, but where is the faq. In general it
> is difficult to find basic info like javadocs on the eclipse site but i will
> save this for later)) I cannot find it.
>
> There is no mention at-all in the widget on the type of event that is fired.
> Supposedly, the addListener method is inherited from Item. TreeItem also
> inherits addDisposeListener. Now, why would there be two methods for just
> dispose?
>
> Further more, the documentation as you suggest does not mention the event
> that triggers the listener.
>
> So, who can back Grant and/or point me to the correct javadoc for SWT where
> eventType is explained for addListener
>
> Regards,
>
> Wim
>
> javadoc for Item:
> addListener
> public void addListener(int eventType,
> Listener listener)Adds the listener to the
> collection of listeners who will be notifed when an event of the given type
> occurs. When the event does occur in the widget, the listener is notified by
> sending it the handleEvent() message.
>
> Parameters:
> eventType - the type of event to listen for
> listener - the listener which should be notified when the event occurs
> Throws:
> IllegalArgumentException -
> a.. ERROR_NULL_ARGUMENT - if the listener is null
> SWTException -
> a.. ERROR_WIDGET_DISPOSED - if the receiver has been disposed
> b.. ERROR_THREAD_INVALID_ACCESS - if not called from the thread that
> created the receiver
> See Also:
> Listener, removeListener(int, org.eclipse.swt.widgets.Listener)
>
> ------------------------------------------------------------ --------------------
>
>
>
>
> "Grant Gayed" <grant_gayed@ca.ibm.com> wrote in message
> news:d3edtn$i5k$1@news.eclipse.org...
>
>>The only event that TreeItem fires is Dispose; other types of listeners
>>must
>>be hooked to the parent Tree (hint: see a widget class's javadoc for a
>>list
>>of the events that it fires). Example snippet:
>>
>>public static void main(String[] args) {
>> Display display = new Display();
>> Shell shell = new Shell(display);
>> shell.setBounds(10,10,200,200);
>> Tree tree = new Tree(shell, SWT.NONE);
>> tree.setBounds(10,10,150,150);
>> tree.addTreeListener(new TreeListener() {
>> public void treeExpanded(TreeEvent e) {
>> System.out.println("expanded: " +
>>((TreeItem)e.item).getText());
>> }
>> public void treeCollapsed(TreeEvent e) {
>> System.out.println("collapsed: " +
>>((TreeItem)e.item).getText());
>> }
>> });
>> tree.addSelectionListener(new SelectionAdapter(){
>> public void widgetSelected(SelectionEvent e) {
>> System.out.println("selected: " +
>>((TreeItem)e.item).getText());
>> }
>> public void widgetDefaultSelected(SelectionEvent e) {
>> System.out.println("default selected: " +
>>((TreeItem)e.item).getText());
>> }
>> });
>> TreeItem rootItem = new TreeItem(tree, SWT.NONE);
>> rootItem.setText("root item");
>> new TreeItem(rootItem, SWT.NONE).setText("child item");
>> shell.open();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch()) display.sleep();
>> }
>> display.dispose();
>>}
>>
>>Grant
>>
>>"Wim Jongman" <wim@nospam.org> wrote in message
>>news:d3c6o6$mss$1@news.eclipse.org...
>>
>>>Hi,
>>>
>>>What is the secret with TreeItem listener?. Whatever i try, i cannot seem
>>
>>to
>>
>>>get them going. I know it is me and that frustrates me more. Been
>>>spending
>>>some time searching but can not find an answer, nore a snippet that
>>>implements the treeitem listener.
>>>
>>>Thanks for your help,
>>>
>>>Wim Jongman
>>>
>>>
>>> // Applications filter
>>> TreeItem appFilterNode = new TreeItem(appNode, SWT.MULTI | SWT.CHECK);
>>> appFilterNode.setText("Select Applications");
>>> appFilterNode.setImage(new Image(shell.getDisplay(), this.getClass()
>>> .getResourceAsStream("filter.gif")));
>>> appFilterNode.addListener(SWT.Selection, new Listener() {
>>> public void handleEvent(Event e) {
>>> System.out.println("Boem");
>>> }
>>> });
>>>
>>>
>>
>>
>
>
Previous Topic:How to find out absolute index of an item in a Tree?
Next Topic:How to change color of image using code?
Goto Forum:
  


Current Time: Thu Apr 25 21:02:04 GMT 2024

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

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

Back to the top