Dynamic Creation of Objects using Tree Control

I am able to Create Dynamic Objets using List control in
flex,but not able to create objects using TreeControl,currently iam
using switch case to do that iam embedding source code please help
me how to do that
<?xml version="1.0" encoding="utf-8"?>
<!--This Application Deals With How to Create Objects
Dynamically -->
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:XML id="treeDP">
<node label="Controls">
<node label="Button"/>
<node label="ComboBox"/>
<node label="ColorPicker"/>
<node label="Hslider"/>
<node label="Vslider"/>
<node label="Checkbox"/>
</node>
</mx:XML>
<mx:Script>
<![CDATA[
import mx.core.UIComponentGlobals;
import mx.containers.HBox;
import mx.controls.*;
import mx.controls.VSlider;
import mx.controls.Button;
import mx.controls.Alert;
import mx.core.UIComponent;
import mx.controls.Image;
import mx.managers.DragManager;
import mx.events.DragEvent;
import mx.controls.Tree;
import mx.core.DragSource
import mx.core.IFlexDisplayObject;
/*This function accepts the item as on when it is dragged
from tree Component */
private function ondragEnter(event:DragEvent) : void
if (event.dragSource.hasFormat("treeItems"))
DragManager.acceptDragDrop(Canvas(event.currentTarget));
DragManager.showFeedback(DragManager.COPY);
return;
else{
DragManager.acceptDragDrop(Canvas(event.currentTarget));
return;
/*This Function creates objects as the items are Dragged
from the TreeComponent
And Creates Objects as and When They Are Dropped on the
Container */
private function ondragDrop(event:DragEvent) : void
if (event.dragSource.hasFormat("treeItems"))
var items:Array =event.dragSource.dataForFormat("treeItems")
as Array;
for (var i:int = items.length - 1; i >= 0; i--)
switch(items
[email protected]())
case "Button":
var b:Button=new Button();
b.x = event.localX;
b.y = event.localY;
b.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
myCanvas.addChild(b);
break;
case "ComboBox":
var cb:ComboBox=new ComboBox();
myCanvas.addChild(cb);
cb.x = event.localX;
cb.y = event.localY;
cb.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
break;
case "ColorPicker":
var cp:ColorPicker=new ColorPicker();
myCanvas.addChild(cp);
cp.x = event.localX;
cp.y = event.localY;
cp.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
break;
case "Vslider":
var vs:VSlider=new VSlider();
myCanvas.addChild(vs);
vs.x = event.localX;
vs.y = event.localY;
vs.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
break;
case "Hslider":
var hs:HSlider=new HSlider();
myCanvas.addChild(hs);
hs.x = event.localX;
hs.y = event.localY;
hs.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
break;
case "Checkbox":
var check:CheckBox=new CheckBox();
myCanvas.addChild(check);
check.x = event.localX;
check.y = event.localY;
check.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
break;
else {
var Component:UIComponent =
event.dragSource.dataForFormat("items") as UIComponent ;
Component.x = event.localX;
Component.y = event.localY;
Component.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
myCanvas.addChild(Component);
/*How to move the Objects within the Container */
public function mouseMoveHandler(event:MouseEvent):void{
var
dragInitiator:UIComponent=UIComponent(event.currentTarget);
var ds:DragSource = new DragSource();
ds.addData(dragInitiator,"items")
DragManager.doDrag(dragInitiator, ds, event);
]]>
</mx:Script>
<mx:Tree dataProvider="{treeDP}" labelField="@label"
dragEnabled="true" width="313" left="0" bottom="-193" top="0"/>
<mx:Canvas id="myCanvas" dragEnter="ondragEnter(event)"
dragDrop="ondragDrop(event)" backgroundColor="#DDDDDD"
borderStyle="solid" left="321" right="-452" top="0"
bottom="-194"/>
</mx:Application>
iwant to optimize the code in the place of switch case
TextText

Assuming your objects are known and what you need are simply
variable names created by the program, try using objects as
associative arrays:
var asArray:Object = new Object();
for (var n:int = 0; n < 10; n++) {
asArray["obj" + n] = new WHAT_EVER();

Similar Messages

  • Flex Using Tree Control in item renderer(Url Navigate)?

    HI All.,
                Iam Using flex 3 using tree control in item renderer to click haschildren label to be navigate url is possible ?.
    Any one help me.....
    Thanks in Advance......

    You can do this by writing the item's tag to the ActiveItemTag property, the column number you're intersted in to the ActiveColNum property and reading the Cell String Property.
    Mike....
    PS: If anybody at NI is listening, that interface really, really, REALLY needs to get rewritten...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
    Attachments:
    tree_properties.vi ‏9 KB

  • How to use Tree control like a Tree in SAP HANA Live Browser?

    Hello SDN!
    I need a Tree control such as following:
    As I understand, there is no such standard control in SAPUI5 control library. Is it possible to use this control? If yes, how I can embed it in my app?
    Regards,
    Lev

    Hi Sandip!
    Thanks for your tip. I've applied this example to my app. Tree is working now, but this is a little problem - on each expand/collapse and click on treeItem the onAfterRendering() method called. It means that the complete rerender of tree executed which looks not good. How I can avoid this?
    Lev

  • Dynamic creating SAPBobsCOM objects using reflection

    Hi All,
    I'm writing a tool (C#) for SBO for exporting object (oItems, oBanks etc.) to XML files. And I have a problem how to dynamically create object by it's string description. I'm trying to create it using System.Reflection, but cant't find right way to create it.
    It must be like that, but it doesn't work:
               Type  sboObject = System.Type.GetType("SAPbobsCOM.Items, Interop.SAPbobsCOM", true, true);
               object ibaseObject = Activator.CreateInstance(sboObject);
    Any ideas?)

    Hi
    I've writen this code for instantiating DI API objects using .NET reflection
            private object getObjectBo(int tipo) //tipo: integer representing the object type
                object o = null;
                try
                    Type tipoComp = kernel.Company.GetType(); //Type SAPbobsCOM.Company
                    MethodInfo info = tipoComp.GetMethod("GetBusinessObject");
                    object[] parametros = new object[1]; //Parameters of GetBusinessObject
                    object tipoObj = Enum.ToObject(typeof(SAPbobsCOM.BoObjectTypes), tipo);
                    parametros[0] = tipoObj;
                    o = info.Invoke(kernel.Company, parametros);  //Calling GetBusinessObject           
                catch (Exception ex)
                    kernel.Application.MessageBox(ex.Message, 0, "", "", "");
                return o;
    The object returned is COM object (not managed code) then we can't use .NET reflection directly for exploring its methods and attributes .. I think we should use C++ and IDispatch interface, but i don't know how do this yet.
    Hope it helps.
    Regards

  • Dynamic creation of object

    Hai
    There is a calss Firm like below
    public class Firm
    public void sayHai()
    System.out.println("Hai");
    There is a main class like below
    public main
    public void getObject(String className,Object firmObject)
    In this method I am passing Object as a parameter.
    I want to accessw sayHai() method of Firm Class by using firmObject
    variable.
    Actually i am trying like below
    Class clsFirm = Class.forName(className);
    Object objFirm = clsFirm.newInstance();
    objFirm.sayHai(); // Here it is showing error. I am not getting
    // How to cast the ObjFirm to actual object.
    // Since I know className only.
    public static void main(String args[])
              Main doMain = new Main();
    Firm doFirm = new doFirm();
              dc.getObject("Firm",doFirm);
    Thnks in advance for clarifying my doubt.

    There are two approaches. Usually the best one is to predefine an interface which your dynamically loaded are required to implement. Then you can cast the dynamically created object to that interface and call it from there.
    public interface DynInterface {
      public void sayHI();
    public class Firm implements DynInterface {
      public void sayHi() {
    Class cls = Class.forName("Firm");
    DynInterface obj = (Dyninterface)cls.newInstance();
    obj.sayHi();If you don't have that kind of control over the specs of the dynamically loaded classes they you need to resort to introspecion. In this can use the getMethod() call of Class to get a java.lang.reflect.Method object and use "invoke" on it:
    Class cls = Class.forName("Firm");
    Method m = cls.getMethod("sayHi", null);
    Object obj = cls.newInstance();
    m.invoke(obj, null);

  • Dynamic creation of objects at runtime

    supposed i want to create a tree structure and i use objects to represent the nodes...but i need the user to specify the number of nodes in the tree...so the user will enter 10 or 13 whatever.So how do we create those nodes dynamically...i know how to add nodes ...umm Example
    Node A=new node('A');
    Node B=new node('B');
    //this creates a new node A of type node(user defined class)
    but how to create it dynamicaaly
    eg
    for(i=1;i<=Totalnodes;i++)
    Node A= new node('A');
    } //well obviously this code is wrong .
    Here is a copy of the main program where nodes are added to the code and not specified by the user
    public class Main {
         public static void main(String[] args)
              //Lets create nodes as given as an example in the article
              Node nA=new Node('A');
              Node nB=new Node('B');
              Node nC=new Node('C');
              Node nD=new Node('D');
              Node nE=new Node('E');
              Node nF=new Node('F');
              //Create the graph, add nodes, create edges between nodes
              Graph g=new Graph();
              g.addNode(nA);
              g.addNode(nB);
              g.addNode(nC);
              g.addNode(nD);
              g.addNode(nE);
              g.addNode(nF);
              g.setRootNode(nA);
              g.connectNode(nA,nB);
              g.connectNode(nA,nC);
              g.connectNode(nA,nD);
              g.connectNode(nB,nE);
              g.connectNode(nB,nF);
              g.connectNode(nC,nF);
    .

    Ugh i so messed up..ok ok im gonna explain clearly now coz i just kinda blurted out stuff before :P
    ok So here is the main program :
    public class Main {
         public static void main(String[] args)
              //Lets create nodes as given as an example in the article
              Node nA=new Node('A');
              Node nB=new Node('B');
              Node nC=new Node('C');
              Node nD=new Node('D');
              Node nE=new Node('E');
              Node nF=new Node('F');
              //Create the graph, add nodes, create edges between nodes
              Graph g=new Graph();
              g.addNode(nA);
              g.addNode(nB);
              g.addNode(nC);
              g.addNode(nD);
              g.addNode(nE);
              g.addNode(nF);
              g.setRootNode(nA);
              g.connectNode(nA,nB);
              g.connectNode(nA,nC);
              g.connectNode(nA,nD);
              g.connectNode(nB,nE);
              g.connectNode(nB,nF);
              g.connectNode(nC,nF);
              //Perform the traversal of the graph
              System.out.println("DFS Traversal of a tree is ------------->");
              g.dfs();
              System.out.println("\nBFS Traversal of a tree is ------------->");
              g.bfs();
    And this is the Graph module:
    import java.util.ArrayList;
    import java.util.LinkedList;
    import java.util.Queue;
    import java.util.Stack;
    public class Graph
         public Node rootNode;
         public ArrayList nodes=new ArrayList();
         public int[][] adjMatrix;//Edges will be represented as adjacency Matrix
         int size;
         public void setRootNode(Node n)
              this.rootNode=n;
         public Node getRootNode()
              return this.rootNode;
         public void addNode(Node n)
              nodes.add(n);
         //This method will be called to make connect two nodes
         public void connectNode(Node start,Node end)
              if(adjMatrix==null)
                   size=nodes.size();
                   adjMatrix=new int[size][size];
              int startIndex=nodes.indexOf(start);
              int endIndex=nodes.indexOf(end);
              adjMatrix[startIndex][endIndex]=1;
              adjMatrix[endIndex][startIndex]=1;
         private Node getUnvisitedChildNode(Node n)
              int index=nodes.indexOf(n);
              int j=0;
              while(j<size)
                   if(adjMatrix[index][j]==1 && ((Node)nodes.get(j)).visited==false)
                        return (Node)nodes.get(j);
                   j++;
              return null;
         //BFS traversal of a tree is performed by the bfs() function
         public void bfs()
              //BFS uses Queue data structure
              Queue q=new LinkedList();
              q.add(this.rootNode);
              printNode(this.rootNode);
              rootNode.visited=true;
              while(!q.isEmpty())
                   Node n=(Node)q.remove();
                   Node child=null;
                   while((child=getUnvisitedChildNode(n))!=null)
                        child.visited=true;
                        printNode(child);
                        q.add(child);
              //Clear visited property of nodes
              clearNodes();
         //DFS traversal of a tree is performed by the dfs() function
         public void dfs()
              //DFS uses Stack data structure
              Stack s=new Stack();
              s.push(this.rootNode);
              rootNode.visited=true;
              printNode(rootNode);
              while(!s.isEmpty())
                   Node n=(Node)s.peek();
                   Node child=getUnvisitedChildNode(n);
                   if(child!=null)
                        child.visited=true;
                        printNode(child);
                        s.push(child);
                   else
                        s.pop();
              //Clear visited property of nodes
              clearNodes();
         //Utility methods for clearing visited property of node
         private void clearNodes()
              int i=0;
              while(i<size)
                   Node n=(Node)nodes.get(i);
                   n.visited=false;
                   i++;
         //Utility methods for printing the node's label
         private void printNode(Node n)
              System.out.print(n.label+" ");
    And this is the node module:
    public class Node
         public char label;
         public boolean visited=false;
         public Node(char l)
              this.label=l;
    So my question is: How do i get the user to specify the number of nodes..i.e take input the number of nodes...add them to a tree....and how do i convert this graph into a tree

  • Comparing dynamic fields of objects using equals and hashCode methods

    To compare the different objects of the same class with their contents like jobTitleId, classificationId, deptId & classificationId was to be done and do some manipulations later using Set and Map. I was able to do that by simply overriding the equals and hashCode methods of Object class and was able to fetch the information (like in the following Map).
        Map<LocationData, List<LocationData>>
    The following is the class I used (its been shown to you so that it can be referred for my problem statement):
    LocationData class
        package com.astreait.bulkloader;
        public class LocationData {    
            String locId, deptId, jobTitleId, classificationId;
            @Override  
            public boolean equals(Object obj) {        
                LocationData ld = (LocationData)obj;       
                return this.deptId.equals(ld.deptId) && this.jobTitleId.equals(ld.jobTitleId) && this.classificationId.equals(ld.classificationId) &&
        this.locId.equals(ld.locId);   
            @Override  
            public int hashCode() {        
                return deptId.hashCode() + jobTitleId.hashCode() + classificationId.hashCode() +locId.hashCode();  
    Problem:
    I'm already known to which all fields of this object I need to make the comparison.
    i.e I'm bound to use the variables named classificationId, deptId, jobTitleId & locId etc.
    Need:
    I need to customize this logic such that the fields Names (classificationId, deptId, jobTitleId & locId etc) can be pulled dynamically along with their values. So, as far as my understanding I made use of 2 classes (TableClass and ColWithData) such that the List of ColWithData is there in TableClass object.
    I'm thinking what if I override the same two methods `equals() & hashCode();`
    such that the same can be achieved.
        TableClass class #1
        class TableClass{
            List<ColWithData> cwdList;
            @Override
            public boolean equals(Object obj) {
                boolean returnVal = false;
                        // I need to have the logic to be defined such that
                        // all of the dynamic fields can be compared
                return returnVal;
            @Override
            public int hashCode() {
                int returnVal = 0;
                        // I need to have the logic to be defined such that
                        // all of the dynamic fields can be found for their individual hashCodes
                return returnVal;
    ColWithData class #2
        class ColWithData{
            String col; // here the jobTitleId, classificationId, deptId, locId or any other more fields info can come.
            String data; // The corresponding data or value for each jobTitleId, classificationId, deptId, locId or any other more fields.
    Please let me know if I'm proceeding in the right direction or I should make some any other approach. If it is ok to use the current approach then what should be performed in the equals and hashCode methods?
    Finally I need to make the map as: (Its not the concern how I will make, but can be considered as my desired result from this logic)
        Map<TableClass, List<TableClass>> finalMap;

    Hello,
    What is the relation with the Oracle Forms tool ?
    Francois

  • Dynamic creation of participants using PAPI WS

    Hi ,
    Can anyone tell me how to create participants in the studio using the PAPI WS ?
    Thanks in advance!!!
    Regards,
    Shiny

    Hi Capgemini,
    You BIRT questions are welcome at http://www.birt-exchange.com. There are forums specifically for BIRT.
    To answer your questions, you can use a scripted data source which allows you to call Java objects to fill the data.
    There are a couple of examples already posted there:
    One uses the Java API's only:
    http://www.birt-exchange.com/modules/wfdownloads/singlefile.php?cid=2&lid=156
    and one uses Javascript inside the report design:
    http://www.birt-exchange.com/modules/wfdownloads/singlefile.php?cid=2&lid=117
    Virgil

  • Dynamic creation of object names

    Dear all,
    I have chose a rather generic title for a rather special problem, since I believe the above is the root. I am trying to create a bunch of JButtons which should have a running number in their names, like: button1, button2, button3, etc. Naturally, I'd like to do this in a loop. But it seems like I can't just concatenate the loop index to the button name like this:
    for(int i = 0; i < x; i++)
          JButton myButton + i = new JButton("Text");
        }How else could I achieve this? Thanks a lot in advance for any hitns!
    Cheers,
    N.

    Sorry for checking back so late...got distracted.
    To clarify further: I want to populate a column in a JTable with the buttons. The table rows contain pairs of words for a simple vocabulary trainer. If the user clicks on the button, the respective row should be deleted. The table data is built in a loop that populates a 2-dimensional object array. So, the buttons need some sort of identifier associated with them, so that I can determine which row should be deleted.
    Cheers,
    N.

  • Flex tree control expanditem dynamically..?

    Hi All.,
               I have using tree control using to display. when i pass the data with folder id dynamically  to expanding particular child node of tree.
        How to extarct tree with dynamic...?
    Below sample coding.....
    <mx:tree id="folderTree" />
    folderid=2618;
         callLater(expandTree, [folderid]);
         private function expandTree(folderid: Object) : void
                    folderTree.expandChildrenOf(folderTree.getChildAt(0), true);
                    folderTree.selectedItem = folderid;
    but not extracting tree.
    anyone help this problem
    With Regards.,
    Lings

    Thanks buddy for the answer.
    Unfortunately the answer came after quite long time of posting the message. Anyway I was able to open a tree on demand using HttpService and due to my new requirement I changed it to RemoteObject.
    I my latest change I am able to populate tree nodes on demand and also the same solution if getting update from server via JMS using Consumer object.
    I kind a like this solution because it took me good amount of effort to find the right solution.
    If any one is intersted the he/she can reply to the post and I can provide code here or may at some location so that it can be easily downloaded.
    The solution is Flex-Grails combination.
    Thanks everybody.

  • Check Box in Tree Control

    I found that the oracle installation is using tree control with check box. I tried to use the same feature in my application. But I found that the tree control in swing and infoswing is not having the feature to add checkbox in the tree control. If anybody knows how to add checkbox in the tree control using the jdeveloper please help me.

    You can see how to do it the next link http://www2.gol.com/users/tame/swing/examples/JTreeExamples2.html
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by S. Arun ([email protected]):
    I found that the oracle installation is using tree control with check box. I tried to use the same feature in my application. But I found that the tree control in swing and infoswing is not having the feature to add checkbox in the tree control. If anybody knows how to add checkbox in the tree control using the jdeveloper please help me.<HR></BLOCKQUOTE>
    null

  • Numeric cell in Tree control ?

    Hi y'all !
    I'd like to have numeric input cells in my TREE CONTROL. I can see the types string, ring, combo box, etc. ... but NUMERIC is not included.
    I'm using CVI 2012.
    Is there an alternative or does anyone know at least why it is not supported ?
    Thanks!

    Hi carolynturnell,
    Indeed cell types included in a tree control are String,Ring, ComboBox, CheckBox, ColorPicker and HorizontalBar.
    Tree controls are used to view a hierarchical list of items.
    Why do you want to display Numeric/use tree control ?
    Valentin
    Certified TestStand Architect
    Certified LabVIEW Developer
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    Travaux Pratiques d'initiation à LabVIEW et à la mesure
    Du 2 au 23 octobre, partout en France

  • Tree Control Drop? Event in LV 8

    Hi,
    I developed one application using LV 7.1 which uses tree control Drop? event.
    using this event I can get and compare source tag and target tag and based on result I can omite the Drag and Drop event.
    But in LV 8 for Drop? event I am not getting Source and Target Tags. Same function how I can implement in LV 8.0?

    Hello,
    There is a lengthy thread on this topic here (including comments from the owner of Drag-and-Drop on the LabVIEW team):
    http://forums.ni.com/ni/board/message?board.id=170&message.id=158683
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Problems handling xml data for tree control.

    Hi,
    I have tried using tree control for displaying my xml data
    but I had a problem that i did not have labels in my xml data. A
    sample xml data is attached. So it displays the whole data at each
    level in the tree. The root label will be the entire the xml data
    and then one level down the remaining xml data and so on...
    How do i solve this issue i,e get the tags names itself as
    labels..
    Thanks in advance....

    An update after some efforts..
    Could get the folders perfectly i.e until the level of
    CPUTime perfectly but could not get the leaf: 32 since i used the
    following to set the label.
    I would like to know if there is a way to find out if a node
    is a leaf or folder and according set the label

  • Flex 4 skin  how to set tree control corner radius..?

    hi .,
         i have using flex4 mx tree control to reduce the corner radius.
    application using tree control code...
    <mx:Tree   contentBackgroundColor="#FFFFFF"  id="folderTree" labelField="documentFolderName" dataProvider="{folderTreeArray}" itemClick="clcikchanged(event)" height="650" borderColor="#FFFFFF">        </mx:Tree>
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/halo";
        @namespace mx1 "library://ns.adobe.com/flex/mx";
         mx|Tree
        border-skin: ClassReference('com.istmanagement.skins.Application.boaderskin');
        </fx:Style>
    borderskin.mxml coding here...
    <?xml version="1.0" encoding="utf-8"?>
    <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:fb="http://ns.adobe.com/flashbuilder/2009" alpha.disabled="0.5">
        <fx:Metadata>
    [HostComponent("spark.components.BorderContainer")]
    </fx:Metadata>
        <s:states>
            <s:State name="normal" />
            <s:State name="disabled" />
        </s:states>
          <s:Rect id="background"  left="0" right="0" top="0" bottom="0" >
            <s:fill>
                <s:SolidColor id="bgFill" color="#FFFFFF"/>
            </s:fill>
        </s:Rect>
       <s:BorderContainer cornerRadius="8" width="255" height="650">
        </s:BorderContainer>
        <s:Group id="contentGroup" left="0" right="0" top="0" bottom="0" minWidth="0" minHeight="0">
            <s:layout>
                <s:BasicLayout/>
            </s:layout>
        </s:Group>
    </s:Skin>
    tree control corner radius is reduced to display., after i have using  <mx:HDividedBox > to drag this to override a tree control...
    how to solve this problem.,
    With Regards.,
    LinFlex-

    Did you every solve this issue?

Maybe you are looking for