gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.swing / org.gvsig.vcsgis.swing.impl / src / main / java / org / gvsig / vcsgis / swing / impl / VCSGisEntitySelectorControllerJTree.java @ 3519
History | View | Annotate | Download (25.4 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
package org.gvsig.vcsgis.swing.impl; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.awt.Cursor; |
26 |
import java.awt.FlowLayout; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import java.util.ArrayList; |
30 |
import java.util.Collection; |
31 |
import java.util.Collections; |
32 |
import java.util.HashMap; |
33 |
import java.util.HashSet; |
34 |
import java.util.List; |
35 |
import java.util.Map; |
36 |
import java.util.Set; |
37 |
import java.util.TreeMap; |
38 |
import java.util.function.Predicate; |
39 |
import javax.swing.AbstractCellEditor; |
40 |
import javax.swing.JButton; |
41 |
import javax.swing.JCheckBox; |
42 |
import javax.swing.JLabel; |
43 |
import javax.swing.JOptionPane; |
44 |
import javax.swing.JPanel; |
45 |
import javax.swing.JTextField; |
46 |
import javax.swing.JTree; |
47 |
import javax.swing.event.ChangeListener; |
48 |
import javax.swing.event.TreeSelectionEvent; |
49 |
import javax.swing.event.TreeSelectionListener; |
50 |
import javax.swing.tree.DefaultMutableTreeNode; |
51 |
import javax.swing.tree.DefaultTreeCellRenderer; |
52 |
import javax.swing.tree.DefaultTreeModel; |
53 |
import javax.swing.tree.TreeCellEditor; |
54 |
import javax.swing.tree.TreePath; |
55 |
import static javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION; |
56 |
import org.apache.commons.lang3.StringUtils; |
57 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.i18n.I18nManager; |
59 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
60 |
import org.gvsig.tools.swing.api.ChangeListenerHelper; |
61 |
import org.gvsig.tools.swing.api.FilteredTreeController; |
62 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
63 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
64 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
65 |
import org.gvsig.tools.util.CompareUtils; |
66 |
import org.gvsig.tools.util.LabeledValue; |
67 |
import org.gvsig.tools.util.LabeledValueImpl; |
68 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
69 |
import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_REPOSITORY_NEW; |
70 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
71 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
72 |
import static org.gvsig.vcsgis.swing.impl.VCSGisEntitySelectorController.ACTION_CHECK; |
73 |
import static org.gvsig.vcsgis.swing.impl.VCSGisEntitySelectorController.ACTION_CHECK_ID; |
74 |
import static org.gvsig.vcsgis.swing.impl.VCSGisEntitySelectorController.ACTION_SELECT; |
75 |
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.notInSwingThreadInvokeLater; |
76 |
import org.slf4j.Logger; |
77 |
import org.slf4j.LoggerFactory; |
78 |
|
79 |
/**
|
80 |
*
|
81 |
* @author gvSIG Team
|
82 |
*/
|
83 |
public class VCSGisEntitySelectorControllerJTree |
84 |
implements
|
85 |
VCSGisEntitySelectorController { |
86 |
|
87 |
private static final Logger LOGGER = LoggerFactory.getLogger(VCSGisEntitySelectorControllerJTree.class); |
88 |
|
89 |
private final JTextField txtFilter; |
90 |
private final JTree treeEntities; |
91 |
private Set<String> checkedEntityCodes; |
92 |
private Map<String, VCSGisEntity> entities; |
93 |
private final JButton btnEntities; |
94 |
private FilteredTreeController filteredTree;
|
95 |
private ActionListenerSupport actionListeners;
|
96 |
private ChangeListenerHelper changeListeners;
|
97 |
private VCSGisWorkspace workspace;
|
98 |
private boolean processing; |
99 |
private boolean enabled; |
100 |
private Predicate<VCSGisEntity> viewFilter; |
101 |
private Predicate<VCSGisEntity> filter; |
102 |
private boolean checksEnabled; |
103 |
private JButton btnCheckAll; |
104 |
private JButton btnUnCheckAll; |
105 |
|
106 |
private class EntityCellEditor extends AbstractCellEditor implements TreeCellEditor { |
107 |
|
108 |
private final JCheckBox check; |
109 |
private final JPanel panel; |
110 |
private final JLabel label; |
111 |
private Object currentUserObject; |
112 |
|
113 |
public EntityCellEditor() {
|
114 |
this.check = new JCheckBox(); |
115 |
this.label = new JLabel(); |
116 |
this.panel = new JPanel(); |
117 |
this.panel.setOpaque(false); |
118 |
this.check.setOpaque(false); |
119 |
this.panel.setLayout(new FlowLayout(FlowLayout.RIGHT, 2,1)); |
120 |
this.panel.add(this.check); |
121 |
this.panel.add(this.label); |
122 |
this.currentUserObject = null; |
123 |
this.check.addActionListener(new ActionListener() { |
124 |
@Override
|
125 |
public void actionPerformed(ActionEvent e) { |
126 |
if( currentUserObject==null ) { |
127 |
if( check.isSelected() ) {
|
128 |
checkedEntityCodes.addAll(getAllEntityCodesFromCategory(null));
|
129 |
} else {
|
130 |
checkedEntityCodes.removeAll(getAllEntityCodesFromCategory(null));
|
131 |
} |
132 |
postCheck(); |
133 |
return;
|
134 |
} |
135 |
if( !(currentUserObject instanceof LabeledValue) ) { //Category |
136 |
String category = (String)currentUserObject; |
137 |
if( check.isSelected() ) {
|
138 |
checkedEntityCodes.addAll(getAllEntityCodesFromCategory(category)); |
139 |
} else {
|
140 |
checkedEntityCodes.removeAll(getAllEntityCodesFromCategory(category)); |
141 |
} |
142 |
postCheck(); |
143 |
return;
|
144 |
} |
145 |
VCSGisEntity entity = ((LabeledValue<VCSGisEntity>) currentUserObject).getValue(); |
146 |
if( entity == null ) { |
147 |
return;
|
148 |
} |
149 |
if( check.isSelected() ) {
|
150 |
checkedEntityCodes.add(entity.getEntityCode()); |
151 |
} else {
|
152 |
checkedEntityCodes.remove(entity.getEntityCode()); |
153 |
} |
154 |
postCheck(); |
155 |
} |
156 |
}); |
157 |
} |
158 |
|
159 |
private void postCheck() { |
160 |
this.stopCellEditing();
|
161 |
treeEntities.repaint(); |
162 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
163 |
} |
164 |
|
165 |
@Override
|
166 |
public Object getCellEditorValue() { |
167 |
return currentUserObject;
|
168 |
} |
169 |
|
170 |
@Override
|
171 |
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { |
172 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
173 |
if( checksEnabled ) {
|
174 |
this.check.setVisible(true); |
175 |
this.check.setEnabled(false); |
176 |
this.check.setSelected(false); |
177 |
if(value instanceof DefaultMutableTreeNode){ |
178 |
currentUserObject = ((DefaultMutableTreeNode) value).getUserObject();
|
179 |
if( currentUserObject instanceof LabeledValue ) { |
180 |
VCSGisEntity entity = ((LabeledValue<VCSGisEntity>) currentUserObject).getValue(); |
181 |
if( entity != null ) { |
182 |
this.check.setEnabled(true); |
183 |
this.check.setSelected(checkedEntityCodes.contains(entity.getEntityCode()));
|
184 |
this.label.setText(((LabeledValue<VCSGisEntity>) currentUserObject).getLabel());
|
185 |
} |
186 |
} else if( currentUserObject instanceof String || currentUserObject == null) { |
187 |
this.check.setEnabled(true); |
188 |
this.check.setSelected(areSelectedAllEntitiesFromCategory((String)currentUserObject)); |
189 |
if(StringUtils.isBlank((String)currentUserObject)){ |
190 |
this.label.setText(i18n.getTranslation("_Others")); |
191 |
} else {
|
192 |
this.label.setText(i18n.getTranslation((String)currentUserObject)); |
193 |
} |
194 |
} |
195 |
} |
196 |
} else {
|
197 |
this.check.setVisible(false); |
198 |
} |
199 |
return this.panel; |
200 |
} |
201 |
|
202 |
} |
203 |
|
204 |
private class EntityCellRenderer extends DefaultTreeCellRenderer { |
205 |
|
206 |
private final JCheckBox check; |
207 |
private final JPanel panel; |
208 |
private final JLabel label; |
209 |
|
210 |
public EntityCellRenderer() {
|
211 |
this.check = new JCheckBox(); |
212 |
this.label = new JLabel(); |
213 |
this.panel = new JPanel(); |
214 |
this.panel.setOpaque(false); |
215 |
this.check.setOpaque(false); |
216 |
this.panel.setLayout(new FlowLayout(FlowLayout.RIGHT, 2,1)); |
217 |
this.panel.add(this.check); |
218 |
this.panel.add(this.label); |
219 |
this.setLeafIcon(null); |
220 |
} |
221 |
|
222 |
@Override
|
223 |
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { |
224 |
JLabel c = (JLabel) super.getTreeCellRendererComponent(tree, value, leaf, expanded, leaf, row, hasFocus); |
225 |
this.label.setText(c.getText());
|
226 |
this.label.setForeground(c.getForeground());
|
227 |
this.label.setBackground(c.getBackground());
|
228 |
if( checksEnabled ) {
|
229 |
this.check.setVisible(true); |
230 |
this.check.setForeground(c.getForeground());
|
231 |
this.check.setBackground(c.getBackground());
|
232 |
this.check.setEnabled(false); |
233 |
this.check.setSelected(false); |
234 |
|
235 |
if(value instanceof DefaultMutableTreeNode){ |
236 |
Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); |
237 |
if( userObject instanceof LabeledValue ) { |
238 |
VCSGisEntity entity = ((LabeledValue<VCSGisEntity>) userObject).getValue(); |
239 |
if( entity != null ) { |
240 |
this.check.setEnabled(true); |
241 |
this.check.setSelected(checkedEntityCodes.contains(entity.getEntityCode()));
|
242 |
} |
243 |
} else if( userObject instanceof String || userObject == null) { |
244 |
this.check.setEnabled(true); |
245 |
this.check.setSelected(areSelectedAllEntitiesFromCategory((String)userObject)); |
246 |
if(StringUtils.isBlank((String)userObject)){ |
247 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
248 |
this.label.setText(i18n.getTranslation("_Others")); |
249 |
} else {
|
250 |
this.label.setText((String)userObject); |
251 |
} |
252 |
} |
253 |
} |
254 |
} else {
|
255 |
this.check.setVisible(false); |
256 |
} |
257 |
return this.panel; |
258 |
} |
259 |
|
260 |
protected JCheckBox getCheckBox() { |
261 |
return this.check; |
262 |
} |
263 |
|
264 |
} |
265 |
|
266 |
public VCSGisEntitySelectorControllerJTree(JTree treeEntities) { |
267 |
this(treeEntities, null, null, null, null); |
268 |
} |
269 |
|
270 |
public VCSGisEntitySelectorControllerJTree(JTree treeEntities, JTextField txtFilter, JButton btnTable, JButton btnCheckAll, JButton btnUnCheckAll) { |
271 |
viewFilter = ALL_ENTITIES; |
272 |
filter = ALL_ENTITIES; |
273 |
|
274 |
this.treeEntities = treeEntities;
|
275 |
this.checkedEntityCodes = new HashSet<>(); |
276 |
this.entities = new HashMap<>(); |
277 |
if (txtFilter == null) { |
278 |
this.txtFilter = new JTextField(); |
279 |
} else {
|
280 |
this.txtFilter = txtFilter;
|
281 |
} |
282 |
if (btnTable == null) { |
283 |
this.btnEntities = new JButton(); |
284 |
} else {
|
285 |
this.btnEntities = btnTable;
|
286 |
} |
287 |
|
288 |
if( btnCheckAll==null ) { |
289 |
this.btnCheckAll = new JButton(); |
290 |
} else {
|
291 |
this.btnCheckAll = btnCheckAll;
|
292 |
} |
293 |
if( btnUnCheckAll==null ) { |
294 |
this.btnUnCheckAll = new JButton(); |
295 |
} else {
|
296 |
this.btnUnCheckAll = btnCheckAll;
|
297 |
} |
298 |
|
299 |
this.processing = false; |
300 |
|
301 |
this.initComponents();
|
302 |
} |
303 |
|
304 |
private void initComponents() { |
305 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
306 |
|
307 |
this.actionListeners = toolsSwingManager.createActionListenerSupport();
|
308 |
this.changeListeners = toolsSwingManager.createChangeListenerHelper();
|
309 |
|
310 |
this.btnEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
311 |
|
312 |
this.treeEntities.getSelectionModel().setSelectionMode(SINGLE_TREE_SELECTION);
|
313 |
this.treeEntities.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { |
314 |
@Override
|
315 |
public void valueChanged(TreeSelectionEvent e) { |
316 |
fireActionEvent(new ActionEvent(this, 0, ACTION_SELECT)); |
317 |
} |
318 |
}); |
319 |
filteredTree = toolsSwingManager.createFilteredTreeController(treeEntities, txtFilter, btnEntities); |
320 |
filteredTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); |
321 |
EntityCellRenderer cellRenderer = new EntityCellRenderer();
|
322 |
this.treeEntities.setCellRenderer(cellRenderer);
|
323 |
this.treeEntities.setCellEditor(new EntityCellEditor()); |
324 |
this.treeEntities.setEditable(true); |
325 |
|
326 |
this.btnCheckAll.addActionListener(new ActionListener() { |
327 |
@Override
|
328 |
public void actionPerformed(ActionEvent e) { |
329 |
checkAll(); |
330 |
} |
331 |
}); |
332 |
this.btnUnCheckAll.addActionListener(new ActionListener() { |
333 |
@Override
|
334 |
public void actionPerformed(ActionEvent e) { |
335 |
clearChecks(); |
336 |
} |
337 |
}); |
338 |
|
339 |
} |
340 |
|
341 |
@Override
|
342 |
public boolean isProcessing() { |
343 |
return this.processing; |
344 |
} |
345 |
|
346 |
@Override
|
347 |
public VCSGisEntity getSelectedEntity() {
|
348 |
if (this.workspace == null) { |
349 |
return null; |
350 |
} |
351 |
TreePath path = treeEntities.getSelectionPath();
|
352 |
if (path == null) { |
353 |
return null; |
354 |
} |
355 |
LabeledValue selected = (LabeledValue) path.getLastPathComponent(); |
356 |
if (selected == null) { |
357 |
return null; |
358 |
} |
359 |
VCSGisEntity entity = (VCSGisEntity) selected.getValue(); |
360 |
if (!this.filter.test(entity)) { |
361 |
return null; |
362 |
} |
363 |
return entity;
|
364 |
} |
365 |
|
366 |
@Override
|
367 |
public List<VCSGisEntity> getCheckedEntities() { |
368 |
List<VCSGisEntity> checkedEntities = new ArrayList<>(); |
369 |
for (String entityCode : this.checkedEntityCodes) { |
370 |
checkedEntities.add(this.entities.get(entityCode));
|
371 |
} |
372 |
return checkedEntities;
|
373 |
} |
374 |
|
375 |
@Override
|
376 |
public void setWorkspace(VCSGisWorkspace workspace) { |
377 |
this.checkedEntityCodes.clear();
|
378 |
this.entities.clear();
|
379 |
if (workspace == null) { |
380 |
this.workspace = workspace;
|
381 |
filteredTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); |
382 |
return;
|
383 |
} |
384 |
if (this.processing && this.workspace == workspace) { |
385 |
LOGGER.info("Reentrada");
|
386 |
return;
|
387 |
} |
388 |
|
389 |
this.workspace = workspace;
|
390 |
Thread task = new Thread(() -> { |
391 |
reloadEntities(this.workspace);
|
392 |
}, "VCSGisEntitySelectorReloadEntities");
|
393 |
task.start(); |
394 |
} |
395 |
|
396 |
@Override
|
397 |
public VCSGisWorkspace getWorkspace() {
|
398 |
return this.workspace; |
399 |
} |
400 |
|
401 |
private void reloadEntities(VCSGisWorkspace workspace) { |
402 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
403 |
try {
|
404 |
fireActionEvent(new ActionEvent(this, ACTION_BEGIN_PROCESSING_ID, ACTION_BEGIN_PROCESSING)); |
405 |
this.processing = true; |
406 |
this.doUpdateComponents();
|
407 |
workspace.reloadRepositoryEntities(null);
|
408 |
List<VCSGisEntity> allEntities = workspace.getRepositoryEntities();
|
409 |
List<VCSGisWorkspaceEntity> localEntities = workspace.getWorkspaceEntities();
|
410 |
for (VCSGisWorkspaceEntity localEntity : localEntities) {
|
411 |
if (StringUtils.isBlank(localEntity.getRepositoryRevisionCode())) {
|
412 |
allEntities.add(localEntity); |
413 |
} |
414 |
} |
415 |
Collections.sort(allEntities, new CompareUtils.NullSafeComparator<VCSGisEntity>() { |
416 |
@Override
|
417 |
public int safeCompare(VCSGisEntity o1, VCSGisEntity o2) { |
418 |
return StringUtils.compare(o1.getEntityName(), o2.getEntityName(), true); |
419 |
} |
420 |
}); |
421 |
|
422 |
|
423 |
Map<String, VCSGisEntity> theEntities; |
424 |
Map<String, DefaultMutableTreeNode> theEntityNodes; |
425 |
|
426 |
theEntityNodes = new TreeMap<>((String o1, String o2) -> StringUtils.compare(o1, o2, false)); |
427 |
|
428 |
theEntities = new HashMap<>(); |
429 |
|
430 |
for (VCSGisEntity entity : allEntities) {
|
431 |
VCSGisWorkspaceEntity lentity = workspace.getWorkspaceEntityByCode(entity.getEntityCode()); |
432 |
LabeledValue entry; |
433 |
String s;
|
434 |
if (StringUtils.isBlank(entity.getRepositoryRevisionCode())) { //Es entidad local nueva |
435 |
s = VCSGisSwingCommons.getHTMLColorTag( |
436 |
((VCSGisWorkspaceEntity)entity).getState(), |
437 |
entity.getEntityName() |
438 |
); |
439 |
} else {
|
440 |
s = VCSGisSwingCommons.getHTMLColorTag( |
441 |
lentity == null ? STATE_REPOSITORY_NEW : lentity.getState(),
|
442 |
entity.getEntityName() |
443 |
); |
444 |
} |
445 |
|
446 |
if(lentity != null && this.viewFilter.test(lentity)){ |
447 |
entity = lentity; |
448 |
} else {
|
449 |
if(!this.viewFilter.test(entity)){ |
450 |
entity = null;
|
451 |
} |
452 |
} |
453 |
|
454 |
if (entity!=null) { |
455 |
theEntities.put(entity.getEntityCode(), entity); |
456 |
entry = new LabeledValueImpl(s, entity);
|
457 |
List<String> categories = entity.getCategoriesAsList(); |
458 |
if(categories.size()>0){ |
459 |
for (String cat : categories) { |
460 |
String category = StringUtils.trimToNull(cat);
|
461 |
addNodeEntity(theEntityNodes, category, entry); |
462 |
} |
463 |
} else {
|
464 |
String category = StringUtils.trimToNull(entity.getCategory());
|
465 |
addNodeEntity(theEntityNodes, category, entry); |
466 |
} |
467 |
} |
468 |
} |
469 |
|
470 |
this.entities = theEntities;
|
471 |
|
472 |
DefaultMutableTreeNode root = new DefaultMutableTreeNode(); |
473 |
for (DefaultMutableTreeNode node : theEntityNodes.values()) { |
474 |
root.add(node); |
475 |
} |
476 |
postReloadEntities(root); |
477 |
|
478 |
} catch (Exception e) { |
479 |
LOGGER.warn("_Cant_retrieve_entities_from_repository", e);
|
480 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
481 |
dialogs.messageDialog( |
482 |
i18n.getTranslation("_Cant_retrieve_entities_from_repository") + "\n" + e.getMessage(), |
483 |
i18n.getTranslation("_Checkout"),
|
484 |
JOptionPane.WARNING_MESSAGE
|
485 |
); |
486 |
} finally {
|
487 |
this.processing = false; |
488 |
this.doUpdateComponents();
|
489 |
fireActionEvent(new ActionEvent(this, ACTION_END_PROCESSING_ID, ACTION_END_PROCESSING)); |
490 |
} |
491 |
|
492 |
} |
493 |
|
494 |
@Override
|
495 |
public Collection<VCSGisEntity> getEntities() { |
496 |
return this.entities.values(); |
497 |
} |
498 |
|
499 |
private void addNodeEntity(Map<String, DefaultMutableTreeNode> theEntityNodes, String category, LabeledValue entry) { |
500 |
DefaultMutableTreeNode branch = theEntityNodes.get(category);
|
501 |
if (branch == null) { |
502 |
branch = new DefaultMutableTreeNode(category, true); |
503 |
theEntityNodes.put(category, branch); |
504 |
} |
505 |
branch.add(new DefaultMutableTreeNode(entry, false)); |
506 |
} |
507 |
|
508 |
private void postReloadEntities(DefaultMutableTreeNode entities) { |
509 |
if (notInSwingThreadInvokeLater(() -> {
|
510 |
postReloadEntities(entities); |
511 |
})) { |
512 |
return;
|
513 |
} |
514 |
filteredTree.setModel(new DefaultTreeModel(entities)); |
515 |
this.expandAllNodes(treeEntities);
|
516 |
this.processing = false; |
517 |
fireActionEvent(new ActionEvent(this, ACTION_RELOAD_ID, ACTION_RELOAD)); |
518 |
} |
519 |
|
520 |
private void doUpdateComponents() { |
521 |
if (notInSwingThreadInvokeLater(this::doUpdateComponents)) { |
522 |
return;
|
523 |
} |
524 |
this.txtFilter.setEnabled(enabled && !processing);
|
525 |
this.btnEntities.setEnabled(enabled && !processing);
|
526 |
this.treeEntities.setEnabled(enabled && !processing);
|
527 |
} |
528 |
|
529 |
@Override
|
530 |
public void setEnabled(boolean enabled) { |
531 |
this.enabled = enabled;
|
532 |
doUpdateComponents(); |
533 |
} |
534 |
|
535 |
@Override
|
536 |
public boolean isEnabled() { |
537 |
return enabled;
|
538 |
} |
539 |
|
540 |
@Override
|
541 |
public void setChecksEnabled(boolean enabled) { |
542 |
this.checksEnabled = enabled;
|
543 |
} |
544 |
|
545 |
@Override
|
546 |
public boolean isChecksEnabled() { |
547 |
return this.checksEnabled; |
548 |
} |
549 |
|
550 |
@Override
|
551 |
public void addActionListener(ActionListener al) { |
552 |
this.actionListeners.addActionListener(al);
|
553 |
} |
554 |
|
555 |
@Override
|
556 |
public ActionListener[] getActionListeners() { |
557 |
return this.actionListeners.getActionListeners(); |
558 |
} |
559 |
|
560 |
@Override
|
561 |
public void removeActionListener(ActionListener al) { |
562 |
this.actionListeners.removeActionListener(al);
|
563 |
} |
564 |
|
565 |
@Override
|
566 |
public void removeAllActionListener() { |
567 |
this.actionListeners.removeAllActionListener();
|
568 |
} |
569 |
|
570 |
@Override
|
571 |
public void fireActionEvent(ActionEvent ae) { |
572 |
this.actionListeners.fireActionEvent(ae);
|
573 |
} |
574 |
|
575 |
@Override
|
576 |
public boolean hasActionListeners() { |
577 |
return this.actionListeners.hasActionListeners(); |
578 |
} |
579 |
|
580 |
@Override
|
581 |
public void addChangeListener(ChangeListener cl) { |
582 |
this.changeListeners.addChangeListener(cl);
|
583 |
} |
584 |
|
585 |
@Override
|
586 |
public ChangeListener[] getChangeListeners() { |
587 |
return this.changeListeners.getChangeListeners(); |
588 |
} |
589 |
|
590 |
@Override
|
591 |
public void removeChangeListener(ChangeListener cl) { |
592 |
this.changeListeners.removeChangeListener(cl);
|
593 |
} |
594 |
|
595 |
@Override
|
596 |
public void removeAllChangeListener() { |
597 |
this.changeListeners.removeAllChangeListener();
|
598 |
} |
599 |
|
600 |
@Override
|
601 |
public boolean hasChangeListeners() { |
602 |
return this.changeListeners.hasChangeListeners(); |
603 |
} |
604 |
|
605 |
@Override
|
606 |
public void setViewFilter(Predicate<VCSGisEntity> viewFilter) { |
607 |
this.viewFilter = viewFilter;
|
608 |
} |
609 |
|
610 |
@Override
|
611 |
public void setFilter(Predicate<VCSGisEntity> filter) { |
612 |
this.filter = filter;
|
613 |
} |
614 |
|
615 |
@Override
|
616 |
public void check(VCSGisEntity entity) { |
617 |
this.checkedEntityCodes.add(entity.getEntityCode());
|
618 |
this.treeEntities.repaint();
|
619 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
620 |
} |
621 |
|
622 |
@Override
|
623 |
public void checkAll() { |
624 |
for (Map.Entry<String, VCSGisEntity> entry : entities.entrySet()) { |
625 |
this.checkedEntityCodes.add(entry.getValue().getEntityCode());
|
626 |
} |
627 |
this.treeEntities.repaint();
|
628 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
629 |
} |
630 |
|
631 |
@Override
|
632 |
public void clearChecks() { |
633 |
this.checkedEntityCodes.clear();
|
634 |
this.treeEntities.repaint();
|
635 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
636 |
} |
637 |
|
638 |
private void expandAllNodes(JTree tree) { |
639 |
int j = tree.getRowCount();
|
640 |
int i = 0; |
641 |
while(i < j) {
|
642 |
tree.expandRow(i); |
643 |
i += 1;
|
644 |
j = tree.getRowCount(); |
645 |
} |
646 |
} |
647 |
|
648 |
private boolean areSelectedAllEntitiesFromCategory(String category) { |
649 |
|
650 |
for (Map.Entry<String, VCSGisEntity> entry : this.entities.entrySet()) { |
651 |
VCSGisEntity entity = entry.getValue(); |
652 |
if(StringUtils.isBlank(category)){
|
653 |
if(StringUtils.isBlank(entity.getCategory())){
|
654 |
if (!this.checkedEntityCodes.contains(entity.getEntityCode())) { |
655 |
return false; |
656 |
} |
657 |
} |
658 |
} else {
|
659 |
if (entity.getCategoriesAsList().contains(category)) {
|
660 |
if (!this.checkedEntityCodes.contains(entity.getEntityCode())) { |
661 |
return false; |
662 |
} |
663 |
} |
664 |
} |
665 |
} |
666 |
return true; |
667 |
} |
668 |
|
669 |
private Set<String> getAllEntityCodesFromCategory(String category){ |
670 |
Set<String> entityCodes = new HashSet<>(); |
671 |
for (Map.Entry<String, VCSGisEntity> entry : this.entities.entrySet()) { |
672 |
VCSGisEntity entity = entry.getValue(); |
673 |
if(StringUtils.isBlank(category)){
|
674 |
if(StringUtils.isBlank(entity.getCategory())){
|
675 |
entityCodes.add(entity.getEntityCode()); |
676 |
} |
677 |
} else {
|
678 |
if (entity.getCategoriesAsList().contains(category)) {
|
679 |
entityCodes.add(entity.getEntityCode()); |
680 |
} |
681 |
} |
682 |
} |
683 |
return entityCodes;
|
684 |
} |
685 |
|
686 |
} |