Skip to main content
summaryrefslogtreecommitdiffstats
blob: eb878c0bf32027e44db9939bbc2cac2c64d30fc0 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************************
 * Copyright (c) 2003, 2004 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.jst.j2ee.internal.wizard;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.ui.dialogs.FileSystemElement;
import org.eclipse.ui.model.AdaptableList;
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;

/**
 * The <code>MinimizedFileSystemElement</code> is a <code>FileSystemElement</code> that knows if
 * it has been populated or not.
 */
class MinimizedFileSystemElement extends FileSystemElement {
	private boolean populated = false;
	private String packageBaseDirName = null;


	/**
	 * Create a <code>MinimizedFileSystemElement</code> with the supplied name and parent.
	 * 
	 * @param name
	 *            the name of the file element this represents
	 * @param parent
	 *            the containing parent
	 * @param isDirectory
	 *            indicated if this could have children or not
	 */
	MinimizedFileSystemElement(String name, org.eclipse.ui.dialogs.FileSystemElement parent, boolean isDirectory) {
		super(name, parent, isDirectory);
	}

	public void setPackageBaseDirName(String s) {
		packageBaseDirName = s;
	}

	public void addChild(FileSystemElement child) {
		if (child.isDirectory()) {
			super.addChild(child);
		} else {
			if (child.getFileNameExtension().equals("class")) { //$NON-NLS-1$
				super.addChild(child);
			}
		}
	}

	/**
	 * Returns a list of the files that are immediate children. Use the supplied provider if it
	 * needs to be populated. of this folder.
	 */
	public AdaptableList getFiles(IImportStructureProvider provider) {
		if (!populated)
			populate(provider);

		return super.getFiles();

	}

	/**
	 * Returns a list of the folders that are immediate children. Use the supplied provider if it
	 * needs to be populated. of this folder.
	 */
	public AdaptableList getFolders(IImportStructureProvider provider) {
		if (!populated)
			populate(provider);

		return super.getFolders();

	}

	/**
	 * Return whether or not population has happened for the receiver.
	 */
	boolean isPopulated() {
		return this.populated;
	}

	/**
	 * Return whether or not population has not happened for the receiver.
	 */
	boolean notPopulated() {
		return !this.populated;
	}

	/**
	 * Populate the files and folders of the receiver using the suppliec structure provider.
	 * 
	 * @param provider
	 *            org.eclipse.ui.wizards.datatransfer.IImportStructureProvider
	 */
	private void populate(IImportStructureProvider provider) {

		Object fileSystemObject = getFileSystemObject();

		List children = provider.getChildren(fileSystemObject);
		if (children == null)
			children = new ArrayList(1);
		Iterator childrenEnum = children.iterator();
		while (childrenEnum.hasNext()) {
			Object child = childrenEnum.next();

			String elementLabel = provider.getLabel(child);
			if (elementLabel.equals(packageBaseDirName) || packageBaseDirName == null) {
				//Create one level below

				MinimizedFileSystemElement result = new MinimizedFileSystemElement(elementLabel, this, provider.isFolder(child));
				result.setFileSystemObject(child);
			}
		}
		setPopulated();

	}

	/**
	 * Set whether or not population has happened for the receiver to true.
	 */
	void setPopulated() {
		this.populated = true;
	}
}

Back to the top