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