Search in sources :

Example 11 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project pentaho-kettle by pentaho.

the class Spoon method showWelcomePage.

public void showWelcomePage() {
    try {
        LocationListener listener = new LocationListener() {

            @Override
            public void changing(LocationEvent event) {
                if (event.location.endsWith(".pdf")) {
                    Program.launch(event.location);
                    event.doit = false;
                } else if (event.location.contains("samples/transformations") || event.location.contains("samples/jobs") || event.location.contains("samples/mapping")) {
                    try {
                        FileObject fileObject = KettleVFS.getFileObject(event.location);
                        if (fileObject.exists()) {
                            if (event.location.endsWith(".ktr") || event.location.endsWith(".kjb")) {
                                openFile(event.location, false);
                            } else {
                                lastDirOpened = KettleVFS.getFilename(fileObject);
                                openFile(true);
                            }
                            event.doit = false;
                        }
                    } catch (Exception e) {
                        log.logError("Error handling samples location: " + event.location, e);
                    }
                }
            }

            @Override
            public void changed(LocationEvent event) {
            // System.out.println("Changed to: " + event.location);
            }
        };
        // create callback functions for welcome
        Runnable openFileFunction = new Runnable() {

            public void run() {
                Spoon.this.openFile();
            }
        };
        Runnable newTransFunction = new Runnable() {

            public void run() {
                Spoon.this.newTransFile();
            }
        };
        Runnable newJobFunction = new Runnable() {

            public void run() {
                Spoon.this.newJobFile();
            }
        };
        HashMap<String, Runnable> functions = new HashMap<String, Runnable>();
        functions.put("openFileFunction", openFileFunction);
        functions.put("newTransFunction", newTransFunction);
        functions.put("newJobFunction", newJobFunction);
        // see if we are in webstart mode
        String webstartRoot = System.getProperty("spoon.webstartroot");
        if (webstartRoot != null) {
            URL url = new URL(webstartRoot + '/' + FILE_WELCOME_PAGE);
            // ./docs/English/tips/index.htm
            addSpoonBrowser(STRING_WELCOME_TAB_NAME, url.toString(), true, listener, functions, false);
        } else {
            // see if we can find the welcome file on the file system
            File file = new File(FILE_WELCOME_PAGE);
            if (file.exists()) {
                // ./docs/English/tips/index.htm
                addSpoonBrowser(STRING_WELCOME_TAB_NAME, file.toURI().toURL().toString(), true, listener, functions, false);
            }
        }
    } catch (MalformedURLException e1) {
        log.logError(Const.getStackTracker(e1));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) LocationListener(org.eclipse.swt.browser.LocationListener) WaitBoxRunnable(org.pentaho.ui.xul.components.WaitBoxRunnable) FileObject(org.apache.commons.vfs2.FileObject) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LastUsedFile(org.pentaho.di.core.LastUsedFile) File(java.io.File) LocationEvent(org.eclipse.swt.browser.LocationEvent) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 12 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project archi by archimatetool.

the class BrowserEditor method createBrowser.

/**
 * Create the Browser if possible
 */
protected Browser createBrowser(Composite parent) {
    Browser browser = null;
    try {
        browser = new Browser(parent, SWT.NONE);
        browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
        // Don't allow external hosts if set
        browser.addLocationListener(new LocationAdapter() {

            @Override
            public void changing(LocationEvent e) {
                if (getEditorInput() != null && !getEditorInput().getExternalHostsEnabled()) {
                    e.doit = e.location != null && (// $NON-NLS-1$
                    e.location.startsWith("file:") || // $NON-NLS-1$
                    e.location.startsWith("data:") || // $NON-NLS-1$
                    e.location.startsWith("about:"));
                }
            }
        });
    } catch (SWTError error) {
        error.printStackTrace();
        // Remove junk child controls that might be created with failed load
        for (Control child : parent.getChildren()) {
            child.dispose();
        }
    }
    return browser;
}
Also used : SWTError(org.eclipse.swt.SWTError) Control(org.eclipse.swt.widgets.Control) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) GridData(org.eclipse.swt.layout.GridData) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 13 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project archi by archimatetool.

the class HintsView method createBrowser.

/**
 * Create the Browser if possible
 */
private Browser createBrowser(Composite parent) {
    Browser browser = null;
    try {
        browser = new Browser(parent, SWT.NONE);
        // Don't allow external hosts if set
        browser.addLocationListener(new LocationAdapter() {

            @Override
            public void changing(LocationEvent e) {
                if (!ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.HINTS_BROWSER_EXTERNAL_HOSTS_ENABLED)) {
                    e.doit = e.location != null && (// $NON-NLS-1$
                    e.location.startsWith("file:") || // $NON-NLS-1$
                    e.location.startsWith("data:") || // $NON-NLS-1$
                    e.location.startsWith("about:"));
                }
            }
        });
    } catch (SWTError error) {
        error.printStackTrace();
        // Remove junk child controls that might be created with failed load
        for (Control child : parent.getChildren()) {
            if (child != fTitleLabel) {
                child.dispose();
            }
        }
    }
    return browser;
}
Also used : SWTError(org.eclipse.swt.SWTError) Control(org.eclipse.swt.widgets.Control) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 14 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_evaluateInCallback.

/**
 *  This test replicates what happens internally
 *  if you click on a link in a javadoc popup hoverbox.
 *  I.e, in a location listener, evaluation() is performed.
 *
 *  The goal of this test is to ensure there are no 'Freezes'/deadlocks if
 *  javascript evaluation is invoked inside an SWT listener.
 *
 *  At time of writing, it also highlights that evaluation inside SWT listeners
 *  is not consistent across browsers.
 */
@Test
public void test_LocationListener_evaluateInCallback() {
    assumeTrue(isWebkit2 || SwtTestUtil.isCocoa || SwtTestUtil.isWindows);
    // On Webki1 this test works, but is prone to crashes. See Bug 509411
    AtomicBoolean changingFinished = new AtomicBoolean(false);
    AtomicBoolean changedFinished = new AtomicBoolean(false);
    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            // Broken on Webkit1. I.e evaluate() in a 'changing()' signal doesn't do anything.
            browser.evaluate("SWTchanging = true");
            changingFinished.set(true);
        }

        @Override
        public void changed(LocationEvent event) {
            browser.evaluate("SWTchanged = true");
            changedFinished.set(true);
        }
    });
    browser.setText("<body>Hello <b>World</b></body>");
    // Wait till both listeners were fired.
    if (SwtTestUtil.isWindows) {
        // Windows doesn't reach changedFinished.get();
        waitForPassCondition(changingFinished::get);
    } else
        waitForPassCondition(() -> (changingFinished.get() && changedFinished.get()));
    // Inspect if evaluate() was executed correctly.
    Boolean changed = false;
    try {
        changed = (Boolean) browser.evaluate("return SWTchanged");
    } catch (SWTException e) {
    }
    Boolean changing = false;
    try {
        changing = (Boolean) browser.evaluate("return SWTchanging");
    } catch (SWTException e) {
    }
    String errMsg = "\n  changing:  fired:" + changingFinished.get() + "    evaluated:" + changing + "\n  changed:   fired:" + changedFinished.get() + "    evaluated:" + changed;
    boolean passed = false;
    if (isWebkit2) {
        // Evaluation works in all cases.
        passed = changingFinished.get() && changedFinished.get() && changed && changing;
    } else if (isWebkit1) {
        // On Webkit1, evaluation in 'changing' fails.
        // && changing (broken)
        passed = changingFinished.get() && changedFinished.get() && changed;
    } else if (SwtTestUtil.isCocoa) {
        // On Cocoa, evaluation in 'changing' fails.
        // && changing (broken)
        passed = changingFinished.get() && changedFinished.get() && changed;
    } else if (SwtTestUtil.isWindows) {
        // On Windows, evaluation inside SWT listeners fails altogether.
        // Further, only 'changing' is fired if evaluation is invoked inside listeners.
        passed = changingFinished.get();
    }
    assertTrue(errMsg, passed);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SWTException(org.eclipse.swt.SWTException) LocationListener(org.eclipse.swt.browser.LocationListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationEvent(org.eclipse.swt.browser.LocationEvent) Test(org.junit.Test)

Example 15 with LocationEvent

use of org.eclipse.swt.browser.LocationEvent in project BiglyBT by BiglySoftware.

the class SearchResultsTabAreaBrowser method anotherSearch.

@Override
public void anotherSearch(SearchQuery sq) {
    this.sq = sq;
    String url = Constants.URL_WEBSEARCH.replaceAll("%s", UrlUtils.encode(sq.term));
    AEProxyFactory.PluginHTTPProxy proxy = getSearchProxy(this);
    if (proxy != null) {
        url = proxy.proxifyURL(url);
    }
    if (Utils.isThisThreadSWT()) {
        try {
            final AESemaphore sem = new AESemaphore("brwoserWait");
            final BrowserWrapper browser = browserSkinObject.getBrowser();
            browser.addLocationListener(new LocationListener() {

                @Override
                public void changing(LocationEvent event) {
                }

                @Override
                public void changed(LocationEvent event) {
                    browser.removeLocationListener(this);
                    sem.releaseForever();
                }
            });
            browserSkinObject.getBrowser().setUrl("about:blank");
            browserSkinObject.getBrowser().refresh();
            browserSkinObject.getBrowser().update();
            final String finalURL = url;
            Utils.getOffOfSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    sem.reserve(300);
                    browserSkinObject.setURL(finalURL);
                }
            });
        } catch (Throwable t) {
        }
    } else {
        browserSkinObject.setURL(url);
    }
}
Also used : LocationListener(org.eclipse.swt.browser.LocationListener) BrowserWrapper(com.biglybt.ui.swt.BrowserWrapper) AEProxyFactory(com.biglybt.core.proxy.AEProxyFactory) LocationEvent(org.eclipse.swt.browser.LocationEvent)

Aggregations

LocationEvent (org.eclipse.swt.browser.LocationEvent)17 LocationListener (org.eclipse.swt.browser.LocationListener)12 Browser (org.eclipse.swt.browser.Browser)11 LocationAdapter (org.eclipse.swt.browser.LocationAdapter)6 URL (java.net.URL)4 SWTException (org.eclipse.swt.SWTException)4 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)4 ProgressListener (org.eclipse.swt.browser.ProgressListener)4 Point (org.eclipse.swt.graphics.Point)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 SWTError (org.eclipse.swt.SWTError)3 Composite (org.eclipse.swt.widgets.Composite)3 Test (org.junit.Test)3 MalformedURLException (java.net.MalformedURLException)2 OpenWindowListener (org.eclipse.swt.browser.OpenWindowListener)2 TitleListener (org.eclipse.swt.browser.TitleListener)2 WindowEvent (org.eclipse.swt.browser.WindowEvent)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2