Statistics
| Revision:

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 / changes / VCSGisJChangesImpl.java @ 4014

History | View | Annotate | Download (13.8 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.vcsgis.swing.impl.changes;
24

    
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ComponentAdapter;
27
import java.awt.event.ComponentEvent;
28
import java.util.List;
29
import javax.swing.ImageIcon;
30
import javax.swing.JComponent;
31
import javax.swing.JPanel;
32
import javax.swing.JSplitPane;
33
import javax.swing.SwingUtilities;
34
import javax.swing.Timer;
35
import javax.swing.event.ChangeEvent;
36
import javax.swing.event.ChangeListener;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.dispose.DisposeUtils;
39
import org.gvsig.tools.swing.api.ToolsSwingLocator;
40
import org.gvsig.tools.swing.api.ToolsSwingManager;
41
import org.gvsig.tools.swing.api.ToolsSwingUtils;
42
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
43
import org.gvsig.tools.swing.api.task.TaskStatusController;
44
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager;
45
import org.gvsig.tools.swing.api.windowmanager.Dialog;
46
import org.gvsig.vcsgis.lib.VCSGisEntity;
47
import org.gvsig.vcsgis.lib.VCSGisRuntimeException;
48
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
49
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity;
50
import org.gvsig.vcsgis.swing.VCSGisJChanges;
51
import org.gvsig.vcsgis.swing.VCSGisSwingLocator;
52
import org.gvsig.vcsgis.swing.VCSGisSwingManager;
53
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.notInSwingThreadInvokeLater;
54
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors;
55
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationRequiredMessage;
56
import org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl;
57
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_COMMON_GROUP_NAME;
58
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_GROUP_NAME;
59
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_PROVIDER_NAME;
60
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.registerIcons;
61
import org.slf4j.Logger;
62
import org.slf4j.LoggerFactory;
63

    
64
/**
65
 *
66
 * @author gvSIG Team
67
 */
68
@SuppressWarnings("UseSpecificCatch")
69
public class VCSGisJChangesImpl 
70
        extends VCSGisJChangesView 
71
        implements VCSGisJChanges
72
    {
73
    
74
    private static final Logger LOGGER = LoggerFactory.getLogger(VCSGisJChangesImpl.class);
75

    
76
    public static final int LOCAL_TAB_INDEX = 0;
77
    public static final int REMOTE_TAB_INDEX = 1;
78

    
79
    private PickerController<VCSGisWorkspace> workspacePicker;
80
    private LocalChangesController localChangesController;
81
    private RemoteChangesController remoteChangesController;
82
    private final List<VCSGisWorkspaceEntity> workspaceEntities = null;
83
    private final List<VCSGisEntity> repositoryEntities = null;
84
    private boolean entitiesUpdateds;
85
    private VCSGisWorkspace currentWorkspace;
86
    private TaskStatusController taskStatusController;
87
    private Timer timerClearMsg;
88
    /* friend */ boolean processing;
89
    private JSplitPane splWorkingCopy;
90
    private JSplitPane splRepository;
91
    
92
    
93
    public VCSGisJChangesImpl() {
94
        processing = false;
95
        initComponents();
96
    }
97

    
98
    @Override
99
    public JComponent asJComponent() {
100
        return this;
101
    }
102

    
103
    @Override
104
    public ImageIcon loadImage(String imageName) {
105
        return VCSGisSwingManagerImpl.loadImage(imageName);
106
    }
107
    
108
    private void translate() {
109
        ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
110
        swingManager.translate(this.lblWorkspace);
111
        swingManager.translate(this.btnWorkspace);
112

    
113
        swingManager.translate(this.tabLocalAndRemote);
114
    }
115

    
116
    private void initComponents() {
117
        VCSGisSwingManager vcsSwingManager = VCSGisSwingLocator.getVCSGisSwingManager();
118
        TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager();
119
        
120
        this.addComponentListener(new ComponentAdapter() {
121
            @Override
122
            public void componentHidden(ComponentEvent e) {
123
                dispose();
124
            }
125
            
126
        });
127
        
128
        this.splWorkingCopy = ToolsSwingUtils.createHorizontalSplit(
129
                this.gridWorkingCopy, 
130
                this.gridWorkingCopyList, false, 
131
                this.gridWokingCopyTable, false
132
        );
133
        this.splWorkingCopy.setDividerLocation(ToolsSwingUtils.cols2px(45));
134

    
135
        this.splRepository = ToolsSwingUtils.createHorizontalSplit(
136
                this.gridRepository, 
137
                this.gridRepositoryList, false, 
138
                this.gridRepositoryTable, false
139
        );
140
        this.splRepository.setDividerLocation(ToolsSwingUtils.cols2px(45));
141
        
142
        this.timerClearMsg = new Timer(5000, (ActionEvent e) -> {
143
            getTaskStatusController().message("");
144
        });
145
        this.timerClearMsg.setRepeats(false);
146
        
147
        translate();
148

    
149
        this.taskStatusController = taskStatusManager.createTaskStatusController(
150
                this.lblStatusCaption, 
151
                this.lblStatusMessages, 
152
                this.pbStatus
153
        );
154
        this.taskStatusController.setShowCancelButton(false);
155
        this.taskStatusController.setShowRemoveTaskButton(false);
156
        this.taskStatusController.bind(ToolsLocator.getTaskStatusManager());
157
        SwingUtilities.invokeLater(() -> {this.setVisibleStatus(false); });
158
        
159
        
160
        this.workspacePicker = vcsSwingManager.createWorkspacePickerController(
161
                this.cboWorkspace,
162
                this.btnWorkspace
163
        );
164
        
165
        this.workspacePicker.addChangeListener(new ChangeListener() {
166
            @Override
167
            public void stateChanged(ChangeEvent e) {
168
                doChangeWorkspace();
169
            }
170
        });
171
        
172

    
173
        this.localChangesController = new LocalChangesController(
174
            this,
175
            this.workspacePicker,
176
            this.btnLocalCheckAllEntities,
177
            this.btnLocalUnCheckAllEntities,
178
            this.tblLocalChanges,
179
            this.btnLocalCheckAll,
180
            this.btnLocalUnCheckAll,
181
            this.btnLocalShowForm,
182
            this.btnLocalRefresh,
183
            this.btnLocalCommit,
184
            this.btnLocalRevert,
185
            this.lblLocalEffectiveDate,
186
            this.txtLocalEffectiveDate,
187
            this.txtLocalComment,
188
            this.btnLocalEffectiveDate,
189
            this.lblLocalComment,
190
            this.btnLocalZoom,
191
            this.btnLocalCenter,
192
            this.btnLocalHighlight,
193
            this.btnLocalCleanHighligthed,
194
            this.lblLocalChangesCount,
195
            this.txtLocalTablesFilter,
196
            this.btnLocalTable,
197
            this.treeLocalTables,
198
            this.btnExecuteTopologyPlan
199
        );
200
        
201
        this.remoteChangesController = new RemoteChangesController(
202
            this,
203
                
204
            this.workspacePicker,
205

    
206
            this.treeRepositoryTables,
207
            this.txtRepositoryTablesFilter,
208
            this.btnRepositoryTablesFilter,
209
                
210
            this.btnRemoteTablesReload,
211

    
212
            this.tblRemoteChanges,
213
            this.btnRemoteCheckAll,
214
            this.btnRemoteUncheckAll,
215
            this.btnRemoteDownloadChanges,
216
            this.btnRemoteReloadChanges,
217
            this.btnRemoteCleanChanges,
218
            this.btnRemoteUpdate,
219
            this.btnRemoteMerge,
220
            this.btnRemoteShowForm,
221
            this.btnRemoteZoom,
222
            this.btnRemoteCenter,
223
            this.btnRemoteHighlight,
224
            this.btnRemoteCheckout,
225
            this.btnRemoteCleanHighligthed,
226
            this.lblRemoteChangesCount
227
        );
228
        
229
        ToolsSwingUtils.ensureRowsCols(this, 14, 100);
230
    }
231
    
232
    /* friend */ void doUpdateComponents() {
233
        if( notInSwingThreadInvokeLater(() -> {doUpdateComponents();}) ) {
234
            return;
235
        }
236
        
237
        if(this.localChangesController != null){
238
            this.localChangesController.doUpdateComponents();
239
        }
240
        if(this.remoteChangesController != null){
241
            this.remoteChangesController.doUpdateComponents();
242
        }
243
    }
244
    
245
    public void updateLocalChangesTable() {
246
        if( notInSwingThreadInvokeLater(() -> {updateLocalChangesTable();}) ) {
247
            return;
248
        }
249
        this.localChangesController.doReloadTables();
250
    }
251

    
252
    public VCSGisWorkspace getWorkspace() {
253
        VCSGisWorkspace ws = this.workspacePicker.get();
254
        return ws;
255
    }
256
    
257
    private VCSGisWorkspace getUndisposableWorkspace() {
258
        VCSGisWorkspace ws = this.workspacePicker.get();
259
        DisposeUtils.disposeQuietly(ws);
260
        LOGGER.info("ws.references = " + DisposeUtils.getReferences(ws));
261
        return ws;
262
    }
263

    
264
    
265
    private void doChangeWorkspace() {
266
        VCSGisWorkspace ws = null;
267
        try {
268
            ws = this.getWorkspace();
269
            if(ws == null) {
270
                this.localChangesController.doChangeWorkspace();
271
                this.remoteChangesController.doChangeWorkspace();
272
                return;
273
            }
274
            if(ws.authenticate(null)) {
275
                this.localChangesController.doChangeWorkspace();
276
                this.remoteChangesController.doChangeWorkspace();
277
                return;
278
            }
279
            showAuthenticationRequiredMessage("_VCS_Changes");
280
            this.workspacePicker.set(null);
281
            doChangeWorkspace();
282
        } catch (VCSGisRuntimeException e1) {
283
            LOGGER.warn("Can't set workspace.", e1);
284
            if (showAuthenticationErrors("_VCS_Changes", e1)) {
285
                this.workspacePicker.set(null);
286
                doChangeWorkspace();
287
            }
288
        } catch (Exception e2) {
289
            LOGGER.warn("Can't set workspace.", e2);
290
        } finally {
291
            DisposeUtils.disposeQuietly(ws);
292
        }
293
    }
294

    
295
    
296
    public void updateEntitiesFromRepository(boolean forceUpdateEntities) {
297
        VCSGisWorkspace ws = null;
298
        try {
299
            ws = this.getWorkspace();
300
            if( ws == null ) {
301
                return;
302
            }
303
            if( !forceUpdateEntities && this.currentWorkspace==ws && this.entitiesUpdateds ) {
304
                return;
305
            }
306
            setVisibleStatus(true);
307
            ws.updateEntitiesFromRepository();
308
            this.currentWorkspace = ws;
309
            this.entitiesUpdateds = true;
310
            setVisibleStatus(false);
311
        } finally {
312
            DisposeUtils.disposeQuietly(ws);
313
        }
314
    }
315
    
316

    
317
    public void message(final String msg) {
318
        if( notInSwingThreadInvokeLater(() -> {message(msg);})) {
319
            return;
320
        }
321
        this.timerClearMsg.stop();
322
        this.getTaskStatusController().message(msg);
323
        this.timerClearMsg.start();
324
    }
325

    
326
    public void setVisibleStatus(boolean visible) {
327
        if( notInSwingThreadInvokeLater(() -> {setVisibleStatus(visible);}) ) {
328
            return;
329
        }
330
        this.lblStatusCaption.setVisible(visible);
331
        this.pbStatus.setVisible(visible);
332
        this.lblStatusMessages.setVisible(true);
333
    }
334
    
335
    public TaskStatusController getTaskStatusController() {
336
        return this.taskStatusController;
337
    }
338

    
339
    public static void selfRegister() {
340
        String[][] iconsInfo = new String[][]{
341
            new String[]{ICON_PROVIDER_NAME, ICON_COMMON_GROUP_NAME, "common-check-off"},
342
            new String[]{ICON_PROVIDER_NAME, ICON_COMMON_GROUP_NAME, "common-check-on"},
343
            new String[]{ICON_PROVIDER_NAME, ICON_COMMON_GROUP_NAME, "common-showform"},
344
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-commit-all"},
345
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-refresh-status"},
346
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-revert"},
347
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-update-all"},
348
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-merge"},
349
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-show-local-changes"},
350
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-show-remote-changes"},
351
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-show-local-and-remote-changes"},
352
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-center-context"},
353
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-zoom-context"},
354
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-clean-highlighted"},
355
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-topology-plan"},
356
        };
357
        registerIcons(iconsInfo);
358
        
359
    }
360

    
361
    @Override
362
    public boolean isProcessing() {
363
        return this.processing;
364
    }
365
    
366
    public void selectTab(int tab){
367
        this.tabLocalAndRemote.setSelectedIndex(tab);
368
    }
369
    
370
    public void selectOnlyALocalEntity(VCSGisEntity selectedTable){
371
        this.localChangesController.selectOnlyAEntity(selectedTable);
372
    }
373

    
374
    @Override
375
    public void setDialog(Dialog dialog) {
376
        // Do nothing
377
    }
378
    
379
    public void dispose() {
380
        DisposeUtils.disposeQuietly(localChangesController);
381
        DisposeUtils.disposeQuietly(remoteChangesController);
382
        DisposeUtils.disposeQuietly(currentWorkspace);
383
    }
384

    
385
}