[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] SWT Browser How-to show new composite

When an error is catch (Error 404) I would like show a new composite (parentController.showProbemeOpenflyers) but my application block to the current browser.

parentController.showProblemeOpenflyers make a stackLayout.topControl to set a Composite ProblemeOpenflyers and make a setLayout()

How do make  this ?

package datacet.acm.gui.view;

import java.io.File;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.CloseWindowListener;
import org.eclipse.swt.browser.WindowEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.mozilla.interfaces.nsIHttpChannel;
import org.mozilla.interfaces.nsIObserver;
import org.mozilla.interfaces.nsIObserverService;
import org.mozilla.interfaces.nsIRequest;
import org.mozilla.interfaces.nsISupports;
import org.mozilla.xpcom.Mozilla;

import datacet.acm.deister.ClesOuvertureDegrade;
import datacet.acm.gui.controller.OuvrirVolController;
import datacet.acm.gui.controller.ParentController;
import datacet.acm.gui.listener.OuvrirVolProgressListener;
import datacet.acm.util.FichierConfiguration;

public class OuvrirVol extends Composite {
    private OuvrirVolController ouvrirVolController;
   
    private OuvrirVol ouvrirVol;

    private Browser browser;
   
    private OuvrirVolProgressListener ouvrirVolProgressListener;
   
    /**
     * Create the composite.
     * @param parent
     * @param style
     */
    public OuvrirVol(final ParentController parentController, int style) {
        super(parentController.getComposite(), style);
        ouvrirVol = this;
        setLayout(new GridLayout(1, false));

        this.ouvrirVolController = new OuvrirVolController();

        Mozilla.getInstance().initialize(new File("/home/user/xulrunner/xulrunner-sdk/bin/"));
       

        browser = new Browser(this, SWT.MOZILLA);
        browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        browser.setUrl(FichierConfiguration.getParameter("OPENFLYERS.DECONNECTION"));


        final Button accueilPageAdherent = new Button(this, SWT.NONE);
        accueilPageAdherent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
        accueilPageAdherent.setFont(Parent.FONT_TITLE);
        accueilPageAdherent.setText(ouvrirVolController.getName(0));
        accueilPageAdherent.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event arg0) {
                // TODO Auto-generated method stub
                ouvrirVolController.action(parentController, accueilPageAdherent);
            }

        });

        browser.addListener(SWT.MenuDetect, new Listener() {
            public void handleEvent(Event event) {
                event.doit = false;
            }
        });
       
        nsIObserver observer = new nsIObserver() {
            public nsISupports queryInterface(String aIID) {
                if (aIID.equals(nsIObserver.NS_IOBSERVER_IID) || aIID.equals(nsIObserver.NS_ISUPPORTS_IID)) {
                    return this;
                }
                return null;
            }
            public void observe(nsISupports subject, String topic, String data)  {
                nsIHttpChannel channel = (nsIHttpChannel)subject.queryInterface(nsIHttpChannel.NS_IHTTPCHANNEL_IID);
                nsIRequest request = (nsIRequest)subject.queryInterface(nsIRequest.NS_IREQUEST_IID);
                if (topic.equals("http-on-modify-request")) {

                }
                else {
                    /* http-on-examine-response */
                    System.out.println("---------------------\n\tSome Response Header Values for " + request.getName() + ':');
                    System.out.println( "\t" + channel.getResponseStatus() +" " + channel.getResponseStatusText() );
                    if(channel.getResponseStatus()==404) {

                        parentController.showProblemeOpenflyers();

                
                       try {
                            Thread.sleep(10000);
                        } catch (InterruptedException e) {
                           e.printStackTrace();
                        }
                        //new ClesOuvertureDegrade(parentController, parentController.getDisplay());;
                        browser.stop();
                    }
                }
            }

        };
        nsIObserverService observerService = (nsIObserverService)Mozilla.getInstance().getServiceManager().getServiceByContractID(
            "@mozilla.org/observer-service;1", nsIObserverService.NS_IOBSERVERSERVICE_IID);
        observerService.addObserver(observer, "http-on-modify-request", false);
        observerService.addObserver(observer, "http-on-examine-response", false);

        //ouvrirVolProgressListener = new OuvrirVolProgressListener(browser, parentController);
        //browser.addProgressListener(ouvrirVolProgressListener);
       

    }
   
    public void closeBrowser() {
        browser.close();
    }
   
    public String getText() {
        //while(ouvrirVolProgressListener.getChange());
        return browser.getText();
    }

    @Override
    protected void checkSubclass() {
        // Disable the check that prevents subclassing of SWT components
    }

}