[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: pb building TreeView
|
You were right, now I size the array with getLength() and tree.setInput()
works perfectly. It seems to build a tree in memory and then expand the
tree in the view, BUT without the root element.
What's the trick to display it?
anthony
Knut Radloff wrote:
> I just noticed that you initialize your children array (elnts) to a fixed
size. The array you return must only have enough slots for
> all the children and no extra null slots. That's probably what's causing the
exception.
> You need to size it to getChildNodes().getLength(). If you have no children
an empty array will be returned.
> Knut
> "anthony saucet" <anthony.saucet@xxxxxxxxxxx> wrote in message
news:b8bjer$6na$1@xxxxxxxxxxxxxxxx
> > getChildNodes() is not null BUT getChildNodes().getLength() = 0 !!!
> > I've printed out what happens in class contentProvider:
> >
> > getChildNodes: !null
> > j: 0 /* getChildNodes().getLength() */
> > contentPovider getChildren end /* end of method getChildren() */
> > hasChild /* call method hasChild */
> > contentPovider getChildren /* calls method getChildren() */
> >
> > and when tries j = getChildNodes().getLength(), stops here and after lot
> > of things I didn't catch, exception.
> > anthony
> >
> >
> > Knut Radloff wrote:
> >
> > > Does getChildNodes return null when there are no more children? You can
set
> > an exception breakpoint in the debugger and find
> > > out.where the exception is occurring.
> >
> > > Knut
> >
> > > PS: Please continue the thread on eclipse.platform, eclipse.tools should
no
> > longer be used and will be made read-only soon.
> >
> > > "anthony saucet" <anthony.saucet@xxxxxxxxxxx> wrote in message
> > news:b8bbcv$u1r$1@xxxxxxxxxxxxxxxx
> > > > I'm trying to build a TreeView in my perspective to have a look on a
DOM
> > > > tree built in memory.
> > > > I've implemented the TreeView with new TreeViewer, called
> > > > setContentProvider() and setLabelProvider(). setInput() gets the
> > > > rootElement of my DOM tree. Then in class contentProvider, the tree is
> > > > being built by getChildren(), and everything seems ok.
> > > > here's the code to get the children:
> > > >
> > > > public Object[] getChildren(Object element) {
> > > > Object elnts[]=new Object[20];
> > > > int i = 0;
> > > > int j=((Element)element).getChildNodes().getLength();
> > > >
> > > > for(Node child = ((Element)element).getFirstChild(); i<j;
> > > > ((Element)element).getNextSibling()){
> > > > elnts[i]=((Element)element).getChildNodes().item(i);
> > > > i++;
> > > > }
> > > > return elnts;
> > > > }
> > > >
> > > > I don't really know what happens BUT when it arrives at the end, when
no
> > > > more child or items, it tries to continue and to create the tree and
the
> > > > following message appears:
> > > > "Unable to create part: Tree" from
> > > > eclipse.core.internal.runtime.InternalPlatform
> > > > and the exception: "nullPointerException".
> > > >
> > > > Does anybody have an idea of what I need to do, or what I missed ?
> > > > many thx
> > > >
> >
> >
> >
> >
> >