Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 9b8690f286ab41eb2ee38061fefc7dfc38ca0ec8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jem.internal.beaninfo.ui;
/*


 */


import org.eclipse.jdt.ui.StandardJavaElementContentProvider;

import org.eclipse.jdt.core.IPackageFragment;
import java.util.*;
/**
 * A content provider which will only go down to the package level,
 * it won't explore further. The advantage of this is so that plus signs ('+')
 * won't show up on packages. The Filter technique could be used to not
 * show the children, but this still shows the plus sign.
 *
 * Also, if the element is a java.util.List, then that list will be returned
 * as the children. This allows for a root to be composed instead of being
 * one of the standard Java Elements.
 */

public class PackageOnlyContentProvider extends StandardJavaElementContentProvider {
	
	/**
	 * If the element is a list, return the iterator on it.
	 * Else send it up the chain.
	 */
	public Object[] getChildren(Object element) {
		if (element instanceof List)
			return ((List) element).toArray();
		return super.getChildren(element);
	}
	
	/**
	 * If the element is a list and it is not empty, it has children,
	 * if it is a IPackageFragment it does not,
	 * else send it up the chain.
	 */
	public boolean hasChildren(Object element) {
		if (element instanceof List)
			return !((List) element).isEmpty();
		if (element instanceof IPackageFragment)
			return false;
		return super.hasChildren(element);
	}
}

Back to the top