svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerWizardPanelController.java @ 44237
History | View | Annotate | Download (19.8 KB)
1 | 43152 | fdiaz | package org.gvsig.fmap.dal.serverexplorer.filesystem.swing; |
---|---|---|---|
2 | |||
3 | 43208 | jjdelcerro | import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager; |
4 | import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanel; |
||
5 | 43321 | fdiaz | |
6 | 43152 | fdiaz | import java.awt.Component; |
7 | import java.awt.Window; |
||
8 | import java.awt.event.ActionEvent; |
||
9 | import java.awt.event.ActionListener; |
||
10 | import java.io.File; |
||
11 | import java.util.ArrayList; |
||
12 | import java.util.Iterator; |
||
13 | import java.util.List; |
||
14 | import java.util.Locale; |
||
15 | |||
16 | import javax.swing.DefaultListSelectionModel; |
||
17 | 43256 | jjdelcerro | import javax.swing.JFileChooser; |
18 | 43152 | fdiaz | import javax.swing.ListSelectionModel; |
19 | import javax.swing.event.ListSelectionEvent; |
||
20 | import javax.swing.event.ListSelectionListener; |
||
21 | 43321 | fdiaz | import javax.swing.table.TableColumn; |
22 | 43152 | fdiaz | |
23 | import org.cresques.cts.IProjection; |
||
24 | import org.slf4j.Logger; |
||
25 | import org.slf4j.LoggerFactory; |
||
26 | |||
27 | import org.gvsig.andami.messages.NotificationManager; |
||
28 | import org.gvsig.app.ApplicationLocator; |
||
29 | import org.gvsig.app.ApplicationManager; |
||
30 | import org.gvsig.app.prepareAction.PrepareContext; |
||
31 | 43256 | jjdelcerro | import org.gvsig.filedialogchooser.FileDialogChooser; |
32 | 44237 | jjdelcerro | import org.gvsig.filedialogchooser.FileDialogChooserManager; |
33 | 43534 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
34 | 43152 | fdiaz | import org.gvsig.fmap.dal.DataStoreParameters; |
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
||
37 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
||
38 | import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel.MyFileFilter; |
||
39 | 43208 | jjdelcerro | import org.gvsig.fmap.dal.swing.DALSwingLocator; |
40 | 43152 | fdiaz | import org.gvsig.fmap.mapcontext.MapContext; |
41 | import org.gvsig.tools.ToolsLocator; |
||
42 | import org.gvsig.tools.dynobject.DynObject; |
||
43 | import org.gvsig.tools.i18n.I18nManager; |
||
44 | 43256 | jjdelcerro | import org.gvsig.tools.util.ToolsUtilLocator; |
45 | 43152 | fdiaz | |
46 | |||
47 | /**
|
||
48 | * @author fdiaz
|
||
49 | *
|
||
50 | */
|
||
51 | public class FilesystemExplorerWizardPanelController extends FilesystemExplorerWizardPanelView { |
||
52 | |||
53 | |||
54 | /**
|
||
55 | *
|
||
56 | */
|
||
57 | private static final long serialVersionUID = -2351856603294610783L; |
||
58 | |||
59 | @SuppressWarnings("unused") |
||
60 | private static final Logger LOG = LoggerFactory |
||
61 | .getLogger(FilesystemExplorerWizardPanelController.class); |
||
62 | |||
63 | /**
|
||
64 | *
|
||
65 | */
|
||
66 | public static final String OPEN_LAYER_FILE_CHOOSER_ID = "OPEN_LAYER_FILE_CHOOSER_ID"; |
||
67 | |||
68 | private static final String DEFAULT_FILTER = "All_supported"; |
||
69 | |||
70 | protected FilesystemServerExplorer explorer;
|
||
71 | private ArrayList<MyFileFilter> filters; |
||
72 | protected MapContext mapContext;
|
||
73 | protected int selectedIndex; |
||
74 | private static MyFileFilter lastFilter = null; |
||
75 | 43534 | jjdelcerro | private boolean tabularOnly; |
76 | 43152 | fdiaz | |
77 | /**
|
||
78 | * @param mapContext
|
||
79 | * @param explorer
|
||
80 | * @param filters
|
||
81 | */
|
||
82 | public FilesystemExplorerWizardPanelController(MapContext mapContext, FilesystemServerExplorer explorer, ArrayList<MyFileFilter> filters) { |
||
83 | this.mapContext = mapContext;
|
||
84 | this.explorer = explorer;
|
||
85 | this.filters = filters;
|
||
86 | this.selectedIndex = -1; |
||
87 | |||
88 | initComponents(); |
||
89 | translate(); |
||
90 | } |
||
91 | |||
92 | private void translate() { |
||
93 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
94 | 43176 | jjdelcerro | btnAdd.setText(i18nManager.getTranslation("Anadir"));
|
95 | btnProperties.setText(i18nManager.getTranslation("Properties"));
|
||
96 | btnRemove.setText(i18nManager.getTranslation("Eliminar"));
|
||
97 | btnUp.setText(i18nManager.getTranslation("arriba"));
|
||
98 | btnDown.setText(i18nManager.getTranslation("abajo"));
|
||
99 | 43443 | jjdelcerro | |
100 | btnAdd.setToolTipText(i18nManager.getTranslation(btnAdd.getToolTipText())); |
||
101 | btnProperties.setToolTipText(i18nManager.getTranslation(btnProperties.getToolTipText())); |
||
102 | btnRemove.setToolTipText(i18nManager.getTranslation(btnRemove.getToolTipText())); |
||
103 | btnUp.setToolTipText(i18nManager.getTranslation(btnUp.getToolTipText())); |
||
104 | btnDown.setToolTipText(i18nManager.getTranslation(btnDown.getToolTipText())); |
||
105 | |||
106 | 43534 | jjdelcerro | btnChangeViewProjection.setText(i18nManager.getTranslation(btnChangeViewProjection.getText())); |
107 | btnChangeViewProjection.setToolTipText(i18nManager.getTranslation(btnChangeViewProjection.getToolTipText())); |
||
108 | 43152 | fdiaz | } |
109 | |||
110 | /**
|
||
111 | * @param locale
|
||
112 | *
|
||
113 | */
|
||
114 | public void setLocate(Locale locale) { |
||
115 | Locale l = super.getLocale(); |
||
116 | if (!l.equals(locale)) {
|
||
117 | translate(); |
||
118 | } |
||
119 | super.setLocale(locale);
|
||
120 | } |
||
121 | |||
122 | private void initComponents() { |
||
123 | |||
124 | this.btnAdd.addActionListener(new ActionListener() { |
||
125 | 43534 | jjdelcerro | @Override
|
126 | 43152 | fdiaz | public void actionPerformed(ActionEvent e) { |
127 | doAdd(); |
||
128 | } |
||
129 | }); |
||
130 | |||
131 | this.btnProperties.addActionListener(new ActionListener() { |
||
132 | 43534 | jjdelcerro | @Override
|
133 | 43152 | fdiaz | public void actionPerformed(ActionEvent e) { |
134 | doOpenProperties(); |
||
135 | } |
||
136 | }); |
||
137 | |||
138 | this.btnRemove.addActionListener(new ActionListener() { |
||
139 | 43534 | jjdelcerro | @Override
|
140 | 43152 | fdiaz | public void actionPerformed(ActionEvent e) { |
141 | doRemove(); |
||
142 | } |
||
143 | }); |
||
144 | |||
145 | this.btnUp.addActionListener(new ActionListener() { |
||
146 | 43534 | jjdelcerro | @Override
|
147 | 43152 | fdiaz | public void actionPerformed(ActionEvent e) { |
148 | doUp(); |
||
149 | } |
||
150 | }); |
||
151 | |||
152 | this.btnDown.addActionListener(new ActionListener() { |
||
153 | 43534 | jjdelcerro | @Override
|
154 | 43152 | fdiaz | public void actionPerformed(ActionEvent e) { |
155 | doDown(); |
||
156 | } |
||
157 | }); |
||
158 | |||
159 | 43534 | jjdelcerro | this.btnChangeViewProjection.addActionListener(new ActionListener() { |
160 | @Override
|
||
161 | public void actionPerformed(ActionEvent e) { |
||
162 | doChangeViewProjection(); |
||
163 | } |
||
164 | }); |
||
165 | |||
166 | 43152 | fdiaz | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
167 | |||
168 | this.tableFiles.setModel(new FilesystemExplorerWizardTableModel()); |
||
169 | this.tableFiles.getColumn(
|
||
170 | i18nManager.getTranslation(FilesystemExplorerWizardTableModel.COLUMN_STORE_PARAMETERS_NAME)) |
||
171 | .setCellRenderer(new FilesystemStoreParameteresCellRenderer(mapContext));
|
||
172 | 43321 | fdiaz | TableColumn columnTiled = this.tableFiles.getColumn( |
173 | i18nManager.getTranslation(FilesystemExplorerWizardTableModel.COLUMN_TILED_NAME)); |
||
174 | columnTiled.setMaxWidth(80);
|
||
175 | columnTiled.setCellRenderer(new TiledCellRenderer());
|
||
176 | 43152 | fdiaz | this.tableFiles.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
177 | this.tableFiles.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
||
178 | |||
179 | 43534 | jjdelcerro | @Override
|
180 | 43152 | fdiaz | public void valueChanged(ListSelectionEvent e) { |
181 | handleSelectionEvent(e); |
||
182 | } |
||
183 | }); |
||
184 | 43534 | jjdelcerro | this.btnChangeViewProjection.setEnabled(false); |
185 | 43152 | fdiaz | } |
186 | |||
187 | |||
188 | protected void updateComponents() { |
||
189 | btnUp.setEnabled(selectedIndex > 0 && selectedIndex < tableFiles.getRowCount());
|
||
190 | btnDown.setEnabled(selectedIndex >= 0 && selectedIndex < (tableFiles.getRowCount() - 1)); |
||
191 | btnProperties.setEnabled(selectedIndex >= 0 && selectedIndex < tableFiles.getRowCount());
|
||
192 | btnRemove.setEnabled(selectedIndex >= 0 && selectedIndex < tableFiles.getRowCount());
|
||
193 | } |
||
194 | |||
195 | protected void handleSelectionEvent(ListSelectionEvent e){ |
||
196 | 43534 | jjdelcerro | if (e.getValueIsAdjusting()) {
|
197 | 43152 | fdiaz | return;
|
198 | 43534 | jjdelcerro | } |
199 | 43152 | fdiaz | final DefaultListSelectionModel target = (DefaultListSelectionModel)e.getSource(); |
200 | selectedIndex = target.getAnchorSelectionIndex(); |
||
201 | |||
202 | updateComponents(); |
||
203 | } |
||
204 | |||
205 | protected void doAdd() { |
||
206 | |||
207 | List<FilesystemStoreParameters> list = chooseFilesParameters();
|
||
208 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel) this.tableFiles.getModel();
|
||
209 | |||
210 | for (FilesystemStoreParameters filesystemStoreParameters : list) {
|
||
211 | 43321 | fdiaz | model.add(filesystemStoreParameters); |
212 | 43152 | fdiaz | updateTable(); |
213 | int index = model.getRowCount()-1; |
||
214 | this.tableFiles.getSelectionModel().setSelectionInterval(index, index);
|
||
215 | } |
||
216 | 43534 | jjdelcerro | updateChangeViewProjection(); |
217 | 43152 | fdiaz | } |
218 | |||
219 | protected void doRemove() { |
||
220 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel)this.tableFiles.getModel();
|
||
221 | if(selectedIndex>=0 && selectedIndex<model.getRowCount()){ |
||
222 | int index = selectedIndex;
|
||
223 | model.remove(index); |
||
224 | updateTable(); |
||
225 | if(index>(model.getRowCount()-1)) { |
||
226 | index = model.getRowCount()-1;
|
||
227 | }; |
||
228 | this.tableFiles.getSelectionModel().setSelectionInterval(index, index);
|
||
229 | 43534 | jjdelcerro | updateChangeViewProjection(); |
230 | 43152 | fdiaz | } |
231 | } |
||
232 | |||
233 | protected void doOpenProperties() { |
||
234 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel) this.tableFiles.getModel();
|
||
235 | if (selectedIndex >= 0 && selectedIndex < model.getRowCount()) { |
||
236 | int index = selectedIndex;
|
||
237 | FilesystemStoreParameters parameters = model.getParams(index); |
||
238 | showPropertiesDialog((DynObject) parameters); |
||
239 | updateTable(); |
||
240 | this.tableFiles.getSelectionModel().setSelectionInterval(index, index);
|
||
241 | 43534 | jjdelcerro | updateChangeViewProjection(); |
242 | 43152 | fdiaz | } |
243 | } |
||
244 | |||
245 | protected void doUp() { |
||
246 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel)this.tableFiles.getModel();
|
||
247 | if(selectedIndex>0 && selectedIndex<model.getRowCount()){ |
||
248 | int index = selectedIndex;
|
||
249 | model.up(index); |
||
250 | updateTable(); |
||
251 | this.tableFiles.getSelectionModel().setSelectionInterval(index-1, index-1); |
||
252 | 43534 | jjdelcerro | updateChangeViewProjection(); |
253 | 43152 | fdiaz | } |
254 | } |
||
255 | |||
256 | protected void doDown() { |
||
257 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel)this.tableFiles.getModel();
|
||
258 | if(selectedIndex>=0 && selectedIndex<model.getRowCount()-1){ |
||
259 | int index = selectedIndex;
|
||
260 | model.down(index); |
||
261 | updateTable(); |
||
262 | this.tableFiles.getSelectionModel().setSelectionInterval(index+1, index+1); |
||
263 | 43534 | jjdelcerro | updateChangeViewProjection(); |
264 | 43152 | fdiaz | } |
265 | } |
||
266 | |||
267 | protected void showPropertiesDialog(final DynObject parameters) { |
||
268 | 43208 | jjdelcerro | DataStoreParametersPanelManager manager = DALSwingLocator.getDataStoreParametersPanelManager(); |
269 | 43209 | jjdelcerro | DataStoreParametersPanel panel = manager.createDataStoreParametersPanel(parameters); |
270 | 43152 | fdiaz | panel.setExcludeGeometryOptions(false);
|
271 | manager.showPropertiesDialog(parameters, panel); |
||
272 | } |
||
273 | |||
274 | private void updateTable(){ |
||
275 | ((FilesystemExplorerWizardTableModel)this.tableFiles.getModel()).fireTableDataChanged();
|
||
276 | updateRowHeights(); |
||
277 | 43534 | jjdelcerro | this.tableFiles.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
|
278 | 43152 | fdiaz | } |
279 | |||
280 | private void updateRowHeights() { |
||
281 | |||
282 | /*
|
||
283 | * Auto adjust the height of rows in a JTable.
|
||
284 | * The only way to know the row height for sure is to render each cell
|
||
285 | * to determine the rendered height. After your table is populated with
|
||
286 | * data you can do:
|
||
287 | *
|
||
288 | */
|
||
289 | for (int row = 0; row < this.tableFiles.getRowCount(); row++) { |
||
290 | int rowHeight = this.tableFiles.getRowHeight(); |
||
291 | for (int column = 0; column < this.tableFiles.getColumnCount(); column++) |
||
292 | { |
||
293 | Component comp = this.tableFiles.prepareRenderer(this.tableFiles.getCellRenderer(row, column), row, column); |
||
294 | rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
|
||
295 | } |
||
296 | this.tableFiles.setRowHeight(row, rowHeight);
|
||
297 | } |
||
298 | } |
||
299 | |||
300 | |||
301 | private List<FilesystemStoreParameters> chooseFilesParameters() { |
||
302 | |||
303 | 44237 | jjdelcerro | FileDialogChooserManager fileDialogChooserManager = ToolsUtilLocator.getFileDialogChooserManager(); |
304 | FileDialogChooser fileChooser = fileDialogChooserManager.create(OPEN_LAYER_FILE_CHOOSER_ID); |
||
305 | fileChooser.setCurrentDirectory(fileDialogChooserManager.getLastPath(OPEN_LAYER_FILE_CHOOSER_ID, explorer.getCurrentPath())); |
||
306 | 43152 | fdiaz | fileChooser.setMultiSelectionEnabled(true);
|
307 | fileChooser.setAcceptAllFileFilterUsed(false);
|
||
308 | |||
309 | Iterator<MyFileFilter> iter = this.filters.iterator(); |
||
310 | while (iter.hasNext()) {
|
||
311 | fileChooser.addChoosableFileFilter(iter.next()); |
||
312 | } |
||
313 | |||
314 | if (filters.size() > 0) { |
||
315 | MyFileFilter firstf = filters.get(0);
|
||
316 | // Set first filter
|
||
317 | fileChooser.setFileFilter(firstf); |
||
318 | } |
||
319 | |||
320 | // If there is a last filter, use it
|
||
321 | if (lastFilter != null && filters.contains(lastFilter)) { |
||
322 | fileChooser.setFileFilter(lastFilter); |
||
323 | } |
||
324 | |||
325 | int result = fileChooser.showOpenDialog(this); |
||
326 | |||
327 | 43534 | jjdelcerro | List<FilesystemStoreParameters> toAdd = new ArrayList<>(); |
328 | 43152 | fdiaz | |
329 | if (result == JFileChooser.APPROVE_OPTION) { |
||
330 | lastFilter = (MyFileFilter) fileChooser.getFileFilter(); |
||
331 | String providerName = null; |
||
332 | if( lastFilter!=null ) { |
||
333 | if( !DEFAULT_FILTER.equalsIgnoreCase(lastFilter.getDescription()) ) {
|
||
334 | providerName = lastFilter.getName(); |
||
335 | } |
||
336 | } |
||
337 | toAdd = this.getParametersList(
|
||
338 | fileChooser.getCurrentDirectory(), |
||
339 | fileChooser.getSelectedFiles(), |
||
340 | providerName |
||
341 | ); |
||
342 | } |
||
343 | return toAdd;
|
||
344 | } |
||
345 | |||
346 | |||
347 | private List<FilesystemStoreParameters> getParametersList(File folder, File[] files, String providerName) { |
||
348 | ApplicationManager application = ApplicationLocator.getManager(); |
||
349 | |||
350 | PrepareContext context = this.getPrepareDataStoreContext();
|
||
351 | |||
352 | 43534 | jjdelcerro | List<DataStoreParameters> params = new ArrayList<>(); |
353 | 43152 | fdiaz | List<DataStoreParameters> preparedParams = null; |
354 | 43534 | jjdelcerro | List<FilesystemStoreParameters> returnParams = new ArrayList<>(); |
355 | 43152 | fdiaz | |
356 | for ( File aFile : files ) { |
||
357 | String currentProvider = providerName;
|
||
358 | DataStoreParameters param; |
||
359 | try {
|
||
360 | if( folder == null) { |
||
361 | explorer.setCurrentPath(aFile.getParentFile()); |
||
362 | } else {
|
||
363 | explorer.setCurrentPath(folder); |
||
364 | } |
||
365 | if( currentProvider == null ) { |
||
366 | for( int i=1; i<this.filters.size(); i++) { |
||
367 | MyFileFilter filter = this.filters.get(i);
|
||
368 | if( filter.accept(aFile)) {
|
||
369 | currentProvider = filter.getName(); |
||
370 | break;
|
||
371 | } |
||
372 | } |
||
373 | } |
||
374 | if( currentProvider == null ) { |
||
375 | // TODO: ask user
|
||
376 | continue;
|
||
377 | } |
||
378 | param = explorer.createStoreParameters(aFile, currentProvider); |
||
379 | if ( param == null ) { |
||
380 | // TODO show warning
|
||
381 | continue;
|
||
382 | } |
||
383 | params.add(param); |
||
384 | |||
385 | } catch (DataException e) {
|
||
386 | NotificationManager.addError(e); |
||
387 | return null; |
||
388 | } |
||
389 | } |
||
390 | |||
391 | try {
|
||
392 | preparedParams |
||
393 | = application.prepareOpenDataStoreParameters(params, context); |
||
394 | } catch (Exception e) { |
||
395 | NotificationManager.addError(e); |
||
396 | } |
||
397 | |||
398 | if ( preparedParams != null ) { |
||
399 | for ( int i = 0; i < preparedParams.size(); i++ ) { |
||
400 | returnParams.add((FilesystemStoreParameters) preparedParams.get(i)); |
||
401 | } |
||
402 | } |
||
403 | return returnParams;
|
||
404 | } |
||
405 | |||
406 | /**
|
||
407 | * @return
|
||
408 | */
|
||
409 | protected PrepareContext getPrepareDataStoreContext() {
|
||
410 | return new PrepareContext() { |
||
411 | |||
412 | @Override
|
||
413 | public IProjection getViewProjection() {
|
||
414 | return FilesystemExplorerWizardPanelController.this.mapContext.getProjection();
|
||
415 | } |
||
416 | |||
417 | @Override
|
||
418 | public Window getOwnerWindow() { |
||
419 | return null; |
||
420 | } |
||
421 | }; |
||
422 | } |
||
423 | |||
424 | /**
|
||
425 | * @return DataStoreParameters[]
|
||
426 | */
|
||
427 | public DataStoreParameters[] getParameters() { |
||
428 | return ((FilesystemExplorerWizardTableModel)this.tableFiles.getModel()).getParameters(); |
||
429 | } |
||
430 | |||
431 | /**
|
||
432 | * @param files
|
||
433 | */
|
||
434 | public void addFiles(List<File> files) { |
||
435 | File[] filesArray = files.toArray(new File[files.size()]); |
||
436 | this.addFilesFromParameters(this.getParametersList(null, filesArray, null)); |
||
437 | } |
||
438 | |||
439 | private void addFilesFromParameters(List<FilesystemStoreParameters> filesParams) { |
||
440 | if ( filesParams.isEmpty() ) {
|
||
441 | return;
|
||
442 | } |
||
443 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel)this.tableFiles.getModel();
|
||
444 | 43321 | fdiaz | model.add(filesParams); |
445 | 43534 | jjdelcerro | updateChangeViewProjection(); |
446 | 43554 | jjdelcerro | this.updateTable();
|
447 | 43152 | fdiaz | } |
448 | |||
449 | /**
|
||
450 | * @param parameters
|
||
451 | * @return boolean
|
||
452 | */
|
||
453 | public boolean isTiled(DataStoreParameters parameters) { |
||
454 | return ((FilesystemExplorerWizardTableModel)this.tableFiles.getModel()).isTiled(parameters); |
||
455 | } |
||
456 | |||
457 | /**
|
||
458 | * @param explorer
|
||
459 | */
|
||
460 | public void setExplorer(FilesystemServerExplorer explorer) { |
||
461 | this.explorer = explorer;
|
||
462 | } |
||
463 | |||
464 | /**
|
||
465 | * @param filters
|
||
466 | */
|
||
467 | public void setFilters(ArrayList<MyFileFilter> filters) { |
||
468 | this.filters=filters;
|
||
469 | } |
||
470 | |||
471 | /**
|
||
472 | * Dispose filters and explorer.
|
||
473 | *
|
||
474 | */
|
||
475 | public void dispose() { |
||
476 | if (explorer != null) { |
||
477 | explorer.dispose(); |
||
478 | explorer = null;
|
||
479 | } |
||
480 | if (filters != null) { |
||
481 | filters.clear(); |
||
482 | filters = null;
|
||
483 | } |
||
484 | } |
||
485 | |||
486 | 43534 | jjdelcerro | private void updateChangeViewProjection() { |
487 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel) this.tableFiles.getModel();
|
||
488 | if (selectedIndex < 0 && selectedIndex >= model.getRowCount()) { |
||
489 | this.btnChangeViewProjection.setEnabled(false); |
||
490 | 43600 | jjdelcerro | return;
|
491 | 43534 | jjdelcerro | } |
492 | IProjection projection; |
||
493 | 43688 | jjdelcerro | if( model.getRowCount()>0 ) { |
494 | DynObject parameters = (DynObject) model.getParams(0);
|
||
495 | if( parameters.getDynClass().getDynField(DataStore.METADATA_CRS) != null ) { |
||
496 | projection = (IProjection) parameters.getDynValue(DataStore.METADATA_CRS); |
||
497 | if( mapContext == null || mapContext.getLayers().isEmpty() ) { |
||
498 | if( projection == null ) { |
||
499 | this.btnChangeViewProjection.setEnabled(false); |
||
500 | } else if( projection.equals(mapContext.getProjection()) ) { |
||
501 | this.btnChangeViewProjection.setEnabled(false); |
||
502 | } else {
|
||
503 | for( DataStoreParameters p : model.getParameters()) {
|
||
504 | projection = (IProjection) p.getDynValue(DataStore.METADATA_CRS); |
||
505 | if( projection != null ) { |
||
506 | String s = projection.getFullCode();
|
||
507 | if( s.contains("@") ) { |
||
508 | this.btnChangeViewProjection.setEnabled(false); |
||
509 | return;
|
||
510 | } |
||
511 | 43534 | jjdelcerro | } |
512 | } |
||
513 | 43688 | jjdelcerro | this.btnChangeViewProjection.setEnabled(true); |
514 | 43534 | jjdelcerro | } |
515 | } |
||
516 | } |
||
517 | } |
||
518 | } |
||
519 | |||
520 | private void doChangeViewProjection() { |
||
521 | FilesystemExplorerWizardTableModel model = (FilesystemExplorerWizardTableModel) this.tableFiles.getModel();
|
||
522 | if( model.getRowCount() <= 0 || |
||
523 | (selectedIndex < 0 && selectedIndex >= model.getRowCount()) ) {
|
||
524 | this.btnChangeViewProjection.setEnabled(false); |
||
525 | return;
|
||
526 | } |
||
527 | IProjection projection; |
||
528 | DynObject parameters = (DynObject) model.getParams(selectedIndex); |
||
529 | if( parameters.getDynClass().getDynField(DataStore.METADATA_CRS) != null ) { |
||
530 | projection = (IProjection) parameters.getDynValue(DataStore.METADATA_CRS); |
||
531 | if( mapContext == null || mapContext.getLayers().isEmpty() ) { |
||
532 | mapContext.setProjection(projection); |
||
533 | updateTable(); |
||
534 | } |
||
535 | } |
||
536 | } |
||
537 | 43152 | fdiaz | |
538 | 43534 | jjdelcerro | void setTabularOnly(boolean tabularOnly) { |
539 | this.tabularOnly = tabularOnly;
|
||
540 | this.btnChangeViewProjection.setVisible(!tabularOnly);
|
||
541 | } |
||
542 | 43152 | fdiaz | } |