Example usage for org.apache.commons.vfs2 FileObject getName

List of usage examples for org.apache.commons.vfs2 FileObject getName

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject getName.

Prototype

FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java

/**
 * Returns the number of children of <code>parent</code>. Returns 0 if the node is a leaf or if it has no children.
 * <code>parent</code> must be a node previously obtained from this data source.
 *
 * @param parent/*from ww  w .ja v  a  2  s  . co  m*/
 *          a node in the tree, obtained from this data source
 * @return the number of children of the node <code>parent</code>
 */
public int getChildCount(Object parent) {
    if (parent instanceof RepositoryTreeRoot) {
        final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
        parent = root1.getRoot();
        if (parent == null) {
            return 0;
        }
    }
    try {
        final FileObject parElement = (FileObject) parent;
        if (parElement.getType() != FileType.FOLDER) {
            return 0;
        }

        final FileObject[] children = parElement.getChildren();
        int count = 0;
        for (int i = 0; i < children.length; i++) {
            final FileObject child = children[i];
            if (isShowFoldersOnly() && child.getType() != FileType.FOLDER) {
                continue;
            }
            if (isShowHiddenFiles() == false && child.isHidden()) {
                continue;
            }
            if (child.getType() != FileType.FOLDER
                    && PublishUtil.acceptFilter(filters, child.getName().getBaseName()) == false) {
                continue;
            }

            count += 1;
        }
        return count;
    } catch (FileSystemException fse) {
        logger.debug("Failed", fse);
        return 0;
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModel.java

/**
 * Returns the index of child in parent. If either <code>parent</code> or <code>child</code> is <code>null</code>,
 * returns -1. If either <code>parent</code> or <code>child</code> don't belong to this tree model, returns -1.
 *
 * @param parent/*from   w  w w  .j ava  2s .co  m*/
 *          a note in the tree, obtained from this data source
 * @param childNode
 *          the node we are interested in
 * @return the index of the child in the parent, or -1 if either <code>child</code> or <code>parent</code> are
 *         <code>null</code> or don't belong to this tree model
 */
public int getIndexOfChild(Object parent, final Object childNode) {
    if (parent instanceof RepositoryTreeRoot) {
        final RepositoryTreeRoot root1 = (RepositoryTreeRoot) parent;
        parent = root1.getRoot();
        if (parent == null) {
            return -1;
        }
    }

    try {
        final FileObject parChild = (FileObject) childNode;
        final FileObject parElement = (FileObject) parent;
        final FileObject[] childs = parElement.getChildren();
        int count = 0;
        for (int i = 0; i < childs.length; i++) {
            final FileObject child = childs[i];
            if (isShowFoldersOnly() && child.getType() != FileType.FOLDER) {
                continue;
            }
            if (isShowHiddenFiles() == false && child.isHidden()) {
                continue;
            }
            if (child.getType() != FileType.FOLDER
                    && PublishUtil.acceptFilter(filters, child.getName().getBaseName()) == false) {
                continue;
            }

            if (child.getName().equals(parChild.getName())) {
                return count;
            }

            count += 1;
        }

        return -1;
    } catch (FileSystemException fse) {
        logger.debug("Failed", fse);
        return -1;
    }
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.util.RepositoryTreeCellRenderer.java

public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel,
        final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
    final JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
            hasFocus);/* w  w  w.j a  va  2 s  .  c o  m*/
    if (value instanceof FileObject) {
        final FileObject node = (FileObject) value;
        try {
            if (leaf && (node.getType() == FileType.FOLDER)) {
                component.setIcon(getOpenIcon());
            }
        } catch (FileSystemException fse) {
            // ignore exception here
        }
        component.setText(node.getName().getBaseName());
    } else {
        component.setText("/");
        component.setIcon(getOpenIcon());
    }
    return component;
}

From source file:org.pentaho.vfs.test.FileChooserTest.java

public static void main(String args[]) {
    FileSystemManager fsManager = null;//w  ww . j a v a 2s .  c o m
    FileObject maybeRootFile = null;
    try {
        fsManager = VFS.getManager();
        if (fsManager instanceof DefaultFileSystemManager) {
            File f = new File("."); //$NON-NLS-1$
            try {
                ((DefaultFileSystemManager) fsManager).setBaseFile(f.getCanonicalFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //maybeRootFile = fsManager.resolveFile("jar:lib/mail-1.3.2.jar"); //$NON-NLS-1$
        // rootFile = fsManager.resolveFile("file:/home/mdamour/workspace/apache-vfs-browser");
        maybeRootFile = fsManager.resolveFile("file:///c:/");
        // maybeRootFile = fsManager.resolveFile("jar:lib/mail.jar");
        // maybeRootFile = fsManager.resolveFile("ftp://ftpgolden.pentaho.org/");

        // maybeRootFile.getFileSystem().getParentLayer().

        // maybeRootFile.getFileSystem().getFileSystemManager().gets

    } catch (Exception e) {
        e.printStackTrace();
    }
    final FileObject rootFile = maybeRootFile;
    final Shell applicationShell = new Shell(SWT.SHELL_TRIM | SWT.CLOSE | SWT.MIN | SWT.MAX);
    applicationShell.setLayout(new FillLayout());
    applicationShell.setText(Messages.getString("FileChooserTest.application")); //$NON-NLS-1$
    applicationShell.setSize(640, 400);
    Menu bar = new Menu(applicationShell, SWT.BAR);
    applicationShell.setMenuBar(bar);
    MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
    fileItem.setText(Messages.getString("FileChooserTest.file")); //$NON-NLS-1$
    fileItem.setAccelerator(SWT.CTRL + 'F');
    Menu fileSubMenu = new Menu(applicationShell, SWT.DROP_DOWN);
    fileItem.setMenu(fileSubMenu);
    MenuItem fileOpenItem = new MenuItem(fileSubMenu, SWT.CASCADE);
    fileOpenItem.setText(Messages.getString("FileChooserTest.open")); //$NON-NLS-1$
    fileOpenItem.setAccelerator(SWT.CTRL + 'O');
    final String filters[] = new String[] { "*.*", "*.xml;*.XML;", "*.class", "*.map" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    final String filterNames[] = new String[] { Messages.getString("FileChooserTest.allFiles"), //$NON-NLS-1$
            Messages.getString("FileChooserTest.xmlFiles"), Messages.getString("FileChooserTest.javaFiles"), //$NON-NLS-1$//$NON-NLS-2$
            Messages.getString("FileChooserTest.mapFiles") }; //$NON-NLS-1$
    fileOpenItem.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            FileObject initialFile = rootFile;
            // try {
            // // initialFile = rootFile.resolveFile("/home/mdamour");
            // } catch (FileSystemException e) {
            // e.printStackTrace();
            // }
            try {
                VfsFileChooserDialog fileOpenDialog = new VfsFileChooserDialog(applicationShell,
                        VFS.getManager(), rootFile, initialFile);
                fileOpenDialog.addVFSUIPanel(buildHDFSPanel("HDFS", fileOpenDialog));
                fileOpenDialog.addVFSUIPanel(buildHDFSPanel("S3", fileOpenDialog));
                fileOpenDialog.addVFSUIPanel(buildHDFSPanel("file", fileOpenDialog));
                FileObject selectedFile = fileOpenDialog.open(applicationShell, null, filters, filterNames,
                        VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE);
                if (selectedFile != null) {
                    System.out.println(
                            Messages.getString("FileChooserTest.selectedFileEquals") + selectedFile.getName()); //$NON-NLS-1$
                } else {
                    System.out.println(Messages.getString("FileChooserTest.noFileSelected")); //$NON-NLS-1$
                }
            } catch (FileSystemException ex) {
                ex.printStackTrace();
            }
        }
    });
    MenuItem saveAsOpenItem = new MenuItem(fileSubMenu, SWT.CASCADE);
    saveAsOpenItem.setText(Messages.getString("FileChooserTest.saveAs")); //$NON-NLS-1$
    saveAsOpenItem.setAccelerator(SWT.CTRL + 'A');
    saveAsOpenItem.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }

        public void widgetSelected(SelectionEvent arg0) {
            FileObject initialFile = null;
            try {
                initialFile = rootFile.resolveFile("/home/mdamour"); //$NON-NLS-1$
            } catch (FileSystemException e) {
                e.printStackTrace();
            }
            try {
                VfsFileChooserDialog fileOpenDialog = new VfsFileChooserDialog(applicationShell,
                        VFS.getManager(), rootFile, initialFile);
                FileObject selectedFile = fileOpenDialog.open(applicationShell,
                        Messages.getString("FileChooserTest.untitled"), filters, filterNames, //$NON-NLS-1$
                        VfsFileChooserDialog.VFS_DIALOG_SAVEAS);
                if (selectedFile != null) {
                    System.out.println(
                            Messages.getString("FileChooserTest.selectedFileEquals") + selectedFile.getName()); //$NON-NLS-1$
                } else {
                    System.out.println(Messages.getString("FileChooserTest.noFileSelected")); //$NON-NLS-1$
                }
            } catch (FileSystemException ex) {
                ex.printStackTrace();
            }
        }
    });
    applicationShell.open();
    while (!applicationShell.isDisposed()) {
        if (!applicationShell.getDisplay().readAndDispatch())
            applicationShell.getDisplay().sleep();
    }
}

From source file:org.pentaho.vfs.ui.VfsBrowser.java

public boolean deleteItem(TreeItem ti) throws FileSystemException {
    FileObject file = (FileObject) ti.getData();
    if (file.getName().getPath().equals("/"))
        return false; // If the root folder is attempted to delete, do nothing.
    if (file.delete()) {
        ti.dispose();/*from w  ww .j  a v  a  2s  .c  om*/
        return true;
    }
    // If deleting a file object failed and no exception was kicked in, the selected object is a non-empty folder.
    // Show a second Confirm message, and perform a recursive delete if OK is pressed.
    MessageBox messageDialog = new MessageBox(fileSystemTree.getShell(), SWT.YES | SWT.NO);
    messageDialog.setText(Messages.getString("VfsFileChooserDialog.confirm")); //$NON-NLS-1$
    messageDialog.setMessage(Messages.getString("VfsFileChooserDialog.deleteFolderWithContents")); //$NON-NLS-1$
    int status = messageDialog.open();
    if (status == SWT.YES) {
        if (file.delete(new AllFileSelector()) != 0) {
            ti.dispose();
            return true;
        }
    }
    return false;
}

From source file:org.pentaho.vfs.ui.VfsBrowser.java

public void selectTreeItemByFileObject(FileObject selectedFileObject, boolean expandSelection)
        throws FileSystemException {
    // note that this method WILL cause the tree to load files from VFS
    // go through selectedFileObject's parent elements until we hit the root
    if (selectedFileObject == null) {
        return;/*from   w w w.  j  a v a2 s. c o  m*/
    }
    List selectedFileObjectParentList = new ArrayList();
    selectedFileObjectParentList.add(selectedFileObject);
    FileObject parent = selectedFileObject.getParent();
    while (parent != null && !parent.equals(rootFileObject)) {
        selectedFileObjectParentList.add(parent);
        parent = parent.getParent();
    }

    if (fileSystemTree.getSelection().length > 0) {
        TreeItem treeItem = fileSystemTree.getSelection()[0];
        treeItem.setExpanded(true);
        fileSystemTree.setSelection(treeItem);
        setSelectedFileObject(selectedFileObject);
        for (int i = selectedFileObjectParentList.size() - 1; i >= 0; i--) {
            FileObject obj = (FileObject) selectedFileObjectParentList.get(i);
            treeItem = findTreeItemByName(treeItem, obj.getName().getBaseName());
            if (treeItem != null && !treeItem.isDisposed()) {
                if (treeItem.getData() == null || treeItem.getData("isLoaded") == null //$NON-NLS-1$
                        || !((Boolean) treeItem.getData("isLoaded")).booleanValue()) { //$NON-NLS-1$
                    treeItem.removeAll();
                    populateFileSystemTree(obj, fileSystemTree, treeItem);
                }
            }
            if (treeItem != null && !treeItem.isDisposed()) {
                fileSystemTree.setSelection(treeItem);
                treeItem.setExpanded(expandSelection);
            }
        }
    }
}

From source file:org.pentaho.vfs.ui.VfsBrowser.java

public void populateTreeItemText(TreeItem ti, FileObject fileObject) {
    try {//w  w  w .  j av  a2  s  .c o m
        String contentType = fileObject.getContent().getContentInfo().getContentType();
        DateFormat df = SimpleDateFormat.getDateTimeInstance();
        Date date = new Date(fileObject.getContent().getLastModifiedTime());
        if (contentType == null) {
            contentType = ""; //$NON-NLS-1$
        }
        ti.setText(new String[] { fileObject.getName().getBaseName(), contentType, df.format(date) });
    } catch (Throwable t) {
        // t.printStackTrace();
        ti.setText(fileObject.getName().getBaseName());
    }
}

From source file:org.pentaho.vfs.ui.VfsBrowser.java

public void populateFileSystemTree(final FileObject inputFile, final Tree tree, TreeItem item) {
    if (inputFile == null) {
        return;//  www . j  a  va2s .  com
    }
    if (item == null) {
        item = new TreeItem(tree, SWT.NONE);
        String rootName = inputFile.getName().getBaseName();
        if (rootName == null || "".equals(rootName)) {
            rootName = "/";
        }
        item.setText(rootName);
        item.setData(inputFile);
        item.setExpanded(true);
        tree.setSelection(item);
    } else {
        item.setData(inputFile);
    }
    final TreeItem myItem = item;
    Runnable r = new Runnable() {
        public void run() {
            FileObject[] children = null;
            try {
                children = (FileObject[]) fileObjectChildrenMap.get(inputFile.getName().getFriendlyURI());
                if (children == null && inputFile.getType().equals(FileType.FOLDER)) {
                    children = inputFile.getChildren();
                    if (children == null) {
                        children = new FileObject[0];
                    }
                    Arrays.sort(children, new Comparator<FileObject>() {
                        public int compare(FileObject o1, FileObject o2) {
                            try {
                                if (o1.getType().equals(o2.getType())) {
                                    return o1.getName().getBaseName().compareTo(o2.getName().getBaseName());
                                }
                                if (o1.getType().equals(FileType.FOLDER)) {
                                    return -1;
                                }
                                if (o1.getType().equals(FileType.FILE)) {
                                    return 1;
                                }
                            } catch (Exception e) {
                            }
                            return 0;
                        }

                        public boolean equals(Object obj) {
                            return super.equals(obj);
                        }
                    });
                    fileObjectChildrenMap.put(inputFile.getName().getFriendlyURI(), children);
                }
            } catch (FileSystemException e) {
                e.printStackTrace();
            }
            myItem.setData("isLoaded", Boolean.TRUE); //$NON-NLS-1$
            if (children != null) {
                myItem.setImage(getFolderImage(tree.getDisplay()));
            } else if (showFoldersOnly) {
                myItem.removeAll();
                myItem.dispose();
                return;
            }
            for (int i = 0; children != null && i < children.length; i++) {
                FileObject fileObj = children[i];
                try {
                    if (fileObj.getType().hasChildren()) {
                        TreeItem childTreeItem = new TreeItem(myItem, SWT.NONE);
                        populateTreeItemText(childTreeItem, fileObj);
                        childTreeItem.setImage(getFileImage(tree.getDisplay()));
                        childTreeItem.setData(fileObj);
                        childTreeItem.setData("isLoaded", Boolean.FALSE); //$NON-NLS-1$
                        childTreeItem.setImage(getFolderImage(tree.getDisplay()));
                        TreeItem tmpItem = new TreeItem(childTreeItem, SWT.NONE);
                        populateTreeItemText(tmpItem, fileObj);
                    } else if (fileObj.getType().equals(FileType.FOLDER)) {
                        TreeItem childTreeItem = new TreeItem(myItem, SWT.NONE);
                        populateTreeItemText(childTreeItem, fileObj);
                        childTreeItem.setImage(getFileImage(tree.getDisplay()));
                        childTreeItem.setData(fileObj);
                        childTreeItem.setData("isLoaded", Boolean.FALSE); //$NON-NLS-1$
                        childTreeItem.setImage(getFolderImage(tree.getDisplay()));
                        TreeItem tmpItem = new TreeItem(childTreeItem, SWT.NONE);
                        populateTreeItemText(tmpItem, fileObj);
                    } else if (!fileObj.getType().equals(FileType.FOLDER) && !showFoldersOnly) {
                        if (isAcceptedByFilter(fileObj.getName())) {
                            TreeItem childTreeItem = new TreeItem(myItem, SWT.NONE);
                            populateTreeItemText(childTreeItem, fileObj);
                            childTreeItem.setImage(getFileImage(tree.getDisplay()));
                            childTreeItem.setData(fileObj);
                            childTreeItem.setData("isLoaded", Boolean.FALSE); //$NON-NLS-1$
                        }
                    }
                } catch (FileSystemException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            if (fileSystemTree.getItemCount() > 0 && fileSystemTree.getSelection().length == 0) {
                fileSystemTree.setSelection(fileSystemTree.getItem(0));
                fileSystemTree.getItem(0).setExpanded(true);
            }
        }
    };
    BusyIndicator.showWhile(tree.getDisplay(), r);
}

From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java

public FileObject open(Shell applicationShell, String[] schemeRestrictions, String initialScheme,
        boolean showFileScheme, String fileName, String[] fileFilters, String[] fileFilterNames,
        boolean returnUserAuthenticatedFile, int fileDialogMode, boolean showLocation, boolean showCustomUI) {

    this.fileDialogMode = fileDialogMode;
    this.fileFilters = fileFilters;
    this.fileFilterNames = fileFilterNames;
    this.applicationShell = applicationShell;
    this.showFileScheme = showFileScheme;
    this.initialScheme = initialScheme;
    this.schemeRestrictions = schemeRestrictions;
    this.showLocation = showLocation;
    this.showCustomUI = showCustomUI;

    FileObject tmpInitialFile = initialFile;

    if (defaultInitialFile != null && rootFile == null) {
        try {/*from  www .j ava  2s.  c o  m*/
            rootFile = defaultInitialFile.getFileSystem().getRoot();
            initialFile = defaultInitialFile;
        } catch (FileSystemException ignored) {
            // well we tried
        }
    }

    createDialog(applicationShell);

    if (!showLocation) {
        comboPanel.setParent(fakeShell);
    } else {
        comboPanel.setParent(customUIPanel);
    }

    if (!showCustomUI) {
        customUIPanel.setParent(fakeShell);
    } else {
        customUIPanel.setParent(dialog);
    }

    // create our file chooser tool bar, contains parent folder combo and various controls
    createToolbarPanel(dialog);
    // create our vfs browser component
    createVfsBrowser(dialog);
    populateCustomUIPanel(dialog);
    if (fileDialogMode == VFS_DIALOG_SAVEAS) {
        createFileNamePanel(dialog, fileName);
    } else {
        // create file filter panel
        createFileFilterPanel(dialog);
    }
    // create our ok/cancel buttons
    createButtonPanel(dialog);

    initialFile = tmpInitialFile;
    // set the initial file selection
    try {
        if (initialFile != null || rootFile != null) {
            vfsBrowser.selectTreeItemByFileObject(initialFile != null ? initialFile : rootFile, true);
            updateParentFileCombo(initialFile != null ? initialFile : rootFile);
            setSelectedFile(initialFile != null ? initialFile : rootFile);
            openFileCombo.setText(
                    initialFile != null ? initialFile.getName().getURI() : rootFile.getName().getURI());
        }
    } catch (FileSystemException e) {
        MessageBox box = new MessageBox(dialog.getShell());
        box.setText(Messages.getString("VfsFileChooserDialog.error")); //$NON-NLS-1$
        box.setMessage(e.getMessage());
        box.open();
    }

    // set the size and show the dialog
    int height = 550;
    int width = 800;
    dialog.setSize(width, height);
    Rectangle bounds = dialog.getDisplay().getPrimaryMonitor().getClientArea();
    int x = (bounds.width - width) / 2;
    int y = (bounds.height - height) / 2;
    dialog.setLocation(x, y);
    dialog.open();

    if (rootFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) {
        if (!rootFile.getFileSystem().hasCapability(Capability.WRITE_CONTENT)) {
            MessageBox messageDialog = new MessageBox(dialog.getShell(), SWT.OK);
            messageDialog.setText(Messages.getString("VfsFileChooserDialog.warning")); //$NON-NLS-1$
            messageDialog.setMessage(Messages.getString("VfsFileChooserDialog.noWriteSupport")); //$NON-NLS-1$
            messageDialog.open();
        }
    }

    vfsBrowser.fileSystemTree.forceFocus();
    while (!dialog.isDisposed()) {
        if (!dialog.getDisplay().readAndDispatch())
            dialog.getDisplay().sleep();
    }

    // we just woke up, we are probably disposed already..
    if (!dialog.isDisposed()) {
        hideCustomPanelChildren();
        dialog.dispose();
    }
    if (okPressed) {
        FileObject returnFile = vfsBrowser.getSelectedFileObject();
        if (returnFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) {
            try {
                if (returnFile.getType().equals(FileType.FILE)) {
                    returnFile = returnFile.getParent();
                }
                returnFile = returnFile.resolveFile(enteredFileName);
            } catch (FileSystemException e) {
                e.printStackTrace();
            }
        }

        // put user/pass on the filename so it comes out in the getUri call.
        if (!returnUserAuthenticatedFile) {
            // make sure to put the user/pass on the url if it's not there
            if (returnFile != null && returnFile.getName() instanceof URLFileName) {
                URLFileName urlFileName = (URLFileName) returnFile.getName();
                if (urlFileName.getUserName() == null || urlFileName.getPassword() == null) {
                    // set it
                    String user = "";
                    String pass = "";

                    UserAuthenticator userAuthenticator = DefaultFileSystemConfigBuilder.getInstance()
                            .getUserAuthenticator(returnFile.getFileSystem().getFileSystemOptions());

                    if (userAuthenticator != null) {
                        UserAuthenticationData data = userAuthenticator
                                .requestAuthentication(AUTHENTICATOR_TYPES);
                        user = String.valueOf(data.getData(UserAuthenticationData.USERNAME));
                        pass = String.valueOf(data.getData(UserAuthenticationData.PASSWORD));
                        try {
                            user = URLEncoder.encode(user, "UTF-8");
                            pass = URLEncoder.encode(pass, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            // ignore, just use the un encoded values
                        }
                    }

                    // build up the url with user/pass on it
                    int port = urlFileName.getPort();
                    String portString = (port < 1) ? "" : (":" + port);
                    String urlWithUserPass = urlFileName.getScheme() + "://" + user + ":" + pass + "@"
                            + urlFileName.getHostName() + portString + urlFileName.getPath();

                    try {
                        returnFile = currentPanel.resolveFile(urlWithUserPass);
                    } catch (FileSystemException e) {
                        // couldn't resolve with user/pass on url??? interesting
                        e.printStackTrace();
                    }

                }
            }
        }
        return returnFile;
    } else {
        return null;
    }
}

From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java

public void widgetSelected(SelectionEvent se) {
    if (se.widget == openFileCombo) {
        // String filePath = parentFoldersCombo.getItem(parentFoldersCombo.getSelectionIndex());
        // vfsBrowser.selectTreeItemByName(filePath, true);

        try {//ww w. j  av a2  s .co  m
            // resolve the selected folder (without displaying access/secret keys in plain text)
            //        FileObject newRoot = rootFile.getFileSystem().getFileSystemManager().resolveFile(folderURL.getFolderURL(openFileCombo.getText()));
            FileObject newRoot = currentPanel.resolveFile(getSelectedFile().getName().getURI());
            vfsBrowser.resetVfsRoot(newRoot);
        } catch (FileSystemException e) {
        }

    } else if (se.widget == okButton) {
        okPressed();
    } else if (se.widget == folderUpButton) {
        try {
            FileObject newRoot = vfsBrowser.getSelectedFileObject().getParent();
            if (newRoot != null) {
                vfsBrowser.resetVfsRoot(newRoot);
                vfsBrowser.setSelectedFileObject(newRoot);
                // make sure access/secret keys not displayed in plain text
                //          String str = folderURL.setFolderURL(newRoot.getName().getURI());
                openFileCombo.setText(newRoot.getName().getURI());
            }
        } catch (Exception e) {
            // top of root
        }
    } else if (se.widget == newFolderButton) {
        promptForNewFolder();
    } else if (se.widget == deleteFileButton) {
        MessageBox messageDialog = new MessageBox(se.widget.getDisplay().getActiveShell(), SWT.YES | SWT.NO);
        messageDialog.setText(Messages.getString("VfsFileChooserDialog.confirm")); //$NON-NLS-1$
        messageDialog.setMessage(Messages.getString("VfsFileChooserDialog.deleteFile")); //$NON-NLS-1$
        int status = messageDialog.open();
        if (status == SWT.YES) {
            try {
                vfsBrowser.deleteSelectedItem();
            } catch (FileSystemException e) {
                MessageBox errorDialog = new MessageBox(se.widget.getDisplay().getActiveShell(), SWT.OK);
                errorDialog.setText(Messages.getString("VfsFileChooserDialog.error")); //$NON-NLS-1$
                errorDialog.setMessage(e.getMessage());
                errorDialog.open();
            }
        }
        // } else if (se.widget == changeRootButton) {
        // promptForNewVfsRoot();
    } else if (se.widget == fileFilterCombo) {

        Runnable r = new Runnable() {
            public void run() {
                String filter = fileFilters[fileFilterCombo.getSelectionIndex()];
                vfsBrowser.setFilter(filter);
                try {
                    vfsBrowser.applyFilter();
                } catch (FileSystemException e) {
                    MessageBox mb = new MessageBox(newFolderButton.getShell(), SWT.OK);
                    mb.setText(Messages.getString("VfsFileChooserDialog.errorApplyFilter")); //$NON-NLS-1$
                    mb.setMessage(e.getMessage());
                    mb.open();
                }
            }
        };
        BusyIndicator.showWhile(fileFilterCombo.getDisplay(), r);
    } else {
        okPressed = false;
        hideCustomPanelChildren();
        dialog.dispose();
    }
}