at.spardat.xma.boot.component.ComponentHelper Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
/*
* @(#) $Id: ComponentHelper.java 2084 2007-11-27 14:53:31Z s3460 $
*/
package at.spardat.xma.boot.component;
import java.util.Properties;
import org.eclipse.swt.widgets.Display;
/**
* This class is deployed in the same classloader as SWT and IComponent.
* It encapsulates the code of the bootruntime which is dependend on SWT.
* @author s2877
*/
public class ComponentHelper implements IComponentHelper {
private static Display display;
private static boolean display_created=false;
/**
* Just casts the given object to IComponent.
* @return the unchanged component
* @throws ClassCastException if the given object is not an IComponent
*/
public IComponent castToIComponent(Object component) {
return (IComponent) component;
}
/**
* Calls {@link IComponent#getRTSession()} on the given component.
* @return the client side session the given component belongs to.
* @throws ClassCastException if the given object is not an IComponent
*/
public IRtXMASessionClient getRTSession(Object component) {
return ((IComponent)component).getRTSession();
}
/**
* Launches the given component. The input properties are passed to the component,
* then the component is invoked. Finally the component is disposed.
* @return the output properties of the given component
* @throws ClassCastException if the given object is not an IComponent
*/
public Properties launch(Object component, Properties input) {
IComponent rtc = (IComponent) component;
try {
rtc.setProperties(input);
rtc.invoke(null);
return rtc.getProperties();
} finally {
rtc.dispose();
}
}
/**
* Creates a Display in SWT if none allready exists.
* @return the preexisting or created Display.
*/
public Object initSWTDisplay() {
display = Display.getCurrent();
if(display==null) {
display_created = true;
display = Display.getDefault();
}
return display;
}
/**
* Disposes the display created by {@link #initSWTDisplay()} of this ComponentHelper.
* If no display was created by {@link #initSWTDisplay()}, it does nothing.
*/
public void cleanupSWTDisplay() {
if(display!=null && display_created) {
display.dispose();
display_created = false;
}
}
}