Example usage for com.vaadin.ui Panel addDetachListener

List of usage examples for com.vaadin.ui Panel addDetachListener

Introduction

In this page you can find the example usage for com.vaadin.ui Panel addDetachListener.

Prototype

@Override
    public Registration addDetachListener(DetachListener listener) 

Source Link

Usage

From source file:annis.gui.docbrowser.DocBrowserController.java

License:Apache License

public void openDocVis(String corpus, String doc, Visualizer visConfig, Button btn) {

    final String canonicalTitle = corpus + " > " + doc + " - " + "Visualizer: " + visConfig.getDisplayName();
    final String tabCaption = StringUtils.substring(canonicalTitle, 0, 15) + "...";

    if (visibleVisHolder.containsKey(canonicalTitle)) {
        Panel visHolder = visibleVisHolder.get(canonicalTitle);
        ui.getSearchView().getTabSheet().setSelectedTab(visHolder);
        return;/*from   w  ww .j  av  a 2s.  c  o  m*/
    }

    Panel visHolder = new Panel();
    visHolder.setSizeFull();
    visHolder.addDetachListener(new ClientConnector.DetachListener() {
        @Override
        public void detach(ClientConnector.DetachEvent event) {
            visibleVisHolder.remove(canonicalTitle);
        }
    });

    // first set loading indicator
    ProgressBar progressBar = new ProgressBar(1.0f);
    progressBar.setIndeterminate(true);
    progressBar.setSizeFull();
    VerticalLayout layoutProgress = new VerticalLayout(progressBar);
    layoutProgress.setSizeFull();
    layoutProgress.setComponentAlignment(progressBar, Alignment.MIDDLE_CENTER);

    visHolder.setContent(layoutProgress);

    Tab visTab = ui.getSearchView().getTabSheet().addTab(visHolder, tabCaption);
    visTab.setDescription(canonicalTitle);
    visTab.setIcon(EYE_ICON);
    visTab.setClosable(true);
    ui.getSearchView().getTabSheet().setSelectedTab(visTab);

    // register visible visHolder
    this.visibleVisHolder.put(canonicalTitle, visHolder);

    Background.run(new DocVisualizerFetcher(corpus, doc, canonicalTitle, visConfig.getType(), visHolder,
            visConfig, btn, UI.getCurrent()));
}