All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openxma.rwt.launch.EmbeddInternalComponent Maven / Gradle / Ivy

The newest version!
package org.openxma.rwt.launch;

import javax.servlet.http.HttpServletRequest;

import org.eclipse.rwt.RWT;
import org.eclipse.rwt.lifecycle.IEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.openxma.rwt.bridge.XMARWTApplicationConfigurator;
import org.openxma.rwt.bridge.XMARWTConfiguration;

public class EmbeddInternalComponent extends OpenxmaLauncher implements IEntryPoint {
	
	/**
	 * Determine the component url from the request.
	 * 
	 * @return
	 */
	protected String getInternalComponentUrl() {
		
		HttpServletRequest request = RWT.getRequest();
		
		/* Server a and context path */
		String scheme = request.getScheme();		
		String serverName = request.getServerName();
		Integer serverPort = request.getServerPort();
		String contextPath = request.getContextPath();
		
		/* Component name*/
		String componentName = (String)request.getParameter("component");
		if (componentName != null) {			
			System.out.println("Component url from session: "+componentName);
		} else {
			componentName = XMARWTConfiguration.getInstance().getDefaultComponentName();
		}
		
		if (componentName == null || componentName.length() == 0) {
			throw new RuntimeException("No component name specified");
		}
		
		String componentUrl = scheme+"://"+serverName+":"+serverPort+contextPath+"/"+componentName;
		return componentUrl;						
	}
			
	/**
	 * 
	 */
	public int createUI() {
				
		/* create display and shell */
		Display display = new Display();
		final Shell shell = new Shell(display, SWT.NO_TRIM);				
    	shell.setVisible(false);
		shell.setLayout(new FormLayout());		
		
		/* embedd openXMA component */
		String componentUrl = getInternalComponentUrl();
		embeddComponent(componentUrl,shell);
		
		/* event loop */
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
		return 0;
	}   
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy