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 / revisions / VCSGisJRevisionsImpl.java @ 3603

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

    
25
import java.awt.event.ItemEvent;
26
import javax.swing.DefaultComboBoxModel;
27
import javax.swing.ImageIcon;
28
import javax.swing.JComponent;
29
import javax.swing.SwingUtilities;
30
import javax.swing.event.ChangeEvent;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.swing.api.ToolsSwingLocator;
33
import org.gvsig.tools.swing.api.ToolsSwingManager;
34
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
35
import org.gvsig.tools.swing.api.task.TaskStatusController;
36
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager;
37
import org.gvsig.tools.swing.api.windowmanager.Dialog;
38
import org.gvsig.tools.util.LabeledValue;
39
import org.gvsig.tools.util.LabeledValueImpl;
40
import org.gvsig.vcsgis.lib.VCSGisEntity;
41
import org.gvsig.vcsgis.lib.VCSGisManager;
42
import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_REPOSITORY_NEW;
43
import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_UNKNOWN;
44
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
45
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity;
46
import org.gvsig.vcsgis.swing.VCSGisJRevisions;
47
import org.gvsig.vcsgis.swing.VCSGisSwingLocator;
48
import org.gvsig.vcsgis.swing.VCSGisSwingManager;
49
import org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons;
50
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingCommons.notInSwingThreadInvokeLater;
51
import org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl;
52
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_GROUP_NAME;
53
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.ICON_PROVIDER_NAME;
54
import static org.gvsig.vcsgis.swing.impl.VCSGisSwingManagerImpl.registerIcons;
55

    
56
/**
57
 *
58
 * @author gvSIG Team
59
 */
60
public class VCSGisJRevisionsImpl extends VCSGisJRevisionsView implements VCSGisJRevisions {
61

    
62
    private boolean processing;
63
    private TaskStatusController taskStatusController;
64
    private PickerController<VCSGisWorkspace> workspacePicker;
65
    private VCSGisJRevisionsController revisionsController;
66
   
67
    public VCSGisJRevisionsImpl() {
68
        this.processing = false;
69
        this.initComponents();
70
    }
71

    
72
    @Override
73
    public boolean isProcessing() {
74
        return this.processing;
75
    }
76

    
77
    @Override
78
    public JComponent asJComponent() {
79
        return this;
80
    }
81
    
82
    private void initComponents() {
83
        VCSGisSwingManager vcsSwingManager = VCSGisSwingLocator.getVCSGisSwingManager();
84
        TaskStatusSwingManager taskStatusManager = ToolsSwingLocator.getTaskStatusSwingManager();
85

    
86
        this.taskStatusController = taskStatusManager.createTaskStatusController(
87
                null, 
88
                this.lblMessages, 
89
                null
90
        );
91
        this.taskStatusController.setShowCancelButton(false);
92
        this.taskStatusController.setShowRemoveTaskButton(false);
93
        this.taskStatusController.bind(ToolsLocator.getTaskStatusManager());
94
        SwingUtilities.invokeLater(() -> {this.setVisibleStatus(false); });
95
        
96
        
97
        this.workspacePicker = vcsSwingManager.createWorkspacePickerController(
98
                this.cboWorkspace,
99
                this.btnWorkspace
100
        );
101
        this.workspacePicker.addChangeListener((ChangeEvent e) -> {
102
            this.revisionsController.setWorkspace(this.workspacePicker.get());
103
            doReloadTables();
104
        });
105
        this.cboTables.addItemListener((ItemEvent e) -> {
106
            this.revisionsController.setEntity(getSelectedTable());
107
        });
108
        this.revisionsController = new VCSGisJRevisionsController(
109
                this.tblRevisions, 
110
                this.btnMore, 
111
                this.btnFilter, 
112
                this.lblMessages
113
        );
114
        this.revisionsController.addChangeListener((ChangeEvent e) -> {
115
            this.processing = this.revisionsController.isProcessing();
116
            updateStateComponents();
117
        });
118
        
119
        translate();
120
                
121
    }
122
    
123
    private void translate() {
124
        ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
125
        toolsSwingManager.translate(this.btnMore);
126
        toolsSwingManager.translate(this.btnFilter);
127
        toolsSwingManager.translate(this.lblTable);
128
        toolsSwingManager.translate(this.lblWorkspace);
129
    }
130
    
131
    private void updateStateComponents() {
132
        if (notInSwingThreadInvokeLater(() -> {updateStateComponents();})) {
133
            return;
134
        }
135
        VCSGisWorkspace ws = this.workspacePicker.get();
136
        VCSGisEntity table = this.getSelectedTable();
137
        
138
        
139
        this.workspacePicker.setEnabled(!processing);
140
        this.cboTables.setEnabled(!processing && ws!=null);
141
        this.revisionsController.setEnabled(!processing && table!=null);
142
    }
143

    
144
    private VCSGisEntity getSelectedTable() {
145
        VCSGisWorkspace ws = this.workspacePicker.get();
146
        if( ws==null ) {
147
            return null;
148
        }
149
        LabeledValue<VCSGisEntity> x = (LabeledValue<VCSGisEntity>) this.cboTables.getSelectedItem();
150
        if(x == null){
151
            return null;
152
        }
153
        return x.getValue();
154
    }
155
    
156
    private void doReloadTables() {
157
        VCSGisWorkspace ws = this.getWorkspace();
158
        if (ws == null) {
159
            this.cboTables.setModel(new DefaultComboBoxModel());
160
            return;
161
        }
162
        Thread task = new Thread(
163
                () -> {
164
                    try {
165
                        this.processing = true;
166
                        this.updateStateComponents();
167
                        
168
                        message("Updating list of tables from remote repository...");
169
                        ws.updateEntitiesFromRepository();
170
                        message("Loading list of tables...");
171

    
172
                        DefaultComboBoxModel model = new DefaultComboBoxModel();
173
                        for (VCSGisEntity rentity : ws.getRepositoryEntities()) {
174
                            VCSGisWorkspaceEntity lentity = getWorkspace().getWorkspaceEntity(rentity.getEntityCode());
175
                            String label = VCSGisSwingCommons.getHTMLColorTag(
176
                                    lentity == null ? STATE_REPOSITORY_NEW : lentity.getState(),
177
                                    rentity.getEntityName()
178
                            );            
179
                            model.addElement(new LabeledValueImpl<>(label, rentity));
180
                        }
181
                        SwingUtilities.invokeLater(() -> { 
182
                            this.cboTables.setModel(model); 
183
                            this.cboTables.setSelectedIndex(-1);
184
                        });
185
                    } finally {
186
                        this.processing = false;
187
                        this.updateStateComponents();
188
                        this.message("Ready.");
189
                    }
190
                },
191
                "VCSGis_UpdateEntitiesFromRepository"
192
        );
193
        this.processing = true;
194
        this.updateStateComponents();
195
        task.start();
196
    }
197
    
198
    @Override
199
    public ImageIcon loadImage(String imageName) {
200
        return VCSGisSwingManagerImpl.loadImage(imageName);
201
    }
202

    
203
    public static void selfRegister() {
204
        String[][] iconsInfo = new String[][]{
205
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-revisions"},
206
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-revisions-more"},
207
            new String[]{ICON_PROVIDER_NAME, ICON_GROUP_NAME, "vcsgis-revisions-filter"},
208
        };
209
        registerIcons(iconsInfo);
210
        
211
    }
212

    
213
    private void message(final String msg) {
214
        if( notInSwingThreadInvokeLater(() -> {message(msg);})) {
215
            return;
216
        }
217
        this.getTaskStatusController().message(msg);
218
    }
219

    
220
    public void setVisibleStatus(boolean visible) {
221
        if( notInSwingThreadInvokeLater(() -> {setVisibleStatus(visible);}) ) {
222
            return;
223
        }
224
        this.lblMessages.setVisible(visible);
225
    }
226
    
227
    public TaskStatusController getTaskStatusController() {
228
        return this.taskStatusController;
229
    }
230
    
231
    public VCSGisWorkspace getWorkspace() {
232
        VCSGisWorkspace ws = this.workspacePicker.get();
233
        return ws;
234
    }
235

    
236
    @Override
237
    public void setDialog(Dialog dialog) {
238
        // Do nothing
239
    }
240
    
241
    
242
}