001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.wizards.datatransfer;
011:
012: import java.io.InputStream;
013: import java.util.ArrayList;
014: import java.util.Arrays;
015: import java.util.List;
016:
017: import org.eclipse.core.filesystem.EFS;
018: import org.eclipse.core.filesystem.IFileStore;
019: import org.eclipse.core.runtime.CoreException;
020: import org.eclipse.core.runtime.NullProgressMonitor;
021: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
022:
023: /**
024: * FileStoreStructureProvider is the structure provider for {@link IFileStore}
025: * based file structures.
026: *
027: * @since 3.2
028: *
029: */
030: public class FileStoreStructureProvider implements
031: IImportStructureProvider {
032:
033: /**
034: * Holds a singleton instance of this class.
035: */
036: public final static FileStoreStructureProvider INSTANCE = new FileStoreStructureProvider();
037:
038: /*
039: * (non-Javadoc)
040: *
041: * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getChildren(java.lang.Object)
042: */
043: public List getChildren(Object element) {
044: try {
045: return Arrays.asList(((IFileStore) element).childStores(
046: EFS.NONE, new NullProgressMonitor()));
047: } catch (CoreException exception) {
048: logException(exception);
049: return new ArrayList();
050: }
051: }
052:
053: /**
054: * Log the exception.
055: *
056: * @param exception
057: */
058: private void logException(CoreException exception) {
059: IDEWorkbenchPlugin.log(exception.getLocalizedMessage(),
060: exception);
061:
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getContents(java.lang.Object)
068: */
069: public InputStream getContents(Object element) {
070: try {
071: return ((IFileStore) element).openInputStream(EFS.NONE,
072: new NullProgressMonitor());
073: } catch (CoreException exception) {
074: logException(exception);
075: return null;
076: }
077: }
078:
079: /*
080: * (non-Javadoc)
081: *
082: * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getFullPath(java.lang.Object)
083: */
084: public String getFullPath(Object element) {
085: return ((IFileStore) element).toURI().getSchemeSpecificPart();
086: }
087:
088: /*
089: * (non-Javadoc)
090: *
091: * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#getLabel(java.lang.Object)
092: */
093: public String getLabel(Object element) {
094: return ((IFileStore) element).getName();
095: }
096:
097: /*
098: * (non-Javadoc)
099: *
100: * @see org.eclipse.ui.wizards.datatransfer.IImportStructureProvider#isFolder(java.lang.Object)
101: */
102: public boolean isFolder(Object element) {
103: return ((IFileStore) element).fetchInfo().isDirectory();
104: }
105:
106: }
|