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

Mutations

42

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

43

1.1
Location : getLeafIcon
Killed by : none
replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase::getLeafIcon → 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

51

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

55

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

59

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

67

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

69

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

71

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

73

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

78

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.19.1