ManagerFile.java

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.manager;
12
13
import com.jsql.util.LogLevelUtil;
14
import com.jsql.view.swing.list.ItemList;
15
import com.jsql.view.swing.manager.util.StateButton;
16
import com.jsql.view.swing.util.I18nViewUtil;
17
import com.jsql.view.swing.util.MediatorHelper;
18
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
20
21
import javax.swing.*;
22
import java.awt.*;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
25
import java.util.Arrays;
26
import java.util.List;
27
28
/**
29
 * Manager to read a file from the host.
30
 */
31
public class ManagerFile extends AbstractManagerList {
32
33
    private static final Logger LOGGER = LogManager.getRootLogger();
34
35
    /**
36
     * Create the manager panel to read a file.
37
     */
38
    public ManagerFile() {
39
        super("swing/list/file.txt");
40 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerFile::buildRunButton → NO_COVERAGE
        this.buildRunButton("FILE_RUN_BUTTON_LABEL", "FILE_RUN_BUTTON_TOOLTIP");
41 1 1. <init> : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE
        this.run.setEnabled(false);
42 1 1. <init> : removed call to com/jsql/view/swing/manager/util/JButtonStateful::addActionListener → NO_COVERAGE
        this.run.addActionListener(new ActionFile());
43 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerFile::buildPrivilege → NO_COVERAGE
        this.buildPrivilege();
44 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerFile::add → NO_COVERAGE
        this.add(this.lastLine, BorderLayout.SOUTH);
45
    }
46
47
    private class ActionFile implements ActionListener {
48
        @Override
49
        public void actionPerformed(ActionEvent e) {
50 1 1. actionPerformed : negated conditional → NO_COVERAGE
            if (ManagerFile.this.listPaths.getSelectedValuesList().isEmpty()) {
51
                LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Select in the list at least one file to read");
52
                return;
53
            }
54
            if (!Arrays.asList(
55
                MediatorHelper.model().getMediatorEngine().getSqlite(),
56
                MediatorHelper.model().getMediatorEngine().getDerby(),
57
                MediatorHelper.model().getMediatorEngine().getH2(),
58
                MediatorHelper.model().getMediatorEngine().getHsqldb(),
59
                MediatorHelper.model().getMediatorEngine().getMysql(),
60
                MediatorHelper.model().getMediatorEngine().getPostgres()
61 1 1. actionPerformed : negated conditional → NO_COVERAGE
            ).contains(MediatorHelper.model().getMediatorEngine().getEngine())) {
62
                LOGGER.log(
63
                    LogLevelUtil.CONSOLE_ERROR,
64
                    "Read file not implemented for [{}], share a working example on GitHub to speed up release",
65
                    MediatorHelper.model().getMediatorEngine().getEngine()
66
                );
67
                return;
68
            }
69
            new SwingWorker<>() {
70
                @Override
71
                protected Object doInBackground() {
72 1 1. doInBackground : removed call to java/lang/Thread::setName → NO_COVERAGE
                    Thread.currentThread().setName("SwingWorkerManagerFile");
73 1 1. doInBackground : negated conditional → NO_COVERAGE
                    if (ManagerFile.this.run.getState() == StateButton.STARTABLE) {
74 1 1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE
                        ManagerFile.this.run.setText(I18nViewUtil.valueByKey("FILE_RUN_BUTTON_STOP"));
75 1 1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
                        ManagerFile.this.run.setState(StateButton.STOPPABLE);
76 1 1. doInBackground : removed call to java/awt/Component::setVisible → NO_COVERAGE
                        ManagerFile.this.horizontalGlue.setVisible(false);
77 1 1. doInBackground : removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE
                        ManagerFile.this.progressBar.setVisible(true);
78
                        try {
79
                            List<String> filePaths = ManagerFile.this.listPaths.getSelectedValuesList().stream().map(ItemList::toString).toList();
80
                            MediatorHelper.model().getResourceAccess().readFile(filePaths);
81
                        } catch (InterruptedException e) {
82
                            LOGGER.log(LogLevelUtil.IGNORE, e, e);
83 1 1. doInBackground : removed call to java/lang/Thread::interrupt → NO_COVERAGE
                            Thread.currentThread().interrupt();
84
                        } catch (Exception e) {
85
                            LOGGER.log(LogLevelUtil.CONSOLE_ERROR, e, e);
86
                        }
87 1 1. doInBackground : removed call to com/jsql/view/swing/manager/ManagerFile::endProcess → NO_COVERAGE
                        ManagerFile.this.endProcess();
88
                    } else {
89 1 1. doInBackground : removed call to com/jsql/model/accessible/ResourceAccess::stopSearchFile → NO_COVERAGE
                        MediatorHelper.model().getResourceAccess().stopSearchFile();
90 1 1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE
                        ManagerFile.this.run.setEnabled(false);
91 1 1. doInBackground : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
                        ManagerFile.this.run.setState(StateButton.STOPPING);
92
                    }
93
                    return null;
94
                }
95 1 1. actionPerformed : removed call to com/jsql/view/swing/manager/ManagerFile$ActionFile$1::execute → NO_COVERAGE
            }.execute();
96
        }
97
    }
98
}

Mutations

40

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerFile::buildRunButton → NO_COVERAGE

41

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE

42

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::addActionListener → NO_COVERAGE

43

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerFile::buildPrivilege → NO_COVERAGE

44

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerFile::add → NO_COVERAGE

50

1.1
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

61

1.1
Location : actionPerformed
Killed by : none
negated conditional → NO_COVERAGE

72

1.1
Location : doInBackground
Killed by : none
removed call to java/lang/Thread::setName → NO_COVERAGE

73

1.1
Location : doInBackground
Killed by : none
negated conditional → NO_COVERAGE

74

1.1
Location : doInBackground
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE

75

1.1
Location : doInBackground
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE

76

1.1
Location : doInBackground
Killed by : none
removed call to java/awt/Component::setVisible → NO_COVERAGE

77

1.1
Location : doInBackground
Killed by : none
removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE

83

1.1
Location : doInBackground
Killed by : none
removed call to java/lang/Thread::interrupt → NO_COVERAGE

87

1.1
Location : doInBackground
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerFile::endProcess → NO_COVERAGE

89

1.1
Location : doInBackground
Killed by : none
removed call to com/jsql/model/accessible/ResourceAccess::stopSearchFile → NO_COVERAGE

90

1.1
Location : doInBackground
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE

91

1.1
Location : doInBackground
Killed by : none
removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE

95

1.1
Location : actionPerformed
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerFile$ActionFile$1::execute → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.22.1