KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.InputStream JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.filesystem.EFS;
19 import org.eclipse.core.filesystem.IFileStore;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.NullProgressMonitor;
22 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
23
24 /**
25  * FileStoreStructureProvider is the structure provider for {@link IFileStore}
26  * based file structures.
27  *
28  * @since 3.2
29  *
30  */

31 public class FileStoreStructureProvider implements IImportStructureProvider {
32
33     /**
34      * Holds a singleton instance of this class.
35      */

36     public final static FileStoreStructureProvider INSTANCE = new FileStoreStructureProvider();
37
38     /*
39      * (non-Javadoc)
40      *
41      * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getChildren(java.lang.Object)
42      */

43     public List JavaDoc getChildren(Object JavaDoc element) {
44         try {
45             return Arrays.asList(((IFileStore) element).childStores(EFS.NONE,
46                     new NullProgressMonitor()));
47         } catch (CoreException exception) {
48             logException(exception);
49             return new ArrayList JavaDoc();
50         }
51     }
52
53     /**
54      * Log the exception.
55      *
56      * @param exception
57      */

58     private void logException(CoreException exception) {
59         IDEWorkbenchPlugin.log(exception.getLocalizedMessage(), exception);
60
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getContents(java.lang.Object)
67      */

68     public InputStream JavaDoc getContents(Object JavaDoc element) {
69         try {
70             return ((IFileStore) element).openInputStream(EFS.NONE,
71                     new NullProgressMonitor());
72         } catch (CoreException exception) {
73             logException(exception);
74             return null;
75         }
76     }
77
78     /*
79      * (non-Javadoc)
80      *
81      * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getFullPath(java.lang.Object)
82      */

83     public String JavaDoc getFullPath(Object JavaDoc element) {
84         return ((IFileStore) element).toURI().getSchemeSpecificPart();
85     }
86
87     /*
88      * (non-Javadoc)
89      *
90      * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getLabel(java.lang.Object)
91      */

92     public String JavaDoc getLabel(Object JavaDoc element) {
93         return ((IFileStore) element).getName();
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#isFolder(java.lang.Object)
100      */

101     public boolean isFolder(Object JavaDoc element) {
102         return ((IFileStore) element).fetchInfo().isDirectory();
103     }
104
105 }
106
Popular Tags