NodeModelDatabase.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.model;
12
13
import com.jsql.model.bean.database.Database;
14
import com.jsql.util.LogLevelUtil;
15
import com.jsql.view.swing.util.MediatorHelper;
16
import com.jsql.view.swing.util.UiUtil;
17
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
19
20
import javax.swing.*;
21
import javax.swing.tree.DefaultTreeModel;
22
import javax.swing.tree.TreePath;
23
24
/**
25
 * Database model displaying the database icon on the label.
26
 */
27
public class NodeModelDatabase extends AbstractNodeModel {
28
    
29
    /**
30
     * Log4j logger sent to view.
31
     */
32
    private static final Logger LOGGER = LogManager.getRootLogger();
33
    
34
    /**
35
     * Node as a database model.
36
     * @param database Element database coming from model
37
     */
38
    public NodeModelDatabase(Database database) {
39
        super(database);
40
    }
41
42
    @Override
43
    protected Icon getLeafIcon(boolean leaf) {
44 1 1. getLeafIcon : negated conditional → NO_COVERAGE
        if (leaf) {
45 1 1. getLeafIcon : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase::getLeafIcon → NO_COVERAGE
            return UiUtil.ICON_DATABASE_GO;
46
        } else {
47 1 1. getLeafIcon : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase::getLeafIcon → NO_COVERAGE
            return UiUtil.ICON_DATABASE;
48
        }
49
    }
50
51
    @Override
52
    public void runAction() {
53
        
54 1 1. runAction : negated conditional → NO_COVERAGE
        if (this.isRunning()) {
55
            return;
56
        }
57
    
58 1 1. runAction : removed call to javax/swing/tree/DefaultMutableTreeNode::removeAllChildren → NO_COVERAGE
        MediatorHelper.treeDatabase().getTreeNodeModels().get(this.getElementDatabase()).removeAllChildren();
59
        DefaultTreeModel treeModel = (DefaultTreeModel) MediatorHelper.treeDatabase().getModel();
60
        
61
        // Fix #90522: ArrayIndexOutOfBoundsException on reload()
62
        try {
63 1 1. runAction : removed call to javax/swing/tree/DefaultTreeModel::reload → NO_COVERAGE
            treeModel.reload(MediatorHelper.treeDatabase().getTreeNodeModels().get(this.getElementDatabase()));
64
        } catch (ArrayIndexOutOfBoundsException e) {
65
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
66
        }
67
        
68
        new SwingWorker<>() {
69
            @Override
70
            protected Object doInBackground() throws Exception {
71
                
72 1 1. doInBackground : removed call to java/lang/Thread::setName → NO_COVERAGE
                Thread.currentThread().setName("SwingWorkerNodeModelDatabase");
73
                var selectedDatabase = (Database) NodeModelDatabase.this.getElementDatabase();
74 1 1. doInBackground : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase$1::doInBackground → NO_COVERAGE
                return MediatorHelper.model().getDataAccess().listTables(selectedDatabase);
75
            }
76 1 1. runAction : removed call to com/jsql/view/swing/tree/model/NodeModelDatabase$1::execute → NO_COVERAGE
        }.execute();
77
        
78 1 1. runAction : removed call to com/jsql/view/swing/tree/model/NodeModelDatabase::setRunning → NO_COVERAGE
        this.setRunning(true);
79
    }
80
81
    @Override
82
    public boolean isPopupDisplayable() {
83 4 1. isPopupDisplayable : negated conditional → NO_COVERAGE
2. isPopupDisplayable : negated conditional → NO_COVERAGE
3. isPopupDisplayable : replaced boolean return with true for com/jsql/view/swing/tree/model/NodeModelDatabase::isPopupDisplayable → NO_COVERAGE
4. isPopupDisplayable : negated conditional → NO_COVERAGE
        return this.isLoaded() || !this.isLoaded() && this.isRunning();
84
    }
85
86
    @Override
87
    protected void buildMenu(JPopupMenuCustomExtract tablePopupMenu, TreePath path) {
88
        // Do nothing
89
    }
90
}

Mutations

44

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

45

1.1
Location : getLeafIcon
Killed by : none
replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase::getLeafIcon → NO_COVERAGE

47

1.1
Location : getLeafIcon
Killed by : none
replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase::getLeafIcon → NO_COVERAGE

54

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

58

1.1
Location : runAction
Killed by : none
removed call to javax/swing/tree/DefaultMutableTreeNode::removeAllChildren → NO_COVERAGE

63

1.1
Location : runAction
Killed by : none
removed call to javax/swing/tree/DefaultTreeModel::reload → NO_COVERAGE

72

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

74

1.1
Location : doInBackground
Killed by : none
replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase$1::doInBackground → NO_COVERAGE

76

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

78

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

83

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

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

3.3
Location : isPopupDisplayable
Killed by : none
replaced boolean return with true for com/jsql/view/swing/tree/model/NodeModelDatabase::isPopupDisplayable → NO_COVERAGE

4.4
Location : isPopupDisplayable
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1