AbstractManagerList.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.I18nUtil;
14
import com.jsql.util.LogLevelUtil;
15
import com.jsql.view.swing.list.DnDList;
16
import com.jsql.view.swing.list.ItemList;
17
import com.jsql.view.swing.manager.util.JButtonStateful;
18
import com.jsql.view.swing.manager.util.StateButton;
19
import com.jsql.view.swing.text.JToolTipI18n;
20
import com.jsql.view.swing.util.I18nViewUtil;
21
import com.jsql.view.swing.util.UiUtil;
22
import org.apache.commons.lang3.StringUtils;
23
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
25
26
import javax.swing.*;
27
import java.awt.*;
28
import java.io.BufferedReader;
29
import java.io.IOException;
30
import java.io.InputStreamReader;
31
import java.nio.charset.StandardCharsets;
32
import java.util.ArrayList;
33
import java.util.List;
34
import java.util.Objects;
35
import java.util.concurrent.atomic.AtomicBoolean;
36
import java.util.concurrent.atomic.AtomicReference;
37
import java.util.stream.StreamSupport;
38
39
/**
40
 * Abstract manager containing a drag and drop list of item.
41
 */
42
public abstract class AbstractManagerList extends JPanel {
43
44
    /**
45
     * Log4j logger sent to view.
46
     */
47
    private static final Logger LOGGER = LogManager.getRootLogger();
48
49
    public static final String PRIVILEGE_TOOLTIP = "PRIVILEGE_TOOLTIP";
50
    protected final transient List<ItemList> itemsList = new ArrayList<>();
51
    protected final JPanel lastLine = new JPanel();
52
53
    /**
54
     * Contains the paths of files.
55
     */
56
    protected DnDList listPaths;
57
    protected final JScrollPane scrollListPaths;
58
59
    /**
60
     * Starts the upload process.
61
     */
62
    protected JButtonStateful run;
63
64
    /**
65
     * Display the FILE privilege of current user.
66
     */
67
    protected JLabel privilege;
68
69
    /**
70
     * Text of the button that start the upload process.
71
     * Used to get back the default text after a search (defaultText->"Stop"->defaultText).
72
     */
73
    protected String labelI18nRunButton;
74
    protected String tooltipI18nRunButton;
75
76
    /**
77
     * An animated bar displayed during processing.
78
     */
79
    protected final JProgressBar progressBar = new JProgressBar();
80
    protected final Component horizontalGlue = Box.createHorizontalGlue();
81
82
    protected AbstractManagerList(String nameFile) {
83 1 1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerList::setLayout → NO_COVERAGE
        this.setLayout(new BorderLayout());
84
85 1 1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerList::buildList → NO_COVERAGE
        this.buildList(nameFile);
86 1 1. <init> : removed call to javax/swing/JProgressBar::setIndeterminate → NO_COVERAGE
        this.progressBar.setIndeterminate(true);
87 1 1. <init> : removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE
        this.progressBar.setVisible(false);
88 1 1. <init> : removed call to javax/swing/JProgressBar::setBorder → NO_COVERAGE
        this.progressBar.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
89 1 1. <init> : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE
        this.lastLine.setLayout(new BoxLayout(this.lastLine, BoxLayout.X_AXIS));
90
91
        this.scrollListPaths = new JScrollPane(this.listPaths);
92 1 1. <init> : removed call to com/jsql/view/swing/manager/AbstractManagerList::add → NO_COVERAGE
        this.add(this.scrollListPaths, BorderLayout.CENTER);
93
    }
94
95
    public void buildRunButton(String labelI18n, String tooltipI18n) {
96
        this.labelI18nRunButton = labelI18n;
97
        this.tooltipI18nRunButton = tooltipI18n;
98
        var tooltip = new AtomicReference<>(new JToolTipI18n(I18nUtil.valueByKey(this.tooltipI18nRunButton)));
99
        this.run = new JButtonStateful(this.labelI18nRunButton) {
100
            @Override
101
            public JToolTip createToolTip() {
102 1 1. createToolTip : replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList$1::createToolTip → NO_COVERAGE
                return tooltip.get();
103
            }
104
        };
105 1 1. buildRunButton : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey(this.labelI18nRunButton, this.run);
106 1 1. buildRunButton : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey(this.tooltipI18nRunButton, tooltip.get());
107 1 1. buildRunButton : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setToolTipText → NO_COVERAGE
        this.run.setToolTipText(I18nUtil.valueByKey(this.tooltipI18nRunButton));
108
    }
109
110
    public void buildList(String nameFile) {
111
        try (
112
            var inputStream = UiUtil.class.getClassLoader().getResourceAsStream(nameFile);
113
            var inputStreamReader = new InputStreamReader(Objects.requireNonNull(inputStream), StandardCharsets.UTF_8);
114
            var reader = new BufferedReader(inputStreamReader)
115
        ) {
116
            String line;
117 1 1. buildList : negated conditional → NO_COVERAGE
            while ((line = reader.readLine()) != null) {
118
                this.itemsList.add(new ItemList(line));
119
            }
120
            this.listPaths = new DnDList(this.itemsList);
121
        } catch (IOException e) {
122
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
123
        }
124
    }
125
126
    public void buildPrivilege() {
127
        var tooltip = new AtomicReference<>(new JToolTipI18n(I18nUtil.valueByKey(AbstractManagerList.PRIVILEGE_TOOLTIP)));
128
        this.privilege = new JLabel(I18nUtil.valueByKey("PRIVILEGE_LABEL"), UiUtil.SQUARE.getIcon(), SwingConstants.LEFT) {
129
            @Override
130
            public JToolTip createToolTip() {
131 1 1. createToolTip : replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList$2::createToolTip → NO_COVERAGE
                return tooltip.get();
132
            }
133
        };
134 1 1. buildPrivilege : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("PRIVILEGE_LABEL", this.privilege);
135 1 1. buildPrivilege : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey(AbstractManagerList.PRIVILEGE_TOOLTIP, tooltip.get());
136 1 1. buildPrivilege : removed call to javax/swing/JLabel::setToolTipText → NO_COVERAGE
        this.privilege.setToolTipText(I18nUtil.valueByKey(AbstractManagerList.PRIVILEGE_TOOLTIP));
137
138
        this.lastLine.add(Box.createHorizontalStrut(5));
139
        this.lastLine.add(this.privilege);
140
        this.lastLine.add(this.horizontalGlue);
141
        this.lastLine.add(this.progressBar);
142
        this.lastLine.add(this.run);
143
    }
144
145
    /**
146
     * Add a new string to the list if it's not a duplicate.
147
     * @param element The string to add to the list
148
     */
149
    public void addToList(String element) {
150
        AtomicBoolean isFound = new AtomicBoolean(false);
151
152
        DefaultListModel<ItemList> listModel = (DefaultListModel<ItemList>) this.listPaths.getModel();
153 1 1. lambda$addToList$0 : replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList::lambda$addToList$0 → NO_COVERAGE
        Iterable<ItemList> iterable = () -> listModel.elements().asIterator();
154
        StreamSupport.stream(iterable.spliterator(), false)
155 2 1. lambda$addToList$1 : replaced boolean return with false for com/jsql/view/swing/manager/AbstractManagerList::lambda$addToList$1 → NO_COVERAGE
2. lambda$addToList$1 : replaced boolean return with true for com/jsql/view/swing/manager/AbstractManagerList::lambda$addToList$1 → NO_COVERAGE
            .filter(itemList -> itemList.toString().equals(element))
156 2 1. lambda$addToList$2 : removed call to java/util/concurrent/atomic/AtomicBoolean::set → NO_COVERAGE
2. addToList : removed call to java/util/stream/Stream::forEach → NO_COVERAGE
            .forEach(itemList -> isFound.set(true));
157
158 1 1. addToList : negated conditional → NO_COVERAGE
        if (!isFound.get()) {
159 1 1. addToList : removed call to javax/swing/DefaultListModel::add → NO_COVERAGE
            listModel.add(0, new ItemList(element));
160
        }
161
    }
162
    
163
    public void highlight(String url, String tag) {
164
        var itemLabel = String.format(" [%s]", tag);
165
        DefaultListModel<ItemList> listModel = (DefaultListModel<ItemList>) this.listPaths.getModel();
166 2 1. highlight : changed conditional boundary → NO_COVERAGE
2. highlight : negated conditional → NO_COVERAGE
        for (var i = 0 ; i < listModel.getSize() ; i++) {
167
            ItemList itemList = listModel.getElementAt(i);
168 1 1. highlight : negated conditional → NO_COVERAGE
            if (url.contains(itemList.getOriginalString())) {
169 1 1. highlight : removed call to com/jsql/view/swing/list/ItemList::setVulnerable → NO_COVERAGE
                itemList.setVulnerable(true);
170 1 1. highlight : removed call to com/jsql/view/swing/list/ItemList::setInternalString → NO_COVERAGE
                itemList.setInternalString(
171
                    itemList.getInternalString().replace(itemLabel, StringUtils.EMPTY) + itemLabel
172
                );
173 1 1. highlight : removed call to javax/swing/DefaultListModel::setElementAt → NO_COVERAGE
                listModel.setElementAt(itemList, i);
174
            }
175
        }
176
    }
177
    
178
    public void endProcess() {
179 1 1. endProcess : removed call to javax/swing/SwingUtilities::invokeLater → NO_COVERAGE
        SwingUtilities.invokeLater(() -> {  // required to prevent scan glitches
180 1 1. lambda$endProcess$3 : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE
            this.run.setText(I18nViewUtil.valueByKey(this.labelI18nRunButton));
181 1 1. lambda$endProcess$3 : removed call to com/jsql/view/swing/manager/AbstractManagerList::setButtonEnable → NO_COVERAGE
            this.setButtonEnable(true);
182 1 1. lambda$endProcess$3 : removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE
            this.progressBar.setVisible(false);
183 1 1. lambda$endProcess$3 : removed call to java/awt/Component::setVisible → NO_COVERAGE
            this.horizontalGlue.setVisible(true);
184 1 1. lambda$endProcess$3 : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE
            this.run.setState(StateButton.STARTABLE);
185
        });
186
    }
187
188
    /**
189
     * Enable or disable the button.
190
     * @param isEnable The new state of the button
191
     */
192
    public void setButtonEnable(boolean isEnable) {
193 1 1. setButtonEnable : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE
        this.run.setEnabled(isEnable);
194
    }
195
196
    /**
197
     * Display another icon to the Privilege label.
198
     * @param icon The new icon
199
     */
200
    public void changePrivilegeIcon(Icon icon) {
201 1 1. changePrivilegeIcon : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE
        this.privilege.setIcon(icon);
202
    }
203
}

Mutations

83

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

85

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

86

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JProgressBar::setIndeterminate → NO_COVERAGE

87

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

88

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JProgressBar::setBorder → NO_COVERAGE

89

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JPanel::setLayout → NO_COVERAGE

92

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

102

1.1
Location : createToolTip
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList$1::createToolTip → NO_COVERAGE

105

1.1
Location : buildRunButton
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

106

1.1
Location : buildRunButton
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

107

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

117

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

131

1.1
Location : createToolTip
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList$2::createToolTip → NO_COVERAGE

134

1.1
Location : buildPrivilege
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

135

1.1
Location : buildPrivilege
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

136

1.1
Location : buildPrivilege
Killed by : none
removed call to javax/swing/JLabel::setToolTipText → NO_COVERAGE

153

1.1
Location : lambda$addToList$0
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/AbstractManagerList::lambda$addToList$0 → NO_COVERAGE

155

1.1
Location : lambda$addToList$1
Killed by : none
replaced boolean return with false for com/jsql/view/swing/manager/AbstractManagerList::lambda$addToList$1 → NO_COVERAGE

2.2
Location : lambda$addToList$1
Killed by : none
replaced boolean return with true for com/jsql/view/swing/manager/AbstractManagerList::lambda$addToList$1 → NO_COVERAGE

156

1.1
Location : lambda$addToList$2
Killed by : none
removed call to java/util/concurrent/atomic/AtomicBoolean::set → NO_COVERAGE

2.2
Location : addToList
Killed by : none
removed call to java/util/stream/Stream::forEach → NO_COVERAGE

158

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

159

1.1
Location : addToList
Killed by : none
removed call to javax/swing/DefaultListModel::add → NO_COVERAGE

166

1.1
Location : highlight
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : highlight
Killed by : none
negated conditional → NO_COVERAGE

168

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

169

1.1
Location : highlight
Killed by : none
removed call to com/jsql/view/swing/list/ItemList::setVulnerable → NO_COVERAGE

170

1.1
Location : highlight
Killed by : none
removed call to com/jsql/view/swing/list/ItemList::setInternalString → NO_COVERAGE

173

1.1
Location : highlight
Killed by : none
removed call to javax/swing/DefaultListModel::setElementAt → NO_COVERAGE

179

1.1
Location : endProcess
Killed by : none
removed call to javax/swing/SwingUtilities::invokeLater → NO_COVERAGE

180

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

181

1.1
Location : lambda$endProcess$3
Killed by : none
removed call to com/jsql/view/swing/manager/AbstractManagerList::setButtonEnable → NO_COVERAGE

182

1.1
Location : lambda$endProcess$3
Killed by : none
removed call to javax/swing/JProgressBar::setVisible → NO_COVERAGE

183

1.1
Location : lambda$endProcess$3
Killed by : none
removed call to java/awt/Component::setVisible → NO_COVERAGE

184

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

193

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

201

1.1
Location : changePrivilegeIcon
Killed by : none
removed call to javax/swing/JLabel::setIcon → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1