cancel
Showing results for 
Search instead for 
Did you mean: 

Interacting with trees

JosefKoenig
Explorer
0 Kudos

Hi!

I recently did some testing with trees in Web Dynpro...

...and encountered some problems.

What I want to do is simulating some kind of context menu in a tree structure

to enable the user to trigger actions like "Detail-view (for a leaf)", "Add new node"

or "Delete current node". Is there a UI element that can be used to do this?

Because I didn't find such a popup (or equivalent element), I tried to simulate

it otherwise: In this second scenario I wanted to use the mouse-click of the

user to select an entry in the tree. The different actions would be triggered by

clicking on additional buttons on the screen (one button per action).

Here I encountered the problem, that the selection in the tree is displayed

only by a (nearly invisible) border around this element. Is there a different

way to modify the appearance of a node in a tree (ie. make the text bold)?    

Moreover I wanted to have icons displayed in the tree. I therefore specified

file://doc.ico as IconSource for my nodes (TreeItemType) with no effect

(except the error-msg: IconSource is not implemented on CSF_WDTreeItemType: LDCN.TreeView.level1). What / where do I have to specify / implement

the icon source?

When specifying the same URL as defaultIconItemSource at root-level

there are at least placeholders (with red cross) showing that there is some

icon which cannot be displayed. In this case there is no error-msg.

(doc.ico is available under mime...).

My system specs are:

Version: Sneak Preview 2.0.0

Build id: 20030515144

I would be pleased if someone could give me some hints... ;o)

Thanx

Thomas Koch

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Thomas,

Your observation is correct: The current implementation of the Tree in Web Dynpro does not support a context menu.

Concerning your idea to simulate a context menu and the problems you encountered: The selected node (the one that was clicked on) should be highlighted in blue and not only by a small border around it. This might be a bug in the Sneak Preview version. Icons are supported, however, like all other resources icons have to be placed into a specific folder. If you switch from the Web Dynpro Explorer view to the Navigator view you find the folder .  

Drag & drop your icons into this folder. As iconSource of TreeNodeType you now simply specify "doc.ico" without any path. This should work.

Please let me know!

Best regards,

Karin

JosefKoenig
Explorer
0 Kudos

Hello Karin,

thanks for the fast response.

The procedure you described for implementing the icons is exactly what I did in first place

Unfortunatelly there are no icons displayed and the error-msg I described in my previous posting.

Meanwhile I found a way to have icons displayed in my tree (by setting the default icons for TreeNodeType / TreeItemType nodes at root level). But if I try to specify the icons at node level it doesn't work...  

Perhaps this problem results (like the highlighting topic) from my Sneak Preview Version.

In the meantime I encountered two more interessting questions:

Is there only one action (event) possible for each TreeNodeType/TreeItemType element in a tree (the one specified for "onAction") or can I also react for example on a mouse-click on the little triangle (expand icon)?

Is there a way to extend the functionallity of the TreeItemType element? It would be great if I had more than one icon for one entry (leaf of the tree) and each of this icons triggering a different action / event.

That would be much more userfriendly than the other approach 🐵

Best regards,

Thomas      

Former Member
0 Kudos

Hello Thomas,

it's very easy to use different icons for different tree nodes and/or leafs. Exactly the same way as you define a Context attribute to display the text of each node and then bind the text-property of the node to this context attribute you may define an attribute "IconName" for example, which you bind to the "iconSource" property of the TreeNodeType/TreeItemType. Something like this in the controller context should work:

TreeContent (Value Node)

  - Text (Value Attribute:string)

  - IconName (Value Attribute:string)

  - RelatedAction (Value Attribute:IWDAction)

As the contents of the IconName attribute changes from entry to entry, the displayed icon will change also (if your Sneak Preview Version works correctly).

On the other hand you can bind only one action to a TreeNodeType or TreeItemType, but you can use this "default" action as a "dispatcher" for a related action, which is also integrated in the context node like the example above shows.

Best regards

Stefan

Former Member
0 Kudos

Hi Stefan,

I have slightly different question. Is there any easy way to get the context element that corresponds to the selected tree node. My problem is that I dont know what node will be selected in the tree in advance and if I use wdContext.getCurrentElement() I am retrieving the Root Element but I want the actually selected element. I have to iterate the context levels from the root below in order to see on which level the selection is done. Actually I've expected that getCurrentElement returns me the currently selected element.

Regards,

Metodi

JosefKoenig
Explorer
0 Kudos

Hi Stefan,

thanks for your answer.

What I did is nearly exactly what you described:

My example is based on the "non-recursive tree example".

My nodes in the Context have both the attributes "text" and "icon" (both of type string).

In "wdDoInit()" I have the following code to fill the tree with content:

ICustomerNode customerNode = wdContext.nodeCustomer();

for (int i = 0; i < 3; i++) {

   ICustomerElement customer = customerNode.createCustomerElement();

   customer.setText("Customer No:" + i);

   customer.setIcon("icon.jpg");

   customerNode.addElement(customer);

   IOrderNode orderNode = customerNode.nodeOrder(); // *??*

   for (int j = 0; j < 3; j++) {

      IOrderElement order = orderNode.createOrderElement();

      ...

   }

}

This results in the error message I described in my first posting (iconsource not implemented).

Note that in the line I marked (*??*) I am not able to use "customer.nodeOrder()" like it is

done in the example because my customer element has no such method. Therefore all order

nodes are attached to the first customer. But I don't think that this is the reason for the

problem with the icons. Maybe I should wait for a newer version to continue testing...

Your suggestion for the actions doesn't solve my problem either :o(. If there were multiple icons

possible for one entry (triggering different actions) I could use one to display the details for

this entry, one to add dynamically a new child node at this position, and so on. To do it this way

it is essential to have more than one "triggering region" per entry...

Nevertheless I would thank you for your answer.

Best regards

Thomas

Former Member
0 Kudos

Hello Thomas,

The problem with the iconSource of TreeNodeType and TreeItemType seems to be a problem with the sneak preview. Concerning reacting on clicking the expand icon: This fires the onLoadChildren Event (defined on TreeNodeType) and allows the application to add(load) children on demand. This is very performance critical if you deal with huge hierarchical structures: Instead of retrieving the complete hierarchy from the backend at once (probably causing performance problems) you only retrieve the hierarchy to a certain level. Data below this level can then be added if the corresponding tree node is expanded. Concerning additional icons: The current implementation does not support several icons that trigger different actions.

Best regards,

Karin

Former Member
0 Kudos

Hi Metodi,

You are right - iterating through the context to find out which node was clicked on is very cumbersome. There is a more elegant way to retrieve this information. Unfortunately, this feature is not available in the sneak preview version of web dynpro but was added in a later version, what you have. The onAction event fired by the TreeNode/Item now has a parameter 'path' that contains the path to the context element that corresponds to the context element that was clicked on.

Best regards, Karin

JosefKoenig
Explorer
0 Kudos

Hello Karin,

you wrote in your last answer:

> Concerning reacting on clicking the expand icon: This fires the onLoadChildren Event

> (defined on TreeNodeType) and allows the application to add(load) children on demand.

But I have no clue where to find this event or how to react on it...

In my sources the Interface IWDTreeNodeType has only a setter and getter for one event

defined and this event is "onAction" inherited from Interface IWDAbstractTreeNodeType.

The documentation at http://help.sap.com is identical for these items and in the layout tab

of my test view TreeNodeType nodes also have on the event "onAction"...

Are you refering to another TreeNodeType class, or is this just one more bug in my version?

Best regards,

Thomas

Former Member
0 Kudos

Hi Thomas,

i think this is the result of a mismatch in the versions the posters are using. You have to distinguish between the Sneak preview edition, the ramp up version and the "SAP internal" beta versions, which, in the latter case, seem to provide many features not currently available to the people in the "outer world"

Best regards

Stefan

Former Member
0 Kudos

Hi All,

We are aiming another Sneak Preview of the SAP Web AS (including SAP NetWeaver Developers Studio) for end of January/beginning of February 2004.Please stay tuned on SDN. All will have the same features and functions thenceforward.

Best regards, Karin

JosefKoenig
Explorer
0 Kudos

Hi Karin,

now that I have a newer Version of the Netweaver Developer Studio (build 200306250218)

most of the problems I formerly had are gone g.

But there is still one topic left...

Each entry in a tree has two "triggering areas": By clicking on the little triangle

on the left side of the entry you can expand/collapse it. When clicking on the

description of the entry there is an eventhandler called, where I can place my

custom code. But unfortunatelly I found no way how to expand the entry in

this custom code...

In my scenario I use the click on one entry to add new child nodes at runtime.

Afterwards you have to click on the triangle manually to open the entry and see

the new child items, what is quite not userfriendly. That's why I need a way to

expand an entry by code. An other approach would be some kind of

"auto-expand" flag that expands/collapses entries automatically when clicked

on the TEXT of an entry. But a function would be more flexible...  

Is there some way of achieving this with my version?

If no, is it planned for upcomming releases?

Best regards,

Thomas Koch

Former Member
0 Kudos

Hi Thomas,

Yes - there is possibility to control the expanded state of a tree node: The TreeNodeType UIElement has an attribute 'expanded' that can be bound against a boolean attribute within the context. To control the expanded state of each node within the tree, just create an attribute of type boolean on the context node the TreeNodeType is bound against. Within your your custom code, you can then modify the attribute within your context in order to modify the expand state of your node.

However: According to your description you want to implement something we call "Load on Demand", meaning that you add children during runtime. But this is usually done as follows: Instead of using the onAction you use the onLoadChildren Event that is also defined on the TreeNodeType and that is triggered when the node is expanded. If you place your code that adds the child elements within the onLoadChildren event handler you don't have to deal with the expanded state since the node is already expanded.

Hope that helps.

Best regards, Karin

JosefKoenig
Explorer
0 Kudos

Hi Karin,

the solutions you describe would fit perfectly into my scenario...

...there is only one little problem: I can't implement them ;-(

Seems to be one more time a version problem.

To verify this I would give you some more info:

At the end of December 2003 we got a package containing

the "SAP J2EE Engine 6.30 (Add-In)". I used the included

CD containing "SAP WEB AS 6.30" and "Java Development

Environment" to install to NetWeaver Developer Studio and

the SAPDB locally on my maschine. As I mentioned above

the Netweaver build is: 200306250218. If you need some

more information, please feel free to contact me by email

(thomas.koch@ixos.de).

With this version most of the problems I formerly had were

gone, but my class TreeNodeType still does not contain an

attribute named "expand" nor an action "onLoadChildren".

Do we both speak of the class situated in package

com.sap.tc.webdynpro.clientserver.uielib.standard.impl?

Because TreeNodeType extends AbstractTreeNodeType

I also searched this class (without success).

What can I do to get newer sources? Install other components

from the delivered package? Download newer jar-files?

Thanks for your help...

Best regards, Thomas

Former Member
0 Kudos

Hi Thomas,

I am afraid the attributs you mention are not available within that version. Appr. mid February we will offer another version based on 6.40. I know, still 4 weeks left, but this make the last issues go as well. I will inform you via e-mail as soon as the new stuff is available. Would that be okay for you?

Best regards, Karin