1 19 20 package org.apache.jmeter.module.nodes; 21 22 import java.text.Collator ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.Comparator ; 26 import java.util.SortedSet ; 27 import java.util.TreeSet ; 28 import org.apache.jmeter.module.cookies.JMeterCookie; 29 import org.apache.jmeter.testelement.TestElement; 30 import org.apache.jorphan.collections.HashTree; 31 import org.openide.nodes.Children; 32 import org.openide.nodes.Node; 33 34 38 public class JMeterElementChildren extends Children.Keys implements Comparator <TestElement> { 39 private static Collator SORTER = Collator.getInstance(); 40 41 private SortedSet <TestElement> allTestElements; 42 private HashTree nodeTree = null; 43 44 public JMeterElementChildren(final HashTree tree) { 45 nodeTree = tree; 46 } 47 48 public void rebind(final HashTree tree) { 49 nodeTree = tree; 50 allTestElements = null; 51 refreshKeys(true); 52 } 53 54 @Override 55 protected void addNotify() { 56 super.addNotify(); 57 refreshKeys(true); 58 } 59 60 @Override 61 protected void removeNotify() { 62 super.removeNotify(); 63 setKeys(Collections.EMPTY_SET); 64 synchronized (this) { 65 allTestElements = null; 66 } 67 } 68 69 @Override 70 protected Node[] createNodes(Object key) { 71 TestElement t = (TestElement) key; 72 73 return new Node[] {new JMeterElementNode(t, nodeTree.getTree(t))}; 75 } 76 77 public int compare(TestElement t1, TestElement t2) { 78 int x = SORTER.compare(t1.getProperty("TestElement.name").getStringValue(), t2.getProperty("TestElement.name").getStringValue()); 79 if (x != 0 || t1 == t2) { 80 return x; 81 } else { 82 return System.identityHashCode(t1) - System.identityHashCode(t2); 84 } 85 } 86 87 private void refreshKeys(boolean createKeys) { 88 Collection keys = null; 89 synchronized (this) { 90 if (allTestElements == null && !createKeys) { 91 return; 93 } 94 allTestElements = new TreeSet <TestElement>(this); 95 for(Object elementObj : nodeTree.list()) { 97 allTestElements.add((TestElement)elementObj); 98 } 99 keys = allTestElements; 101 } 105 if (keys != null) { setKeys(keys); 107 } 108 } 109 110 } 111 | Popular Tags |