|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 Oakland Software Incorporated and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Francis Upton IV, Oakland Software - initial API and implementation |
| 10 |
******************************************************************************/ |
| 11 |
package org.eclipse.ui.tests.navigator.extension; |
| 12 |
|
| 13 |
import java.util.ArrayList; |
| 14 |
import java.util.List; |
| 15 |
|
| 16 |
import org.eclipse.core.resources.IResource; |
| 17 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
| 18 |
import org.eclipse.jface.viewers.Viewer; |
| 19 |
|
| 20 |
/** |
| 21 |
* Provides some children for a given resource. |
| 22 |
*/ |
| 23 |
public class TestSimpleChildrenContentProvider implements ITreeContentProvider { |
| 24 |
|
| 25 |
public String _name; |
| 26 |
|
| 27 |
private Object[] _children; |
| 28 |
|
| 29 |
public class SimpleChild { |
| 30 |
public String _name; |
| 31 |
public IResource _parent; |
| 32 |
|
| 33 |
public String toString() { |
| 34 |
return _name; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
public TestSimpleChildrenContentProvider() { |
| 39 |
} |
| 40 |
|
| 41 |
public Object[] getElements(Object inputElement) { |
| 42 |
return getChildren(inputElement); |
| 43 |
} |
| 44 |
|
| 45 |
public Object[] getChildren(Object parentElement) { |
| 46 |
if (parentElement instanceof IResource) { |
| 47 |
if (_children == null) { |
| 48 |
List l = new ArrayList(); |
| 49 |
for (int i = 0; i < 4; i++) { |
| 50 |
SimpleChild child = new SimpleChild(); |
| 51 |
child._parent = (IResource) parentElement; |
| 52 |
child._name = _name + i; |
| 53 |
l.add(child); |
| 54 |
} |
| 55 |
_children = l.toArray(); |
| 56 |
} |
| 57 |
return _children; |
| 58 |
} |
| 59 |
throw new RuntimeException("Can only be called as a child of a resource"); |
| 60 |
} |
| 61 |
|
| 62 |
public Object getParent(Object element) { |
| 63 |
SimpleChild child = (SimpleChild) element; |
| 64 |
return child._parent; |
| 65 |
} |
| 66 |
|
| 67 |
public boolean hasChildren(Object element) { |
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
public void inputChanged(Viewer aViewer, Object oldInput, Object newInput) { |
| 72 |
_children = null; |
| 73 |
} |
| 74 |
|
| 75 |
public void dispose() { |
| 76 |
} |
| 77 |
} |