| 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.action; | |
| 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 | this.nodeModel = nodeModel; | |
| 36 | this.currentTableNode = currentTableNode; | |
| 37 | } | |
| 38 | ||
| 39 | @Override | |
| 40 | public void actionPerformed(ActionEvent e) { | |
| 41 | final List<Column> columnsToSearch = this.getSelectedColumns(); | |
| 42 |
2
1. actionPerformed : negated conditional → NO_COVERAGE 2. actionPerformed : negated conditional → NO_COVERAGE |
if (!this.nodeModel.isRunning() && columnsToSearch.isEmpty()) { |
| 43 | return; | |
| 44 | } | |
| 45 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (!this.nodeModel.isRunning()) { |
| 46 |
1
1. actionPerformed : removed call to com/jsql/view/swing/tree/action/ActionLoadStop::startListValues → NO_COVERAGE |
this.startListValues(columnsToSearch); |
| 47 | } else { | |
| 48 |
1
1. actionPerformed : removed call to com/jsql/view/swing/tree/action/ActionLoadStop::stopAbstractNode → NO_COVERAGE |
this.stopAbstractNode(); |
| 49 | } | |
| 50 |
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()); |
| 51 | } | |
| 52 | ||
| 53 | private void startListValues(final List<Column> columnsToSearch) { | |
| 54 | new SwingWorker<>() { | |
| 55 | @Override | |
| 56 | protected Object doInBackground() throws Exception { | |
| 57 |
1
1. doInBackground : removed call to java/lang/Thread::setName → NO_COVERAGE |
Thread.currentThread().setName("SwingWorkerActionLoadStop"); |
| 58 | MediatorHelper.model().getDataAccess().listValues(columnsToSearch); | |
| 59 | return null; | |
| 60 | } | |
| 61 |
1
1. startListValues : removed call to com/jsql/view/swing/tree/action/ActionLoadStop$1::execute → NO_COVERAGE |
}.execute(); |
| 62 | } | |
| 63 | ||
| 64 | private void stopAbstractNode() { | |
| 65 | AbstractSuspendable suspendableTask = MediatorHelper.model().getMediatorUtils().getThreadUtil().get(this.nodeModel.getElementDatabase()); | |
| 66 | // Fix #21394: NullPointerException on stop() | |
| 67 |
1
1. stopAbstractNode : negated conditional → NO_COVERAGE |
if (suspendableTask != null) { |
| 68 |
1
1. stopAbstractNode : removed call to com/jsql/model/suspendable/AbstractSuspendable::stop → NO_COVERAGE |
suspendableTask.stop(); |
| 69 | } | |
| 70 | | |
| 71 |
1
1. stopAbstractNode : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIndexProgress → NO_COVERAGE |
this.nodeModel.setIndexProgress(0); |
| 72 |
1
1. stopAbstractNode : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setProgressing → NO_COVERAGE |
this.nodeModel.setProgressing(false); |
| 73 |
1
1. stopAbstractNode : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setLoading → NO_COVERAGE |
this.nodeModel.setLoading(false); |
| 74 | | |
| 75 |
1
1. stopAbstractNode : removed call to com/jsql/util/ThreadUtil::remove → NO_COVERAGE |
MediatorHelper.model().getMediatorUtils().getThreadUtil().remove(this.nodeModel.getElementDatabase()); |
| 76 | } | |
| 77 | ||
| 78 | private List<Column> getSelectedColumns() { | |
| 79 | DefaultTreeModel treeModel = (DefaultTreeModel) MediatorHelper.treeDatabase().getModel(); | |
| 80 | DefaultMutableTreeNode tableNode = this.currentTableNode; | |
| 81 | final List<Column> columnsToSearch = new ArrayList<>(); | |
| 82 | ||
| 83 | int tableChildCount = treeModel.getChildCount(tableNode); | |
| 84 |
2
1. getSelectedColumns : negated conditional → NO_COVERAGE 2. getSelectedColumns : changed conditional boundary → NO_COVERAGE |
for (var i = 0 ; i < tableChildCount ; i++) { |
| 85 | DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) treeModel.getChild(tableNode, i); | |
| 86 |
1
1. getSelectedColumns : negated conditional → NO_COVERAGE |
if (currentChild.getUserObject() instanceof AbstractNodeModel) { |
| 87 | AbstractNodeModel columnTreeNodeModel = (AbstractNodeModel) currentChild.getUserObject(); | |
| 88 |
1
1. getSelectedColumns : negated conditional → NO_COVERAGE |
if (columnTreeNodeModel.isSelected()) { |
| 89 | columnsToSearch.add((Column) columnTreeNodeModel.getElementDatabase()); | |
| 90 | } | |
| 91 | } | |
| 92 | } | |
| 93 |
1
1. getSelectedColumns : replaced return value with Collections.emptyList for com/jsql/view/swing/tree/action/ActionLoadStop::getSelectedColumns → NO_COVERAGE |
return columnsToSearch; |
| 94 | } | |
| 95 | } | |
Mutations | ||
| 42 |
1.1 2.2 |
|
| 45 |
1.1 |
|
| 46 |
1.1 |
|
| 48 |
1.1 |
|
| 50 |
1.1 2.2 |
|
| 57 |
1.1 |
|
| 61 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 |
|
| 75 |
1.1 |
|
| 84 |
1.1 2.2 |
|
| 86 |
1.1 |
|
| 88 |
1.1 |
|
| 93 |
1.1 |