Revision 21299 branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/VectorialUniqueValue.java

View differences:

VectorialUniqueValue.java
45 45
import java.awt.FlowLayout;
46 46
import java.awt.event.ActionEvent;
47 47
import java.awt.event.ActionListener;
48
import java.util.ArrayList;
49
import java.util.Iterator;
48 50
import java.util.Random;
49 51

  
50 52
import javax.swing.DefaultComboBoxModel;
......
56 58
import javax.swing.JPanel;
57 59

  
58 60
import org.apache.log4j.Logger;
61
import org.gvsig.data.ReadException;
62
import org.gvsig.data.vectorial.Feature;
63
import org.gvsig.data.vectorial.FeatureAttributeDescriptor;
64
import org.gvsig.data.vectorial.FeatureStore;
59 65
import org.gvsig.fmap.mapcontext.layers.FLayer;
60 66
import org.gvsig.fmap.mapcontext.layers.operations.AlphanumericData;
61 67
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
......
64 70
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
65 71
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
66 72
import org.gvsig.fmap.mapcontext.rendering.legend.NullUniqueValue;
73
import org.gvsig.fmap.mapcontext.rendering.legend.NullValue;
67 74
import org.gvsig.fmap.mapcontext.rendering.legend.VectorialUniqueValueLegend;
68 75
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
69 76
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
70 77
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
71 78
import org.gvsig.gui.beans.swing.JButton;
72 79
import org.gvsig.raster.datastruct.ColorItem;
80
import org.omg.CORBA.portable.ValueFactory;
73 81

  
74
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
75
import com.hardcode.gdbms.engine.data.DataSource;
76
import com.hardcode.gdbms.engine.values.NullValue;
77
import com.hardcode.gdbms.engine.values.Value;
78
import com.hardcode.gdbms.engine.values.ValueFactory;
79 82
import com.iver.andami.PluginServices;
80 83
import com.iver.andami.messages.NotificationManager;
81 84
import com.iver.cit.gvsig.gui.styling.JComboBoxColorScheme;
......
188 191
     * DOCUMENT ME!
189 192
     */
190 193
    private void fillTableValues() {
191
        DataSource elRs;
194
        FeatureStore elRs;
192 195

  
193 196
        try {
194
            elRs = ((FLyrVect) layer).getRecordset();
195
            logger.debug("elRs.start()");
196
            elRs.start();
197
            elRs = ((FLyrVect) layer).getFeatureStore();
198
//            logger.debug("elRs.start()");
199
//            elRs.start();
197 200

  
198 201
            int idField = -1;
199 202
            String fieldName = (String) cmbFields.getSelectedItem();
......
202 205
            	return;
203 206
            }
204 207

  
205
            idField = elRs.getFieldIndexByName(fieldName);
208
//            idField = elRs.getFieldIndexByName(fieldName);
206 209
            theLegend.setClassifyingFieldNames(new String[] {fieldName});
207 210

  
208 211
            //long numReg = elRs.getRowCount();
209
            if (idField == -1) {
210
                NotificationManager.addWarning(
211
                		PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null);
212
//            if (idField == -1) {
213
//                NotificationManager.addWarning(
214
//                		PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null);
215
//
216
//                return;
217
//            }
212 218

  
213
                return;
214
            }
215

  
216 219
            symbolTable.removeAllItems();
217 220

  
218 221
            int numSymbols = 0;
......
221 224
            //auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend();
222 225
            auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
223 226

  
224
            Value clave;
227
            Object clave=null;
225 228

  
226 229
            //Object resul;
227 230
            if (chbUseDefault.isSelected()) {
......
233 236
            ColorItem[] colorScheme = cmbColorScheme.getSelectedColors();
234 237
            Random rand = new Random(System.currentTimeMillis());
235 238

  
236
            for (int j = 0; j < elRs.getRowCount(); j++) {
237
                clave = elRs.getFieldValue(j, idField);
239
            Iterator iterator=elRs.getDataCollection().iterator();
240
            while (iterator.hasNext()) {
241
				Feature feature = (Feature) iterator.next();
242
				feature.get(fieldName);
243
//			}
244
//            for (int j = 0; j < elRs.getRowCount(); j++) {
245
//                clave = elRs.getFieldValue(j, idField);
238 246

  
239 247
                if (clave instanceof NullValue) {
240 248
                    continue;
......
270 278

  
271 279
            symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
272 280
                auxLegend.getValues(), auxLegend.getDescriptions());
273
            elRs.stop();
274
        } catch (ReadDriverException e) {
281
//            elRs.stop();
282
        } catch (ReadException e) {
275 283
        	NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
276 284
        }
277 285

  
......
286 294
     * el symbolList, si no tambi�n el arrayKeys y el defaultRenderer
287 295
     */
288 296
    private void fillSymbolListFromTable() {
289
        Value clave;
297
        Object clave=null;
290 298
        ISymbol theSymbol;
291 299

  
292 300
        // Borramos las anteriores listas:
......
298 306
        /////////////////////////////////////////PEPE
299 307
        FLyrVect m = (FLyrVect) layer;
300 308
        try {
301
        	int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
302
        	theLegend.setClassifyingFieldTypes(new int[] {fieldType});
303
        } catch (ReadDriverException e) {
309
        	String fieldType=m.getFeatureStore().getDefaultFeatureType().getByOrder((int)cmbFields.getSelectedIndex()).getName();
310
//        	int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
311
        	theLegend.setClassifyingFieldTypes(new String[] {fieldType});
312
        } catch (ReadException e) {
304 313
        	NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e);
305 314
        }
306 315
        /////////////////////////////////////////PEPE
......
311 320
        }
312 321

  
313 322
        for (int row = 0; row < symbolTable.getRowCount(); row++) {
314
            clave = (Value) symbolTable.getFieldValue(row, 1);
323
            clave = (Object) symbolTable.getFieldValue(row, 1);
315 324
            theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
316 325
            theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2));
317 326
            theLegend.addSymbol(clave, theSymbol);
......
327 336
     * DOCUMENT ME!
328 337
     */
329 338
    private void fillFieldNames() {
330
        DataSource rs;
339
        FeatureStore rs;
331 340

  
332 341
        try {
333
            rs = ((AlphanumericData) layer).getRecordset();
334
            logger.debug("rs.start()");
335
            rs.start();
342
            rs = ((AlphanumericData) layer).getFeatureStore();
343
//            logger.debug("rs.start()");
344
//            rs.start();
336 345

  
337
            String[] nomFields = new String[rs.getFieldCount()];
346
            ArrayList names=new ArrayList();
347
            Iterator iterator=rs.getDefaultFeatureType().iterator();
348
            while (iterator.hasNext()) {
349
				FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next();
350
				names.add(descriptor.getDataType());
351
			}
352
//            String[] nomFields = new String[rs.getFieldCount()];
353
//
354
//            for (int i = 0; i < rs.getFieldCount(); i++) {
355
//                nomFields[i] = rs.getFieldName(i).trim();
356
//            }
357
//
358
//            rs.stop();
338 359

  
339
            for (int i = 0; i < rs.getFieldCount(); i++) {
340
                nomFields[i] = rs.getFieldName(i).trim();
341
            }
342

  
343
            rs.stop();
344

  
345
            DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields);
360
            DefaultComboBoxModel cM = new DefaultComboBoxModel((String[])names.toArray(new String[0]));
346 361
            cmbFields.setModel(cM);
347 362

  
348 363
            // fieldsListValor.setSelectedIndex(0);
349
        } catch (ReadDriverException e) {
364
        } catch (ReadException e) {
350 365
        	NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
351 366
        }
352 367
    }
......
356 371
      	int shapeType = 0;
357 372
      	try {
358 373
      		shapeType = this.layer.getShapeType();
359
      	} catch (ReadDriverException e) {
374
      	} catch (ReadException e) {
360 375
    		NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e);
361 376
		}
362 377

  
......
478 493
    		try {
479 494
    			symbolTable.addTableRecord(SymbologyFactory.
480 495
    					createDefaultSymbolByShapeType(layer.getShapeType()),
481
    					ValueFactory.createValue(0.0), "0 - 0");
482
    		} catch (ReadDriverException ex) {
496
    					new Double(0.0), "0 - 0");
497
    		} catch (ReadException ex) {
483 498
    			NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex);
484 499
    		}
485 500
    	}

Also available in: Unified diff