gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / OnlineEntitySelectorControllerJList.java @ 9518
History | View | Annotate | Download (24 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 |
|
23 |
package org.gvsig.online.swing.impl; |
24 |
|
25 |
import java.awt.Component; |
26 |
import java.awt.Cursor; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import java.awt.event.MouseEvent; |
30 |
import java.awt.event.MouseMotionAdapter; |
31 |
import java.util.ArrayList; |
32 |
import java.util.Collection; |
33 |
import java.util.Collections; |
34 |
import java.util.HashSet; |
35 |
import java.util.List; |
36 |
import java.util.Set; |
37 |
import java.util.function.Function; |
38 |
import java.util.function.Predicate; |
39 |
import javax.swing.JButton; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JList; |
42 |
import javax.swing.JOptionPane; |
43 |
import javax.swing.JTextField; |
44 |
import javax.swing.ListCellRenderer; |
45 |
import javax.swing.ListModel; |
46 |
import javax.swing.ListSelectionModel; |
47 |
import javax.swing.event.ChangeListener; |
48 |
import javax.swing.event.ListSelectionEvent; |
49 |
import javax.swing.event.ListSelectionListener; |
50 |
import javax.swing.text.JTextComponent; |
51 |
import org.apache.commons.collections.CollectionUtils; |
52 |
import org.apache.commons.lang3.StringUtils; |
53 |
import static org.gvsig.online.lib.api.OnlineManager.STATE_REMOTE_NEW; |
54 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
55 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
56 |
import org.gvsig.online.swing.api.OnlineEntitySelectorController; |
57 |
import static org.gvsig.online.swing.impl.OnlineSwingCommons.notInSwingThreadInvokeLater; |
58 |
import org.gvsig.tools.ToolsLocator; |
59 |
import org.gvsig.tools.dispose.DisposeUtils; |
60 |
import org.gvsig.tools.dispose.impl.AbstractDisposable; |
61 |
import org.gvsig.tools.exception.BaseException; |
62 |
import org.gvsig.tools.i18n.I18nManager; |
63 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
64 |
import org.gvsig.tools.swing.api.ChangeListenerHelper; |
65 |
import org.gvsig.tools.swing.api.FilteredListController; |
66 |
import org.gvsig.tools.swing.api.FilteredListModel; |
67 |
import org.gvsig.tools.swing.api.JListWithCheckbox; |
68 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
69 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
70 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
71 |
import org.gvsig.tools.util.LabeledValue; |
72 |
import org.gvsig.tools.util.LabeledValueImpl; |
73 |
import org.slf4j.Logger; |
74 |
import org.slf4j.LoggerFactory; |
75 |
|
76 |
/**
|
77 |
*
|
78 |
* @author gvSIG Team
|
79 |
*/
|
80 |
public class OnlineEntitySelectorControllerJList extends AbstractDisposable implements OnlineEntitySelectorController |
81 |
{ |
82 |
private static final Logger LOGGER = LoggerFactory.getLogger(OnlineEntitySelectorControllerJList.class); |
83 |
|
84 |
private final JTextComponent txtFilter; |
85 |
private final JList lstTables; |
86 |
private JListWithCheckbox lstTablesWithCheckbox;
|
87 |
private final JButton btnTable; |
88 |
private FilteredListController filteredList;
|
89 |
private ActionListenerSupport actionListeners;
|
90 |
private ChangeListenerHelper changeListeners;
|
91 |
private OnlineWorkingcopy workspace;
|
92 |
private boolean processing; |
93 |
private boolean enabled; |
94 |
private Predicate<OnlineEntity> viewFilter; |
95 |
private Predicate<OnlineEntity> filter; |
96 |
private JButton btnCheckAll; |
97 |
private JButton btnUnCheckAll; |
98 |
private ArrayList<OnlineEntity> entities; |
99 |
private Thread lastThread; |
100 |
private Function<OnlineEntity, String> labelEntityFormatter; |
101 |
|
102 |
public OnlineEntitySelectorControllerJList(JList lstTables) { |
103 |
this(lstTables, null, null, null, null); |
104 |
} |
105 |
|
106 |
public OnlineEntitySelectorControllerJList(JList lstTables, JTextComponent txtFilter, JButton btnTable, JButton btnCheckAll, JButton btnUnCheckAll) { |
107 |
viewFilter = ALL_ENTITIES; |
108 |
filter = ALL_ENTITIES; |
109 |
|
110 |
this.lstTables = lstTables;
|
111 |
this.lstTablesWithCheckbox = null; |
112 |
if( txtFilter==null ) { |
113 |
this.txtFilter = new JTextField(); |
114 |
} else {
|
115 |
this.txtFilter = txtFilter;
|
116 |
} |
117 |
if( btnTable==null ) { |
118 |
this.btnTable = new JButton(); |
119 |
} else {
|
120 |
this.btnTable = btnTable;
|
121 |
} |
122 |
if( btnCheckAll==null ) { |
123 |
this.btnCheckAll = new JButton(); |
124 |
} else {
|
125 |
this.btnCheckAll = btnCheckAll;
|
126 |
} |
127 |
if( btnUnCheckAll==null ) { |
128 |
this.btnUnCheckAll = new JButton(); |
129 |
} else {
|
130 |
this.btnUnCheckAll = btnUnCheckAll;
|
131 |
} |
132 |
this.lstTables.setCellRenderer(new ListCellRenderer() { |
133 |
JLabel label = new JLabel(); |
134 |
@Override
|
135 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
136 |
if( value instanceof OnlineEntity && workspace!=null ) { |
137 |
this.label.setText(workspace.formatEntityLabel((OnlineEntity)value));
|
138 |
} else {
|
139 |
this.label.setText(value.toString());
|
140 |
} |
141 |
return this.label; |
142 |
} |
143 |
}); |
144 |
|
145 |
this.processing = false; |
146 |
|
147 |
this.initComponents();
|
148 |
} |
149 |
|
150 |
private void initComponents() { |
151 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
152 |
|
153 |
this.actionListeners = toolsSwingManager.createActionListenerSupport();
|
154 |
this.changeListeners = toolsSwingManager.createChangeListenerHelper();
|
155 |
|
156 |
this.btnTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
157 |
|
158 |
this.lstTables.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
159 |
this.lstTables.addListSelectionListener(new ListSelectionListener() { |
160 |
boolean alreadyInEvent = false; |
161 |
@Override
|
162 |
public void valueChanged(ListSelectionEvent e) { |
163 |
if( e.getValueIsAdjusting() || this.alreadyInEvent ) { |
164 |
return;
|
165 |
} |
166 |
try {
|
167 |
this.alreadyInEvent = true; |
168 |
fireActionEvent(new ActionEvent(this, ACTION_SELECT_ID, ACTION_SELECT)); |
169 |
} finally {
|
170 |
this.alreadyInEvent = false; |
171 |
} |
172 |
} |
173 |
}); |
174 |
|
175 |
this.btnCheckAll.addActionListener(new ActionListener() { |
176 |
@Override
|
177 |
public void actionPerformed(ActionEvent e) { |
178 |
checkAll(); |
179 |
} |
180 |
}); |
181 |
this.btnUnCheckAll.addActionListener(new ActionListener() { |
182 |
@Override
|
183 |
public void actionPerformed(ActionEvent e) { |
184 |
clearChecks(); |
185 |
} |
186 |
}); |
187 |
this.lstTables.addMouseMotionListener(new MouseMotionAdapter() { |
188 |
@Override
|
189 |
public void mouseMoved(MouseEvent e) { |
190 |
super.mouseMoved(e);
|
191 |
doMouseMoved(lstTables.locationToIndex(e.getPoint())); |
192 |
} |
193 |
}); |
194 |
|
195 |
filteredList = toolsSwingManager.createFilteredListController(lstTables, txtFilter, btnTable); |
196 |
this.lstTables.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
197 |
} |
198 |
|
199 |
private void doMouseMoved(int rowindex) { |
200 |
if(rowindex<0 ){ |
201 |
return;
|
202 |
} |
203 |
Object x = this.lstTables.getModel().getElementAt(rowindex); |
204 |
if(!(x instanceof LabeledValue)){ |
205 |
this.lstTables.setToolTipText(""); |
206 |
return;
|
207 |
} |
208 |
LabeledValue lv = (LabeledValue)x; |
209 |
if (lv.getValue() instanceof OnlineEntity) { |
210 |
OnlineEntity entity = (OnlineEntity) lv.getValue(); |
211 |
|
212 |
OnlineEntity lentity = workspace.getWorkspaceEntityByCode(entity.getEntityCode()); |
213 |
String s;
|
214 |
// if (StringUtils.isBlank(entity.getRepositoryRevisionCode())) { //Es entidad local nueva
|
215 |
// s = OnlineSwingCommons.getStateDescription(
|
216 |
// ((OnlineEntity) entity).getState()
|
217 |
// );
|
218 |
// } else {
|
219 |
s = OnlineSwingCommons.getStateDescription( |
220 |
lentity == null ? STATE_REMOTE_NEW : lentity.getState()
|
221 |
); |
222 |
// }
|
223 |
if( StringUtils.equalsIgnoreCase(entity.getEntityCode(), entity.getLabel()) ) {
|
224 |
s = "<html>"+entity.getLabelOrName()+"<br>"+s+"</html>"; |
225 |
} else {
|
226 |
s = "<html>"+entity.getLabel()+"<br>"+entity.getEntityName()+"<br>"+s+"</html>"; |
227 |
} |
228 |
this.lstTables.setToolTipText(s);
|
229 |
|
230 |
} else {
|
231 |
this.lstTables.setToolTipText(""); |
232 |
} |
233 |
} |
234 |
|
235 |
@Override
|
236 |
public boolean isProcessing() { |
237 |
return this.processing; |
238 |
} |
239 |
|
240 |
@Override
|
241 |
public OnlineEntity getSelectedEntity() {
|
242 |
if( this.workspace==null ) { |
243 |
return null; |
244 |
} |
245 |
LabeledValue selected = (LabeledValue) lstTables.getSelectedValue(); |
246 |
if (selected == null) { |
247 |
return null; |
248 |
} |
249 |
OnlineEntity entity = (OnlineEntity) selected.getValue(); |
250 |
if(!this.filter.test(entity)){ |
251 |
return null; |
252 |
} |
253 |
return entity;
|
254 |
} |
255 |
|
256 |
@Override
|
257 |
public void setSelectedEntity(OnlineEntity entity) { |
258 |
if( this.workspace==null ) { |
259 |
return;
|
260 |
} |
261 |
ListModel model = lstTables.getModel();
|
262 |
for (int i = 0; i < model.getSize(); i++) { |
263 |
OnlineEntity value = ((LabeledValue<OnlineEntity>)model.getElementAt(i)).getValue(); |
264 |
if(StringUtils.equals(entity.getEntityCode(), value.getEntityCode())){
|
265 |
lstTables.setSelectedIndex(i); |
266 |
return;
|
267 |
} |
268 |
} |
269 |
} |
270 |
|
271 |
@Override
|
272 |
public List<OnlineEntity> getCheckedEntities() { |
273 |
if (this.lstTablesWithCheckbox == null) { |
274 |
OnlineEntity entity = this.getSelectedEntity();
|
275 |
if (entity == null) { |
276 |
return Collections.EMPTY_LIST; |
277 |
} |
278 |
return Collections.singletonList(this.getSelectedEntity()); |
279 |
} |
280 |
List<OnlineEntity> checkedEntities = new ArrayList<>(); |
281 |
ListSelectionModel checkedModel = this.lstTablesWithCheckbox.getCheckedModel(); |
282 |
ListModel model = this.lstTablesWithCheckbox.getModel(); |
283 |
for (int i = 0; i < model.getSize(); i++) { |
284 |
if(checkedModel.isSelectedIndex(i)){
|
285 |
checkedEntities.add((OnlineEntity) ((LabeledValue) model.getElementAt(i)).getValue()); |
286 |
} |
287 |
} |
288 |
return checkedEntities;
|
289 |
} |
290 |
|
291 |
@Override
|
292 |
public void setWorkspace(OnlineWorkingcopy workspace) { |
293 |
DisposeUtils.disposeQuietly(workspace); |
294 |
this.workspace = workspace;
|
295 |
DisposeUtils.bind(this.workspace);
|
296 |
reloadEntities(true);
|
297 |
} |
298 |
|
299 |
@Override
|
300 |
public OnlineWorkingcopy getWorkspace() {
|
301 |
return this.workspace; |
302 |
} |
303 |
|
304 |
@Override
|
305 |
public void reloadEntities() { |
306 |
reloadEntities(true);
|
307 |
} |
308 |
|
309 |
private void reloadEntities(boolean forceUpdateEntities) { |
310 |
this.filteredList.getModel().clear();
|
311 |
if (workspace == null) { |
312 |
postReloadTables(Collections.EMPTY_LIST);
|
313 |
return;
|
314 |
} |
315 |
Thread task = new Thread(() -> {reloadTables(this.workspace, forceUpdateEntities);}, "VCSGisEntitySelectorListReloadEntities"); |
316 |
task.start(); |
317 |
this.lastThread = task;
|
318 |
} |
319 |
|
320 |
private boolean isCancelled(){ |
321 |
return Thread.currentThread() != this.lastThread; |
322 |
} |
323 |
|
324 |
private void reloadTables(OnlineWorkingcopy workspace, boolean forceUpdateEntities) { |
325 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
326 |
try {
|
327 |
fireActionEvent(new ActionEvent(this, ACTION_BEGIN_PROCESSING_ID, ACTION_BEGIN_PROCESSING)); |
328 |
this.processing = true; |
329 |
this.doUpdateComponents();
|
330 |
// if(forceUpdateEntities){
|
331 |
// workspace.updateEntitiesFromRepository();
|
332 |
// }
|
333 |
// List<OnlineEntity> repoEntities = workspace.getRepositoryEntities();
|
334 |
|
335 |
List<LabeledValue<OnlineEntity>> entities = new ArrayList<>(); |
336 |
// for (OnlineEntity rentity : repoEntities) {
|
337 |
// if(isCancelled()){
|
338 |
// return;
|
339 |
// }
|
340 |
// OnlineEntity lentity = workspace.getWorkspaceEntityByCode(rentity.getEntityCode());
|
341 |
// LabeledValue entry;
|
342 |
// String s = OnlineSwingCommons.getHTMLColorTag(
|
343 |
// lentity == null ? STATE_REMOTE_NEW : lentity.getState(),
|
344 |
// this.getLabelOfEntity(rentity)
|
345 |
// );
|
346 |
// if(lentity != null && this.viewFilter.test(lentity)){
|
347 |
// entry = new LabeledValueImpl(s, lentity);
|
348 |
// entities.add(entry);
|
349 |
// } else {
|
350 |
// if(this.viewFilter.test(rentity)){
|
351 |
// entry = new LabeledValueImpl(s, rentity);
|
352 |
// entities.add(entry);
|
353 |
// }
|
354 |
// }
|
355 |
// }
|
356 |
|
357 |
List<OnlineEntity> localEntities = workspace.getWorkspaceEntities();
|
358 |
for (OnlineEntity localEntity : localEntities) {
|
359 |
if(isCancelled()){
|
360 |
return;
|
361 |
} |
362 |
// if (StringUtils.isBlank(localEntity.getRepositoryRevisionCode())) { //Es entidad local nueva
|
363 |
// if (!this.viewFilter.test(localEntity)) {
|
364 |
// continue;
|
365 |
// }
|
366 |
// LabeledValue entry;
|
367 |
// String s = OnlineSwingCommons.getHTMLColorTag(
|
368 |
// localEntity.getState(),
|
369 |
// this.getLabelOfEntity(localEntity)
|
370 |
// );
|
371 |
// entry = new LabeledValueImpl(s, localEntity);
|
372 |
// entities.add(entry);
|
373 |
// }
|
374 |
} |
375 |
|
376 |
Collections.sort(entities, (LabeledValue<OnlineEntity> o1, LabeledValue<OnlineEntity> o2) -> StringUtils.compareIgnoreCase(
|
377 |
o1.getValue().getLabelOrName(), |
378 |
o2.getValue().getLabelOrName() |
379 |
)); |
380 |
if(!isCancelled()){
|
381 |
postReloadTables(entities); |
382 |
} |
383 |
|
384 |
} catch (Exception e) { |
385 |
LOGGER.warn("_Cant_retrieve_entities_from_repository", e);
|
386 |
if (!isCancelled()) {
|
387 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
388 |
dialogs.messageDialog( |
389 |
i18n.getTranslation("_Cant_retrieve_entities_from_repository") + "\n" + e.getMessage(), |
390 |
i18n.getTranslation("_VCS_Checkout"),
|
391 |
JOptionPane.WARNING_MESSAGE
|
392 |
); |
393 |
} |
394 |
} finally {
|
395 |
if (!isCancelled()) {
|
396 |
this.processing = false; |
397 |
this.doUpdateComponents();
|
398 |
fireActionEvent(new ActionEvent(this, ACTION_END_PROCESSING_ID, ACTION_END_PROCESSING)); |
399 |
} |
400 |
} |
401 |
|
402 |
} |
403 |
|
404 |
private void postReloadTables(List<LabeledValue<OnlineEntity>> entities ) { |
405 |
if( notInSwingThreadInvokeLater(() -> { postReloadTables(entities); }) ) {
|
406 |
return;
|
407 |
} |
408 |
this.entities = new ArrayList<>(); |
409 |
FilteredListModel model = this.filteredList.getModel();
|
410 |
Set<String> checkeds = new HashSet<>(); |
411 |
ListSelectionModel checkedModel = null; |
412 |
if(lstTablesWithCheckbox != null) { |
413 |
checkedModel = lstTablesWithCheckbox.getCheckedModel(); |
414 |
for(int i = 0; i<model.getSize(); i++){ |
415 |
if(checkedModel.isSelectedIndex(i)){
|
416 |
checkeds.add(((OnlineEntity) (model.getElementAt(i).getValue())).getEntityCode()); |
417 |
} |
418 |
} |
419 |
checkedModel.clearSelection(); |
420 |
} |
421 |
model.clear(); |
422 |
this.lstTables.getSelectionModel().clearSelection();
|
423 |
for (LabeledValue<OnlineEntity> entity : entities) {
|
424 |
if(entity != null){ |
425 |
this.entities.add(entity.getValue());
|
426 |
model.addElement(entity); |
427 |
} |
428 |
} |
429 |
|
430 |
if(checkedModel != null) { |
431 |
for(int i = 0; i<model.getSize(); i++){ |
432 |
OnlineEntity entity = (OnlineEntity) (model.getElementAt(i).getValue()); |
433 |
if(checkeds.contains(entity.getEntityCode())){
|
434 |
checkedModel.addSelectionInterval(i, i); |
435 |
} |
436 |
} |
437 |
} |
438 |
|
439 |
this.processing = false; |
440 |
fireActionEvent(new ActionEvent(this, ACTION_RELOAD_ID, ACTION_RELOAD)); |
441 |
} |
442 |
|
443 |
@Override
|
444 |
public Collection<OnlineEntity> getEntities() { |
445 |
return this.entities; |
446 |
} |
447 |
|
448 |
|
449 |
private void doUpdateComponents() { |
450 |
if( notInSwingThreadInvokeLater(this::doUpdateComponents) ) { |
451 |
return;
|
452 |
} |
453 |
this.txtFilter.setEnabled(enabled && !processing);
|
454 |
this.btnTable.setEnabled(enabled && !processing);
|
455 |
this.lstTables.setEnabled(enabled && !processing);
|
456 |
} |
457 |
|
458 |
@Override
|
459 |
public void setEnabled(boolean enabled) { |
460 |
this.enabled = enabled;
|
461 |
doUpdateComponents(); |
462 |
} |
463 |
|
464 |
@Override
|
465 |
public boolean isEnabled() { |
466 |
return enabled;
|
467 |
} |
468 |
|
469 |
@Override
|
470 |
public void setChecksEnabled(boolean enabled) { |
471 |
if(enabled){
|
472 |
lstTablesWithCheckbox = ToolsSwingLocator.getToolsSwingManager().createJListWithCheckbox(lstTables); |
473 |
lstTablesWithCheckbox.getCheckedModel().addListSelectionListener((ListSelectionEvent e) -> {
|
474 |
if( e.getValueIsAdjusting() ) {
|
475 |
return;
|
476 |
} |
477 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
478 |
}); |
479 |
} else {
|
480 |
lstTablesWithCheckbox = null;
|
481 |
} |
482 |
} |
483 |
|
484 |
@Override
|
485 |
public boolean isChecksEnabled() { |
486 |
return lstTablesWithCheckbox != null; |
487 |
} |
488 |
|
489 |
@Override
|
490 |
public void addActionListener(ActionListener al) { |
491 |
this.actionListeners.addActionListener(al);
|
492 |
} |
493 |
|
494 |
@Override
|
495 |
public ActionListener[] getActionListeners() { |
496 |
return this.actionListeners.getActionListeners(); |
497 |
} |
498 |
|
499 |
@Override
|
500 |
public void removeActionListener(ActionListener al) { |
501 |
this.actionListeners.removeActionListener(al);
|
502 |
} |
503 |
|
504 |
@Override
|
505 |
public void removeAllActionListener() { |
506 |
this.actionListeners.removeAllActionListener();
|
507 |
} |
508 |
|
509 |
@Override
|
510 |
public void fireActionEvent(ActionEvent ae) { |
511 |
this.actionListeners.fireActionEvent(ae);
|
512 |
} |
513 |
|
514 |
@Override
|
515 |
public boolean hasActionListeners() { |
516 |
return this.actionListeners.hasActionListeners(); |
517 |
} |
518 |
|
519 |
@Override
|
520 |
public void addChangeListener(ChangeListener cl) { |
521 |
this.changeListeners.addChangeListener(cl);
|
522 |
} |
523 |
|
524 |
@Override
|
525 |
public ChangeListener[] getChangeListeners() { |
526 |
return this.changeListeners.getChangeListeners(); |
527 |
} |
528 |
|
529 |
@Override
|
530 |
public void removeChangeListener(ChangeListener cl) { |
531 |
this.changeListeners.removeChangeListener(cl);
|
532 |
} |
533 |
|
534 |
@Override
|
535 |
public void removeAllChangeListener() { |
536 |
this.changeListeners.removeAllChangeListener();
|
537 |
} |
538 |
|
539 |
@Override
|
540 |
public boolean hasChangeListeners() { |
541 |
return this.changeListeners.hasChangeListeners(); |
542 |
} |
543 |
|
544 |
@Override
|
545 |
public void setViewFilter(Predicate<OnlineEntity> viewFilter) { |
546 |
this.viewFilter = viewFilter;
|
547 |
reloadEntities(false);
|
548 |
// OnlineWorkingcopy ws = getWorkspace();
|
549 |
// if (ws != null) {
|
550 |
// Thread task = new Thread(() -> {reloadTables(this.workspace);}, "VCSGisEntitySelectorListReloadEntities");
|
551 |
// task.start();
|
552 |
// }
|
553 |
} |
554 |
|
555 |
@Override
|
556 |
public void setFilter(Predicate<OnlineEntity> filter) { |
557 |
this.filter = filter;
|
558 |
reloadEntities(false);
|
559 |
// OnlineWorkingcopy ws = getWorkspace();
|
560 |
// if (ws != null) {
|
561 |
// reloadTables(getWorkspace());
|
562 |
// }
|
563 |
} |
564 |
|
565 |
@Override
|
566 |
public void check(OnlineEntity entity) { |
567 |
if (lstTablesWithCheckbox != null && entity != null) { |
568 |
ListModel model = this.filteredList.getModel(); |
569 |
for (int i = 0; i < model.getSize(); i++) { |
570 |
LabeledValueImpl element = (LabeledValueImpl) model.getElementAt(i); |
571 |
OnlineEntity ent = (OnlineEntity) element.getValue(); |
572 |
if (StringUtils.equalsIgnoreCase(
|
573 |
ent.getEntityCode(), |
574 |
entity.getEntityCode() |
575 |
)) { |
576 |
lstTablesWithCheckbox.getCheckedModel().addSelectionInterval(i, i); |
577 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
578 |
return;
|
579 |
} |
580 |
} |
581 |
} |
582 |
} |
583 |
|
584 |
@Override
|
585 |
public void unCheck(OnlineEntity entity) { |
586 |
if (lstTablesWithCheckbox != null && entity != null) { |
587 |
ListModel model = this.filteredList.getModel(); |
588 |
for (int i = 0; i < model.getSize(); i++) { |
589 |
LabeledValueImpl element = (LabeledValueImpl) model.getElementAt(i); |
590 |
OnlineEntity ent = (OnlineEntity) element.getValue(); |
591 |
if (StringUtils.equalsIgnoreCase(
|
592 |
ent.getEntityCode(), |
593 |
entity.getEntityCode() |
594 |
)) { |
595 |
lstTablesWithCheckbox.getCheckedModel().removeSelectionInterval(i, i); |
596 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
597 |
return;
|
598 |
} |
599 |
} |
600 |
} |
601 |
} |
602 |
|
603 |
@Override
|
604 |
public void clearChecks() { |
605 |
if(lstTablesWithCheckbox != null){ |
606 |
lstTablesWithCheckbox.getCheckedModel().clearSelection(); |
607 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
608 |
} |
609 |
} |
610 |
|
611 |
@Override
|
612 |
public void checkAll() { |
613 |
lstTablesWithCheckbox.getCheckedModel().setSelectionInterval(0, lstTablesWithCheckbox.getModel().getSize());
|
614 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
615 |
|
616 |
} |
617 |
|
618 |
public void setCheck(Collection<String> entityCodes, boolean check) { |
619 |
if (lstTablesWithCheckbox != null && !CollectionUtils.isEmpty(entityCodes)) { |
620 |
ListModel model = this.filteredList.getModel(); |
621 |
ListSelectionModel checkedModel = lstTablesWithCheckbox.getCheckedModel();
|
622 |
for (int i = 0; i < model.getSize(); i++) { |
623 |
LabeledValueImpl element = (LabeledValueImpl) model.getElementAt(i); |
624 |
OnlineEntity ent = (OnlineEntity) element.getValue(); |
625 |
if( entityCodes.contains(ent.getEntityCode())) {
|
626 |
if( check ) {
|
627 |
checkedModel.addSelectionInterval(i, i); |
628 |
} else {
|
629 |
checkedModel.removeSelectionInterval(i, i); |
630 |
} |
631 |
} |
632 |
} |
633 |
fireActionEvent(new ActionEvent(this, ACTION_CHECK_ID, ACTION_CHECK)); |
634 |
} |
635 |
} |
636 |
|
637 |
@Override
|
638 |
public void clear() { |
639 |
this.setWorkspace(null); |
640 |
} |
641 |
|
642 |
@Override
|
643 |
protected void doDispose() throws BaseException { |
644 |
DisposeUtils.disposeQuietly(this.workspace);
|
645 |
} |
646 |
|
647 |
private String getLabelOfEntity(OnlineEntity entity) { |
648 |
if( this.labelEntityFormatter==null ) { |
649 |
return workspace.formatEntityLabel(entity);
|
650 |
// return entity.getLabelOrName();
|
651 |
} |
652 |
return this.labelEntityFormatter.apply(entity); |
653 |
} |
654 |
|
655 |
public void setLabelEntityFormatter(Function<OnlineEntity,String> formatter) { |
656 |
this.labelEntityFormatter = formatter;
|
657 |
} |
658 |
|
659 |
@Override
|
660 |
public String getCategory(OnlineEntity entity) { |
661 |
String category = entity.getFirstCategory();
|
662 |
return category;
|
663 |
} |
664 |
|
665 |
@Override
|
666 |
public void collapseAll() { |
667 |
} |
668 |
|
669 |
@Override
|
670 |
public void expandAll() { |
671 |
} |
672 |
} |