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 / checkout / VCSGisJCheckoutImpl.java @ 2822
History | View | Annotate | Download (11.2 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 |
package org.gvsig.vcsgis.swing.impl.checkout; |
23 |
|
24 |
import java.awt.Dimension; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.util.List; |
28 |
import javax.swing.Action; |
29 |
import javax.swing.ButtonGroup; |
30 |
import javax.swing.ButtonModel; |
31 |
import javax.swing.ComboBoxModel; |
32 |
import javax.swing.JComponent; |
33 |
import javax.swing.ListSelectionModel; |
34 |
import javax.swing.event.ChangeEvent; |
35 |
import javax.swing.event.ListSelectionEvent; |
36 |
import org.apache.commons.lang3.StringUtils; |
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
38 |
import org.gvsig.tools.swing.api.Component; |
39 |
import org.gvsig.tools.swing.api.FilteredListController; |
40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
41 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
42 |
import org.gvsig.tools.swing.api.pickercontroller.DatePickerController; |
43 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
44 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
45 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
46 |
import org.gvsig.tools.util.LabeledValue; |
47 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
48 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
49 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
50 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
51 |
import org.gvsig.vcsgis.swing.VCSGisJCheckout; |
52 |
import org.gvsig.vcsgis.swing.VCSGisSwingLocator; |
53 |
import org.gvsig.vcsgis.swing.VCSGisSwingManager; |
54 |
import org.gvsig.vcsgis.swing.VCSGisSwingServices; |
55 |
import org.slf4j.LoggerFactory; |
56 |
|
57 |
/**
|
58 |
*
|
59 |
* @author gvSIG Team
|
60 |
*/
|
61 |
public class VCSGisJCheckoutImpl extends VCSGisJCheckoutView |
62 |
implements Component, VCSGisJCheckout { |
63 |
|
64 |
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(VCSGisJCheckoutImpl.class); |
65 |
|
66 |
private Dialog dialog; |
67 |
|
68 |
private PickerController<VCSGisWorkspace> workspacePicker;
|
69 |
private DatePickerController datePicker;
|
70 |
private FilteredListController filteredList;
|
71 |
|
72 |
public VCSGisJCheckoutImpl() {
|
73 |
translate(); |
74 |
|
75 |
initComponents(); |
76 |
} |
77 |
|
78 |
private void initComponents() { |
79 |
|
80 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
81 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
82 |
this.workspacePicker = swingManager.createWorkspacePickerController(
|
83 |
cboWorkspaces, |
84 |
btnInitWorkspace |
85 |
); |
86 |
|
87 |
this.workspacePicker.addChangeListener((ChangeEvent e) -> { |
88 |
doChangeWorkspace(); |
89 |
doUpdateEnableComponents(); |
90 |
}); |
91 |
|
92 |
// this.cboWorkspaces.addItemListener((ItemEvent e) -> {
|
93 |
// if (e.getStateChange() == ItemEvent.SELECTED) {
|
94 |
// doChangeWorkspace();
|
95 |
// doUpdateEnableComponents();
|
96 |
// }
|
97 |
// });
|
98 |
|
99 |
this.lstTables.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
100 |
this.lstTables.addListSelectionListener((ListSelectionEvent e) -> { |
101 |
//FIXME: for use when branches are included
|
102 |
// dochangeTable();
|
103 |
doUpdateEnableComponents(); |
104 |
}); |
105 |
|
106 |
filteredList = toolsSwingManager.createFilteredListController(lstTables, txtFilter, btnTable); |
107 |
|
108 |
this.datePicker = toolsSwingManager.createDatePickerController(txtEffectiveDate, btnEffectiveDate);
|
109 |
|
110 |
this.rdbRevision.setEnabled(false); |
111 |
this.lstRevisions.setEnabled(false); |
112 |
//Effective date dissabled
|
113 |
this.rdbEffectiveDate.setEnabled(false); |
114 |
this.btnEffectiveDate.setEnabled(false); |
115 |
this.txtEffectiveDate.setEnabled(false); |
116 |
// this.rdbBranch.setEnabled(false);
|
117 |
// this.cboBranches.setEnabled(false);
|
118 |
|
119 |
//FIXME: for use when branches are included
|
120 |
|
121 |
// this.rdbBranch.addActionListener(new ActionListener() {
|
122 |
// @Override
|
123 |
// public void actionPerformed(ActionEvent e) {
|
124 |
// if(rdbBranch.isSelected()){
|
125 |
// cboBranches.setEnabled(true);
|
126 |
// lstRevisions.setEnabled(false);
|
127 |
// }
|
128 |
// }
|
129 |
// });
|
130 |
//
|
131 |
// this.rdbRevision.addActionListener(new ActionListener() {
|
132 |
// @Override
|
133 |
// public void actionPerformed(ActionEvent e) {
|
134 |
// if(rdbRevision.isSelected()){
|
135 |
// rdbBranch.setSelected(true);
|
136 |
// }
|
137 |
// }
|
138 |
// });
|
139 |
|
140 |
|
141 |
VCSGisSwingServices services = swingManager.getDefaultServices(); |
142 |
|
143 |
ComboBoxModel<LabeledValue> viewDocumentsModel = services.getViewDocumentsComboBoxModel();
|
144 |
|
145 |
cboView.setModel(viewDocumentsModel); |
146 |
|
147 |
cboView.addActionListener((ActionEvent e) -> {
|
148 |
doUpdateEnableComponents(); |
149 |
}); |
150 |
|
151 |
|
152 |
this.rdbDontAddToProject.addActionListener((ActionEvent e) -> { |
153 |
doUpdateEnableComponents(); |
154 |
}); |
155 |
|
156 |
this.rdbAddLayerToView.addActionListener((ActionEvent e) -> { |
157 |
doUpdateEnableComponents(); |
158 |
}); |
159 |
|
160 |
this.rdbAddTableToProject.addActionListener((ActionEvent e) -> { |
161 |
doUpdateEnableComponents(); |
162 |
}); |
163 |
|
164 |
this.setPreferredSize(
|
165 |
new Dimension(520, 340) |
166 |
); |
167 |
|
168 |
} |
169 |
|
170 |
@Override
|
171 |
public JComponent asJComponent() { |
172 |
return this; |
173 |
} |
174 |
|
175 |
@Override
|
176 |
public void setDialog(Dialog dialog) { |
177 |
this.dialog = dialog;
|
178 |
this.doUpdateEnableComponents();
|
179 |
} |
180 |
|
181 |
private void doChangeWorkspace() { |
182 |
VCSGisWorkspace workspace = workspacePicker.get(); |
183 |
|
184 |
workspace.updateEntities(); |
185 |
List<VCSGisWorkspaceEntity> wsEntities = workspace.getWorkspaceEntities();
|
186 |
this.filteredList.getModel().clear();
|
187 |
// for (VCSGisWorkspace.LocalEntity entity : wsEntities) {
|
188 |
// this.filteredList.getModel().addElement(entity);
|
189 |
// }
|
190 |
|
191 |
//Obtenemos la entidades del repositorio que no estan todavia en el workspace
|
192 |
List<VCSGisEntity> repoEntities = workspace.getRepositoryEntities();
|
193 |
for (VCSGisEntity rentity : repoEntities) {
|
194 |
VCSGisEntity lentity = workspace.getWorkspaceEntityByCode(rentity.getEntityCode()); |
195 |
if(lentity == null){ |
196 |
this.filteredList.getModel().addElement(rentity);
|
197 |
} |
198 |
|
199 |
} |
200 |
} |
201 |
|
202 |
|
203 |
// FIXME: for use when branches are included
|
204 |
// private void doChangeTable() {
|
205 |
// vcsgisWorkspace.Entity entity = (vcsgisWorkspace.Entity) lstTables.getSelectedValue();
|
206 |
// entity.getEntityName()
|
207 |
// }
|
208 |
|
209 |
@Override
|
210 |
public VCSGisWorkspace getWorkspace() {
|
211 |
return this.workspacePicker.get(); |
212 |
} |
213 |
|
214 |
// @Override
|
215 |
// public VCSGisWorkspace.LocalEntity getTable() {
|
216 |
// return (VCSGisWorkspace.LocalEntity) lstTables.getSelectedValue();
|
217 |
// }// @Override
|
218 |
// public VCSGisWorkspace.LocalEntity getTable() {
|
219 |
// return (VCSGisWorkspace.LocalEntity) lstTables.getSelectedValue();
|
220 |
// }
|
221 |
|
222 |
|
223 |
@Override
|
224 |
public VCSGisEntity getTable() {
|
225 |
return (VCSGisEntity) lstTables.getSelectedValue();
|
226 |
} |
227 |
|
228 |
private void doUpdateEnableComponents() { |
229 |
if(this.getTable()==null) { |
230 |
this.rdbDontAddToProject.setEnabled(false); |
231 |
this.rdbAddLayerToView.setEnabled(false); |
232 |
this.cboView.setEnabled(false); |
233 |
this.rdbAddTableToProject.setEnabled(false); |
234 |
} else {
|
235 |
this.rdbDontAddToProject.setEnabled(true); |
236 |
this.rdbAddTableToProject.setEnabled(true); |
237 |
if(isLayer(this.getTable())){ |
238 |
this.rdbAddLayerToView.setEnabled(true); |
239 |
this.cboView.setEnabled(true); |
240 |
} else {
|
241 |
this.rdbAddLayerToView.setEnabled(false); |
242 |
this.cboView.setEnabled(false); |
243 |
} |
244 |
} |
245 |
|
246 |
LabeledValue selectedView = (LabeledValue)cboView.getSelectedItem(); |
247 |
boolean enableInit = this.getWorkspace() != null && this.getTable() != null; |
248 |
|
249 |
boolean dontAddNothing = rdbDontAddToProject.isSelected();
|
250 |
boolean addLayerToView = rdbAddLayerToView.isSelected() && selectedView != null && selectedView.getValue() != null; |
251 |
boolean addTableToProject = rdbAddTableToProject.isSelected();
|
252 |
|
253 |
enableInit = enableInit && (dontAddNothing || (addLayerToView || addTableToProject)); |
254 |
if (dialog != null) { |
255 |
this.dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK,
|
256 |
enableInit |
257 |
); |
258 |
} |
259 |
} |
260 |
|
261 |
private boolean isLayer(VCSGisEntity entity){ |
262 |
return !StringUtils.isBlank(entity.getGeometryFieldName());
|
263 |
} |
264 |
|
265 |
@Override
|
266 |
public int checkout() { |
267 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
268 |
VCSGisSwingServices services = swingManager.getDefaultServices(); |
269 |
|
270 |
VCSGisEntity entity = getTable(); |
271 |
final VCSGisWorkspace workspace = this.getWorkspace(); |
272 |
if (workspace != null && entity != null) { |
273 |
int res = this.getWorkspace().checkout(entity.getEntityName()); |
274 |
if(res == ERR_OK) {
|
275 |
if(!rdbDontAddToProject.isSelected()){
|
276 |
if(rdbAddLayerToView.isSelected()){
|
277 |
if(isLayer(entity)){
|
278 |
FeatureStore store = this.getWorkspace().getFeatureStore(entity.getEntityName());
|
279 |
String layerName = workspace.getLabel()+" - " + store.getName(); |
280 |
services.addLayerToView(store, (LabeledValue)cboView.getSelectedItem(), layerName); |
281 |
} |
282 |
} |
283 |
if(rdbAddTableToProject.isSelected()){
|
284 |
FeatureStore store = this.getWorkspace().getFeatureStore(entity.getEntityName());
|
285 |
services.addTableToProject(workspace, store); |
286 |
} |
287 |
} |
288 |
} |
289 |
return res;
|
290 |
} |
291 |
return -1; |
292 |
} |
293 |
|
294 |
|
295 |
private void translate() { |
296 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
297 |
swingManager.translate(this.lblWorkspace);
|
298 |
swingManager.translate(this.lblTable);
|
299 |
swingManager.translate(this.rdbEffectiveDate);
|
300 |
swingManager.translate(this.rdbRevision);
|
301 |
swingManager.translate(this.rdbDontAddToProject);
|
302 |
swingManager.translate(this.rdbAddLayerToView);
|
303 |
swingManager.translate(this.rdbAddTableToProject);
|
304 |
} |
305 |
|
306 |
} |