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.manager; | |
12 | ||
13 | import com.jsql.util.LogLevelUtil; | |
14 | import com.jsql.view.swing.scrollpane.LightScrollPane; | |
15 | import com.jsql.view.swing.tree.CellEditorNode; | |
16 | import com.jsql.view.swing.tree.CellRendererNode; | |
17 | import com.jsql.view.swing.tree.TreeDatabase; | |
18 | import com.jsql.view.swing.tree.model.AbstractNodeModel; | |
19 | import com.jsql.view.swing.tree.model.NodeModelEmpty; | |
20 | import com.jsql.view.swing.util.I18nViewUtil; | |
21 | import com.jsql.view.swing.util.MediatorHelper; | |
22 | import com.jsql.view.swing.util.UiUtil; | |
23 | import org.apache.logging.log4j.LogManager; | |
24 | import org.apache.logging.log4j.Logger; | |
25 | ||
26 | import javax.swing.*; | |
27 | import javax.swing.event.TreeModelEvent; | |
28 | import javax.swing.event.TreeModelListener; | |
29 | import javax.swing.tree.DefaultMutableTreeNode; | |
30 | import javax.swing.tree.TreePath; | |
31 | import javax.swing.tree.TreeSelectionModel; | |
32 | import java.awt.*; | |
33 | import java.awt.event.*; | |
34 | ||
35 | /** | |
36 | * Manager to code/decode string in various methods. | |
37 | */ | |
38 | public class ManagerDatabase extends JPanel implements Manager { | |
39 | | |
40 | /** | |
41 | * Log4j logger sent to view. | |
42 | */ | |
43 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
44 | ||
45 | private TreeDatabase tree; | |
46 | ||
47 | /** | |
48 | * Create a panel to encode a string. | |
49 | */ | |
50 | public ManagerDatabase() { | |
51 | | |
52 | super(new BorderLayout()); | |
53 | ||
54 |
1
1. <init> : removed call to com/jsql/view/swing/manager/ManagerDatabase::initializeTree → NO_COVERAGE |
this.initializeTree(); |
55 | | |
56 | var scroller = new LightScrollPane(0, 0, 0, 0, this.tree); | |
57 |
1
1. <init> : removed call to com/jsql/view/swing/manager/ManagerDatabase::add → NO_COVERAGE |
this.add(scroller, BorderLayout.CENTER); |
58 | } | |
59 | ||
60 | private void initializeTree() { | |
61 | | |
62 | // First node in tree | |
63 | AbstractNodeModel nodeModelEmpty = new NodeModelEmpty(I18nViewUtil.valueByKey("DATABASE_EMPTY")); | |
64 | var root = new DefaultMutableTreeNode(nodeModelEmpty); | |
65 |
1
1. initializeTree : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE |
I18nViewUtil.addComponentForKey("DATABASE_EMPTY", nodeModelEmpty); |
66 | | |
67 | this.tree = new TreeDatabase(root); | |
68 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::setName → NO_COVERAGE |
this.tree.setName("treeDatabases"); |
69 |
1
1. initializeTree : removed call to com/jsql/view/swing/util/MediatorHelper::register → NO_COVERAGE |
MediatorHelper.register(this.tree); |
70 | ||
71 | // Graphic manager for components | |
72 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::setCellRenderer → NO_COVERAGE |
this.tree.setCellRenderer(new CellRendererNode()); |
73 | ||
74 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::addFocusListener → NO_COVERAGE |
this.tree.addFocusListener(this.getTreeFocusListener()); |
75 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::addMouseListener → NO_COVERAGE |
this.tree.addMouseListener(this.getTreeMouseListener()); |
76 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::addKeyListener → NO_COVERAGE |
this.tree.addKeyListener(this.getTreeKeyListener()); |
77 | ||
78 | // Action manager for components | |
79 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::setCellEditor → NO_COVERAGE |
this.tree.setCellEditor(new CellEditorNode()); |
80 | ||
81 | // Tree setting | |
82 | // allows repaint nodes | |
83 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::setEditable → NO_COVERAGE |
this.tree.setEditable(true); |
84 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::setShowsRootHandles → NO_COVERAGE |
this.tree.setShowsRootHandles(true); |
85 |
1
1. initializeTree : removed call to javax/swing/tree/TreeSelectionModel::setSelectionMode → NO_COVERAGE |
this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); |
86 | ||
87 | // Repaint Gif progress bar | |
88 |
1
1. initializeTree : removed call to javax/swing/tree/TreeModel::addTreeModelListener → NO_COVERAGE |
this.tree.getModel().addTreeModelListener(new TreeModelGifListener()); |
89 | ||
90 |
1
1. initializeTree : removed call to com/jsql/view/swing/tree/TreeDatabase::setBorder → NO_COVERAGE |
this.tree.setBorder(BorderFactory.createEmptyBorder(0, 0, LightScrollPane.THUMB_SIZE, 0)); |
91 | } | |
92 | ||
93 | private KeyAdapter getTreeKeyListener() { | |
94 | | |
95 |
1
1. getTreeKeyListener : replaced return value with null for com/jsql/view/swing/manager/ManagerDatabase::getTreeKeyListener → NO_COVERAGE |
return new KeyAdapter() { |
96 | ||
97 | @Override | |
98 | public void keyPressed(KeyEvent e) { | |
99 | | |
100 |
1
1. keyPressed : negated conditional → NO_COVERAGE |
if (e.getKeyCode() == KeyEvent.VK_F2) { |
101 | | |
102 | DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) ManagerDatabase.this.tree.getLastSelectedPathComponent(); | |
103 | | |
104 |
1
1. keyPressed : negated conditional → NO_COVERAGE |
if (treeNode != null) { |
105 | | |
106 | AbstractNodeModel nodeModel = (AbstractNodeModel) treeNode.getUserObject(); | |
107 | | |
108 |
3
1. keyPressed : negated conditional → NO_COVERAGE 2. keyPressed : negated conditional → NO_COVERAGE 3. keyPressed : negated conditional → NO_COVERAGE |
if (nodeModel != null && nodeModel.getPanel() != null && !nodeModel.isRunning()) { |
109 | | |
110 |
1
1. keyPressed : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
nodeModel.getPanel().getLabel().setBackground(UiUtil.COLOR_FOCUS_LOST); |
111 |
1
1. keyPressed : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
nodeModel.getPanel().getLabel().setBorder(UiUtil.BORDER_FOCUS_LOST); |
112 |
1
1. keyPressed : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE |
nodeModel.setIsEdited(true); |
113 | } | |
114 | } | |
115 | } | |
116 | } | |
117 | }; | |
118 | } | |
119 | ||
120 | private MouseAdapter getTreeMouseListener() { | |
121 | | |
122 |
1
1. getTreeMouseListener : replaced return value with null for com/jsql/view/swing/manager/ManagerDatabase::getTreeMouseListener → NO_COVERAGE |
return new MouseAdapter() { |
123 | ||
124 | @Override | |
125 | public void mousePressed(MouseEvent event) { | |
126 | | |
127 | int selRow = ManagerDatabase.this.tree.getRowForLocation(event.getX(), event.getY()); | |
128 | TreePath selPath = ManagerDatabase.this.tree.getPathForLocation(event.getX(), event.getY()); | |
129 | | |
130 |
2
1. mousePressed : negated conditional → NO_COVERAGE 2. mousePressed : negated conditional → NO_COVERAGE |
if (selRow != -1 && event.getClickCount() == 2) { |
131 | // Fix ArrayIndexOutOfBoundsException on collapsePath() | |
132 | try { | |
133 |
1
1. mousePressed : negated conditional → NO_COVERAGE |
if (ManagerDatabase.this.tree.isExpanded(selPath)) { |
134 |
1
1. mousePressed : removed call to com/jsql/view/swing/tree/TreeDatabase::collapsePath → NO_COVERAGE |
ManagerDatabase.this.tree.collapsePath(selPath); |
135 | } else { | |
136 |
1
1. mousePressed : removed call to com/jsql/view/swing/tree/TreeDatabase::expandPath → NO_COVERAGE |
ManagerDatabase.this.tree.expandPath(selPath); |
137 | } | |
138 | } catch (ArrayIndexOutOfBoundsException e) { | |
139 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
140 | } | |
141 | } | |
142 | } | |
143 | }; | |
144 | } | |
145 | ||
146 | private FocusListener getTreeFocusListener() { | |
147 | | |
148 |
1
1. getTreeFocusListener : replaced return value with null for com/jsql/view/swing/manager/ManagerDatabase::getTreeFocusListener → NO_COVERAGE |
return new FocusListener() { |
149 | ||
150 | @Override | |
151 | public void focusLost(FocusEvent e) { | |
152 | | |
153 | DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) ManagerDatabase.this.tree.getLastSelectedPathComponent(); | |
154 | | |
155 |
1
1. focusLost : negated conditional → NO_COVERAGE |
if (treeNode != null) { |
156 | | |
157 | AbstractNodeModel nodeModel = (AbstractNodeModel) treeNode.getUserObject(); | |
158 | | |
159 |
2
1. focusLost : negated conditional → NO_COVERAGE 2. focusLost : negated conditional → NO_COVERAGE |
if (nodeModel != null && nodeModel.getPanel() != null) { |
160 | | |
161 |
1
1. focusLost : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
nodeModel.getPanel().getLabel().setBackground(UiUtil.COLOR_FOCUS_LOST); |
162 |
1
1. focusLost : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
nodeModel.getPanel().getLabel().setBorder(UiUtil.BORDER_FOCUS_LOST); |
163 | } | |
164 | } | |
165 | } | |
166 | ||
167 | @Override | |
168 | public void focusGained(FocusEvent e) { | |
169 | | |
170 | DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) ManagerDatabase.this.tree.getLastSelectedPathComponent(); | |
171 | | |
172 |
1
1. focusGained : negated conditional → NO_COVERAGE |
if (treeNode != null) { |
173 | | |
174 | AbstractNodeModel nodeModel = (AbstractNodeModel) treeNode.getUserObject(); | |
175 | | |
176 |
2
1. focusGained : negated conditional → NO_COVERAGE 2. focusGained : negated conditional → NO_COVERAGE |
if (nodeModel != null && nodeModel.getPanel() != null) { |
177 | | |
178 |
1
1. focusGained : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
nodeModel.getPanel().getLabel().setBackground(UiUtil.COLOR_FOCUS_GAINED); |
179 |
1
1. focusGained : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
nodeModel.getPanel().getLabel().setBorder(UiUtil.BORDER_FOCUS_GAINED); |
180 | } | |
181 | } | |
182 | } | |
183 | }; | |
184 | } | |
185 | | |
186 | private class TreeModelGifListener implements TreeModelListener { | |
187 | | |
188 | @Override | |
189 | public void treeNodesChanged(TreeModelEvent arg0) { | |
190 | | |
191 |
1
1. treeNodesChanged : negated conditional → NO_COVERAGE |
if (arg0 == null) { |
192 | return; | |
193 | } | |
194 | | |
195 |
1
1. treeNodesChanged : removed call to com/jsql/view/swing/tree/TreeDatabase::firePropertyChange → NO_COVERAGE |
ManagerDatabase.this.tree.firePropertyChange( |
196 | JTree.ROOT_VISIBLE_PROPERTY, | |
197 |
1
1. treeNodesChanged : negated conditional → NO_COVERAGE |
!ManagerDatabase.this.tree.isRootVisible(), |
198 | ManagerDatabase.this.tree.isRootVisible() | |
199 | ); | |
200 | | |
201 |
1
1. treeNodesChanged : removed call to com/jsql/view/swing/tree/TreeDatabase::treeDidChange → NO_COVERAGE |
ManagerDatabase.this.tree.treeDidChange(); |
202 | } | |
203 | ||
204 | @Override | |
205 | public void treeStructureChanged(TreeModelEvent arg0) { | |
206 | // Do nothing | |
207 | } | |
208 | ||
209 | @Override | |
210 | public void treeNodesRemoved(TreeModelEvent arg0) { | |
211 | // Do nothing | |
212 | } | |
213 | ||
214 | @Override | |
215 | public void treeNodesInserted(TreeModelEvent arg0) { | |
216 | // Do nothing | |
217 | } | |
218 | } | |
219 | ||
220 | | |
221 | // Getter and setter | |
222 | ||
223 | public JTree getTree() { | |
224 |
1
1. getTree : replaced return value with null for com/jsql/view/swing/manager/ManagerDatabase::getTree → NO_COVERAGE |
return this.tree; |
225 | } | |
226 | } | |
Mutations | ||
54 |
1.1 |
|
57 |
1.1 |
|
65 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
72 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
76 |
1.1 |
|
79 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
88 |
1.1 |
|
90 |
1.1 |
|
95 |
1.1 |
|
100 |
1.1 |
|
104 |
1.1 |
|
108 |
1.1 2.2 3.3 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
122 |
1.1 |
|
130 |
1.1 2.2 |
|
133 |
1.1 |
|
134 |
1.1 |
|
136 |
1.1 |
|
148 |
1.1 |
|
155 |
1.1 |
|
159 |
1.1 2.2 |
|
161 |
1.1 |
|
162 |
1.1 |
|
172 |
1.1 |
|
176 |
1.1 2.2 |
|
178 |
1.1 |
|
179 |
1.1 |
|
191 |
1.1 |
|
195 |
1.1 |
|
197 |
1.1 |
|
201 |
1.1 |
|
224 |
1.1 |