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 @ 3459

History | View | Annotate | Download (12 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.Dimension;
26
import java.awt.event.ActionEvent;
27
import java.util.List;
28
import javax.swing.ImageIcon;
29
import javax.swing.JComponent;
30
import javax.swing.SwingUtilities;
31
import javax.swing.Timer;
32
import javax.swing.event.ChangeEvent;
33
import javax.swing.event.ChangeListener;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.swing.api.ToolsSwingLocator;
36
import org.gvsig.tools.swing.api.ToolsSwingManager;
37
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
38
import org.gvsig.tools.swing.api.task.TaskStatusController;
39
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager;
40
import org.gvsig.tools.swing.api.windowmanager.Dialog;
41
import org.gvsig.vcsgis.lib.VCSGisEntity;
42
import org.gvsig.vcsgis.lib.VCSGisRuntimeException;
43
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
44
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity;
45
import org.gvsig.vcsgis.swing.VCSGisJChanges;
46
import org.gvsig.vcsgis.swing.VCSGisSwingLocator;
47
import org.gvsig.vcsgis.swing.VCSGisSwingManager;
48
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.notInSwingThreadInvokeLater;
49
import org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl;
50
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_COMMON_GROUP_NAME;
51
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_GROUP_NAME;
52
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_PROVIDER_NAME;
53
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.registerIcons;
54
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
56
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationRequiredMessage;
57
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors;
58
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors;
59
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.showAuthenticationErrors;
60

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

    
73
    public static final int LOCAL_TAB_INDEX = 0;
74
    public static final int REMOTE_TAB_INDEX = 1;
75

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

    
93
    @Override
94
    public JComponent asJComponent() {
95
        return this;
96
    }
97

    
98
    @Override
99
    public ImageIcon loadImage(String imageName) {
100
        return VCSGisSwingManagerImpl.loadImage(imageName);
101
    }
102
    
103
    private void translate() {
104
        ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
105
        swingManager.translate(this.lblWorkspace);
106
        swingManager.translate(this.btnWorkspace);
107

    
108
        swingManager.translate(this.tabLocalAndRemote);
109
    }
110

    
111
    private void initComponents() {
112
        VCSGisSwingManager vcsSwingManager = VCSGisSwingLocator.getVCSGisSwingManager();
113
        TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager();
114

    
115
        this.timerClearMsg = new Timer(5000, (ActionEvent e) -> {
116
            getTaskStatusController().message("");
117
        });
118
        this.timerClearMsg.setRepeats(false);
119
        
120
        translate();
121

    
122
        this.taskStatusController = taskStatusManager.createTaskStatusController(
123
                this.lblStatusCaption, 
124
                this.lblStatusMessages, 
125
                this.pbStatus
126
        );
127
        this.taskStatusController.setShowCancelButton(false);
128
        this.taskStatusController.setShowRemoveTaskButton(false);
129
        this.taskStatusController.bind(ToolsLocator.getTaskStatusManager());
130
        SwingUtilities.invokeLater(() -> {this.setVisibleStatus(false); });
131
        
132
        
133
        this.workspacePicker = vcsSwingManager.createWorkspacePickerController(
134
                this.cboWorkspace,
135
                this.btnWorkspace
136
        );
137
        
138
        this.workspacePicker.addChangeListener(new ChangeListener() {
139
            @Override
140
            public void stateChanged(ChangeEvent e) {
141
                doChangeWorkspace();
142
            }
143
        });
144
        
145

    
146
        this.localChangesController = new LocalChangesController(
147
            this,
148
            this.workspacePicker,
149
            this.btnLocalCheckAllEntities,
150
            this.btnLocalUnCheckAllEntities,
151
            this.tblLocalChanges,
152
            this.btnLocalCheckAll,
153
            this.btnLocalUnCheckAll,
154
            this.btnLocalShowForm,
155
            this.btnLocalRefresh,
156
            this.btnLocalCommit,
157
            this.btnLocalRevert,
158
            this.lblLocalEffectiveDate,
159
            this.txtLocalEffectiveDate,
160
            this.txtLocalComment,
161
            this.btnLocalEffectiveDate,
162
            this.lblLocalComment,
163
            this.btnLocalZoom,
164
            this.btnLocalCenter,
165
            this.btnLocalCleanHighligthed,
166
            this.lblLocalChangesCount,
167
            this.txtLocalTablesFilter,
168
            this.btnLocalTable,
169
            this.treeLocalTables
170
        );
171
        
172
        this.remoteChangesController = new RemoteChangesController(
173
            this,
174
                
175
            this.workspacePicker,
176

    
177
            this.lstRemoteTables,
178
            this.btnRemoteTablesReload,
179

    
180
            this.tblRemoteChanges,
181
            this.btnRemoteCheckAll,
182
            this.btnRemoteUncheckAll,
183
            this.btnRemoteDownloadChanges,
184
            this.btnRemoteReloadChanges,
185
            this.btnRemoteCleanChanges,
186
            this.btnRemoteUpdate,
187
            this.btnRemoteMerge,
188
            this.btnRemoteShowForm,
189
            this.btnRemoteZoom,
190
            this.btnRemoteCenter,
191
            this.btnRemoteCheckout,
192
            this.btnRemoteCleanHighligthed,
193
            this.lblRemoteChangesCount
194
        );
195
        
196
        this.setPreferredSize(new Dimension(640, 480));
197
    }
198
    
199
    /* friend */ void doUpdateComponents() {
200
        if( notInSwingThreadInvokeLater(() -> {doUpdateComponents();}) ) {
201
            return;
202
        }
203
        
204
        if(this.localChangesController != null){
205
            this.localChangesController.doUpdateComponents();
206
        }
207
        if(this.remoteChangesController != null){
208
            this.remoteChangesController.doUpdateComponents();
209
        }
210
    }
211
    
212
    public void updateLocalChangesTable() {
213
        if( notInSwingThreadInvokeLater(() -> {updateLocalChangesTable();}) ) {
214
            return;
215
        }
216
        this.localChangesController.doReloadTables();
217
        this.localChangesController.doUpdateTableLocalChanges();
218
    }
219

    
220
    public VCSGisWorkspace getWorkspace() {
221
        VCSGisWorkspace ws = this.workspacePicker.get();
222
        return ws;
223
    }
224
    
225
    private void doChangeWorkspace() {
226
        try {
227
            VCSGisWorkspace ws = this.getWorkspace();
228
            if(ws == null) {
229
                this.localChangesController.doChangeWorkspace();
230
                this.remoteChangesController.doChangeWorkspace();
231
                return;
232
            }
233
            if(ws.authenticate(null)) {
234
                this.localChangesController.doChangeWorkspace();
235
                this.remoteChangesController.doChangeWorkspace();
236
                return;
237
            }
238
            showAuthenticationRequiredMessage("_VCS_Changes");
239
            this.workspacePicker.set(null);
240
            doChangeWorkspace();
241
        } catch (VCSGisRuntimeException e1) {
242
            LOGGER.warn("Can't set workspace.", e1);
243
            if (showAuthenticationErrors("_VCS_Changes", e1)) {
244
                this.workspacePicker.set(null);
245
                doChangeWorkspace();
246
            }
247
        } catch (Exception e2) {
248
            LOGGER.warn("Can't set workspace.", e2);
249
        }
250
    }
251

    
252
    
253
    public void updateEntitiesFromRepository(boolean forceUpdateEntities) {
254
        VCSGisWorkspace ws = this.getWorkspace();
255
        if( ws == null ) {
256
            return;
257
        }
258
        if( !forceUpdateEntities && this.currentWorkspace==ws && this.entitiesUpdateds ) {
259
            return;
260
        }
261
        setVisibleStatus(true);
262
        ws.updateEntitiesFromRepository();
263
        this.currentWorkspace = ws;
264
        this.entitiesUpdateds = true;
265
        setVisibleStatus(false);
266
    }
267
    
268

    
269
    public void message(final String msg) {
270
        if( notInSwingThreadInvokeLater(() -> {message(msg);})) {
271
            return;
272
        }
273
        this.timerClearMsg.stop();
274
        this.getTaskStatusController().message(msg);
275
        this.timerClearMsg.start();
276
    }
277

    
278
    public void setVisibleStatus(boolean visible) {
279
        if( notInSwingThreadInvokeLater(() -> {setVisibleStatus(visible);}) ) {
280
            return;
281
        }
282
        this.lblStatusCaption.setVisible(visible);
283
        this.pbStatus.setVisible(visible);
284
        this.lblStatusMessages.setVisible(true);
285
    }
286
    
287
    public TaskStatusController getTaskStatusController() {
288
        return this.taskStatusController;
289
    }
290

    
291
    public static void selfRegister() {
292
        String[][] iconsInfo = new String[][]{
293
            new String[]{ICON_PROVIDER_NAME, ICON_COMMON_GROUP_NAME, "common-check-off"},
294
            new String[]{ICON_PROVIDER_NAME, ICON_COMMON_GROUP_NAME, "common-check-on"},
295
            new String[]{ICON_PROVIDER_NAME, ICON_COMMON_GROUP_NAME, "common-showform"},
296
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-commit-all"},
297
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-refresh-status"},
298
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-revert"},
299
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-update-all"},
300
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-merge"},
301
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-show-local-changes"},
302
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-show-remote-changes"},
303
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-show-local-and-remote-changes"},
304
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-center-context"},
305
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-zoom-context"},
306
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-clean-highlighted"},
307
        };
308
        registerIcons(iconsInfo);
309
        
310
    }
311

    
312
    @Override
313
    public boolean isProcessing() {
314
        return this.processing;
315
    }
316
    
317
    public void selectTab(int tab){
318
        this.tabLocalAndRemote.setSelectedIndex(tab);
319
    }
320
    
321
    public void selectOnlyALocalEntity(VCSGisEntity selectedTable){
322
        this.localChangesController.selectOnlyAEntity(selectedTable);
323
    }
324

    
325
    @Override
326
    public void setDialog(Dialog dialog) {
327
        // Do nothing
328
    }
329
}