1 package fr.ifremer.dali.ui.swing.content.extraction.list;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import fr.ifremer.dali.ui.swing.action.AbstractDaliAction;
25
26 import java.io.File;
27
28 import static org.nuiton.i18n.I18n.t;
29
30
31
32
33 public class ExportExtractionAction extends AbstractDaliAction<ExtractionsTableUIModel, ExtractionsTableUI, ExtractionsTableUIHandler> {
34
35 private File exportFile;
36
37
38
39
40
41
42 public ExportExtractionAction(ExtractionsTableUIHandler handler) {
43 super(handler, false);
44 }
45
46 @Override
47 public boolean prepareAction() throws Exception {
48 if (!super.prepareAction()) return false;
49
50 if (getModel().getSingleSelectedRow() == null) {
51 return false;
52 }
53
54 if (getModel().getSingleSelectedRow().isDirty()) {
55 getContext().getDialogHelper().showWarningDialog(
56 t("dali.extraction.list.export.dirty.message"),
57 t("dali.extraction.list.export.title")
58 );
59 return false;
60 }
61
62 String fileName = String.format("%s-%s", t("dali.service.extraction.file.prefix"), getModel().getSingleSelectedRow().getName());
63 String fileExtension = getConfig().getExtractionFileExtension();
64 exportFile = saveFile(
65 fileName,
66 fileExtension,
67 t("dali.extraction.list.export.title"),
68 t("dali.common.export"),
69 "^.*\\." + fileExtension,
70 t("dali.common.file." + fileExtension)
71 );
72
73 return exportFile != null;
74 }
75
76 @Override
77 public void doAction() throws Exception {
78
79 getContext().getExtractionService().exportExtraction(getModel().getSingleSelectedRow(), exportFile);
80 }
81
82 @Override
83 protected void releaseAction() {
84 super.releaseAction();
85
86 exportFile = null;
87 }
88 }