com.mucommander.desktop.osx
Class OSXTrash

java.lang.Object
  extended by com.mucommander.desktop.AbstractTrash
      extended by com.mucommander.desktop.QueuedTrash
          extended by com.mucommander.desktop.osx.OSXTrash

public class OSXTrash
extends QueuedTrash

OSXTrash provides access to the Mac OS X Finder's trash. Only local files (or locally mounted files) can be moved to the trash.

Implementation notes:

This trash is implemented as a QueuedTrash for several reasons:


This class uses AppleScript to interact with the trash.

Author:
Maxence Bernard
See Also:
OSXTrashProvider

Field Summary
 
Fields inherited from class com.mucommander.desktop.QueuedTrash
moveToTrashLock, moveToTrashThread, QUEUE_PERIOD
 
Constructor Summary
OSXTrash()
           
 
Method Summary
 boolean canEmpty()
          Implementation notes: always returns true.
 boolean canMoveToTrash(AbstractFile file)
          Implementation notes: returns true only for local files that are not archive entries.
 boolean canOpen()
          Implementation notes: always returns true.
 boolean empty()
          Attempts to empty this trash and returns true if it was successfully emptied.
 int getItemCount()
          Implementation notes: this method is implemented and returns -1 only if an error ocurred while retrieving the trash item count.
 boolean isTrashFile(AbstractFile file)
          Returns true if the given file is a trash folder, or one of its children.
protected  boolean moveToTrash(java.util.Vector queuedFiles)
          Performs the actual job of moving files to the trash using AppleScript.
 void open()
          Opens the trash in the default file manager of the current OS/Desktop manager.
 
Methods inherited from class com.mucommander.desktop.QueuedTrash
moveToTrash, waitForPendingOperations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OSXTrash

public OSXTrash()
Method Detail

canMoveToTrash

public boolean canMoveToTrash(AbstractFile file)
Implementation notes: returns true only for local files that are not archive entries.

Specified by:
canMoveToTrash in class AbstractTrash
Parameters:
file - the file to test
Returns:
true if the given file can be moved to the trash

canEmpty

public boolean canEmpty()
Implementation notes: always returns true.

Specified by:
canEmpty in class AbstractTrash
Returns:
true if the trash can be emptied.

empty

public boolean empty()
Description copied from class: AbstractTrash
Attempts to empty this trash and returns true if it was successfully emptied.

Specified by:
empty in class AbstractTrash
Returns:
true if the trash was successfully emptied

isTrashFile

public boolean isTrashFile(AbstractFile file)
Description copied from class: AbstractTrash
Returns true if the given file is a trash folder, or one of its children. For example, if /home/someuser/.Trash is a trash folder, calling this method with:

Note that this method does not check the existence of the given file, the test is solely based on the file's path.

Specified by:
isTrashFile in class AbstractTrash
Parameters:
file - the file to test
Returns:
true if the given file is a trash folder, or one of its children.

getItemCount

public int getItemCount()
Implementation notes: this method is implemented and returns -1 only if an error ocurred while retrieving the trash item count.

Specified by:
getItemCount in class AbstractTrash
Returns:
the number of items that currently are in this trash, -1 if this information is not available

open

public void open()
Description copied from class: AbstractTrash
Opens the trash in the default file manager of the current OS/Desktop manager.

Specified by:
open in class AbstractTrash

canOpen

public boolean canOpen()
Implementation notes: always returns true.

Specified by:
canOpen in class AbstractTrash
Returns:
true if this trash can be opened in the default file manager of the current OS/Desktop manager.

moveToTrash

protected boolean moveToTrash(java.util.Vector queuedFiles)
Performs the actual job of moving files to the trash using AppleScript.

The thread starts by waiting QueuedTrash.QUEUE_PERIOD milliseconds before moving them to give additional files a chance to be queued and regrouped as a single AppleScript call. If some files were queued during that period, the thread will wait an additional QueuedTrash.QUEUE_PERIOD, and so on.

There are several reasons for doing that instead of executing an AppleScript synchroneously for each file passed to QueuedTrash.moveToTrash(com.mucommander.file.AbstractFile) :

Specified by:
moveToTrash in class QueuedTrash
Parameters:
queuedFiles - a Vector of AbstractFile to move to the trash
Returns:
true if all files were moved successfully


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard