Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Close shell from within browser widget
Close shell from within browser widget [message #811533] Fri, 02 March 2012 13:27 Go to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 309
Registered: August 2011
Senior Member
Hi,

In my RAP application I have a shell that only has one browser widget (full screen) as its content. Although the user has the possiblity to close this shell with the [x] button at the upper right corner, I like to automatically close the window after the work is done or offer the user a close button in the browser.

I cannot find a way to do this, so is this possible and if yes how?

Regards Bertin
Re: Close shell from within browser widget [message #811668 is a reply to message #811533] Fri, 02 March 2012 17:05 Go to previous messageGo to next message
Stephan Leicht Vogt is currently offline Stephan Leicht VogtFriend
Messages: 102
Registered: February 2010
Location: Baden Switzerland
Senior Member

Hi Bertin

Sure you can close a shell automatically and also with a close button.
Here the code snippet for a simple button:

Button close = new Button(shell, SWT.CENTER | SWT.PUSH);
close.setText("Close");
close.addSelectionListener(new SelectionAdapter() {
private static final long serialVersionUID = 1L;

@Override
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});

With this snippet I'm sure you're also able to write your work-method which closes the shell automatically.

But as soon as Eclipse 3.8 is live you'll be able to start your Eclipse Scout App as RAP-Application out of the box ;)

Greetings Stephan
Re: Close shell from within browser widget [message #811694 is a reply to message #811533] Fri, 02 March 2012 17:47 Go to previous messageGo to next message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 387
Registered: July 2009
Senior Member
Hi.

If i understand your scenario correctly, what you want might be possible
using the BrowserFunction class. That allows you to call Java (RAP
application) from JavaScript (browser widget).

Greetings,
Tim
Re: Close shell from within browser widget [message #813001 is a reply to message #811694] Sun, 04 March 2012 17:45 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 309
Registered: August 2011
Senior Member
I tried using the browser function but I always get an error when closing the shell that created the browser and browserfunction.

public class OddOneOut extends Shell {
	private Browser b;
	private OddOneOutOefening oefening;

	public OddOneOut(final Shell parent, final int style, OddOneOutOefening o) {
		super(parent, style);
		setLayout(new FillLayout());
		setMaximized(true);
		this.oefening = o;

		b = new Browser(this, SWT.None);
		String url = "./resource/oddoneout.html";

		new CloseWindow(b, "closeWindow");
		
		b.setUrl(url);
	}

	class CloseWindow extends BrowserFunction {
		CloseWindow(Browser browser, String name) {
			super(browser, name);
		}

		public Object function(Object[] arguments) {
			try{
				System.out.println("Close Window just called from the browser");
				OddOneOut.this.close();
			}
			catch(Exception ex){
				System.out.println("CloseWindow");
			}
			return arguments;
		}
	}


So when I remove the line "OddOneOut.this.close();" everything works fine, but with this line enabled I get the error:

org.eclipse.swt.SWTError: Unknown error
	at org.eclipse.swt.SWT.error(SWT.java:3567)
	at org.eclipse.swt.SWT.error(SWT.java:3458)
	at org.eclipse.swt.SWT.error(SWT.java:3429)
	at org.eclipse.swt.browser.BrowserFunction.getName(BrowserFunction.java:185)
	at org.eclipse.swt.internal.browser.browserkit.BrowserLCA$2.run(BrowserLCA.java:282)
	at org.eclipse.rwt.lifecycle.ProcessActionRunner.executeNext(ProcessActionRunner.java:57)
	at org.eclipse.swt.widgets.Display.runPendingMessages(Display.java:1132)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1124)
	at nl.rid.gramma.Application.createUI(Application.java:23)
	at org.eclipse.rwt.internal.lifecycle.EntryPointManager.createUI(EntryPointManager.java:73)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:211)
	at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:88)
	at java.lang.Thread.run(Thread.java:662)
	at org.eclipse.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)


I don't think it is strange getting an error because the window is closed by the browser function. Maybe there is some other trick to make it work?

Regards Bertin


Re: Close shell from within browser widget [message #813497 is a reply to message #813001] Mon, 05 March 2012 10:38 Go to previous message
Tim Buschtoens is currently offline Tim BuschtoensFriend
Messages: 387
Registered: July 2009
Senior Member
Seems the BrowserFunction is disposed while its still running. (Because
the shell is disposed.) It might work if you use Display#asyncExec to
close the shell, but I'm not sure. If it doesnt work, try if it works in
SWT (with and without asyncExec). If it does work in SWT, you can open a
bug in the RAP bugzilla.


Am 04.03.2012 18:45, schrieb Bertin Kiekebosch:
> I tried using the browser function but I always get an error when
> closing the shell that created the browser and browserfunction.
>
>
> public class OddOneOut extends Shell {
> private Browser b;
> private OddOneOutOefening oefening;
>
> public OddOneOut(final Shell parent, final int style, OddOneOutOefening
> o) {
> super(parent, style);
> setLayout(new FillLayout());
> setMaximized(true);
> this.oefening = o;
>
> b = new Browser(this, SWT.None);
> String url = "./resource/oddoneout.html";
>
> new CloseWindow(b, "closeWindow");
>
> b.setUrl(url);
> }
>
> class CloseWindow extends BrowserFunction {
> CloseWindow(Browser browser, String name) {
> super(browser, name);
> }
>
> public Object function(Object[] arguments) {
> try{
> System.out.println("Close Window just called from the browser");
> OddOneOut.this.close();
> }
> catch(Exception ex){
> System.out.println("CloseWindow");
> }
> return arguments;
> }
> }
>
>
> So when I remove the line "OddOneOut.this.close();" everything works
> fine, but with this line enabled I get the error:
>
>
> org.eclipse.swt.SWTError: Unknown error
> at org.eclipse.swt.SWT.error(SWT.java:3567)
> at org.eclipse.swt.SWT.error(SWT.java:3458)
> at org.eclipse.swt.SWT.error(SWT.java:3429)
> at
> org.eclipse.swt.browser.BrowserFunction.getName(BrowserFunction.java:185)
> at
> org.eclipse.swt.internal.browser.browserkit.BrowserLCA$2.run(BrowserLCA.java:282)
>
> at
> org.eclipse.rwt.lifecycle.ProcessActionRunner.executeNext(ProcessActionRunner.java:57)
>
> at org.eclipse.swt.widgets.Display.runPendingMessages(Display.java:1132)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1124)
> at nl.rid.gramma.Application.createUI(Application.java:23)
> at
> org.eclipse.rwt.internal.lifecycle.EntryPointManager.createUI(EntryPointManager.java:73)
>
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:211)
>
> at
> org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:88)
>
> at java.lang.Thread.run(Thread.java:662)
> at org.eclipse.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)
>
>
> I don't think it is strange getting an error because the window is
> closed by the browser function. Maybe there is some other trick to make
> it work?
>
> Regards Bertin
>
>
>
Previous Topic:Business design in an RCP application
Next Topic:GEF with RAP
Goto Forum:
  


Current Time: Fri Nov 28 20:52:43 GMT 2014

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

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