private void exportSelectedMasks() { final Mask[] masks = getMaskForm().getSelectedMasks(); if (masks.length == 0) { return; boolean[] masksExported = addContent(masks, document); boolean dialogApproved = false; if (hasAtLeastOneMaskExported(masksExported)) { final JFileChooser fileChooser = new SnapFileChooser(); fileChooser.setDialogTitle(ACTION_NAME); final FileFilter fileFilter = new SnapFileFilter("XML", ".xml", "XML files (*.xml)"); fileChooser.setFileFilter(fileFilter); final File targetDirectory = getDirectory(); fileChooser.setCurrentDirectory(targetDirectory); fileChooser.setSelectedFile(new File(targetDirectory, masks[0].getName())); if (file != null) { if (Boolean.TRUE.equals(Dialogs.requestOverwriteDecision(ACTION_NAME, file))) { setDirectory(file.getAbsoluteFile().getParentFile()); file = FileUtils.ensureExtension(file, ".xml"); writeXml(file, document); boolean allExportsFailed = countFailedMasks(masksExported) == masksExported.length; if (dialogApproved || allExportsFailed) { showUserFeedback(masks, masksExported);
private void showUserFeedback(Mask[] masks, boolean[] masksExported) { StringBuilder stringBuilder = new StringBuilder(); if (countExportedMasks(masksExported) > 0) { stringBuilder.append("Successfully exported mask"); if (countExportedMasks(masksExported) > 1) { stringBuilder.append("s"); final Mask mask = masks[i]; if (masksExported[i]) { addMaskName(stringBuilder, maskIndex++, mask.getName(), countExportedMasks(masksExported)); if (countFailedMasks(masksExported) > 0) { stringBuilder.append("\n"); stringBuilder.append("Unable to export mask"); if (countFailedMasks(masksExported) > 1) { stringBuilder.append("s"); final Mask mask = masks[i]; if (!masksExported[i]) { addMaskName(stringBuilder, maskIndex++, mask.getName(), countFailedMasks(masksExported));
@Override public void actionPerformed(ActionEvent e) { exportSelectedMasks(); }
MaskFormActions(ToolTopComponent maskTopComponent, MaskForm maskForm) { maskActions = new MaskAction[]{ new NewBandMathsAction(maskForm), new NewRangeAction(maskForm), new NewVectorDataNodeAction(maskForm), new NullAction(maskForm), new NewUnionAction(maskForm), new NewIntersectionAction(maskForm), new NewDifferenceAction(maskForm), new NewInvDifferenceAction(maskForm), new NewComplementAction(maskForm), new NullAction(maskForm), new CopyAction(maskForm), new EditAction(maskForm), new RemoveAction(maskForm), new TransferAction(maskForm), new ImportAction(maskTopComponent, maskForm), new ExportAction(maskTopComponent, maskForm), new ZoomToVectorMaskAction(maskTopComponent, maskForm), new NullAction(maskForm), }; }
@Override void updateState() { setEnabled(getMaskForm().isInManagementMode() && getMaskForm().getSelectedRowCount() > 0); }