}
@Override
public void execute() {
try {
final Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKey,consumerSecret);
if(!context.getSettings().containsKey(TWITTER_TOKEN) || force) {
//u.p("no auth info already");
final RequestToken requestToken = twitter.getOAuthRequestToken();
final String url = requestToken.getAuthorizationURL();
final Textbox pin = new Textbox("");
pin.setPrefWidth(50);
pin.setWidth(50);
final Stage stage = Stage.createStage();
stage.setContent(
new GridBox()
.createColumn(50,GridBox.Align.Right)
.createColumn(50,GridBox.Align.Fill)
.addControl(new Label(getString("twitterAuthDialog.text1")))
.addControl(new Label(getString("twitterAuthDialog.text2")))
.nextRow()
.addControl(new Spacer())
.addControl(new Button("Goto Twitter.com").onClicked(new Callback<ActionEvent>() {
public void call(ActionEvent event) {
OSUtil.openBrowser(url);
}
}))
.nextRow()
.addControl(new Label("PIN"))
.addControl(pin)
.nextRow()
.addControl(new Button(getString("dialog.cancel")).onClicked(new Callback<ActionEvent>(){
public void call(ActionEvent event) {
stage.hide();
}
}))
.addControl(new Button(getString("twitterAuthDialog.authenticate")).onClicked(new Callback<ActionEvent>(){
public void call(ActionEvent event) {
stage.hide();
try {
String pinText = pin.getText();
//u.p("using pin text " + pinText);
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken,pinText);
context.getSettings().setProperty(TWITTER_TOKEN,accessToken.getToken());
context.getSettings().setProperty(TWITTER_TOKEN_SECRET,accessToken.getTokenSecret());
} catch (TwitterException e) {
e.printStackTrace();
StandardDialog.showError("Twitter authentication failed.\nPlease try again.");