Search in sources :

Example 6 with FileSystemElement

use of org.eclipse.ui.dialogs.FileSystemElement in project linuxtools by eclipse.

the class SelectFilesOperation method createElement.

/**
 * Creates and returns a <code>FileSystemElement</code> if the specified
 * file system object merits one. The criteria for this are: - if the file
 * system object is a container then it must have either a child container
 * or an associated file - if the file system object is a file then it must
 * have an extension suitable for selection
 */
@SuppressWarnings("rawtypes")
protected FileSystemElement createElement(FileSystemElement parent, Object fileSystemObject) throws InterruptedException {
    ModalContext.checkCanceled(monitor);
    boolean isContainer = provider.isFolder(fileSystemObject);
    String elementLabel = parent == null ? provider.getFullPath(fileSystemObject) : provider.getLabel(fileSystemObject);
    if (!isContainer && !hasDesiredExtension(elementLabel)) {
        return null;
    }
    FileSystemElement result = new FileSystemElement(elementLabel, parent, isContainer);
    result.setFileSystemObject(fileSystemObject);
    if (isContainer) {
        boolean haveChildOrFile = false;
        List children = provider.getChildren(fileSystemObject);
        if (children == null) {
            children = new ArrayList(1);
        }
        Iterator childrenEnum = children.iterator();
        while (childrenEnum.hasNext()) {
            if (createElement(result, childrenEnum.next()) != null) {
                haveChildOrFile = true;
            }
        }
        if (!haveChildOrFile && parent != null) {
            parent.removeFolder(result);
            result = null;
        }
    }
    return result;
}
Also used : FileSystemElement(org.eclipse.ui.dialogs.FileSystemElement) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

FileSystemElement (org.eclipse.ui.dialogs.FileSystemElement)6 ArrayList (java.util.ArrayList)4 Composite (org.eclipse.swt.widgets.Composite)4 Iterator (java.util.Iterator)3 List (java.util.List)3 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)3 SWT (org.eclipse.swt.SWT)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)3 WorkbenchViewerComparator (org.eclipse.ui.model.WorkbenchViewerComparator)3 ContainerFileProxy (org.eclipse.linuxtools.internal.docker.core.ContainerFileProxy)2 MinimizedFileSystemElement (org.eclipse.linuxtools.internal.docker.ui.MinimizedFileSystemElement)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 GridData (org.eclipse.swt.layout.GridData)2 Control (org.eclipse.swt.widgets.Control)2 Shell (org.eclipse.swt.widgets.Shell)2 SelectionDialog (org.eclipse.ui.dialogs.SelectionDialog)2 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)2 IImportStructureProvider (org.eclipse.ui.wizards.datatransfer.IImportStructureProvider)2