com.pietschy.command.file
Class AbstractFileOpenCommand

java.lang.Object
  extended by com.pietschy.command.Command
      extended by com.pietschy.command.ActionCommand
          extended by com.pietschy.command.file.AbstractFileCommand
              extended by com.pietschy.command.file.AbstractFileOpenCommand
All Implemented Interfaces:
ActionCommandExecutor, Bindable, Identifiable

public abstract class AbstractFileOpenCommand
extends AbstractFileCommand

An abstract class that provides generic file open behaviour. On 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.prepareFileChooser() and configuring appropriately.

Version:
$Revision: 1.5 $
Author:
andrewp

Field Summary
static java.lang.String FILE_TO_OPEN
          If specified as a parameter the command will bypass the chooser dialog and open the file directly.
 
Fields inherited from class com.pietschy.command.ActionCommand
PARAMETER_ACTION_EVENT, PARAMETER_INVOKER, PARAMETER_INVOKER_WINDOW, PARAMETER_MODIFIERS
 
Fields inherited from class com.pietschy.command.Command
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE
 
Constructor Summary
AbstractFileOpenCommand(java.lang.String id, javax.swing.filechooser.FileFilter... filters)
          Creates a new command with the specified id and list of FileFilter
 
Method Summary
protected  void handleExecute()
          Main entry point for command subclasses that must be implemented to provide command specific behaviour.
 boolean isMultiselectionEnabled()
          Checks if multiple selection is enabled.
protected  void performFileAction(java.io.File[] files, javax.swing.JFileChooser chooser, java.awt.Component centerOn)
          Simply delegates to performOpen(File[]).
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.Component centerOn)
          Shows the standard file open chooser.
 
Methods inherited from class com.pietschy.command.file.AbstractFileCommand
beforeProceeding, getComponentToCenterOn, getDefaultFileFilter, handleCancel, handleError, isAcceptAllFileFilterUsed, isRememberLastFilter, prepareFileChooser, setAcceptAllFileFilterUsed, setDefaultFileFilter, setRememberLastFilter, setSelectedFile, setSelectedFiles
 
Methods inherited from class com.pietschy.command.ActionCommand
addActionCommandListener, addInterceptor, bindToContainer, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, doButtonAttachments, doButtonDetachments, execute, execute, getActionAdapter, getActionAdapter, getActionEvent, getInvoker, getInvokerWindow, getModifiers, getParameter, getParameter, getParameters, installShortCut, installShortCut, postExecute, preExecute, putParameter, putParameters, removeActionCommandListener, removeInterceptor, requestDefaultIn, unbindFromContainer, uninstallShortCut, uninstallShortCut
 
Methods inherited from class com.pietschy.command.Command
addContainerPropertyListener, addFace, addHoverListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, attach, bind, bind, bind, buttonIterator, configureAppearance, configureAppearances, configureButtonAppearances, configureButtonStates, configureButtonStates, createButton, createButton, createButton, createButton, createComponent, createMenuItem, createMenuItem, createMenuItem, createMenuItem, detach, faceExists, findBestFace, fireHoverEnded, fireHoverStarted, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlternativeFaceContexts, getButtonFactory, getButtonIn, getCommandContainer, getContainerProperty, getDefaultFace, getDefaultFace, getFace, getFace, getId, getMenuFactory, getProperty, getProperty, getPropertyNames, getToolbarFactory, isAnonymous, isAttachedTo, isBound, isEnabled, isVisible, loadConfiguration, notifyCommandContainerHierarchyChanged, putProperties, putProperty, rebind, removeContainerPropertyListener, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setButtonFactory, setEnabled, setMenuFactory, setToolbarFactory, setVisible, toString, unbind, validateId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.pietschy.command.ActionCommandExecutor
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface com.pietschy.command.Identifiable
getId
 

Field Detail

FILE_TO_OPEN

public static final java.lang.String FILE_TO_OPEN
If specified as a parameter the command will bypass the chooser dialog and open the file directly.

See Also:
Constant Field Values
Constructor Detail

AbstractFileOpenCommand

public AbstractFileOpenCommand(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.Component centerOn)
Shows the standard file open chooser.

Specified by:
showChooserDialog in class AbstractFileCommand
Parameters:
chooser - the chooser instance.
centerOn - the component on which to center the chooser.
Returns:
the result of JFileChooser.showOpenDialog(Component).

performFileAction

protected void performFileAction(java.io.File[] files,
                                 javax.swing.JFileChooser chooser,
                                 java.awt.Component centerOn)
Simply delegates to performOpen(File[]).

Specified by:
performFileAction in class AbstractFileCommand
Parameters:
files - the files selected in the chooser.
chooser - the chooser that was used.
centerOn - the component on which to center any subsequent dialogs.

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.

handleExecute

protected void handleExecute()
Description copied from class: ActionCommand
Main entry point for command subclasses that must be implemented to provide command specific behaviour.

This method should never be called directly to invoke a command. All command invocation must be performed using the ActionCommand.execute() and ActionCommand.execute(Map) methods.

Overrides:
handleExecute in class AbstractFileCommand

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.


Copyright © 2006 - 2007 Andrew Pietsch