001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.wizards.datatransfer;
011:
012: import java.util.ArrayList;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: import org.eclipse.ui.dialogs.FileSystemElement;
017: import org.eclipse.ui.model.AdaptableList;
018: import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
019:
020: /**
021: * The <code>MinimizedFileSystemElement</code> is a <code>FileSystemElement</code> that knows
022: * if it has been populated or not.
023: */
024: public class MinimizedFileSystemElement extends FileSystemElement {
025: private boolean populated = false;
026:
027: /**
028: * Create a <code>MinimizedFileSystemElement</code> with the supplied name and parent.
029: * @param name the name of the file element this represents
030: * @param parent the containing parent
031: * @param isDirectory indicated if this could have children or not
032: */
033: public MinimizedFileSystemElement(String name,
034: FileSystemElement parent, boolean isDirectory) {
035: super (name, parent, isDirectory);
036: }
037:
038: /**
039: * Returns a list of the files that are immediate children. Use the supplied provider
040: * if it needs to be populated.
041: * of this folder.
042: */
043: public AdaptableList getFiles(IImportStructureProvider provider) {
044: if (!populated) {
045: populate(provider);
046: }
047: return super .getFiles();
048: }
049:
050: /**
051: * Returns a list of the folders that are immediate children. Use the supplied provider
052: * if it needs to be populated.
053: * of this folder.
054: */
055: public AdaptableList getFolders(IImportStructureProvider provider) {
056: if (!populated) {
057: populate(provider);
058: }
059: return super .getFolders();
060: }
061:
062: /**
063: * Return whether or not population has happened for the receiver.
064: */
065: boolean isPopulated() {
066: return this .populated;
067: }
068:
069: /**
070: * Populate the files and folders of the receiver using the suppliec structure provider.
071: * @param provider org.eclipse.ui.wizards.datatransfer.IImportStructureProvider
072: */
073: private void populate(IImportStructureProvider provider) {
074:
075: Object fileSystemObject = getFileSystemObject();
076:
077: List children = provider.getChildren(fileSystemObject);
078: if (children == null) {
079: children = new ArrayList(1);
080: }
081: Iterator childrenEnum = children.iterator();
082: while (childrenEnum.hasNext()) {
083: Object child = childrenEnum.next();
084:
085: String elementLabel = provider.getLabel(child);
086: //Create one level below
087: MinimizedFileSystemElement result = new MinimizedFileSystemElement(
088: elementLabel, this , provider.isFolder(child));
089: result.setFileSystemObject(child);
090: }
091: setPopulated();
092: }
093:
094: /**
095: * Set whether or not population has happened for the receiver to true.
096: */
097: public void setPopulated() {
098: this .populated = true;
099: }
100: }
|