KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > wizards > datatransfer > MinimizedFileSystemElement


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.wizards.datatransfer;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.ui.dialogs.FileSystemElement;
18 import org.eclipse.ui.model.AdaptableList;
19 import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
20
21 /**
22  * The <code>MinimizedFileSystemElement</code> is a <code>FileSystemElement</code> that knows
23  * if it has been populated or not.
24  */

25 public class MinimizedFileSystemElement extends FileSystemElement {
26     private boolean populated = false;
27
28     /**
29      * Create a <code>MinimizedFileSystemElement</code> with the supplied name and parent.
30      * @param name the name of the file element this represents
31      * @param parent the containing parent
32      * @param isDirectory indicated if this could have children or not
33      */

34     public MinimizedFileSystemElement(String JavaDoc name, FileSystemElement parent,
35             boolean isDirectory) {
36         super(name, parent, isDirectory);
37     }
38
39     /**
40      * Returns a list of the files that are immediate children. Use the supplied provider
41      * if it needs to be populated.
42      * of this folder.
43      */

44     public AdaptableList getFiles(IImportStructureProvider provider) {
45         if (!populated) {
46             populate(provider);
47         }
48         return super.getFiles();
49     }
50
51     /**
52      * Returns a list of the folders that are immediate children. Use the supplied provider
53      * if it needs to be populated.
54      * of this folder.
55      */

56     public AdaptableList getFolders(IImportStructureProvider provider) {
57         if (!populated) {
58             populate(provider);
59         }
60         return super.getFolders();
61     }
62
63     /**
64      * Return whether or not population has happened for the receiver.
65      */

66     boolean isPopulated() {
67         return this.populated;
68     }
69
70     /**
71      * Populate the files and folders of the receiver using the suppliec structure provider.
72      * @param provider org.eclipse.ui.wizards.datatransfer.IImportStructureProvider
73      */

74     private void populate(IImportStructureProvider provider) {
75
76         Object JavaDoc fileSystemObject = getFileSystemObject();
77
78         List JavaDoc children = provider.getChildren(fileSystemObject);
79         if (children == null) {
80             children = new ArrayList JavaDoc(1);
81         }
82         Iterator JavaDoc childrenEnum = children.iterator();
83         while (childrenEnum.hasNext()) {
84             Object JavaDoc child = childrenEnum.next();
85
86             String JavaDoc elementLabel = provider.getLabel(child);
87             //Create one level below
88
MinimizedFileSystemElement result = new MinimizedFileSystemElement(
89                     elementLabel, this, provider.isFolder(child));
90             result.setFileSystemObject(child);
91         }
92         setPopulated();
93     }
94
95     /**
96      * Set whether or not population has happened for the receiver to true.
97      */

98    public void setPopulated() {
99         this.populated = true;
100     }
101 }
102
Popular Tags