01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.wizards.datatransfer;
11:
12: import java.util.ArrayList;
13: import java.util.Iterator;
14: import java.util.List;
15:
16: import org.eclipse.jface.operation.ModalContext;
17: import org.eclipse.ui.dialogs.FileSystemElement;
18: import org.eclipse.ui.internal.wizards.datatransfer.MinimizedFileSystemElement;
19:
20: /**
21: * The PopulateFilesOperation is an operation used to populate a FileSystemElement one
22: * level deep rather than the whole way.
23: */
24: public class PopulateRootOperation extends SelectFilesOperation {
25: /**
26: * Create a new <code>PopulateFilesOperation</code>.
27: * @param rootObject the object to be populated
28: * @param structureProvider the object that defines how we are to populate it.
29: */
30: public PopulateRootOperation(Object rootObject,
31: IImportStructureProvider structureProvider) {
32: super (rootObject, structureProvider);
33: }
34:
35: /**
36: * Creates and returns a <code>FileSystemElement</code> if the specified
37: * file system object merits one. The criteria for this are:
38: * - if the file system object is a container then it must have either a
39: * child container or an associated file
40: * - if the file system object is a file then it must have an extension
41: * suitable for selection
42: */
43: protected FileSystemElement createElement(FileSystemElement parent,
44: Object fileSystemObject) throws InterruptedException {
45:
46: //Iterate on level deep
47: return createElement(parent, fileSystemObject, 2);
48:
49: }
50:
51: /**
52: * Creates and returns a <code>FileSystemElement</code> if the specified
53: * file system object merits one. The criteria for this are:
54: * - if the file system object is a container then it must have either a
55: * child container or an associated file
56: * - if the file system object is a file then it must have an extension
57: * suitable for selection
58: * recurse down for depth to populate children
59: */
60: protected FileSystemElement createElement(FileSystemElement parent,
61: Object fileSystemObject, int depth)
62: throws InterruptedException {
63: ModalContext.checkCanceled(monitor);
64: boolean isContainer = provider.isFolder(fileSystemObject);
65: String 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 children = provider.getChildren(fileSystemObject);
76: if (children == null) {
77: children = new ArrayList(1);
78: }
79: Iterator childrenEnum = children.iterator();
80: while (childrenEnum.hasNext()) {
81: createElement(result, childrenEnum.next(),
82: depth - 1);
83: }
84: result.setPopulated();
85: }
86:
87: }
88:
89: return result;
90: }
91: }
|