Saving and retreiving  JTree structure

Hi everybody
In the following code I had intended to save the path of expanded nodes of a tree just before collapsing and retreiving the same structure of the tree again , but the path is not expanding at all .
Can any body help me to solve the problem
Vector paths
public void saveTreePaths() {
          Object path = selectionTree.getModel().getRoot();
                           paths = new Vector();
          TreePath tp = new TreePath(path);
          nodes = selectionTree.getExpandedDescendants(tp);
          while(nodes.hasMoreElements()) {
               paths.add(nodes.nextElement());
     public void reloadTreePath() {
             for(int j = 0; j < paths.size(); j++) {
                 TreePath  Path = (TreePath) paths.get(j);
                  selectionTree.expandPath(Path);      
                                    }

Hi Deepak!
The problem is to expand a certain node on a certain path all parent nodes should be expanded for the node(lastPathComponent). If you had looked at the enumeration(Saved paths) it is not in tree order. So you have to order them. Here is the code which as I think (I've checked it and it worked) will help you.
  private void expandSavedPaths(List listOfSavedPathes)
    Comparator c = new Comparator()
      public int compare(Object tp1, Object tp2)
        return ((TreePath) tp2).getPathCount() - ((TreePath) tp1).getPathCount();
    };//comparator which compares only by tree path length i.e. level
    //enshure that the tree pathes are sordted by node level,
    //which enables to expand tree nodes which parents are already expanded
    java.util.Collections.sort(listOfSavedPathes, c);
    for (int i = 0; i < listOfSavedPathes.size(); i++)
      opTree.expandPath((TreePath) listOfSavedPathes.get(i));
  }

Similar Messages

  • Best practice for saving and recalling objects from disk?

    I've been using the OOP features of LabVIEW for various projects lately and one thing that I struggle with is a clean method to save and recall objects.
    Most of my design schemes have consisted of a commanding objects which holds a collection of worker objects.  Its a pretty simple model, but seems to work for some design problems.  The commander and my interface talk to each other and the commander sends orders to his minions in order to get things done.  For example, one parrent class might be called "Data Device Collection" and it has a property that is an array of "Data Device" objects.
    The Data Device object is a parent class and its children consist of various data devices such as "DAQmx Device", "O-Scope Device", "RS-232 Device", etc.
    When it comes to saving and loading data, the commanding class's "Save" or "Load" routine is called and at that time all of the minions' settings are saved or recalled from disk.
    My save routine is more-or-less straight forward, although it still requires an overwriting "Save" and "Load" vi.  Here is an example:
    It isn't too bad in that it is pretty straight forward and simple and there also would be no changes to this if the data structure of the class changed at all.  It also can save more generalized settings from it's parrent's class which is also a good feature.  What I don't like is that it looks essentially the same for each child class, but I'm at a loss on an effective way to move the handling of the save routing into the parent class.
    The load routine is more problematic for me.  Here is an example:
    Again, the desirability of moving this into the parent class would be awesome.  But the biggest complaint here is that I can't maintain my dynamic dispatch input-output requirements because the object that I load is strictly typed.  Instead I have to rely on reading the information from the loaded object and then writing that information to the object that exists on the dynamic dispatch wire.  I also dislike that unlike my Save Routine, I will need to modify this VI if my data structure of my object changes.
    Anyway, any input and insight would be great.  I'm really tired of writing these same VIs over-and-over-and-over again, and am after a better way to take care of this in the parent class by keeping the code generalized but still maintain the ability to bring back the saved parameters of each of the children classes.
    Thanks for your time.

    I'm with Ben. Don't rely on the current ability to serialize an object. Create a save method and implement some form of data persistence there. If you modify your class you might be disappointed when you cannot load objects you previously saved. It mostly works but as soon as you reset the version information in the class, you can no longer load the old objects. This is fine if you know how to avoid resetting the history. One thing that will do this is if you move the class into or out of a library. It becomes a new class with version 1.0.0 and it no longer recognizes the old objects.
    [Edit:  I see that you are just writing to a binary file. I'm not sure you can load older objects anyway using that method but I have never tried it.]
    This will not help you right now but there are plans for a nice robust API for saving objects.
    =====================
    LabVIEW 2012

  • Looking for suitable and robust data structure?

    I have an application where i have to give user an option to correlate the
    response returned by a method call with other methods arguments.
    I have provided a jtree struture where user can see methods and their
    responses and can correlate them by selecting appropriate arguments
    where these values could be used.
    I used a data structure to store such relations like
    A hashmap where every key is a unique number representing method number
    and value ia a matrix.
    In each matrix, the first element of every row would be the Response object and
    all remaining elments in the row would be Argument objects. :)
    Now maybe someone would ask, for every method there is always only one return type
    then why such a matrix with Reponse object as first element of each row.
    The reason is that i gave user an option to not only relate response as a whole Object to
    different arguments of different methods but user can select a field of this response object if this
    is a complex type or user can select any element if the response is a Collection object to relate
    with arguments.
    I am not sure whether this structure is more appropriate or i can use more robust
    and memory efficient structure.
    Please give me your useful suggestions.

    J2EER wrote:
    I have an application where i have to give user an option to correlate the
    response returned by a method call with other methods arguments.I really don't understand you.
    I have provided a jtree struture where user can see methods and their
    responses and can correlate them by selecting appropriate arguments
    where these values could be used.Huh?
    I used a data structure to store such relations likeErr, what happened to the rest of your sentence? Or is the next part the rest of it?
    A hashmap where every key is a unique number representing method number
    and value ia a matrix.Where does this matrix come from? In my book, a matrix is a 2 dimensional structure. What do you mean by it?
    In each matrix, the first element of every row would be the Response object and
    all remaining elments in the row would be Argument objects. :)
    Now maybe someone would ask, for every method there is always only one return type
    then why such a matrix with Reponse object as first element of each row.You're still talking about methods? If so, don't all methods have just one return type?
    The reason is that i gave user an option to not only relate response as a whole Object to
    different arguments of different methods but user can select a field of this response object if this
    is a complex type or user can select any element if the response is a Collection object to relate
    with arguments.
    I am not sure whether this structure is more appropriate or i can use more robust
    and memory efficient structure.
    Please give me your useful suggestions.Perhaps you could give a more detailed explanation and more importantly, provide some examples of what you mean.

  • How to organize variables for file saving and scalability?

    Hello,
    I have created several CVI applications that store production data for numerous machines.  To organize the data for file saving I have implemented structures.  This has worked well with one limitation, the inability to scale the structure at a later date without invalidating existing files.  I would like to consider alternative approaches that would allow scalability.
    Here's an example of my current method...
    // Definition of structure per machine.
    struct machine_1
       int  int_param_1, int_param_2, int_param_3;
       double  dbl_param_1, dbl_param2, dbl_param3;
    struct machine_2
       int int_param_1, int_param_2, int_param_3;
       double dbl_param_1, dbl_param2, dbl_param3;
    // Definition of inclusive structure. (Member name and structure tag name are the same.)
    struct
       struct machine_1   machine_1;
       struct machine_2   machine_2;
    } machine_parameters;
    To assign a value to a structure variable:
    // Assign value.
    machine_parameters.machine_1. dbl_param_2 = 77.47;
    Then when it comes time to save the populated structures:
    // Save structure.
    error = fwrite (&machine_parameters, sizeof(machine_parameters), 1, dest);
    The problem comes later when multiple files already exist and one of the machine structures needs an additional variable added.  For example, if I need to add int_param_4 to the machine_1 structure.  Adding this variable will invalidate the previously saved files because they were saved with a different structure and will not be able to be opened with a new structure containing one additional variable due to the structure definition mismatch.
    I have added spare variables per data type to the structures for each machine, but it's a losing game.  If I add 10 spare variables, I end up needing to store 11 more pieces of data.
    Is there a better approach?
    Thanks,
    Aaron T.

    One simple way is to output the data as ASCII comma separated values, with a newline character at the end of each row of data.
    I.E., the only structure to your file data is a "row" of CSV's, with the file containing some number of rows.
    Then, you load the data into Excel, and it will parse the CSV's for you and when it sees the newline, put the next set of CSV's on the next row of the worksheet.
    If you ever need to expand the number of items in a row, you just add them as you generate data, pushing the newline to the right, the extra data  extending the row.
    So you get an Excel worksheet filled with rows of (possibly varying length) data.   So long as you add data at the end of the row when you redefine what you're saving, anything reading the file should see the same stuff that was always there.
    You can write a macro to reformat or parse the CSV's once they're in the spreadsheet.  With Excel 2007 supporting very large worksheets, you can put a lot of data into one.  I think they expose a C interface for writing fast data manipulation of cell data now too - sort of a fast macro from the Excel viewpoint.  I think the number of columns is 16384 and 1 million rows in a "Big Grid". The Excel 2007 engine is multi-threaded and you can tell it how many cores to use on a multicore machine.
    So the only problem I see is the loss of local structure (your C structs get serialized and get concatenated to one another) but you could re-introduce the structure with a macro.
    Or, if you were to write out serialized binary values and then view the file data using a hex editor like Neo, you can tell Neo what your C structs were and it will pick up binary file data and put it back into the C structs for viewing.
    Or use MatLab to read the CSV's and reformat it.
    Or use the CVI SQL interface and write it out as database records.  I think the SQL toolkit costs extra, maybe it comes with the FDS. 
    Menchar

  • Store and retreive image/bitmapdata to/from local storage in iOS-app

    I'm trying to store and retreive cam-captured bitmapdata to the local app-space, but after a whole day of searching and trying I can't find any working example.
    It's no problem capturing cam-bitmapdata, but how to store (and retreive).
    Thanks!

    If its just a problem of saving the bitmapdata, follow along:
    http://actionsnippet.com/?p=1093
    Use http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.h tml#applicationStorageDirectory to resolve to the correct location.

  • I assume that when I uninstall Thunderbird and later re-install it all my old emails and the account structure will be kept untouched and I will not lose it.

    I assume that when I uninstall Thunderbird and later re-install it all my old emails and the account structure (including tags etc.) will stay untouched. Is that right?

    And there is nothing you can do about that except SAVE all of them and when you change the connection Protocol to IMAP or Exchange Active Sync you might be able to copy those emails back into the folders for the new connection protocol and have them all show up on the Outlook.com server.
    The company I work for change their email hosting service to Office 365, basically Outlook.com, and I need to move all my current emails from the old hosting service to the Office 365 email system. I did that by saving all of them to Local folders on my computer then Copying them into folder I created for the Office 365 email system. They all appeared in the Office 365 Outlook webmail system and then they were available to multiple devices.
    It was a Long Drawn out process and had some hickups but in the end I didn't lose any emails.

  • I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    What file format did you export it to?

  • Excise invoice is not saving and not showing datas

    in erxcise invoice i ve made settings as per the sap best practices then also the excise invoice is not saved and not generated also
    please help me to solve the problem
    the error is coming like this
    Error in allocating Excise invoice number Interval not found Number object J_1IEXCLOC
    Message no. 8I336
    i ve already maintainthe number range for this object in tool in tax in goods moment
    please give some better advice for the excise invoice setting.

    Sub Transaction type determines the subcontracting attributes and determines the accounts for the posting while doing a sub contracting transaction.
    Sub transaction type is also used for determining the accounts while
    doing excise removals.
    Within CIN the account determination is based on the transaction type.
    So normally you can have a single set of accounts for Excise
    utilization. In case you need alternate account determination for
    handling various scenarios you can define sub transaction types. The
    sub transaction types and corresponding account assignments needs to be
    maintained in CIN customization
    To make customization of Sub Transaction type, goto
    <b>SPRO --> Logistics General --> Tax on Goods Movements --> India --> Account Determination and check whether you have assigned second and third one, viz. "Specify Excise Accounts per Excise Transaction and Specify GL Accounts per Excise Transaction".</b>
    Check
    <b>Taxes on goods mvnt--indiaaccnt determination---specify excise accnts for excise transaction...maintain the sub transction type , ip or 01,
    against the appropriate ETT</b>
    Message was edited by:
            sam masker

  • Billing plan (Downpayment) for saved and open sales orders at header level?

    Hi gurus,
    I have configured billing plan in my SD environment at Item Level.
    I want to change it to header level.
    Questions:
    1- When I make the changes to update the system to have billing plan at header level for future sales orders, is that possible for me to change all my saved orders and open orders with the new settings so that I can also have those saved and open orders with a billing plan at item level?
    2- If that scenario is not possible, could we for example copy the data of a previously saved or open sales order into a new sales order with the new customizing (Billing plan at Header level?)
    Thanks for your input
    Kind regards
    Chris

    Hi
    I am afraid you cannot do that converstion for the existing orders. BP at header level are enabled at teh document type level, while BP at item level is done at item category. So both are independent. Mostly it is advisabel to use BP at item level only.
    If you are already using item level BP, and want to mvoe to header BP, then only future transactions can be executed with BP at header level. Existing item level BPlans will remain so in the system.

  • Major problem saving and printing documents on two computers

    This is a bizarre problem that seems to have been transferred from my old MDD to my new Mini when I migrated all my old data and it has me baffled. My apologies if this explanation seems long and complicated but I want to be pretty thorough.
    About a month ago I started experiencing a problem with printing. I noticed when printing a sheet of business cards that the page was getting compressed, for lack of a better word, vertically. This was very noticeable because the trim marks on the side of the page were not lining up with the perforations and each row of cards was getting progressively closer to the top as each row was printed. In other words, the first row of cards was okay but then the next row was a little too far "north", the next row a little more, the next row a little more, etc. The bottom of the page was not cut off, it was just squeezed up a bit but not enough that you could tell that the proportions were off. Now I see that many of my documents are like that no matter what application I've use to create them – Pages, Illustrator, Avery DesignPro. What's even worse, I've used Pages to create a sheet of business cards for a friend and Illustrator to make packaging labels and she's having the same problem printing the PDFs of the labels on a different computer. What this seems to tell me is that something has been corrupted and the computer is saving messed up files.
    So, about ten days ago I got a Mini and migrated my data using Migration Assistant. And the problem has now been transferred to the Mini. So I now have two Macs connected to two different HP printers that are both incapable of printing (and apparently saving) documents in the proper proportions.
    Now, a truly weird thing is that I printed a test sheet of business cards from the Mini on the printer connected to the MDD (via printer sharing) and it appeared that the document printed at the correct length. However, another document, a sheet of labels created in Illustrator, printed at the right length but one edge was slightly cropped off. Grrr.
    Anyway, as I said, until about a month ago everything worked fine so something got messed up at that time to cause this problem with saving and printing documents. I need to get this resolved for business reasons – I'm an aspiring designer – but the only thing I can think of doing is wiping out my Mini and reloading everything except my account settings from Time Machine unless someone has advice on what to do. Help! (And yes, I've checked to see that page scaling was always set at 100%.)

    Well, I've just about had it. I erased the disk, reinstalled the OS, Adobe CS4, and iWork. I did not use Migration Assistant this time to restore my settings but still my Mac prints documents in the wrong dimensions. Could this be a sudden HP problem? It seems to me some system setting somewhere is making my computer save and print documents in the wrong size. I now have a computer that is almost useless for designing. Lucky me.

  • Before when I scanned a photo, it would automatically save and ask to scan another photo. Now, the photo is not saving and it doesn't ask to scan again. Help?

    Before when I scanned a photo, it would automatically save and ask to scan another photo. Now, the photo is not saving and it doesn't ask to scan again. Help?

    What Scanner and scanware are you using....?
    Check out > Mac Basics: Using a scanner
    I only use Image Capture and it always sends my photos to wherever I tell it to.

  • How can i get my credit card info to save? it says its saved and then as soon as i leave the page it says i have to provide credit card info?

    every time i save my credit card info in my account on ITunes, it shows as saved and as soon as I go to buy something, it says I have no credit card on file and starts over again.

    I don't mind having my card info on there but now I can't download anything and it's frustrating. All it ask for is the card security number and when I put it in it says it's invalid. So now while I'm trying to delete it, it just won't let me. The visa part stays checked all the time and I can't unmarked it. I tried to just erase the card number and security code and stuff but it says I have to have it filled in. Do you know how I can check to see if it says I owe money?

  • Saving and backing up iMovie projects

    Here is a question I never dreamed I'd be asking: how do you save an iMovie "project"? Since 1984, every Mac application has had "Save" under the "File" menu where you could name and save your file. "Save often" became the main way to avoid disaster in the event of a application malfunction. Idiocy reigns at Apple; saving is no longer possible. Now I know iMovie is supposed to auto-save, but really...the Web is full of disaster stories of crashed apps and lost files.
    Anyway, I want to do several things: 1.) I want to save my project so that I can open it at a later date and work on it again. 2.) Related to #1, I want to start a new project, confident that my old project is still accessible. 3.) I want to do twice daily back-ups of my working project so that if iMovie crashes I don't lose more than a half day of work.
    All of this has become almost automatic in my nearly 25 years of working on Macs. File saving and backing up are one of the few constants that, until iMovie, were unchanged. Apple, in a regrettable display of poor decisionmaking, has abandoned this tried and true procedure. I really hope I'm missing something simple and I have to eat my words. Can anyone help me save my files? Thanks. By the way, no Time Machine here. I want to save these files manually.

    Hi:
    Michael Brown12 wrote:
    Anyway, I want to do several things: 1.) I want to save my project so that I can open it at a later date and work on it again.
    Quit iMovie and open it later when you want to restart your project.
    2.) Related to #1, I want to start a new project, confident that my old project is still accessible.
    In iMovie, menu File > New. It will open a dialog box that allows you to name your new project and set the aspect ratio you will use.
    You can see your old projects by clicking the "Project Library" button at the upper left corner of the iMovie window. It will show you all your projects. You can duplicate or rename any project, as you wish, in the library. If you want to edit an older project, select it in the library and then click the button "Edit Project" in the upper left corner of the iMovie window.
    3.) I want to do twice daily back-ups of my working project so that if iMovie crashes I don't lose more than a half day of work.
    iMovie store the projects and project events in the folder Home Folder username > Movies > iMovie Projects and Home Folder username > Movies > iMovie Events. Feel free to back up those folders as often as you'd like. I would incorporate some kind of naming convention that allow you to readily see the date/time of your backup, but that is up to you. If you crash for some reason, you can restore the contents of the folders from your backups.
    All of this has become almost automatic in my nearly 25 years of working on Macs. File saving and backing up are one of the few constants that, until iMovie, were unchanged. Apple, in a regrettable display of poor decisionmaking, has abandoned this tried and true procedure.
    Well, hmmmmmmm. Most mission critical software that I know, such as QuickBooks Pro, or Filemaker Pro do not have save commands, as I guess the designers feel that it is safer to have the program do the auto-save after every change the operator makes than leaving it up to the operator to remember.
    Even Final Cut Pro, Apple's flagship edit software, has built in auto-save *in addition to* the manual save commands. I have my auto-save in FCP set to every two minutes.
    Hope this helps.

  • Upon startup Firefox says "Proxy is refusing connections." When I select "Auto-Detect Proxy" from Advanced settings and solve problem, changes are not saved and upon next startup I must select again...!

    Firefox 4 was working fine. Then one day, when I started up Firefox, it says "Proxy is refusing connections." I solved this by selecting "Auto-Detect Proxy" from Advanced network settings, but my changes are not saved and upon every start-up I must select it again! (I even completely removed my webroot antivirus protection, as it as hindering many proxy related programs, but this seems to not be the source of the problem)

    You can find the connection settings in Tools > Options > Advanced : Network : Connection
    If you do not need to use a proxy to connect to internet then select "No Proxy"
    See "Firefox connection settings":
    * https://support.mozilla.com/kb/Firefox+cannot+load+websites+but+other+programs+can
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes
    See also:
    *http://kb.mozillazine.org/Preferences_not_saved

  • How to fix file when it says, "Cannot open file " ". Adobe Indesign does not support the file format, a plug-in that supports the file may be missing, or file may be open in another application." It worked one second, I saved and closed the file, then tri

    How to fix file when it says, "Cannot open file " ". Adobe Indesign does not support the file format, a plug-in that supports the file may be missing, or file may be open in another application." It worked one second, I saved and closed the file, then tried to reopen and now it won't work. I am using Adobe InDesign CS5. It is the only version on my comp. I have tried opening on another comp & copying the file – same error comes up. PLEASE HELP

    First check the version of the document with Jongware's script "Identify.jsx" (ExtendScript/JavaScript).
    You can find it here:
    [Ann] Identify Your InDesign File
    If it is CS 5.5 or above, you need someone to open it in the version the script says and export an IDML representation from that. Another way would be to install a 30days version of CS6 or above (CC) and do it yourself.
    In regards of the script showing a result for InDesign files higher than CS6:
    CS7 = CC v9
    CS8 = CC v10 = CC-2014 or CC2014.1
    Uwe

Maybe you are looking for

  • How to add web template in actions

    i want to add a website in my app using action i tried to do that with Http but website open in browser after using http option. i want  that website to be open inside the app like webtemplate

  • Sales analysis(amt wise)

    hi,     can i do a sales analysis( selection criteria as amountwise). regards, Vignesh

  • How i can manipulate xml  writeXML()

    I am using wirteXML() Method for creating xml from ADF BC Viewobject from generated xml i want to create txt file with the help of xslt but my consern is when i am creating concern file i want it align properly for that reason what i can do if is it

  • Exception Error 10 in MD04

    Hi Experts, after MRP for a material, an exception error 10 was appeared in MD04, can someone tell me in which situation the error message will display? Thanks, Nadali

  • Clips not rendering

    Can anyone tell me why my edited clips are not rendering? I've never had this problem before... Left iMovie up all night, and they're still not done (or even started).