Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Displaying Select Nodes from DOM Model
Displaying Select Nodes from DOM Model [message #205443] Thu, 06 December 2007 20:01 Go to next message
Eclipse User
Originally posted by: italdesign99.hotmail.com

I am working on an XML Forms Editor and have one issue with displaying
specific nodes in the content outline view.

The content provider for my TreeViewer is the JFaceNodeContentProvider(ie.
org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeCont entProvider)

I tried modifying my label provider so it only provides an image/text for
certain nodes in the DOM model that I want to be displayed in the content
outline, however the problem with this is that the nodes that aren't
displayed still have the plus/minus sign beside them so you still have to
expand the tree with blank labels until you get to the nodes that actually
have an image/text(ie. these are the nodes you want displayed). It seems
that modifying the label provider will not do the trick for displaying
only the nodes that I desire in the TreeViewer.

Can someone help me out here? Here is the code for the content provider:


public class JFaceNodeContentProvider implements ITreeContentProvider {
private TreeContentHelper treeContentHelper = new TreeContentHelper();

public JFaceNodeContentProvider() {
super();
}

/**
* The visual part that is using this content provider is about to be
* disposed. Deallocate all allocated SWT resources.
*/
public void dispose() {
}

/**
* Returns the JFace adapter for the specified object.
*
* @param adaptable
* java.lang.Object The object to get the adapter for
*/
protected IJFaceNodeAdapter getAdapter(Object adaptable) {
if (adaptable instanceof INodeNotifier) {
INodeAdapter adapter = ((INodeNotifier)
adaptable).getAdapterFor(IJFaceNodeAdapter.class);
if (adapter instanceof IJFaceNodeAdapter) {
return (IJFaceNodeAdapter) adapter;
}
}
return null;
}

public Object[] getChildren(Object object) {
IJFaceNodeAdapter adapter = getAdapter(object);

if (adapter != null) {
return treeContentHelper.getChildren(object);
//return adapter.getChildren(object);
}

return new Object[0];
}

public Object[] getElements(Object object) {
// The root is usually an instance of an XMLStructuredModel in
// which case we want to extract the document.
Object topNode = object;
if (object instanceof IDOMModel) {
topNode = ((IDOMModel) object).getDocument();
}

IJFaceNodeAdapter adapter = getAdapter(topNode);

if (adapter != null) {
return getChildren(topNode);
//return adapter.getElements(topNode);
}

return new Object[0];
}

public Object getParent(Object object) {
IJFaceNodeAdapter adapter = getAdapter(object);

if (adapter != null) {
Object result = null;
if (object instanceof Node) {
Node node = (Node) object;
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
result = ((Attr) node).getOwnerElement();
}
else {
result = node.getParentNode();
}
}
return result;

//return adapter.getParent(object);
}

return null;
}

public boolean hasChildren(Object object) {
IJFaceNodeAdapter adapter = getAdapter(object);

if (adapter != null) {
return getChildren(object).length > 0;

//return adapter.hasChildren(object);
}

return false;
}

public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{
if ((oldInput != null) && (oldInput instanceof IStructuredModel)) {
IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory)
((IStructuredModel)
oldInput).getFactoryRegistry().getFactoryFor(IJFaceNodeAdapt er.class);
if (factory != null) {
factory.removeListener(viewer);
}
}
if ((newInput != null) && (newInput instanceof IStructuredModel)) {
IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory)
((IStructuredModel)
newInput).getFactoryRegistry().getFactoryFor(IJFaceNodeAdapt er.class);
if (factory != null) {
factory.addListener(viewer);
}
}
}
}
Re: Displaying Select Nodes from DOM Model [message #205550 is a reply to message #205443] Mon, 10 December 2007 15:21 Go to previous message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2272
Registered: July 2009
Senior Member
Muneer wrote:
> I am working on an XML Forms Editor and have one issue with displaying
> specific nodes in the content outline view.
>
> The content provider for my TreeViewer is the
> JFaceNodeContentProvider(ie.
> org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeCont entProvider)
>
> I tried modifying my label provider so it only provides an image/text
> for certain nodes in the DOM model that I want to be displayed in the
> content outline, however the problem with this is that the nodes that
> aren't displayed still have the plus/minus sign beside them so you still
> have to expand the tree with blank labels until you get to the nodes
> that actually have an image/text(ie. these are the nodes you want
> displayed). It seems that modifying the label provider will not do the
> trick for displaying only the nodes that I desire in the TreeViewer.

As with any tree viewer, your content provider has to provide the
list of children you want seen in the tree, only those children, and
with correct parenting information in terms of how it should be in
the viewer. The content provider controls what's shown in the tree,
the label provider only controls *how* it's shown.

---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Previous Topic:text editor and icon (plus/ minus)
Next Topic:WTP Architecture Group - user feedback on proposed expanded downloads
Goto Forum:
  


Current Time: Fri Sep 19 14:04:53 GMT 2014

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

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