Project

General

Profile

« Previous | Next » 

Revision ad0d2649

Added by Patrick Plitzner over 7 years ago

ref #5458 Notify user when taxon tree is loading

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionSettingsConfigWindow.java
21 21
import com.vaadin.data.Property.ValueChangeListener;
22 22
import com.vaadin.data.util.BeanItemContainer;
23 23
import com.vaadin.data.util.sqlcontainer.RowId;
24
import com.vaadin.server.Page;
24 25
import com.vaadin.server.VaadinSession;
25 26
import com.vaadin.ui.AbstractLayout;
26 27
import com.vaadin.ui.Alignment;
......
29 30
import com.vaadin.ui.ComboBox;
30 31
import com.vaadin.ui.HorizontalLayout;
31 32
import com.vaadin.ui.ListSelect;
33
import com.vaadin.ui.Notification;
34
import com.vaadin.ui.ProgressBar;
32 35
import com.vaadin.ui.Table.ColumnHeaderMode;
33 36
import com.vaadin.ui.TextField;
34 37
import com.vaadin.ui.Tree.ExpandEvent;
35 38
import com.vaadin.ui.Tree.ExpandListener;
36 39
import com.vaadin.ui.TreeTable;
40
import com.vaadin.ui.UI;
37 41
import com.vaadin.ui.VerticalLayout;
38 42

  
39 43
import eu.etaxonomy.cdm.common.CdmUtils;
......
217 221
        }
218 222
        else if(property==taxonFilter){
219 223
            String filterText = taxonFilter.getValue();
220
            if(CdmUtils.isNotBlank(filterText)){
221
                List<UuidAndTitleCache<TaxonNode>> taxa = CdmSpringContextHelper.getTaxonNodeService().getUuidAndTitleCache(null, filterText);
222
                if(!taxa.isEmpty()){
223
                    BeanItemContainer<UuidAndTitleCache<TaxonNode>> container = new BeanItemContainer<>(UuidAndTitleCache.class);
224
                    taxonTree.setContainerDataSource(container);
225
                    for (UuidAndTitleCache<TaxonNode> taxon : taxa) {
226
                        container.addItem(taxon);
227
                        taxonTree.setChildrenAllowed(taxon, false);
228
                    }
229
                    taxonTree.setVisibleColumns("titleCache");
230
                }
224
            Property uuidProperty = classificationBox.getContainerProperty(classificationBox.getValue(),"uuid");
225
            if(uuidProperty==null){
226
            	Notification.show("Please select a classification");
231 227
            }
232 228
            else{
233
                UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue());
234
                showClassificationTaxa(parent);
229
            	if(CdmUtils.isNotBlank(filterText)){
230
            		UUID classificationUuid = UUID.fromString((String) uuidProperty.getValue());
231
            		List<UuidAndTitleCache<TaxonNode>> taxa = CdmSpringContextHelper.getTaxonNodeService().getUuidAndTitleCache(null, filterText, classificationUuid);
232
            		BeanItemContainer<UuidAndTitleCache<TaxonNode>> container = new BeanItemContainer<>(UuidAndTitleCache.class);
233
            		taxonTree.setContainerDataSource(container);
234
            		for (UuidAndTitleCache<TaxonNode> taxon : taxa) {
235
            			container.addItem(taxon);
236
            			taxonTree.setChildrenAllowed(taxon, false);
237
            		}
238
            		taxonTree.setVisibleColumns("titleCache");
239
            	}
240
            	else{
241
            		UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue());
242
            		showClassificationTaxa(parent);
243
            	}
235 244
            }
236 245
        }
237 246
        else if(property==distAreaBox){
......
278 287
    }
279 288

  
280 289
    private void showClassificationTaxa(UuidAndTitleCache<TaxonNode> parent) {
281
        Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent);
282
        taxonTree.setContainerDataSource(new TaxonNodeContainer(children));
290
        final Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent);
291
        // Enable polling and set frequency to 0.5 seconds
292
        UI.getCurrent().setPollInterval(500);
293
        taxonTree.setEnabled(false);
294
        Notification.show("Loading taxa...");
295

  
296
        new TreeUpdater(children).start();
283 297
    }
284 298

  
285 299
    private UuidAndTitleCache<TaxonNode> getUuidAndTitleCacheFromRowId(Object classificationSelection) {
......
290 304
        UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
291 305
        return parent;
292 306
    }
307
    
308
    private class TreeUpdater extends Thread{
309
    	
310
    	private Collection<UuidAndTitleCache<TaxonNode>> children;
311

  
312
    	
313
		public TreeUpdater(Collection<UuidAndTitleCache<TaxonNode>> children) {
314
			this.children = children;
315
		}
316

  
317
		@Override
318
    	public void run() {
319
			UI.getCurrent().access(new Runnable() {
320
				@Override
321
				public void run() {
322
					taxonTree.setContainerDataSource(new TaxonNodeContainer(children));
323

  
324
			        Notification notification = new Notification("Loading complete");
325
			        notification.setDelayMsec(500);
326
			        notification.show(Page.getCurrent());
327
			        taxonTree.setEnabled(true);
328

  
329
			        //disable polling when all taxa are loaded
330
			        UI.getCurrent().setPollInterval(-1);
331
				}
332
			});
333
    	}
334
    }
293 335
}

Also available in: Unified diff