AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

valueForPathChanged event

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
rob
Guest





PostPosted: Mon May 21, 2007 11:05 pm    Post subject: valueForPathChanged event Reply with quote



Hello all,

In my program I load xml data from file to the DOM, create a custom
model for the tree and display the data in the gui in the form of a
tree. If I want to edit the elements of the tree I have to modify the
valueForPathChanged event in my tree model.
I can't find any description how to do this in the literature.
Everybody seems to omit that part assuming in their examples that the
tree will not be editable.

I will be very grateful for suggestions how to implement the
valueForPathChanged event in my code (which is essentially a little
modified code from the java tutorial) so it is possible to edit the
displayed tree nodes.

My tree model looks like this:

class DomToTreeModelAdapter implements javax.swing.tree.TreeModel
{

private Document document;

public DomToTreeModelAdapter(Document document)
{
this.document=document;
}

public Object getRoot() {
return new AdapterNode(document);
}
public boolean isLeaf(Object aNode) {
AdapterNode node = (AdapterNode) aNode;
if (node.childCount() > 0) return false;
return true;
}
public int getChildCount(Object parent) {
AdapterNode node = (AdapterNode) parent;
return node.childCount();
}
public Object getChild(Object parent, int index) {
AdapterNode node = (AdapterNode) parent;
return node.child(index);
}
public int getIndexOfChild(Object parent, Object child) {
AdapterNode node = (AdapterNode) parent;
return node.index((AdapterNode) child);
}
public void valueForPathChanged(TreePath path, Object newValue) {


//AdapterNode node = (AdapterNode)path.getLastPathComponent();
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)path.getLastPathComponent();
String value = (String)newValue;
if (object != null) {
node.setUserObject(object);
} else {
node.setUserObject(value);
}*/
if (value!=null)
node.setUserObject(value);
}

private Vector listenerList = new Vector();
public void addTreeModelListener(TreeModelListener listener) {
if ( listener != null && ! listenerList.contains( listener ) )
{
listenerList.addElement( listener );
}
}
public void removeTreeModelListener(TreeModelListener listener) {
if ( listener != null ) {
listenerList.removeElement( listener );
}
}

public void fireTreeNodesChanged( TreeModelEvent e ) {
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() ) {
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeNodesChanged( e );
}
}
public void fireTreeNodesInserted( TreeModelEvent e ) {
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() ) {
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeNodesInserted( e );
}
}
public void fireTreeNodesRemoved( TreeModelEvent e ) {
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() ) {
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeNodesRemoved( e );
}
}
public void fireTreeStructureChanged( TreeModelEvent e ) {
Enumeration listeners = listenerList.elements();
while ( listeners.hasMoreElements() ) {
TreeModelListener listener =
(TreeModelListener) listeners.nextElement();
listener.treeStructureChanged( e );
}
}
}

Regards,
Rob
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.