|
|
Re: SWT Browser problem [message #523383 is a reply to message #523234] |
Fri, 26 March 2010 09:19 |
Manish Veerwal Messages: 5 Registered: March 2010 |
Junior Member |
|
|
My code for browser is as follows:
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());
Browser browser = new Browser(shell, SWT.NONE);
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());
}
String url = createURL(interactiveAlert);
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();
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();
}
in above code closeBrowser boolean is used to close the browser. i set it true from another thread.
I am not writing to anywhere in file system. All i am doing is calling above code in a separate thread in which i am calling browser.setUrl(...).I am showing the customer details from web server. URL is calling a jsp page.
if i open that page in IE 6.0 stand alone repeatedly then it has no problem. only when i call that page on swt repeatedly it starts asking me to open save or cancel the page.
It loads the jsp page first and then saves in temporary internet files and from there it asks me to open save and cancel option. I do understand why first time page loads in my swt browser perfectly and from second time it starts asking to save or open.
One more thing i want to add that above mentioned problem does not happen if i try to open google or yahoo websites. It happens when i try to open any intranet site like my URL or even tomcat's localhost:8080.
[Updated on: Fri, 26 March 2010 12:09] Report message to a moderator
|
|
|
|
|
|
Re: SWT Browser problem [message #524357 is a reply to message #524035] |
Wed, 31 March 2010 15:37 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
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 19:48 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04647 seconds