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.Table; | |
14 | import com.jsql.model.suspendable.AbstractSuspendable; | |
15 | import com.jsql.util.StringUtil; | |
16 | import com.jsql.view.swing.text.JPopupTextField; | |
17 | import com.jsql.view.swing.tree.custom.CheckBoxMenuItemIconCustom; | |
18 | import com.jsql.view.swing.tree.ImageOverlap; | |
19 | import com.jsql.view.swing.tree.PanelNode; | |
20 | import com.jsql.view.swing.tree.action.ActionCheckAll; | |
21 | import com.jsql.view.swing.tree.custom.JPopupMenuCustomExtract; | |
22 | import com.jsql.view.swing.util.I18nViewUtil; | |
23 | import com.jsql.view.swing.util.MediatorHelper; | |
24 | import com.jsql.view.swing.util.UiUtil; | |
25 | ||
26 | import javax.swing.*; | |
27 | import javax.swing.tree.DefaultMutableTreeNode; | |
28 | import javax.swing.tree.DefaultTreeModel; | |
29 | import javax.swing.tree.TreePath; | |
30 | import java.awt.*; | |
31 | ||
32 | /** | |
33 | * Table model displaying the table icon on the label. | |
34 | */ | |
35 | public class NodeModelTable extends AbstractNodeModel { | |
36 | | |
37 | /** | |
38 | * Node as a table model. | |
39 | * @param table Element table coming from model | |
40 | */ | |
41 | public NodeModelTable(Table table) { | |
42 | super(table); | |
43 | } | |
44 | ||
45 | @Override | |
46 | protected Icon getLeafIcon(boolean leaf) { | |
47 |
1
1. getLeafIcon : negated conditional → NO_COVERAGE |
if (leaf) { |
48 |
1
1. getLeafIcon : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelTable::getLeafIcon → NO_COVERAGE |
return UiUtil.TABLE_LINEAR.getIcon(); |
49 | } else { | |
50 |
1
1. getLeafIcon : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelTable::getLeafIcon → NO_COVERAGE |
return UiUtil.TABLE_BOLD.getIcon(); |
51 | } | |
52 | } | |
53 | ||
54 | @Override | |
55 | protected void displayProgress(PanelNode panelNode, DefaultMutableTreeNode currentNode) { | |
56 |
1
1. displayProgress : negated conditional → NO_COVERAGE |
if (StringUtil.INFORMATION_SCHEMA.equals(this.getParent().toString())) { |
57 |
1
1. displayProgress : removed call to com/jsql/view/swing/tree/PanelNode::showLoader → NO_COVERAGE |
panelNode.showLoader(); |
58 | AbstractSuspendable suspendableTask = MediatorHelper.model().getMediatorUtils().getThreadUtil().get(this.getElementDatabase()); | |
59 |
2
1. displayProgress : negated conditional → NO_COVERAGE 2. displayProgress : negated conditional → NO_COVERAGE |
if (suspendableTask != null && suspendableTask.isPaused()) { |
60 |
1
1. displayProgress : removed call to com/jsql/view/swing/tree/PanelNode::setLoaderIcon → NO_COVERAGE |
panelNode.setLoaderIcon(new ImageOverlap(UiUtil.HOURGLASS.getIcon(), UiUtil.PATH_PAUSE)); |
61 | } | |
62 | } else { | |
63 |
1
1. displayProgress : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::displayProgress → NO_COVERAGE |
super.displayProgress(panelNode, currentNode); |
64 | } | |
65 | } | |
66 | ||
67 | @Override | |
68 | public void runAction() { | |
69 |
1
1. runAction : negated conditional → NO_COVERAGE |
if (this.isRunning()) { // Prevent double thread run |
70 | return; | |
71 | } | |
72 | | |
73 | DefaultMutableTreeNode treeNode = MediatorHelper.treeDatabase().getTreeNodeModels().get(this.getElementDatabase()); | |
74 |
1
1. runAction : removed call to javax/swing/tree/DefaultMutableTreeNode::removeAllChildren → NO_COVERAGE |
treeNode.removeAllChildren(); |
75 | | |
76 | DefaultTreeModel treeModel = (DefaultTreeModel) MediatorHelper.treeDatabase().getModel(); | |
77 |
1
1. runAction : removed call to javax/swing/tree/DefaultTreeModel::reload → NO_COVERAGE |
treeModel.reload(treeNode); |
78 | ||
79 | new SwingWorker<>() { | |
80 | @Override | |
81 | protected Object doInBackground() throws Exception { | |
82 |
1
1. doInBackground : removed call to java/lang/Thread::setName → NO_COVERAGE |
Thread.currentThread().setName("SwingWorkerNodeModelTable"); |
83 | var selectedTable = (Table) NodeModelTable.this.getElementDatabase(); | |
84 |
1
1. doInBackground : replaced return value with null for com/jsql/view/swing/tree/model/NodeModelTable$1::doInBackground → NO_COVERAGE |
return MediatorHelper.model().getDataAccess().listColumns(selectedTable); |
85 | } | |
86 |
1
1. runAction : removed call to com/jsql/view/swing/tree/model/NodeModelTable$1::execute → NO_COVERAGE |
}.execute(); |
87 | | |
88 |
1
1. runAction : removed call to com/jsql/view/swing/tree/model/NodeModelTable::setRunning → NO_COVERAGE |
this.setRunning(true); |
89 | } | |
90 | ||
91 | @Override | |
92 | protected void buildMenu(JPopupMenuCustomExtract tablePopupMenu, final TreePath path) { | |
93 |
1
1. buildMenu : removed call to com/jsql/view/swing/tree/model/NodeModelTable::addCheckUncheckItems → NO_COVERAGE |
this.addCheckUncheckItems(tablePopupMenu, path); |
94 | // this.addCustomLoadItems(tablePopupMenu); | |
95 | } | |
96 | ||
97 | private void addCustomLoadItems(JPopupMenuCustomExtract tablePopupMenu) { | |
98 | | |
99 | var menuCustomLoad = new JMenu("Custom load"); | |
100 | | |
101 | var buttonGroupLoadRows = new ButtonGroup(); | |
102 | | |
103 | JMenuItem menuItemLoadAllRows = new JRadioButtonMenuItem("Load all rows (default)", true); | |
104 | JMenuItem menuItemLoadOneRow = new JRadioButtonMenuItem("Load first row only"); | |
105 | JMenuItem menuItemDump = new JCheckBoxMenuItem("Dump to a file"); | |
106 | | |
107 | var panelCustomFromRow = new JPanel(new BorderLayout()); | |
108 | final JTextField inputCustomFromRow = new JPopupTextField("no.", "1").getProxy(); | |
109 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setHorizontalAlignment → NO_COVERAGE |
inputCustomFromRow.setHorizontalAlignment(SwingConstants.TRAILING); |
110 | var d = new Dimension( | |
111 |
1
1. addCustomLoadItems : Replaced integer addition with subtraction → NO_COVERAGE |
(int) inputCustomFromRow.getPreferredSize().getWidth() + 50, |
112 | (int) inputCustomFromRow.getPreferredSize().getHeight() | |
113 | ); | |
114 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE |
inputCustomFromRow.setPreferredSize(d); |
115 | ||
116 | final var radioCustomFromRow = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load from row no.	</pre></html>"); | |
117 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setBorder → NO_COVERAGE |
radioCustomFromRow.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0)); |
118 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setIcon → NO_COVERAGE |
radioCustomFromRow.setIcon(new CheckBoxMenuItemIconCustom()); |
119 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setFocusPainted → NO_COVERAGE |
radioCustomFromRow.setFocusPainted(false); |
120 | | |
121 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomFromRow.add(radioCustomFromRow, BorderLayout.LINE_START); |
122 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomFromRow.add(inputCustomFromRow, BorderLayout.CENTER); |
123 | | |
124 | var panelCustomToRow = new JPanel(new BorderLayout()); | |
125 | final JTextField inputCustomToRow = new JPopupTextField("no.", "65565").getProxy(); | |
126 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setHorizontalAlignment → NO_COVERAGE |
inputCustomToRow.setHorizontalAlignment(SwingConstants.TRAILING); |
127 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE |
inputCustomToRow.setPreferredSize(d); |
128 | ||
129 | final var radioCustomToRow = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load to row no.						</pre></html>"); | |
130 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setBorder → NO_COVERAGE |
radioCustomToRow.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0)); |
131 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setIcon → NO_COVERAGE |
radioCustomToRow.setIcon(new CheckBoxMenuItemIconCustom()); |
132 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setFocusPainted → NO_COVERAGE |
radioCustomToRow.setFocusPainted(false); |
133 | | |
134 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomToRow.add(radioCustomToRow, BorderLayout.LINE_START); |
135 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomToRow.add(inputCustomToRow, BorderLayout.CENTER); |
136 | | |
137 | var panelCustomFromChar = new JPanel(new BorderLayout()); | |
138 | final JTextField inputCustomFromChar = new JPopupTextField("no.", "1").getProxy(); | |
139 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setHorizontalAlignment → NO_COVERAGE |
inputCustomFromChar.setHorizontalAlignment(SwingConstants.TRAILING); |
140 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE |
inputCustomFromChar.setPreferredSize(d); |
141 | ||
142 | final var radioCustomFromChar = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load from char no.</pre></html>"); | |
143 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setBorder → NO_COVERAGE |
radioCustomFromChar.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0)); |
144 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setIcon → NO_COVERAGE |
radioCustomFromChar.setIcon(new CheckBoxMenuItemIconCustom()); |
145 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setFocusPainted → NO_COVERAGE |
radioCustomFromChar.setFocusPainted(false); |
146 | | |
147 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomFromChar.add(radioCustomFromChar, BorderLayout.LINE_START); |
148 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomFromChar.add(inputCustomFromChar, BorderLayout.CENTER); |
149 | | |
150 | var panelCustomToChar = new JPanel(new BorderLayout()); | |
151 | final JTextField inputCustomToChar = new JPopupTextField("no.", "65565").getProxy(); | |
152 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setHorizontalAlignment → NO_COVERAGE |
inputCustomToChar.setHorizontalAlignment(SwingConstants.TRAILING); |
153 |
1
1. addCustomLoadItems : removed call to javax/swing/JTextField::setPreferredSize → NO_COVERAGE |
inputCustomToChar.setPreferredSize(d); |
154 | ||
155 | final var radioCustomToChar = new JCheckBox("<html><pre style=\"font-family:'Segoe UI';padding-left: 1px;\">Load to char no.					</pre></html>"); | |
156 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setBorder → NO_COVERAGE |
radioCustomToChar.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0)); |
157 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setIcon → NO_COVERAGE |
radioCustomToChar.setIcon(new CheckBoxMenuItemIconCustom()); |
158 |
1
1. addCustomLoadItems : removed call to javax/swing/JCheckBox::setFocusPainted → NO_COVERAGE |
radioCustomToChar.setFocusPainted(false); |
159 | | |
160 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomToChar.add(radioCustomToChar, BorderLayout.LINE_START); |
161 |
1
1. addCustomLoadItems : removed call to javax/swing/JPanel::add → NO_COVERAGE |
panelCustomToChar.add(inputCustomToChar, BorderLayout.CENTER); |
162 | ||
163 |
1
1. addCustomLoadItems : removed call to javax/swing/ButtonGroup::add → NO_COVERAGE |
buttonGroupLoadRows.add(menuItemLoadAllRows); |
164 |
1
1. addCustomLoadItems : removed call to javax/swing/ButtonGroup::add → NO_COVERAGE |
buttonGroupLoadRows.add(menuItemLoadOneRow); |
165 | | |
166 | menuCustomLoad.add(menuItemLoadAllRows); | |
167 | menuCustomLoad.add(menuItemLoadOneRow); | |
168 | menuCustomLoad.add(new JSeparator()); | |
169 | menuCustomLoad.add(panelCustomFromRow); | |
170 | menuCustomLoad.add(panelCustomToRow); | |
171 | menuCustomLoad.add(panelCustomFromChar); | |
172 | menuCustomLoad.add(panelCustomToChar); | |
173 | menuCustomLoad.add(new JSeparator()); | |
174 | menuCustomLoad.add(menuItemDump); | |
175 | ||
176 | tablePopupMenu.add(new JSeparator()); | |
177 | tablePopupMenu.add(menuCustomLoad); | |
178 | | |
179 |
1
1. addCustomLoadItems : removed call to com/jsql/view/swing/tree/custom/JPopupMenuCustomExtract::setButtonGroupLoadRows → NO_COVERAGE |
tablePopupMenu.setButtonGroupLoadRows(buttonGroupLoadRows); |
180 |
1
1. addCustomLoadItems : removed call to com/jsql/view/swing/tree/custom/JPopupMenuCustomExtract::setRadioCustomFromChar → NO_COVERAGE |
tablePopupMenu.setRadioCustomFromChar(radioCustomFromChar); |
181 |
1
1. addCustomLoadItems : removed call to com/jsql/view/swing/tree/custom/JPopupMenuCustomExtract::setRadioCustomToChar → NO_COVERAGE |
tablePopupMenu.setRadioCustomToChar(radioCustomToChar); |
182 |
1
1. addCustomLoadItems : removed call to com/jsql/view/swing/tree/custom/JPopupMenuCustomExtract::setRadioCustomFromRow → NO_COVERAGE |
tablePopupMenu.setRadioCustomFromRow(radioCustomFromRow); |
183 |
1
1. addCustomLoadItems : removed call to com/jsql/view/swing/tree/custom/JPopupMenuCustomExtract::setRadioCustomToRow → NO_COVERAGE |
tablePopupMenu.setRadioCustomToRow(radioCustomToRow); |
184 | } | |
185 | ||
186 | private void addCheckUncheckItems(JPopupMenuCustomExtract tablePopupMenu, final TreePath path) { | |
187 | JMenuItem menuItemCheckAll = new JMenuItem(I18nViewUtil.valueByKey("COLUMNS_CHECK_ALL"), 'C'); | |
188 |
1
1. addCheckUncheckItems : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("COLUMNS_CHECK_ALL", menuItemCheckAll); |
189 | | |
190 | JMenuItem menuItemUncheckAll = new JMenuItem(I18nViewUtil.valueByKey("COLUMNS_UNCHECK_ALL"), 'U'); | |
191 |
1
1. addCheckUncheckItems : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("COLUMNS_UNCHECK_ALL", menuItemUncheckAll); |
192 | ||
193 |
1
1. addCheckUncheckItems : negated conditional → NO_COVERAGE |
if (!this.isLoaded()) { |
194 |
1
1. addCheckUncheckItems : removed call to javax/swing/JMenuItem::setEnabled → NO_COVERAGE |
menuItemCheckAll.setEnabled(false); |
195 |
1
1. addCheckUncheckItems : removed call to javax/swing/JMenuItem::setEnabled → NO_COVERAGE |
menuItemUncheckAll.setEnabled(false); |
196 | } | |
197 | ||
198 |
1
1. addCheckUncheckItems : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE |
menuItemCheckAll.addActionListener(new ActionCheckAll(true, path)); |
199 |
1
1. addCheckUncheckItems : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE |
menuItemUncheckAll.addActionListener(new ActionCheckAll(false, path)); |
200 | ||
201 | tablePopupMenu.add(new JSeparator()); | |
202 | tablePopupMenu.add(menuItemCheckAll); | |
203 | tablePopupMenu.add(menuItemUncheckAll); | |
204 | } | |
205 | | |
206 | @Override | |
207 | public boolean isPopupDisplayable() { | |
208 |
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/NodeModelTable::isPopupDisplayable → NO_COVERAGE 4. isPopupDisplayable : negated conditional → NO_COVERAGE |
return this.isLoaded() || !this.isLoaded() && this.isRunning(); |
209 | } | |
210 | } | |
Mutations | ||
47 |
1.1 |
|
48 |
1.1 |
|
50 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
59 |
1.1 2.2 |
|
60 |
1.1 |
|
63 |
1.1 |
|
69 |
1.1 |
|
74 |
1.1 |
|
77 |
1.1 |
|
82 |
1.1 |
|
84 |
1.1 |
|
86 |
1.1 |
|
88 |
1.1 |
|
93 |
1.1 |
|
109 |
1.1 |
|
111 |
1.1 |
|
114 |
1.1 |
|
117 |
1.1 |
|
118 |
1.1 |
|
119 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
134 |
1.1 |
|
135 |
1.1 |
|
139 |
1.1 |
|
140 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
145 |
1.1 |
|
147 |
1.1 |
|
148 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 |
|
158 |
1.1 |
|
160 |
1.1 |
|
161 |
1.1 |
|
163 |
1.1 |
|
164 |
1.1 |
|
179 |
1.1 |
|
180 |
1.1 |
|
181 |
1.1 |
|
182 |
1.1 |
|
183 |
1.1 |
|
188 |
1.1 |
|
191 |
1.1 |
|
193 |
1.1 |
|
194 |
1.1 |
|
195 |
1.1 |
|
198 |
1.1 |
|
199 |
1.1 |
|
208 |
1.1 2.2 3.3 4.4 |