Search in sources :

Example 1 with SearchFile

use of com.mucommander.commons.file.protocol.search.SearchFile in project mucommander by mucommander.

the class LocationChanger method tryChangeCurrentFolder.

/**
 * Tries to change current folder to the new specified one, and selects the given file after the folder has been
 * changed. The user is notified by a dialog if the folder could not be changed.
 *
 * <p>If the current folder could not be changed to the requested folder and <code>findWorkableFolder</code> is
 * <code>true</code>, the current folder will be changed to the first existing parent of the request folder if there
 * is one, to the first existing local volume otherwise. In the unlikely event that no local volume is workable,
 * the user will be notified that the folder could not be changed.</p>
 *
 * <p>This method spawns a separate thread that takes care of the actual folder change and returns it.
 * It does nothing and returns <code>null</code> if another folder change is already underway.</p>
 *
 * <p>
 * This method is <b>not</b> I/O-bound and returns immediately, without any chance of locking the calling thread.
 * </p>
 *
 * @param folder the folder to be made current folder
 * @param selectThisFileAfter the file to be selected after the folder has been changed (if it exists in the folder), can be null in which case FileTable rules will be used to select current file
 * @param changeLockedTab - flag that indicates whether to change the presented folder in the currently selected tab although it's locked
 * @return the thread that performs the actual folder change, null if another folder change is already underway
 */
public ChangeFolderThread tryChangeCurrentFolder(AbstractFile folder, AbstractFile selectThisFileAfter, boolean findWorkableFolder, boolean changeLockedTab) {
    LOGGER.debug("folder=" + folder + " selectThisFileAfter=" + selectThisFileAfter);
    synchronized (FOLDER_CHANGE_LOCK) {
        // MainFrame#setNoEventsMode.
        if (changeFolderThread != null) {
            LOGGER.debug("A folder change is already taking place (" + changeFolderThread + "), returning null");
            return null;
        }
        // Important: the ChangeFolderThread instance must be kept in a local variable (as opposed to the
        // changeFolderThread field only) before being returned. The reason for this is that ChangeFolderThread
        // changes the changeFolderThread field to null when finished, and it may do so before this method has
        // returned (I've seen this happening). Relying solely on the changeFolderThread field could thus cause
        // a null value to be returned, which is particularly problematic during startup (would cause an NPE).
        FileURL folderURL = folder.getURL();
        ChangeFolderThread thread;
        switch(folderURL.getScheme()) {
            case SearchFile.SCHEMA:
                if (folder instanceof SearchFile)
                    ((SearchFile) folder).stop();
                folder = FileFactory.getFile(folderURL);
                thread = new SearchUpdaterThread(folderURL, changeLockedTab, mainFrame, folderPanel, locationManager, this);
                break;
            default:
                thread = new BrowseLocationThread(folder, findWorkableFolder, changeLockedTab, mainFrame, folderPanel, locationManager, this);
        }
        if (selectThisFileAfter != null)
            thread.selectThisFileAfter(selectThisFileAfter);
        thread.start();
        changeFolderThread = thread;
        return thread;
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) SearchFile(com.mucommander.commons.file.protocol.search.SearchFile)

Aggregations

FileURL (com.mucommander.commons.file.FileURL)1 SearchFile (com.mucommander.commons.file.protocol.search.SearchFile)1