Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Wizard with xwt
Wizard with xwt [message #636960] Wed, 03 November 2010 10:32 Go to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 57
Registered: September 2009
Member
Hello,

Is it possible to define wizard's pages with XWT ?

Have you got a simple example ?

My aim is to reuse a page (ie a XWT file) in several wizard.

Thank you.
Re: Wizard with xwt [message #637172 is a reply to message #636960] Thu, 04 November 2010 09:12 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 57
Registered: September 2009
Member
Hello,

I reply to me because I found a solution. I added a class XWTWizardPage which load XWT file.

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;
    }

}


The ActionWizard class is the wizard which add pages:

public class ActionWizard extends Wizard {
    
    private PropagationData m_data;
    
    public ActionWizard() {
        super();
      }

      public void addPages() {      
        addPage(new OnePage(FirstPage.class, data)); // data is used for binding in FirstPage.xwt
        addPage(new TwoPage(SecondPage.class, data));// data is used for binding in SecondPage.xwt
      }
}


OnePage.java and TwoPage.java extend XWTWizardPage.java.

Then, you have to define FirstPage.xwt which contains a Composite, and FirstPage.java which extends Composite.
The same for SecondPage.
Re: Wizard with xwt [message #637615 is a reply to message #637172] Sun, 07 November 2010 16:42 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANG
Messages: 687
Registered: July 2009
Senior Member
Can you fill a bug in bugzilla and add your code in it? It helps the
integration in XWT.

Best regards
Yves YANG
"Valoueee" <val.dupin@free.fr> wrote in message
news:iaub9b$o9j$1@news.eclipse.org...
> Hello,
>
> I reply to me because I found a solution. I added a class XWTWizardPage
> which load XWT file.
>
> 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;
> }
>
> }
>
> The ActionWizard class is the wizard which add pages:
>
> public class ActionWizard extends Wizard {
> private PropagationData m_data;
> public ActionWizard() {
> super();
> }
>
> public void addPages() { addPage(new OnePage(FirstPage.class,
> data)); // data is used for binding in FirstPage.xwt
> addPage(new TwoPage(SecondPage.class, data));// data is used for
> binding in SecondPage.xwt
> }
> }
>
>
> OnePage.java and TwoPage.java extend XWTWizardPage.java.
>
> Then, you have to define FirstPage.xwt which contains a Composite, and
> FirstPage.java which extends Composite.
> The same for SecondPage.
Re: Wizard with xwt [message #637648 is a reply to message #637615] Mon, 08 November 2010 03:37 Go to previous messageGo to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 57
Registered: September 2009
Member
Hello,

Are you sure it's a bug ? I think It's a lack no ?
Re: Wizard with xwt [message #637808 is a reply to message #637648] Mon, 08 November 2010 18:19 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANG
Messages: 687
Registered: July 2009
Senior Member
It is not a bug. But eclipse uses the bugzilla to handle each case. It is
the way we work.

Best regards
Yves YNAG
"Valoueee" <val.dupin@free.fr> wrote in message
news:ib8cli$ekk$1@news.eclipse.org...
> Hello,
>
> Are you sure it's a bug ? I think It's a lack no ?
Re: Wizard with xwt [message #639385 is a reply to message #636960] Tue, 16 November 2010 05:57 Go to previous message
Yves YANG is currently offline Yves YANG
Messages: 687
Registered: July 2009
Senior Member
The bug is created here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=330332

Please join this bug to discuss the design and follow the integration and development.

[Updated on: Tue, 16 November 2010 05:58]

Report message to a moderator

Previous Topic:Consistent duplication of custom xwt UI
Next Topic:Can't reopen a persisted closed part!
Goto Forum:
  


Current Time: Tue Jul 29 13:12:06 EDT 2014

Powered by FUDForum. Page generated in 0.03697 seconds