Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Control over SWT Browser Widget ?
Control over SWT Browser Widget ? [message #447707] Thu, 16 December 2004 13:37 Go to next message
Eclipse UserFriend
Originally posted by: ssc.acentic.net

Hi

I have a little javascript/php driven HTML WYSIWYG editor, which I now
implemented into a SWT application. I would really like to get rid off the
php stuff, but to do so I need more control over the content in the browser
widget.

How much control do I actually have over the browser widget ?

I know that there are a few Listeners available and with the new 3.1 M3 I
found the execute command very handy to implement javascript commands. For
the time beeing I only see a way to use the StatusTextListener to have any
feedback from the displayed html page.
Is there a direct way to call a method directly from the html page with
javascript ?

-Sebastian
Re: Control over SWT Browser Widget ? [message #447713 is a reply to message #447707] Thu, 16 December 2004 15:32 Go to previous messageGo to next message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
> Is there a direct way to call a method directly from the html page with
> javascript ?
No. The way you described is the typical one.
Step 1. html page modifies the window.status DOM attribute. e.g.
"window.status=myAction1"
Step 2. SWT Browser receives a StatusTextListener notification "myAction1"
and application code can respond accordingly.

browser.addStatusTextListener(new StatusTextListener() {
public void changed(StatusTextEvent event) {
if (event.text.equals("myAction1") { ... }
}
});

For a related example that you have probably already seen, see the following
snippet "query DOM node value"
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet160.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup

If you only need to invoke a particular method when one of your own links is
activated, then it is simpler to set your link such as:
<a href="http://www.org.eclipse.myplugin/actionOpenEditor>Open Editor</a>

And then listen to LocationListener.changing notifications.

e.g. here is a simple demo.

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.browser.*;

public class PRBrowser {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("PRBrowser");
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
browser.addLocationListener(new LocationListener() {
public void changing(LocationEvent event) {
if (event.location.indexOf("openEditor") != -1) {
event.doit = false; // cancel the navigation since it is not a real
link
openEditor();
}
}
public void changed(LocationEvent event) {
}
});
browser.setText("<html><body><a
href=\"http://www.org.eclipse.myplugin/openEditor\">Open
Editor</a></body></html>");
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

public static void openEditor() {
System.out.println("Open Editor");
}
}
Re: Control over SWT Browser Widget ? [message #447752 is a reply to message #447713] Fri, 17 December 2004 08:22 Go to previous message
Eclipse UserFriend
Originally posted by: ssc.acentic.net

So I will follow my original solution

Thanks

Sebastian

Christophe Cornu wrote:

>> Is there a direct way to call a method directly from the html page with
>> javascript ?
> No. The way you described is the typical one.
> Step 1. html page modifies the window.status DOM attribute. e.g.
> "window.status=myAction1"
> Step 2. SWT Browser receives a StatusTextListener notification "myAction1"
> and application code can respond accordingly.

> browser.addStatusTextListener(new StatusTextListener() {
> public void changed(StatusTextEvent event) {
> if (event.text.equals("myAction1") { ... }
> }
> });

> For a related example that you have probably already seen, see the following
> snippet "query DOM node value"
>
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet160.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup

> If you only need to invoke a particular method when one of your own links is
> activated, then it is simpler to set your link such as:
> <a href="http://www.org.eclipse.myplugin/actionOpenEditor>Open Editor</a>

> And then listen to LocationListener.changing notifications.

> e.g. here is a simple demo.

> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.browser.*;

> public class PRBrowser {

> public static void main(String[] args) {
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setText("PRBrowser");
> shell.setLayout(new FillLayout());
> Browser browser = new Browser(shell, SWT.NONE);
> browser.addLocationListener(new LocationListener() {
> public void changing(LocationEvent event) {
> if (event.location.indexOf("openEditor") != -1) {
> event.doit = false; // cancel the navigation since it is not a real
> link
> openEditor();
> }
> }
> public void changed(LocationEvent event) {
> }
> });
> browser.setText("<html><body><a
> href="http://www.org.eclipse.myplugin/openEditor">Open
> Editor</a></body></html>");
> shell.open();

> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> }

> public static void openEditor() {
> System.out.println("Open Editor");
> }
> }
Previous Topic:Trying to find a widget that behaves like widget in Outlook 2003
Next Topic:GridLayout: can I have an empty cell in the grid?
Goto Forum:
  


Current Time: Sat Oct 31 16:55:37 GMT 2020

Powered by FUDForum. Page generated in 0.02146 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top