summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/core/LoginComposite.java
blob: 5a387e8f1faec1fead317cc101f7f880d6117e7e (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package gui.core;

import gui.GuiManager;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class LoginComposite extends Composite {

	private Image titleImage;

	// textfield of the username
	private Text usernameText;

	// textfield of the password
	private Text passwordText;

	String title = "Dozmod - Login";
	String authenticationGroupLabel = "Authentifizierungsart";


	/**
	 * Create a new login composite
	 * @param mainShell The shell it should be added to
	 */
	public LoginComposite(final Shell mainShell) {
		super(mainShell, SWT.NONE);

		// title for composite
		mainShell.setText(title);

		// left authentication selection and right loginmask
		GridLayout gridLayout = new GridLayout(2, true);
		this.setLayout(gridLayout);

		// load the needed Picture
		loadImage();

		Label titlePicture = new Label(this, SWT.NONE);
		titlePicture.setImage(titleImage);
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		gridData.horizontalSpan = 2;
		gridData.horizontalAlignment = SWT.CENTER;
		titlePicture.setLayoutData(gridData);

		// group for the authentication method.
		// groups have borders and a title
		Group authGroup = new Group(this, SWT.NONE);
		authGroup.setText(authenticationGroupLabel);
		gridLayout = new GridLayout();
		gridLayout.numColumns = 1;
		authGroup.setLayout(gridLayout);
		gridData = new GridData(GridData.FILL, GridData.FILL, false, false);
		gridData.heightHint = 150;
		authGroup.setLayoutData(gridData);

		// add the authentication method selection buttons
		Button[] authButtons = new Button[3];

		authButtons[0] = new Button(authGroup, SWT.RADIO);
		authButtons[0].setSelection(true);
		authButtons[0].setText("Authentifizierung über bwIDM");
		gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
		authButtons[0].setLayoutData(gridData);

		authButtons[1] = new Button(authGroup, SWT.RADIO);
		authButtons[1].setText("Test-Zugang mit festem Benutzernamen");
		gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
		authButtons[1].setLayoutData(gridData);

		authButtons[2] = new Button(authGroup, SWT.RADIO);
		authButtons[2].setText("Direkte Verbindung zum Satteliten");
		gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
		authButtons[2].setLayoutData(gridData);


		// group for the login mask
		final Group loginGroup = new Group(this, SWT.NONE);
		loginGroup.setText("Zugangsdaten");
		gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		loginGroup.setLayout(gridLayout);
		gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
		gridData.heightHint = 150;
		loginGroup.setLayoutData(gridData);


		final Label idpText = new Label(loginGroup, SWT.NONE);
		idpText.setText("IdP:");


		final Combo idpCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
		idpCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

		fillIdPCombo(idpCombo);


		new Label(loginGroup, SWT.NONE).setText("Benutzername:");
		usernameText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER);
		usernameText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));

		new Label(loginGroup, SWT.NONE).setText("Passwort:");
		passwordText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
		passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
		Button loginButton = new Button(loginGroup, SWT.PUSH);
		loginButton.setText("Login");
		Button saveUsernameCheck = new Button(loginGroup, SWT.CHECK);
		saveUsernameCheck.setText("Benutzername speichern");


		// actions of the login button
		loginButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				clickedLoginButton();
			}
		});

		// for save username checkbox.
		saveUsernameCheck.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				clickedSaveUsernameCheck();
			}
		});

		// selecting the "Authentifizierung über bwIDM" radio button
		authButtons[0].addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				idpText.setVisible(true);
				idpCombo.setVisible(true);
			}
		});

		// selecting the "Test-Zugang über bwIDM" radio button
		authButtons[1].addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				idpText.setVisible(false);
				idpCombo.setVisible(false);
			}
		});

		authButtons[2].setEnabled(false);
		// selecting the "Direkte Verbindung zum Satteliten" radio button
		authButtons[2].addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				idpText.setVisible(false);
				idpCombo.setVisible(false);
			}
		});
	}



	//
	// logical functions for GUI
	//

	/**
	 * function to execute when checking the saveUsername checkbox
	 */
	protected void clickedSaveUsernameCheck() {
		System.out.println("Checkboxtoggle");		
	}


	/**
	 * function to execute when clicking the login button
	 */
	protected void clickedLoginButton() {
		GuiManager.addContent(new DisclaimerComposite(getShell()));		
	}


	/**
	 * fill the idpCombo with idpCombo.add(String)
	 * @param idpCombo
	 */
	protected void fillIdPCombo(Combo idpCombo) {
		idpCombo.add("No Entries!");
	}


	private void loadImage(){
		try {
			titleImage = new Image(GuiManager.getDisplay(), getClass().getResourceAsStream("/img/Logo_bwLehrpool.png"));
			ImageData imgData = titleImage.getImageData();
			imgData = imgData.scaledTo(imgData.width/5, imgData.height/5);
			titleImage = new Image(GuiManager.getDisplay(), imgData);
		} catch (Exception e) {
			System.out.println("Cannot load image");
			System.out.println(e.getMessage());
		}
	}

}