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 | /** | |
31 | * Log4j logger sent to view. | |
32 | */ | |
33 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
34 | | |
35 | /** | |
36 | * Node as a database model. | |
37 | * @param database Element database coming from model | |
38 | */ | |
39 | public NodeModelDatabase(Database database) { | |
40 | super(database); | |
41 | } | |
42 | ||
43 | @Override | |
44 | protected Icon getLeafIcon(boolean leaf) { | |
45 |
1
1. getLeafIcon : negated conditional → NO_COVERAGE |
if (leaf) { |
46 |
1
1. getLeafIcon : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase::getLeafIcon → NO_COVERAGE |
return UiUtil.DATABASE_LINEAR.getIcon(); |
47 | } else { | |
48 |
1
1. getLeafIcon : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelDatabase::getLeafIcon → NO_COVERAGE |
return UiUtil.DATABASE_BOLD.getIcon(); |
49 | } | |
50 | } | |
51 | ||
52 | @Override | |
53 | public void runAction() { | |
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 | // Fix #90522: ArrayIndexOutOfBoundsException on reload() | |
61 | try { | |
62 |
1
1. runAction : removed call to javax/swing/tree/DefaultTreeModel::reload → NO_COVERAGE |
treeModel.reload(MediatorHelper.treeDatabase().getTreeNodeModels().get(this.getElementDatabase())); |
63 | } catch (ArrayIndexOutOfBoundsException e) { | |
64 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
65 | } | |
66 | | |
67 | new SwingWorker<>() { | |
68 | @Override | |
69 | protected Object doInBackground() throws Exception { | |
70 |
1
1. doInBackground : removed call to java/lang/Thread::setName → NO_COVERAGE |
Thread.currentThread().setName("SwingWorkerNodeModelDatabase"); |
71 | var selectedDatabase = (Database) NodeModelDatabase.this.getElementDatabase(); | |
72 |
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); |
73 | } | |
74 |
1
1. runAction : removed call to com/jsql/view/swing/tree/model/NodeModelDatabase$1::execute → NO_COVERAGE |
}.execute(); |
75 | | |
76 |
1
1. runAction : removed call to com/jsql/view/swing/tree/model/NodeModelDatabase::setRunning → NO_COVERAGE |
this.setRunning(true); |
77 | } | |
78 | ||
79 | @Override | |
80 | public boolean isPopupDisplayable() { | |
81 |
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(); |
82 | } | |
83 | ||
84 | @Override | |
85 | protected void buildMenu(JPopupMenuCustomExtract tablePopupMenu, TreePath path) { | |
86 | // Do nothing | |
87 | } | |
88 | } | |
Mutations | ||
45 |
1.1 |
|
46 |
1.1 |
|
48 |
1.1 |
|
54 |
1.1 |
|
58 |
1.1 |
|
62 |
1.1 |
|
70 |
1.1 |
|
72 |
1.1 |
|
74 |
1.1 |
|
76 |
1.1 |
|
81 |
1.1 2.2 3.3 4.4 |