root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / main / java / org / gvsig / wfs / gui / panels / WFSSelectFeaturePanel.java @ 10
History | View | Annotate | Download (38.4 KB)
1 |
package org.gvsig.wfs.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Component; |
5 |
import java.awt.Graphics; |
6 |
import java.awt.Point; |
7 |
import java.awt.Rectangle; |
8 |
import java.awt.event.MouseAdapter; |
9 |
import java.awt.event.MouseEvent; |
10 |
import java.io.IOException; |
11 |
import java.net.ConnectException; |
12 |
import java.text.Collator; |
13 |
import java.util.Collections; |
14 |
import java.util.List; |
15 |
import java.util.Locale; |
16 |
import java.util.Vector; |
17 |
|
18 |
import javax.swing.DefaultListSelectionModel; |
19 |
import javax.swing.JCheckBox; |
20 |
import javax.swing.JComponent; |
21 |
import javax.swing.JLabel; |
22 |
import javax.swing.JOptionPane; |
23 |
import javax.swing.JPanel; |
24 |
import javax.swing.JScrollPane; |
25 |
import javax.swing.JTable; |
26 |
import javax.swing.JTextField; |
27 |
import javax.swing.ListSelectionModel; |
28 |
import javax.swing.UIManager; |
29 |
import javax.swing.event.DocumentEvent; |
30 |
import javax.swing.event.DocumentListener; |
31 |
import javax.swing.event.ListSelectionListener; |
32 |
import javax.swing.plaf.basic.BasicTableHeaderUI; |
33 |
import javax.swing.table.AbstractTableModel; |
34 |
import javax.swing.table.DefaultTableCellRenderer; |
35 |
import javax.swing.table.TableCellRenderer; |
36 |
import javax.swing.table.TableColumn; |
37 |
import javax.swing.table.TableColumnModel; |
38 |
import javax.swing.table.TableModel; |
39 |
|
40 |
import org.gvsig.andami.PluginServices; |
41 |
import org.gvsig.andami.messages.NotificationManager; |
42 |
import org.gvsig.app.ApplicationLocator; |
43 |
import org.gvsig.gui.beans.panelGroup.IPanelGroup; |
44 |
import org.gvsig.i18n.Messages; |
45 |
import org.gvsig.remoteclient.wfs.WFSFeatureField; |
46 |
import org.gvsig.remoteclient.wfs.WFSProtocolHandlerFactory; |
47 |
import org.gvsig.utils.StringComparator; |
48 |
import org.gvsig.wfs.gui.panels.WFSSelectFeaturePanel.LayerTable.LayerTableModel; |
49 |
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature; |
50 |
import org.gvsig.wfs.gui.wizards.WFSWizard; |
51 |
|
52 |
|
53 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
54 |
*
|
55 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
56 |
*
|
57 |
* This program is free software; you can redistribute it and/or
|
58 |
* modify it under the terms of the GNU General Public License
|
59 |
* as published by the Free Software Foundation; either version 2
|
60 |
* of the License, or (at your option) any later version.
|
61 |
*
|
62 |
* This program is distributed in the hope that it will be useful,
|
63 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
64 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
65 |
* GNU General Public License for more details.
|
66 |
*
|
67 |
* You should have received a copy of the GNU General Public License
|
68 |
* along with this program; if not, write to the Free Software
|
69 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
70 |
*
|
71 |
* For more information, contact:
|
72 |
*
|
73 |
* Generalitat Valenciana
|
74 |
* Conselleria d'Infraestructures i Transport
|
75 |
* Av. Blasco Ib??ez, 50
|
76 |
* 46010 VALENCIA
|
77 |
* SPAIN
|
78 |
*
|
79 |
* +34 963862235
|
80 |
* gvsig@gva.es
|
81 |
* www.gvsig.gva.es
|
82 |
*
|
83 |
* or
|
84 |
*
|
85 |
* IVER T.I. S.A
|
86 |
* Salamanca 50
|
87 |
* 46005 Valencia
|
88 |
* Spain
|
89 |
*
|
90 |
* +34 963163400
|
91 |
* dac@iver.es
|
92 |
*/
|
93 |
/* CVS MESSAGES:
|
94 |
*
|
95 |
* $Id: WFSSelectFeaturePanel.java 18799 2008-02-12 16:53:03Z vcaballero $
|
96 |
* $Log$
|
97 |
* Revision 1.19 2007-09-19 16:14:50 jaume
|
98 |
* removed unnecessary imports
|
99 |
*
|
100 |
* Revision 1.18 2007/03/15 13:34:16 ppiqueras
|
101 |
* Eliminado mensaje de aviso no necesario.
|
102 |
*
|
103 |
* Revision 1.17 2007/03/05 13:49:42 ppiqueras
|
104 |
* Si una capa WFS no tiene campos (y por tanto no tiene un campo obligatorio de tipo geometr?a), que avise al usuario y no permita que se intente cargar dicha capa.
|
105 |
*
|
106 |
* Revision 1.16 2007/02/22 12:25:09 ppiqueras
|
107 |
* A?adidas tool tip text.
|
108 |
*
|
109 |
* Revision 1.15 2007/02/09 14:12:39 jorpiell
|
110 |
* Soporte para WFS 1.1 y WFS-T
|
111 |
*
|
112 |
* Revision 1.14 2007/02/07 13:26:23 ppiqueras
|
113 |
* Corregido bug: al seleccionar una feature, pero sin cerrar el di?logo, se retrocede y se conecta a otro servidor, se manten?a la posici?n seleccionada en la tabla de features. Se ha solucionado haciendo que se quede deseleccionada toda la tabla de features.
|
114 |
*
|
115 |
* Revision 1.13 2007/01/23 13:12:43 ppiqueras
|
116 |
* Corregido un peque?o bug: el ?rea de texto del nombre de la feature no debe ser editable, dado que si se edita no procesa el texto escrito.
|
117 |
*
|
118 |
* Revision 1.12 2007/01/15 14:16:22 ppiqueras
|
119 |
* Corregido bug: no cargaba los campos al principio y adem?s se ejecutaba m?s de una vez.
|
120 |
*
|
121 |
* Revision 1.11 2006/12/15 13:57:34 ppiqueras
|
122 |
* eliminado un import que sobraba
|
123 |
*
|
124 |
* Revision 1.10 2006/12/12 10:24:45 ppiqueras
|
125 |
* Nueva funcionalidad: Pulsando doble 'click' sobre una capa de un servidor, se carga (igual que antes), pero adem?s se avanza a la siguiente pesta?a sin tener que pulsar el bot?n 'Siguiente'.
|
126 |
*
|
127 |
* Revision 1.9 2006/12/04 08:59:47 ppiqueras
|
128 |
* Algunos bugs corregidos. A cambio hay 2 bugs relacionados que todav?a no han sido corregidos (ver PHPCollab) (los tiene asignados Jorge).
|
129 |
*
|
130 |
* Revision 1.8 2006/10/27 06:44:56 jorpiell
|
131 |
* Se han cambiado algunas etiquetas de texto que sal?an recortadas
|
132 |
*
|
133 |
* Revision 1.7 2006/07/21 11:50:31 jaume
|
134 |
* improved appearance
|
135 |
*
|
136 |
* Revision 1.6 2006/06/21 12:35:45 jorpiell
|
137 |
* Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
|
138 |
*
|
139 |
* Revision 1.5 2006/05/25 10:31:06 jorpiell
|
140 |
* Como ha cambiado la forma de mostrar las capas (una tabla, en lugar de una lista), los paneles han tenido que ser modificados
|
141 |
*
|
142 |
* Revision 1.4 2006/05/23 08:09:39 jorpiell
|
143 |
* Se ha cambiado la forma en la que se leian los valores seleccionados en los paneles y se ha cambiado el comportamiento de los botones
|
144 |
*
|
145 |
* Revision 1.3 2006/05/19 12:57:08 jorpiell
|
146 |
* Modificados algunos paneles
|
147 |
*
|
148 |
* Revision 1.2 2006/04/20 16:38:24 jorpiell
|
149 |
* Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
|
150 |
*
|
151 |
*
|
152 |
*/
|
153 |
|
154 |
|
155 |
/**
|
156 |
* <p>Panel where user can select a feature type to load as a WFS layer.</p>
|
157 |
*
|
158 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
159 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
160 |
*/
|
161 |
public class WFSSelectFeaturePanel extends AbstractWFSPanel { |
162 |
private static final long serialVersionUID = -3781080396069038450L; |
163 |
private JPanel featureListPanel = null; |
164 |
private JScrollPane jScrollPane = null; |
165 |
private LayerTable lstFeatures = null; |
166 |
private JTextField txtName = null; |
167 |
private JCheckBox chkExtendedNames = null; |
168 |
private JPanel layerNamePanel = null; |
169 |
private WFSSelectedFeature layerNode = null; |
170 |
private ListSelectionListener listSelectionListener = null; |
171 |
|
172 |
/**
|
173 |
* Creates a new WFS select feature panel.
|
174 |
*/
|
175 |
public WFSSelectFeaturePanel() {
|
176 |
super();
|
177 |
initialize(); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* This method initializes coveragesListPanel
|
182 |
*
|
183 |
* @return javax.swing.JPanel
|
184 |
*/
|
185 |
private JPanel getFeaturesListPanel() { |
186 |
if (featureListPanel == null) { |
187 |
java.awt.GridBagConstraints gridBagConstraints; |
188 |
featureListPanel = new JPanel(); |
189 |
featureListPanel.setLayout(new java.awt.GridBagLayout());
|
190 |
featureListPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
191 |
null, PluginServices.getText(this, "select_features"), |
192 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
193 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
194 |
|
195 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
196 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
197 |
gridBagConstraints.weightx = 1.0;
|
198 |
gridBagConstraints.weighty = 1.0;
|
199 |
featureListPanel.add(getJScrollPane(), gridBagConstraints); |
200 |
} |
201 |
|
202 |
return featureListPanel;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* This method initializes jScrollPane
|
207 |
*
|
208 |
* @return javax.swing.JScrollPane
|
209 |
*/
|
210 |
private JScrollPane getJScrollPane() { |
211 |
if (jScrollPane == null) { |
212 |
jScrollPane = new JScrollPane(); |
213 |
jScrollPane.setViewportView(getLstFeatures()); |
214 |
jScrollPane.setToolTipText(PluginServices.getText(jScrollPane, "feature_Selection_Info"));
|
215 |
} |
216 |
|
217 |
return jScrollPane;
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* This method initializes lstFeatures
|
222 |
*
|
223 |
* @return javax.swing.LayerTable
|
224 |
*/
|
225 |
public LayerTable getLstFeatures() {
|
226 |
if (lstFeatures == null) { |
227 |
lstFeatures = new LayerTable();
|
228 |
lstFeatures.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
229 |
lstFeatures.getSelectionModel().addListSelectionListener(getListSelectionListener()); |
230 |
lstFeatures.setToolTipText(PluginServices.getText(lstFeatures, "feature_Selection_Info"));
|
231 |
|
232 |
// Double-click -> click the 'Next' button
|
233 |
lstFeatures.addMouseListener(new MouseAdapter() { |
234 |
/*
|
235 |
* (non-Javadoc)
|
236 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
237 |
*/
|
238 |
public void mouseClicked(MouseEvent e) { |
239 |
if (e.getClickCount() == 2) { |
240 |
Object obj = getPanelGroup();
|
241 |
|
242 |
if ((obj != null) && (obj instanceof WFSParamsPanel)) |
243 |
((WFSParamsPanel)obj).doClickOnNextButton(); |
244 |
} |
245 |
} |
246 |
}); |
247 |
} |
248 |
|
249 |
return lstFeatures;
|
250 |
} |
251 |
|
252 |
public int getSelectedFeaturesCount() { |
253 |
|
254 |
if (lstFeatures == null) { |
255 |
return 0; |
256 |
} |
257 |
|
258 |
ListSelectionModel m = lstFeatures.getSelectionModel();
|
259 |
if (m == null || m.isSelectionEmpty()) { |
260 |
return 0; |
261 |
} else {
|
262 |
int resp = 0; |
263 |
for (int i = m.getMinSelectionIndex(); |
264 |
i <= m.getMaxSelectionIndex(); |
265 |
i++) { |
266 |
|
267 |
if (m.isSelectedIndex(i)) {
|
268 |
resp++; |
269 |
} |
270 |
} |
271 |
return resp;
|
272 |
} |
273 |
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* Creates the list selection listener for the layers list
|
278 |
*
|
279 |
* @return the listener
|
280 |
*/
|
281 |
private ListSelectionListener getListSelectionListener(){ |
282 |
if (listSelectionListener == null){ |
283 |
listSelectionListener = new ListSelectionListener(){ |
284 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
285 |
DefaultListSelectionModel model = (DefaultListSelectionModel) e.getSource(); |
286 |
LayerTableModel t_model = ((LayerTableModel)lstFeatures.getModel()); |
287 |
if (t_model.isUpdatingSelection())
|
288 |
return;
|
289 |
|
290 |
// With this condition we force to execute the updating only when a row has been selected by the user
|
291 |
if ((model.getMinSelectionIndex() > -1) && (e.getValueIsAdjusting() == false)) { |
292 |
// Indicate that now we are loading a new layer
|
293 |
IPanelGroup panelGroup = getPanelGroup(); |
294 |
|
295 |
if (panelGroup == null) |
296 |
return;
|
297 |
|
298 |
if (((WFSParamsPanel)panelGroup).getFilterPanel() == null) |
299 |
return;
|
300 |
|
301 |
refreshData(); |
302 |
} |
303 |
|
304 |
// =============================================
|
305 |
// If zero selected, settings are invalid
|
306 |
int n_sel = getSelectedFeaturesCount();
|
307 |
if (n_sel == 0) { |
308 |
Object obj = getPanelGroup();
|
309 |
if (obj != null && obj instanceof WFSParamsPanel) { |
310 |
obj = ((WFSParamsPanel) obj).getParent(); |
311 |
if (obj instanceof WFSWizard) { |
312 |
((WFSWizard) obj).callStateChanged(false);
|
313 |
} |
314 |
} |
315 |
} |
316 |
// =============================================
|
317 |
} |
318 |
}; |
319 |
} |
320 |
|
321 |
return listSelectionListener;
|
322 |
} |
323 |
|
324 |
/**
|
325 |
* This method initializes jTextField
|
326 |
*
|
327 |
* @return javax.swing.JTextField
|
328 |
*/
|
329 |
public JTextField getTxtName() { |
330 |
if (txtName == null) { |
331 |
txtName = new JTextField(); |
332 |
txtName.setBounds(6, 19, 472, 20); |
333 |
txtName.setText(PluginServices.getText(this, "WFSLayer")); |
334 |
txtName.setEditable(false);
|
335 |
txtName.setBackground(Color.WHITE);
|
336 |
txtName.setToolTipText(PluginServices.getText(txtName, "feature_to_load"));
|
337 |
|
338 |
txtName.getDocument().addDocumentListener(new DocumentListener() { |
339 |
/*
|
340 |
* (non-Javadoc)
|
341 |
* @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
|
342 |
*/
|
343 |
public void changedUpdate(DocumentEvent e) { |
344 |
} |
345 |
|
346 |
/*
|
347 |
* (non-Javadoc)
|
348 |
* @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
|
349 |
*/
|
350 |
public void insertUpdate(DocumentEvent e) { |
351 |
IPanelGroup panelGroup = getPanelGroup(); |
352 |
|
353 |
if (panelGroup == null) |
354 |
return;
|
355 |
|
356 |
((WFSParamsPanel)panelGroup).setApplicable(true);
|
357 |
} |
358 |
|
359 |
/*
|
360 |
* (non-Javadoc)
|
361 |
* @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
|
362 |
*/
|
363 |
public void removeUpdate(DocumentEvent e) { |
364 |
} |
365 |
}); |
366 |
} |
367 |
|
368 |
return txtName;
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* This method initializes chkExtendedNames
|
373 |
*
|
374 |
* @return javax.swing.JCheckBox
|
375 |
*/
|
376 |
private JCheckBox getChkExtendedNames() { |
377 |
if (chkExtendedNames == null) { |
378 |
chkExtendedNames = new JCheckBox(); |
379 |
chkExtendedNames.setText(PluginServices.getText(this, "show_layer_names")); |
380 |
chkExtendedNames.setBounds(10, 372, 382, 20); |
381 |
chkExtendedNames.addItemListener(new java.awt.event.ItemListener() {
|
382 |
/*
|
383 |
* (non-Javadoc)
|
384 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
385 |
*/
|
386 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
387 |
boolean b = chkExtendedNames.isSelected();
|
388 |
getLstFeatures().setShowLayerNames(b); |
389 |
getLstFeatures().repaint(); |
390 |
} |
391 |
}); |
392 |
} |
393 |
|
394 |
return chkExtendedNames;
|
395 |
} |
396 |
|
397 |
/**
|
398 |
* Set the selected layer node
|
399 |
*
|
400 |
* @param layerNode the layer to select
|
401 |
*/
|
402 |
public void setSelectedFeature(WFSSelectedFeature layerNode){ |
403 |
int index = -1; |
404 |
|
405 |
for (int i=0; i<getLstFeatures().getRowCount(); i++){ |
406 |
WFSSelectedFeature node = (WFSSelectedFeature)getLstFeatures().getValueAt(i); |
407 |
|
408 |
if (node != null && layerNode.getName().equals(node.getName())){ |
409 |
index = i; |
410 |
} |
411 |
} |
412 |
|
413 |
if (index != -1){ |
414 |
getLstFeatures().changeSelection(index, 0, false, false); |
415 |
} |
416 |
} |
417 |
|
418 |
/**
|
419 |
* Refresh the features list
|
420 |
*/
|
421 |
public void refresh(WFSSelectedFeature layer) { |
422 |
// Unselects all features
|
423 |
unselectAllFeatures(); |
424 |
|
425 |
// Add the new features
|
426 |
getLstFeatures().addFeatures(getSelectedFeatureManager().getLayerList()); |
427 |
|
428 |
if (layer != null) { |
429 |
layerNode = layer; |
430 |
setLayerName(layer.getName()); |
431 |
setSelectedFeature(layer); |
432 |
} |
433 |
} |
434 |
|
435 |
/**
|
436 |
* Refreshes the wizard components data each time a feature
|
437 |
* is selected. The <i>describeFeatureType</i> operation must be sent.
|
438 |
*/
|
439 |
public void refreshData() { |
440 |
WFSSelectedFeature lyr = (WFSSelectedFeature)getLstFeatures().getSelectedValue(); |
441 |
|
442 |
try {
|
443 |
getTxtName().setText(lyr.getTitle()); |
444 |
} catch (NullPointerException e){ |
445 |
getTxtName().setText(PluginServices.getText(this,"default_name")); |
446 |
NotificationManager.addError(PluginServices.getText(this,"default_name"), e); |
447 |
} |
448 |
|
449 |
IPanelGroup panelGroup = getPanelGroup(); |
450 |
|
451 |
if (panelGroup == null) |
452 |
return;
|
453 |
|
454 |
WFSParamsPanel wfspp = (WFSParamsPanel) panelGroup; |
455 |
|
456 |
String url = wfspp.getServerExplorer().getUrl();
|
457 |
List sel_ver = null; |
458 |
|
459 |
try {
|
460 |
sel_ver = WFSProtocolHandlerFactory.getRequestableVersions(url); |
461 |
wfspp.refresh(lyr, sel_ver); |
462 |
} catch (Exception e) { |
463 |
ApplicationLocator.getManager().message( |
464 |
Messages.getText("_Unable_to_get_server_version"),
|
465 |
JOptionPane.ERROR_MESSAGE);
|
466 |
} |
467 |
|
468 |
|
469 |
repaint(); |
470 |
} |
471 |
|
472 |
/**
|
473 |
* This method initializes layerNamePanel
|
474 |
*
|
475 |
* @return javax.swing.JPanel
|
476 |
*/
|
477 |
private JPanel getLayerNamePanel() { |
478 |
if (layerNamePanel == null) { |
479 |
java.awt.GridBagConstraints gridBagConstraints; |
480 |
layerNamePanel = new JPanel(); |
481 |
layerNamePanel.setLayout(new java.awt.GridBagLayout());
|
482 |
layerNamePanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
483 |
null, PluginServices.getText(this, "layer_name"), |
484 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
485 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
486 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
487 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
488 |
gridBagConstraints.weightx = 1.0;
|
489 |
layerNamePanel.add(getTxtName(), gridBagConstraints); |
490 |
} |
491 |
|
492 |
return layerNamePanel;
|
493 |
} |
494 |
|
495 |
/**
|
496 |
* Gets the name of the layer (feature) selected.
|
497 |
*
|
498 |
* @return the layer name
|
499 |
*/
|
500 |
public String getLayerName() { |
501 |
if ((WFSSelectedFeature)getLstFeatures().getSelectedValue() != null){ |
502 |
return ((WFSSelectedFeature)getLstFeatures().getSelectedValue()).getName();
|
503 |
} |
504 |
return ""; |
505 |
} |
506 |
|
507 |
/**
|
508 |
* Gets the name space of the layer (feature) selected.
|
509 |
*
|
510 |
* @return the name space
|
511 |
*/
|
512 |
public String getLayerNameSpace(){ |
513 |
return ((WFSSelectedFeature)getLstFeatures().getSelectedValue()).getNameSpace();
|
514 |
} |
515 |
|
516 |
/**
|
517 |
* Gets the selected feature.
|
518 |
*
|
519 |
* @return the selected feature
|
520 |
*/
|
521 |
public WFSSelectedFeature getSelectedFeature() {
|
522 |
WFSSelectedFeature selectedFeature = (WFSSelectedFeature)getLstFeatures().getSelectedValue(); |
523 |
|
524 |
if (selectedFeature != null) { |
525 |
layerNode = selectedFeature; |
526 |
} |
527 |
|
528 |
return layerNode;
|
529 |
} |
530 |
|
531 |
/**
|
532 |
* Sets the name of the feature selected.
|
533 |
*
|
534 |
* @param name the name of the feature selected
|
535 |
*/
|
536 |
public void setLayerName(String name) { |
537 |
getTxtName().setText(name); |
538 |
} |
539 |
|
540 |
/*
|
541 |
* (non-Javadoc)
|
542 |
* @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#initialize()
|
543 |
*/
|
544 |
protected void initialize() { |
545 |
setLabel(PluginServices.getText(this, "feature")); |
546 |
setLabelGroup(PluginServices.getText(this, "wfs")); |
547 |
java.awt.GridBagConstraints gridBagConstraints; |
548 |
this.setLayout(new java.awt.GridBagLayout()); |
549 |
|
550 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
551 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
552 |
gridBagConstraints.weightx = 1.0;
|
553 |
this.add(getLayerNamePanel(), gridBagConstraints);
|
554 |
|
555 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
556 |
gridBagConstraints.gridx = 0;
|
557 |
gridBagConstraints.gridy = 1;
|
558 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
559 |
gridBagConstraints.weightx = 1.0;
|
560 |
gridBagConstraints.weighty = 1.0;
|
561 |
this.add(getFeaturesListPanel(), gridBagConstraints);
|
562 |
|
563 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
564 |
gridBagConstraints.gridx = 0;
|
565 |
gridBagConstraints.gridy = 2;
|
566 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
567 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
568 |
gridBagConstraints.weightx = 1.0;
|
569 |
this.add(getChkExtendedNames(), gridBagConstraints);
|
570 |
|
571 |
} |
572 |
|
573 |
/*
|
574 |
* (non-Javadoc)
|
575 |
* @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#setReference(java.lang.Object)
|
576 |
*/
|
577 |
public void setReference(Object ref) { |
578 |
super.setReference(ref);
|
579 |
// if (ref instanceof FLyrWFS){
|
580 |
// getPanelGroup().setEnabledApplyButton(false);
|
581 |
// }
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* Updates the list with no feature selected.
|
586 |
*/
|
587 |
public void unselectAllFeatures() { |
588 |
// Reset the last row selection of the features table
|
589 |
int numberOfFeatures = getLstFeatures().getRowCount();
|
590 |
|
591 |
if (numberOfFeatures > 0) { |
592 |
ListSelectionModel model = getLstFeatures().getSelectionModel();
|
593 |
model.removeSelectionInterval(0, numberOfFeatures - 1); // whatever row selection |
594 |
} |
595 |
} |
596 |
|
597 |
/**
|
598 |
* Table with the information of all layers which could be selected from the server connected.
|
599 |
*
|
600 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
601 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
602 |
*/
|
603 |
public class LayerTable extends JTable { |
604 |
private static final long serialVersionUID = 4700375945858283696L; |
605 |
private int headerSelected = -1; |
606 |
|
607 |
/**
|
608 |
* Creates a new instance of <code>LayerTable</code>
|
609 |
*/
|
610 |
public LayerTable() {
|
611 |
super();
|
612 |
|
613 |
setModel(new LayerTableModel());
|
614 |
|
615 |
getTableHeader().setUI(new BasicTableHeaderSelectableUI());
|
616 |
|
617 |
getTableHeader().addMouseListener(new MouseAdapter() { |
618 |
/*
|
619 |
* (non-Javadoc)
|
620 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
621 |
*/
|
622 |
public void mouseClicked(MouseEvent e) { |
623 |
// Sorts according the selected column
|
624 |
((LayerTableModel)getModel()).sort(getTableHeader().getColumnModel().getColumnIndexAtX(e.getX())); |
625 |
} |
626 |
|
627 |
/*
|
628 |
* (non-Javadoc)
|
629 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
630 |
*/
|
631 |
public void mousePressed(MouseEvent e) { |
632 |
headerSelected = getTableHeader().getColumnModel().getColumnIndexAtX(e.getX()); |
633 |
getTableHeader().repaint(); |
634 |
} |
635 |
|
636 |
/*
|
637 |
* (non-Javadoc)
|
638 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
639 |
*/
|
640 |
public void mouseReleased(MouseEvent e) { |
641 |
headerSelected = -1;
|
642 |
} |
643 |
}); |
644 |
} |
645 |
|
646 |
/*
|
647 |
* (non-Javadoc)
|
648 |
* @see javax.swing.JTable#createDefaultColumnsFromModel()
|
649 |
*/
|
650 |
public void createDefaultColumnsFromModel() { |
651 |
TableModel m = getModel();
|
652 |
if (m != null) { |
653 |
// Remove any current columns
|
654 |
TableColumnModel cm = getColumnModel();
|
655 |
while (cm.getColumnCount() > 0) { |
656 |
cm.removeColumn(cm.getColumn(0));
|
657 |
} |
658 |
|
659 |
// Create new columns from the data model info
|
660 |
for (int i = 0; i < m.getColumnCount(); i++) { |
661 |
TableColumn newColumn = new TableColumn(i); |
662 |
|
663 |
// Special renderer for supporting selection of a particular column header
|
664 |
newColumn.setHeaderRenderer(new DefaultTableSelectableCellRenderer());
|
665 |
addColumn(newColumn); |
666 |
} |
667 |
} |
668 |
} |
669 |
|
670 |
/**
|
671 |
* Gets the selected <i>WFS</i> layer.
|
672 |
*
|
673 |
* @return node of the selected <i>WFS</i> layer
|
674 |
*/
|
675 |
public WFSSelectedFeature getSelectedValue() {
|
676 |
int selectedRow = getSelectedRow();
|
677 |
LayerTableModel model = (LayerTableModel)getModel(); |
678 |
|
679 |
return model.getLayerAt(selectedRow);
|
680 |
} |
681 |
|
682 |
/**
|
683 |
* Gets the layer at a row position.
|
684 |
*
|
685 |
* @return node of the selected <i>WFS</i> layer
|
686 |
*/
|
687 |
public WFSSelectedFeature getValueAt(int position) { |
688 |
if (position < this.getRowCount()) { |
689 |
LayerTableModel model = (LayerTableModel)getModel(); |
690 |
|
691 |
return model.getLayerAt(position);
|
692 |
} |
693 |
|
694 |
return null; |
695 |
} |
696 |
|
697 |
/**
|
698 |
* Adds the available features to load as a <i>WFS</i> layer.
|
699 |
*
|
700 |
* @param features available features
|
701 |
*/
|
702 |
public void addFeatures(WFSSelectedFeature[] features) { |
703 |
LayerTableModel model = (LayerTableModel)getModel(); |
704 |
model.deleteAllRows(); |
705 |
|
706 |
for (int i=0 ; i < features.length ; i++){ |
707 |
model.addRow(features[i]); |
708 |
} |
709 |
} |
710 |
|
711 |
/**
|
712 |
* Shows the names of the features.
|
713 |
*
|
714 |
* @param showFeatureNameType The showLayerNames to set.
|
715 |
*/
|
716 |
public void setShowLayerNames(boolean showFeatureNameType) { |
717 |
LayerTableModel model = (LayerTableModel)getModel(); |
718 |
model.setShowedFeatureNameType(showFeatureNameType); |
719 |
} |
720 |
|
721 |
/**
|
722 |
* Model of the <code>LayerTable</code> that stores the features available to load as a WFS layer.
|
723 |
*
|
724 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
725 |
* @author Pablo Piqueras Bartolome (pablo.piqueras@iver.es)
|
726 |
*/
|
727 |
public class LayerTableModel extends AbstractTableModel { |
728 |
private static final long serialVersionUID = 2722138264867593508L; |
729 |
private Vector<WFSSelectedFeature> layers = new Vector<WFSSelectedFeature>(); |
730 |
private boolean showFeatureNameType = false; |
731 |
private WFSLayerStringComparator stringComparator;
|
732 |
private boolean updatingSelection; |
733 |
private short previousColumnSorted; |
734 |
|
735 |
|
736 |
/**
|
737 |
* Constructs an investment table model.
|
738 |
*/
|
739 |
public LayerTableModel(){
|
740 |
super();
|
741 |
|
742 |
// Alphabetical sort ordering support
|
743 |
updatingSelection = false;
|
744 |
previousColumnSorted = -1;
|
745 |
Collator collator = Collator.getInstance(new Locale("en_EN")); |
746 |
stringComparator = new WFSLayerStringComparator();
|
747 |
stringComparator.setLocaleRules(stringComparator.new LocaleRules(true, collator));
|
748 |
stringComparator.setCaseSensitive(false);
|
749 |
stringComparator.setAscendingOrdering(true);
|
750 |
} |
751 |
|
752 |
|
753 |
/*
|
754 |
* (non-Javadoc)
|
755 |
* @see javax.swing.table.TableModel#getRowCount()
|
756 |
*/
|
757 |
public int getRowCount(){ |
758 |
return layers.size();
|
759 |
} |
760 |
|
761 |
/*
|
762 |
* (non-Javadoc)
|
763 |
* @see javax.swing.table.TableModel#getColumnCount()
|
764 |
*/
|
765 |
public int getColumnCount(){ |
766 |
return 2; |
767 |
} |
768 |
|
769 |
/*
|
770 |
* (non-Javadoc)
|
771 |
* @see javax.swing.table.TableModel#getValueAt(int, int)
|
772 |
*/
|
773 |
public Object getValueAt(int rowNumber, int columnNumber){ |
774 |
if (rowNumber < layers.size()) {
|
775 |
WFSSelectedFeature layer = (WFSSelectedFeature)layers.get(rowNumber); |
776 |
|
777 |
if (columnNumber == 0) { |
778 |
return getLayerName(layer);
|
779 |
} else {
|
780 |
if (layer.getGeometryField() != null){ |
781 |
return PluginServices.getText(this, layer.getGeometryField().getType()); |
782 |
} |
783 |
return ""; |
784 |
} |
785 |
} else {
|
786 |
return ""; |
787 |
} |
788 |
} |
789 |
|
790 |
/**
|
791 |
* Gets the layer name displaying the type name of the feature collection associated if it's needed.
|
792 |
*
|
793 |
* @param layer a <i>WFS</i> layer
|
794 |
* @return the layer name
|
795 |
*/
|
796 |
private String getLayerName(WFSSelectedFeature layer){ |
797 |
if (showFeatureNameType){
|
798 |
return "[" + layer.getName() + "] " + layer.getTitle(); |
799 |
} else {
|
800 |
return layer.getTitle();
|
801 |
} |
802 |
} |
803 |
|
804 |
/**
|
805 |
* Gets the layer at the specified position.
|
806 |
*
|
807 |
* @param rowNumber row position
|
808 |
* @return <i>WFS</i> layer node
|
809 |
*/
|
810 |
public WFSSelectedFeature getLayerAt(int rowNumber){ |
811 |
try {
|
812 |
if (rowNumber == -1) |
813 |
return null; |
814 |
|
815 |
return (WFSSelectedFeature)layers.get(rowNumber);
|
816 |
} catch (ArrayIndexOutOfBoundsException e) { |
817 |
NotificationManager.addError(e); |
818 |
return null; |
819 |
} |
820 |
} |
821 |
|
822 |
/**
|
823 |
* Adds a new layer to the table model, each table will be represented as a row.
|
824 |
*
|
825 |
* @param layer a new <i>WFS</i> layer
|
826 |
*/
|
827 |
public void addRow(WFSSelectedFeature layer){ |
828 |
layers.add(layer); |
829 |
fireTableRowsInserted(getRowCount(), getRowCount()); |
830 |
fireTableRowsUpdated(0,getRowCount());
|
831 |
} |
832 |
|
833 |
/**
|
834 |
* Deletes all the table rows.
|
835 |
*/
|
836 |
public void deleteAllRows(){ |
837 |
layers.clear(); |
838 |
int rows = getRowCount();
|
839 |
|
840 |
if (rows >= 1){ |
841 |
fireTableRowsDeleted(0, rows - 1); |
842 |
} |
843 |
} |
844 |
|
845 |
/**
|
846 |
* Delete all the table rows
|
847 |
*/
|
848 |
public void deleteRow(int rowPosition){ |
849 |
layers.remove(rowPosition); |
850 |
fireTableRowsDeleted(rowPosition, rowPosition); |
851 |
fireTableRowsUpdated(0,getRowCount());
|
852 |
} |
853 |
|
854 |
/*
|
855 |
* (non-Javadoc)
|
856 |
* @see javax.swing.table.TableModel#getColumnName(int)
|
857 |
*/
|
858 |
public String getColumnName(int columnIndex){ |
859 |
if (columnIndex == 0){ |
860 |
return PluginServices.getText(this, "layerName"); |
861 |
}else{
|
862 |
return PluginServices.getText(this, "layerType"); |
863 |
} |
864 |
} |
865 |
|
866 |
/**
|
867 |
* Gets if shows the feature name type.
|
868 |
*
|
869 |
* @return <code>true</code> if shows the feature name type; <code>false</code> otherwise
|
870 |
*/
|
871 |
public boolean isShowedFeatureNameType() { |
872 |
return showFeatureNameType;
|
873 |
} |
874 |
|
875 |
/**
|
876 |
* Gets if shows the feature name type.
|
877 |
*
|
878 |
* @param showFeatureNameType <code>true</code> if shows the feature name type; <code>false</code> otherwise
|
879 |
*/
|
880 |
public void setShowedFeatureNameType(boolean showFeatureNameType) { |
881 |
this.showFeatureNameType = showFeatureNameType;
|
882 |
|
883 |
this.stringComparator.setShowFeatureNameType(showFeatureNameType);
|
884 |
} |
885 |
|
886 |
/**
|
887 |
* Sorts the rows of the table alphabetically.
|
888 |
*
|
889 |
* @param column index of the column to sort. In this table there are only 2 columns.
|
890 |
*/
|
891 |
public void sort(int column) { |
892 |
// Orders the layer alphabetically according the Spanish alphabetically rules
|
893 |
switch(column) {
|
894 |
case 0: |
895 |
stringComparator.setColumn(WFSLayerStringComparator.LAYER_NAME); |
896 |
break;
|
897 |
case 1: |
898 |
stringComparator.setColumn(WFSLayerStringComparator.GEOMETRY_TYPE); |
899 |
break;
|
900 |
} |
901 |
|
902 |
if (previousColumnSorted != column)
|
903 |
stringComparator.setAscendingOrdering(true);
|
904 |
|
905 |
previousColumnSorted = (short) column;
|
906 |
|
907 |
WFSSelectedFeature layer = getSelectedValue(); |
908 |
|
909 |
Collections.sort(layers, stringComparator);
|
910 |
|
911 |
if (layer != null) { |
912 |
updatingSelection = true;
|
913 |
unselectAllFeatures(); |
914 |
int row = Collections.binarySearch(layers, layer, stringComparator); |
915 |
|
916 |
if (row != -1) { |
917 |
ListSelectionModel model = getSelectionModel();
|
918 |
model.setLeadSelectionIndex(row); |
919 |
} |
920 |
|
921 |
updatingSelection = false;
|
922 |
} |
923 |
stringComparator.setAscendingOrdering(!stringComparator.isAscendingOrdering()); |
924 |
} |
925 |
|
926 |
/**
|
927 |
* Determines if now is updating the selection of the previous selected item.
|
928 |
*
|
929 |
* @return <code>true</code> if now is updating the selection of the previous selected item; otherwise <code>false</code>
|
930 |
*/
|
931 |
public boolean isUpdatingSelection() { |
932 |
return updatingSelection;
|
933 |
} |
934 |
} |
935 |
|
936 |
/**
|
937 |
* <p>Enhances {@link BasicTableHeaderUI BasicTableHeaderUI} adding support for column head selection.</p>
|
938 |
*
|
939 |
* @see BasicTableHeaderUI
|
940 |
*
|
941 |
* @version 29/01/2008
|
942 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
943 |
*/
|
944 |
private class BasicTableHeaderSelectableUI extends BasicTableHeaderUI { |
945 |
/**
|
946 |
* Creates a new BasicTableHeaderSelectableUI object
|
947 |
*/
|
948 |
public BasicTableHeaderSelectableUI() {
|
949 |
super();
|
950 |
} |
951 |
|
952 |
//
|
953 |
// Some Paint Methods and support re-implemented
|
954 |
//
|
955 |
|
956 |
/*
|
957 |
* (non-Javadoc)
|
958 |
* @see javax.swing.plaf.basic.BasicTableHeaderUI#paint(java.awt.Graphics, javax.swing.JComponent)
|
959 |
*/
|
960 |
public void paint(Graphics g, JComponent c) { |
961 |
if (header.getColumnModel().getColumnCount() <= 0) { |
962 |
return;
|
963 |
} |
964 |
|
965 |
boolean ltr = header.getComponentOrientation().isLeftToRight();
|
966 |
|
967 |
Rectangle clip = g.getClipBounds();
|
968 |
Point left = clip.getLocation();
|
969 |
Point right = new Point( clip.x + clip.width - 1, clip.y ); |
970 |
TableColumnModel cm = header.getColumnModel();
|
971 |
int cMin = header.columnAtPoint( ltr ? left : right );
|
972 |
int cMax = header.columnAtPoint( ltr ? right : left );
|
973 |
// This should never happen.
|
974 |
if (cMin == -1) { |
975 |
cMin = 0;
|
976 |
} |
977 |
// If the table does not have enough columns to fill the view we'll get -1.
|
978 |
// Replace this with the index of the last column.
|
979 |
if (cMax == -1) { |
980 |
cMax = cm.getColumnCount()-1;
|
981 |
} |
982 |
|
983 |
TableColumn draggedColumn = header.getDraggedColumn();
|
984 |
int columnWidth;
|
985 |
Rectangle cellRect = header.getHeaderRect(ltr ? cMin : cMax);
|
986 |
TableColumn aColumn;
|
987 |
if (ltr) {
|
988 |
for(int column = cMin; column <= cMax ; column++) { |
989 |
aColumn = cm.getColumn(column); |
990 |
columnWidth = aColumn.getWidth(); |
991 |
cellRect.width = columnWidth; |
992 |
if (aColumn != draggedColumn) {
|
993 |
paintCell(g, cellRect, column); |
994 |
} |
995 |
cellRect.x += columnWidth; |
996 |
} |
997 |
} else {
|
998 |
for(int column = cMax; column >= cMin; column--) { |
999 |
aColumn = cm.getColumn(column); |
1000 |
columnWidth = aColumn.getWidth(); |
1001 |
cellRect.width = columnWidth; |
1002 |
if (aColumn != draggedColumn) {
|
1003 |
paintCell(g, cellRect, column); |
1004 |
} |
1005 |
cellRect.x += columnWidth; |
1006 |
} |
1007 |
} |
1008 |
|
1009 |
// Paint the dragged column if we are dragging.
|
1010 |
if (draggedColumn != null) { |
1011 |
int draggedColumnIndex = viewIndexForColumn(draggedColumn);
|
1012 |
Rectangle draggedCellRect = header.getHeaderRect(draggedColumnIndex);
|
1013 |
|
1014 |
// Draw a gray well in place of the moving column.
|
1015 |
g.setColor(header.getParent().getBackground()); |
1016 |
g.fillRect(draggedCellRect.x, draggedCellRect.y, |
1017 |
draggedCellRect.width, draggedCellRect.height); |
1018 |
|
1019 |
draggedCellRect.x += header.getDraggedDistance(); |
1020 |
|
1021 |
// Fill the background.
|
1022 |
g.setColor(header.getBackground()); |
1023 |
g.fillRect(draggedCellRect.x, draggedCellRect.y, |
1024 |
draggedCellRect.width, draggedCellRect.height); |
1025 |
|
1026 |
paintCell(g, draggedCellRect, draggedColumnIndex); |
1027 |
} |
1028 |
|
1029 |
// Remove all components in the rendererPane.
|
1030 |
rendererPane.removeAll(); |
1031 |
} |
1032 |
|
1033 |
private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) { |
1034 |
Component component = getHeaderRenderer(columnIndex);
|
1035 |
rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, |
1036 |
cellRect.width, cellRect.height, true);
|
1037 |
} |
1038 |
|
1039 |
private Component getHeaderRenderer(int columnIndex) { |
1040 |
TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
|
1041 |
TableCellRenderer renderer = aColumn.getHeaderRenderer();
|
1042 |
|
1043 |
if (renderer == null) { |
1044 |
renderer = header.getDefaultRenderer(); |
1045 |
} |
1046 |
|
1047 |
if (headerSelected == columnIndex) {
|
1048 |
headerSelected = -1;
|
1049 |
return renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), true, false, -1, columnIndex); |
1050 |
} |
1051 |
else {
|
1052 |
return renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, columnIndex); |
1053 |
} |
1054 |
} |
1055 |
|
1056 |
private int viewIndexForColumn(TableColumn aColumn) { |
1057 |
TableColumnModel cm = header.getColumnModel();
|
1058 |
|
1059 |
for (int column = 0; column < cm.getColumnCount(); column++) { |
1060 |
if (cm.getColumn(column) == aColumn) {
|
1061 |
return column;
|
1062 |
} |
1063 |
} |
1064 |
|
1065 |
return -1; |
1066 |
} |
1067 |
} |
1068 |
|
1069 |
/**
|
1070 |
* <p>Simulates the selection / unselection of the head of the column clicked.</p>
|
1071 |
*
|
1072 |
* @version 29/01/2008
|
1073 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
1074 |
*/
|
1075 |
private class DefaultTableSelectableCellRenderer extends DefaultTableCellRenderer { |
1076 |
private static final long serialVersionUID = -3896516869747447668L; |
1077 |
|
1078 |
/*
|
1079 |
* (non-Javadoc)
|
1080 |
* @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
|
1081 |
*/
|
1082 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
1083 |
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
1084 |
|
1085 |
Color bgColor = getTableHeader().getBackground();
|
1086 |
|
1087 |
if (isSelected)
|
1088 |
comp.setBackground(new Color(bgColor.getRed() - 10 , bgColor.getGreen() - 10, bgColor.getBlue() - 10)); |
1089 |
else
|
1090 |
comp.setBackground(bgColor); |
1091 |
|
1092 |
((JLabel)comp).setText((value == null) ? "" : value.toString()); |
1093 |
((JLabel)comp).setBorder(UIManager.getBorder("TableHeader.cellBorder")); |
1094 |
|
1095 |
return comp;
|
1096 |
} |
1097 |
} |
1098 |
|
1099 |
/**
|
1100 |
* Compares two chain of characters alphabetically, bearing in mind the information of a WFS layer.
|
1101 |
*
|
1102 |
* @version 24/01/2008
|
1103 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
1104 |
*/
|
1105 |
private class WFSLayerStringComparator extends StringComparator { |
1106 |
public static final short LAYER_NAME = 0; |
1107 |
public static final short GEOMETRY_TYPE = 1; |
1108 |
|
1109 |
protected short column = LAYER_NAME; // by default the first column |
1110 |
protected boolean showFeatureNameType = false; // by default doesn't shows the feature name type |
1111 |
protected boolean ascendingOrdering = true; // by default: ascending ordering |
1112 |
|
1113 |
/*
|
1114 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
1115 |
*/
|
1116 |
public int compare(Object o1, Object o2) { |
1117 |
String s1 = null, s2 = null; |
1118 |
|
1119 |
switch(column) {
|
1120 |
case LAYER_NAME:
|
1121 |
if (ascendingOrdering) {
|
1122 |
s1 = o1.toString(); |
1123 |
s2 = o2.toString(); |
1124 |
} |
1125 |
else {
|
1126 |
s1 = o2.toString(); |
1127 |
s2 = o1.toString(); |
1128 |
} |
1129 |
|
1130 |
if (showFeatureNameType) {
|
1131 |
if (ascendingOrdering) {
|
1132 |
return super.compare(o1, o2); |
1133 |
} |
1134 |
else {
|
1135 |
return super.compare(o2, o1); |
1136 |
} |
1137 |
} |
1138 |
|
1139 |
// Only if "showFeatureNameType == true" :
|
1140 |
int index = s1.indexOf(']'); |
1141 |
|
1142 |
if (index > 0) |
1143 |
s1 = s1.substring(index, s1.length()).trim(); |
1144 |
else
|
1145 |
s1 = s1.trim(); |
1146 |
|
1147 |
index = s2.indexOf(']');
|
1148 |
|
1149 |
if (index > 0) |
1150 |
s2 = s2.substring(index, s2.length()).trim(); |
1151 |
else
|
1152 |
s2 = s2.trim(); |
1153 |
|
1154 |
break;
|
1155 |
case GEOMETRY_TYPE:
|
1156 |
WFSFeatureField gType = ((WFSSelectedFeature)o1).getGeometryField(); |
1157 |
|
1158 |
if (gType == null) |
1159 |
s1 = "";
|
1160 |
else
|
1161 |
s1 = gType.getName(); |
1162 |
|
1163 |
gType = ((WFSSelectedFeature)o2).getGeometryField(); |
1164 |
|
1165 |
if (gType == null) |
1166 |
s2 = "";
|
1167 |
else
|
1168 |
s2 = gType.getName(); |
1169 |
|
1170 |
if (ascendingOrdering)
|
1171 |
return super.compare(s1, s2); |
1172 |
else
|
1173 |
return super.compare(s2, s1); |
1174 |
default:
|
1175 |
return 0; |
1176 |
} |
1177 |
|
1178 |
// If localeRules is null -> use the default rules
|
1179 |
if (getLocaleRules() == null) { |
1180 |
if (isCaseSensitive()) {
|
1181 |
return s1.compareTo(s2);
|
1182 |
} |
1183 |
else {
|
1184 |
return s1.compareToIgnoreCase(s2);
|
1185 |
} |
1186 |
} |
1187 |
else {
|
1188 |
if (getLocaleRules().isUseLocaleRules()) {
|
1189 |
Collator collator = getLocaleRules().getCollator();
|
1190 |
|
1191 |
if (isCaseSensitive()) {
|
1192 |
return collator.compare(s1, s2);
|
1193 |
} |
1194 |
else {
|
1195 |
//return collator.compare(s1.toLowerCase(), s2.toLowerCase());
|
1196 |
return collator.compare(s1.toUpperCase(), s2.toUpperCase());
|
1197 |
} |
1198 |
} |
1199 |
else {
|
1200 |
if (isCaseSensitive()) {
|
1201 |
return s1.compareTo(s2);
|
1202 |
} |
1203 |
else {
|
1204 |
return s1.compareToIgnoreCase(s2);
|
1205 |
} |
1206 |
} |
1207 |
} |
1208 |
} |
1209 |
|
1210 |
/**
|
1211 |
* Determines if the name of each element includes the type name.
|
1212 |
*
|
1213 |
* @return <code>true</code> if the name of each element includes the type name; otherwise <code>false</code>
|
1214 |
*/
|
1215 |
public boolean isShowFeatureNameType() { |
1216 |
return showFeatureNameType;
|
1217 |
} |
1218 |
|
1219 |
/**
|
1220 |
* Sets if the name of each element includes the type name.
|
1221 |
*
|
1222 |
* @param showFeatureNameType <code>true</code> if the name of each element includes the type name; otherwise <code>false</code>
|
1223 |
*/
|
1224 |
public void setShowFeatureNameType(boolean showFeatureNameType) { |
1225 |
this.showFeatureNameType = showFeatureNameType;
|
1226 |
} |
1227 |
|
1228 |
/**
|
1229 |
* <p>Sets which column well be alphabetically sort ordered.</p>
|
1230 |
*
|
1231 |
* <p>There are two columns:
|
1232 |
* <ul>
|
1233 |
* <li><i>LAYER_NAME</i>: name of the layer.</li>
|
1234 |
* <li><i>GEOMETRY_TYPE</i>: geometry type that layer is.</li>
|
1235 |
* </ul>
|
1236 |
* </p>
|
1237 |
*
|
1238 |
* @param column
|
1239 |
*/
|
1240 |
public void setColumn(short column) { |
1241 |
this.column = column;
|
1242 |
} |
1243 |
|
1244 |
/**
|
1245 |
* <p>Sets if the alphabetical sort will be ascending or descending.</p>
|
1246 |
*
|
1247 |
* @param b <code>true</code> if the alphabetical sort will be ascending, <code>false</code> if descending
|
1248 |
*/
|
1249 |
public void setAscendingOrdering(boolean b) { |
1250 |
ascendingOrdering = b; |
1251 |
} |
1252 |
|
1253 |
/**
|
1254 |
* <p>Determines if the alphabetical sort will be ascending or descending.</p>
|
1255 |
*
|
1256 |
* @param b <code>true</code> if the alphabetical sort will be ascending, <code>false</code> if descending
|
1257 |
*/
|
1258 |
public boolean isAscendingOrdering() { |
1259 |
return ascendingOrdering;
|
1260 |
} |
1261 |
} |
1262 |
} |
1263 |
} |