KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.jface.operation.ModalContext;
18 import org.eclipse.ui.dialogs.FileSystemElement;
19 import org.eclipse.ui.internal.wizards.datatransfer.MinimizedFileSystemElement;
20
21 /**
22  * The PopulateFilesOperation is an operation used to populate a FileSystemElement one
23  * level deep rather than the whole way.
24  */

25 public class PopulateRootOperation extends SelectFilesOperation {
26     /**
27      * Create a new <code>PopulateFilesOperation</code>.
28      * @param rootObject the object to be populated
29      * @param structureProvider the object that defines how we are to populate it.
30      */

31     public PopulateRootOperation(Object JavaDoc rootObject,
32             IImportStructureProvider structureProvider) {
33         super(rootObject, structureProvider);
34     }
35
36     /**
37      * Creates and returns a <code>FileSystemElement</code> if the specified
38      * file system object merits one. The criteria for this are:
39      * - if the file system object is a container then it must have either a
40      * child container or an associated file
41      * - if the file system object is a file then it must have an extension
42      * suitable for selection
43      */

44     protected FileSystemElement createElement(FileSystemElement parent,
45             Object JavaDoc fileSystemObject) throws InterruptedException JavaDoc {
46
47         //Iterate on level deep
48
return createElement(parent, fileSystemObject, 2);
49
50     }
51
52     /**
53      * Creates and returns a <code>FileSystemElement</code> if the specified
54      * file system object merits one. The criteria for this are:
55      * - if the file system object is a container then it must have either a
56      * child container or an associated file
57      * - if the file system object is a file then it must have an extension
58      * suitable for selection
59      * recurse down for depth to populate children
60      */

61     protected FileSystemElement createElement(FileSystemElement parent,
62             Object JavaDoc fileSystemObject, int depth) throws InterruptedException JavaDoc {
63         ModalContext.checkCanceled(monitor);
64         boolean isContainer = provider.isFolder(fileSystemObject);
65         String JavaDoc elementLabel = parent == null ? provider
66                 .getFullPath(fileSystemObject) : provider
67                 .getLabel(fileSystemObject);
68
69         MinimizedFileSystemElement result = new MinimizedFileSystemElement(
70                 elementLabel, parent, isContainer);
71         result.setFileSystemObject(fileSystemObject);
72
73         if (isContainer) {
74             if (depth > 0) {
75                 List JavaDoc children = provider.getChildren(fileSystemObject);
76                 if (children == null) {
77                     children = new ArrayList JavaDoc(1);
78                 }
79                 Iterator JavaDoc childrenEnum = children.iterator();
80                 while (childrenEnum.hasNext()) {
81                     createElement(result, childrenEnum.next(), depth - 1);
82                 }
83                 result.setPopulated();
84             }
85
86         }
87
88         return result;
89     }
90 }
91
Popular Tags