Changeset 164 for trunk/EventBenchConsole/src/de/ugoe/cs
- Timestamp:
- 08/16/11 18:29:34 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swing/DlgInsert.java
r155 r164 3 3 import java.awt.BorderLayout; 4 4 import java.util.ArrayList; 5 import java.util.Enumeration; 5 6 import java.util.List; 6 7 … … 33 34 import javax.swing.tree.DefaultTreeModel; 34 35 import javax.swing.tree.DefaultMutableTreeNode; 36 import javax.swing.tree.TreePath; 37 import javax.swing.event.TreeSelectionListener; 38 import javax.swing.event.TreeSelectionEvent; 35 39 36 40 public class DlgInsert extends JDialog { … … 81 85 final JComboBox comboBoxTestcase = new JComboBox(); 82 86 final JPanel panelTextEquals = new JPanel(); 83 panelTextEquals.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); 87 panelTextEquals.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, 88 null)); 84 89 final JPanel panelFileEquals = new JPanel(); 85 panelFileEquals.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); 90 panelFileEquals.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, 91 null)); 86 92 87 93 // JComboBox: comboBoxTestcase … … 140 146 panelTextEquals.add(scrollPane); 141 147 142 final JList listTargets = new JList(modelListTargets); 148 final JList listTargets = new JList(modelListTargets); 143 149 scrollPane.setViewportView(listTargets); 144 150 145 151 JScrollPane scrollPane_1 = new JScrollPane(); 146 152 scrollPane_1.setBounds(10, 63, 474, 276); 147 153 panelTextEquals.add(scrollPane_1); 148 149 //JTree to hold the targets 150 JTree tree = new JTree(); 151 tree.setModel(new DefaultTreeModel( 152 new DefaultMutableTreeNode("Targets") { 153 { 154 List<DefaultMutableTreeNode> nodes = new ArrayList<DefaultMutableTreeNode>(); 155 List<String> listTargets = new ArrayList<String>(); 156 List<String> sortedTargets = new ArrayList<String>(); 157 158 try { 159 listTargets = (List<String>) GlobalDataContainer.getInstance().getData("ListTargets"); 160 } 161 catch (ClassCastException e) { 162 Console.println("Not able to cast data in GlobalDataContainer to List of Strings"); 163 } 164 165 int parts = 1; 166 while(sortedTargets.size() < listTargets.size()) { 167 for(int i=0; i<listTargets.size(); i++) { 168 String splitted[] = listTargets.get(i).split("/>"); 169 if(splitted.length == parts) { 170 sortedTargets.add(listTargets.get(i)); 171 modelListTargets.addElement(listTargets.get(i)); 172 173 //insert in tree 174 boolean inserted = false; 175 for(int j=parts-2; j>=0 && !inserted; j--) { 176 splitted[j] = splitted[j] + "/>"; 177 for(int k=0; k<nodes.size(); k++) { 178 if(nodes.get(k).toString().compareTo(splitted[j]) == 0) { 179 DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(splitted[j+1]); 180 nodes.add(newNode); 181 nodes.get(k).add(newNode); 182 inserted = true; 183 break; 184 } 185 } 186 } 187 188 if(!inserted) { 189 DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(listTargets.get(i).toString()); 190 nodes.add(newNode); 191 add(newNode); 192 } 154 155 // JTree to hold the targets 156 final JTree tree = new JTree(); 157 tree.addTreeSelectionListener(new TreeSelectionListener() { 158 public void valueChanged(TreeSelectionEvent arg0) { 159 TreePath path = tree.getSelectionPath(); 160 textFieldExpectedValue.setText(path.toString()); 161 } 162 }); 163 DefaultTreeModel treeModel = new DefaultTreeModel(null); 164 DefaultMutableTreeNode root = new DefaultMutableTreeNode("Targets"); 165 treeModel.setRoot(root); 166 tree.setModel(treeModel); 167 168 // List<DefaultMutableTreeNode> nodes = new 169 // ArrayList<DefaultMutableTreeNode>(); 170 List<String> listTargets1 = new ArrayList<String>(); // targets out of 171 // GlobalDataContainer 172 List<String> sortedTargets = new ArrayList<String>(); // targets will be 173 // sorted by 174 // number of 175 // parts, 176 // splitted at 177 // "/>" 178 179 try { 180 listTargets1 = (List<String>) GlobalDataContainer.getInstance() 181 .getData("ListTargets"); 182 } catch (ClassCastException e) { 183 Console.println("Not able to cast data in GlobalDataContainer to List of Strings"); 184 } 185 186 int parts = 1; 187 while (sortedTargets.size() < listTargets1.size()) { 188 for (int i = 0; i < listTargets1.size(); i++) { 189 String splitted[] = listTargets1.get(i).split("/>"); 190 191 // sort targets by number of parts 192 if (splitted.length != parts) 193 continue; 194 195 sortedTargets.add(listTargets1.get(i)); 196 197 // insert in tree 198 DefaultMutableTreeNode node = compareTargetWithNode(root, 199 listTargets1.get(i)); 200 201 if (node == null) { 202 DefaultMutableTreeNode newNode[] = new DefaultMutableTreeNode[splitted.length]; 203 204 for (int j = 0; j < splitted.length; j++) { 205 newNode[j] = new DefaultMutableTreeNode(splitted[j] 206 + "/>"); 207 208 if (j == 0) { 209 root.add(newNode[0]); 210 } else { 211 newNode[j - 1].add(newNode[j]); 212 } 213 } 214 } else { 215 for (int j = 0; j < splitted.length; j++) { 216 if (node.toString().compareTo(splitted[j] + "/>") != 0) 217 continue; 218 219 DefaultMutableTreeNode newNode[] = new DefaultMutableTreeNode[splitted.length 220 - j - 1]; 221 for (int k = 0; k < newNode.length; k++) { 222 newNode[k] = new DefaultMutableTreeNode(splitted[j 223 + k + 1] 224 + "/>"); 225 226 if (k == 0) { 227 node.add(newNode[0]); 228 } else { 229 newNode[k - 1].add(newNode[k]); 193 230 } 194 231 } 195 196 parts++;197 232 } 198 233 } 199 234 } 200 )); 235 parts++; 236 } 201 237 scrollPane_1.setViewportView(tree); 202 203 238 204 239 if (listTargets.getComponentCount() > 0) … … 242 277 { 243 278 JPanel buttonPane = new JPanel(); 244 buttonPane.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); 279 buttonPane.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, 280 null)); 245 281 buttonPane.setBounds(12, 531, 494, 51); 246 282 contentPanel.add(buttonPane); … … 355 391 // *** 356 392 } 393 394 DefaultMutableTreeNode compareTargetWithNode(DefaultMutableTreeNode node, 395 String target) { 396 397 if (node.isLeaf()) { 398 if (target.contains(node.toString())) 399 return node; 400 else 401 return null; 402 } else { 403 for (@SuppressWarnings("unchecked") 404 Enumeration<DefaultMutableTreeNode> e = node.children(); e 405 .hasMoreElements();) { 406 DefaultMutableTreeNode nodeReturn = compareTargetWithNode( 407 e.nextElement(), target); 408 if (nodeReturn == null) { 409 if (target.contains(node.toString())) 410 return node; 411 } else 412 return nodeReturn; 413 } 414 } 415 416 return null; 417 } 357 418 }
Note: See TracChangeset
for help on using the changeset viewer.