[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Comparing treePath selections

Posted on 2004-08-19
20
Medium Priority
?
206 Views
Last Modified: 2009-07-29
I want to keep track of nodes selected in  a tree such that a node or  a child which is already selected cannot be selected again.i tried using getLeadSelectionPath() and getOldLeadSelectionPath() but the comparison was not producing any good results.i also thought of  using  Object[] path=paths[i].getPath() to store the nodes in say String[] and probably loop through to see whether a new selected item is already stored.
Can anybody help...
Thanks in advance.
0
Comment
Question by:rjopata
  • 10
  • 7
  • 3
20 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11842799
Hi rjopata,

can you not just disable the nodes you visit? Call getTreeCellEditorComponent()  and pass it the node. Then call setEnable(false) on the component. This should disable it and not be able to select it again.

Regards
0
 

Author Comment

by:rjopata
ID: 11842878
Hi girionis thanks for ur quick response.i actually dont want to disable it completely becuase that prevents any further action to be taken on that node.rather i want to let the user know the node has been selected and if there is a change in decision something else could be done to the node then.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11842914
Since you already have the node selected can you not put it in a Vector? Then with each other node selected just go throuhg the vector and see if it is already there. Can you post some code?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:rjopata
ID: 11842984
that was exactly my initial intention as i posted.but the problem i forsee is with a large tree then lots of data needs to be stored just to locate a child down the tree and thought probably there exists a better way out.
Sorry i cannot post some code now since i wanted to have opinions before trying to put in an array or Vector as u put it.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11843020
I am not sure of any better way but I would stick with a collections object, at least for start. Make it work first and optimize later :) But it would be intersting what othre peopel can come up with, lets wait for more suggestions.
0
 

Author Comment

by:rjopata
ID: 11843531
thanks.lets see what others have.someone might come up with a magic touch.
0
 
LVL 92

Expert Comment

by:objects
ID: 11846790
A Set would would perhaps handle it better than a Vector.
0
 

Author Comment

by:rjopata
ID: 11849599
sounds like the expert is approving the intended solution but with a better option.
i never used Set, would u like to educate 'objects' please?
0
 
LVL 92

Expert Comment

by:objects
ID: 11849622
Set is a collection where all elements are unique.
http://java.sun.com/docs/books/tutorial/collections/interfaces/set.html
0
 

Author Comment

by:rjopata
ID: 11850642
thanks objects for the link provided.
0
 

Author Comment

by:rjopata
ID: 11857901
objects ur link presents a solution but i'm still not clear abt this problem i have here :
a node/child selected in the tree can be assigned 4 or even more values say from a combo box.
how do i keep track of these two distinct values ie the node/child and the values assigned from the combo box.in my case i need to store both the node and its distinct corresponding values from the combo box so that if i reselect the node i know oh this node is already selected and has that distinct values.
please any ideas ????
0
 
LVL 35

Expert Comment

by:girionis
ID: 11858229
0
 

Author Comment

by:rjopata
ID: 11859603
Sorry for missing out on ur comment girionis.well i guess with the HashMap using Object put(Object key, Object value) will do but in this case Object value itself is a String [] consisting of say 4 of more items.iterating through the HashMap will surely not retrieve the String [] items and might event  result in a class cast exception.
0
 

Author Comment

by:rjopata
ID: 11865560
can somebody rewrite the code below or produce a similar one to reflect what i'm thinking of
basically i want to store elements from the combo box in an ArrayList and with a selected node use the hashmap appropriately.

HashMap collect=new HashMap();
//initialize ArrayList with selected items from combo box
ArrayList ar=new ArrayList();
ar.add(combo1.getSelectedItem());
ar.add(combo2.getSelectedItem());
ar.add(combo3.getSelectedItem());
ar.add(combo4.getSelectedItem());
ar.add(combo5.getSelectedItem());
//put items in hashmap
m.put(new String("node selected"),ar);
//print out key and values
System.out.println(m)
0
 
LVL 35

Expert Comment

by:girionis
ID: 11867563
>  will do but in this case Object value itself is a String [] consisting of say 4 of more items

I do not see this being a problem

String [] array = {"1", "2", "3", "4"};
            
HashMap map = new HashMap();
map.put("array", array);
String [] ar = (String []) map.get("array");
0
 

Author Comment

by:rjopata
ID: 11867632
thanks girionis for the above.well i guess i have to carefully read the Map interface to get things right but can u kindly produce a code that will retrieve the key in the above case as well as the elements of the String (not as a set).
0
 
LVL 35

Accepted Solution

by:
girionis earned 300 total points
ID: 11867645
String [] array = {"1", "2", "3", "4"};
         
HashMap map = new HashMap();
map.put("numbers", array);
String [] ar = (String []) map.get("numbers");

The "numbers" is the key of the hash map.

To iterate through the elements of the "ar" you can do:

for (int i=0; i<ar.length; i++)
{
    System.out.println(ar[i]);
}
0
 
LVL 92

Expert Comment

by:objects
ID: 11867673
what else would go in the map?
0
 

Author Comment

by:rjopata
ID: 11867705
> what else would go in the Map ?
objects distinct nodes and corresponding selected items from a combo box.so for a selected node i collect items selected in a combo box and put all in a hashmap.the idea is to show the items in the combo box back again if the same node is reselected.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11914177
:)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question