private void createXYDisplacementBands(Product product) { final SnapApp snapApp = SnapApp.getDefault(); final Frame mainFrame = snapApp.getMainFrame(); String dialogTitle = Bundle.CTL_CreateGeoCodingDisplacementBandsDialogTitle(); final ProgressMonitorSwingWorker swingWorker = new ProgressMonitorSwingWorker<Band[], Object>(mainFrame, dialogTitle) { @Override protected Band[] doInBackground(ProgressMonitor pm) throws Exception { final Band[] xyDisplacementBands = createXYDisplacementBands(product, pm); UndoRedo.Manager undoManager = SnapApp.getDefault().getUndoManager(product); if (undoManager != null) { undoManager.addEdit( new UndoableDisplacementBandsCreation(product, xyDisplacementBands)); } return xyDisplacementBands; } @Override public void done() { if (snapApp .getPreferences() .getBoolean(UiBehaviorController.PREFERENCE_KEY_AUTO_SHOW_NEW_BANDS, true)) { try { Band[] bands = get(); if (bands == null) { return; } for (Band band : bands) { Band oldBand = product.getBand(band.getName()); if (oldBand != null) { product.removeBand(oldBand); } product.addBand(band); } } catch (Exception e) { Throwable cause = e; if (e instanceof ExecutionException) { cause = e.getCause(); } String msg = "An internal error occurred:\n" + e.getMessage(); if (cause instanceof IOException) { msg = "An I/O error occurred:\n" + e.getMessage(); } SnapDialogs.showError(dialogTitle, msg); } finally { UIUtils.setRootFrameDefaultCursor(mainFrame); } } } }; swingWorker.execute(); }