com.talk2object.plum.interaction.session.SessionManagerImpl Maven / Gradle / Ivy
package com.talk2object.plum.interaction.session;
import java.util.ArrayList;
import java.util.List;
import com.talk2object.common.ApplicationContextUtils;
import com.talk2object.common.Context;
import com.talk2object.plum.interaction.InteractionManager;
import com.talk2object.plum.interaction.WindowInteractionManager;
import com.talk2object.plum.interaction.application.PlumApplicationContextUtils;
import com.talk2object.plum.interaction.context.InteractionContextUtils;
import com.talk2object.plum.interaction.rich.field.ViewMode;
import com.talk2object.plum.interaction.viewgeneneration.BuilderMatchPolicy;
import com.talk2object.plum.interaction.viewgeneneration.ViewBuildContext;
import com.talk2object.plum.interaction.viewgeneneration.ViewClass;
import com.talk2object.plum.interaction.viewgeneneration.ViewDetail;
import com.talk2object.plum.interaction.viewgeneneration.ViewFactory;
import com.talk2object.plum.view._abstract.components.containers.window.EventThreadContext;
import com.talk2object.plum.view._abstract.components.containers.window.MainWindow;
import com.talk2object.plum.view._abstract.components.containers.window.WindowManager;
import com.talk2object.plum.view.context.ViewSessionContextUtils;
/**
* manages all client sessions
*
* @author jack
*
*/
public class SessionManagerImpl implements SessionManager {
private List sessionContextList = new ArrayList();
private Context applicationContext;
private String defaultModelClassName;
private Class defaultModelClass;
public SessionManagerImpl() {
applicationContext = ApplicationContextUtils.getApplicationContext();
}
@Override
public List getSessionContextList() {
return sessionContextList;
}
@Override
public SessionContext createSession(SessionConfig config) {
SessionContext sessionContext = new SessionContext(applicationContext);
sessionContextList.add(sessionContext);
if (config == null)
config = createDefaultSessionConfig();
createSessionView(sessionContext, config);
ViewSessionContextUtils.init(sessionContext);
return sessionContext;
}
private SessionConfig createDefaultSessionConfig() {
return new SessionConfig(defaultModelClassName);
}
private void createSessionView(SessionContext sessionContext,
SessionConfig config) {
Object model = config.getModel(true);
// create new view
ViewFactory viewFactory = PlumApplicationContextUtils.getViewFactory();
MainWindow mainWindow = (MainWindow) viewFactory.create(model,
BuilderMatchPolicy.EXACT, ViewClass.WINDOWS.getFullName(),
ViewBuildContext.DEFAULT, null);
// create window manager
WindowManager windowManager = new WindowManager();
mainWindow.setWindowManager(windowManager);
windowManager.register(mainWindow);
// set session context into main event thread context, sub-windows
// inherit it.
mainWindow.getEventThread().getContext()
.setSessionContext(sessionContext);
// create interaction manager
InteractionManager interactionManager = new WindowInteractionManager(
mainWindow);
InteractionContextUtils.setInteractionManager(
mainWindow.getEventThread(), interactionManager);
mainWindow.show();
// inject into session context
sessionContext.setModel(model);
sessionContext.setView(mainWindow);
ViewSessionContextUtils.setWindowManager(sessionContext, windowManager);
}
public String getDefaultModelClassName() {
return defaultModelClassName;
}
public void setDefaultModelClassName(String defaultModelClassName) {
this.defaultModelClassName = defaultModelClassName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy