Bette way to referenced tree model nodes from UI to perform actions on them

A singleton facade is built.
Its init() method loads several "tree model configs", each of them referenced by a name.
This singleton creates a Project instance for a given "tree model config" calling the facade method -> createProject(String pjrName, String modelConfigName)
When the Project is built a new Model instance is set ( remember the model instance is a tree holding nodes )
The new Project instance built is added to a List that the facade has and then it's returned to the UI part that called ->createProject(prjName,modelconfigName)
Given the Project instance the UI has to build a JTree representation of the model that the project references and the UI will have button actions that should call methods of the Nodes of the model referenced by the Project.
Doing it this way the UI will be able to reference objects directly without going through the facade.
Maybe I should return to the UI something like a ProjectKey instance instead of letting have the UI the Project instance ?
It should be better if I process the possible node actions behind the Facade and not the UI, but how can I do it ?
Having a ProjectKey in my UI I could ask the facade a model tree representation but not having the real nodes, otherwise having some NodeKey instances ?

Sounds like you want to represent a tree structure, without a reference to the real tree.
I'll take it further: maybe you don't want the UI to know there's a real tree data-structure with nodes and pointers to children, because maybe you build the tree on the fly from a database.
So use the Builder pattern instead of committing to a specific data structure.
Google results for Builder pattern: http://www.google.com/search?hl=en&q=builder+pattern&btnG=Google+Search
Your UI should know how to construct nodes and children graphically, when told. This means it should have methods like addNode, but related to the domain: addSubProject maybe.
A Project object is the Director, knowing which part goes where, but it doesn't know the real end result (a JPanel or HTML). So it has a method buildProject(Builder e) or exportProject(Exporter e), where all logic of assembling the parts is.
When you have that, write a class JTreeProjectExporter implements Exporter.
Hope this helps.

Similar Messages

  • How to create a new DOM tree with nodes from another DOM tree?

    Hello,
    I would like to create a DOM tree by using nodes from an existing DOM. How can I do that? I tried with appendChild and it gaves me as error: "WRONG_DOCUMENT_ERR".
    Thx!

    The xml that should be parsed is something like that:
    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns="http://www.nebi.biz/schemas/bd/nebienvelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" BusinessDocumentVersion="7.0" xsi:schemaLocation="http://www.nebi.biz/schemas/bd/nebienvelope NeBiEnvelope_L_0_3.xsd">
        <Header>
            <To>
                <OrganisationId>OrganisationId0</OrganisationId>
                <DestinationType>DestinationType0</DestinationType>
                <Destination>Destination0</Destination>
            </To>
            <From>
                <OrganisationId>OrganisationId1</OrganisationId>
                <DestinationType>DestinationType1</DestinationType>
                <Destination>Destination1</Destination>
            </From>
            <Dialog>Dialog0</Dialog>
            <DialogId>DialogId0</DialogId>
            <MessageType>MessageType0</MessageType>
            <MessageId>MessageId0</MessageId>
            <Reference Role="buyer" Type="BusinessAgreement">Reference0</Reference>
            <SequenceId>SequenceId0</SequenceId>
            <Checksum Type="MD5">Checksum0</Checksum>
        </Header>
        <Body>
            <Order xmlns="http://www.nebi.biz/schemas/bd/order" BusinessDocumentVersion="7.0" OrderType="request" xsi:schemaLocation="http://www.nebi.biz/schemas/bd/order Order_L_0_96.xsd">
                <OrderId Role="buyer"/>
                <ProductLine Number="1">
                    <ProductUseCaseDetails Id="WICreation">
                        <wiCreation xmlns="http://mydomain.com/GRIPP/workitem">
                            <wiCreationHeader>
                                <userId>wmadm</userId>
                                <taskModelName>DNS02_CreateMasterZone</taskModelName>
                            </wiCreationHeader>
                            <wiCreationBody>
                                <DNS02CreationBody>
                                    <GlobalSection xmlns="http://mydomain.com/GRIPP/dns02">
                                        <Outcome>1</Outcome>
                                    </GlobalSection>
                                    <SpecificSection xmlns="http://mydomain.com/GRIPP/dns02">
                                        <Zonename>0.0</Zonename>
                                        <RRLocation>Domain</RRLocation>
                                        <RemoteSlaves type="multiline">
                                            <RemoteSlaveFQDN>test.com</RemoteSlaveFQDN>
                                            <RemoteSlaveIP>123.234.234.123</RemoteSlaveIP>
                                            <RemoteSlaveFQDN>test.net</RemoteSlaveFQDN>
                                            <RemoteSlaveIP>123.123.123.123</RemoteSlaveIP>
                                        </RemoteSlaves>
                                    </SpecificSection>
                                </DNS02CreationBody>
                            </wiCreationBody>
                        </wiCreation>
                    </ProductUseCaseDetails>
                </ProductLine>
             </Order>
        </Body>
        <Trace>
            <CheckPoint>
                <SystemName>SystemName0</SystemName>
                <SystemDateTime>2006-05-04T18:13:51.0Z</SystemDateTime>
            </CheckPoint>
        </Trace>
    </root>This is the output of the Document after parsing and augmentation with the Xerces parser.

  • Can't add new element to model node from web service

    Hi Folks,
    we are using the old WebService (not adaptive one) for calling a service on XI. We are reusing the same service for loading the data and also sending them back to the backend to modify, delete or add new elements. Request and response tree structure consist basically of the same structure.
    Now everything works fine so far except adding a new element to the model tree.
    So what are we doing:
    After calling the service for reading (and invalidate on the response), we copy the received data from response node into the request node. All the view forms are bound to the model elements in the request.
    Modifying single attributes worked just fine (from dialog and programatically). A new element we add to the model tree shows up in the dialog and seems to work equally fine, but when we trigger the service call to send the collected data, every change to the model data is send except the new added element. It just won't be send.
    What's the problem here? Seems to me this must be somehow related to the supplying relation role maybe.
    What code do you need to look at and how do I mark code in the new forum editor so it gets displayed properly formatted?
    Thanks,
      ok

    Hi,
    Can you tell me which code are you using currently for transferrring the data? It might help me to figure out what your problem is.

  • Is there any way to take backed up files from an old OS and get them onto a new phone?  They are backed up as txt files.

    I have a six year old lap top with an old OS and itunes 10.  I backed up my i phone 4 on it.  I got an I phone 5 and the version of Itunes compatible is not supported by the laptop.  I installed itunes on a different computer and when trying to sync the iphone 4 to the desktop, updated the iphone 4 software.  Now my iphone 4 is no longer compatible with my laptop.  I am interested in getting my contacts and photos from my old laptop to either iphone at this point.  I have the backed up files but they are txt files in the Mobile Sync Back ups.  Any suggestions would be appreciated!

    Generally when moving from one phone to another, individuals will make a backup of the one device and then restore to the second device. However, it seems you are no longer using the computer you made the backup on, so that can be a problem. There is no way for you to take information out of the backup and insert it in the iPhone. It is an all or none proposition. But, just moving the backup folder from one computer to another doesn't work either.
    Did you sync the contacts to a supported application on the computer? Also, if you are referring to the photos in the camera roll, you can import them to the computer by connecting the phone to the computer. You do not need iTunes to do that. Just plug in and let the computer photo import utility take the pictures and put them on the computer. Then you would sync the photos back to the photo library on the new phone,
    Contacts you can look at a 3rd party app that might help. MCBackup is in the app store and converts your contacts to a file you can email to yourself and then click on it and open it. Suggest syncing contacts/calendar to a supported application on the computer, or to iCloud so you can recover a lot easier.

  • Looking for a better way to determine string variable from multiple options

    Hi,
    I trying to figure out a better way to determine a string variable from multiple options.
    Say i have five pictures each with a different filename: img1 - img5...these file names could be named anything really but for this example i will keep them as img1, img2, img3, img4 and img5.
    I want to display a messagebox with the string depending on what a certain variable is.
    So for example, we have the number X, if X = 1 then i want the messagebox to show "img1" as the message
    Essentially the way I have been doing it so far is:
    Private Sub WhichImage()
    Dim ImageName As String = ""
    Dim i as integer
    If i = 0 Then
    ImageName = "img1"
    End If
    If i = 1 Then
    ImageName = "img2"
    End If
    If i = 2 Then
    ImageName = "img3"
    End If
    If i = 3 Then
    ImageName = "img4"
    End If
    If i = 4 Then
    ImageName = "img5"
    End If
    MessageBox.show(imagename, "Name of image", MsgBox.Style.OkOnly, MsgBoxResult.Ok)
    end
    Up until now, this has been fine, but what if I have 50 images, do I have to do this for all 50 images? or is there an easier way like putting the image names into a text file and have it read from the file depending on what the variable i equals? If so,
    how do I go about this? Does each image name go on a separate line? can it just be separated by a comma instead? or is there a better way?
    Please note that i know that i have declared "i" above in my code and not intialised it with anything, in reality "i" comes from somewhere else in the program so please ignore that part, it is not what I am concerned with.
    Thanks
    Mersec

    Does each image name go on a separate line? can it just be separated by a comma instead? or is there a better way?
    Arrays are useful for this.
    Dim imagenames() As String = {"img1", "img2", "img3", "img4", "img5"}
    Dim imagename As String = imagenames(i)
    MessageBox.Show(imagename, "Name of image")
    Any sort of collection will do instead of an array, and may be simpler to manage. There are many other options - the most suitable one probably depends on where the names originally come from.  For instance, if you are getting them from a folder
    using the FileSystem.GetFiles method, then they are already in a collection.
    If the files names never change then you may as well include them in the program code, using something like the code above.  If they can change, then you could use a text file, but that means you need a file update routine.  If that is required
    then the way you store the names will dictate how you access them.

  • How to set the Model Class for a newly created Model Node ?

    Hello All,
      I am trying to map a Model node from SourceA to DestinationB.
      To do so, I created a model node for Destination B in the interface controller (set the isInputElement to true). However why I try to map the node, I get an error saying that "Both context nodes have to be bound to a model class". Upon a closer look, I realised that the model node that I created in DestinationB has no entries under the properties.
      Does anyone knows/advise how I can add the model class entry to the model node that I have created as I am not able to do so. Or otherwise, is there a way to map a model node to another model node across different components ? Thank you very much.
    from
    Kwok Wei
    from
    Kwok Wei

    Hello Pascal
      The instructioons that you gave are for mapping the model between the view controller and the component controller within the same component is that right ?
      I am tryng to map a model node in the component controller of SourceA to another model node that belongs to another Component. I do believe that in this case I will need to create a model node in the interface controller of DestinationB and map that to the component controller of SourceA. However, by creating my own model node, how do I change the property modelClass in the context ?
      Thanks !
    from
    Kwok Wei

  • HT201471 Is there another way to see what model iPad I have without prying it out of the case?

    it seem to get an answer to my question, I must know the model of my iPad.  My iPad is encased in a protective unit that Sampson couldn't break and one  that I can't figure out how to remove. - and the Apple (so called) "support" site only gives pretty pictures for me to compare to my iPad.  And I'm supposed to conduct this comparison of pictures on the screen to the back of my iPad (that needs to be turned upside down!!!). And just how am I supposed to see the screen with the iPad turned over?!?  WAY TO GO, APPLE!  Surely there is a better way to find the model Information!   If one looks in Settings, one finds Everything about the iPad -Except the model!  Aargh!  Does Anyone know of a better way to discover the iPad model?

       FROM Chrley's Mom (because I dont know how to "post back" as one responder requested  OK!  I found it!  Now, why didn't the Apple "support" site say that?!?  Why wasn't it on the Apple "support" site Instead of those idiot pictures.  Does Apple think we have lost the ability to read and need "picto-nary" instructions?!?   Aargh!
       NOW, you folk have been very helpful, so maybe you can help me with the original reason I went to Apple "support". ( I hope I'm not in the wrong "pew" for these there questions).
       i updated my iPad and three things happened;  a blank gray panel now covers 1/3 of my iPad screen in the landscape view; I lost all my site Bookmarks and everything on my Reading List!  So,
    1). How do I get rid of that empty gray panel?  It covers over whatever is showing in the landscape view but disappears in the portrait view.  And it only appears when I'm using Safari to view the Internet. 
    2). is there a way I can retrieve my site Bookmarks?
    3). and my Reading List?  (No, the iPad isn't synced to a Mac - because I don't use a Mac) 

  • Mapping Model Nodes

    Hi Gurus,
    Can anybody tell me , which is the best practise for mapping a structure to view through Component Controller .
    1) Setting all the model node values to a Value node on controller level and Map to the view
    2) Directly mapping the model node from controller to View .
    Please tell me the advantage also ?
    Thanks  in advance .
    Tony Isaac.

    Hi Tony,
    This looks quite wiered. As far as I think EHP1 should not restrict you to bind any modeled node attribute with the UI element. This is very basic requirement and as I said earlier if the scenario demands then we always bind teh values directly to the UI element.
    It makes no sence in first copying the values of the modeled node to the value node and then used the value nodes and finally take the values of the value node, copy them back to modeled node and finally save it. It will definitely hinder the performance. And in scenariois where we have lot of attributes in the structure then in all such cases the performance will be decresed drastically.
    Therefore I dont feel that there will be any such restriction on this.
    I hope this helps!
    Thanks and Regards
    Pravesh

  • Tree View Node Element Resize

    Hello,
    Is there any way to resize Tree View Node Element programatically.
    In .fr file the height of the tree view node element is set to 90.
    On a button click I want to resize the element height to 18.
    I have tried using IControlView->SetFrame(TmpRect); but with no luck.
    Thanks,
    Prakash.

    Take a look at ITreeViewWidgetMgr, you can implement GetNodeWidgetHeight(...)
    and you may need to call ITreeViewMgr->NodeChanged(...) to get the TreeView to re-paint your Node.

  • How to Transper data Model Node to Vallue Node

    Hi Friends
    I am getting problem in Create the Check box in Table
    I am getting model node from ECC System(Zmmoa_Pending_Getlist_Input)
    This is path for attributes avaliable
    Zmmoa_Pending_Getlist_Input-Output-outtab 
    Under outtab  all attributes available
    My Requrement is display Check box. So I am doing like this I will care one more Vallue Node (OutTab_1) under this Vallue Node I put I have node attributes.here I careate one Check boxdatatype --Boolean(i.e Under outtab attributes)
    Now I will get data from ModelNode and send that data to Vallue Node(by this node that data display in table formate.Eache Row Having Check box)
    So I have to this Code But Data is Not getting in Vallunode table
    in FirstView
    in Submit Button
    public void onActionGetData(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionGetData(ServerEvent)
        //$$begin ActionButton(1164287125)
        //wdThis.wdGetExamp2CompController().checkSRA();
         wdThis.wdGetExamp2CompController().checkBox();
        wdThis.wdFirePlugToSV();
        //$$end
        //@@end
    This is code writen in CC
    public void checkBox( )
        //@@begin checkBox()
        //Date today = new Date(System.currentTimeMillis());
        IWDMessageManager mes = wdComponentAPI.getMessageManager();
        try
             Zmmoa_Pending_Getlist_Input input1 = new Zmmoa_Pending_Getlist_Input();
             wdContext.nodeZmmoa_Pending_Getlist_Input().bind(input1);        
              wdContext.currentZmmoa_Pending_Getlist_InputElement().modelObject().execute();
              wdContext.nodeOuttab().invalidate();
    //          IPrivateExamp2Comp.IOutTab_1Element elem = wdContext.nodeOutTab_1().getOutTab_1ElementAt(i);         
             //mes.reportSuccess("Input:" +wdContext.nodeOuttab().size());
                      for (int i =0; i < wdContext.nodeOuttab().size(); i++)
                   //mes.reportSuccess("Input Of I:" +wdContext.nodeOutput().size());
                   //mes.reportSuccess("Input:" );
                   IPrivateExamp2Comp.IOuttabElement  elem = wdContext.nodeOuttab().getOuttabElementAt(i);
                   //wdComponentAPI.getMessageManager().reportSuccess("elem::  "+elem);
                   IPrivateExamp2Comp.IOutTab_1Element result = wdContext.nodeOutTab_1().createOutTab_1Element();
             //Zbapiresult result = new Zbapiresult();
             result.setCheckBox(false);
             result.setConf_Shp_Date(elem.getConf_Shp_Date());        
              wdComponentAPI.getMessageManager().reportSuccess("Conf_Shp_Date::  "+elem.getConf_Shp_Date());
             result.setExpt_Shp_Date(elem.getExpt_Shp_Date());
             result.setMaterial(elem.getMaterial());
             result.setMatl_Desc(elem.getMatl_Desc());
             result.setOa_Quantity(elem.getOa_Quantity());
             result.setOpn_Quantity(elem.getOpn_Quantity());
             result.setPo_Item(elem.getPo_Item());
             result.setPo_Number(elem.getPo_Number());
             result.setPo_Status(elem.getPo_Status());
             result.setPur_Group(elem.getPur_Group());
             result.setStat_Date(elem.getStat_Date());
             result.setQuantity(elem.getQuantity());
             wdContext.nodeOutTab_1().addElement(result);
         catch(Exception e)
                   mes.reportException(e.getMessage(), false);
        //@@end
    can u help me
    how to Transper data Model Node to Vallue Node. By using vallue node that data will display in table format with Check box.
    I need data display in table format with Check box
    Regards
    Vijay Kalluri

    Hi Vijay,
    TO copy values from Model Node to Value Node use the copyElements() method of the WDCopyService API. To acheive this, the name and type of the attibutes in the Value Node should be same as Model node attributes.
    Example: -
    Model Node <----
    > Value node
    ---Name-String                                       ---Name - String
    ---Number-Integer                                  ---Number -  Integer.
    then use the following statement:
    WDCopyService.copyElements(wdContext.node<ModelNode>(),wdContext.node<ValueNode>());
    This will copy all the values.
    Regards,
    Poojith MV

  • How to find black macbook model number from serial number?

    My friend has a black macbook, 2007 or late 2006 I think he said. Genius bar told him the logic board died, so I am looking for replacement part. Is there a way to find the model number from that? Or what parts it would take?
    Thanks.
    Message was edited by: Host

    Try this page:
    https://selfsolve.apple.com/GetWarranty.do
    That will give you the time when it was manufactured. From there, you can use an application like MacTracker to get the model information.
    http://mactracker.dreamhosters.com/
    ~Lyssa

  • Is there a way to export an iTunes playlist from a windows XP pc and import on an iMac?

    I have a PC running Windows XP that I've had for many years. I just got an iMac and want to make that my main music source for syncing iPods, playing,music in the house, etc. I have a lot of playlists on the old PC that I want to move over to the iMac and I don't have to rebuild them all by hand. Is there a way to export the original playlists from the Windows PC and import them to the iMac since the file systems are different? Thanks.

    The problem really is that one person has InDesign and the other has Photoshop.
    The workflow is images from photoshop are placed in Photoshop.
    Not the layout from InDesign is placed in photoshop.
    That's how the software is designed to work.
    What people are saying is that Photoshop cannot work this way in dealing with layouts, it's a nightmare and will give you terrible results and cost you time and effort when updating things in Photoshop, it has all the makings of a Final Destination movie, particularly in the area of the later sequels.
    But let's not get hung up on those franchises.
    If the person needs to edit an Indesign file and can't afford the full cost of InDesign then there are other workarounds:
    1. If it's just text
    If all they are doing is updating text then you can use File>Export>Rich Text Format from a selection of text, this will make a Word version of the text that they can edit. You can then use File>Import and import the RTF that is edited.
    2. You can use InCopy
    This is a viable solution for editors that need to see the text in the Layout Format, but it hasn't got all the bells and whistles of InDesign, but it works in tangent with InDesign, it's not as pricey as InDesign and it also allows you to lock out editors from editing certain parts or moving things within the layout. And it can update your InDesign file on the fly.
    3. You can use Rorohikos Story Tweaker
    http://www.rorohiko.com/wordpress/2009/03/25/storytweakertextedits/
    There are workarounds that you can find for people that don't have InDesign. It's just that the Photoshop workflow isn't a viable solution in any sense.
    For example, I have my layouts proofed in PDF format, where the proofreader adds Comments to the PDF. It works for our workflow as I'm the one editing the only file in existence.
    But to go from InDesign to Photoshop is a complete  waste of time and effort on everyone's part. There is no need to go that route, there's no reason, there's no point.

  • How to hide a tree node from the GUI but still keep it in the tree model?

    Hi, All
    I used a JTree in my project in which I have a DefaultTreeModel to store all the tree structure and a JTree show it on the screen. But for some reason, I want to hide some of the nodes from the user, but I don't want to remove them from the tree model because later on I still need to use them.
    I searched on the web, some people suggested method to hide the root node, but that's not appliable to my project because I want to hide some non-root nodes; Some people also suggested to collapse the parent node when there are child to hide, it is not appliable to me either, because there still some other childnodes (sibling of the node to hide) I want to show.
    How can I hide some of the tree node from the user? Thanks for any information.
    Linda

    Here's an example using a derivation of DefaultTreeModel that shows (or does not show) two types of Sneech (appologies to the good Dr Zeus) by overiding two methods on the model.
    Now, there are many things wrong with this example (using instanceof, for example), but it's pretty tight and shows one way of doing what you want.
    Note: to make it useful, you''d have to change the implementation of setShowStarBelliedSneeches() to do something more sophisticated than simply firing a structure change event on the root node. You'd want to find all the star bellied sneech nodes and call fireTreeNodesRemoved(). That way the tree would stay expanded rather than collapse as it does now.
    import javax.swing.JTree;
    import javax.swing.JScrollPane;
    import javax.swing.JOptionPane;
    import javax.swing.JCheckBox;
    import javax.swing.JPanel;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.DefaultMutableTreeNode;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Enumeration;
    class FilteredTree
         private class PlainBelliedSneech {
              public String toString() { return "Plain Bellied Sneech"; }
         private class StarBelliedSneech {
              public String toString() { return "Star Bellied Sneech"; }
         private class FilteredTreeModel
              extends DefaultTreeModel
              private boolean mShowStarBelliedSneeches= true;
              private DefaultMutableTreeNode mRoot;
              FilteredTreeModel(DefaultMutableTreeNode root)
                   super(root);
                   mRoot= root;
              public Object getChild(Object parent, int index)
                   DefaultMutableTreeNode node=
                        (DefaultMutableTreeNode) parent;
                   if (mShowStarBelliedSneeches)
                        return node.getChildAt(index);
                   int pos= 0;
                   for (int i= 0, cnt= 0; i< node.getChildCount(); i++) {
                        if (((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject()
                                            instanceof PlainBelliedSneech)
                             if (cnt++ == index) {
                                  pos= i;
                                  break;
                   return node.getChildAt(pos);
              public int getChildCount(Object parent)
                   DefaultMutableTreeNode node=
                        (DefaultMutableTreeNode) parent;
                   if (mShowStarBelliedSneeches)
                        return node.getChildCount();
                   int childCount= 0;
                   Enumeration children= node.children();
                   while (children.hasMoreElements()) {
                        if (((DefaultMutableTreeNode) children.nextElement()).getUserObject()
                                            instanceof PlainBelliedSneech)
                             childCount++;
                   return childCount;
              public boolean getShowStarBelliedSneeches() {
                   return mShowStarBelliedSneeches;
              public void setShowStarBelliedSneeches(boolean showStarBelliedSneeches)
                   if (showStarBelliedSneeches != mShowStarBelliedSneeches) {
                        mShowStarBelliedSneeches= showStarBelliedSneeches;
                        Object[] path= { mRoot };
                        int[] childIndices= new int[root.getChildCount()];
                        Object[] children= new Object[root.getChildCount()];
                        for (int i= 0; i< root.getChildCount(); i++) {
                             childIndices= i;
                             children[i]= root.getChildAt(i);
                        fireTreeStructureChanged(this, path, childIndices, children);
         private FilteredTree()
              final DefaultMutableTreeNode root= new DefaultMutableTreeNode("Root");
              DefaultMutableTreeNode parent;
              DefaultMutableTreeNode child;
              for (int i= 0; i< 2; i++) {
                   parent= new DefaultMutableTreeNode(new PlainBelliedSneech());
                   root.add(parent);
                   for (int j= 0; j< 2; j++) {
                        child= new DefaultMutableTreeNode(new StarBelliedSneech());
                        parent.add(child);
                        for (int k= 0; k< 2; k++)
                             child.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
                   for (int j= 0; j< 2; j++)
                        parent.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
                   parent= new DefaultMutableTreeNode(new StarBelliedSneech());
                   root.add(parent);
                   for (int j= 0; j< 2; j++) {
                        child= new DefaultMutableTreeNode(new PlainBelliedSneech());
                        parent.add(child);
                        for (int k= 0; k< 2; k++)
                             child.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
                   for (int j= 0; j< 2; j++)
                        parent.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
              final FilteredTreeModel model= new FilteredTreeModel(root);
              JTree tree= new JTree(model);
    tree.setShowsRootHandles(true);
    tree.putClientProperty("JTree.lineStyle", "Angled");
              tree.setRootVisible(false);
              JScrollPane sp= new JScrollPane(tree);
              sp.setPreferredSize(new Dimension(200,400));
              final JCheckBox check= new JCheckBox("Show Star Bellied Sneeches");
              check.setSelected(model.getShowStarBelliedSneeches());
              check.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        model.setShowStarBelliedSneeches(check.isSelected());
              JPanel panel= new JPanel(new BorderLayout());
              panel.add(check, BorderLayout.NORTH);
              panel.add(sp, BorderLayout.CENTER);
              JOptionPane.showOptionDialog(
                   null, panel, "Sneeches on Beeches",
                   JOptionPane.DEFAULT_OPTION,
                   JOptionPane.PLAIN_MESSAGE,
                   null, new String[0], null
              System.exit(0);
         public static void main(String[] argv) {
              new FilteredTree();

  • Can't remove a node from a tree

    I am using the custom tree dataDescriptor provided in Flex live
    doc. It works for creating the tree and add notes, however when I
    try to remove a node from the tree it cant work. Does anyone have
    any idea?
    This is the code for MyCustomeTreeDataDescriptor.as
    package
    import mx.collections.ArrayCollection;
    import mx.collections.CursorBookmark;
    import mx.collections.ICollectionView;
    import mx.collections.IViewCursor;
    import mx.events.CollectionEvent;
    import mx.events.CollectionEventKind;
    import mx.controls.treeClasses.*;
    public class MyCustomTreeDataDescriptor implements
    ITreeDataDescriptor
    // The getChildren method requires the node to be an Object
    // with a children field.
    // If the field contains an ArrayCollection, it returns the
    field
    // Otherwise, it wraps the field in an ArrayCollection.
    public function getChildren(node:Object,
    model:Object=null):ICollectionView
    try
    if (node is Object) {
    if(node.children is ArrayCollection){
    return node.children;
    }else{
    return new ArrayCollection(node.children);
    catch (e:Error) {
    trace("[Descriptor] exception checking for getChildren");
    return null;
    // The isBranch method simply returns true if the node is an
    // Object with a children field.
    // It does not support empty branches, but does support null
    children
    // fields.
    public function isBranch(node:Object,
    model:Object=null):Boolean {
    try {
    if (node is Object) {
    if (node.children != null) {
    return true;
    catch (e:Error) {
    trace("[Descriptor] exception checking for isBranch");
    return false;
    // The hasChildren method Returns true if the node actually
    has children.
    public function hasChildren(node:Object,
    model:Object=null):Boolean {
    if (node == null)
    return false;
    var children:ICollectionView = getChildren(node, model);
    try {
    if (children.length > 0)
    return true;
    catch (e:Error) {
    return false;
    // The getData method simply returns the node as an Object.
    public function getData(node:Object,
    model:Object=null):Object {
    try {
    return node;
    catch (e:Error) {
    return null;
    // The addChildAt method does the following:
    // If the parent parameter is null or undefined, inserts
    // the child parameter as the first child of the model
    parameter.
    // If the parent parameter is an Object and has a children
    field,
    // adds the child parameter to it at the index parameter
    location.
    // It does not add a child to a terminal node if it does not
    have
    // a children field.
    public function addChildAt(parent:Object, child:Object,
    index:int,
    model:Object=null):Boolean {
    var event:CollectionEvent = new
    CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
    event.kind = CollectionEventKind.ADD;
    event.items = [child];
    event.location = index;
    if (!parent) {
    var iterator:IViewCursor = model.createCursor();
    iterator.seek(CursorBookmark.FIRST, index);
    iterator.insert(child);
    else if (parent is Object) {
    if (parent.children != null) {
    if(parent.children is ArrayCollection) {
    parent.children.addItemAt(child, index);
    if (model){
    model.dispatchEvent(event);
    model.itemUpdated(parent);
    return true;
    else {
    parent.children.splice(index, 0, child);
    if (model)
    model.dispatchEvent(event);
    return true;
    return false;
    // The removeChildAt method does the following:
    // If the parent parameter is null or undefined, removes
    // the child at the specified index in the model.
    // If the parent parameter is an Object and has a children
    field,
    // removes the child at the index parameter location in the
    parent.
    public function removeChildAt(parent:Object, child:Object,
    index:int, model:Object=null):Boolean
    var event:CollectionEvent = new
    CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
    event.kind = CollectionEventKind.REMOVE;
    event.items = [child];
    event.location = index;
    //handle top level where there is no parent
    if (!parent)
    var iterator:IViewCursor = model.createCursor();
    iterator.seek(CursorBookmark.FIRST, index);
    iterator.remove();
    if (model)
    model.dispatchEvent(event);
    return true;
    else if (parent is Object)
    if (parent.children != undefined)
    parent.children.splice(index, 1);
    if (model)
    model.dispatchEvent(event);
    return true;
    return false;
    This is my tree definition:
    <mx:Tree width="143" top="0" bottom="0" left="0"
    height="100%"
    id="publicCaseTree"
    dataDescriptor="{new MyCustomTreeDataDescriptor()}"
    dataProvider="{ac}"
    defaultLeafIcon="@Embed('assets/caseIcon.png')"
    change="publicTreeChanged(event)"
    dragEnabled="true"
    dragMoveEnabled="false"/>
    This is how I remove the selected node from the tree. When
    Delete button is clicked, the doDeleteCase function is
    exectuted.
    public function publicTreeChanged(event:Event):void {
    selectedNode =
    publicCaseTree.dataDescriptor.getData(Tree(event.target).selectedItem,
    ac);
    public function doDeleteCase(event:Event):void{
    publicCaseTree.dataDescriptor.removeChildAt(publicCaseTree.firstVisibleItem,
    selectedNode, 0, ac);
    Any help would be appreciated.Thanks.

    Finally I removed nodes from tree, but not sure I did in the
    right way. Anybody encounter the same problem, please
    discuss.

  • WD ABAP: selecting a tree node from program and scroll to it

    Hi guys!
    I am using a tree in Web Dynpro ABAP. I would like to select/highlight one node from the coding, without user interaction. Is it possible? I couldn't find any (obvious) way so far...
    If it is possible, then let us go a little bit further. Suppose, that the tree grew so big, that cannot fit in the container. Suppose, that you can scroll the tree up/down to see all the nodes. Now, if you mark one tree node from the coding, is it possible somehow, that you scroll the tree automatically, so that the selected node is visible?
    I am interested in any solutions within WD ABAP.
    If you can only answer one of the questions, that is also appreciated!
    Thanks for the help in advance.
    Best regards,
    Janos Kis
    Aerospace&Defense(ERP)

    Hi Thomas,
    thanks for the advice, it works, I have already tried it. The tree node in the lead selection appears highlighted.
    The scrolling doesn't work, though. I have tried to put the tree in a scroll container, and I have also tried it without (relying on the browser to scroll). Neither of them worked, it doesn't scroll to the selected node, it remains offscreen. Can you think of a way, to bring it automatically within the visible range? Ideas, anyone?
    Actually we would like to implement a search function in the tree, and show the result within the tree (highlight the node, expand, if necessary, and bring it on the screen, if off-screen)
    A negative answer is good enough for me, so that I know, that I can stop looking for a solution. Thanks in advance.
    Janos

Maybe you are looking for

  • LOV of column names with a report's custom column headings?

    I have a list ov values definition that looks like this: select column_name d, column_name r from all_tab_columns where table_name = 'DATABASE_LIST' I'd like to list the custom column headings from a report as d, rather than repeating the column_name

  • Multiple Error message at Item Level....

    Hi all, I have some doubt into display multiple error message from item level. The scenario is, I have to run some validation at each line item. If validation fails error message is population. Now suppose user ignore the error message or with that e

  • Need help naming photo files in a sequence?

    I want to name a group of files in a sequence. For example, I have 10 photo's from Joe's birthday party. I want to name the files JoeBirthday with a number after them (JoeBirthday1, JoeBirthday2, and so on.). I cannot figure out how to do this. Can s

  • Is there a "master uninstaller" for CS? (CS2 in this case)

    I've got CS2, upgrading to CS4. XP SP3. I'm currently in limbo: * CS2 partially uninstalled * Nothing in add/remove programs * CS installers/uninstallers think I manually installed four CS apps and refuse to touch them * I installed using CS and have

  • My daughter accidentally trashed all her photos. How do I return them to iPhoto Library?

    MacBook OS X Leopard. Version 10.5.8. iPhoto '09 version 8.1.2 (424) My daughter was attempting to copy a few photos to a USB pen drive and ended up sending all photos as well as iPhoto to the trash.