Revision 41630 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/paging/impl/FeaturePagingHelperImpl.java

View differences:

FeaturePagingHelperImpl.java
168 168
    /**
169 169
     * @return the selectionUp status
170 170
     */
171
    protected boolean isSelectionUp() {
171
    public boolean isSelectionUp() {
172 172
        return selectionUp;
173 173
    }
174 174

  
175 175
    public void setSelectionUp(boolean selectionUp) {
176 176
        this.selectionUp = selectionUp;
177 177
        try {
178
            if (selectionUp) {
179
                initialSelection =
180
                    (FeatureSelection) getFeatureStore().getFeatureSelection()
181
                        .clone();
178
            FeatureSelection currentSelection = getFeatureStore().getFeatureSelection();
179
            if (selectionUp && !currentSelection.isEmpty()) {
180
                initialSelection =(FeatureSelection) currentSelection.clone();
182 181
                setCalculator(new OneSubsetOneSetPagingCalculator(
183 182
                    new FeatureSetSizeableDelegate(initialSelection),
184 183
                    new FeatureSetSizeableDelegate(getFeatureSet(false)),
......
348 347
    }
349 348
    
350 349
    private void loadCurrentPageDataWithSelectionUp(final Feature[] values)
351
        throws BaseException {
350
            throws BaseException {
352 351
        FeatureSelection selection = initialSelection;
352
        if (selection == null) {
353
            loadCurrentPageDataNoSelection(values);
354
        } else {
355
            FeatureSet set = getFeatureSet(false);
356
            try {
357
                OneSubsetOneSetPagingCalculator twoSetsCalculator = null;
358
                if (getCalculator() instanceof OneSubsetOneSetPagingCalculator) {
359
                    twoSetsCalculator
360
                            = (OneSubsetOneSetPagingCalculator) getCalculator();
361
                } else {
362
                    twoSetsCalculator
363
                            = new OneSubsetOneSetPagingCalculator(
364
                                    new FeatureSetSizeableDelegate(selection),
365
                                    new FeatureSetSizeableDelegate(set),
366
                                    getMaxPageSize(), getCalculator().getCurrentPage());
367
                    setCalculator(twoSetsCalculator);
368
                }
353 369

  
354
        FeatureSet set = getFeatureSet(false);
355
        try {
356
	        OneSubsetOneSetPagingCalculator twoSetsCalculator = null;
357
	        if (getCalculator() instanceof OneSubsetOneSetPagingCalculator) {
358
	            twoSetsCalculator =
359
	                (OneSubsetOneSetPagingCalculator) getCalculator();
360
	        } else {
361
	            twoSetsCalculator =
362
	                new OneSubsetOneSetPagingCalculator(
363
	                    new FeatureSetSizeableDelegate(selection),
364
	                    new FeatureSetSizeableDelegate(set),
365
	                    getMaxPageSize(), getCalculator().getCurrentPage());
366
	            setCalculator(twoSetsCalculator);
367
	        }
368
	
369 370
	        // First load values from the selection, if the current page has
370
	        // elements from it
371
	        if (twoSetsCalculator.hasCurrentPageAnyValuesInFirstSet()) {
372
	            loadDataFromFeatureSet(values, 0, selection,
373
	                twoSetsCalculator.getFirstSetInitialIndex(),
374
	                twoSetsCalculator.getFirstSetHowMany(), null);
375
	        }
371
                // elements from it
372
                if (twoSetsCalculator.hasCurrentPageAnyValuesInFirstSet()) {
373
                    loadDataFromFeatureSet(values, 0, selection,
374
                            twoSetsCalculator.getFirstSetInitialIndex(),
375
                            twoSetsCalculator.getFirstSetHowMany(), null);
376
                }
376 377
	        // Next, load values from the FeatureSet if the current page has values
377
	        // from it
378
	        if (twoSetsCalculator.hasCurrentPageAnyValuesInSecondSet()) {
379
	            loadDataFromFeatureSet(
380
	                values,
381
	                // The cast will work as that size will be <= maxpagesize,
382
	                // which is an int
383
	                (int) twoSetsCalculator.getFirstSetHowMany(), set,
384
	                twoSetsCalculator.getSecondSetInitialIndex(),
385
	                twoSetsCalculator.getSecondSetHowMany(), selection);
386
	        }
387
        } finally {
388
            /*
389
             * This is the feature set
390
             * we dont want to lose it
391
             */
392
        	// set.dispose();
378
                // from it
379
                if (twoSetsCalculator.hasCurrentPageAnyValuesInSecondSet()) {
380
                    loadDataFromFeatureSet(
381
                            values,
382
                            // The cast will work as that size will be <= maxpagesize,
383
                            // which is an int
384
                            (int) twoSetsCalculator.getFirstSetHowMany(), set,
385
                            twoSetsCalculator.getSecondSetInitialIndex(),
386
                            twoSetsCalculator.getSecondSetHowMany(), selection);
387
                }
388
            } finally {
389
                /*
390
                 * This is the feature set
391
                 * we dont want to lose it
392
                 */
393
                // set.dispose();
394
            }
393 395
        }
394 396
    }
395 397

  
......
436 438
                    // features or the feature is not selected
437 439
                    if (selectedFeaturesToSkip == null
438 440
                        || !selectedFeaturesToSkip.isSelected(current)) {
439
                        values[i] = current.getCopy();
440
                        i++;
441
                        try {
442
                            values[i] = current.getCopy();
443
                            i++;
444
                        } catch(Exception ex) {
445
                            // Aqui no deberia petar, pero...
446
                            // me he encontrado un caso que tenia una referencia a
447
                            // una feature seleccionada que ya no existia. No se como 
448
                            // habia pasado, se habia quedado de antes guardada en el
449
                            // proyecto pero la feature ya no existia, y eso hacia que
450
                            // petase al intentar leer de disco la feature a partir
451
                            // de una referencia no valida.
452
                        }
441 453
                    }
442 454
                }
443 455
            }, initialIndex);

Also available in: Unified diff