1 11 package org.eclipse.jface.preference; 12 13 import org.eclipse.jface.viewers.ITreeContentProvider; 14 import org.eclipse.jface.viewers.Viewer; 15 16 21 public class PreferenceContentProvider implements ITreeContentProvider { 22 23 private PreferenceManager manager; 24 25 28 public void dispose() { 29 manager = null; 30 } 31 32 40 private IPreferenceNode findParent(IPreferenceNode parent, 41 IPreferenceNode target) { 42 if (parent.getId().equals(target.getId())) { 43 return null; 44 } 45 46 IPreferenceNode found = parent.findSubNode(target.getId()); 47 if (found != null) { 48 return parent; 49 } 50 51 IPreferenceNode[] children = parent.getSubNodes(); 52 53 for (int i = 0; i < children.length; i++) { 54 found = findParent(children[i], target); 55 if (found != null) { 56 return found; 57 } 58 } 59 60 return null; 61 } 62 63 67 public Object [] getChildren(Object parentElement) { return ((IPreferenceNode) parentElement).getSubNodes(); 69 } 70 71 75 public Object [] getElements(Object inputElement) { return getChildren(((PreferenceManager) inputElement).getRoot()); 77 } 78 79 83 public Object getParent(Object element) { IPreferenceNode targetNode = (IPreferenceNode) element; 85 IPreferenceNode root = manager.getRoot(); 86 return findParent(root, targetNode); 87 } 88 89 92 public boolean hasChildren(Object element) { 93 return getChildren(element).length > 0; 94 } 95 96 99 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 100 manager = (PreferenceManager) newInput; 101 } 102 108 protected void setManager(PreferenceManager manager) { 109 this.manager = manager; 110 } 111 } 112 | Popular Tags |