Search in sources :

Example 1 with LocationListener

use of org.eclipse.swt.browser.LocationListener in project cubrid-manager by CUBRID.

the class BrowserEditorPart method initBrowser.

private void initBrowser(Composite parent) {
    browser = new Browser(parent, SWT.None);
    browser.setLayoutData(createGridData(FILL_BOTH, 3, 1, -1, -1));
    // Add location change listener
    browser.addLocationListener(new LocationListener() {

        public void changing(LocationEvent e) {
            location.setText(e.location);
        }

        public void changed(LocationEvent e) {
            noOp();
        }
    });
    // Add loading listener
    browser.addProgressListener(new ProgressListener() {

        // Set stopItem and progress bar status
        public void changed(ProgressEvent e) {
            if (!stopItem.isEnabled() && e.total != e.current) {
                stopItem.setEnabled(true);
            }
        }

        // Set stopItem,backItem,forwardItem and progress bar status
        public void completed(ProgressEvent e) {
            stopItem.setEnabled(false);
            backItem.setEnabled(browser.isBackEnabled());
            forwardItem.setEnabled(browser.isForwardEnabled());
        }
    });
}
Also used : ProgressListener(org.eclipse.swt.browser.ProgressListener) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) LocationEvent(org.eclipse.swt.browser.LocationEvent) Browser(org.eclipse.swt.browser.Browser)

Example 2 with LocationListener

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

the class Spoon method showDocumentMap.

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

            @Override
            public void changing(LocationEvent event) {
                if (event.location.endsWith(".pdf")) {
                    Program.launch(event.location);
                    event.doit = false;
                }
            }

            @Override
            public void changed(LocationEvent event) {
                System.out.println("Changed to: " + event.location);
            }
        };
        URL url = new URL(DOCUMENTATION_URL);
        HelpUtils.openHelpDialog(shell, STRING_DOCUMENT_TAB_NAME, url.toString(), listener);
    } catch (MalformedURLException e1) {
        log.logError(Const.getStackTracker(e1));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) LocationListener(org.eclipse.swt.browser.LocationListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) URL(java.net.URL)

Example 3 with LocationListener

use of org.eclipse.swt.browser.LocationListener 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 4 with LocationListener

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

the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_ProgressListener_cancledLoad.

@Test
public /**
 * "event.doit = false" in Location.changing() should stop 'Loction.changed & progress.completed' from getting fired.
 */
void test_LocationListener_ProgressListener_cancledLoad() {
    AtomicBoolean locationChanging = new AtomicBoolean(false);
    AtomicBoolean unexpectedLocationChanged = new AtomicBoolean(false);
    AtomicBoolean unexpectedProgressCompleted = new AtomicBoolean(false);
    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            event.doit = false;
            locationChanging.set(true);
        }

        @Override
        public void changed(LocationEvent event) {
            if (event.location.length() != 0) {
                // See footnote 1
                unexpectedLocationChanged.set(true);
            }
        }
    });
    browser.addProgressListener(completedAdapter(event -> {
        String location = browser.getUrl();
        if (location.length() != 0) {
            // See footnote 1
            unexpectedProgressCompleted.set(true);
        }
    }));
    shell.open();
    browser.setText("You should not see this message.");
    // We must wait for events *not* to fire.
    // On Gtk, Quadcore (Intel i7-4870HQ pci-e SSD, all events fire after ~80ms.
    // For stability, wait 1000 ms.
    waitForMilliseconds(1000);
    boolean passed = locationChanging.get() && !unexpectedLocationChanged.get() && !unexpectedProgressCompleted.get();
    String errMsg = "\nUnexpected event fired. \n" + "LocationChanging (should be true): " + locationChanging.get() + "\n" + "LocationChanged unexpectedly (should be false): " + unexpectedLocationChanged.get() + "\n" + "ProgressChanged unexpectedly (should be false): " + unexpectedProgressCompleted.get() + "\n";
    assertTrue(errMsg, passed);
/* FOOTNOTE 1
	 *
	 * Feature on Internet Explorer. If there is no current location, IE still fires a DocumentComplete
	 * following the BeforeNavigate2 cancel event. This DocumentComplete event contains an empty URL
	 * since the URL in BeforeNavigate2 was correctly cancelled.
	 * The test considers it is OK to send a Location.changed and a Progress.completed events after
	 * a Location.changing cancel true - at the condition that the current location is empty,
	 * otherwise it is considered that the location was not successfully cancelled.
	 */
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StatusTextListener(org.eclipse.swt.browser.StatusTextListener) URL(java.net.URL) Assume.assumeFalse(org.junit.Assume.assumeFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationAdapter(org.eclipse.swt.browser.LocationAdapter) CloseWindowListener(org.eclipse.swt.browser.CloseWindowListener) ProgressListener(org.eclipse.swt.browser.ProgressListener) TitleListener(org.eclipse.swt.browser.TitleListener) VisibilityWindowAdapter(org.eclipse.swt.browser.VisibilityWindowAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Point(org.eclipse.swt.graphics.Point) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) BrowserFunction(org.eclipse.swt.browser.BrowserFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) TestName(org.junit.rules.TestName) LocationListener.changedAdapter(org.eclipse.swt.browser.LocationListener.changedAdapter) VisibilityWindowListener.showAdapter(org.eclipse.swt.browser.VisibilityWindowListener.showAdapter) WindowEvent(org.eclipse.swt.browser.WindowEvent) LocationListener(org.eclipse.swt.browser.LocationListener) ProgressListener.completedAdapter(org.eclipse.swt.browser.ProgressListener.completedAdapter) Assert.fail(org.junit.Assert.fail) SWTException(org.eclipse.swt.SWTException) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Before(org.junit.Before) OpenWindowListener(org.eclipse.swt.browser.OpenWindowListener) ProgressAdapter(org.eclipse.swt.browser.ProgressAdapter) Browser(org.eclipse.swt.browser.Browser) Shell(org.eclipse.swt.widgets.Shell) MalformedURLException(java.net.MalformedURLException) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) LocationListener.changingAdapter(org.eclipse.swt.browser.LocationListener.changingAdapter) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) LocationEvent(org.eclipse.swt.browser.LocationEvent) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationListener(org.eclipse.swt.browser.LocationListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) Test(org.junit.Test)

Example 5 with LocationListener

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

the class Test_org_eclipse_swt_browser_Browser method test_LocationListener_changingAndOnlyThenChanged.

@Test
public void test_LocationListener_changingAndOnlyThenChanged() {
    // Test proper order of events.
    // Check that 'changed' is only fired after 'changing' has fired at least once.
    AtomicBoolean changingFired = new AtomicBoolean(false);
    AtomicBoolean changedFired = new AtomicBoolean(false);
    AtomicBoolean changedFiredTooEarly = new AtomicBoolean(false);
    AtomicBoolean finished = new AtomicBoolean(false);
    browser.addLocationListener(new LocationListener() {

        @Override
        public void changing(LocationEvent event) {
            // Multiple changing events can occur during a load.
            changingFired.set(true);
        }

        @Override
        public void changed(LocationEvent event) {
            if (!changingFired.get())
                changedFiredTooEarly.set(true);
            changedFired.set(true);
            finished.set(true);
        }
    });
    shell.open();
    browser.setText("Hello world");
    waitForPassCondition(() -> finished.get());
    if (finished.get() && changingFired.get() && changedFired.get() && !changedFiredTooEarly.get()) {
        // pass
        return;
    } else if (!finished.get()) {
        fail("Test timed out. 'changed()' never fired");
    } else {
        if (changedFiredTooEarly.get())
            fail("changed() was fired before changing(). Wrong signal order");
        else if (!changingFired.get())
            fail("changing() was never fired");
        else {
            fail("LocationListener test failed. changing():" + changingFired.get() + "  changed():" + changedFired.get() + " changedFiredTooEarly:" + changedFiredTooEarly.get());
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocationListener(org.eclipse.swt.browser.LocationListener) LocationEvent(org.eclipse.swt.browser.LocationEvent) Test(org.junit.Test)

Aggregations

LocationEvent (org.eclipse.swt.browser.LocationEvent)12 LocationListener (org.eclipse.swt.browser.LocationListener)12 Browser (org.eclipse.swt.browser.Browser)6 URL (java.net.URL)4 SWTException (org.eclipse.swt.SWTException)4 MalformedURLException (java.net.MalformedURLException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)3 ProgressListener (org.eclipse.swt.browser.ProgressListener)3 Point (org.eclipse.swt.graphics.Point)3 Test (org.junit.Test)3 TitleListener (org.eclipse.swt.browser.TitleListener)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Shell (org.eclipse.swt.widgets.Shell)2 AEProxyFactory (com.biglybt.core.proxy.AEProxyFactory)1 BrowserWrapper (com.biglybt.ui.swt.BrowserWrapper)1 File (java.io.File)1