1 11 package org.eclipse.ui.model; 12 13 import java.lang.reflect.Array ; 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.Assert; 19 import org.eclipse.core.runtime.IAdaptable; 20 21 32 public class AdaptableList extends WorkbenchAdapter implements IAdaptable { 33 34 protected List children = null; 35 36 40 public AdaptableList() { 41 children = new ArrayList (); 42 } 43 44 50 public AdaptableList(int initialCapacity) { 51 children = new ArrayList (initialCapacity); 52 } 53 54 59 public AdaptableList(IAdaptable[] newChildren) { 60 this(newChildren.length); 61 for (int i = 0; i < newChildren.length; i++) { 62 children.add(newChildren[i]); 63 } 64 } 65 66 74 public AdaptableList(Collection c) { 75 this(c.size()); 76 children.addAll(c); 77 } 78 79 85 public AdaptableList add(IAdaptable adaptable) { 86 Assert.isNotNull(adaptable); 87 children.add(adaptable); 88 return this; 89 } 90 91 96 public void remove(IAdaptable adaptable) { 97 Assert.isNotNull(adaptable); 98 children.remove(adaptable); 99 } 100 101 106 public int size() { 107 return children.size(); 108 } 109 110 113 public Object getAdapter(Class adapter) { 114 if (adapter == IWorkbenchAdapter.class) { 115 return this; 116 } 117 return null; 118 } 119 120 123 public Object [] getChildren(Object o) { 124 return children.toArray(); 126 } 127 128 133 public Object [] getChildren() { 134 return children.toArray(); 135 } 136 137 144 public Object [] getTypedChildren(Class type) { 145 return children.toArray((Object []) Array.newInstance(type, children 146 .size())); 147 } 148 149 152 public String toString() { 153 return children.toString(); 154 } 155 } 156 | Popular Tags |