1 12 package org.eclipse.debug.internal.ui.views.variables; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.debug.core.DebugException; 20 import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; 21 import org.eclipse.debug.internal.ui.views.AbstractViewerState; 22 import org.eclipse.jface.viewers.TreePath; 23 import org.eclipse.swt.widgets.Tree; 24 import org.eclipse.swt.widgets.TreeItem; 25 26 31 public class ViewerState extends AbstractViewerState { 32 33 public ViewerState() { 34 } 35 36 39 public ViewerState(AsynchronousTreeViewer viewer) { 40 super(viewer); 41 } 42 43 46 protected IPath encodeElement(TreeItem item) throws DebugException { 47 StringBuffer path = new StringBuffer (); 48 TreeItem parent = item.getParentItem(); 49 while (parent != null) { 50 int i = parent.indexOf(item); 51 path.insert(0, i); 52 path.insert(0, '/'); 53 item = parent; 54 parent = item.getParentItem(); 55 } 56 Tree tree = item.getParent(); 57 int i = tree.indexOf(item); 58 path.insert(0, i); 59 return new Path(path.toString()); 60 } 61 62 66 protected TreePath decodePath(IPath path, AsynchronousTreeViewer viewer) throws DebugException { 67 String [] indicies = path.segments(); 68 if (indicies.length == 0) { 69 return null; 70 } 71 Tree tree = viewer.getTree(); 72 int index = -1; 73 try { 74 index = Integer.parseInt(indicies[0]); 75 } catch (NumberFormatException e) { 76 return null; 77 } 78 TreeItem item = null; 79 if (index < tree.getItemCount()) { 80 item = tree.getItem(index); 81 } else { 82 return null; 83 } 84 85 List elements = new ArrayList (); 86 elements.add(viewer.getInput()); 87 Object element = item.getData(); 88 if (element != null) { 89 elements.add(element); 90 } else { 91 return null; 92 } 93 94 for (int i = 1; i < indicies.length; i++) { 95 try { 96 index = Integer.parseInt(indicies[i]); 97 } catch (NumberFormatException e) { 98 return null; 99 } 100 if (index < item.getItemCount()) { 101 item = item.getItem(index); 102 } else { 103 break; } 105 element = item.getData(); 106 if (element != null) { 107 elements.add(element); 108 } else { 109 break; } 111 } 112 113 return new TreePath(elements.toArray()); 114 } 115 116 117 } 118 | Popular Tags |