Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Modify the node in a TreeField(Manage add, delete and modify operation in a TreeField)
icon3.gif  Modify the node in a TreeField [message #1232668] Fri, 17 January 2014 13:08 Go to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
Hi all,
I have two needs to be implemented:


  1. when a node is selected, highlight a row in a table
  2. 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 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
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 Go to previous messageGo to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
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 #1233729 is a reply to message #1233727] Mon, 20 January 2014 10:54 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi Marco,

glad you got it working. Smile

One minor note: It should work without the
super.treeChanged(e)

since the super implementation is empty.

Best regards,
Matthias
Re: Modify the node in a TreeField [message #1234139 is a reply to message #1233729] Tue, 21 January 2014 10:22 Go to previous messageGo to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
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 #1234279 is a reply to message #1234139] Tue, 21 January 2014 15:55 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi marco,

unfortunately Scout does not allow inline editing of tree nodes yet. The table on the other hand can do inline editing.

If you think this would be a nice feature, feel free to open a bug and classify it as enhancement.

Back to your problem:
I would do the following:
1) Create a new form with a textfield and OK, Cancel button - e.g. NodeEditForm
2) If you have a doubleclick event on a tree node, open your NodeEditForm and put the node's text into the textfield
3) Now the user can change the value of the textfield and close the dialog if finished
4) Get the new text and update the node's text accordingly

If you need help implementing this feature or if it does not meet your requirements, I will be glad to help.

Best regards,
Matthias
Re: Modify the node in a TreeField [message #1234286 is a reply to message #1234279] Tue, 21 January 2014 16:07 Go to previous messageGo to next message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
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 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
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 217 times)
Re: Modify the node in a TreeField [message #1234666 is a reply to message #1234592] Wed, 22 January 2014 14:17 Go to previous message
marco giudici is currently offline marco giudiciFriend
Messages: 204
Registered: February 2013
Location: Italy
Senior Member
Hi Matthias,
thank you very much for your suggestion, I have adapted your code to my situation and it works to perfection.
Previous Topic:REST service
Next Topic:Scout Preferences Implementation
Goto Forum:
  


Current Time: Tue Mar 19 09:50:48 GMT 2024

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

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

Back to the top