com.ultimatetech.cim.dialogs.UsernamePasswordDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.ultimatetech.cim.dialogs.UsernamePasswordDialog.java

Source

/*******************************************************************************
 * Copyright (c) 2006 Ultimate Technology, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Bojan Vukojevic - initial API and implementation
 *******************************************************************************/
package com.ultimatetech.cim.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * @author Bojan Vukojevic
 *
 */
public class UsernamePasswordDialog extends Dialog {

    Text usernameValue = null;
    Text passValue = null;
    String user = null;
    String pass = null;

    public UsernamePasswordDialog(Shell parentShell) {
        super(parentShell);

    }

    protected Control createDialogArea(Composite parent) {
        Composite composite = (Composite) super.createDialogArea(parent);
        createUsernameAndPasswordFields(composite);
        return composite;
    }

    protected void createUsernameAndPasswordFields(Composite parent) {
        Composite composite = new Composite(parent, SWT.NONE);

        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        layout.makeColumnsEqualWidth = false;
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        composite.setLayout(layout);
        GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER);
        data.minimumWidth = 300;
        composite.setLayoutData(data);
        composite.setFont(parent.getFont());

        GridData gridData = new GridData();
        gridData.grabExcessHorizontalSpace = true;
        gridData.minimumWidth = 150;
        Label title = new Label(composite, SWT.NONE);
        title.setText("Enter username and password to connect to CIMOM");
        GridData gd = new GridData();
        gd.horizontalAlignment = SWT.LEFT;
        gd.horizontalSpan = 2;
        title.setLayoutData(gd);

        Label usernameLabel = new Label(composite, SWT.NONE);
        usernameLabel.setText("Username:");
        usernameValue = new Text(composite, SWT.SINGLE | SWT.BORDER);

        usernameValue.setLayoutData(gridData);
        Label passLabel = new Label(composite, SWT.NONE);
        passLabel.setText("Password:");
        passValue = new Text(composite, SWT.SINGLE | SWT.BORDER);
        passValue.setEchoChar('*');
        passValue.setLayoutData(gridData);
    }

    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("Username and Password");
    }

    protected void okPressed() {
        user = usernameValue.getText();
        pass = passValue.getText();
        super.okPressed();
    }

    public String getEnteredUsername() {
        return user;
    }

    public String getEnteredPassword() {
        return pass;
    }

}