Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to dis/enable a TreeItem in a TreeView?
How to dis/enable a TreeItem in a TreeView? [message #316869] Wed, 20 June 2007 15:45 Go to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Hey,

I am trying to disable/enable a tree item in a CheckboxTreeView
depending on the status of a domain object. But the CheckboxTreeView
only provides setCheck(Object element, boolean state) and setGrayed(Object
element, boolean state). I tried the setGrayed
method, the TreeItem still can be checked/unchecked after I set
it as grayed. So, it seems it's not what I want. How can I disable/
enable a TreeItem in a CheckboxTreeView?

Thanks.
Re: How to dis/enable a TreeItem in a TreeView? [message #316873 is a reply to message #316869] Wed, 20 June 2007 17:31 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
This is not possible. I think there are already threads in this, the swt
or the rcp newsgroup. I'd say that you can mimic this by adding a
MouseListener and cancle mouse events if they occur on a "disabled"
TreeItem.

Tom

Raymond schrieb:
> Hey,
>
> I am trying to disable/enable a tree item in a CheckboxTreeView
> depending on the status of a domain object. But the CheckboxTreeView
> only provides setCheck(Object element, boolean state) and
> setGrayed(Object element, boolean state). I tried the setGrayed
> method, the TreeItem still can be checked/unchecked after I set
> it as grayed. So, it seems it's not what I want. How can I disable/
> enable a TreeItem in a CheckboxTreeView?
>
> Thanks.
>
Re: How to dis/enable a TreeItem in a TreeView? [message #316878 is a reply to message #316873] Wed, 20 June 2007 18:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Ok, I see. BTW, what is the setGrayed() method for?
I did not see any difference when I set a TreeItem
as grayed. :-)
Re: How to dis/enable a TreeItem in a TreeView? [message #316882 is a reply to message #316878] Wed, 20 June 2007 20:46 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
setGrayed() affects the item's checkbox, assuming that the Tree was created
with style SWT.CHECK.

"Raymond" <ku_long@hotmail.com> wrote in message
news:b5df04ee1002fd632e6046860f2d21b5$1@www.eclipse.org...
> Ok, I see. BTW, what is the setGrayed() method for?
> I did not see any difference when I set a TreeItem
> as grayed. :-)
>
Re: How to dis/enable a TreeItem in a TreeView? [message #316883 is a reply to message #316882] Wed, 20 June 2007 21:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Thanks for you guys' answers. Since the TreeItem
can not be simply disabled/enabled, I tried lots
of other approaches (e.g. catch mouse down event)
to prevent a TreeItem on a CheckboxTreeView from
being checked. But no one worked. Anyone know how
to do that?

Thanks.
Re: How to dis/enable a TreeItem in a TreeView? [message #316890 is a reply to message #316883] Thu, 21 June 2007 08:06 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Don't work with SWT.CHECK but emulate it using Images and CellEditors
this way you can enable/disable the editor easily.

http://wiki.eclipse.org/index.php/Tables_And_Trees_And_Nativ eControls

Tom

Raymond schrieb:
> Thanks for you guys' answers. Since the TreeItem
> can not be simply disabled/enabled, I tried lots of other approaches
> (e.g. catch mouse down event)
> to prevent a TreeItem on a CheckboxTreeView from being checked. But no
> one worked. Anyone know how to do that?
>
> Thanks.
>
Re: How to dis/enable a TreeItem in a TreeView? [message #316918 is a reply to message #316890] Thu, 21 June 2007 14:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Ok, it seem it can not be eassily solved, :-(
I have another question. I tried to catch
the mouse event on an TreeItem, I wrote the
code like following:

children[i].addListener(SWT.SELECTED, new Listener(){
public void handleEvent(Event event) {
System.out.println("Mous event: " + event.type);
}
});

children is defined as TreeItem[]. I tried to
output some simple information to see if the
SELECTED event can be caught. But it turned out
that the event could not be caught. I also tried
lots of other events like mousedown, mouse doubleclick.
No one can be caught if I add the listeners on the
TreeItem. If I add the listeners on the Tree, the
events can be caught but that's not what I want.
Anyone knows why that could happen?
Re: How to dis/enable a TreeItem in a TreeView? [message #316920 is a reply to message #316918] Thu, 21 June 2007 15:04 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

You need to catch them on the tree and then calculate the item using
Tree#getItem(new Point(e.x,e.y)). This is only possible when you use
MouseListeners. All other events won't give you x and y.

Another problem you might have is that you also need to catch keyboard
navigation (e.g. a user is clicking a parent node, afterwards collapses
the tree using ARROW_LEFT and afterwards ARROW_DOWN => and suddenly he's
on an item you don't allow him to access)!

As I already told you you are maybe better of by shifting your whole
code to use CellEditors.

Another possibility is that you allow the user to click the item but
immediately reset the restate.

Tom

Raymond schrieb:
> Ok, it seem it can not be eassily solved, :-(
> I have another question. I tried to catch the mouse event on an
> TreeItem, I wrote the
> code like following:
>
> children[i].addListener(SWT.SELECTED, new Listener(){
> public void handleEvent(Event event) {
> System.out.println("Mous event: " + event.type);
> }
> });
>
> children is defined as TreeItem[]. I tried to output some simple
> information to see if the SELECTED event can be caught. But it turned out
> that the event could not be caught. I also tried
> lots of other events like mousedown, mouse doubleclick.
> No one can be caught if I add the listeners on the
> TreeItem. If I add the listeners on the Tree, the
> events can be caught but that's not what I want. Anyone knows why that
> could happen?
>
Re: How to dis/enable a TreeItem in a TreeView? [message #316921 is a reply to message #316920] Thu, 21 June 2007 15:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Ok, I will try them.
I read the link you gave me in the previous answer thread.
I have a question why JFace does not make the TreeItem can
be simply enabled/disabled? Is that very difficult to
implement?

Thanks.
Re: How to dis/enable a TreeItem in a TreeView? [message #316925 is a reply to message #316921] Thu, 21 June 2007 15:39 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Because SWT-Items for TreeItem and TableItem don't have such a concept
it's a very though thing for JFace to overcome such "limitation" because
when JFace provides it it has to catch all possibilities. We cann't
advertise a feature which is only working half way.

Although we started to over come SWT-Limitations in JFace in 3.3 like
e.g. cell navigation I cann't currently imaging how support for such a
feature from JFace could look like.

Have you ever searched bugzilla whether someone has requested such a
feature once? If not you could file a feature request.

Tom

Raymond schrieb:
> Ok, I will try them. I read the link you gave me in the previous answer
> thread.
> I have a question why JFace does not make the TreeItem can
> be simply enabled/disabled? Is that very difficult to implement?
>
> Thanks.
>
Previous Topic:[Q]How best for my plugin to disable itself.
Next Topic:Are there any articles/examples on creating Compare/Merge tools
Goto Forum:
  


Current Time: Wed Apr 24 20:52:43 GMT 2024

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

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

Back to the top