Revision 46737 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/DefaultProject.java

View differences:

DefaultProject.java
393 393
     */
394 394
    @Override
395 395
    public List<Document> getDocuments() {
396
        return Collections.unmodifiableList(documents);
396
        return this.getDocuments((Predicate<Document>)null);
397 397
    }
398 398

  
399 399
    /**
......
405 405
     */
406 406
    @Override
407 407
    public List<Document> getDocuments(String type) {
408
        List<Document> docs = new ArrayList<Document>();
409
        if (type != null) {
408
        return this.getDocuments((Document t) -> t!=null && 
409
                (type==null  || StringUtils.equalsIgnoreCase(type, t.getTypeName()))
410
        );
411
    }
412

  
413
    @Override
414
    public List<Document> getDocuments(Class<? extends Document> documentClass) {
415
        return this.getDocuments((Document t) -> t!=null && 
416
                (documentClass==null  || documentClass.isAssignableFrom(t.getClass()))
417
        );
418
    }
419

  
420
    @Override
421
    public List<Document> getDocuments(Predicate<Document> filter) {
422
        List<Document> docs;
423
        if( filter == null ) {
424
            docs = new ArrayList<Document>(this.documents);
425
        } else {
426
            docs = new ArrayList<Document>();
410 427
            for (Document document : this.documents) {
411
                if (type.equalsIgnoreCase(document.getTypeName())) {
428
                if ( filter.test(document) ) {
412 429
                    docs.add(document);
413 430
                }
414 431
            }
......
1350 1367
        }
1351 1368
        return null;
1352 1369
    }
1370
    
1371
    @Override
1372
    public List<Document> getOpenDocuments(Class<? extends Document> documentClass) {
1373
        return this.getOpenDocuments((Document doc) -> {
1374
            return doc!=null && (documentClass==null || documentClass.isAssignableFrom(doc.getClass()));
1375
        });
1376
    }
1377
    
1378
    @Override
1379
    public List<Document> getOpenDocuments(String type) {
1380
        return this.getOpenDocuments((Document doc) -> {
1381
            return  doc!=null && StringUtils.equals(type, doc.getTypeName());
1382
        });
1383
    }
1384
    
1385
    @SuppressWarnings("UnnecessaryContinue")
1386
    @Override
1387
    public List<Document> getOpenDocuments(Predicate<Document>filter) {
1388
        ApplicationManager application = ApplicationLocator.getManager();
1353 1389

  
1390
        List<Document> docs = new ArrayList<>();
1391
        IWindow[] windows = application.getUIManager().getOrderedWindows();
1392
        for (IWindow window : windows) {
1393
            if (window instanceof SingletonWindow && window instanceof IDocumentWindow) {
1394
                // Cogemos no la primera ventana, si no la primera
1395
                // ventana de tipo documento (SingletonWindow).
1396
                // Y por si las mosca no es un documento, atrapamos
1397
                // los errores y continuamos si no puede hacer un cast
1398
                // del Model a Document
1399
                try {
1400
                    Document doc = (Document) ((SingletonWindow) window).getWindowModel();
1401
                    if (filter == null) {
1402
                        docs.add(doc);
1403
                        continue;
1404
                    }
1405
                    if ( filter.test(doc) ) {
1406
                        docs.add(doc);
1407
                        continue;
1408
                    }
1409
                    // Ojo, no debe tener en cuenta los subdocumentos.
1410
                } catch (ClassCastException e) {
1411
                    // Do nothing, skip this window
1412
                }
1413
            }
1414
        }
1415
        return docs;
1416
    }
1417

  
1354 1418
    @Override
1355 1419
    public Document getActiveDocument(Class<? extends Document> documentClass) {
1356 1420
        ApplicationManager application = ApplicationLocator.getManager();

Also available in: Unified diff