putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl shift I"));
}
@Override
public void actionPerformed(ActionEvent e) {
Bossanova2 application = BossaNovaReferentComponent.getSingleton().getApplication();
try {
JTable table = BossaNovaReferentComponent.getSingleton().getApplication().getMainScreen().getBatchViewerPanel().getTable();
String defaultPath = BossanovaUserPref.getPref(BossanovaUserPref.BATCH_DIRECTORY, System.getProperty("user.home"));
JFileChooser fileChooser = new JFileChooser(defaultPath);
fileChooser.showOpenDialog(application.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)
BossaNovaReferentComponent.getSingleton().getApplication().setSelectedStep(batch.getStep(0), false);
table.getSelectionModel().setSelectionInterval(index+1, index+1);
StateMachine.getInstance().transitionTo(StateMachine.MODEL_OPEN);
}
}
} catch (Exception e1) {
e1.printStackTrace();
PopupUtil.showError(application.getMainScreen(), HMIMessages.ERROR_GENERIC, "Didn't work out"
+ e1.getMessage());
}
}