public void setTargetFolder(final File path) { if (targetProductSelector != null) { final TargetProductSelectorModel targetProductSelectorModel = targetProductSelector.getModel(); targetProductSelectorModel.setProductDir(path); } }
@Override public void actionPerformed(ActionEvent event) { Window windowAncestor = null; if (event.getSource() instanceof JComponent) { JComponent eventSource = (JComponent) event.getSource(); windowAncestor = SwingUtilities.getWindowAncestor(eventSource); } final JFileChooser chooser = FileChooserFactory.getInstance().createDirChooser(model.getProductDir()); chooser.setDialogTitle("Select Target Directory"); if (chooser.showDialog(windowAncestor, APPROVE_BUTTON_TEXT) == JFileChooser.APPROVE_OPTION) { final File selectedDir = chooser.getSelectedFile(); if (selectedDir != null) { model.setProductDir(selectedDir); } else { model.setProductDir(new File(".")); } } } }
@Override public JComponent CreateOpTab(String operatorName, Map<String, Object> parameterMap, AppContext appContext) { initializeOperatorUI(operatorName, parameterMap); final JComponent panel = createPanel(); initParameters(); divisionBy.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { updateDivisionBy(); } }); File saveDir = null; final Object value = paramMap.get(FILE_PARAMETER); if (value != null) { final File file = (File) value; saveDir = file.getParentFile(); } if (saveDir == null) { final String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final String savePath = SnapApp.getDefault().getPreferences().get(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); saveDir = new File(savePath); } targetProductSelector.getModel().setProductDir(saveDir); targetProductSelector.getOpenInAppCheckBox().setText("Open in " + appContext.getApplicationName()); return panel; }
@Override public JComponent CreateOpTab(String operatorName, Map<String, Object> parameterMap, AppContext appContext) { paramMap = parameterMap; targetProductSelector = new TargetProductSelector(new TargetProductSelectorModel(), true); this.appContext = appContext; File saveDir = null; final Object value = paramMap.get(FILE_PARAMETER); if (value != null) { final File file = (File) value; saveDir = file.getParentFile(); } if (saveDir == null) { final String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final String savePath = SnapApp.getDefault().getPreferences().get(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); saveDir = new File(savePath); } targetProductSelector.getModel().setProductDir(saveDir); initParameters(); return targetProductSelector.createDefaultPanel(); }
File outputDir = outputFile.getParentFile(); if (outputDir != null) { getTargetProductSelector().getModel().setProductDir(outputDir);
@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)); } } }
@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)); } } }
final String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final String saveDir = SnapApp.getDefault().getPreferences().get(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); targetProductSelector.getModel().setProductDir(new File(saveDir)); targetProductSelector.getOpenInAppCheckBox().setText("Open in " + theAppContext.getApplicationName());
protected SingleTargetProductDialog(AppContext appContext, String title, int buttonMask, String helpID, TargetProductSelectorModel model, boolean alwaysWriteOutput) { super(appContext.getApplicationWindow(), title, buttonMask, helpID); this.appContext = appContext; targetProductSelector = new TargetProductSelector(model, alwaysWriteOutput); String homeDirPath = SystemUtils.getUserHomeDir().getPath(); String saveDir = appContext.getPreferences().getPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); targetProductSelector.getModel().setProductDir(new File(saveDir)); if (!alwaysWriteOutput) { targetProductSelector.getOpenInAppCheckBox().setText("Open in " + appContext.getApplicationName()); } targetProductSelector.getModel().getValueContainer().addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("saveToFileSelected") || evt.getPropertyName().equals("openInAppSelected")) { updateRunButton(); } }); AbstractButton button = getButton(ID_APPLY); button.setText("Run"); button.setMnemonic('R'); updateRunButton(); }
targetProductSelectorModel.setProductDir(operatorDescriptor.resolveVariables(operatorDescriptor.getWorkingDir()));
public ProductSetPanel(final AppContext theAppContext, final String title, final FileTable fileTable, final boolean incTrgProduct, final boolean incButtonPanel) { super(new BorderLayout()); this.appContext = theAppContext; this.productSetTable = fileTable; setBorderTitle(title); final JPanel productSetContent = createComponent(productSetTable); if (incButtonPanel) { buttonPanel = createButtonPanel(productSetTable); productSetContent.add(buttonPanel, BorderLayout.EAST); } this.add(productSetContent, BorderLayout.CENTER); if (incTrgProduct) { targetProductSelector = new TargetFolderSelector(); final String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final String saveDir = SnapApp.getDefault().getPreferences().get(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); targetProductSelector.getModel().setProductDir(new File(saveDir)); targetProductSelector.getOpenInAppCheckBox().setText("Open in " + theAppContext.getApplicationName()); targetProductSelector.getOpenInAppCheckBox().setVisible(false); this.add(targetProductSelector.createPanel(), BorderLayout.SOUTH); } else { targetProductSelector = null; } fileTable.getModel().addTableModelListener(this); updateComponents(); }
@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()); }