KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > provider > AdapterFactoryTreeIterator


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: AdapterFactoryTreeIterator.java,v 1.2 2005/06/08 06:17:05 nickb Exp $
16  */

17 package org.eclipse.emf.edit.provider;
18
19
20 import java.util.Collections JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import org.eclipse.emf.common.notify.AdapterFactory;
24 import org.eclipse.emf.common.util.AbstractTreeIterator;
25
26
27 /**
28  * This implements a tree iterator that iterates over an object, it's children, their children, and so on,
29  * use the {@link ITreeItemContentProvider}s produced by an adapter factory.
30  */

31 public class AdapterFactoryTreeIterator extends AbstractTreeIterator
32 {
33   /**
34    * This keeps track of the factory used to generate the ITreeItemContentProvider adapters.
35    */

36   protected AdapterFactory adapterFactory;
37
38   /**
39    * This constructs tree iterator that iterates over an object, it's children, their children, and so on.
40    */

41   public AdapterFactoryTreeIterator(AdapterFactory adapterFactory, Object JavaDoc object)
42   {
43     super(object);
44     this.adapterFactory = adapterFactory;
45   }
46
47   /**
48    * This constructs tree iterator that iterates over an object (but only if includeRoot is true),
49    * it's children, their children, and so on.
50    */

51   public AdapterFactoryTreeIterator(AdapterFactory adapterFactory, Object JavaDoc object, boolean includeRoot)
52   {
53     super(object, includeRoot);
54     this.adapterFactory = adapterFactory;
55   }
56
57   protected Iterator JavaDoc getChildren(Object JavaDoc o)
58   {
59     ITreeItemContentProvider treeItemContentProvider = (ITreeItemContentProvider)adapterFactory.adapt(o, ITreeItemContentProvider.class);
60     return
61       treeItemContentProvider != null ?
62         treeItemContentProvider.getChildren(o).iterator() :
63         Collections.EMPTY_LIST.iterator();
64   }
65 }
66
Popular Tags