Revision 17593 trunk/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/WFSSelectFeaturePanel.java

View differences:

WFSSelectFeaturePanel.java
1 1
package com.iver.cit.gvsig.gui.panels;
2 2

  
3 3
import java.awt.Color;
4
import java.awt.event.MouseAdapter;
5
import java.awt.event.MouseEvent;
6 4

  
7 5
import javax.swing.JCheckBox;
8 6
import javax.swing.JPanel;
9 7
import javax.swing.JScrollPane;
10 8
import javax.swing.JTextField;
11
import javax.swing.ListSelectionModel;
12 9
import javax.swing.event.ListSelectionListener;
13 10

  
14 11
import com.iver.andami.PluginServices;
12
import com.iver.cit.gvsig.fmap.layers.FLyrWFS;
15 13
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
16
import com.iver.cit.gvsig.gui.wizards.WFSWizardData;
17 14

  
18 15
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
19 16
 *
......
118 115
/**
119 116
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
120 117
 */
121
public class WFSSelectFeaturePanel extends JPanel {
118
public class WFSSelectFeaturePanel extends DefaultWFSDialogPanel {
122 119
	private JPanel coveragesListPanel = null;
123 120
	private JScrollPane jScrollPane = null;
124 121
	private LayerTable lstFeatures = null;
125 122
	private JTextField txtName = null;
126 123
	private JCheckBox chkExtendedNames = null;
127
	private WFSWizardData data = null;
128
	private WFSParamsPanel parent = null;
129 124
	private JPanel layerNamePanel = null;
130
	
125
	private WFSLayerNode layerNode = null;
126
	private WFSSelectFeaturePanelListener listener = null;
127
	private ListSelectionListener listSelectionListener = null;
131 128

  
132
	/**
133
	 * This method initializes
134
	 *
135
	 */
136
	public WFSSelectFeaturePanel(WFSParamsPanel parent) {
129
	public WFSSelectFeaturePanel() {
137 130
		super();
138
		this.parent = parent;
139 131
		initialize();
140 132
	}
141 133

  
142 134
	/**
143
	 * This method initializes this
144
	 *
145
	 */
146
	private void initialize() {
147
		this.setLayout(null);
148
		this.setBounds(10, 5, 481, 427);
149
		this.add(getFeaturesListPanel(), null);
150
		this.add(getChkExtendedNames(), null);
151
		this.add(getLayerNamePanel(), null);
152
	}
153

  
154
	/**
155 135
	 * This method initializes coveragesListPanel
156 136
	 *
157 137
	 * @return javax.swing.JPanel
......
195 175
		if (lstFeatures == null) {
196 176
			lstFeatures = new LayerTable();
197 177
			lstFeatures.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
198
			lstFeatures.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
178
			lstFeatures.getSelectionModel().addListSelectionListener(getListSelectionListener());
179
			lstFeatures.setToolTipText(PluginServices.getText(lstFeatures, "feature_Selection_Info"));
180
		}
181

  
182
		return lstFeatures;
183
	}
184

  
185
	/**
186
	 * Creates the list selection listener for the layers list
187
	 * @return
188
	 * The listener
189
	 */
190
	private ListSelectionListener getListSelectionListener(){
191
		if (listSelectionListener == null){
192
			listSelectionListener = new ListSelectionListener(){
199 193
				public void valueChanged(javax.swing.event.ListSelectionEvent e) {
200 194
					// With this condition we force that the two lines only will be execute one time when user presses the JList
201 195
					if (e.getValueIsAdjusting() == false) {
202 196
						// Indicate that now we are loading a new layer
203
						parent.setWFSFilterPanelIsAsTabForWFSLayersLoad(true);
204
						
205 197
						refreshData();
206 198
					}
207 199
				}
208
			});
209
			
210
			// Double-click -> click the 'Next' button
211
			lstFeatures.addMouseListener(new MouseAdapter() {
212
				/*
213
				 *  (non-Javadoc)
214
				 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
215
				 */
216
				public void mouseClicked(MouseEvent e) {
217
					if (e.getClickCount() == 2) {
218
						parent.doClickOnNextButton();
219
					}
220
				}			
221
			});
222
			
223
			
224
			lstFeatures.setToolTipText(PluginServices.getText(lstFeatures, "feature_Selection_Info"));
200
			};	
225 201
		}
226
		
227
		return lstFeatures;
202
		return listSelectionListener;
228 203
	}
229
	
204

  
230 205
	/**
231 206
	 * This method initializes jTextField
232 207
	 *
......
242 217
			txtName.setToolTipText(PluginServices.getText(txtName, "feature_to_load"));
243 218
			txtName.addKeyListener(new java.awt.event.KeyAdapter() {
244 219
				public void keyTyped(java.awt.event.KeyEvent e) {
245
					parent.isApplicable(true);
220
					getParamsPanelData().isApplicable(true);
246 221
				}
247 222
			});
248 223
		}
......
277 252
	}
278 253

  
279 254
	/**
280
	 *
281
	 * @return The selected Feature
255
	 * Set the selectad layer node
256
	 * @param layerNode
257
	 * TYhe layer to select
282 258
	 */
283
	public WFSLayerNode getSelectedFeature(){
284
		return (WFSLayerNode)getLstFeatures().getSelectedValue();
285
	}
286

  
287 259
	public void setSelectedFeature(WFSLayerNode layerNode){
288 260
		int index = -1;
289 261
		for (int i=0; i<getLstFeatures().getRowCount(); i++){
......
298 270
	}
299 271

  
300 272
	/**
301
	 * Sets the object that holds the wizard data.
302
	 *
303
	 * Establece el objeto que contiene los datos del wizard.
304
	 *
305
	 * @param data
306
	 */
307
	public void setWizardData(WFSWizardData data) {
308
		this.data = data;
309
		refreshInfo();
310
	}
311

  
312
	/**
313 273
	 * Refresh the features list
314 274
	 */
315
	public void refreshInfo(){
316
		// Unselects all features
317
		unselectAllFeatures();
318
		
275
	public void refresh(WFSLayerNode layer) {
319 276
		// Add the new features
320
		getLstFeatures().addFeatures(data.getFeatures());
277
		getLstFeatures().addFeatures(getWizardData().getFeatures());
278
		if (layer != null){
279
			layerNode = layer;
280
			setLayerName(layer.getName());
281
			setSelectedFeature(layer);			
282
		}		
321 283
	}
322 284

  
323 285
	/**
324
	 * Updates the list with no feature selected
325
	 */
326
	public void unselectAllFeatures() {
327
		// Reset the last row selection of the features table
328
		int numberOfFeatures = getLstFeatures().getRowCount();
329

  
330
		if (numberOfFeatures > 0) {			
331
			ListSelectionModel model = getLstFeatures().getSelectionModel();
332
			model.removeSelectionInterval(0, numberOfFeatures - 1); // whatever row selection
333
		}
334
	}
335
	
336
	/**
337 286
	 * Refreshes the wizard components data each time a feature
338 287
	 * is selected. The describeFeatureType operation must be
339 288
	 * sent
......
344 293
			getTxtName().setText(lyr.getTitle());
345 294
		}catch(NullPointerException e){
346 295
			getTxtName().setText(PluginServices.getText(this,"default_name"));
347
		}
348
		
349
		parent.refreshData(lyr);
296
		}		
297
		getParamsPanelData().refresh(lyr);
298
		repaint();
350 299
	}
351 300

  
352 301
	/**
......
376 325
	public String getLayerName(){
377 326
		return ((WFSLayerNode)getLstFeatures().getSelectedValue()).getName();
378 327
	}
379
	
328

  
380 329
	/**
381 330
	 *
382 331
	 * @return the name space
......
384 333
	public String getLayerNameSpace(){
385 334
		return ((WFSLayerNode)getLstFeatures().getSelectedValue()).getNameSpace();
386 335
	}
387
	
336

  
337
	/**
338
	 * @return the selected layer node
339
	 */
388 340
	public WFSLayerNode getWFSLayerNode(){
389
		WFSLayerNode layerNode = (WFSLayerNode)getLstFeatures().getSelectedValue();
341
		WFSLayerNode selectedLayerNode = (WFSLayerNode)getLstFeatures().getSelectedValue();
342
		if (selectedLayerNode != null){
343
			layerNode = selectedLayerNode;
344
		}
390 345
		return layerNode;
391 346
	}
392 347

  
......
403 358
		getTxtName().setText(name);
404 359
	}
405 360

  
361
	@Override
362
	public void accept() {
363
		if (getPanelGroup().isEnabledApplyButton()){
364
			getListener().actionPerformed(WFSSelectFeaturePanelListener.ACCEPT_BUTTON_ACTION_COMMAND);
365
		}
366
	}
406 367

  
368
	@Override
369
	public void apply() {
370
		getPanelGroup().setEnabledApplyButton(false);
371
		getListener().actionPerformed(WFSSelectFeaturePanelListener.APPLY_BUTTON_ACTION_COMMAND);		
372
	}		
407 373

  
374
	/**
375
	 * @return the listener
376
	 */
377
	public WFSSelectFeaturePanelListener getListener() {
378
		if (listener == null){
379
			listener = new WFSSelectFeaturePanelListener(getParamsPanelData());	
380
		}
381
		return listener;
382
	}
408 383

  
384

  
385
	@Override
386
	public void cancel() {
387
		// TODO Auto-generated method stub
388

  
389
	}
390

  
391
	@Override
392
	protected void initialize() {
393
		setLabel(PluginServices.getText(this, "feature"));
394
		setLabelGroup(PluginServices.getText(this, "wfs"));
395
		this.setLayout(null);
396
		this.setBounds(10, 5, 481, 427);
397
		this.add(getFeaturesListPanel(), null);
398
		this.add(getChkExtendedNames(), null);
399
		this.add(getLayerNamePanel(), null);
400
	}
401
	
402
	@Override
403
	public void setReference(Object ref) {
404
		super.setReference(ref);
405
		if (ref instanceof FLyrWFS){			
406
			getPanelGroup().setEnabledApplyButton(false);
407
		}		
408
	}	
409

  
410
	@Override
411
	public void selected() {
412
		// TODO Auto-generated method stub
413

  
414
	}
415

  
409 416
}  //  @jve:decl-index=0:visual-constraint="10,16"

Also available in: Unified diff