Statistics
| Revision:

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 / changes / OnlineJChangesImpl.java @ 9512

History | View | Annotate | Download (27.6 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.changes;
24

    
25
import java.awt.Color;
26
import java.awt.Cursor;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.event.ComponentAdapter;
30
import java.awt.event.ComponentEvent;
31
import java.sql.Timestamp;
32
import java.util.ArrayList;
33
import java.util.Collection;
34
import java.util.Collections;
35
import java.util.HashSet;
36
import java.util.List;
37
import java.util.Map;
38
import java.util.Set;
39
import javax.swing.DefaultComboBoxModel;
40
import javax.swing.ImageIcon;
41
import javax.swing.JComponent;
42
import javax.swing.JSplitPane;
43
import javax.swing.SwingUtilities;
44
import javax.swing.Timer;
45
import javax.swing.event.ChangeEvent;
46
import org.apache.commons.lang3.StringUtils;
47
import org.gvsig.fmap.dal.feature.FeatureStore;
48
import org.gvsig.fmap.geom.primitive.Envelope;
49
import org.gvsig.fmap.mapcontrol.MapControl;
50
import org.gvsig.online.lib.api.OnlineLayer;
51
import org.gvsig.online.lib.api.OnlineManager;
52
import org.gvsig.online.lib.api.OnlineProject;
53
import org.gvsig.online.lib.api.OnlineRuntimeException;
54
import org.gvsig.online.lib.api.workingcopy.OnlineEntity;
55
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy;
56
import org.gvsig.online.lib.api.workingcopy.WorkingArea;
57
import org.gvsig.online.swing.api.OnlineEntitySelectorController;
58
import org.gvsig.online.swing.api.OnlineJChanges;
59
import org.gvsig.online.swing.api.OnlineSwingLocator;
60
import org.gvsig.online.swing.api.OnlineSwingManager;
61
import org.gvsig.online.swing.api.OnlineSwingServices;
62
import org.gvsig.online.swing.impl.OnlineSwingCommons;
63
import static org.gvsig.online.swing.impl.OnlineSwingCommons.notInSwingThreadInvokeLater;
64
import static org.gvsig.online.swing.impl.OnlineSwingCommons.showAuthenticationErrors;
65
import org.gvsig.online.swing.impl.OnlineSwingLibraryImpl;
66
import org.gvsig.online.swing.impl.OnlineSwingManagerImpl;
67
import static org.gvsig.online.swing.impl.OnlineSwingManagerImpl.ICON_GROUP_NAME;
68
import static org.gvsig.online.swing.impl.OnlineSwingManagerImpl.ICON_PROVIDER_NAME;
69
import org.gvsig.online.swing.impl.workingarea.WorkingAreaPickerControllerImpl;
70
import org.gvsig.tools.ToolsLocator;
71
import org.gvsig.tools.dispose.DisposeUtils;
72
import org.gvsig.tools.i18n.I18nManager;
73
import org.gvsig.tools.swing.api.ToolsSwingLocator;
74
import org.gvsig.tools.swing.api.ToolsSwingManager;
75
import org.gvsig.tools.swing.api.ToolsSwingUtils;
76
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
77
import org.gvsig.tools.swing.api.task.TaskStatusController;
78
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager;
79
import org.gvsig.tools.swing.api.windowmanager.Dialog;
80
import org.gvsig.tools.task.SimpleTaskStatus;
81
import org.gvsig.tools.util.LabeledValue;
82
import org.gvsig.tools.util.LabeledValueImpl;
83
import org.gvsig.tools.util.PropertiesSupport;
84
import org.gvsig.tools.util.PropertiesSupportHelper;
85
import org.slf4j.Logger;
86
import org.slf4j.LoggerFactory;
87

    
88
/**
89
 *
90
 * @author gvSIG Team
91
 */
92
@SuppressWarnings("UseSpecificCatch")
93
public class OnlineJChangesImpl 
94
        extends OnlineJChangesView 
95
        implements OnlineJChanges, PropertiesSupport
96
    {
97
    
98
    private static final Logger LOGGER = LoggerFactory.getLogger(OnlineJChangesImpl.class);
99

    
100
    private static final int ZONE_ONLY_CHANGES = 0;
101
    private static final int ZONE_CHANGES_AND_WORKING_AREA = 1;
102
    
103
    public static final int NOTCLOSABLE = 64;
104
    public static final int RESIZABLE = 1;
105
    public static final int MAXIMIZABLE = 2;
106
    public static final int ICONIFIABLE = 4;
107
    
108
    public static final int LOCAL_TAB_INDEX = 0;
109
    public static final int REMOTE_TAB_INDEX = 1;
110

    
111
    private PickerController<OnlineWorkingcopy> workspacePicker;
112
    private LocalChangesController localChangesController;
113
    private RemoteChangesController remoteChangesController;
114
//    private final List<VCSGisWorkspaceEntity> workspaceEntities = null;
115
//    private final List<OnlineEntity> repositoryEntities = null;
116
    private boolean entitiesUpdateds;
117
    private OnlineWorkingcopy currentWorkingcopy;
118
    private TaskStatusController taskStatusController;
119
    private Timer timerClearMsg;
120
    /* friend */ boolean processing;
121
    private JSplitPane splChanges;
122
    private SimpleTaskStatus taskStatus;
123
    private PropertiesSupportHelper propertiesSupport;
124
    private List<String> defaultTablesSelection;
125
    private OnlineEntitySelectorController entitySelector;
126
    private WorkingAreaPickerControllerImpl workingAreaPicker;
127
    
128
    public OnlineJChangesImpl() {
129
        this(null,null,null, null);
130
    }        
131
        
132
    public OnlineJChangesImpl(OnlineWorkingcopy workspace, List<String> tableNames, Timestamp efectivedate, String comment) {
133
        if( tableNames==null ) {
134
            this.defaultTablesSelection = Collections.EMPTY_LIST;
135
        } else {
136
            this.defaultTablesSelection = tableNames;
137
        }
138
        this.processing = false;
139
        this.propertiesSupport = new PropertiesSupportHelper();
140
        this.propertiesSupport.setProperty("WindowInfo.Flags", NOTCLOSABLE|RESIZABLE|MAXIMIZABLE|ICONIFIABLE);
141
        initComponents();
142
        SwingUtilities.invokeLater(() -> {
143
            this.workspacePicker.set(workspace);
144
        });
145
    }
146

    
147
    public List<String> getDefaultTablesSelection() {
148
        return this.defaultTablesSelection;
149
    }
150
    
151
    @Override
152
    public JComponent asJComponent() {
153
        return this;
154
    }
155

    
156
    @Override
157
    public ImageIcon loadImage(String imageName) {
158
        return OnlineSwingManagerImpl.loadImage(imageName);
159
    }
160
    
161
    private void translate() {
162
        ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
163
        swingManager.translate(this.lblWorkspace);
164
        swingManager.translate(this.btnWorkspace);
165
        swingManager.translate(this.btnClose);
166

    
167
        swingManager.translate(this.tabLocalAndRemote);
168
        swingManager.translate(this.btnSynchronize);
169

    
170
        swingManager.translate(this.btnLocalCheckRecomendedEntities);
171
        swingManager.translate(this.btnLocalCheckAllEntities);
172
        swingManager.translate(this.btnLocalUnCheckAllEntities);
173
        swingManager.translate(this.btnLocalCollapseAllEntities);
174
        swingManager.translate(this.btnLocalExpandAllEntities);
175
        swingManager.translate(this.btnEntitiesReload);
176
        
177
        swingManager.translate(this.lblSynchorizationZone);
178
        swingManager.translate(this.cboSynchorizationZone);
179
        
180
    }
181

    
182
    private void initComponents() {
183
        OnlineSwingManager onlineSwingManager = OnlineSwingLocator.getOnlineSwingManager();
184
        TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager();
185
        OnlineSwingServices onlineservices = OnlineSwingLocator.getOnlineSwingManager().getDefaultServices();
186
        
187
        this.addComponentListener(new ComponentAdapter() {
188
            @Override
189
            public void componentHidden(ComponentEvent e) {
190
                dispose();
191
            }
192
            
193
        });
194
        
195
        this.splChanges = ToolsSwingUtils.createHorizontalSplit(
196
                this.gridChanges, 
197
                this.gridWorkingCopyList, false, 
198
                this.gridTabs, false
199
        );
200
        this.splChanges.setDividerLocation(ToolsSwingUtils.cols2px(45));
201
        
202
        this.timerClearMsg = new Timer(20000, (ActionEvent e) -> {
203
//            getTaskStatusController().message("");
204
            this.lblStatusMessages.setText("");
205
        });
206
        this.timerClearMsg.setRepeats(false);
207
        
208
        translate();
209

    
210
        this.taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("");
211
        this.taskStatusController = taskStatusManager.createTaskStatusController(
212
                this.lblStatusCaption, 
213
                this.lblStatusMessages, 
214
                this.pbStatus
215
        );
216
        this.taskStatusController.setShowCancelButton(false);
217
        this.taskStatusController.setShowRemoveTaskButton(false);
218
        this.taskStatusController.bind(this.taskStatus);
219
        SwingUtilities.invokeLater(() -> {this.setVisibleStatus(false); });
220
        
221
        
222
        this.workspacePicker = onlineSwingManager.createPickerWorkspaceController(
223
                this.cboWorkspace//,
224
//                this.btnWorkspace
225
        );
226
        
227
        this.workspacePicker.addChangeListener((ChangeEvent e) -> {
228
            doChangeWorkspace();
229
        });
230
        
231
        this.btnLocalCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
232
        this.btnLocalUnCheckAllEntities.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
233
        
234
        this.btnLocalCheckAllEntities.addActionListener((ActionEvent e) -> {
235
            this.entitySelector.checkAll();
236
        });
237

    
238
        this.btnLocalUnCheckAllEntities.addActionListener((ActionEvent e) -> {
239
            this.entitySelector.clearChecks();
240
        });
241
        this.btnLocalCollapseAllEntities.addActionListener((ActionEvent e) -> {
242
            this.entitySelector.collapseAll();
243
        });
244
        this.btnLocalExpandAllEntities.addActionListener((ActionEvent e) -> {
245
            this.entitySelector.expandAll();
246
        });
247
        
248
        this.entitySelector = onlineSwingManager.createEntitySelectorController(
249
                this.treeLocalTables, 
250
                txtLocalTablesFilter, 
251
                btnLocalTable
252
        );
253
        this.entitySelector.setViewFilter(OnlineEntitySelectorController.LOCAL_ENTITIES);
254
        this.entitySelector.setFilter(OnlineEntitySelectorController.LOCAL_ENTITIES);
255
        this.entitySelector.setChecksEnabled(true);
256
        this.entitySelector.addChangeListener((ChangeEvent e) -> {
257
            localChangesController.doUpdateTableLocalChanges();
258
        });
259
        this.entitySelector.addActionListener((ActionEvent e) -> {
260
            switch(e.getID()) {
261
                case OnlineEntitySelectorController.ACTION_SELECT_ID:
262
                    doUpdateComponents();
263
                    break;
264
                case OnlineEntitySelectorController.ACTION_CHECK_ID:
265
                    localChangesController.doUpdateTableLocalChanges();
266
                    remoteChangesController.doReloadChanges();
267
                    doUpdateComponents();
268
                    break;
269
                case OnlineEntitySelectorController.ACTION_RELOAD_ID:
270
                    localChangesController.doUpdateTableLocalChanges();
271
                    remoteChangesController.doReloadChanges();
272
                    doUpdateComponents();
273
                    break;
274
            }
275
        });
276

    
277
        this.workingAreaPicker = new WorkingAreaPickerControllerImpl(
278
            () -> {return getWorkspace().getSite();},
279
            txtWorkingAreaLabel,
280
            txtWorkingArea,
281
            btnWorkingAreaFromView,
282
            btnWorkingAreaDialog,
283
            btnWorkingAreaHistory,
284
            btnWorkingAreaBookmarks,
285
            () -> {
286
                LabeledValue<MapControl> n = onlineservices.getActiveMapControl();
287
                return (n == null) ? null : n.getValue();
288
            },
289
            () -> {
290
                List<OnlineLayer> selectedLayers = getSelectedLayers();
291
                if (selectedLayers.isEmpty()) {
292
                    return null;
293
                }
294
                return selectedLayers;
295
            }
296
        );
297
        this.workingAreaPicker.addChangeListener((ChangeEvent e) -> {
298
            doUpdateComponents();
299
        });
300
        
301
        I18nManager i18n = ToolsLocator.getI18nManager();
302
        DefaultComboBoxModel<LabeledValue<Integer>> zoneModel = new DefaultComboBoxModel<>();
303
        zoneModel.addElement(new LabeledValueImpl<>(i18n.getTranslation("_Only_changes_zone"), ZONE_ONLY_CHANGES));
304
        zoneModel.addElement(new LabeledValueImpl<>(i18n.getTranslation("_Changes_zone_and_working_area"), ZONE_CHANGES_AND_WORKING_AREA));
305
        this.cboSynchorizationZone.setModel(zoneModel);
306
        this.cboSynchorizationZone.addActionListener(new ActionListener() {
307
            @Override
308
            public void actionPerformed(ActionEvent e) {
309
                doUpdateComponents();
310
            }
311
        });
312
        this.cboSynchorizationZone.setSelectedIndex(0);
313

    
314
        this.localChangesController = new LocalChangesController(
315
            this,
316
            this.workspacePicker,
317
            this.tblLocalChanges,
318
            this.btnLocalCheckAll,
319
            this.btnLocalUnCheckAll,
320
            this.btnLocalShowForm,
321
            this.btnLocalRefresh,
322
            this.btnLocalCommit,
323
            this.btnLocalRevert,
324
            this.btnLocalZoom,
325
            this.btnLocalCenter,
326
            this.btnLocalHighlight,
327
            this.btnLocalCleanHighligthed,
328
            this.lblLocalChangesCount,
329
            this.txtLocalTablesFilter,
330
            this.btnLocalTable
331
        );
332
        
333
        this.remoteChangesController = new RemoteChangesController(
334
            this,
335
            this.workspacePicker,
336
            this.tblRemoteChanges,
337
            this.btnRemoteCheckAll,
338
            this.btnRemoteUncheckAll,
339
            this.btnRemoteReloadChanges,
340
            this.btnRemoteCleanChanges,
341
            this.btnRemoteUpdate,
342
            this.btnRemoteMerge,
343
            this.btnRemoteShowForm,
344
            this.btnRemoteZoom,
345
            this.btnRemoteCenter,
346
            this.btnRemoteHighlight,
347
            this.btnRemoteCleanHighligthed,
348
            this.lblRemoteChangesCount
349
        );
350
        this.btnClose.addActionListener((ActionEvent e) -> {
351
            if( this.processing ) {
352
                return;
353
            }
354
            this.setVisible(false);
355
        });
356
        
357
        this.btnLocalCheckRecomendedEntities.addActionListener((ActionEvent e) -> {
358
            doCheckRecomendedEntities();
359
        });
360

    
361
        this.btnEntitiesReload.addActionListener((ActionEvent e) -> {
362
            doReloadTables();
363
//            remoteChangesController.doReloadChanges();
364
        });
365

    
366
        this.btnSynchronize.addActionListener((ActionEvent e) -> {
367
            doSynchronize();
368
        });
369

    
370
        ToolsSwingUtils.ensureRowsCols(this, 14, 100);
371
    }
372
    
373
    private List<OnlineLayer> getSelectedLayers(){
374
        List<OnlineEntity> entities = this.getEntitySelector().getCheckedEntities();
375
        OnlineProject project = this.getWorkspace().getProject();
376
        List<OnlineLayer> result = new ArrayList<>();
377
        for (OnlineEntity entity : entities) {
378
            OnlineLayer layer = project.getLayer(
379
                (OnlineLayer t) -> StringUtils.equalsIgnoreCase(t.getName(), entity.getEntityName()),
380
                null
381
            );
382
            result.add(layer);
383
        }
384
        return result;
385
    }
386

    
387
    /* friend */ void doUpdateComponents() {
388
        if( notInSwingThreadInvokeLater(() -> {doUpdateComponents();}) ) {
389
            return;
390
        }
391
        if(this.localChangesController != null){
392
            this.localChangesController.doUpdateComponents();
393
        }
394
        if(this.remoteChangesController != null){
395
            this.remoteChangesController.doUpdateComponents();
396
        }
397
        OnlineWorkingcopy ws = this.getWorkspace();
398
        if(ws == null) {
399
            this.cboSynchorizationZone.setEnabled(false);
400
            this.workingAreaPicker.setEnabled(false);
401
            this.btnSynchronize.setEnabled(false);
402
            this.btnEntitiesReload.setEnabled(false);
403
            return;
404
        }
405
        LabeledValue<Integer> zoneMode = (LabeledValue<Integer>) this.cboSynchorizationZone.getSelectedItem();
406
        if(zoneMode == null) {
407
            this.cboSynchorizationZone.setEnabled(false);
408
            this.workingAreaPicker.setEnabled(false);
409
            this.btnSynchronize.setEnabled(false);
410
            this.btnEntitiesReload.setEnabled(false);
411
            return;
412
        }
413
        this.cboSynchorizationZone.setEnabled(true);
414
        this.btnSynchronize.setEnabled(true);
415
        this.btnEntitiesReload.setEnabled(true);
416
        switch (zoneMode.getValue()) {
417
            case ZONE_CHANGES_AND_WORKING_AREA:
418
                this.workingAreaPicker.setEnabled(true);
419
                break;
420
            case ZONE_ONLY_CHANGES:
421
            default:
422
                this.workingAreaPicker.setEnabled(false);
423
                break;
424
        }
425
    }
426
    
427
    public void updateLocalChangesTable() {
428
        if( notInSwingThreadInvokeLater(() -> {updateLocalChangesTable();}) ) {
429
            return;
430
        }
431
        this.entitySelector.reloadEntities();
432
//        this.localChangesController.doReloadTables();
433
    }
434

    
435
    public OnlineWorkingcopy getWorkspace() {
436
        OnlineWorkingcopy ws = this.workspacePicker.get();
437
        return ws;
438
    }
439
    
440
    private OnlineWorkingcopy getUndisposableWorkspace() {
441
        OnlineWorkingcopy ws = this.workspacePicker.get();
442
        DisposeUtils.disposeQuietly(ws);
443
        LOGGER.info("ws.references = " + DisposeUtils.getReferences(ws));
444
        return ws;
445
    }
446

    
447
    
448
    private void doChangeWorkspace() {
449
        OnlineWorkingcopy ws = null;
450
        try {
451
            ws = this.getWorkspace();
452
            this.entitySelector.setWorkspace(ws);
453
            if (ws != null) {
454
                for (String tableName : this.getDefaultTablesSelection()) {
455
                    OnlineEntity entity = ws.getWorkspaceEntity(tableName);
456
                    if (entity != null) {
457
                        this.entitySelector.check(entity);
458
                    }
459
                }
460
            } else {
461
                this.remoteChangesController.doReloadChanges();//.doChangeWorkspace();
462
            }
463

    
464
//            if(ws.isOffline() || ws.authenticate(null)) {
465
//                this.localChangesController.doChangeWorkspace();
466
                this.remoteChangesController.doReloadChanges();//.doChangeWorkspace();
467
//                return;
468
//            }
469
//            showAuthenticationRequiredMessage("_Online_Changes");
470
//            this.workspacePicker.set(null);
471
//            doChangeWorkspace();
472
            this.workingAreaPicker.set(ws.getCurrentWorkingArea());
473
        } catch (OnlineRuntimeException e1) {
474
            LOGGER.warn("Can't set workspace.", e1);
475
            if (showAuthenticationErrors("_Online_Changes", e1)) {
476
                this.workspacePicker.set(null);
477
                doChangeWorkspace();
478
            }
479
        } catch (Exception e2) {
480
            LOGGER.warn("Can't set workspace.", e2);
481
        } finally {
482
            DisposeUtils.disposeQuietly(ws);
483
        }
484
    }
485

    
486
    public void doReloadTables() {
487
        OnlineWorkingcopy ws = this.getUndisposableWorkspace();
488
        if (ws == null) {
489
            this.entitySelector.setWorkspace(null);
490
            return;
491
        }
492
        this.entitySelector.reloadEntities();
493
//        context.doUpdateComponents();
494
    }
495
    
496
    private void doSynchronize() {
497
        OnlineWorkingcopy ws = this.getUndisposableWorkspace();
498
        if (ws == null) {
499
            this.entitySelector.setWorkspace(null);
500
            return;
501
        }
502
        LabeledValue<Integer> zoneMode = (LabeledValue<Integer>) this.cboSynchorizationZone.getSelectedItem();
503
        int zone = ZONE_ONLY_CHANGES;
504
        if(zoneMode != null){
505
            zone = zoneMode.getValue();
506
        }
507
        WorkingArea workingArea = this.workingAreaPicker.get();
508
        Envelope env = null;
509
        switch(zone){
510
            case ZONE_CHANGES_AND_WORKING_AREA:
511
                if(workingArea != null) {
512
                    env = workingArea.getValue();
513
                }
514
                break;
515
            case ZONE_ONLY_CHANGES:
516
            default:
517
                break;
518
        }
519
        
520
        List<OnlineEntity> checkedEntities = this.entitySelector.getCheckedEntities();
521
        for (OnlineEntity checkedEntity : checkedEntities) {
522
            ws.synchronize(checkedEntity, env, this.taskStatus);
523
        }
524

    
525
        doReloadTables();
526
        localChangesController.doUpdateTableLocalChanges();
527
        remoteChangesController.doReloadChanges();
528
        remoteChangesController.doUpdateComponents();
529
        
530
    }
531
    
532
    
533
    public void updateEntitiesFromRepository(boolean forceUpdateEntities) {
534
        OnlineWorkingcopy ws = null;
535
        try {
536
            ws = this.getWorkspace();
537
            if( ws == null ) {
538
                return;
539
            }
540
            if( !forceUpdateEntities && this.currentWorkingcopy==ws && this.entitiesUpdateds ) {
541
                return;
542
            }
543
            setVisibleStatus(true);
544
//            ws.updateEntitiesFromRepository();
545
            this.currentWorkingcopy = ws;
546
            this.entitiesUpdateds = true;
547
            setVisibleStatus(false);
548
        } finally {
549
            DisposeUtils.disposeQuietly(ws);
550
        }
551
    }
552
    
553

    
554
    public void alert(String msg) {
555
        if( StringUtils.startsWith(msg, "_") ) {
556
            I18nManager i18n = ToolsLocator.getI18nManager();
557
            msg = i18n.getTranslation(msg);
558
        }
559
        message(OnlineSwingCommons.getHTMLColorTag(Color.red.darker(), msg));
560
    }
561
    
562
    public void message(final String msg) {
563
        if( notInSwingThreadInvokeLater(() -> {message(msg);})) {
564
            return;
565
        }
566
        String message = msg;
567
        this.timerClearMsg.stop();
568
        if( StringUtils.startsWith(message, "_") ) {
569
            I18nManager i18n = ToolsLocator.getI18nManager();
570
            message = i18n.getTranslation(message);
571
        }
572
//        this.getTaskStatusController().message(message);
573
        this.lblStatusMessages.setVisible(true);
574
        this.lblStatusMessages.setText(message);
575
        this.timerClearMsg.start();
576
    }
577

    
578
    public void setVisibleStatus(boolean visible) {
579
        if( notInSwingThreadInvokeLater(() -> {setVisibleStatus(visible);}) ) {
580
            return;
581
        }
582
        this.lblStatusCaption.setVisible(visible);
583
        this.pbStatus.setVisible(visible);
584
        this.lblStatusMessages.setVisible(true);
585
    }
586
    
587
    public TaskStatusController getTaskStatusController() {
588
        return this.taskStatusController;
589
    }
590

    
591
    public static void selfRegister() {
592
        
593
        ToolsSwingUtils.registerIcons(
594
                OnlineSwingLibraryImpl.class, 
595
                "/org/gvsig/vcsgis/swing/impl/images",
596
                ICON_PROVIDER_NAME,
597
                new String[]{ ICON_GROUP_NAME, "vcsgis-commit-all", "vcsgis-changes"},
598
                new String[]{ ICON_GROUP_NAME, "vcsgis-revert", "vcsgis-changes"},
599
                new String[]{ ICON_GROUP_NAME, "vcsgis-topology-plan", "vcsgis-changes"},
600
                new String[]{ ICON_GROUP_NAME, "vcsgis-show-local-changes", "vcsgis-changes"},
601
                new String[]{ ICON_GROUP_NAME, "vcsgis-checkout-overwrite", "vcsgis-changes"},
602
                
603
                new String[]{ ICON_GROUP_NAME, "vcsgis-remotechanges-clear", "vcsgis-changes"},
604
                new String[]{ ICON_GROUP_NAME, "vcsgis-remotechanges-download", "vcsgis-changes"},
605
                new String[]{ ICON_GROUP_NAME, "vcsgis-remotechanges-reload", "vcsgis-changes"},
606
                new String[]{ ICON_GROUP_NAME, "vcsgis-highlight-context", "vcsgis-changes"},
607
                
608
                new String[]{ ICON_GROUP_NAME, "vcsgis-update-all", "vcsgis-changes"},
609
                new String[]{ ICON_GROUP_NAME, "vcsgis-merge", "vcsgis-changes"},
610
                new String[]{ ICON_GROUP_NAME, "vcsgis-show-remote-changes", "vcsgis-changes"},
611
                new String[]{ ICON_GROUP_NAME, "vcsgis-center-context", "vcsgis-changes"},
612
                new String[]{ ICON_GROUP_NAME, "vcsgis-zoom-context", "vcsgis-changes"},
613
                new String[]{ ICON_GROUP_NAME, "vcsgis-clean-highlighted", "vcsgis-changes"}
614
                
615
//                new String[]{ ICON_GROUP_NAME, "vcsgis-show-local-and-remote-changes"},
616
        );         
617
        ToolsSwingUtils.registerSubgroupIconScreenshot(
618
                OnlineSwingLibraryImpl.class, 
619
                "vcsgis", 
620
                "vcsgis-changes", 
621
                "/org/gvsig/vcsgis/swing/impl/screenshots/vcsgis-changes-local.png"
622
        );
623
        ToolsSwingUtils.registerSubgroupIconScreenshot(
624
                OnlineSwingLibraryImpl.class, 
625
                "vcsgis", 
626
                "vcsgis-changes", 
627
                "/org/gvsig/vcsgis/swing/impl/screenshots/vcsgis-changes-remote.png"
628
        );
629
        
630
    }
631

    
632
    @Override
633
    public boolean isProcessing() {
634
        return this.processing;
635
    }
636
    
637
    public void selectTab(int tab){
638
        this.tabLocalAndRemote.setSelectedIndex(tab);
639
    }
640
    
641
    public void selectOnlyALocalEntity(OnlineEntity selectedTable){
642
        this.localChangesController.selectOnlyAEntity(selectedTable);
643
    }
644

    
645
    public void selectOnlyALocalEntity(List<OnlineEntity> selectedTables){
646
        this.localChangesController.selectOnlyAEntity(selectedTables);
647
    }
648

    
649
    @Override
650
    public void setDialog(Dialog dialog) {
651
        // Do nothing
652
    }
653
    
654
    public void dispose() {
655
        DisposeUtils.disposeQuietly(localChangesController);
656
        DisposeUtils.disposeQuietly(remoteChangesController);
657
        DisposeUtils.disposeQuietly(currentWorkingcopy);
658
        DisposeUtils.disposeQuietly(entitySelector);
659
    }
660

    
661
    public void setTaskStatus(SimpleTaskStatus taskStatus) {
662
        this.taskStatusController.bind(taskStatus);
663
    }
664

    
665
    @Override
666
    public Object getProperty(String name) {
667
        return this.propertiesSupport.getProperty(name);
668
    }
669

    
670
    @Override
671
    public void setProperty(String name, Object value) {
672
        this.propertiesSupport.setProperty(name, value);
673
    }
674

    
675
    @Override
676
    public Map<String, Object> getProperties() {
677
        return this.propertiesSupport.getProperties();
678
    }
679

    
680
    public OnlineEntitySelectorController getEntitySelector() {
681
        return entitySelector;
682
    }
683
    
684
    private void doCheckRecomendedEntities() {
685
        final OnlineWorkingcopy workspace = this.getUndisposableWorkspace();
686
        if( workspace==null ) {
687
            return;
688
        }
689
        Set<String> updateEntities = new HashSet<>();
690
        Collection<OnlineEntity> entities = this.entitySelector.getEntities();
691
        for (OnlineEntity entity : entities) {
692
            if (workspace.existsInWorkspace(entity)) {
693
                OnlineEntity lentity = workspace.getWorkspaceEntityByCode(entity.getEntityCode());
694
                switch (lentity.getState()) {
695
                    case OnlineManager.STATE_LOCAL_MODIFIED:
696
                    case OnlineManager.STATE_LOCAL_NEW:
697
                    case OnlineManager.STATE_LOCAL_UNMODIFIED:
698
                    case OnlineManager.STATE_REMOTE_NEW:
699
                    default:
700
                        break;
701
                    case OnlineManager.STATE_CONFLICT:
702
                    case OnlineManager.STATE_LOCAL_OUTDATED:
703
                    case OnlineManager.STATE_LOCAL_OUTDATED_AND_MODIFIED:
704
                        updateEntities.add(entity.getEntityCode());
705
                        break;
706
                }
707
            }
708
        }
709
        this.entitySelector.setCheck(updateEntities, true);
710
    }
711

    
712
    protected FeatureStore getWorkspaceStoreOfSelectedEntity() {
713
        OnlineEntity entity = this.getEntitySelector().getSelectedEntity();
714
        FeatureStore store = null;
715
        
716
        if(entity != null){
717
            OnlineWorkingcopy ws = getUndisposableWorkspace();
718
            store = ws.openFeatureStore(entity.getEntityName(),false);
719
        }
720
        return store;
721
    }
722
    
723
}