summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-10 19:57:55 +0200
committerSimon Rettberg2015-07-10 19:57:55 +0200
commitd3b015ba0ef85459f3eba313d1d8bcc3765a5348 (patch)
treedfd0c0374bd53bd5770f076283655f039aaba946
parentMerge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff)
downloadtutor-module-d3b015ba0ef85459f3eba313d1d8bcc3765a5348.tar.gz
tutor-module-d3b015ba0ef85459f3eba313d1d8bcc3765a5348.tar.xz
tutor-module-d3b015ba0ef85459f3eba313d1d8bcc3765a5348.zip
[client] Got rid of ini4j, store config as java properties file, simplified config handling
-rw-r--r--dozentenmodul/pom.xml6
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/Config.java330
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java10
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java14
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java72
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtualizerNoticeWindow.java4
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java53
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java17
8 files changed, 265 insertions, 241 deletions
diff --git a/dozentenmodul/pom.xml b/dozentenmodul/pom.xml
index 4f634868..ef130c4b 100644
--- a/dozentenmodul/pom.xml
+++ b/dozentenmodul/pom.xml
@@ -287,12 +287,6 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.ini4j</groupId>
- <artifactId>ini4j</artifactId>
- <version>0.5.2</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java
index 80a50685..c15c6bb1 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java
@@ -1,10 +1,17 @@
package org.openslx.dozmod;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
import org.apache.log4j.Logger;
-import org.ini4j.Wini;
+import org.openslx.dozmod.util.FormatHelper;
+import org.openslx.util.QuickTimer;
+import org.openslx.util.QuickTimer.Task;
/**
* Represents the configuration of the client
@@ -19,12 +26,20 @@ public class Config {
*/
private final static Logger LOGGER = Logger.getLogger(Config.class);
+ public static interface ErrorCallback {
+ void writeError(Throwable t);
+ }
+
/**
- * The main configuration object is of type Wini
- * It contains the content of the config.ini as
- * determined in the init() function.
+ * Out property holder with all the setting keys
*/
- private static Wini ini = null;
+ private static final Properties prop = new Properties();
+
+ private static ErrorCallback errorCb = null;
+
+ private static File configFile = null;
+
+ private static boolean writePending = false;
/**
* Initializes the class by determining the path
@@ -41,7 +56,6 @@ public class Config {
// Variables only needed locally
String configPath = null;
- File configFile = null;
// Determine OS
String osName = System.getProperty("os.name").toLowerCase();
@@ -52,26 +66,23 @@ public class Config {
// C:\Users\<user>\AppData\Roaming
String appDataPath = System.getenv("APPDATA");
if (!appDataPath.isEmpty()) {
- configPath = appDataPath + "\\bwSuite\\config.ini";
+ configPath = appDataPath;
} else {
// APPDATA was empty, let's guess
LOGGER.warn("APPDATA is empty.");
- configPath = System.getProperty("user.home") + "\\AppData\\Roaming\\bwSuite\\config.ini";
+ configPath = System.getProperty("user.home") + "\\AppData\\Roaming";
}
} else if (osName.contains("linux")) {
- configPath = System.getProperty("user.home") + "/.config/bwSuite/config.ini";
- } else {
+ configPath = System.getProperty("user.home") + "/.config";
+ }
+ if (configPath == null || configPath.isEmpty()) {
// Not Windows nor Linux, try fallback to relative path
// TODO MacOS Support?
- configPath = "." + File.separatorChar + "bwSuite" + File.separatorChar + "config.ini";
+ configPath = ".";
}
// Check if we got a path
- if (!(configPath.isEmpty() || configPath == null)) {
- configFile = new File(configPath);
- } else {
- throw new IOException("Could not determine the path to the config file.");
- }
+ configFile = new File(configPath + File.separatorChar + "bwSuite" + File.separatorChar + "config.properties");
// Check if the directory exists.
if (!configFile.getParentFile().exists()) {
@@ -82,33 +93,74 @@ public class Config {
}
}
- // Check if the file already exists
if (!configFile.exists()) {
- // Does not, create it
- configFile.createNewFile();
-
- // Check if file is writeable
- if (configFile.canWrite()) {
- ini = new Wini(configFile);
- LOGGER.info("Creating '" + configFile + "'...");
- // write default configuration options and values
- ini.put("main", "disclaimer_agreement", false);
- ini.put("main", "vmware_license_agreement", false);
- ini.put("main", "auth_method", "");
- ini.put("main", "username", "");
- ini.put("main", "download_path", "");
- ini.put("main", "upload_path", "");
- ini.put("main", "identity_provider", "");
- ini.store();
+ forceSaveInternal();
+ }
+
+ // Make sure all settings are saved when we exit
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ Config.forceSave();
+ }
+ });
- } else {
- throw new IOException("Can not write to '" + configFile + "'. Do you have permissions?");
+ // Load configuration from java properties file
+ InputStream in = new FileInputStream(configFile);
+ try {
+ prop.load(in);
+ } finally {
+ in.close();
+ }
+ }
+
+ private static void forceSaveInternal() throws FileNotFoundException, IOException {
+ synchronized (prop) {
+ prop.store(new FileOutputStream(configFile), "bwLehrpool Dozentenmodul Client Config");
+ }
+ }
+
+ public static boolean forceSave() {
+ synchronized (prop) {
+ if (!writePending)
+ return true;
+ writePending = false;
+ if (configFile == null)
+ return false;
+ try {
+ forceSaveInternal();
+ return true;
+ } catch (Exception e) {
+ if (errorCb != null)
+ errorCb.writeError(e);
}
- } else {
- ini = new Wini(configFile);
- LOGGER.info("Loaded '" + configFile + "'.");
+ return false;
}
- } // end constructor.
+ }
+
+ /**
+ * Called internally by all set[TYPE]() methods. This triggers
+ * a save-task in one second, if one isn't pending yet. This is so
+ * we don't write the file many times, possibly concurrently, if lots
+ * of settings are changed.
+ */
+ private static void queueSave() {
+ synchronized (prop) {
+ if (writePending)
+ return;
+ writePending = true;
+ QuickTimer.scheduleOnce(new Task() {
+ @Override
+ public void fire() {
+ forceSave();
+ }
+ }, 1000);
+ }
+ }
+
+ public static void setErrorCallback(ErrorCallback cb) {
+ errorCb = cb;
+ }
/**
* Query the path of the configuration file
@@ -116,218 +168,206 @@ public class Config {
* @return path to the configuration file
*/
public static String getPath() {
- if (ini.getFile().getParentFile().isDirectory())
- return ini.getFile().getParentFile().toString();
- else
- return null;
+ return configFile.getParent();
}
+ /*
+ * Getters and setters for the various config options
+ */
+
/**
* Query the value of 'BillOfRights' from the configuration file.
*
* @return true if the user already accepted bill of rights, false
* otherwise.
*/
- public static boolean getDisclaimerAgreement() {
- return getBoolean("main", "disclaimer_agreement", false);
+ public static int getDisclaimerAgreement() {
+ return getInteger("disclaimer.accepted_version", 0);
}
/**
- * Query the value of 'vmware' from the configuration file.
+ * Sets the value of 'BillOfRights' in the configuration file to 'value'
*
- * @return true if the user already accepted vmware license, false
- * otherwise.
+ * @return true if it succeeded, false otherwise
*/
- public static boolean getVmwareLicenseAgreement() {
- return getBoolean("main", "vmware_license_agreement", false);
+ public static void setDisclaimerAgreement(int value) {
+ setInteger("disclaimer.accepted_version", value);
+ }
+
+ public static boolean getVirtualizerRead() {
+ return getBoolean("notice.virtualizer", false);
+ }
+
+ public static void setVirtualizerRead(boolean selection) {
+ setBoolean("notice.virtualizer", selection);
}
/**
- * Query the value of 'Benutzername' from the configuration file.
+ * Get the remembered user, if set.
*
- * @return username if saved, an empty string otherwise.
+ * @return user name if saved, an empty string otherwise.
*/
public static String getUsername() {
- return getString("main", "username", "");
+ return getString("login.name", "");
}
/**
- * Query the value of 'Letzter Downloadpfad' from the configuration file.
+ * Sets the name of the remembered user
*
- * @return last download path if saved, the path to the user's home
- * otherwise.
+ * @return true if it succeeded, false otherwise
*/
- public static String getDownloadPath() {
- return getString("main", "download_path", System.getProperty("user.home"));
+ public static void setUsername(String value) {
+ setString("login.name", value);
}
/**
- * Query the value of 'Letzter Uploadpfad' from the configuration file.
+ * Query the value of 'Letzter Downloadpfad' from the configuration file.
*
- * @return last upload path if saved, the path to the user's home otherwise.
+ * @return last download path if saved, the path to the user's home
+ * otherwise.
*/
- public static String getUploadPath() {
- return getString("main", "upload_path", System.getProperty("user.home"));
+ public static String getDownloadPath() {
+ return getString("download.path", System.getProperty("user.home"));
}
/**
- * Query the IdP of the configuration file
+ * Sets the value of 'Letzter Downloadpfad' in the configuration file to
+ * 'value'
*
- * @return stored IdP
+ * @return true if it succeeded, false otherwise
*/
- public static String getIdentityProvider() {
- return getString("main", "identity_provider", "");
+ public static void setDownloadPath(String value) {
+ setString("download.path", value);
}
/**
- * Query the authentication method of the configuration file
+ * Query the value of 'Letzter Uploadpfad' from the configuration file.
*
- * @return stored IdP
+ * @return last upload path if saved, the path to the user's home otherwise.
*/
- public static String getAuthenticationMethod() {
- return getString("main", "auth_method", "bwlp");
+ public static String getUploadPath() {
+ return getString("upload.path", System.getProperty("user.home"));
}
/**
- * Sets the value of 'BillOfRights' in the configuration file to 'value'
+ * Sets the value of "Letzter Uploadpfad" in the configuration file to
+ * 'value'
*
* @return true if it succeeded, false otherwise
*/
- public static boolean setDisclaimerAgreement(boolean value) {
- return setBoolean("main", "disclaimer_agreement", value);
+ public static void setUploadPath(String value) {
+ setString("upload.path", value);
}
/**
- * Sets the value of 'vmware' in the configuration file to 'value'
+ * Query the IdP of the configuration file
*
- * @return true if it succeeded, false otherwise
+ * @return stored IdP
*/
- public static boolean setVmwareLicenseAgreement(boolean value) {
- return setBoolean("main", "vmware_license_agreement", value);
+ public static String getIdentityProvider() {
+ return getString("login.idp", "");
}
/**
- * Sets the value of 'Benutzername' in the configuration file to 'value'
+ * Sets the value of "IdP" in the configuration file to 'value'
*
* @return true if it succeeded, false otherwise
*/
- public static boolean setUsername(String value) {
- return setString("main", "username", value);
+ public static void setIdentityProvider(String value) {
+ setString("login.idp", value);
}
/**
- * Sets the value of 'Letzter Downloadpfad' in the configuration file to
- * 'value'
+ * Query the authentication method of the configuration file
*
- * @return true if it succeeded, false otherwise
+ * @return stored IdP
*/
- public static boolean setDownloadPath(String value) {
- return setString("main", "download_path", value);
+ public static String getAuthenticationMethod() {
+ return getString("login.method", "ECP");
}
/**
- * Sets the value of "Letzter Uploadpfad" in the configuration file to
- * 'value'
+ * Sets the value of the selected authentication method in the configuration
+ * file to 'value'
*
* @return true if it succeeded, false otherwise
*/
- public static boolean setUploadPath(String value) {
- return setString("main", "upload_path", value);
+ public static void setAuthenticationMethod(String value) {
+ setString("login.method", value);
}
- /**
- * Sets the value of "IdP" in the configuration file to 'value'
- *
- * @return true if it succeeded, false otherwise
+ /*
+ * Generic helpers for different data types
*/
- public static boolean setIdentityProvider(String value) {
- return setString("main", "identity_provider", value);
- }
/**
- * Sets the value of the selected authentication method in the configuration
- * file to 'value'
+ * Gets the boolean from the given key.
+ * If nothing is found, return the given default value
*
- * @return true if it succeeded, false otherwise
+ * @param key key to query in that section
+ * @param defaultValue default value to be returned, if none is found.
+ * @return
*/
- public static boolean setAuthenticationMethod(String value) {
- return setString("main", "auth_method", value);
+ private static boolean getBoolean(String key, boolean defaultValue) {
+ return Boolean.parseBoolean(prop.getProperty(key, Boolean.toString(defaultValue)));
}
/**
- * Save the changes to the ini file to actual file on the disk.
+ * Sets the given key to value.
*
- * @return true if succeeded, false otherwise
+ * @param key key to set
+ * @param value value to assign to key
*/
- public static boolean store() {
- try {
- ini.store();
- return true;
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
+ private static void setBoolean(String key, boolean value) {
+ prop.setProperty(key, Boolean.toString(value));
+ queueSave();
}
/**
- * Gets the boolean from the given 'key' in the given 'section'.
- * If nothing is found, return the given 'defaultValue'
+ * Gets the integer from the given key.
+ * If nothing is found, return the given default value
*
- * @param section section to search the key in
* @param key key to query in that section
* @param defaultValue default value to be returned, if none is found.
* @return
*/
- private static boolean getBoolean(String section, String key, Boolean defaultValue) {
- if (ini.containsKey(section) && ini.get(section).containsKey(key)) {
- return ini.get(section, key, Boolean.class);
- } else {
- return defaultValue;
- }
+ private static int getInteger(String key, int defaultValue) {
+ return FormatHelper.parseInt(prop.getProperty(key), defaultValue);
}
/**
- * Gets the string from the given 'key' in the given 'section'
- * If nothing is found, return the given 'defaultValue'
+ * Sets the given key to value.
*
- * @param section section of the configuration file to search for
- * @param key key to lookup in the section
- * @param defaultValue default value to return if none is found in the file
- * @return value of 'key' in 'section' if it exists, 'defaultValue'
- * otherwise
+ * @param key key to set
+ * @param value value to assign to key
*/
- private static String getString(String section, String key, String defaultValue) {
- if (ini.containsKey(section) && ini.get(section).containsKey(key)) {
- return ini.get(section, key);
- } else {
- return defaultValue;
- }
+ private static void setInteger(String key, int value) {
+ prop.setProperty(key, Integer.toString(value));
+ queueSave();
}
/**
- * Sets the given 'key' in the given 'section' to 'value'.
- * Restricted to boolean.
+ * Gets the string from the given key.
+ * If nothing is found, return the given default value
*
- * @param section section of the configuration file
- * @param key key to set
- * @param value value to assign to key
- * @return true if it succeeded, false otherwise
+ * @param key key to lookup in the section
+ * @param defaultValue default value to return if none is found in the file
+ * @return
*/
- private static boolean setBoolean(String section, String key, boolean value) {
- return ini.put(section, key, value) != null;
+ private static String getString(String key, String defaultValue) {
+ return prop.getProperty(key, defaultValue);
}
/**
* Sets the given 'key' in the given 'section' to 'value'.
* Restricted to string.
*
- * @param section section of the configuration file
* @param key key to set
* @param value value to assign to key
- * @return true if it succeeded, false otherwise
*/
- private static boolean setString(String section, String key, String value) {
- return ini.put(section, key, value) != null;
+ private static void setString(String key, String value) {
+ prop.setProperty(key, value);
+ queueSave();
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
index b3517403..1bdb3220 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
@@ -15,6 +15,7 @@ import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
+import org.openslx.dozmod.Config;
import org.openslx.dozmod.gui.helper.Gui;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.window.DisclaimerWindow;
@@ -89,7 +90,6 @@ public abstract class MainWindow {
// Set up thrift error message displaying
ThriftManager.setErrorCallback(new ErrorCallback() {
-
@Override
public boolean thriftError(int failCount, String method, Throwable t) {
// Ask user if we should retry
@@ -97,6 +97,14 @@ public abstract class MainWindow {
}
});
+ // Same for config errors
+ Config.setErrorCallback(new Config.ErrorCallback() {
+ @Override
+ public void writeError(Throwable t) {
+ showMessageBox("Konnte Programmeinstellungen nicht speichern", MessageType.WARNING, LOGGER, t);
+ }
+ });
+
// Global key listener
Gui.display.addFilter(SWT.KeyDown, new Listener() {
@Override
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java
index 0f02bedb..def223bd 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java
@@ -8,6 +8,11 @@ import org.openslx.dozmod.Config;
import org.openslx.dozmod.gui.window.layout.DisclaimerWindowLayout;
public class DisclaimerWindow extends DisclaimerWindowLayout {
+
+ /**
+ * Use a version number for the disclaimer. Whenever we add/change something, this will be increased
+ */
+ private static final int DISCLAIMER_VERSION = 1;
private final static Logger LOGGER = Logger.getLogger(DisclaimerWindow.class);
@@ -28,13 +33,14 @@ public class DisclaimerWindow extends DisclaimerWindowLayout {
@Override
public void widgetSelected(SelectionEvent e) {
// save the agreement to config
- if (!Config.setDisclaimerAgreement(true))
- LOGGER.error("Could not set the agreement to the disclaimer in '" + Config.getPath()
- + "'!");
- Config.store();
+ Config.setDisclaimerAgreement(DISCLAIMER_VERSION);
me.getShell().dispose();
}
});
}
+
+ public static boolean shouldBeShown() {
+ return Config.getDisclaimerAgreement() < DISCLAIMER_VERSION;
+ }
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
index 2f1271c9..66e1f030 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
@@ -83,26 +83,18 @@ public class LoginWindow extends LoginWindowLayout {
// check if we had saved an authentication method
String savedAuthMethod = Config.getAuthenticationMethod();
- if (savedAuthMethod != null && !savedAuthMethod.isEmpty()) {
- LOGIN_TYPE savedLoginType = LOGIN_TYPE.getEnum(savedAuthMethod);
+ LOGIN_TYPE savedLoginType;
+ try {
+ savedLoginType = LOGIN_TYPE.valueOf(savedAuthMethod);
+ } catch (Exception e) {
// if no valid LOGIN_TYPE was saved, just enable the BWIDM button
- if (savedLoginType == null) {
- authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true);
- loginType = LOGIN_TYPE.BWIDM;
- idpText.setVisible(true);
- idpCombo.setVisible(true);
- } else {
- authButtons[savedLoginType.getId()].setSelection(true);
- loginType = savedLoginType;
- // enable the IDP combo only if we actually have items in it
- idpText.setVisible(savedLoginType == LOGIN_TYPE.BWIDM);
- idpCombo.setVisible(savedLoginType == LOGIN_TYPE.BWIDM);
- }
- } else {
- // default value for LOGIN_TYPE is BWIDM
- authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true);
- loginType = LOGIN_TYPE.BWIDM;
+ savedLoginType = LOGIN_TYPE.ECP;
}
+ authButtons[savedLoginType.id].setSelection(true);
+ loginType = savedLoginType;
+ // enable the IDP combo only if we actually have items in it
+ idpText.setVisible(savedLoginType == LOGIN_TYPE.ECP);
+ idpCombo.setVisible(savedLoginType == LOGIN_TYPE.ECP);
// finally check if we had a saved username
String savedUsername = Config.getUsername();
@@ -136,7 +128,7 @@ public class LoginWindow extends LoginWindowLayout {
public void widgetSelected(SelectionEvent e) {
idpText.setVisible(true);
idpCombo.setVisible(true);
- loginType = LOGIN_TYPE.BWIDM;
+ loginType = LOGIN_TYPE.ECP;
}
});
@@ -146,7 +138,7 @@ public class LoginWindow extends LoginWindowLayout {
public void widgetSelected(SelectionEvent e) {
idpText.setVisible(false);
idpCombo.setVisible(false);
- loginType = LOGIN_TYPE.BWLP;
+ loginType = LOGIN_TYPE.TEST_ACCOUNT;
}
});
@@ -157,7 +149,7 @@ public class LoginWindow extends LoginWindowLayout {
public void widgetSelected(SelectionEvent e) {
idpText.setVisible(false);
idpCombo.setVisible(false);
- loginType = LOGIN_TYPE.SAT;
+ loginType = LOGIN_TYPE.DIRECT_CONNECT;
}
});
@@ -234,26 +226,19 @@ public class LoginWindow extends LoginWindowLayout {
if (saveUsernameCheck.isEnabled()) {
// save username
String username = usernameText.getText();
- if (username != null && !username.isEmpty()) {
- // all good, save it
- if (!Config.setUsername(username))
- LOGGER.error("Could not save username '" + username + "' to '" + Config.getPath() + "'.");
+ if (!username.isEmpty()) {
+ Config.setUsername(username);
}
+ } else {
+ Config.setUsername("");
}
// always save the authentication method and potentially the identity provider
- if (!Config.setAuthenticationMethod(loginType.getTag()))
- LOGGER.error("Could not save authentication method '" + loginType.getTag() + "' to '"
- + Config.getPath() + "'.");
- // check if we are doing bwIDM authentication
- if (loginType == LOGIN_TYPE.BWIDM) {
- // save the selected identity provider
- Organization selectedOrg = getSelectedOrganization();
- if (!Config.setIdentityProvider(selectedOrg.organizationId))
- LOGGER.error("Could not save the identity provider '" + selectedOrg.organizationId + "'!");
+ Config.setAuthenticationMethod(loginType.toString());
+ // save the selected identity provider
+ Organization selectedOrg = getSelectedOrganization();
+ if (selectedOrg != null) {
+ Config.setIdentityProvider(selectedOrg.organizationId);
}
- // finalize by actually storing the config file
- if (!Config.store())
- LOGGER.error("Could not save '" + Config.getPath() + "'!");
}
/**
@@ -329,13 +314,13 @@ public class LoginWindow extends LoginWindowLayout {
// now switch over the login types.
Authenticator authenticator;
switch (loginType) {
- case BWIDM:
+ case ECP:
authenticator = new EcpAuthenticator(selectedOrg.getEcpUrl());
break;
- case BWLP:
+ case TEST_ACCOUNT:
authenticator = new TestAccountAuthenticator();
break;
- case SAT:
+ case DIRECT_CONNECT:
MainWindow.showMessageBox(this.getShell(), "Not yet implemented", MessageType.ERROR, null, null);
return;
default:
@@ -358,16 +343,15 @@ public class LoginWindow extends LoginWindowLayout {
* Functions called by doLogin is the login process succeeded.
*/
private void postSuccessfulLogin() {
- LOGGER.info(loginType.getTag() + " succeeded.");
+ LOGGER.info(loginType.toString() + " succeeded.");
// TODO HACK HACK
ThriftManager.setSatelliteAddress("132.230.8.113");
// now read the config to see if the user already agreed to the disclaimer
- if (!Config.getDisclaimerAgreement())
+ if (DisclaimerWindow.shouldBeShown())
MainWindow.openPopup(DisclaimerWindow.class, true);
- if (!Config.getVmwareLicenseAgreement())
- MainWindow.openPopup(VirtualizerNoticeWindow.class, true);
+ // TODO: Add notice about VMware etc...
getShell().dispose();
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtualizerNoticeWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtualizerNoticeWindow.java
index 4043bb31..b0e443a7 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtualizerNoticeWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtualizerNoticeWindow.java
@@ -20,9 +20,7 @@ public class VirtualizerNoticeWindow extends VirtualizerNoticeWindowLayout {
continueButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (!Config.setVmwareLicenseAgreement(readCheck.getSelection()))
- LOGGER.error("Could not set the agreement to the vmware license in '" + Config.getPath());
- Config.store();
+ Config.setVirtualizerRead(readCheck.getSelection());
me.getShell().dispose();
}
});
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
index 683780c9..7d637b37 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
@@ -16,39 +16,16 @@ import org.openslx.dozmod.gui.helper.Gui;
public abstract class LoginWindowLayout extends Composite {
- // TODO add ids to use for the authButtons group!
+ // TODO This has nothing to to with the layout
protected static enum LOGIN_TYPE {
- BWIDM(0, "bwidm"),
- BWLP(1, "bwlp"),
- SAT(2, "sat");
+ ECP(0),
+ TEST_ACCOUNT(1),
+ DIRECT_CONNECT(2);
- private final int id;
- private final String tag;
+ public final int id;
- private LOGIN_TYPE(final int id, final String tag) {
+ private LOGIN_TYPE(final int id) {
this.id = id;
- this.tag = tag;
- }
-
- public int getId() {
- return this.id;
- }
-
- public String getTag() {
- return this.tag;
- }
-
- public static LOGIN_TYPE getEnum(String tag) {
- switch (tag) {
- case "bwidm":
- return LOGIN_TYPE.BWIDM;
- case "bwlp":
- return LOGIN_TYPE.BWLP;
- case "sat":
- return LOGIN_TYPE.SAT;
- default:
- return null;
- }
}
}
@@ -112,20 +89,20 @@ public abstract class LoginWindowLayout extends Composite {
// add the authentication method selection buttons
authButtons = new Button[3];
- authButtons[LOGIN_TYPE.BWIDM.id] = new Button(authGroup, SWT.RADIO);
- authButtons[LOGIN_TYPE.BWIDM.id].setText("Authentifizierung über bwIDM");
+ authButtons[LOGIN_TYPE.ECP.id] = new Button(authGroup, SWT.RADIO);
+ authButtons[LOGIN_TYPE.ECP.id].setText("Authentifizierung über bwIDM");
gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
- authButtons[LOGIN_TYPE.BWIDM.id].setLayoutData(gridData);
+ authButtons[LOGIN_TYPE.ECP.id].setLayoutData(gridData);
- authButtons[LOGIN_TYPE.BWLP.id] = new Button(authGroup, SWT.RADIO);
- authButtons[LOGIN_TYPE.BWLP.id].setText("Test-Zugang mit festem Benutzernamen");
+ authButtons[LOGIN_TYPE.TEST_ACCOUNT.id] = new Button(authGroup, SWT.RADIO);
+ authButtons[LOGIN_TYPE.TEST_ACCOUNT.id].setText("Test-Zugang mit festem Benutzernamen");
gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
- authButtons[LOGIN_TYPE.BWLP.id].setLayoutData(gridData);
+ authButtons[LOGIN_TYPE.TEST_ACCOUNT.id].setLayoutData(gridData);
- authButtons[LOGIN_TYPE.SAT.id] = new Button(authGroup, SWT.RADIO);
- authButtons[LOGIN_TYPE.SAT.id].setText("Direkte Verbindung zum Satelliten");
+ authButtons[LOGIN_TYPE.DIRECT_CONNECT.id] = new Button(authGroup, SWT.RADIO);
+ authButtons[LOGIN_TYPE.DIRECT_CONNECT.id].setText("Direkte Verbindung zum Satelliten");
gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
- authButtons[LOGIN_TYPE.SAT.id].setLayoutData(gridData);
+ authButtons[LOGIN_TYPE.DIRECT_CONNECT.id].setLayoutData(gridData);
// group for the login mask
final Group loginGroup = new Group(this, SWT.NONE);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
index d69b7746..5b36a18c 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
@@ -32,4 +32,21 @@ public class FormatHelper {
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
+ /**
+ * Parse the given String as a base10 integer.
+ * If the string does not represent a valid integer, return the given
+ * default value.
+ *
+ * @param value string representation to parse to an int
+ * @param defaultValue fallback value if given string can't be parsed
+ * @return
+ */
+ public static int parseInt(String value, int defaultValue) {
+ try {
+ return Integer.parseInt(value);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
}