summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/gui')
-rw-r--r--dozentenmodul/src/main/java/gui/GuiManager.java31
-rw-r--r--dozentenmodul/src/main/java/gui/core/LoginComposite.java148
-rw-r--r--dozentenmodul/src/main/java/gui/core/LoginGUI.java173
3 files changed, 248 insertions, 104 deletions
diff --git a/dozentenmodul/src/main/java/gui/GuiManager.java b/dozentenmodul/src/main/java/gui/GuiManager.java
index ae97d90b..8e28409c 100644
--- a/dozentenmodul/src/main/java/gui/GuiManager.java
+++ b/dozentenmodul/src/main/java/gui/GuiManager.java
@@ -1,5 +1,6 @@
package gui;
+import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -10,10 +11,14 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
public abstract class GuiManager {
+
+ private final static Logger LOGGER = Logger.getLogger(GuiManager.class);
+
static Shell mainShell;
static Composite contentComposite;
static Display display;
@@ -48,6 +53,29 @@ public abstract class GuiManager {
}
}
+ // TODO use showMessageBox
+ public static void showMessage(final String message) {
+ MessageBox msgBox = new MessageBox(mainShell, SWT.ICON_INFORMATION);
+ msgBox.setText("Information");
+ msgBox.setMessage(message);
+ int ret = msgBox.open();
+ }
+// /**
+// * Generic helper to show a message box to the user, and optionally log the message to the log file.
+// *
+// * @param message Message to display. Can be multi line.
+// * @param messageType Type of message (warning, information)
+// * @param logger Logger instance to log to. Can be null.
+// * @param exception Exception related to this message. Can be null.
+// */
+// public static void showMessageBox(String message, MessageType messageType, Logger logger,
+// Throwable exception) {
+// if (logger != null)
+// logger.log(messageType.logPriority, message, exception);
+// if (exception != null)
+// message += "\n\n" + exception.getClass().getSimpleName();
+// JOptionPane.showMessageDialog(mainWindow, message, messageType.title, messageType.optionPaneId);
+// }
public static Display getDisplay(){
return display;
@@ -80,7 +108,7 @@ public abstract class GuiManager {
// Set layout for the mainshell, items added to the shell should get a gridData
mainShell.setLayout(new GridLayout(1, true));
- addContent(new gui.core.LoginComposite(mainShell));
+ addContent(new gui.core.LoginGUI(mainShell));
// center the window on the primary monitor
@@ -96,6 +124,7 @@ public abstract class GuiManager {
mainShell.pack();
mainShell.open();
+ LOGGER.info("GUI initialised.");
while (!mainShell.isDisposed()) {
if (!display.readAndDispatch())
diff --git a/dozentenmodul/src/main/java/gui/core/LoginComposite.java b/dozentenmodul/src/main/java/gui/core/LoginComposite.java
index 5a387e8f..060b1c61 100644
--- a/dozentenmodul/src/main/java/gui/core/LoginComposite.java
+++ b/dozentenmodul/src/main/java/gui/core/LoginComposite.java
@@ -2,9 +2,8 @@ package gui.core;
import gui.GuiManager;
+import org.apache.log4j.Logger;
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;
@@ -19,21 +18,37 @@ import org.eclipse.swt.widgets.Text;
public class LoginComposite extends Composite {
+ private final static Logger LOGGER = Logger.getLogger(LoginComposite.class);
+
+ protected enum LOGIN_TYPE {
+ BWIDM, BWLP, SAT
+ }
+
+ protected LOGIN_TYPE loginType = LOGIN_TYPE.BWIDM;
+
private Image titleImage;
- // textfield of the username
- private Text usernameText;
+ // textfields for the username/password
+ protected Text usernameText;
+ protected Text passwordText;
- // textfield of the password
- private Text passwordText;
+ // ComboBox/label for the IDP
+ protected final Combo idpCombo;
+ protected final Label idpText;
- String title = "Dozmod - Login";
- String authenticationGroupLabel = "Authentifizierungsart";
+ // buttons
+ protected final Button loginButton;
+ protected final Button saveUsernameCheck;
+ protected final Button[] authButtons;
+ private static final String title = "Dozmod - Login";
+ private static final String authenticationGroupLabel = "Authentifizierungsart";
/**
* Create a new login composite
- * @param mainShell The shell it should be added to
+ *
+ * @param mainShell
+ * The shell it should be added to
*/
public LoginComposite(final Shell mainShell) {
super(mainShell, SWT.NONE);
@@ -67,8 +82,7 @@ public class LoginComposite extends Composite {
authGroup.setLayoutData(gridData);
// add the authentication method selection buttons
- Button[] authButtons = new Button[3];
-
+ authButtons = new Button[3];
authButtons[0] = new Button(authGroup, SWT.RADIO);
authButtons[0].setSelection(true);
authButtons[0].setText("Authentifizierung über bwIDM");
@@ -81,11 +95,10 @@ public class LoginComposite extends Composite {
authButtons[1].setLayoutData(gridData);
authButtons[2] = new Button(authGroup, SWT.RADIO);
- authButtons[2].setText("Direkte Verbindung zum Satteliten");
+ authButtons[2].setText("Direkte Verbindung zum Satelliten");
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");
@@ -96,111 +109,40 @@ public class LoginComposite extends Composite {
gridData.heightHint = 150;
loginGroup.setLayoutData(gridData);
-
- final Label idpText = new Label(loginGroup, SWT.NONE);
+ 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);
-
+ idpCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
+ idpCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true,
+ false));
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));
+ 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);
+ passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
+ true, false));
+ // login button
+ loginButton = new Button(loginGroup, SWT.PUSH);
loginButton.setText("Login");
- Button saveUsernameCheck = new Button(loginGroup, SWT.CHECK);
+ 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(){
+ private void loadImage() {
try {
- titleImage = new Image(GuiManager.getDisplay(), getClass().getResourceAsStream("/img/Logo_bwLehrpool.png"));
+ // TODO use the ResourceLoader class to load the logo
+ // this way, we can be sure to get an image
+ // (since the ResourceLoader always returns an image,
+ // even if it cannot load the specified one).
+ titleImage = new Image(GuiManager.getDisplay(), getClass()
+ .getResourceAsStream("/img/Logo_bwLehrpool.png"));
ImageData imgData = titleImage.getImageData();
- imgData = imgData.scaledTo(imgData.width/5, imgData.height/5);
+ imgData = imgData.scaledTo(imgData.width / 5, imgData.height / 5);
titleImage = new Image(GuiManager.getDisplay(), imgData);
} catch (Exception e) {
System.out.println("Cannot load image");
diff --git a/dozentenmodul/src/main/java/gui/core/LoginGUI.java b/dozentenmodul/src/main/java/gui/core/LoginGUI.java
new file mode 100644
index 00000000..5c329d5d
--- /dev/null
+++ b/dozentenmodul/src/main/java/gui/core/LoginGUI.java
@@ -0,0 +1,173 @@
+package gui.core;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.openslx.bwlp.thrift.iface.Organization;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.thrifthelper.ThriftManager;
+
+import auth.BWIDMAuthenticator;
+import auth.BaseAuthenticator.AuthenticatorCallback;
+import edu.kit.scc.dei.ecplean.ECPAuthenticationException;
+import gui.GuiManager;
+
+public class LoginGUI extends LoginComposite {
+
+ private final static Logger LOGGER = Logger.getLogger(LoginGUI.class);
+
+ private final String NO_USERNAME = "Kein Benutzername angegeben!";
+ private final String NO_PASSWORD = "Kein Passwort angegeben!";
+
+ private String username = null;
+ private String password = null;
+
+ /**
+ * @param mainShell
+ */
+ public LoginGUI(final Shell mainShell) {
+ // call the constructor of the superclass
+ super(mainShell);
+
+ // entries in the combo
+ List<Organization> orgs = null;
+ try {
+ orgs = ThriftManager.getMasterClient().getOrganizations();
+ } catch (TException e) {
+ LOGGER.error(
+ "Could not fetch the IdP list from the masterserver! See trace:", e);
+ // in this case, we can just call the default fillIdPCombo method of the
+ // superclass
+ idpCombo.add("No entries");
+ }
+ // all fine, lets sort it
+ Collections.sort(orgs, new Comparator<Organization>() {
+ public int compare(Organization o1, Organization o2) {
+ return o1.getDisplayName().compareTo(o2.getDisplayName());
+ }
+ });
+ for (Organization o : orgs) {
+ idpCombo.add(o.displayName);
+ idpCombo.setData(o.displayName, o);
+ }
+ idpCombo.select(0);
+
+ // actions of the login button
+ loginButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ doLogin(loginType);
+ } catch (ECPAuthenticationException ae) {
+ LOGGER.error("Authentication error, see trace: ", ae);
+ GuiManager.showMessage(ae.getMessage());
+ }
+ }
+ });
+
+ // 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);
+ loginType = LOGIN_TYPE.BWIDM;
+ }
+ });
+
+ // selecting the "Test-Zugang mit festem Benutzer" radio button
+ authButtons[1].addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ idpText.setVisible(false);
+ idpCombo.setVisible(false);
+ loginType = LOGIN_TYPE.BWLP;
+ }
+ });
+
+ 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);
+ loginType = LOGIN_TYPE.SAT;
+ }
+ });
+ }
+
+ /**
+ * Actually do the login using the username/password in the field using the
+ * authentication mechanism corresponding to the selected authButton
+ * @throws ECPAuthenticationException
+ */
+ private void doLogin(LOGIN_TYPE loginType) throws ECPAuthenticationException {
+ // here we only check for the fields
+ username = usernameText.getText();
+ password = passwordText.getText();
+ // login clicked, lets first read the fields
+ if (username == null) {
+ // tell the GUIManager to show an error to the user
+ // TODO either popup or in the bottom status bar
+ GuiManager.showMessage(NO_USERNAME);
+ return;
+ }
+ if (password == null) {
+ // tell the GUIManager to show an error to the user
+ // TODO either popup or in the bottom status bar
+ GuiManager.showMessage(NO_PASSWORD);
+ return;
+ }
+ // get the index of the selected item in the combobox
+ int selectionIndex = idpCombo.getSelectionIndex();
+ if (selectionIndex == -1) {
+ LOGGER
+ .error("No IdP is selected in the combobox. There should be a default value!");
+ return;
+ }
+ Organization selectedOrg =
+ (Organization) idpCombo.getData(idpCombo.getItem(selectionIndex));
+
+ // now switch over the login types.
+ switch (loginType) {
+ case BWIDM:
+ BWIDMAuthenticator bwidmAuth = new BWIDMAuthenticator(
+ selectedOrg.getEcpUrl());
+ bwidmAuth.login(username, password, new AuthenticatorCallback() {
+ @Override
+ public void postLogin(UserInfo user) {
+ LOGGER.info(user.firstName + " " + user.lastName);
+ if (user != null)
+ GuiManager.addContent(new DisclaimerComposite(getShell()));
+ }
+ });
+ break;
+ case BWLP:
+ LOGGER.info("bwlp");
+ break;
+ case SAT:
+ LOGGER.info("sat");
+ break;
+ default:
+ LOGGER.error("derp");
+ break;
+ }
+ return;
+
+ }
+}