@Override public void initParameters() { assert (paramMap != null); String fileName = getDefaultFileName(); String format = "BEAM-DIMAP"; final Object formatValue = paramMap.get(FORMAT_PARAMETER); if (formatValue != null) { format = (String) formatValue; } if (fileName != null) { targetProductSelector.getProductNameTextField().setText(fileName); targetProductSelector.getModel().setProductName(fileName); targetProductSelector.getModel().setFormatName(format); } }
@Override public void propertyChange(PropertyChangeEvent evt) { final Product product = (Product) evt.getNewValue(); final TargetProductSelectorModel selectorModel = targetProductSelector.getModel(); if (product != null) { final String formatName = product.getProductReader().getReaderPlugIn().getFormatNames()[0]; final ProductIOPlugInManager ioPlugInManager = ProductIOPlugInManager.getInstance(); final Iterator<ProductWriterPlugIn> writerIterator = ioPlugInManager.getWriterPlugIns(formatName); if (writerIterator.hasNext()) { selectorModel.setFormatName(formatName); } else { final String errMsg = "Cannot write to update product."; final String iseMsg = String.format("No product writer found for format '%s'", formatName); appContext.handleError(errMsg, new IllegalStateException(iseMsg)); } final File fileLocation = product.getFileLocation(); final String fileName = FileUtils.getFilenameWithoutExtension(fileLocation); final File fileDir = fileLocation.getParentFile(); selectorModel.setProductName(fileName); selectorModel.setProductDir(fileDir); } else { selectorModel.setFormatName(ProductIO.DEFAULT_FORMAT_NAME); selectorModel.setProductName("mosaic"); String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final PropertyMap prefs = appContext.getPreferences(); String saveDir = prefs.getPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); selectorModel.setProductDir(new File(saveDir)); } } }
@Override public void propertyChange(PropertyChangeEvent evt) { final Product product = (Product) evt.getNewValue(); final TargetProductSelectorModel selectorModel = targetProductSelector.getModel(); if (product != null) { final String formatName = product.getProductReader().getReaderPlugIn().getFormatNames()[0]; final ProductIOPlugInManager ioPlugInManager = ProductIOPlugInManager.getInstance(); final Iterator<ProductWriterPlugIn> writerIterator = ioPlugInManager.getWriterPlugIns(formatName); if (writerIterator.hasNext()) { selectorModel.setFormatName(formatName); } else { final String errMsg = "Cannot write to update product."; final String iseMsg = String.format("No product writer found for format '%s'", formatName); appContext.handleError(errMsg, new IllegalStateException(iseMsg)); } final File fileLocation = product.getFileLocation(); final String fileName = FileUtils.getFilenameWithoutExtension(fileLocation); final File fileDir = fileLocation.getParentFile(); selectorModel.setProductName(fileName); selectorModel.setProductDir(fileDir); } else { selectorModel.setFormatName(ProductIO.DEFAULT_FORMAT_NAME); selectorModel.setProductName("Multi-size Mosaic"); String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final PropertyMap prefs = appContext.getPreferences(); String saveDir = prefs.getPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); selectorModel.setProductDir(new File(saveDir)); } } }
@Test public void testSetGetFormatName() { model.setFormatName("Majestix"); assertEquals("Majestix", model.getFormatName()); }
setFormatName(ProductIO.DEFAULT_FORMAT_NAME); } else { setFormatName(formatNames[0]);
@Test public void testSetGetDirectory() { final File directory = new File("Gallien"); model.setProductDir(directory); assertEquals(directory, model.getProductDir()); model.setProductName("Obelix"); assertEquals(new File("Gallien", "Obelix.dim"), model.getProductFile()); // other format model.setFormatName(writerPlugIn.getFormatNames()[0]); assertEquals(new File("Gallien", "Obelix.x"), model.getProductFile()); }
@Test public void testGetFileName() { model.setProductName("Obelix"); assertEquals("Obelix", model.getProductName()); assertEquals("Obelix.dim", model.getProductFileName()); // other format model.setFormatName(writerPlugIn.getFormatNames()[0]); assertEquals("Obelix.x", model.getProductFileName()); model.setProductName("Idefix.dim"); assertEquals("Idefix.dim.x", model.getProductFileName()); model.setProductName("Idefix.x"); assertEquals("Idefix.x", model.getProductFileName()); }