1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2025. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | *******************************************************************************/ | |
11 | package com.jsql.view.swing.list; | |
12 | ||
13 | import com.jsql.util.I18nUtil; | |
14 | import com.jsql.util.LogLevelUtil; | |
15 | import com.jsql.view.swing.util.MediatorHelper; | |
16 | import org.apache.logging.log4j.LogManager; | |
17 | import org.apache.logging.log4j.Logger; | |
18 | ||
19 | import javax.swing.*; | |
20 | import java.awt.event.ActionEvent; | |
21 | import java.awt.event.ActionListener; | |
22 | import java.io.FileOutputStream; | |
23 | import java.io.IOException; | |
24 | import java.io.PrintStream; | |
25 | import java.nio.charset.StandardCharsets; | |
26 | ||
27 | /** | |
28 | * Action to export a JList. | |
29 | */ | |
30 | public class MenuActionExport implements ActionListener { | |
31 | | |
32 | /** | |
33 | * Log4j logger sent to view. | |
34 | */ | |
35 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
36 | ||
37 | /** | |
38 | * List to export. | |
39 | */ | |
40 | private final DnDList myList; | |
41 | | |
42 | /** | |
43 | * Create action to export a list. | |
44 | * @param myList List to export. | |
45 | */ | |
46 | public MenuActionExport(DnDList myList) { | |
47 | this.myList = myList; | |
48 | } | |
49 | ||
50 | @Override | |
51 | public void actionPerformed(ActionEvent actionEvent) { | |
52 | final JFileChooser importFileDialog = new JFileChooser(MediatorHelper.model().getMediatorUtils().getPreferencesUtil().getPathFile()) { | |
53 | @Override | |
54 | public void approveSelection() { | |
55 | var file = this.getSelectedFile(); | |
56 |
2
1. approveSelection : negated conditional → NO_COVERAGE 2. approveSelection : negated conditional → NO_COVERAGE |
if (file.exists() && this.getDialogType() == JFileChooser.SAVE_DIALOG) { |
57 | int replace = JOptionPane.showConfirmDialog( | |
58 | MediatorHelper.frame(), | |
59 | String.format("%s %s", file.getName(), I18nUtil.valueByKey("LIST_EXPORT_CONFIRM_LABEL")), | |
60 | I18nUtil.valueByKey("LIST_EXPORT_CONFIRM_TITLE"), | |
61 | JOptionPane.YES_NO_OPTION | |
62 | ); | |
63 | | |
64 | switch (replace) { | |
65 | case JOptionPane.YES_OPTION: | |
66 |
1
1. approveSelection : removed call to javax/swing/JFileChooser::approveSelection → NO_COVERAGE |
super.approveSelection(); |
67 | return; | |
68 | case JOptionPane.NO_OPTION: | |
69 | case JOptionPane.CLOSED_OPTION: | |
70 | return; | |
71 | case JOptionPane.CANCEL_OPTION: | |
72 |
1
1. approveSelection : removed call to com/jsql/view/swing/list/MenuActionExport$1::cancelSelection → NO_COVERAGE |
this.cancelSelection(); |
73 | return; | |
74 | default: | |
75 | break; | |
76 | } | |
77 | } else { | |
78 |
1
1. approveSelection : removed call to javax/swing/JFileChooser::approveSelection → NO_COVERAGE |
super.approveSelection(); |
79 | } | |
80 | } | |
81 | }; | |
82 | | |
83 |
1
1. actionPerformed : removed call to javax/swing/JFileChooser::setDialogTitle → NO_COVERAGE |
importFileDialog.setDialogTitle(I18nUtil.valueByKey("LIST_EXPORT_TITLE")); |
84 | int choice = importFileDialog.showSaveDialog(this.myList.getTopLevelAncestor()); | |
85 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (choice != JFileChooser.APPROVE_OPTION) { |
86 | return; | |
87 | } | |
88 | ||
89 | try ( | |
90 | var file = new FileOutputStream(importFileDialog.getSelectedFile()); | |
91 | var out = new PrintStream(file, false, StandardCharsets.UTF_8) | |
92 | ) { | |
93 | int len = this.myList.getModel().getSize(); | |
94 |
2
1. actionPerformed : changed conditional boundary → NO_COVERAGE 2. actionPerformed : negated conditional → NO_COVERAGE |
for (var i = 0 ; i < len ; i++) { |
95 |
1
1. actionPerformed : removed call to java/io/PrintStream::println → NO_COVERAGE |
out.println(this.myList.getModel().getElementAt(i).toString()); |
96 | } | |
97 | } catch (IOException e) { | |
98 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
99 | } | |
100 | } | |
101 | } | |
Mutations | ||
56 |
1.1 2.2 |
|
66 |
1.1 |
|
72 |
1.1 |
|
78 |
1.1 |
|
83 |
1.1 |
|
85 |
1.1 |
|
94 |
1.1 2.2 |
|
95 |
1.1 |