1 package fr.ifremer.tutti.ui.swing.util.attachment.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import fr.ifremer.tutti.ui.swing.util.actions.SimpleActionSupport;
28 import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
29 import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentItem;
30 import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentItemModel;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.nuiton.jaxx.application.ApplicationTechnicalException;
34
35 import java.io.File;
36
37 import static org.nuiton.i18n.I18n.t;
38
39
40
41
42
43
44
45 public class OpenAttachmentAction extends SimpleActionSupport<AttachmentItem> {
46
47
48 private static final Log log = LogFactory.getLog(OpenAttachmentAction.class);
49
50 private static final long serialVersionUID = 1L;
51
52 public OpenAttachmentAction(AttachmentItem ui) {
53 super(ui);
54 }
55
56 @Override
57 protected void onActionPerformed(AttachmentItem ui) {
58
59 AttachmentItemModel model = ui.getModel();
60
61 File file;
62
63 if (model.isCreate()) {
64 file = new File(model.getPath());
65
66 } else {
67 file = ui.getHandler().getPersistenceService().getAttachmentFile(model.getId());
68 }
69
70 if (!file.exists()) {
71 throw new ApplicationTechnicalException(t("tutti.attachmentEditor.fileNotFound", file.getAbsolutePath()));
72 }
73
74 if (log.isInfoEnabled()) {
75 log.info("Open attachment: " + file);
76 }
77 TuttiUIUtil.openResource(file);
78
79 }
80
81 }