com.hangum.tadpole.manager.core.dialogs.users.OTPCodeDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.hangum.tadpole.manager.core.dialogs.users.OTPCodeDialog.java

Source

/*******************************************************************************
 * Copyright (c) 2014 hangum.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     hangum - initial API and implementation
 ******************************************************************************/
package com.hangum.tadpole.manager.core.dialogs.users;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.hangum.tadpole.commons.google.analytics.AnalyticCaller;

/**
 * Google OPT URL
 * 
 * @author hangum
 *
 */
public class OTPCodeDialog extends Dialog {
    private String url = "";
    private Browser browser;
    private Text text;

    /**
     * Create the dialog.
     * @param parentShell
     */
    public OTPCodeDialog(Shell parentShell, String url) {
        super(parentShell);
        setShellStyle(SWT.MAX | SWT.RESIZE | SWT.TITLE);

        this.url = url;
    }

    @Override
    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("Google OPT");
    }

    /**
     * Create contents of the dialog.
     * @param parent
     */
    int i = 0;

    @Override
    protected Control createDialogArea(Composite parent) {
        final Composite container = (Composite) super.createDialogArea(parent);
        GridLayout gridLayout = (GridLayout) container.getLayout();
        gridLayout.verticalSpacing = 5;
        gridLayout.horizontalSpacing = 5;
        gridLayout.marginHeight = 5;
        gridLayout.marginWidth = 5;

        text = new Text(container, SWT.BORDER);
        text.addKeyListener(new KeyAdapter() {
            @Override
            public void keyReleased(KeyEvent e) {
                if (e.keyCode == SWT.Selection) {
                    browser.setUrl(text.getText());
                }
            }
        });
        text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text.setText(url);

        browser = new Browser(container, SWT.BORDER);
        browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        browser.setUrl(url);

        browser.addProgressListener(new ProgressListener() {
            @Override
            public void completed(ProgressEvent event) {
                browser.layout();
                container.layout();
            }

            @Override
            public void changed(ProgressEvent event) {
            }
        });

        // google analytic
        AnalyticCaller.track(this.getClass().getName());

        return container;
    }

    /**
     * Create contents of the button bar.
     * @param parent
     */
    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        createButton(parent, IDialogConstants.OK_ID, "OK", false);
    }

    /**
     * Return the initial size of the dialog.
     */
    @Override
    protected Point getInitialSize() {
        return new Point(450, 400);
    }

}