BrowserWindowOpener should solely open in a specific Case

Hello Community,

I want to open a new Browser tab, whose external URL is returned by a method called in the buttonClick()-Method.

The Problem is twofold:

  • the finalURL which should be opened, is returned by a method, which is first called in the buttonClick()-Method, and
  • it should open, only in case of this finalURL starts with “http”. This is to ensure that the finalURL-String is in the right format and doesn`t contain an Error Message instead (which could be).

Here is the code:

        // ClickListener for the Button, starts the IOD, browses
		// the resolved URL in default Browser and shows it in Input-TextField
		resolveButton.addClickListener(new ClickListener() {

			private static final long serialVersionUID = 4169796098241261821L;

			@Override
			public void buttonClick(ClickEvent event) {
				input = (String) inputField.getValue();
				input.trim();

				// before iod.start() is called, check if the dbc is not closed.
				// If it is closed, build it up again. If this fails, stop the
				// Method and show errorLbl.
				try {
					if (dbc.isClosed()) {
						dbc.buildConnection();
					}
				} catch (ClassNotFoundException e1) {
					System.out.println("Treiber nicht gefunden!");
					e1.printStackTrace();
				} catch (SQLException e1) {
					System.out.println("DB-Connect nicht möglich!");
					errorLbl.setValue("DB-Connect nicht möglich!");
					// e.printStackTrace();
					return;
				}

				iod.start(input);
				String finalURL = iod.getOutput();

				bwo.setUriFragment(finalURL);
				errorLbl.setValue(" ");
				
				// if the finalURL doesn`t start with "http" the
				// iod.getOutput()- Method delivers an Error, which is then
				// shown in the Error-Label
				if (finalURL.startsWith("http")) {

					inputField.setValue(finalURL);
					
					// try {
					// // desktop.browse(uri);
					// Runtime.getRuntime().exec(
					// "rundll32 url.dll,FileProtocolHandler "
					// + finalURL);
					//
					// } catch (IOException e) {
					// e.printStackTrace();
					// }
					// getPage().open(finalURL, "_blank");
					// JavaScript.getCurrent().execute("window.open('" +
					// finalURL + "', '_blank')");
					
					bwo.extend(resolveButton);

				} else {
					errorLbl.setValue(finalURL);

					mail.setResource(new ExternalResource(
							"mailto:schneider@wiso.uni-koeln.de?subject=LinkResolverError&body=Link%20Resolver%20Input%20'"
									+ input + "'%20does not work."));
				}
				dbc.closeConnection();
			}
		});
		// Do the same tasks, which the ClickListener does, by clicking ENTER
		resolveButton.setClickShortcut(KeyCode.ENTER); 

As you can see, I´ve tried some ways to open this new tab only in such a “valid” case (lines: 42 ff).

Once the BrowserWindowOpener is extended to the resolveButton it opens a new tab, regardless to what happens in the buttonClick()-Methods. Is it possible to solve this problem? Maybe there is a way to “disable” the BWO after it has been extended? I didn`t find such things in the API.

So, I want to call the method which returns my finalURL (lines: 29,30) and immediately open it in a new tab if its correct (lines: 38 ff), or do other things in case if its not (lines: 57 ff), by clicking ONE button.

Hope there are some though guys who can help me.

Thanks in advance,
Sven

PS: I use Vaadin 7 and Eclipse. Using getPage().open(finalURL, "_blank"); works, but is interrupted by the Browser because of this “Pop-up-Protector”. This is a link to my Prototype-Project:
LINK

Is there no one who can help me to solve this problem? I would be very appreciated.