package at.kugel.tool.buildtray.action;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import at.kugel.tool.buildtray.action.desktop.DesktopOperation;
import at.kugel.tool.buildtray.config.Config;
import at.kugel.tool.buildtray.status.SetStatusAble;
/**
* Open the browser. Invoke Desktip BROWSE.
*
* @author <a href="http://www.code-cop.org/">Peter Kofler</a>
*/
abstract class OpenBrowserCommand extends ActionCommand {
public OpenBrowserCommand(Config config, SetStatusAble statusDisplay) {
super(config, statusDisplay);
}
@Override
protected void workTemplate() throws IOException {
openDesktopBrowser();
}
private void openDesktopBrowser() throws IOException {
new DesktopOperation(Desktop.Action.BROWSE) {
@Override
public void runWithDesktop(Desktop deskTop) throws IOException {
deskTop.browse(createDisplayUri());
}
}.run();
}
private URI createDisplayUri() throws IOException {
try {
return determineDisplayUrl().toURI();
} catch (URISyntaxException e) {
throw new IOException(e);
}
}
protected abstract URL determineDisplayUrl();
}