org.pietschy.command.file
Class AbstractFileOpenCommand

java.lang.Object
  extended by org.pietschy.command.Command
      extended by org.pietschy.command.ActionCommand
          extended by org.pietschy.command.file.AbstractFileCommand
              extended by org.pietschy.command.file.AbstractFileOpenCommand
All Implemented Interfaces:
ActionCommandExecutor

public abstract class AbstractFileOpenCommand
extends AbstractFileCommand

The command provides generic file open behaviour. One execution, the command will display a JFileChooser and if the selection is successful performOpen(java.io.File[]) will be invoked with the selected files. Subclasses must implement performOpen(java.io.File[]) to implement the required behaviour.

Subclasses can change the default settings by overriding AbstractFileCommand.getFileChooser() and configuring appropriately.

Version:
$Revision: 1.5 $
Author:
andrewp

Field Summary
 
Fields inherited from class org.pietschy.command.ActionCommand
HINT_ACTION_EVENT, HINT_INVOKER, HINT_INVOKER_WINDOW, HINT_MODIFIERS
 
Fields inherited from class org.pietschy.command.Command
internalLog, listenerList, pcs
 
Constructor Summary
AbstractFileOpenCommand(CommandManager manager, java.lang.String id, javax.swing.filechooser.FileFilter filter)
          Creates a new command with the specified id and FileFilter
AbstractFileOpenCommand(CommandManager manager, java.lang.String id, javax.swing.filechooser.FileFilter[] filters)
          Creates a new command with the specified id and list of FileFilter
AbstractFileOpenCommand(java.lang.String id, javax.swing.filechooser.FileFilter filter)
          Creates a new command with the specified id and FileFilter.
AbstractFileOpenCommand(java.lang.String id, javax.swing.filechooser.FileFilter[] filters)
          Creates a new command with the specified id and list of FileFilter.
 
Method Summary
 boolean isMultiselectionEnabled()
          Checks if multiple selection is enabled.
protected  void performFileAction(java.io.File[] files, javax.swing.JFileChooser chooser, java.awt.Window invoker)
          This method is invoked if the AbstractFileCommand.showChooserDialog(javax.swing.JFileChooser, java.awt.Window) returns JFileChooser.APPROVE_OPTION.
protected abstract  void performOpen(java.io.File[] files)
          This method is called when the user selects one or more files to open.
 void setMultiselectionEnabled(boolean multiselectionEnabled)
          Configures if the JFileChooser allows multiple selection.
protected  int showChooserDialog(javax.swing.JFileChooser chooser, java.awt.Window invoker)
          Called to display the JFileChooser.
 
Methods inherited from class org.pietschy.command.file.AbstractFileCommand
afterExecute, beforeExecute, confirmProceed, getDefaultFileFilter, getFileChooser, handleCancel, handleError, handleExecute, isAcceptAllFileFilterUsed, isCenterOnInvoker, isRememberLastFilter, setAcceptAllFileFilterUsed, setCenterOnInvoker, setDefaultFileFilter, setRememberLastFilter
 
Methods inherited from class org.pietschy.command.ActionCommand
addCommandListener, addInterceptor, areEqual, attach, configureButtonStates, detach, execute, execute, getActionAdapter, getActionAdapter, getActionCommand, getActionEvent, getHint, getHint, getHints, getInvoker, getInvokerWindow, getModifiers, installShortCut, installShortCut, postExecute, preExecute, putHint, putHints, removeCommandListener, removeInterceptor, requestDefautIn, setActionCommand, uninstallShortCut, uninstallShortCut
 
Methods inherited from class org.pietschy.command.Command
addFace, addHoverListener, addNewFace, addNotify, addPropertyChangeListener, addPropertyChangeListener, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, export, faceExists, fireHoverEnded, fireHoverStarted, getAccelerator, getAlternativeFaceNames, getButtonFactory, getButtonIn, getCommandManager, getDefaultFace, getDefaultFace, getDescription, getFace, getFace, getIcon, getId, getLongDescription, getMenuFactory, getMnemonic, getMnemonicIndex, getProperty, getProperty, getPropertyNames, getSelectedIcon, getText, getTextPosition, getToolbarFactory, initCommandManager, installFace, isAnonymous, isAttachedTo, isEnabled, isVisible, putProperty, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setAccelerator, setButtonFactory, setDescription, setEnabled, setIcon, setLongDescription, setMenuFactory, setMnemonic, setMnemonicIndex, setSelectedIcon, setText, setTextPosition, setToolbarFactory, setVisible, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pietschy.command.ActionCommandExecutor
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

AbstractFileOpenCommand

public AbstractFileOpenCommand(java.lang.String id,
                               javax.swing.filechooser.FileFilter filter)
Creates a new command with the specified id and FileFilter. This command is bound to the default command manager.

Parameters:
id - the id of the command.
filter - the FileFilter to use.

AbstractFileOpenCommand

public AbstractFileOpenCommand(java.lang.String id,
                               javax.swing.filechooser.FileFilter[] filters)
Creates a new command with the specified id and list of FileFilter. This command is bound to the default command manager.

Parameters:
id - the id of the command.
filters - a list of FileFilter instances to use.

AbstractFileOpenCommand

public AbstractFileOpenCommand(CommandManager manager,
                               java.lang.String id,
                               javax.swing.filechooser.FileFilter filter)
Creates a new command with the specified id and FileFilter

Parameters:
id - the id of the command.
filter - the FileFilter to use.

AbstractFileOpenCommand

public AbstractFileOpenCommand(CommandManager manager,
                               java.lang.String id,
                               javax.swing.filechooser.FileFilter[] filters)
Creates a new command with the specified id and list of FileFilter

Parameters:
id - the id of the command.
filters - a list of FileFilter instances to use.
Method Detail

showChooserDialog

protected int showChooserDialog(javax.swing.JFileChooser chooser,
                                java.awt.Window invoker)
Description copied from class: AbstractFileCommand
Called to display the JFileChooser. Subclasses override to display an appropriate version of the chooser (such as an open or save dialog). This method must return the result of the JFileChooser show method. Eg.
protected int showChooserDialog(JFileChooser chooser, Window invoker)
{
   return chooser.showOpenDialog(invoker);
}

Specified by:
showChooserDialog in class AbstractFileCommand
Parameters:
chooser - the chooser to display
Returns:
the result of JFileChooser.showDialog(java.awt.Component, java.lang.String), JFileChooser.showOpenDialog(java.awt.Component) or JFileChooser.showSaveDialog(java.awt.Component).

performFileAction

protected void performFileAction(java.io.File[] files,
                                 javax.swing.JFileChooser chooser,
                                 java.awt.Window invoker)
Description copied from class: AbstractFileCommand
This method is invoked if the AbstractFileCommand.showChooserDialog(javax.swing.JFileChooser, java.awt.Window) returns JFileChooser.APPROVE_OPTION. Subclasses must override to perform the specific file operation.

Specified by:
performFileAction in class AbstractFileCommand
Parameters:
files - the files that were selected in the JFileChooser
chooser - the JFileChooser that was displayed.
invoker - the owner window.

isMultiselectionEnabled

public boolean isMultiselectionEnabled()
Checks if multiple selection is enabled.

Returns:
true if multiple selection is enabled.

setMultiselectionEnabled

public void setMultiselectionEnabled(boolean multiselectionEnabled)
Configures if the JFileChooser allows multiple selection.

Parameters:
multiselectionEnabled - true to allow multiple file selection, false otherwise.

performOpen

protected abstract void performOpen(java.io.File[] files)
This method is called when the user selects one or more files to open. Subclasses must implement this method to perform the required behaviour.

If multiple selection is disabled, the file list will contain only one file.

Parameters:
files - the files that the user has selected.