Exemple #1
0
 public TreePath[] getPathsFor(Object element) {
   Object value = element2TreePaths == null ? null : element2TreePaths.get(element);
   if (value == null) {
     return EMPTY_TREE_PATHS;
   } else if (value instanceof TreePath) {
     return new TreePath[] {(TreePath) value};
   } else if (value instanceof List) {
     List l = (List) value;
     return (TreePath[]) l.toArray(new TreePath[l.size()]);
   } else {
     // should not happen:
     Assert.isTrue(false, "Unhandled case"); // $NON-NLS-1$
     return null;
   }
 }
Exemple #2
0
 private InitializeData(TreePath[] paths, IElementComparer comparer) {
   this.paths = new TreePath[paths.length];
   System.arraycopy(paths, 0, this.paths, 0, paths.length);
   element2TreePaths = new CustomHashtable(comparer);
   int size = paths.length;
   selection = new ArrayList(size);
   for (int i = 0; i < size; i++) {
     Object lastSegment = paths[i].getLastSegment();
     Object mapped = element2TreePaths.get(lastSegment);
     if (mapped == null) {
       selection.add(lastSegment);
       element2TreePaths.put(lastSegment, paths[i]);
     } else if (mapped instanceof List) {
       ((List) mapped).add(paths[i]);
     } else {
       List newMapped = new ArrayList(2);
       newMapped.add(mapped);
       newMapped.add(paths[i]);
       element2TreePaths.put(lastSegment, newMapped);
     }
   }
 }