Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330332

Summary: Integration of XWT Form in Wizard
Product: [Technology] XWT Reporter: Yves YANG <yves.yang>
Component: CoreAssignee: Project Inbox <e4.xwt-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 Flags: yves.yang: iplog+
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Yves YANG CLA 2010-11-16 05:30:06 EST
A request on the integration of XWT in wizard is submitted in e4 newsgroup:
http://www.eclipse.org/forums/index.php?t=msg&th=199619&start=0&S=eeee2217897168580b83685b5756bc21
Comment 1 Yves YANG CLA 2010-11-16 05:32:54 EST
The code is posted by the author (Valoueee) in e4 newsgroup:

package myproject.ui;

public class XWTWizardPage extends WizardPage {

    private Object dataContext;
    private BindingContext bindingContext;
    private AggregateValidationStatus validationStatus;
    
    private Class<?> contentCLS;
    
    /**
     * @param _pageName
     */
    protected XWTWizardPage(String _pageName, Class<?> contentCLS,
            Object dataContext) {
        super(_pageName);
        this.contentCLS = contentCLS;
        this.dataContext = dataContext;
        this.bindingContext = null;
    }
    
    protected XWTWizardPage(String pageName, String title,
            ImageDescriptor titleImage, Class<?> contentCLS,
            Object dataContext) {
        super(pageName, title, null);
        this.contentCLS = contentCLS;
        this.dataContext = dataContext;
        this.bindingContext = null;
    }

   
    @Override
    public void createControl(Composite _parent) {
        
        if (bindingContext == null) {
            bindingContext = new BindingContext(_parent);
        }
        validationStatus = bindingContext.getStatus();
        validationStatus.addChangeListener(new IChangeListener() {
                public void handleChange(ChangeEvent event) {
                        IStatus status = (IStatus) validationStatus.getValue();
                        setMessage(status.getMessage(), status.getSeverity());
                }
        });
    
        ClassLoader classLoader = Thread.currentThread()
                        .getContextClassLoader();
        try {
                Thread.currentThread().setContextClassLoader(
                                contentCLS.getClassLoader());
                HashMap<String, Object> newOptions = new HashMap<String, Object>();
                newOptions.put(XWTLoader.CONTAINER_PROPERTY, _parent);
                Object dataContext = getDataContext();
                if (dataContext != null) {
                        newOptions.put(XWTLoader.DATACONTEXT_PROPERTY, dataContext);
                }
                BindingContext bindingContext = getBindingContext();
                if (bindingContext != null) {
                        newOptions.put(XWTLoader.BINDING_CONTEXT_PROPERTY,
                                        bindingContext);
                }
                newOptions.put(XWTLoader.CLASS_PROPERTY, contentCLS);
    
                Control control = XWT.loadWithOptions(getContentURL(), newOptions);
                control.setParent(_parent);                                            
                
                setPageComplete(true);
                
                setControl(control);
                
        } catch (Exception e) {
                e.printStackTrace();
        } finally {
                Thread.currentThread().setContextClassLoader(classLoader);
                _parent.setVisible(true);
        }

    }
    
    public URL getContentURL() {
        if (contentCLS != null) {
                return contentCLS.getResource(contentCLS.getSimpleName()
                                + IConstants.XWT_EXTENSION_SUFFIX);
        }
        return null; 
    }
    
    public Object getDataContext() {
            return dataContext;
    }
    
    public BindingContext getBindingContext() {
            return bindingContext;
    }
}
Comment 2 Yves YANG CLA 2010-11-16 06:07:50 EST
The contribution code has implemented the data binding such as dataContext and the connection of data binding validation with the Wizard message. I think there are some limitations:
  1. It is limited to load the UI through the class. 
     It is not possible to load a UI Resource with a different name to class or without CLR class
  2. The completePage status is not handled automatically.
Comment 3 Yves YANG CLA 2010-11-16 06:33:24 EST
The XWT UIResource concept should be supported as well to avoid the XML loading and parsing each time.