Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cafa7f00651a65072ce1a8b358bae102b0f33811 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/********************************************************************************
 * Copyright (c) 2008-2010 Motorola 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
 *
 * Initial Contributor:
 * Otavio Ferranti (Motorola)
 *
 * Contributors:
 * Daniel Pastore (Eldorado) - [289870] Moving and renaming Tml to Sequoyah
 ********************************************************************************/

package org.eclipse.sequoyah.device.linuxtools.ui;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.sequoyah.device.linuxtools.tools.ITool;
import org.eclipse.swt.SWT;
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.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * @author Otavio Ferranti
 */
public class DialogLogin extends TitleAreaDialog {

	final private String WINDOW_TITLE = Messages.LoginDialog_Window_Title;
	final private String WINDOW_MESSAGE = Messages.LoginDialog_Window_Message;
	final private String WINDOW_MESSAGE_LOGIN_INVALID =
			Messages.LoginDialog_Msg_Login_Invalid;
	final private String LABEL_USER = Messages.LoginDialog_Label_User;
	final private String LABEL_PASSWORD = Messages.LoginDialog_Label_Password;

	private Text userText;
	private Text passwordText;

	private ITool tool;
	private boolean login_retry = false;

	/**
	 * The constructor.
	 * @param parentShell
	 * @param tool
	 */
	public DialogLogin(Shell parentShell, ITool tool) {
		this(parentShell, tool, false);
	}
	
	/**
	 * The other constructor.
	 * @param parentShell
	 * @param tool
	 * @param login_retry
	 */
	public DialogLogin(Shell parentShell, ITool tool, boolean login_retry) {
		super(parentShell);
		this.login_retry = login_retry;
		this.tool = tool;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createDialogArea(Composite parent) {
		setTitle(WINDOW_TITLE);
		
		if (login_retry) {
			setErrorMessage(WINDOW_MESSAGE_LOGIN_INVALID);
		} else {
			setMessage(WINDOW_MESSAGE);
		}
		
		Composite dialogArea = new Composite(parent, SWT.NONE);
		GridLayout gridLayout = new GridLayout(2, false);
		
		gridLayout.marginLeft = 7;
		gridLayout.marginRight = 7;
		
		dialogArea.setLayout(gridLayout);
		dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH));
		dialogArea.setFont(parent.getFont());
		
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
	
		Label hostLabel = new Label(dialogArea, SWT.NULL);
		hostLabel.setText(LABEL_USER);
		userText = new Text(dialogArea, SWT.BORDER);
		userText.setLayoutData(gridData);
		
		Label portLabel = new Label(dialogArea, SWT.NULL);
		portLabel.setText(LABEL_PASSWORD);
		passwordText = new Text(dialogArea, SWT.BORDER | SWT.PASSWORD);
		passwordText.setLayoutData(gridData);
		
		return dialogArea;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize()
	 */
	protected Point getInitialSize() {
		return super.getInitialSize();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
	protected void okPressed() {
		tool.login(userText.getText(), passwordText.getText());
		super.okPressed();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#cancelPressed()
	 */
	protected void cancelPressed() {
		tool.disconnect();
		super.cancelPressed();
	}
}

Back to the top