Example usage for com.google.gwt.user.client.ui Button Button

List of usage examples for com.google.gwt.user.client.ui Button Button

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Button Button.

Prototype

protected Button(com.google.gwt.dom.client.Element element) 

Source Link

Document

This constructor may be used by subclasses to explicitly use an existing element.

Usage

From source file:com.google.api.gwt.oauth2.samples.multi.client.OAuth2SampleEntryPoint.java

License:Apache License

private void addWindowsLiveAuth() {
    // Since the auth flow requires opening a popup window, it must be started
    // as a direct result of a user action, such as clicking a button or link.
    // Otherwise, a browser's popup blocker may block the popup.
    Button button = new Button("Authenticate with Windows Live");
    button.addClickHandler(new ClickHandler() {
        @Override//from w  w w  . j  ava  2 s . com
        public void onClick(ClickEvent event) {
            final AuthRequest req = new AuthRequest(WINDOWS_LIVE_AUTH_URL, WINDOWS_LIVE_CLIENT_ID)
                    .withScopes(WINDOWS_LIVE_BASIC_SCOPE);
            AUTH.login(req, new Callback<String, Throwable>() {
                @Override
                public void onSuccess(String token) {
                    Window.alert("Got an OAuth token:\n" + token + "\n" + "Token expires in "
                            + AUTH.expiresIn(req) + " ms\n");
                }

                @Override
                public void onFailure(Throwable caught) {
                    Window.alert("Error:\n" + caught.getMessage());
                }
            });
        }
    });
    RootPanel.get().add(button);
}

From source file:com.google.api.gwt.oauth2.samples.multi.client.OAuth2SampleEntryPoint.java

License:Apache License

private void addGoogleAuthNative() {
    Button button = new Button("Authenticate with Google (using native JS)");
    button.addClickHandler(new ClickHandler() {
        @Override// w  w w  .  j a v  a 2s  . c  o  m
        public native void onClick(ClickEvent event) /*-{
                                                     $wnd.oauth2.login({
                                                     "authUrl" : "https://accounts.google.com/o/oauth2/auth",
                                                     "clientId" : "452237527106.apps.googleusercontent.com",
                                                     "scopes" : [
                                                     "https://www.googleapis.com/auth/plus.me"
                                                     ]
                                                     }, function(token) {
                                                     $wnd.alert("Got an OAuth token:\n" + token + "\n"
                                                     + "Token expires in " + $wnd.oauth2.expiresIn(req) + " ms\n");
                                                     }, function(error) {
                                                     $wnd.alert("Error:\n" + error);
                                                     });
                                                     }-*/;
    });
    RootPanel.get().add(button);
}

From source file:com.google.api.gwt.oauth2.samples.multi.client.OAuth2SampleEntryPoint.java

License:Apache License

private void addClearTokens() {
    Button button = new Button("Clear stored tokens");
    button.addClickHandler(new ClickHandler() {
        @Override/*from w  ww  . j a  va2  s . com*/
        public void onClick(ClickEvent event) {
            Auth.get().clearAllTokens();
            Window.alert("All tokens cleared");
        }
    });
    RootPanel.get().add(button);
}

From source file:com.google.api.gwt.samples.calendar.client.CalendarEntryPoint.java

License:Apache License

@Override
public void onModuleLoad() {
    calendar.initialize(new SimpleEventBus(), new GoogleApiRequestTransport(APPLICATION_NAME, API_KEY));

    final Button b = new Button("Authenticate to insert, update and delete an event");
    b.addClickHandler(new ClickHandler() {
        @Override/*  w w  w  . j av a  2  s .  c  o  m*/
        public void onClick(ClickEvent e) {
            login();
            b.setVisible(false);
        }
    });
    RootPanel.get().add(b);
}

From source file:com.google.api.gwt.samples.plus.client.PlusEntryPoint.java

License:Apache License

@Override
public void onModuleLoad() {
    plus.initialize(new SimpleEventBus(), new GoogleApiRequestTransport(APPLICATION_NAME, API_KEY));

    final Button b = new Button("Authenticate to get public activities");
    b.addClickHandler(new ClickHandler() {
        @Override// w w  w.  j av  a  2s .  co  m
        public void onClick(ClickEvent e) {
            login();
            b.setVisible(false);
        }
    });
    RootPanel.get().add(b);
}

From source file:com.google.api.gwt.samples.urlshortener.client.UrlshortenerEntryPoint.java

License:Apache License

/** Demonstrates authentication using OAuth 2.0. */
private void login() {
    final Button button = new Button("Log in to get started");
    button.addClickHandler(new ClickHandler() {
        @Override/*from  w  w  w  .  ja v  a2 s. c  o m*/
        public void onClick(ClickEvent event) {
            new ClientOAuth2Login(CLIENT_ID).withScopes(UrlshortenerAuthScope.URLSHORTENER)
                    .login(new Receiver<String>() {
                        @Override
                        public void onSuccess(String accessToken) {
                            initialize(accessToken);
                        }
                    });
            button.setVisible(false);
        }
    });
    RootPanel.get().add(button);
}

From source file:com.google.appengine.demos.gwtdlx.client.GwtDlx.java

License:Apache License

public void onModuleLoad() {
    Button button = new Button("solve");
    Button clearButton = new Button("clear");

    button.addClickHandler(buildClickHandler());
    clearButton.addClickHandler(buildClearHandler());

    RootPanel.get("button").add(button);
    RootPanel.get("button").add(clearButton);

    noSolution.setVisible(false);//  w  w w  .  jav  a  2  s .  co  m
    noSolution.setStyleName("fail");

    RootPanel.get().add(noSolution);
    RootPanel.get().add(ajax);
    ajax.setStyleName("ajax");
    ajax.setVisible(false);
    ajax.setHorizontalAlignment(Label.ALIGN_CENTER);
    noSolution.setHorizontalAlignment(Label.ALIGN_CENTER);
}

From source file:com.google.appinventor.client.editor.blocks.BlocklyPanel.java

License:Open Source License

/**
 * Create a Dialog Box. We call this from Javascript (blockly) to
 * display a dialog box.  We do this here because we can get calls
 * from the blocklyframe when it is not visible.  Because we are in
 * the parent window, we can display dialogs that will be visible
 * even when the blocklyframe is not visible.
 *
 * @param title      Title for the Dialog Box
 * @param mess       The message to display
 * @param buttonName The string to display in the "OK" button.
 * @param size       0 or 1. 0 makes a smaller box 1 makes a larger box.
 * @param callback   an opague JavaScriptObject that contains the
 *                   callback function provided by the Javascript code.
 * @return The created dialog box.//www.  j a va 2  s.c  o  m
 */

public static DialogBox createDialog(String title, String mess, final String buttonName,
        final String cancelButtonName, int size, final JavaScriptObject callback) {
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(title);
    if (size == 0) {
        dialogBox.setHeight("150px");
    } else {
        dialogBox.setHeight("400px");
    }
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(mess);
    HorizontalPanel holder = new HorizontalPanel();
    if (buttonName != null) { // If buttonName and cancelButtonName are null
        Button ok = new Button(buttonName); // We won't have any buttons and other
        ok.addClickHandler(new ClickHandler() { // code is needed to dismiss us
            @Override
            public void onClick(ClickEvent event) {
                doCallBack(callback, buttonName);
            }
        });
        holder.add(ok);
    }
    if (cancelButtonName != null) {
        Button cancel = new Button(cancelButtonName);
        cancel.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                doCallBack(callback, cancelButtonName);
            }
        });
        holder.add(cancel);
    }
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    terminateDrag(); // cancel a drag before showing the modal dialog
    dialogBox.show();
    return dialogBox;
}

From source file:com.google.appinventor.client.editor.youngandroid.BlocklyPanel.java

License:Open Source License

/**
 * Create a Dialog Box. We call this from Javascript (blockly) to
 * display a dialog box.  We do this here because we can get calls
 * from the blocklyframe when it is not visible.  Because we are in
 * the parent window, we can display dialogs that will be visible
 * even when the blocklyframe is not visible.
 *
 * @param title      Title for the Dialog Box
 * @param mess       The message to display
 * @param buttonName The string to display in the "OK" button.
 * @param size       0 or 1. 0 makes a smaller box 1 makes a larger box.
 * @param callback   an opague JavaScriptObject that contains the
 *                   callback function provided by the Javascript code.
 * @return The created dialog box./*from   w  w  w. j a va 2  s .c o  m*/
 */

public static DialogBox createDialog(String title, String mess, final String buttonName,
        final String cancelButtonName, int size, final JavaScriptObject callback) {
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setStylePrimaryName("ode-DialogBox");
    dialogBox.setText(title);
    if (size == 0) {
        dialogBox.setHeight("150px");
    } else {
        dialogBox.setHeight("400px");
    }
    dialogBox.setWidth("400px");
    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(true);
    dialogBox.center();
    VerticalPanel DialogBoxContents = new VerticalPanel();
    HTML message = new HTML(mess);
    message.setStyleName("DialogBox-message");
    HorizontalPanel holder = new HorizontalPanel();
    if (buttonName != null) { // If buttonName and cancelButtonName are null
        Button ok = new Button(buttonName); // We won't have any buttons and other
        ok.addClickListener(new ClickListener() { // code is needed to dismiss us
            public void onClick(Widget sender) {
                doCallBack(callback, buttonName);
            }
        });
        holder.add(ok);
    }
    if (cancelButtonName != null) {
        Button cancel = new Button(cancelButtonName);
        cancel.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                doCallBack(callback, cancelButtonName);
            }
        });
        holder.add(cancel);
    }
    DialogBoxContents.add(message);
    DialogBoxContents.add(holder);
    dialogBox.setWidget(DialogBoxContents);
    dialogBox.show();
    return dialogBox;
}

From source file:com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidAssetSelectorPropertyEditor.java

License:Open Source License

/**
 * Creates a new property editor for selecting a Young Android asset.
 *
 * @param editor the editor that this property editor belongs to
 *///  w w w  . j  ava  2  s  .  c  o m
public YoungAndroidAssetSelectorPropertyEditor(final YaFormEditor editor) {
    Project project = Ode.getInstance().getProjectManager().getProject(editor.getProjectId());
    assetsFolder = ((YoungAndroidProjectNode) project.getRootNode()).getAssetsFolder();
    project.addProjectChangeListener(this);

    VerticalPanel selectorPanel = new VerticalPanel();
    assetsList = new ListBox();
    assetsList.setVisibleItemCount(10);
    assetsList.setWidth("100%");
    selectorPanel.add(assetsList);

    choices = new ListWithNone(MESSAGES.noneCaption(), new ListWithNone.ListBoxWrapper() {
        @Override
        public void addItem(String item) {
            assetsList.addItem(item);
        }

        @Override
        public String getItem(int index) {
            return assetsList.getItemText(index);
        }

        @Override
        public void removeItem(int index) {
            assetsList.removeItem(index);
        }

        @Override
        public void setSelectedIndex(int index) {
            assetsList.setSelectedIndex(index);
        }
    });

    // Fill choices with the assets.
    if (assetsFolder != null) {
        for (ProjectNode node : assetsFolder.getChildren()) {
            choices.addItem(node.getName());
        }
    }

    Button addButton = new Button(MESSAGES.addButton());
    addButton.setWidth("100%");
    addButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            FileUploadedCallback callback = new FileUploadedCallback() {
                @Override
                public void onFileUploaded(FolderNode folderNode, FileNode fileNode) {
                    // At this point, the asset has been uploaded to the server, and
                    // has even been added to the assetsFolder. We are all set!
                    choices.selectValue(fileNode.getName());
                    closeAdditionalChoiceDialog(true);
                }
            };
            FileUploadWizard uploader = new FileUploadWizard(assetsFolder, callback);
            uploader.show();
        }
    });
    selectorPanel.add(addButton);
    selectorPanel.setWidth("100%");

    // At this point, the editor hasn't finished loading.
    // Use a DeferredCommand to finish the initialization after the editor has finished loading.
    DeferredCommand.addCommand(new Command() {
        @Override
        public void execute() {
            if (editor.isLoadComplete()) {
                finishInitialization();
            } else {
                // Editor still hasn't finished loading.
                DeferredCommand.addCommand(this);
            }
        }
    });

    initAdditionalChoicePanel(selectorPanel);
}