Java 类com.vaadin.server.ClientConnector.DetachEvent 实例源码

项目:osgi-bridge-and-fragmentedui-demo    文件:VaadinOSGiUI.java   
@Override
protected void init(VaadinRequest request) {

    setPollInterval(1000);
    hl = new HorizontalSplitPanel();
    hl.setSizeFull();
    setContent(hl);

    buttonsOnTheLeft = new VerticalLayout();
    buttonsOnTheLeft.setSizeUndefined();

    hl.setFirstComponent(buttonsOnTheLeft);
    hl.setSplitPosition(25, Unit.PERCENTAGE);

    ServiceTracker<FragmentFactory, FragmentFactory> tracker = new ServiceTracker<FragmentFactory, FragmentFactory>(
            VaadinActivator.context, FragmentFactory.class, this);
    tracker.open();

    addDetachListener(new DetachListener() {

        @Override
        public void detach(DetachEvent event) {
            tracker.close();
        }
    });
}
项目:jdal    文件:VaadinScope.java   
public synchronized void detach(DetachEvent event) {
    UI ui = (UI) event.getConnector();
    if (log.isDebugEnabled())
        log.debug("UI [" + ui.getUIId() + "] detached, destroying scoped beans");

    removeBeans(ui);
    sessions.remove(ui);

}
项目:collabsketch_vaadin    文件:CollabSketch.java   
public CollabSketch(CollabSketchLineContainer lineContainer, int width, int height) {
    this.lineContainer = lineContainer;
    setImmediate(true);
    getState().canvasWidth = width;
    getState().canvasHeight = height;

    String color;
    ui = UI.getCurrent();
    sessionID =  ui.getSession().getSession().getId();
    if (lineContainer.getSessionColors().containsKey(sessionID)) {
        color = lineContainer.getSessionColors().get(sessionID);
    } else {
        int user = this.lineContainer.getListeners().size();
        if (user >= colors.length) {
            color = colors[user % colors.length]; 
        } else {
            color = colors[user];
        }
        lineContainer.getSessionColors().put(sessionID, color.toString());
    }

    getState().color = color;
    listener = new CollabSketchUpdateListener(ui) {

            @Override
            public void lineAdded(final DrawLine line) {
                listener.getUi().runSafely(new Runnable() {

                    @Override
                    public void run() {
                        getRpcProxy(CollabSketchClientRpc.class).drawLine(line); 
                    }
                });
            }

            @Override
            public void canvasCleared() {
                listener.getUi().runSafely(new Runnable() {

                    @Override
                    public void run() {
                        getRpcProxy(CollabSketchClientRpc.class).clearCanvas(); 
                    }
                });
            }
        };

    // To receive events from the client, we register ServerRpc
    registerRpc(rpc);
    if (!lineContainer.getLines().isEmpty()) {
        getState().lines = (ArrayList<DrawLine>) lineContainer.getLines();
    }

    lineContainer.getListeners().put(sessionID, listener);


    ui.addDetachListener(new DetachListener() {

        @Override
        public void detach(DetachEvent event) {
            CollabSketch.this.lineContainer.getListeners().remove(listener);
            CollabSketch.this.lineContainer.getSessionColors().remove(sessionID);
        }
    });
}