com.groovemanager.app.mc909se
Class Export909SamplesDialog

java.lang.Object
  extended by org.eclipse.jface.window.Window
      extended by org.eclipse.jface.dialogs.Dialog
          extended by org.eclipse.jface.dialogs.TitleAreaDialog
              extended by com.groovemanager.app.mc909se.Export909SamplesDialog

public class Export909SamplesDialog
extends org.eclipse.jface.dialogs.TitleAreaDialog

This dialog is used for exporting samples from the Mc909 sample editor to the MC909 or for importing them from the 909 to the editor.

Author:
Manu Robledo

Nested Class Summary
 
Nested classes inherited from class org.eclipse.jface.window.Window
org.eclipse.jface.window.Window.IExceptionHandler
 
Field Summary
(package private)  org.eclipse.swt.widgets.Button card
          Radio button for user selection of "USB-Select"
(package private)  org.eclipse.swt.widgets.Button createPatches
          Button for performing export
(package private)  org.eclipse.swt.widgets.Text directory
          Text field for user input of the target path
(package private)  Mc909SampleEditor editor
          The Mc909SampleEditor from whicht this dialog was opened
(package private)  org.eclipse.swt.widgets.Table existingSamples
          Table of existing samples on the Mc909.
(package private)  java.lang.String exportPath
          The path for sample export (Path to the Mc909īs root folder)
(package private)  org.eclipse.swt.widgets.List exportSamples
          List displaying the currently opened samples to be selected for export.
(package private)  java.io.FilenameFilter fileNameFilter
          FileNameFilter to be used for filtering out potential Mc909 samples
(package private)  org.eclipse.swt.widgets.Button internal
          Radio button for user selection of "USB-Select"
(package private)  ScaleNum nextNum
          ScaleNum for user selection of the next sample number used for export
(package private)  java.util.ArrayList properties
          List of Mc909SampleEditor.Properties representing the currently opened samples
(package private) static java.lang.String SMPL_FOLDER
          Relative path from the Mc909īs root path to the sample directory
 
Fields inherited from class org.eclipse.jface.dialogs.TitleAreaDialog
DLG_IMG_TITLE_BANNER, DLG_IMG_TITLE_ERROR, INFO_MESSAGE, WARNING_MESSAGE
 
Fields inherited from class org.eclipse.jface.dialogs.Dialog
buttonBar, dialogArea, DLG_IMG_ERROR, DLG_IMG_INFO, DLG_IMG_MESSAGE_ERROR, DLG_IMG_MESSAGE_INFO, DLG_IMG_MESSAGE_WARNING, DLG_IMG_QUESTION, DLG_IMG_WARNING
 
Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK
 
Constructor Summary
Export909SamplesDialog(org.eclipse.swt.widgets.Shell parentShell, Mc909SampleEditor.Properties[] properties, Mc909SampleEditor editor)
          Create a new ExportSamplesDialog
 
Method Summary
private  boolean askForOverwrite(int num, java.lang.String samplename, java.lang.String firstCollission, java.lang.String secondCollission, boolean stereo)
          If a collossion between existing samples and samples to be exported is detected, this method can be used to ask, if the existing sample should be overwritten or not
 boolean close()
           
protected  void createButtonsForButtonBar(org.eclipse.swt.widgets.Composite parent)
           
protected  org.eclipse.swt.widgets.Control createDialogArea(org.eclipse.swt.widgets.Composite parent)
           
private  void deleteItem(org.eclipse.swt.widgets.TableItem item)
          Remove the given TableItem from the existing samples table
 void errorMessage(java.lang.String m)
          Display an error message to the user
private  int export()
          Try to export all samples that were marked for export.
private  java.io.File export(Mc909SampleEditor.Properties prop, int sampleNum, java.lang.String path)
          Export one sample
private static java.lang.String fillName(java.lang.String name)
          Get a String of length 16 out of the given String.
private  void fillTable(java.lang.String path)
          Fill the existing samples table if and only if the given path is other than the one used the last time for filling the table.
private  void fillTable(java.lang.String path, boolean force)
          Fill the existing samples table.
private  int getIndexForNum(int num)
          Get the index of the TableItem containing the given sample number
private  org.eclipse.swt.widgets.TableItem getItemForNumber(int nr)
          Get the TableItem containing the sample with the given sample nr.
private  java.lang.String getItemName(org.eclipse.swt.widgets.TableItem item)
          Get a String describing the sample represented by the given TableItem
private  void importSamples(org.eclipse.swt.widgets.TableItem[] items)
          Import the samples represented by the given TableItems from the Mc909 to the editor
private  org.eclipse.swt.widgets.TableItem insertItemAt(int pos)
          Create a new Table Item and insert it into the existing samples table at the given index
protected  void okPressed()
           
private  void transfer()
          Move the selected samples from the open file list to the existing samples table to indicate that they will be exported when completing this dialog.
private  void transferOne(Mc909SampleEditor.Properties p, int desiredNum)
          Move a single sample from the opened files list to the table of samples to be exported
private  boolean tryToOverwrite(int num, boolean stereo, java.lang.String sampleName)
          Find out, with which sample(s) the given sample number collides and try ask the user, if they should be overwritten.
 
Methods inherited from class org.eclipse.jface.dialogs.TitleAreaDialog
createContents, getInitialSize, getTitleArea, getTitleImageLabel, setErrorMessage, setMessage, setMessage, setTitle, setTitleAreaColor, setTitleImage
 
Methods inherited from class org.eclipse.jface.dialogs.Dialog
applyDialogFont, buttonPressed, cancelPressed, configureShell, constrainShellSize, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, createButton, createButtonBar, getButton, getButtonBar, getCancelButton, getDialogArea, getImage, getOKButton, initializeBounds, initializeDialogUnits, setButtonLayoutData, setButtonLayoutFormData
 
Methods inherited from class org.eclipse.jface.window.Window
canHandleShellCloseEvent, create, createShell, getContents, getDefaultImage, getInitialLocation, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, handleShellCloseEvent, open, setBlockOnOpen, setDefaultImage, setExceptionHandler, setReturnCode, setShellStyle, setWindowManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

card

org.eclipse.swt.widgets.Button card
Radio button for user selection of "USB-Select"


createPatches

org.eclipse.swt.widgets.Button createPatches
Button for performing export


directory

org.eclipse.swt.widgets.Text directory
Text field for user input of the target path


editor

final Mc909SampleEditor editor
The Mc909SampleEditor from whicht this dialog was opened


existingSamples

org.eclipse.swt.widgets.Table existingSamples
Table of existing samples on the Mc909. Samples marked for export will also be displayed here.


exportPath

java.lang.String exportPath
The path for sample export (Path to the Mc909īs root folder)


exportSamples

org.eclipse.swt.widgets.List exportSamples
List displaying the currently opened samples to be selected for export.


fileNameFilter

java.io.FilenameFilter fileNameFilter
FileNameFilter to be used for filtering out potential Mc909 samples


internal

org.eclipse.swt.widgets.Button internal
Radio button for user selection of "USB-Select"


nextNum

ScaleNum nextNum
ScaleNum for user selection of the next sample number used for export


properties

java.util.ArrayList properties
List of Mc909SampleEditor.Properties representing the currently opened samples


SMPL_FOLDER

static final java.lang.String SMPL_FOLDER
Relative path from the Mc909īs root path to the sample directory

Constructor Detail

Export909SamplesDialog

public Export909SamplesDialog(org.eclipse.swt.widgets.Shell parentShell,
                              Mc909SampleEditor.Properties[] properties,
                              Mc909SampleEditor editor)
Create a new ExportSamplesDialog

Parameters:
parentShell - The shell to be used as parent shell for this dialog
properties - Array of all Mc909SampleEditor.Properties representing the currently opened files
editor - The Mc909SampleEditor from which this dialog was opened
Method Detail

askForOverwrite

private boolean askForOverwrite(int num,
                                java.lang.String samplename,
                                java.lang.String firstCollission,
                                java.lang.String secondCollission,
                                boolean stereo)
If a collossion between existing samples and samples to be exported is detected, this method can be used to ask, if the existing sample should be overwritten or not

Parameters:
num - The sample number where the sample should be exported to
samplename - The name of the sample to be exported
firstCollission - The number and name of the first (and maybe only) sample the exported one collides with
secondCollission - In some cases a stereo file might collide with two samples at a time. In these cases, this parameter should contain the second colliding existing sample. Otherwise it may be null.
stereo - true, if the exported sample is stereo, false otherwise.
Returns:
true, if the user accepted overwriting, false otherwise.

close

public boolean close()
Overrides:
close in class org.eclipse.jface.dialogs.Dialog

createButtonsForButtonBar

protected void createButtonsForButtonBar(org.eclipse.swt.widgets.Composite parent)
Overrides:
createButtonsForButtonBar in class org.eclipse.jface.dialogs.Dialog

createDialogArea

protected org.eclipse.swt.widgets.Control createDialogArea(org.eclipse.swt.widgets.Composite parent)
Overrides:
createDialogArea in class org.eclipse.jface.dialogs.TitleAreaDialog

deleteItem

private void deleteItem(org.eclipse.swt.widgets.TableItem item)
Remove the given TableItem from the existing samples table

Parameters:
item - The TableItem to remove

errorMessage

public void errorMessage(java.lang.String m)
Display an error message to the user

Parameters:
m - The message to display

export

private int export()
Try to export all samples that were marked for export.

Returns:
The number of samples succesfully exported.

export

private java.io.File export(Mc909SampleEditor.Properties prop,
                            int sampleNum,
                            java.lang.String path)
                     throws java.io.IOException,
                            NotReadyException,
                            NotFinishedException
Export one sample

Parameters:
prop - The Properties object representing the file to export
sampleNum - The sample number to export to
path - The Mc909īs root path to use for export
Returns:
The file to ehich the sample was exported.
Throws:
java.io.IOException - If an I/O error occurs
NotReadyException - If the sample could not be read
NotFinishedException - If the sample export operation could not be finished

fillName

private static java.lang.String fillName(java.lang.String name)
Get a String of length 16 out of the given String.

Parameters:
name - The original String
Returns:
A String of length 16 that gets its content from the given String

fillTable

private void fillTable(java.lang.String path)
Fill the existing samples table if and only if the given path is other than the one used the last time for filling the table.

Parameters:
path - The Mc909īs root path

fillTable

private void fillTable(java.lang.String path,
                       boolean force)
Fill the existing samples table. The force parameter specifies, whether the table should be updated even if the path didnīt change.

Parameters:
path - The Mc909īs root path
force - true, if the tableīs content should be updated even if the path didnīt change, false otherwise

getIndexForNum

private int getIndexForNum(int num)
Get the index of the TableItem containing the given sample number

Parameters:
num - The sample number to get the index for.
Returns:
The index of the TableItem containing the sample with the given number or - if no TableItem was found - the index the next created TableItem will have.

getItemForNumber

private org.eclipse.swt.widgets.TableItem getItemForNumber(int nr)
Get the TableItem containing the sample with the given sample nr.

Parameters:
nr - The sample nr in question
Returns:
The TableItem containing the sample with the given sample nr. If no sample with the given number is found, null will be returned.

getItemName

private java.lang.String getItemName(org.eclipse.swt.widgets.TableItem item)
Get a String describing the sample represented by the given TableItem

Parameters:
item - The TableItem containing the sample
Returns:
A text containing the sampleīs name and the sample number(s).

importSamples

private void importSamples(org.eclipse.swt.widgets.TableItem[] items)
Import the samples represented by the given TableItems from the Mc909 to the editor

Parameters:
items - The TableItems selected for import

insertItemAt

private org.eclipse.swt.widgets.TableItem insertItemAt(int pos)
Create a new Table Item and insert it into the existing samples table at the given index

Parameters:
pos - The index where to insert the Item
Returns:
The new created and inserted TableItem

okPressed

protected void okPressed()
Overrides:
okPressed in class org.eclipse.jface.dialogs.Dialog

transfer

private void transfer()
Move the selected samples from the open file list to the existing samples table to indicate that they will be exported when completing this dialog.


transferOne

private void transferOne(Mc909SampleEditor.Properties p,
                         int desiredNum)
Move a single sample from the opened files list to the table of samples to be exported

Parameters:
p - The Properties object representing the opened sample
desiredNum - The number, where to export the sample to

tryToOverwrite

private boolean tryToOverwrite(int num,
                               boolean stereo,
                               java.lang.String sampleName)
Find out, with which sample(s) the given sample number collides and try ask the user, if they should be overwritten.

Parameters:
num - The sample number in question
stereo - true, if the sample to export is stereo, false otherwise
sampleName - The name of the sample to export
Returns:
true, if the user accepted to overwrite, false otherwise