Results 1 to 4 of 4
  1. #1
    janpol1 is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default [SOLVED] Refreshing a tree view

    Hi, i have created a tree view using the org.eclipse.ui.views extension but i don`t know how to make a refresh method. The view`s input it`s a method that reads info from a text file. I`ve added a context menu for the view. The context menu options are added by using the org.eclipse.popupMenus extension. One of this options is a Refresh option, but i have no clue on how to make the refresh.
    I need to know how to refresh the view and how to call this method from the context menu. Thanks a lot for your time

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Look at the Javadoc (API) for the class you are using. It will tell you the methods that class makes available. Look for ones that allow you to build or modify the list items.

    This is a brute force approach, but another way to get the job done is to remove the existing view object from the container and replace it with a new one. You will have to make sure the view's location is not dependent on the order it was added to the container.

    I hope that helps you move forward...

  3. #3
    janpol1 is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    Thanks, i couldīt find an appropiate method to do refresh so i hide then show the view. But now i need to keep the expanded items. I`ve tried the getExpandedElements() and then the setExpandedElements() but itīs not working (perhaps because i hide-show the view??)


    elements = viewer.getExpandedElements(); workbenchWindow.getActivePage().hideView(page[cont].getView(false));
    workbenchWindow.getActivePage().showView("myview") ;
    viewer.setExpandedElements(elements);

    /*viewer itīs the TreeViewer object*/

    Any ideas on how to accomplish this?? Thanks

  4. #4
    janpol1 is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    Iīve finally solved it correctly. I forgot to post it but it goes like this:
    What i do here is getting a list of all the expanded elements before i refresh the view. With the setIntput() method i force the view to rebuild itself with all the new items. Then, I get a list of all the items to compare to the previous expanded ones (i know this part isn`t really elegant but it works just fine :p)
    P.d: Sorry about my english, im from Argentina :D
    Java Code:
    		   
            try {
    			   int i = 0,j=0;
    			   Object elem[] = viewer.getExpandedElements();
    			   viewer.setInput(Hoja.cargar());
    			   viewer.expandAll();
    			   Object elem1[] = viewer.getExpandedElements();
    			   viewer.collapseAll();
    			   while(i<elem.length)
    			   {
    				   j=0;
    				   while(j<elem1.length)
    				   {
    					   if(elem[i].toString().equals(elem1[j].toString()))
    					   {
    						   viewer.expandToLevel(elem1[j], 1);
    				   	   }
    					   j++;
    				   }
    				   i++;
    			   }
    			   				   
    			
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    Last edited by janpol1; 02-26-2009 at 03:18 PM.

Similar Threads

  1. Updating a view using actions in a seperate view
    By xcallmejudasx in forum Eclipse
    Replies: 0
    Last Post: 10-24-2008, 10:24 PM
  2. How to create tree view of the given JList implementation
    By aneesahamedaa in forum AWT / Swing
    Replies: 3
    Last Post: 10-06-2008, 03:45 PM
  3. Why my JTree always collasped after refreshing?
    By lmsook10 in forum AWT / Swing
    Replies: 2
    Last Post: 06-24-2008, 06:55 AM
  4. Bug in refreshing jsp
    By anki1234 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-31-2007, 08:09 AM
  5. how to stop refreshing page
    By cecily in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 02:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •