
org.openxma.rwt.launch.OpenxmaLauncher Maven / Gradle / Ivy
The newest version!
package org.openxma.rwt.launch;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.eclipse.rwt.RWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.openxma.rwt.bridge.SessionFunctions;
import at.spardat.xma.boot.comp.AppManager;
import at.spardat.xma.boot.component.IComponent;
import at.spardat.xma.boot.component.IDialog;
public class OpenxmaLauncher {
protected String determineComponentUrl() {
HttpServletRequest request = RWT.getRequest();
HttpSession httpSession = RWT.getSessionStore().getHttpSession();
System.out.println("Request URI= "+request.getRequestURI());
System.out.println("Request Query string= "+request.getQueryString());
System.out.println("List request parameters");
Enumeration ran = request.getParameterNames();
while (ran.hasMoreElements()) {
String an = (String)ran.nextElement();
String val = (String)request.getParameter(an);
System.out.println("Request attribute: "+an+"="+val);
}
String componentUrl = (String)request.getParameter("component");
if (componentUrl == null) {
componentUrl=SessionFunctions.getComponentUrlFromSession(httpSession);
System.out.println("Component url from session: "+componentUrl);
}
if (componentUrl == null) {
Properties props = getXmaBootHomeProperties();
componentUrl = props.getProperty("defaultComponentUrl");
}
if (componentUrl != null) {
SessionFunctions.setComponentUrlToSession(httpSession, componentUrl);
return componentUrl;
} else {
throw new RuntimeException("No openXMA component specified.");
}
}
protected AppManager createAppManager(HttpSession httpSession) throws IOException, FileNotFoundException {
AppManager manager = (AppManager)httpSession.getAttribute(SessionFunctions.appManagerAttributName);
if (manager != null) {
System.out.println("Found old AppManager when creating a new one in session: "+httpSession);
httpSession.removeAttribute(SessionFunctions.appManagerAttributName);
manager=null;
}
Properties props = getXmaBootHomeProperties();
manager = new AppManager(props);
httpSession.setAttribute(SessionFunctions.appManagerAttributName,manager);
return manager;
}
private Properties getXmaBootHomeProperties() {
Properties props = new Properties();
String xmaBootHomeDir = System.getProperty("xma.boot.homedir");
try {
props.load(new FileInputStream(xmaBootHomeDir+"/settings/bootcfg.properties"));
} catch (Exception e) {
throw new RuntimeException("Can not read settings",e);
}
return props;
}
protected void invokeComponent(String componentUrl, Composite composite) {
HttpSession httpSession = null;
IComponent comp = null;
try {
/* create the application manager */
httpSession = RWT.getSessionStore().getHttpSession();
SessionFunctions.cleanUpSession(httpSession);
AppManager manager = createAppManager(httpSession);
/* create and invoke the component */
comp = manager.getComponent(componentUrl);
SessionFunctions.setComponentToSession(httpSession, comp);
// comp.setProperties...
comp.invoke(composite);
// comp.getProperties...
SessionFunctions.cleanUpSession(httpSession);
} catch (Exception ex) {
SessionFunctions.cleanUpSession(httpSession);
ex.printStackTrace();
Shell msgShell = (composite != null) ? composite.getShell() : null;
MessageBox box = new MessageBox(msgShell);
box.setMessage(ex.getMessage());
box.open();
}
}
/**
*
* @param componentUrl
* @param shell
*/
protected void embeddComponent(String componentUrl, Shell shell) {
HttpSession httpSession = null;
IComponent comp = null;
try {
/* create the application manager */
httpSession = RWT.getSessionStore().getHttpSession();
SessionFunctions.cleanUpSession(httpSession);
AppManager manager = createAppManager(httpSession);
/* create and invoke the component */
comp = manager.getComponent(componentUrl);
SessionFunctions.setComponentToSession(httpSession,comp);
try {
IDialog embeddedDialog = PageUtil.getDialog(comp);
boolean isAppShell = PageUtil.isAppShell(embeddedDialog);
PageUtil.setShell(embeddedDialog,shell);
// if (isAppShell==false) {
// PageUtil.setEventsEnabled(embeddedDialog,true);
// }
PageUtil.setEventsEnabled(embeddedDialog,false);
embeddedDialog.initGUI();
if (isAppShell) {
PageUtil.initForEmbedding(embeddedDialog);
}
shell.setMaximized(true);
shell.layout();
shell.setVisible(true);
embeddedDialog.enterBase();
embeddedDialog.stateChangedBase();
embeddedDialog.updateErrorStatus(embeddedDialog.getFocusControl());
if (isAppShell) {
PageUtil.runRootTask(embeddedDialog);
//PageUtil.setEventsEnabled(embeddedDialog,true);
}
PageUtil.setEventsEnabled(embeddedDialog,true);
} catch (Exception e) {
throw new RuntimeException("Can not invoke methods to embedd a dialog",e);
}
} catch (Exception ex) {
SessionFunctions.cleanUpSession(httpSession);
shell.setMaximized(true);
MessageBox box = new MessageBox(shell);
box.setMessage(ex.getMessage());
box.open();
ex.printStackTrace();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy