1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jface.viewers.ITreeContentProvider; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.ui.model.AdaptableList; 18 19 24 public class WizardContentProvider implements ITreeContentProvider { 25 26 private AdaptableList input; 27 28 33 public void dispose() { 34 input = null; 35 } 36 37 42 public Object [] getChildren(Object parentElement) { 43 if (parentElement instanceof WizardCollectionElement) { 44 ArrayList list = new ArrayList (); 45 WizardCollectionElement element = (WizardCollectionElement) parentElement; 46 47 Object [] childCollections = element.getChildren(); 48 for (int i = 0; i < childCollections.length; i++) { 49 handleChild(childCollections[i], list); 50 } 51 52 Object [] childWizards = element.getWizards(); 53 for (int i = 0; i < childWizards.length; i++) { 54 handleChild(childWizards[i], list); 55 } 56 57 if (list.size() == 1 59 && list.get(0) instanceof WizardCollectionElement) { 60 return getChildren(list.get(0)); 61 } 62 63 return list.toArray(); 64 } else if (parentElement instanceof AdaptableList) { 65 AdaptableList aList = (AdaptableList) parentElement; 66 Object [] children = aList.getChildren(); 67 ArrayList list = new ArrayList (children.length); 68 for (int i = 0; i < children.length; i++) { 69 handleChild(children[i], list); 70 } 71 if (list.size() == 1 73 && list.get(0) instanceof WizardCollectionElement) { 74 return getChildren(list.get(0)); 75 } 76 77 return list.toArray(); 78 } else { 79 return new Object [0]; 80 } 81 } 82 83 88 public Object [] getElements(Object inputElement) { 89 return getChildren(inputElement); 90 } 91 92 97 public Object getParent(Object element) { 98 if (element instanceof WizardCollectionElement) { 99 Object [] children = input.getChildren(); 100 for (int i = 0; i < children.length; i++) { 101 if (children[i].equals(element)) { 102 return input; 103 } 104 } 105 return ((WizardCollectionElement) element).getParent(element); 106 } 107 return null; 108 } 109 110 117 private void handleChild(Object element, ArrayList list) { 118 if (element instanceof WizardCollectionElement) { 119 if (hasChildren(element)) { 120 list.add(element); 121 } 122 } else { 123 list.add(element); 124 } 125 } 126 127 132 public boolean hasChildren(Object element) { 133 if (element instanceof WizardCollectionElement) { 134 if (getChildren(element).length > 0) { 135 return true; 136 } 137 } 138 return false; 139 } 140 141 147 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 148 input = (AdaptableList) newInput; 149 } 150 } 151 | Popular Tags |