|
Re: Modify the node in a TreeField [message #1233649 is a reply to message #1232668] |
Mon, 20 January 2014 02:30   |
Eclipse User |
|
|
|
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 #1234592 is a reply to message #1234286] |
Wed, 22 January 2014 05:23   |
Eclipse User |
|
|
|
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 246 times)
|
|
|
|
Powered by
FUDForum. Page generated in 0.04443 seconds