Modify the node in a TreeField [message #1232668] |
Fri, 17 January 2014 13:08 |
|
Hi all,
I have two needs to be implemented:
- when a node is selected, highlight a row in a table
- I have the need to manage the operations of addition, deletion and modification of a node in a TreeField.
To do this, I thought to add in the initialization phase of the field, a listener on each change of the tree; but when I select one node, the listener isn't invoked.
This is the source code that I add:
@Override
protected void execInitField() throws ProcessingException {
//Listener on tree changed
this.getTree().addTreeListener(new TreeAdapter() {
@Override
public void treeChanged(TreeEvent e) {
//My logic
......
}
});
}
I mistaken the logic or there is some error in the code?
Thanks in advance for any help and suggestion
|
|
|
Re: Modify the node in a TreeField [message #1233649 is a reply to message #1232668] |
Mon, 20 January 2014 07:30 |
Matthias Nick Messages: 197 Registered: August 2013 |
Senior Member |
|
|
Hi Marco,
hm... that's strange. I took our demo widget app (http://wiki.eclipse.org/Scout/Demo#Widgets) and added a listener to the tree as well:
@Order(10.0)
public class TreeField extends AbstractTreeField {
@Override
protected int getConfiguredGridH() {
return 5;
}
@Override
protected String getConfiguredLabel() {
return TEXTS.get("TreeField");
}
@Override
protected void execInitField() throws ProcessingException {
Tree exampleTree = new Tree();
AbstractTreeNode node1 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 1");
}
};
AbstractTreeNode node2 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 2");
}
};
AbstractTreeNode node11 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 1.1");
}
};
AbstractTreeNode node12 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 1.2");
}
};
AbstractTreeNode node13 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 1.3");
}
};
AbstractTreeNode node21 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 2.1");
}
};
AbstractTreeNode node211 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 2.1.1");
}
};
AbstractTreeNode node2111 = new AbstractTreeNode() {
@Override
protected void execDecorateCell(Cell cell) {
cell.setText("Node 2.1.1.1");
}
};
exampleTree.addChildNode(exampleTree.getRootNode(), node1);
exampleTree.addChildNode(exampleTree.getRootNode(), node2);
exampleTree.addChildNode(node1, node11);
exampleTree.addChildNode(node1, node12);
exampleTree.addChildNode(node1, node13);
exampleTree.addChildNode(node2, node21);
exampleTree.addChildNode(node21, node211);
exampleTree.addChildNode(node211, node2111);
setTree(exampleTree, false);
getTree().addTreeListener(new TreeAdapter() {
@Override
public void treeChanged(TreeEvent e) {
super.treeChanged(e);
if (e.getType() == TreeEvent.TYPE_NODE_CLICK) {
MessageBox.showOkMessage("", "", "User clicked on " + e.getNode().getCell().getText());
}
}
});
}
@Order(10.0)
public class Tree extends AbstractTree {
}
}
Whenever I click on a node of the tree, the MessageBox will be opened.
Maybe you can post the complete code of your form. I will be happy to review it.
Best regards,
Matthias
|
|
|
Re: Modify the node in a TreeField [message #1233727 is a reply to message #1233649] |
Mon, 20 January 2014 10:49 |
|
Hi Matthias,
I check your code and compare it with mine.
The first difference is that I popolate the tree during the execution of ExecLoad method of Handler; the second one is that on the treeChanged method of the listener, I don't use the "super.treeChanged(e)".
Now I moved the popolation of the tree in the init field method and add the "super.treeChanged(e)", and now works correctly.
Thanks for your help
[Updated on: Mon, 20 January 2014 10:50] Report message to a moderator
|
|
|
|
Re: Modify the node in a TreeField [message #1234139 is a reply to message #1233729] |
Tue, 21 January 2014 10:22 |
|
Hi,
always linked to the management of events on TreeBox, I wish that on double click the user could edit the text of the node. Is it possibile?
I have already managed to capture correctly the event of double click and identify on which node was performed; but I can not get to edit the text.
Some suggestions?
Thanks a lot for any help
|
|
|
|
Re: Modify the node in a TreeField [message #1234286 is a reply to message #1234279] |
Tue, 21 January 2014 16:07 |
|
Hi Matthias,
thank you for your suggestion. I think to follow the way with the table and use textfield logic as alternative way.
I want to add a table and load it in the same time of tree and open the edit mode on the table.
I have a question about the table for this type of management: is it possible insert a new row in a specific position? For example before or after the selected row?
If yes, how can proceed?
Thanks in advance for your suggestions
|
|
|
Re: Modify the node in a TreeField [message #1234592 is a reply to message #1234286] |
Wed, 22 January 2014 10:23 |
Matthias Nick Messages: 197 Registered: August 2013 |
Senior Member |
|
|
Hi marco,
sure this is possible. However the API does not allow you to do this in 1 step, because by default the new row is always added at the end of the table.
The key method is the following, which allows to move a row in table
getTable().moveRow(int sourceIndex, int targetIndex)
Here is the idea:
1) Add a context menu to the table
2) When the user makes a rightclick on one of the rows, insert a new row
3) We know what element was selected in the table and therefore we can move the new row (at the end of the table) to this position
Here is a code snippet I just created (the MyTableMenu is inside the Table class):
@Order(10.0)
public class MyTableMenu extends AbstractMenu {
@Override
protected boolean getConfiguredEmptySpaceAction() {
return true;
}
@Override
protected String getConfiguredText() {
return "New Line";
}
@Override
protected void execAction() throws ProcessingException {
ITableRow newRow = getEditableTableField().getTable().addRowByArray(new Object[]{getEditableTableField().getTable().getCompanyNrColumn().getValues().length + 1, "New Company", ""});
ITableRow selectedRow = getEditableTableField().getTable().getSelectedRow(); //this is the row where we made the rightclick
if (selectedRow != null) { //okay, insert after selected row
int selectedRowIndex = selectedRow.getRowIndex();
int newRowsindex = newRow.getRowIndex();
if (newRowsindex < getEditableTableField().getTable().getRowCount()) {
getEditableTableField().getTable().moveRow(newRowsindex, selectedRowIndex + 1); //move to the next position after the selected row
}
}
}
}
Hope this helps. If you have any further questions, let us know. We are happy to help you!
Best regards,
Matthias
-
Attachment: table.png
(Size: 46.47KB, Downloaded 232 times)
|
|
|
|
Powered by
FUDForum. Page generated in 0.04502 seconds