ActionLoadStop.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2020.
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 about 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.tree;
12
13
import com.jsql.model.bean.database.Column;
14
import com.jsql.model.suspendable.AbstractSuspendable;
15
import com.jsql.view.swing.tree.model.AbstractNodeModel;
16
import com.jsql.view.swing.util.MediatorHelper;
17
18
import javax.swing.*;
19
import javax.swing.tree.DefaultMutableTreeNode;
20
import javax.swing.tree.DefaultTreeModel;
21
import java.awt.event.ActionEvent;
22
import java.awt.event.ActionListener;
23
import java.util.ArrayList;
24
import java.util.List;
25
26
/**
27
 * Action to start and stop injection process.
28
 */
29
public class ActionLoadStop implements ActionListener {
30
    
31
    private final AbstractNodeModel nodeModel;
32
    private final DefaultMutableTreeNode currentTableNode;
33
34
    public ActionLoadStop(AbstractNodeModel nodeModel, DefaultMutableTreeNode currentTableNode) {
35
        
36
        this.nodeModel = nodeModel;
37
        this.currentTableNode = currentTableNode;
38
    }
39
40
    @Override
41
    public void actionPerformed(ActionEvent e) {
42
        
43
        final List<Column> columnsToSearch = this.getSelectedColumns();
44
45 2 1. actionPerformed : negated conditional → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
        if (!this.nodeModel.isRunning() && columnsToSearch.isEmpty()) {
46
            return;
47
        }
48
49 1 1. actionPerformed : negated conditional → NO_COVERAGE
        if (!this.nodeModel.isRunning()) {
50 1 1. actionPerformed : removed call to com/jsql/view/swing/tree/ActionLoadStop::startListValues → NO_COVERAGE
            this.startListValues(columnsToSearch);
51
        } else {
52 1 1. actionPerformed : removed call to com/jsql/view/swing/tree/ActionLoadStop::stopAbstractNode → NO_COVERAGE
            this.stopAbstractNode();
53
        }
54
        
55 2 1. actionPerformed : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setRunning → NO_COVERAGE
2. actionPerformed : negated conditional → NO_COVERAGE
        this.nodeModel.setRunning(!this.nodeModel.isRunning());
56
    }
57
58
    private void startListValues(final List<Column> columnsToSearch) {
59
        new SwingWorker<>() {
60
            @Override
61
            protected Object doInBackground() throws Exception {
62
                
63 1 1. doInBackground : removed call to java/lang/Thread::setName → NO_COVERAGE
                Thread.currentThread().setName("SwingWorkerActionLoadStop");
64
                MediatorHelper.model().getDataAccess().listValues(columnsToSearch);
65
                
66
                return null;
67
            }
68 1 1. startListValues : removed call to com/jsql/view/swing/tree/ActionLoadStop$1::execute → NO_COVERAGE
        }.execute();
69
    }
70
71
    private void stopAbstractNode() {
72
        
73
        AbstractSuspendable suspendableTask = MediatorHelper.model().getMediatorUtils().getThreadUtil().get(this.nodeModel.getElementDatabase());
74
        
75
        // Fix #21394: NullPointerException on stop()
76 1 1. stopAbstractNode : negated conditional → NO_COVERAGE
        if (suspendableTask != null) {
77 1 1. stopAbstractNode : removed call to com/jsql/model/suspendable/AbstractSuspendable::stop → NO_COVERAGE
            suspendableTask.stop();
78
        }
79
        
80 1 1. stopAbstractNode : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIndexProgress → NO_COVERAGE
        this.nodeModel.setIndexProgress(0);
81 1 1. stopAbstractNode : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setProgressing → NO_COVERAGE
        this.nodeModel.setProgressing(false);
82 1 1. stopAbstractNode : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setLoading → NO_COVERAGE
        this.nodeModel.setLoading(false);
83
        
84 1 1. stopAbstractNode : removed call to com/jsql/util/ThreadUtil::remove → NO_COVERAGE
        MediatorHelper.model().getMediatorUtils().getThreadUtil().remove(this.nodeModel.getElementDatabase());
85
    }
86
87
    private List<Column> getSelectedColumns() {
88
        
89
        DefaultTreeModel treeModel = (DefaultTreeModel) MediatorHelper.treeDatabase().getModel();
90
        DefaultMutableTreeNode tableNode = this.currentTableNode;
91
        final List<Column> columnsToSearch = new ArrayList<>();
92
93
        int tableChildCount = treeModel.getChildCount(tableNode);
94 2 1. getSelectedColumns : changed conditional boundary → NO_COVERAGE
2. getSelectedColumns : negated conditional → NO_COVERAGE
        for (var i = 0 ; i < tableChildCount ; i++) {
95
            
96
            DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) treeModel.getChild(tableNode, i);
97
            
98 1 1. getSelectedColumns : negated conditional → NO_COVERAGE
            if (currentChild.getUserObject() instanceof AbstractNodeModel) {
99
                
100
                AbstractNodeModel columnTreeNodeModel = (AbstractNodeModel) currentChild.getUserObject();
101 1 1. getSelectedColumns : negated conditional → NO_COVERAGE
                if (columnTreeNodeModel.isSelected()) {
102
                    columnsToSearch.add((Column) columnTreeNodeModel.getElementDatabase());
103
                }
104
            }
105
        }
106
        
107 1 1. getSelectedColumns : replaced return value with Collections.emptyList for com/jsql/view/swing/tree/ActionLoadStop::getSelectedColumns → NO_COVERAGE
        return columnsToSearch;
108
    }
109
}

Mutations

45

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

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

49

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

50

1.1
Location : actionPerformed
Killed by : none
removed call to com/jsql/view/swing/tree/ActionLoadStop::startListValues → NO_COVERAGE

52

1.1
Location : actionPerformed
Killed by : none
removed call to com/jsql/view/swing/tree/ActionLoadStop::stopAbstractNode → NO_COVERAGE

55

1.1
Location : actionPerformed
Killed by : none
removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setRunning → NO_COVERAGE

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

63

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

68

1.1
Location : startListValues
Killed by : none
removed call to com/jsql/view/swing/tree/ActionLoadStop$1::execute → NO_COVERAGE

76

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

77

1.1
Location : stopAbstractNode
Killed by : none
removed call to com/jsql/model/suspendable/AbstractSuspendable::stop → NO_COVERAGE

80

1.1
Location : stopAbstractNode
Killed by : none
removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIndexProgress → NO_COVERAGE

81

1.1
Location : stopAbstractNode
Killed by : none
removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setProgressing → NO_COVERAGE

82

1.1
Location : stopAbstractNode
Killed by : none
removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setLoading → NO_COVERAGE

84

1.1
Location : stopAbstractNode
Killed by : none
removed call to com/jsql/util/ThreadUtil::remove → NO_COVERAGE

94

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

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

98

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

101

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

107

1.1
Location : getSelectedColumns
Killed by : none
replaced return value with Collections.emptyList for com/jsql/view/swing/tree/ActionLoadStop::getSelectedColumns → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1