JTable table = BossaNovaData.getSingleton().getApplication().getMainScreen().getBatchViewerPanel().getTable();
String defaultPath = BossanovaUserPref.getPref(BossanovaUserPref.BATCH_DIRECTORY, System.getProperty("user.home"));
JFileChooser fileChooser = new JFileChooser(defaultPath);
fileChooser.showOpenDialog(BossaNovaData.getSingleton().getApplication().getMainScreen());
File selectedFile = fileChooser.getSelectedFile();
Batch batch = null;
if (selectedFile != null) {
batch = BatchManager.readBatchFile(selectedFile);
int index = table.getSelectedRow();
// if no step were selected we import the batch in the end of the current batch
// if the current batch is empty we import the batch content in the current batch in the begin
if(index < 0 || index == table.getRowCount())
{
index = table.getRowCount() - 1;
}
if (batch.getSteps()!=null && batch.getSteps().size()>0) {
sequencer.insertStepsAt(batch.getSteps(),index+1);
// We select the new step.
if(batch.getSteps().size() > 0)
BossaNovaData.getSingleton().getApplication().setSelectedStep(0,batch.getStep(0));
table.getSelectionModel().setSelectionInterval(index+1, index+1);
StateMachine.getInstance().transitionTo(StateMachine.MODEL_OPEN);