SWT Browser problem [message #522982] |
Wed, 24 March 2010 12:48  |
Eclipse User |
|
|
|
Recently, I have been developing a application which opens a SWT browser to browse the customer details. My application takes input from the other application and opens swt browser as new thread.
As SWT browser uses IE for html rendering. It works fine with IE 7.0 or greater but with IE 6.0 it has some problem.
When i start my application, for first time swt browser works fine and shows the page for given URL but from second time it starts asking to open save or cancel the html page which IE has rendered. It saves the current URL in IE temp files and tries to open it from that location and asks if i want to open save or cancel. If i click open then it opens into IE browser not into SWT display. SWT display remains blank and i get my URL opened into IE which i do not want to happen.
Please can someone tell me what is going wrong?
|
|
|
|
|
|
|
|
Re: SWT Browser problem [message #524357 is a reply to message #524035] |
Wed, 31 March 2010 11:37   |
Eclipse User |
|
|
|
I've tried this with tomcat and don't see the problem. My test snippet is
different from yours though (pasted below), since I don't have the other
classes you were using. Are you able to reduce your case to one that shows
the problem but does not use any classes outside of swt? Also, what is your
stand-alone IE's version string from Help->About Internet Explorer? I have
6.0.2800.1106.
public class Main {
static boolean closeBrowser;
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display, SWT.TITLE);
// try {
// InteractiveAlert interactiveAlert = (InteractiveAlert)
session.load(InteractiveAlert.class, alertID);
// if (delay > 0) {
// logger.debug("Interactive SWT Thread sleeping for " + delay);
// Thread.sleep(delay);
// updateStatus();
// }
// super.isOpen = true;
shell.setText(/*interactiveParameters.getFrameTitle()*/"Shell title");
final Browser browser = new Browser(shell, SWT.NONE);
// the following listener is not expected to ever be invoked
browser.addCloseWindowListener(new CloseWindowListener() {
public void close(WindowEvent arg0) {
closeBrowser = true;
}
});
// if (interactiveParameters.isFullScreenMode()) {
// Monitor monitor = shell.getMonitor();
// Rectangle bounds = monitor.getBounds();
// browser.setSize(bounds.width, bounds.height);
// } else {
// browser.setSize(interactiveParameters.getBrowser_width(),
// interactiveParameters.getBrowser_height());
// shell.setSize(interactiveParameters.getBrowser_width(),
// interactiveParameters.getBrowser_height());
shell.setSize(250,250);
browser.setSize(200,200);
// }
final String url = /*createURL(*/"http://localhost:8080/test.html"/*)*/;
browser.setUrl(url);
// if (interactiveParameters.isBeepEnabled()) {
// // display.beep();
// System.out.print("\007");
// System.out.flush();
// }
shell.open();
// shell.setFullScreen(interactiveParameters.isFullScreenMode() );
// shell.setMinimized(interactiveParameters.isMinimizedMode());
shell.forceActive();
shell.setActive();
Runnable runnable = new Runnable() {
public void run() {
if (browser.isDisposed()) return;
System.out.println("here");
browser.setUrl(url);
display.timerExec(999, this);
}
};
display.timerExec(999, runnable);
while (!shell.isDisposed() && !closeBrowser) {
if (!display.readAndDispatch()) display.sleep();
}
// }
display.dispose();
// } catch (SWTError e) {
// MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR |
SWT.OK);
// messageBox.setMessage("Browser cannot be initialized.");
// messageBox.setText("Exit");
// messageBox.open();
// } catch (InterruptedException e) {
// closeBrowser = true;
// logger.info("Closing.");
// } catch (Exception e) {
// logger.error("Error while loading swt browser " + e);
// } finally {
// super.isOpen = false;
// session.close();
// }
}
}
Grant
"Manish Veerwal" <manish.veerwal@gmail.com> wrote in message
news:hosqo6$ham$1@build.eclipse.org...
> Content is always same. It is not changing everytime. I think you can
reproduce the problem. It is not even about the page. Problem even happens
with the simple html page without any content in it. one can create a simple
html page like:
> <html>
> <body>
> </body>
> </html>
>
> put into your tomcat server and try to access it from swt browser
repeatedly. problem happens if IE 6.0 is installed on the machine.
>
>
>
|
|
|
|
Re: SWT Browser problem [message #525793 is a reply to message #524472] |
Wed, 07 April 2010 15:48   |
Eclipse User |
|
|
|
Hi, sorry for the late follow-up,
I actually see a crash when using this approach (IE6 on Windows 2000), so
there's definitely a problem here. My suspicion is that it's the use of
background threads, which should not be needed for what's being done here,
especially given how asynchronous the Browser is. I've re-written the
snippet to use a single thread and it works for me (no crash and does not
ask to save the file). Does this work better for you? Are you able to
transfer an approach like this into your app?
public class Main {
static boolean close = false;
static Display display;
static Shell lastShell;
static String URL = "..."; // TODO set this
public static void main(String[] args) {
display = new Display();
int count = Integer.parseInt(args[0]);
for (int i = 0; i < count; i++) {
display.timerExec(5000 * i, new Runnable() {
public void run() {
doit();
}
});
}
display.timerExec(5000 * count, new Runnable() {
public void run() {
close = true;
}
});
while (!close) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
static void doit() {
if (lastShell != null) lastShell.dispose();
Shell shell = new Shell(display, SWT.CLOSE);
lastShell = shell;
RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
rowLayout.justify = true;
rowLayout.fill = true;
shell.setLayout(rowLayout);
shell.setText("Browser Example");
Browser browser = new Browser(shell, SWT.NONE);
browser.addCloseWindowListener(new CloseWindowListener() {
public void close(WindowEvent event) {
close = true;
}
});
browser.setBounds(shell.getClientArea());
Button button = new Button(shell, SWT.PUSH);
button.setText("HI");
display.beep();
shell.pack();
shell.open();
browser.setUrl(URL);
shell.setMinimized(false);
}
}
Grant
"Manish Veerwal" <manish.veerwal@gmail.com> wrote in message
news:hp1e6u$rlp$1@build.eclipse.org...
> ok...below is my code snippet which i am using to recreate the problem:
>
> public class SWTBrowser extends Thread {
> public static final boolean FULL_SCREEN = false;
>
> private Browser browser = null;
>
> private Display display = null;
>
> private Shell shell = null;
>
> private boolean close = false;
>
> private boolean urlChange = false;
>
> private String url = null;
>
> public SWTBrowser() {
>
> }
>
> @Override
> public void run() {
> show();
> }
>
> public void show() {
> display = new Display();
> shell = new Shell(display, SWT.CLOSE);
>
> RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
> rowLayout.justify = true;
> rowLayout.fill = true;
>
> shell.setLayout(rowLayout);
> shell.setText("Browser Example");
> try {
> browser = new Browser(shell, SWT.MIN);
> browser.addCloseWindowListener(new CloseWindowListener() {
>
> public void close(WindowEvent event) {
> close = true;
> }
> });
> if (FULL_SCREEN) {
> Monitor monitor = shell.getMonitor();
> Rectangle bounds = monitor.getBounds();
> browser.setSize(bounds.width, bounds.height);
> } else {
> browser.setBounds(shell.getClientArea());
> }
>
> display.beep();
> shell.pack();
> shell.open();
> browser.setUrl("http://localhost:8080");
> shell.setFullScreen(FULL_SCREEN);
> shell.setMinimized(false);
> while (!shell.isDisposed() && !close) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
> browser.dispose();
> display.dispose();
> } catch (SWTError e) {
> MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR
> | SWT.OK);
> messageBox.setMessage("Browser cannot be initialized.");
> messageBox.setText("Exit");
> messageBox.open();
> System.exit(-1);
> }
> }
>
> public void setURL() {
> urlChange = true;
> url = "http://localhost:8080";
> }
>
> public void close() {
> close = true;
> }
>
> /**
> * @param args
> */
> public static void main(String[] args) {
> SWTBrowser swtBrowser = new SWTBrowser();
> for (int i = 0; i < Integer.parseInt(args[0]); i++) {
> swtBrowser = new SWTBrowser();
> swtBrowser.start();
> swtBrowser.setURL();
> try {
> Thread.sleep(5000);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> swtBrowser.close();
> }
> }
> }
>
>
> In above code, if you run it , it will open a swt browser and then it will
be closed after 5 secs. pass the args more than 4. Now if you let it run
without your interaction means let the swt browser close after 5 secs it
will work fine. but try to close the swt browser by clicking close button
then from next time when next browser will open it will ask for open save
and cancel.
>
> My IE version is 6.0.2900.2180.xpsp_sp2_gdr.091208-2028
|
|
|
Re: SWT Browser problem [message #526544 is a reply to message #525793] |
Mon, 12 April 2010 04:59  |
Eclipse User |
|
|
|
I am sorry for late reply. Thank you very much. It has solved my problem. It was really a background thread problem. i made few changes also. Instead of closing browser using close boolean, I am calling shell.dispose() in asyncExec method. Thats work perfect.
Thank you.
|
|
|
Powered by
FUDForum. Page generated in 0.29656 seconds