Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.pietschy.command.file
Class AbstractSaveAsCommand

    java.lang.Object
      com.pietschy.command.Command
          com.pietschy.command.ActionCommand
              com.pietschy.command.file.AbstractFileCommand
                  com.pietschy.command.file.AbstractSaveAsCommand

All Implemented Interfaces:
  ActionCommandExecutor, Bindable, Identifiable

    public abstract class AbstractSaveAsCommand

extends AbstractFileCommand

An abstract class that provides behaviour for the standard "save as" operation. On execution, the command will display a `JFileChooser` and if successful `performSave(java.io.File)` will be invoked.

If the filters specified are instances of `ExtensionFileFilter`, the command will also ensure the extension of the file is correct.

If the selected file already exists the command will prompt the user to confirm before `performSave(java.io.File)` is invoked. The message displayed to the user can be configured by specifying the properties `overwriteMessage` and `overwriteTitle`. The message parameter is passed throught a message format where paramter 0 is the file name returned by `File.getName()`. If the parameters aren't defined then the following defaults are used.

        overwriteTitle=Confirm file overwrite
        overwriteMessage=File ''{0}'' already exists.  Overwrite?

If you need greater control over the messages displayed you can overload `getOverwriteTitle()` and/or `getOverwriteMessage(File)`. You can also override `confirmOverwrite(Component, File)` to completely control the user interaction.

Version:
  $Revision: 1.6 $
Author:
  andrewp

Field Summary
`(package private) static java.lang.String` | `DEFAULT_OVERWRITE_MESSAGE`
`(package private) static java.lang.String` | `DEFAULT_OVERWRITE_TITLE`
`static java.lang.String` | `OVERWRITE_MESSAGE_PROPERTY`
`static java.lang.String` | `OVERWRITE_TITLE_PROPERTY`

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
`AbstractSaveAsCommand()` Creates a new anonymous instance.
`AbstractSaveAsCommand(javax.swing.filechooser.FileFilter filter)` Creates a new anonymous instance with the specified `FileFilter`.
`AbstractSaveAsCommand(javax.swing.filechooser.FileFilter[] filters)` Creates new anonymous instance with the specified list of `FileFilter`s.
`AbstractSaveAsCommand(java.lang.String id)` Creates a new instance.
`AbstractSaveAsCommand(java.lang.String id, javax.swing.filechooser.FileFilter filter)` Creates a new instance with the specified `FileFilter`.
`AbstractSaveAsCommand(java.lang.String id, javax.swing.filechooser.FileFilter[] filters)` Creates new instance with the specified id and list of `FileFilter`s.

Method Summary
`protected boolean` | `confirmOverwrite(java.awt.Component centerOn, java.io.File file)` This method is called to confirm the save if the selected file already exists.
`protected java.lang.String` | `getOverwriteMessage(java.io.File file)` Gets the text to display in the dialog that confirms file overwrite.
`protected java.lang.String` | `getOverwriteTitle()` Gets the title to display in the dialog that confirms file overwrite.
`protected void` | `performFileAction(java.io.File[] selectedFiles, javax.swing.JFileChooser chooser, java.awt.Component centerOn)` This method `verifies` the extension, checks if the file exists, confirms overwrite if it does and invokes `performSave(File)`.
`protected abstract void` | `performSave(java.io.File file)` Called to perform the save operation.
`protected int` | `showChooserDialog(javax.swing.JFileChooser chooser, java.awt.Component invoker)` shows the standard save dialog.
`protected java.io.File` | `verifyFileExtension(java.io.File file, javax.swing.filechooser.FileFilter selectedFilter)` Invoked to verify the extension of the file selected by the user.

Methods inherited from class com.pietschy.command.file.AbstractFileCommand
`beforeProceeding, getComponentToCenterOn, getDefaultFileFilter, handleCancel, handleError, handleExecute, 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

### OVERWRITE_MESSAGE_PROPERTY

    public static final java.lang.String OVERWRITE_MESSAGE_PROPERTY

See Also:
  Constant Field Values

### OVERWRITE_TITLE_PROPERTY

    public static final java.lang.String OVERWRITE_TITLE_PROPERTY

See Also:
  Constant Field Values

### DEFAULT_OVERWRITE_MESSAGE

    static final java.lang.String DEFAULT_OVERWRITE_MESSAGE

See Also:
  Constant Field Values

### DEFAULT_OVERWRITE_TITLE

    static final java.lang.String DEFAULT_OVERWRITE_TITLE

See Also:
  Constant Field Values

Constructor Detail

### AbstractSaveAsCommand

    public AbstractSaveAsCommand(java.lang.String id,
                                 javax.swing.filechooser.FileFilter[] filters)

  Creates new instance with the specified id and list of `FileFilter`s.

  Parameters:
    `id` - the commands id.
    `filters` - the `FileFilter` list for the `JFileChooser` to use. If they are instances of `ExtensionFileFilter` the command will ensure the selected file has the correct extension.

### AbstractSaveAsCommand

    public AbstractSaveAsCommand(java.lang.String id,
                                 javax.swing.filechooser.FileFilter filter)

  Creates a new instance with the specified `FileFilter`.

  Parameters:
    `id` - the command id.
    `filter` - the filter to use.

### AbstractSaveAsCommand

    public AbstractSaveAsCommand(java.lang.String id)

  Creates a new instance.

  Parameters:
    `id` - the command id.

### AbstractSaveAsCommand

    public AbstractSaveAsCommand(javax.swing.filechooser.FileFilter[] filters)

  Creates new anonymous instance with the specified list of `FileFilter`s.

  Parameters:
    `filters` - the `FileFilter` list for the `JFileChooser` to use. If they are instances of `ExtensionFileFilter` the command will ensure the selected file has the correct extension.

### AbstractSaveAsCommand

    public AbstractSaveAsCommand(javax.swing.filechooser.FileFilter filter)

  Creates a new anonymous instance with the specified `FileFilter`.

  Parameters:
    `filter` - the filter to use.

### AbstractSaveAsCommand

    public AbstractSaveAsCommand()

  Creates a new anonymous instance.

Method Detail

### showChooserDialog

    protected int showChooserDialog(javax.swing.JFileChooser chooser,
                                    java.awt.Component invoker)

  shows the standard save dialog.

  Specified by:
    `showChooserDialog` in class `AbstractFileCommand`
  Parameters:
    `chooser` - the chooser to display
  Returns:
    the result of `JFileChooser.showSaveDialog(Component)`.

### performFileAction

    protected void performFileAction(java.io.File[] selectedFiles,
                                     javax.swing.JFileChooser chooser,
                                     java.awt.Component centerOn)

  This method `verifies` the extension, checks if the file exists, confirms overwrite if it does and invokes `performSave(File)`.

  Specified by:
    `performFileAction` in class `AbstractFileCommand`
  Parameters:
    `selectedFiles` - the file list from the chooser.
    `chooser` - the chooser that was used.
    `centerOn` - the component to center any subsequent window on.

### verifyFileExtension

    protected java.io.File verifyFileExtension(java.io.File file,
                                               javax.swing.filechooser.FileFilter selectedFilter)

  Invoked to verify the extension of the file selected by the user. This is provided to catch the case where the user has typed the file name but has ommited the extension.

  This implementation checks if the `FileFilter` is an instance of `ExtensionFileFilter`. If it is, it invokes `ExtensionFileFilter.checkAndAddExtension(java.io.File)` on the file, otherwise the file is returned as is.

  Parameters:
    `file` - the file the users has selected, that may or may not have an extension.
    `selectedFilter` - the `FileFilter` selected in the chooser.
  Returns:
    a filename with the correct extension.
  See Also:
    `ExtensionFileFilter`

### confirmOverwrite

    protected boolean confirmOverwrite(java.awt.Component centerOn,
                                       java.io.File file)

  This method is called to confirm the save if the selected file already exists. By default this method invokes `JOptionPane.showConfirmDialog(Component, Object)` with `getOverwriteTitle()` and `getOverwriteMessage(File)`.

  Subclasses can override for complete control over the confirmation process.

  Parameters:
    `centerOn` - the invoker window.
    `file` - the file that is to be overwritten.
  Returns:
    `true` to overwrite the file, `false` to cancel the operation.

### getOverwriteTitle

    protected java.lang.String getOverwriteTitle()

  Gets the title to display in the dialog that confirms file overwrite. This method returns the "overwriteTitle" property or the string `"Confirm file overwrite"` if not defined.

  Returns:
    the title for the confirm overwrite dialog.

### getOverwriteMessage

    protected java.lang.String getOverwriteMessage(java.io.File file)

  Gets the text to display in the dialog that confirms file overwrite. This method retieves the property 'overwriteMessage' and uses it as a `MessageFormat` template. The file name as per `File.getName()` is the first pararmeter. If the property is undefined the template `"File '$1' already exists. Overwrite?"` is used.

  Returns:
    the message to display to confirm overwriting an existing file.

### performSave

    protected abstract void performSave(java.io.File file)

  Called to perform the save operation. Subclasses must implement this method to perform the application specific save behaviour.

  Parameters:
    `file` - the file to save.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006 - 2007 Andrew Pietsch