KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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

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

29 MinimizedFileSystemElement(String JavaDoc name, FileSystemElement parent, boolean isDirectory) {
30     super(name, parent, isDirectory);
31 }
32 /**
33  * Returns a list of the files that are immediate children. Use the supplied provider
34  * if it needs to be populated.
35  * of this folder.
36  */

37 public AdaptableList getFiles(IImportStructureProvider provider) {
38     if (!populated) {
39         populate(provider);
40     }
41     return super.getFiles();
42 }
43 /**
44  * Returns a list of the folders that are immediate children. Use the supplied provider
45  * if it needs to be populated.
46  * of this folder.
47  */

48 public AdaptableList getFolders(IImportStructureProvider provider) {
49     if (!populated) {
50         populate(provider);
51     }
52     return super.getFolders();
53 }
54 /**
55  * Return whether or not population has happened for the receiver.
56  */

57 boolean isPopulated() {
58     return this.populated;
59 }
60 /**
61  * Return whether or not population has not happened for the receiver.
62  */

63 boolean notPopulated() {
64     return !this.populated;
65 }
66 /**
67  * Populate the files and folders of the receiver using the suppliec structure provider.
68  * @param provider org.eclipse.ui.wizards.datatransfer.IImportStructureProvider
69  */

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

93 void setPopulated() {
94     this.populated = true;
95 }
96 }
97
Popular Tags