Revision 2822 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
VCSGisJCheckoutImpl.java | ||
---|---|---|
22 | 22 |
package org.gvsig.vcsgis.swing.impl.checkout; |
23 | 23 |
|
24 | 24 |
import java.awt.Dimension; |
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
25 | 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; |
|
26 | 32 |
import javax.swing.JComponent; |
27 | 33 |
import javax.swing.ListSelectionModel; |
28 | 34 |
import javax.swing.event.ChangeEvent; |
29 | 35 |
import javax.swing.event.ListSelectionEvent; |
36 |
import org.apache.commons.lang3.StringUtils; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
30 | 38 |
import org.gvsig.tools.swing.api.Component; |
31 | 39 |
import org.gvsig.tools.swing.api.FilteredListController; |
32 | 40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
... | ... | |
35 | 43 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
36 | 44 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
37 | 45 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
46 |
import org.gvsig.tools.util.LabeledValue; |
|
38 | 47 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
48 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
|
39 | 49 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
40 | 50 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
41 | 51 |
import org.gvsig.vcsgis.swing.VCSGisJCheckout; |
42 | 52 |
import org.gvsig.vcsgis.swing.VCSGisSwingLocator; |
43 | 53 |
import org.gvsig.vcsgis.swing.VCSGisSwingManager; |
54 |
import org.gvsig.vcsgis.swing.VCSGisSwingServices; |
|
44 | 55 |
import org.slf4j.LoggerFactory; |
45 | 56 |
|
46 | 57 |
/** |
... | ... | |
61 | 72 |
public VCSGisJCheckoutImpl() { |
62 | 73 |
translate(); |
63 | 74 |
|
64 |
initializeComponents();
|
|
75 |
initComponents(); |
|
65 | 76 |
} |
66 | 77 |
|
67 |
private void initializeComponents() {
|
|
78 |
private void initComponents() { |
|
68 | 79 |
|
69 | 80 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
70 | 81 |
VCSGisSwingManager swingManager = VCSGisSwingLocator.getVCSGisSwingManager(); |
... | ... | |
127 | 138 |
// }); |
128 | 139 |
|
129 | 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 |
|
|
130 | 164 |
this.setPreferredSize( |
131 | 165 |
new Dimension(520, 340) |
132 | 166 |
); |
133 | 167 |
|
134 | 168 |
} |
135 |
|
|
169 |
|
|
136 | 170 |
@Override |
137 | 171 |
public JComponent asJComponent() { |
138 | 172 |
return this; |
... | ... | |
191 | 225 |
return (VCSGisEntity) lstTables.getSelectedValue(); |
192 | 226 |
} |
193 | 227 |
|
194 |
|
|
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 |
} |
|
195 | 245 |
|
196 |
private void doUpdateEnableComponents() { |
|
197 |
boolean enableInit = (this.getWorkspace() != null && this.getTable() != null); |
|
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)); |
|
198 | 254 |
if (dialog != null) { |
199 | 255 |
this.dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK, |
200 | 256 |
enableInit |
201 | 257 |
); |
202 | 258 |
} |
203 | 259 |
} |
260 |
|
|
261 |
private boolean isLayer(VCSGisEntity entity){ |
|
262 |
return !StringUtils.isBlank(entity.getGeometryFieldName()); |
|
263 |
} |
|
204 | 264 |
|
205 | 265 |
@Override |
206 | 266 |
public int checkout() { |
207 |
if (this.getWorkspace() != null && this.getTable() != null) { |
|
208 |
return this.getWorkspace().checkout(getTable().getEntityName()); |
|
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; |
|
209 | 290 |
} |
210 | 291 |
return -1; |
211 | 292 |
} |
... | ... | |
217 | 298 |
swingManager.translate(this.lblTable); |
218 | 299 |
swingManager.translate(this.rdbEffectiveDate); |
219 | 300 |
swingManager.translate(this.rdbRevision); |
301 |
swingManager.translate(this.rdbDontAddToProject); |
|
302 |
swingManager.translate(this.rdbAddLayerToView); |
|
303 |
swingManager.translate(this.rdbAddTableToProject); |
|
220 | 304 |
} |
221 | 305 |
|
222 | 306 |
} |
Also available in: Unified diff