NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
nsrivas
Joined: 06 Oct 2011 Posts: 31 Location: Lausanne, Swiz
|
Posted: Thu Oct 06, 2011 2:29 pm Post subject: how to update view to move nodes in BeanTreeView,new user, Kindly help. |
|
|
Hi ,
I am new to netbeans.I am trying to write a moveNodeAction, when i run the project, the node is added to the targeted internal node, but not deleted from its parent node. ....so how to update the UI, .....i read in forums tht to update beantreeview, i need to update/refresh the list of children generated in the chidrenFactory class, i am doing tht but i think im somewhere wrong with the adding of listeners.......
Kindly help.
My action class is below:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alifea.gui.actions;
import graph.basic.Hierarchy;
import graph.basic.Node;
import graph.basic.Edge;
import graph.basic.NetBeanNode;
import graph.utils.NotParentException;
import java.awt.event.ActionEvent;
import java.util.TreeSet;
import javax.swing.AbstractAction;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.util.actions.Presenter;
public final class HierarchyDataMoveNodeAction extends AbstractAction implements Presenter.Popup {
private NetBeanNode n;
private static final String PROP_NODE = "node";
public HierarchyDataMoveNodeAction(NetBeanNode n) {
this.n = n;
}
@Override
public JMenuItem getPopupPresenter() {
JMenu result = new JMenu();
if (n.getNode().isLeaf()) {
result.setText(NbBundle.getMessage(HierarchyDataMoveNodeAction.class, "CTL_HierarchyDataMoveNodeAction"));
Hierarchy h = (Hierarchy) n.getNode().getParent();
TreeSet<Node> nodes = h.getNodeSet();
for (Node n2 : nodes) {
if (!n2.isLeaf()) {
String label = n2.getId() + "";
// String label =n2.getLabel()==null?n2.getId()+"": "label"+n2.getLabel();
JMenuItem item = new JMenuItem();
item.setText(label);
item.putClientProperty(PROP_NODE, n2);
if (n2.equals(n.getNode().getParent())) {
item.setEnabled(false);
}
result.add(item);
item.addActionListener(this);
}
}
}
else
result.setText(NbBundle.getMessage(HierarchyDataMoveNodeAction.class, "CTL_HierarchyDataEditAction"));
return result;
}
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem item = (JMenuItem) e.getSource();
Node node = (Node) item.getClientProperty(PROP_NODE);
Edge edge = n.getNode().getCommonEdge((Node) n.getNode().getParentNodes().last());
n.getNode().getParent().deleteEdge(edge); try {
n.getNode().getParent().newEdge(node, n.getNode());
} catch (NotParentException ex) {
Exceptions.printStackTrace(ex);
}
}
}
and the childrenFactory class is:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alifea.gui.editor.hierarchy;
import graph.basic.NetBeanNode;
import graph.basic.Node;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.nodes.ChildFactory;
import org.openide.util.WeakListeners;
/**
*
* @author nsrivas
*/
public class HierarchyDataEditorChildFactory extends ChildFactory<NetBeanNode> implements ChangeListener {
private TreeSet<Node> children;
public HierarchyDataEditorChildFactory(TreeSet<Node> children) {
this.children = children;
for(Node n : children){
NetBeanNode nbn=new NetBeanNode(n);
nbn.addChangeListener(WeakListeners.change(this, nbn));
}
}
@Override
protected boolean createKeys(List<NetBeanNode> list) {
for (Node n : children) {
NetBeanNode nbn = new NetBeanNode(n);
list.add(nbn);
}
return true;
}
@Override
protected org.openide.nodes.Node[] createNodesForKey(NetBeanNode n2) {
ArrayList<org.openide.nodes.Node> n = new ArrayList<org.openide.nodes.Node>();
if (n2.getNode().isLeaf()) {
n.add(new HierarchyDataEditorLeafNode(n2));
} else {
n.add(new HierarchyDataEditorInternalNode(n2));
}
return n.toArray(new org.openide.nodes.Node[n.size()]);
}
public void refreshList(List<NetBeanNode> list){
createKeys(list);
}
@Override
public void stateChanged(ChangeEvent ce) {
List<NetBeanNode> list = null;
for (Node n : children) {
if (ce.getSource().equals(n)) {
list.addAll((TreeSet<NetBeanNode>) ce.getSource());
}
}
createKeys(list);
}
}
Eagarly waiting for reply.
Thanks. |
|
| Back to top |
|
 |
|
|
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 You can attach files in this forum You can download files in this forum
|
|