@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();
}
});
}
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);
}
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。