summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/org')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/App.java115
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/Config.java333
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java87
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java55
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java33
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ServiceProviderResponse.java15
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethECP.java172
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java171
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java135
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java153
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java147
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java23
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java77
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java40
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java333
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtualizerNoticeWindow.java54
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/DisclaimerWindowLayout.java87
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java369
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java170
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainWindowLayout.java95
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java82
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java48
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java93
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadPageLayout.java87
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java7
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java11
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ACache.java (renamed from dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/ACache.java)2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageCache.java (renamed from dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/ImageCache.java)4
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java (renamed from dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/MetaDataCache.java)2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/OrganizationCache.java (renamed from dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationCache.java)2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java (renamed from dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/Session.java)5
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/CheckIntegrity.java121
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java35
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java236
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java82
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java84
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java95
37 files changed, 3652 insertions, 8 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java
new file mode 100644
index 00000000..c9fc369e
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java
@@ -0,0 +1,115 @@
+package org.openslx.dozmod;
+import java.io.File;
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.spi.LoggingEvent;
+import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.util.ProxyConfigurator;
+
+public class App {
+
+ // Logger
+ private final static Logger LOGGER = Logger.getLogger(App.class);
+
+ private static void setupLogger() {
+
+ // path to the log file
+ final String logFilePath = Config.getPath() + System.getProperty("file.separator") + "bwSuite.log";
+
+ // check if we had an old log file
+ final File logFile = new File(logFilePath);
+ if (logFile.exists() && !logFile.isDirectory()) {
+ // we have one, rename it to 'bwSuite.log.old'
+ LOGGER.info("renaming old log file");
+ try {
+ File oldFile = new File(logFilePath + ".old");
+ FileUtils.forceDelete(oldFile);
+ logFile.renameTo(oldFile);
+ FileUtils.forceDelete(logFile);
+ } catch (Exception e) {
+ LOGGER.error("Could not move '" + logFilePath + "' to '" + logFilePath + ".old'", e);
+ }
+ }
+
+ // add file appender to global logger
+ FileAppender fa = null;
+ try {
+ fa = new FileAppender(new PatternLayout("%d [%F:%M] %m%n"), logFilePath);
+ // All classes should log to file, configure global file appender.
+ } catch (IOException e) {
+ e.printStackTrace();
+ BasicConfigurator.configure();
+ return;
+ }
+
+ final FileAppender ffa = fa;
+ final Pattern re = Pattern.compile("authorization:(\\w|\\+|/|\\s)+", Pattern.CASE_INSENSITIVE
+ | Pattern.MULTILINE);
+
+ AppenderSkeleton ap = new AppenderSkeleton() {
+
+ @Override
+ public boolean requiresLayout() {
+ return ffa.requiresLayout();
+ }
+
+ @Override
+ public void close() {
+ ffa.close();
+ }
+
+ @Override
+ protected void append(LoggingEvent event) {
+ String s = event.getRenderedMessage();
+ if (s.contains("uthorization")) {
+ Matcher m = re.matcher(s);
+ if (!m.find()) {
+ LOGGER.warn("Could not match pattern!");
+ } else {
+ s = m.replaceAll("Authorization: ***********");
+ LOGGER.info("Patched log message");
+ }
+ }
+ ffa.append(new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(),
+ event.getTimeStamp(), event.getLevel(), s, event.getThreadName(),
+ event.getThrowableInformation(), event.getNDC(), event.getLocationInformation(),
+ event.getProperties()));
+ }
+ };
+
+ BasicConfigurator.configure(ap);
+ LOGGER.info("Starting logging to: " + logFilePath);
+ }
+
+ public static void main(final String[] args) {
+
+ // Pruefe und Erzeuge gegebenfalls Config
+ try {
+ Config.init();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ setupLogger();
+
+ // initialise the proxy settings
+ try {
+ ProxyConfigurator.init();
+ } catch (IOException e) {
+ LOGGER.error("IOException when trying to initialise the proxy, see trace: ", e);
+ }
+
+ // start the GUI
+ GuiManager.initGui();
+
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java
new file mode 100644
index 00000000..80a50685
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java
@@ -0,0 +1,333 @@
+package org.openslx.dozmod;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.ini4j.Wini;
+
+/**
+ * Represents the configuration of the client
+ *
+ * @author Jonathan Bauer
+ */
+
+public class Config {
+
+ /**
+ * Logger for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(Config.class);
+
+ /**
+ * The main configuration object is of type Wini
+ * It contains the content of the config.ini as
+ * determined in the init() function.
+ */
+ private static Wini ini = null;
+
+ /**
+ * Initializes the class by determining the path
+ * to the config.ini on the system and setting the
+ * private creating the ini member from that file.
+ *
+ * This function will make a distinction between
+ * Linux and Windows OS's, as the standard paths
+ * for configuration files obviously differ.
+ *
+ * @throws IOException
+ */
+ public static void init() throws IOException {
+
+ // Variables only needed locally
+ String configPath = null;
+ File configFile = null;
+
+ // Determine OS
+ String osName = System.getProperty("os.name").toLowerCase();
+ LOGGER.info("Machine's OS: " + osName);
+ if (osName.contains("windows")) {
+ // Windows machine. Use the environment variable 'APPDATA' which
+ // should point to a path similar to:
+ // C:\Users\<user>\AppData\Roaming
+ String appDataPath = System.getenv("APPDATA");
+ if (!appDataPath.isEmpty()) {
+ configPath = appDataPath + "\\bwSuite\\config.ini";
+ } else {
+ // APPDATA was empty, let's guess
+ LOGGER.warn("APPDATA is empty.");
+ configPath = System.getProperty("user.home") + "\\AppData\\Roaming\\bwSuite\\config.ini";
+ }
+ } else if (osName.contains("linux")) {
+ configPath = System.getProperty("user.home") + "/.config/bwSuite/config.ini";
+ } else {
+ // Not Windows nor Linux, try fallback to relative path
+ // TODO MacOS Support?
+ configPath = "." + File.separatorChar + "bwSuite" + File.separatorChar + "config.ini";
+ }
+
+ // 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.");
+ }
+
+ // Check if the directory exists.
+ if (!configFile.getParentFile().exists()) {
+ LOGGER.info("Folder " + configFile.getParentFile() + " does not exist, creating it.");
+ // Does not, create it
+ if (!configFile.getParentFile().mkdirs()) {
+ throw new IOException("Could not create '" + configFile.getParentFile() + "'.");
+ }
+ }
+
+ // 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();
+
+ } else {
+ throw new IOException("Can not write to '" + configFile + "'. Do you have permissions?");
+ }
+ } else {
+ ini = new Wini(configFile);
+ LOGGER.info("Loaded '" + configFile + "'.");
+ }
+ } // end constructor.
+
+ /**
+ * Query the path of the configuration file
+ *
+ * @return path to the configuration file
+ */
+ public static String getPath() {
+ if (ini.getFile().getParentFile().isDirectory())
+ return ini.getFile().getParentFile().toString();
+ else
+ return null;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Query the value of 'vmware' from the configuration file.
+ *
+ * @return true if the user already accepted vmware license, false
+ * otherwise.
+ */
+ public static boolean getVmwareLicenseAgreement() {
+ return getBoolean("main", "vmware_license_agreement", false);
+ }
+
+ /**
+ * Query the value of 'Benutzername' from the configuration file.
+ *
+ * @return username if saved, an empty string otherwise.
+ */
+ public static String getUsername() {
+ return getString("main", "username", "");
+ }
+
+ /**
+ * Query the value of 'Letzter Downloadpfad' from the configuration file.
+ *
+ * @return last download path if saved, the path to the user's home
+ * otherwise.
+ */
+ public static String getDownloadPath() {
+ return getString("main", "download_path", System.getProperty("user.home"));
+ }
+
+ /**
+ * Query the value of 'Letzter Uploadpfad' from the configuration file.
+ *
+ * @return last upload path if saved, the path to the user's home otherwise.
+ */
+ public static String getUploadPath() {
+ return getString("main", "upload_path", System.getProperty("user.home"));
+ }
+
+ /**
+ * Query the IdP of the configuration file
+ *
+ * @return stored IdP
+ */
+ public static String getIdentityProvider() {
+ return getString("main", "identity_provider", "");
+ }
+
+ /**
+ * Query the authentication method of the configuration file
+ *
+ * @return stored IdP
+ */
+ public static String getAuthenticationMethod() {
+ return getString("main", "auth_method", "bwlp");
+ }
+
+ /**
+ * Sets the value of 'BillOfRights' 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);
+ }
+
+ /**
+ * Sets the value of 'vmware' in the configuration file to 'value'
+ *
+ * @return true if it succeeded, false otherwise
+ */
+ public static boolean setVmwareLicenseAgreement(boolean value) {
+ return setBoolean("main", "vmware_license_agreement", value);
+ }
+
+ /**
+ * Sets the value of 'Benutzername' in the configuration file to 'value'
+ *
+ * @return true if it succeeded, false otherwise
+ */
+ public static boolean setUsername(String value) {
+ return setString("main", "username", value);
+ }
+
+ /**
+ * Sets the value of 'Letzter Downloadpfad' in the configuration file to
+ * 'value'
+ *
+ * @return true if it succeeded, false otherwise
+ */
+ public static boolean setDownloadPath(String value) {
+ return setString("main", "download_path", value);
+ }
+
+ /**
+ * Sets the value of "Letzter Uploadpfad" 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);
+ }
+
+ /**
+ * Sets the value of "IdP" in the configuration file to 'value'
+ *
+ * @return true if it succeeded, false otherwise
+ */
+ 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'
+ *
+ * @return true if it succeeded, false otherwise
+ */
+ public static boolean setAuthenticationMethod(String value) {
+ return setString("main", "auth_method", value);
+ }
+
+ /**
+ * Save the changes to the ini file to actual file on the disk.
+ *
+ * @return true if succeeded, false otherwise
+ */
+ public static boolean store() {
+ try {
+ ini.store();
+ return true;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Gets the boolean from the given 'key' in the given 'section'.
+ * If nothing is found, return the given 'defaultValue'
+ *
+ * @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;
+ }
+ }
+
+ /**
+ * Gets the string from the given 'key' in the given 'section'
+ * If nothing is found, return the given 'defaultValue'
+ *
+ * @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
+ */
+ 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;
+ }
+ }
+
+ /**
+ * Sets the given 'key' in the given 'section' to 'value'.
+ * Restricted to boolean.
+ *
+ * @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 setBoolean(String section, String key, boolean value) {
+ return ini.put(section, key, value) != null;
+ }
+
+ /**
+ * 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;
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java
new file mode 100644
index 00000000..ece74088
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWIDMAuthenticator.java
@@ -0,0 +1,87 @@
+package org.openslx.dozmod.authentication;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+
+import org.apache.http.ParseException;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.TAuthenticationException;
+import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode;
+import org.openslx.thrifthelper.ThriftManager;
+
+import com.google.gson.JsonSyntaxException;
+
+/**
+ * @author Jonathan Bauer
+ *
+ */
+public class BWIDMAuthenticator implements BaseAuthenticator {
+
+ /**
+ * Logger instance for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(BWIDMAuthenticator.class);
+
+ private final String ecpUrl;
+
+ public BWIDMAuthenticator(String ecpUrl) {
+ // first lets check the given ecpUrl
+ if (!ecpUrl.isEmpty())
+ this.ecpUrl = ecpUrl;
+ else
+ this.ecpUrl = null;
+ // NOTE: the actual check for a correct URI will be done by
+ // the ECP client.
+ }
+
+ @Override
+ public void login(String username, String password,
+ AuthenticatorCallback callback) throws TAuthenticationException {
+ // try to login
+ ReturnCode ret = null;
+ try {
+ ret = ShibbolethECP.doLogin(this.ecpUrl, username, password);
+ } catch (JsonSyntaxException e) {
+ LOGGER.error("Could not parse JSON response from the service provider: ", e);
+ } catch (ClientProtocolException e) {
+ LOGGER.error("HTTP client protocol error: ", e);
+ } catch (ParseException e) {
+ LOGGER.error("Error parsing the raw response body from the service provider: ", e);
+ } catch (MalformedURLException e) {
+ LOGGER.error("Bad syntax of the registration URL returned by the service provider: ", e);
+ } catch (URISyntaxException e) {
+ LOGGER.error("Bad syntax of the URL to the identity provider: ", e);
+ } catch (IOException e) {
+ LOGGER.error("IO Error while communicating with the service provider: ", e);
+ }
+ // if ret is still null, some exception happened, so abort.
+ if (ret == null) {
+ LOGGER.error("Error during the ECP authentication process.");
+ return;
+ }
+
+ // else, we do have a valid ReturnCode
+ if (ret == ReturnCode.NO_ERROR) {
+ UserInfo userInfo;
+ try {
+ userInfo = ThriftManager.getMasterClient().getUserFromToken(ShibbolethECP.getResponse().token);
+ } catch (TInvalidTokenException e) {
+ LOGGER.error("Masterserver does not accepts the token received from the Service Provider. See trace: ", e);
+ return;
+ } catch (TException e) {
+ LOGGER.error("Thrift transport error, see trace: ", e);
+ return;
+ }
+ callback.postLogin(ReturnCode.NO_ERROR, userInfo);
+ } else {
+ // else just return the ReturnCode to the GUI
+ // it should then show a corresponding error message!
+ callback.postLogin(ret, null);
+ }
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java
new file mode 100644
index 00000000..7a9e718d
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BWLPAuthenticator.java
@@ -0,0 +1,55 @@
+package org.openslx.dozmod.authentication;
+
+import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.SessionData;
+import org.openslx.bwlp.thrift.iface.TAuthenticationException;
+import org.openslx.bwlp.thrift.iface.TAuthorizationException;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode;
+import org.openslx.thrifthelper.ThriftManager;
+
+/**
+ * @author Jonathan Bauer
+ *
+ */
+public class BWLPAuthenticator implements BaseAuthenticator {
+
+ /**
+ * Logger instance for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(BWLPAuthenticator.class);
+
+ @Override
+ public void login(String username, String password,
+ AuthenticatorCallback callback) throws TAuthenticationException {
+
+ SessionData authResult = null;
+ // try to login user
+ try {
+ authResult = ThriftManager.getMasterClient().authenticate(username, password);
+ } catch (TException e) {
+ LOGGER.error("Thrift communication error: ", e);
+ // TODO authenticate has to return a TAuthenticationException!
+ callback.postLogin(ReturnCode.ERROR_OTHER, null);
+ return;
+ }
+
+ // handle answer from server
+ if (authResult != null && authResult.authToken != null) {
+ UserInfo userInfo = null;
+ try {
+ userInfo = ThriftManager.getMasterClient().getUserFromToken(authResult.authToken);
+ } catch (TException e) {
+ LOGGER.error("Thrift communication error: ", e);
+ // TODO authenticate has to return a TAuthenticationException!
+ callback.postLogin(ReturnCode.ERROR_OTHER, null);
+ return;
+ }
+ callback.postLogin(ReturnCode.NO_ERROR, userInfo);
+ } else {
+ // it should then show a corresponding error message!
+ callback.postLogin(ReturnCode.ERROR_OTHER, null);
+ }
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java
new file mode 100644
index 00000000..60602a3f
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/BaseAuthenticator.java
@@ -0,0 +1,33 @@
+package org.openslx.dozmod.authentication;
+
+import org.openslx.bwlp.thrift.iface.TAuthenticationException;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode;
+
+import edu.kit.scc.dei.ecplean.ECPAuthenticationException;
+
+/**
+ * @author Jonathan Bauer
+ *
+ */
+public interface BaseAuthenticator {
+
+ /**
+ * Callback interface to the login to be called after a login
+ * Note that this will be called after every login, independent
+ * of the success of the operation. This way the GUI can show a
+ * corresponding message to the user.
+ */
+ interface AuthenticatorCallback {
+ void postLogin(ReturnCode returnCode, UserInfo user);
+ }
+ /**
+ * Definition of the generic login method.
+ *
+ * @param username The username as String.
+ * @param password The password as String.
+ * @param callback The callback function to be called after the login
+ * @throws ECPAuthenticationException
+ */
+ void login(String username, String password, AuthenticatorCallback callback) throws TAuthenticationException;
+} \ No newline at end of file
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ServiceProviderResponse.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ServiceProviderResponse.java
new file mode 100644
index 00000000..f222efb7
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ServiceProviderResponse.java
@@ -0,0 +1,15 @@
+package org.openslx.dozmod.authentication;
+
+import java.util.HashMap;
+
+public class ServiceProviderResponse {
+ public String status;
+ public String firstName;
+ public String lastName;
+ public String mail;
+ public HashMap<String, String> satellites;
+ public String token;
+ public String sessionId;
+ public String url;
+ public String error;
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethECP.java b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethECP.java
new file mode 100644
index 00000000..0998c8af
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/authentication/ShibbolethECP.java
@@ -0,0 +1,172 @@
+package org.openslx.dozmod.authentication;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.ParseException;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.util.EntityUtils;
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.AuthenticationError;
+import org.openslx.bwlp.thrift.iface.TAuthenticationException;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonSyntaxException;
+
+import edu.kit.scc.dei.ecplean.ECPAuthenticationException;
+import edu.kit.scc.dei.ecplean.ECPAuthenticator;
+
+public class ShibbolethECP {
+
+ /**
+ * Logger instance for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(ShibbolethECP.class);
+
+ /**
+ * Static gson object for (de)serialization
+ */
+ private static final Gson GSON = new GsonBuilder().create();
+
+ /**
+ * ServiceProviderResponse Object representing the last response we received
+ */
+ private static ServiceProviderResponse lastResponse = null;
+ /**
+ * URL for bwLehrpool registration
+ */
+ private static URL registrationUrl = null;
+ /**
+ * Return codes
+ */
+ public static enum ReturnCode {
+ NO_ERROR(0, "Authentication against the identity provider and request of the service provider resource worked."),
+ IDP_ERROR(1, "Authentication against the identity provider failed."),
+ UNREG_ERROR(2, "User not registered to use bwLehrpool."),
+ ERROR_SP(3, "Invalid resource of the service provider."),
+ ERROR_URL(4, "Invalid URL received from master server."),
+ ERROR_OTHER(5, "Internal error.");
+
+ private final int id;
+ private final String msg;
+
+ ReturnCode(int id, String msg) {
+ this.id = id;
+ this.msg = msg;
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ public String getMsg() {
+ return this.msg;
+ }
+ }
+
+ /**
+ * Static URI to the SP.
+ */
+ private final static URI BWLP_SP;
+ static {
+ URI tmp;
+ try {
+ tmp = new URI("https://bwlp-masterserver.ruf.uni-freiburg.de/webif/shib/api.php");
+ } catch (URISyntaxException e) {
+ // should never happen!
+ LOGGER.error("Bad URI syntax of the service provider, see trace: ", e);
+ tmp = null;
+ }
+ BWLP_SP = tmp;
+ }
+
+ public static ServiceProviderResponse getResponse() {
+ return lastResponse;
+ }
+ /**
+ * Fetches the resource
+ *
+ * @param idpUrl
+ * URL of the identity provider to authenticate against, as String.
+ * @param user
+ * Username as String.
+ * @param pass
+ * Password as String.
+ * @return
+ * true if login worked, false otherwise.
+ * @throws TAuthenticationException
+ */
+ public static ReturnCode doLogin(final String idpUrl, final String user, final String pass)
+ throws TAuthenticationException, URISyntaxException, ClientProtocolException, IOException,
+ ParseException, JsonSyntaxException, MalformedURLException {
+
+ // first lets do some sanity checks
+ if (BWLP_SP == null) {
+ LOGGER.error("URI to service provider is not set. Check the initialization of 'BWLP_SP'.");
+ return ReturnCode.ERROR_OTHER;
+ }
+ if (idpUrl == null) {
+ LOGGER.error("Identity provider is not set, did you initialize this class correctly?");
+ return ReturnCode.ERROR_OTHER;
+ }
+ if (user == null) {
+ LOGGER.error("No username given, aborting...");
+ return ReturnCode.ERROR_OTHER;
+ }
+ if (pass == null) {
+ LOGGER.error("No password given, aborting...");
+ return ReturnCode.ERROR_OTHER;
+ }
+
+ // now init the authenticator for that idp and our static sp
+ final ECPAuthenticator auth = new ECPAuthenticator(user, pass, new URI(idpUrl), BWLP_SP);
+
+ try {
+ auth.authenticate();
+ } catch (ECPAuthenticationException e) {
+ LOGGER.error("ECP Authentication Exception, see trace: ", e);
+ throw new TAuthenticationException(AuthenticationError.GENERIC_ERROR, e.getMessage());
+ }
+ // here test again for the SP's URL
+ final HttpGet testSp = new HttpGet(BWLP_SP);
+ final HttpResponse response = auth.getHttpClient().execute(testSp);
+
+ LOGGER.debug("SP request returned: " + response.getStatusLine());
+ final String responseBody = EntityUtils.toString(response.getEntity());
+
+ lastResponse = GSON.fromJson(responseBody, ServiceProviderResponse.class);
+
+ // TODO: here we will need to parse the answer accordingly.
+ // no errors, meaning everything worked fine.
+ if (lastResponse.status.equals("unregistered")) {
+ registrationUrl = new URL(lastResponse.url);
+ return ReturnCode.UNREG_ERROR;
+ }
+ // TODO the rest of the cases...
+ if (lastResponse.status.equals("error")) {
+ LOGGER.error("Server side error: " + lastResponse.error);
+ return ReturnCode.ERROR_OTHER;
+ }
+ if (lastResponse.status.equals("anonymous")) {
+ LOGGER.error("IdP did not forward user account information to SP. Contact developper.");
+ return ReturnCode.ERROR_OTHER;
+ }
+ if (lastResponse.status.equals("ok")) {
+ return ReturnCode.NO_ERROR;
+ }
+ // still here? then something else went wrong
+ return ReturnCode.ERROR_OTHER;
+ }
+ /**
+ * @return Registration URL given by the SP.
+ */
+ public static URL getRegistrationUrl() {
+ return registrationUrl;
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java
new file mode 100644
index 00000000..aebaf732
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/DownloadTask.java
@@ -0,0 +1,171 @@
+package org.openslx.dozmod.filetransfer;
+
+import java.io.File;
+import java.io.RandomAccessFile;
+
+import javax.swing.JOptionPane;
+import javax.swing.SwingWorker;
+
+import org.apache.log4j.Logger;
+import org.openslx.filetransfer.DataReceivedCallback;
+import org.openslx.filetransfer.Downloader;
+import org.openslx.filetransfer.FileRange;
+import org.openslx.filetransfer.WantRangeCallback;
+
+/**
+ * Execute file download in a background thread and update the progress.
+ *
+ * @author www.codejava.net
+ *
+ */
+public class DownloadTask extends SwingWorker<Void, Void> {
+
+ /**
+ * Logger instance for this class.
+ */
+ private final static Logger LOGGER = Logger.getLogger(DownloadTask.class);
+
+ private static final double UPDATE_INTERVAL_SECONDS = 0.6;
+ private static final double UPDATE_INTERVAL_MS = UPDATE_INTERVAL_SECONDS * 1000;
+ private static final double BYTES_PER_MIB = 1024 * 1024;
+ private static final long CHUNK_SIZE = 16 * 1024 * 1024;
+
+ private final String host;
+ private final int port;
+ private final String downloadToken;
+ private final String saveDir;
+ private final long fileSize;
+ private boolean success = false;
+
+ public DownloadTask(String host, int port, String downloadToken, String saveDir, long fileSize) {
+ this.host = host;
+ this.port = port;
+ this.downloadToken = downloadToken;
+ this.saveDir = saveDir;
+ this.fileSize = fileSize;
+ }
+
+ class Callbacks implements WantRangeCallback, DataReceivedCallback {
+ // initialize the counters needed for speed calculations
+ private long currentRequestedOffset = -1;
+ private long totalBytesRead = 0;
+ private long lastUpdate = 0;
+ private long lastBytes = 0;
+ private long currentBytes = 0;
+ private final RandomAccessFile file;
+
+ public Callbacks(RandomAccessFile file) {
+ this.file = file;
+ }
+
+ @Override
+ public FileRange get() {
+ if (currentRequestedOffset == -1)
+ currentRequestedOffset = 0;
+ else
+ currentRequestedOffset += CHUNK_SIZE;
+ if (currentRequestedOffset >= fileSize)
+ return null;
+ long end = currentRequestedOffset + CHUNK_SIZE;
+ if (end > fileSize)
+ end = fileSize;
+ return new FileRange(currentRequestedOffset, end);
+ }
+
+ @Override
+ public boolean dataReceived(final long fileOffset, final int dataLength, final byte[] data) {
+ try {
+ file.seek(fileOffset);
+ file.write(data, 0, dataLength);
+ } catch (Exception e) {
+ LOGGER.error("Could not write to file at offset " + fileOffset, e);
+ return false;
+ }
+ currentBytes += dataLength;
+ totalBytesRead += dataLength;
+ final long now = System.currentTimeMillis();
+ if (lastUpdate + UPDATE_INTERVAL_MS < now) {
+ final int percentCompleted = (int) ((totalBytesRead * 100) / fileSize);
+ setProgress(percentCompleted);
+ lastBytes = (lastBytes * 2 + currentBytes) / 3;
+ final double speed = lastBytes / UPDATE_INTERVAL_SECONDS;
+ firePropertyChange("speed", 0, speed / BYTES_PER_MIB);
+ firePropertyChange("bytesread", 0, totalBytesRead);
+ lastUpdate = now;
+ currentBytes = 0;
+ }
+ return true;
+ }
+
+ }
+
+ /**
+ * Executed in background thread
+ */
+ @Override
+ protected Void doInBackground() throws Exception {
+ boolean ret = false;
+ // show filesize in the GUI
+ firePropertyChange("filesize", 0, fileSize);
+
+ Downloader download = null;
+ RandomAccessFile file = null;
+ try {
+ download = new Downloader(host, port, null, downloadToken); // TODO: SSL
+ try {
+ file = new RandomAccessFile(new File(saveDir), "rw");
+ } catch (Exception e2) {
+ JOptionPane.showMessageDialog(null, "Could not open destination file:\n" + saveDir + "\n"
+ + e2.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
+ e2.printStackTrace();
+ setProgress(0);
+ return null;
+ }
+
+ Callbacks cb = new Callbacks(file);
+
+ ret = download.download(cb, cb);
+ } finally {
+ if (file != null) {
+ try {
+ file.close();
+ } catch (Exception e) {
+ }
+ }
+ if (download != null)
+ download.close(null);
+ }
+
+ // if the download succeeded, set the progress to 100% manually again here to make
+ // sure the GUI knows about it.
+ if (ret) {
+ setProgress(100);
+ firePropertyChange("bytesread", 0, fileSize);
+ firePropertyChange("success", false, true);
+ success = true;
+ }
+
+ return null;
+ }
+
+ /**
+ * Executed in Swing's event dispatching thread
+ */
+ @Override
+ protected void done() {
+ if (isCancelled())
+ return;
+ if (success) {
+ LOGGER.info("Datei erfolgreich heruntergeladen.");
+ String vmxResult = "";
+ JOptionPane.showMessageDialog(null, "Datei erfolgreich heruntergeladen. " + vmxResult, "Message",
+ JOptionPane.INFORMATION_MESSAGE);
+ } else {
+ LOGGER.error("Datei wurde unvollständig heruntergeladen.");
+ JOptionPane.showMessageDialog(null,
+ "Datei wurde unvollständig heruntergeladen. Bitte wiederholen.", "Message",
+ JOptionPane.INFORMATION_MESSAGE);
+ }
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java
new file mode 100644
index 00000000..c240c5d5
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java
@@ -0,0 +1,135 @@
+package org.openslx.dozmod.filetransfer;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.swing.JOptionPane;
+import javax.swing.SwingWorker;
+
+import org.apache.log4j.Logger;
+import org.openslx.filetransfer.UploadStatusCallback;
+import org.openslx.filetransfer.Uploader;
+
+/**
+ * Executes the file upload in a background thread and updates progress to
+ * listeners that implement the java.beans.PropertyChangeListener interface.
+ *
+ * @author www.codejava.net
+ *
+ */
+public class UploadTask extends SwingWorker<Void, Void> {
+
+ /**
+ * Logger instance for this class.
+ */
+ private final static Logger LOGGER = Logger.getLogger(UploadTask.class);
+
+ private static final double UPDATE_INTERVAL_SECONDS = 0.6;
+ private static final double UPDATE_INTERVAL_MS = UPDATE_INTERVAL_SECONDS * 1000;
+ private static final double BYTES_PER_MIB = 1024 * 1024;
+
+ private final String host;
+ private final int port;
+ private final String uploadToken;
+ private final File uploadFile;
+ private boolean success = false;
+
+ public UploadTask(String host, int port, String uploadToken, File uploadFile) {
+ // TODO: SSL
+ this.host = host;
+ this.port = port;
+ this.uploadToken = uploadToken;
+ this.uploadFile = uploadFile;
+
+ }
+
+ /**
+ * Executed in background thread
+ */
+ @Override
+ protected Void doInBackground() {
+
+ Uploader upload = null;
+ try {
+ upload = new Uploader(host, port, null, uploadToken); // TODO: SSL
+
+ final Uploader ul = upload;
+ /* BROKEN CODE - FIXME class imports
+ final long fileSize = Image.Filesize = uploadFile.length();
+ BROKEN CODE - FIXME class imports */
+ final long fileSize = 1000000;
+
+
+ firePropertyChange("filesize", 0, fileSize); // Updates GUI
+
+ final boolean ret = upload.upload(uploadFile.getAbsolutePath(), new UploadStatusCallback() {
+ // progress counter
+ private long totalBytesRead = 0;
+ // initialize the counters needed for speed calculations
+ private long lastUpdate = 0;
+ private long lastBytes = 0;
+ private long currentBytes = 0;
+
+ @Override
+ public void uploadProgress(long bytesSent) {
+ totalBytesRead += bytesSent;
+ currentBytes += bytesSent;
+ final long now = System.currentTimeMillis();
+ if (lastUpdate + UPDATE_INTERVAL_MS < now) {
+ final int percentCompleted = (int) ((totalBytesRead * 100) / fileSize);
+ setProgress(percentCompleted);
+ lastBytes = (lastBytes * 2 + currentBytes) / 3;
+ final double speed = lastBytes / UPDATE_INTERVAL_SECONDS;
+ firePropertyChange("speed", 0, speed / BYTES_PER_MIB);
+ firePropertyChange("bytesread", 0, totalBytesRead);
+ lastUpdate = now;
+ currentBytes = 0;
+ }
+ }
+
+ @Override
+ public void uploadError(String message) {
+ JOptionPane.showMessageDialog(null, "Error uploading file: " + message, "Error",
+ JOptionPane.ERROR_MESSAGE);
+ ul.close(null);
+ }
+ });
+
+ // if the upload succeeded, set the progress to 100% manually again here to make
+ // sure the GUI knows about it.
+ if (ret) {
+ setProgress(100);
+ firePropertyChange("bytesread", 0, uploadFile.length());
+ firePropertyChange("success", false, true);
+ success = true;
+ }
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(null, "Error uploading file: " + e.getMessage(), "Error",
+ JOptionPane.ERROR_MESSAGE);
+ LOGGER.error("Upload of " + uploadFile.getAbsolutePath() + " failed!", e);
+ } finally {
+ if (upload != null)
+ upload.close(null);
+ }
+
+ return null;
+ }
+
+ /**
+ * Executed in Swing's event dispatching thread
+ */
+ @Override
+ protected void done() {
+ if (isCancelled())
+ return;
+ if (success) {
+ LOGGER.info("Datei erfolgreich hochgeladen.");
+ JOptionPane.showMessageDialog(null, "Datei erfolgreich hochgeladen.", "Message",
+ JOptionPane.INFORMATION_MESSAGE);
+ } else {
+ LOGGER.error("Datei wurde unvollständig hochgeladen.");
+ JOptionPane.showMessageDialog(null, "Datei wurde unvollständig hochgeladen. Bitte wiederholen.",
+ "Message", JOptionPane.INFORMATION_MESSAGE);
+ }
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java
new file mode 100644
index 00000000..b8680607
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java
@@ -0,0 +1,153 @@
+package org.openslx.dozmod.gui.control;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.openslx.thrifthelper.TransferStatusWrapper;
+
+public class BlockProgressBar extends Canvas {
+
+ private final Color white, blue, black;
+
+ private final Color[] blockColors = new Color[5];
+
+ private final TransferStatusWrapper blocks = new TransferStatusWrapper(null);
+
+ private boolean simpleMode = true;
+
+ public BlockProgressBar(Composite parent) {
+ super(parent, SWT.NO_BACKGROUND);
+ setupListeners();
+ white = getDisplay().getSystemColor(SWT.COLOR_WHITE);
+ blue = getDisplay().getSystemColor(SWT.COLOR_BLUE);
+ black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
+ // 0 = complete, 1 = missing, 2 = uploading, 3 = queued for copying, 4 = copying
+ blockColors[0] = black;
+ blockColors[1] = getDisplay().getSystemColor(SWT.COLOR_RED);
+ blockColors[2] = getDisplay().getSystemColor(SWT.COLOR_YELLOW);
+ blockColors[3] = blue;
+ blockColors[4] = getDisplay().getSystemColor(SWT.COLOR_GREEN);
+ }
+
+ public void setStatus(byte[] blocks) {
+ this.blocks.setBlocks(blocks);
+ this.redraw();
+ }
+
+ private void setupListeners() {
+ final BlockProgressBar me = this;
+ // Paint listener
+ this.addPaintListener(new PaintListener() {
+ @Override
+ public void paintControl(PaintEvent e) {
+ me.draw(e);
+ }
+ });
+
+ this.addMouseListener(new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ me.toggleMode();
+ }
+ });
+ }
+
+ private void toggleMode() {
+ simpleMode = !simpleMode;
+ this.redraw();
+ }
+
+ private void draw(PaintEvent e) {
+ if (blocks.isEmpty()) {
+ // No valid block data, draw white window
+ e.gc.setBackground(white);
+ e.gc.fillRectangle(e.x, e.y, e.width, e.height);
+ } else if (simpleMode) {
+ drawSimple(e);
+ } else {
+ drawDetailed(e);
+ }
+ }
+
+ private void drawSimple(PaintEvent e) {
+ final Rectangle a = this.getClientArea();
+ final float width = a.width - 2;
+ final float complete = blocks.getComplete();
+ final float doneWidth = width * complete;
+ e.gc.setBackground(blue);
+ e.gc.fillRectangle(a.x, a.y, (int) doneWidth, a.height);
+ e.gc.setBackground(white);
+ e.gc.fillRectangle(a.x + (int) doneWidth, a.y, (int) (width - doneWidth), a.height);
+ final String progress = (int) (complete * 100) + "%";
+ Point textExtent = e.gc.textExtent(progress, SWT.DRAW_TRANSPARENT);
+ final int textX = a.x + (a.width - textExtent.x) / 2;
+ final int textY = a.y + (a.height - textExtent.y) / 2;
+ e.gc.setForeground(white);
+ e.gc.drawText(progress, textX - 1, textY - 1, true);
+ e.gc.drawText(progress, textX + 1, textY + 1, true);
+ e.gc.setForeground(black);
+ e.gc.drawText(progress, textX, textY, true);
+ }
+
+ private void drawDetailed(PaintEvent e) {
+ final int blockCount = blocks.getBlockCount();
+ // Calculate display mode
+ final Rectangle a = this.getClientArea();
+ final float width = a.width - 2;
+ float blockWidth = width / blockCount;
+ int rows = 1;
+ while (blockWidth * rows < 6 && a.height / rows > 8) {
+ rows++;
+ }
+ blockWidth *= rows;
+ final float blockHeight;
+ final float blockHeightVisible;
+ if (rows == 1) {
+ blockHeightVisible = blockHeight = a.height;
+ } else {
+ blockHeight = (a.height + 2) / rows;
+ blockHeightVisible = blockHeight - 2;
+ }
+ // Draw
+ float x = a.x, y = a.y;
+ for (byte block : blocks.getBlocks()) {
+ if (block >= 0 && block < blockColors.length) {
+ e.gc.setBackground(blockColors[block]);
+ } else {
+ e.gc.setBackground(white);
+ }
+ e.gc.fillRectangle((int) x, (int) y, (int) (x + blockWidth) - (int) x,
+ (int) (y + blockHeightVisible) - (int) y);
+ x += blockWidth;
+ if (x + 0.5 > a.width) {
+ e.gc.setBackground(white);
+ e.gc.fillRectangle(a.x, (int) (y + blockHeightVisible), a.width, 2);
+ x = a.x;
+ y += blockHeight;
+ }
+ }
+ // If we're multiline and have an odd number of blocks, there might be some remaining space - draw white
+ if (x + 0.5 < a.width) {
+ e.gc.setBackground(white);
+ e.gc.fillRectangle((int) x, (int) y, (int) (x + blockWidth) - (int) x,
+ (int) (y + blockHeightVisible) - (int) y);
+ }
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java
new file mode 100644
index 00000000..b79f306d
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java
@@ -0,0 +1,147 @@
+package org.openslx.dozmod.gui.helper;
+
+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.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+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;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.thrifthelper.ThriftManager.ErrorCallback;
+
+public abstract class GuiManager {
+
+ private final static Logger LOGGER = Logger.getLogger(GuiManager.class);
+
+ static Shell mainShell;
+ static Composite contentComposite;
+ static Display display;
+
+ static final int THRIFT_ERROR_RETRY_COUNT = 3;
+ static final String THRIFT_ERROR = "Lost connection to the masterserver. Click OK to retry.";
+ static final String THRIFT_FINAL_ERROR = "Could not re-establish connection to the masterserver after "
+ + THRIFT_ERROR_RETRY_COUNT + " tries. Contact an administrator/developer. Exiting application.";
+
+ /**
+ * Add a new composite with content to the main Shell
+ * @param The composite to add, should be a GUI
+ */
+ public static void addContent( Composite contentComposite ){
+ removeContent();
+
+ GuiManager.contentComposite = contentComposite;
+
+ // sets the starting preferred size.
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ gridData.widthHint = 800;
+ gridData.heightHint = 600;
+ contentComposite.setLayoutData(gridData);
+ mainShell.setMinimumSize(850, 650);
+ mainShell.layout();
+
+ }
+
+ /**
+ * Remove the current content of the main shell
+ */
+ private static void removeContent() {
+ if(contentComposite != null) {
+ GuiManager.contentComposite.dispose();
+
+ }
+ }
+
+ // TODO use showMessageBox
+ public static void showMessage(final String message, final int style) {
+ MessageBox msgBox = new MessageBox(mainShell, style);
+ msgBox.setText("Information");
+ msgBox.setMessage(message);
+ int ret = msgBox.open();
+ LOGGER.info("Message box return value: " + ret);
+ }
+
+ public static Display getDisplay(){
+ return display;
+ }
+
+ public static void initGui() {
+ display = new Display();
+ mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER);
+
+ // setup global thrift connection error handler before anything else
+ // Set master server to use (TODO: make configurable via command line)
+ ThriftManager.setMasterServerAddress( "bwlp-masterserver.ruf.uni-freiburg.de" );
+
+ // Set up thrift error message displaying
+ ThriftManager.setErrorCallback(new ErrorCallback() {
+
+ @Override
+ public boolean thriftError(int failCount, String method, Throwable t) {
+ // first check if we failed 3 reconnects, if so just let the user know
+ // that we are closing the application due to connection problems.
+ MessageBox msgBox = new MessageBox(mainShell, SWT.ICON_ERROR);
+ msgBox.setText("Critical error");
+ if (failCount > THRIFT_ERROR_RETRY_COUNT) {
+ msgBox.setMessage(THRIFT_FINAL_ERROR);
+ return false;
+ } else {
+ msgBox.setMessage(THRIFT_ERROR);
+ return true;
+ }
+ }
+ });
+
+ Menu menuBar = new Menu(mainShell, SWT.BAR);
+ MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE);
+ cascadeFileMenu.setText("&File");
+
+ Menu fileMenu = new Menu(mainShell, SWT.DROP_DOWN);
+ cascadeFileMenu.setMenu(fileMenu);
+
+ MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
+ exitItem.setText("&Exit");
+ exitItem.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ mainShell.getDisplay().dispose();
+ System.exit(0);
+ }
+ });
+
+ mainShell.setText("bwSuite");
+ mainShell.setMenuBar(menuBar);
+
+ // Set layout for the mainshell, items added to the shell should get a gridData
+ mainShell.setLayout(new GridLayout(1, true));
+
+ addContent(new org.openslx.dozmod.gui.window.LoginWindow(mainShell));
+
+ // center the window on the primary monitor
+ Monitor primary = display.getPrimaryMonitor();
+ Rectangle bounds = primary.getBounds();
+ Rectangle rect = mainShell.getBounds();
+
+ int x = bounds.x + (bounds.width - rect.width) / 2;
+ int y = bounds.y + (bounds.height - rect.height) / 2;
+
+ mainShell.setLocation(x, y);
+
+ mainShell.pack();
+ mainShell.open();
+
+ LOGGER.info("GUI initialised.");
+
+ while (!mainShell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java
new file mode 100644
index 00000000..b0f55a5d
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java
@@ -0,0 +1,23 @@
+package org.openslx.dozmod.gui.helper;
+
+import javax.swing.JOptionPane;
+
+import org.apache.log4j.Priority;
+
+@SuppressWarnings("deprecation")
+public enum MessageType {
+ DEBUG(JOptionPane.INFORMATION_MESSAGE, "Debug", Priority.DEBUG),
+ INFO(JOptionPane.INFORMATION_MESSAGE, "Hinweis", Priority.INFO),
+ WARNING(JOptionPane.WARNING_MESSAGE, "Warnung", Priority.WARN),
+ ERROR(JOptionPane.ERROR_MESSAGE, "Fehler", Priority.ERROR);
+
+ public final String title;
+ public final int optionPaneId;
+ public final Priority logPriority;
+
+ private MessageType(int paneId, String title, Priority prio) {
+ this.title = title;
+ this.optionPaneId = paneId;
+ this.logPriority = prio;
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java
new file mode 100644
index 00000000..5a8ca579
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java
@@ -0,0 +1,77 @@
+package org.openslx.dozmod.gui.helper;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.swt.SWT;
+import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
+import org.openslx.bwlp.thrift.iface.OperatingSystem;
+import org.openslx.dozmod.thrift.MetaDataCache;
+
+public final class TableHelper {
+ private TableHelper() {
+ }
+
+ private static void createColumn(TableViewer table, String colName, int width,
+ ColumnLabelProvider provider) {
+ TableViewerColumn col = new TableViewerColumn(table, SWT.NONE);
+ col.getColumn().setWidth(width);
+ col.getColumn().setText(colName);
+ col.setLabelProvider(provider);
+
+ }
+
+ /**
+ * create the columns for the table in the VM mainwindow
+ *
+ * @param table the tableViewer
+ */
+ public static void createImageTableColumns(TableViewer table) {
+ createColumn(table, "Name", 150, new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ ImageSummaryRead image = (ImageSummaryRead) element;
+ return image.getImageName();
+ }
+ });
+
+ createColumn(table, "OS", 90, new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ ImageSummaryRead image = (ImageSummaryRead) element;
+ OperatingSystem os = MetaDataCache.getOsById(image.getOsId());
+
+ if (os == null) {
+ return "Unknown";
+ } else {
+ return os.getOsName();
+ }
+ }
+ });
+
+ createColumn(table, "Verantwortlicher", 130, new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ ImageSummaryRead image = (ImageSummaryRead) element;
+ return image.getOwnerId();
+ }
+ });
+
+ createColumn(table, "Letztes Update", 110, new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ ImageSummaryRead image = (ImageSummaryRead) element;
+ return String.valueOf(image.getUpdateTime());
+ }
+ });
+
+ createColumn(table, "Größe", 80, new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ ImageSummaryRead image = (ImageSummaryRead) element;
+ return String.valueOf(image.getFileSize());
+ }
+ });
+
+ };
+}
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
new file mode 100644
index 00000000..6db29f15
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java
@@ -0,0 +1,40 @@
+package org.openslx.dozmod.gui.window;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.openslx.dozmod.Config;
+import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.window.layout.DisclaimerWindowLayout;
+
+public class DisclaimerWindow extends DisclaimerWindowLayout{
+
+ private final static Logger LOGGER = Logger.getLogger(DisclaimerWindow.class);
+
+ public DisclaimerWindow(final Shell mainShell) {
+ super(mainShell);
+
+ // function for agreement checkbox
+ agreeBox.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ continueButton.setEnabled(!continueButton.isEnabled());
+ }
+ });
+
+ // function for continue button
+ continueButton.addSelectionListener(new SelectionAdapter() {
+ @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();
+ // now check the config to see if the user has agreed to vmware stuff
+ GuiManager.addContent(new VirtualizerNoticeWindow(getShell()));
+ }
+ });
+ }
+
+}
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
new file mode 100644
index 00000000..62860fb5
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
@@ -0,0 +1,333 @@
+package org.openslx.dozmod.gui.window;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+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.TAuthenticationException;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.Config;
+import org.openslx.dozmod.authentication.BWIDMAuthenticator;
+import org.openslx.dozmod.authentication.BWLPAuthenticator;
+import org.openslx.dozmod.authentication.BaseAuthenticator.AuthenticatorCallback;
+import org.openslx.dozmod.authentication.ShibbolethECP.ReturnCode;
+import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.window.layout.LoginWindowLayout;
+import org.openslx.dozmod.gui.window.layout.MainWindowLayout;
+import org.openslx.dozmod.thrift.OrganizationCache;
+import org.openslx.thrifthelper.ThriftManager;
+
+import edu.kit.scc.dei.ecplean.ECPAuthenticationException;
+
+/**
+ * @author Jonathan Bauer
+ *
+ */
+public class LoginWindow extends LoginWindowLayout {
+
+ private final static Logger LOGGER = Logger.getLogger(LoginWindow.class);
+
+ // text constants
+ private final String NO_USERNAME = "Kein Benutzername angegeben!";
+ private final String NO_PASSWORD = "Kein Passwort angegeben!";
+
+ // user input variables
+ private String username = null;
+ private String password = null;
+
+
+ /**
+ * Constructor doing the setup of the logical GUI functions
+ * Fetches the organization list for BWIDM logins and
+ * adds mouse/keyboard event listeners to various widgets.
+ *
+ * @param mainShell
+ */
+ public LoginWindow(final Shell mainShell) {
+ // call the constructor of the superclass
+ super(mainShell);
+
+ // entries in the combo
+ List<Organization> orgs = OrganizationCache.getAll();
+ if (orgs == null) {
+ LOGGER.error("No organizations received from the cache.");
+ 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());
+ }
+ });
+
+ // now check if we had a saved identity provider
+ String savedOrganizationId = Config.getIdentityProvider();
+ // add only organizations which have an ECP URL to the combobox
+ for (Organization o : orgs) {
+ if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) continue;
+ LOGGER.debug("Adding: " + o.toString());
+ idpCombo.add(o.displayName);
+ idpCombo.setData(o.displayName, o);
+ if (savedOrganizationId != null &&
+ !savedOrganizationId.isEmpty() &&
+ savedOrganizationId.equals(o.getOrganizationId()))
+ // select the organization we just added, this seems kinda bad - is there a better way?
+ idpCombo.select(idpCombo.getItemCount() - 1);
+ //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer
+ }
+ // if no organization was saved, none is selected, so select the first one in the combobox
+ if (idpCombo.getSelectionIndex() == -1)
+ idpCombo.select(0);
+ // check if we had saved an authentication method
+ String savedAuthMethod = Config.getAuthenticationMethod();
+ if (savedAuthMethod != null && !savedAuthMethod.isEmpty()) {
+ LOGIN_TYPE savedLoginType = LOGIN_TYPE.getEnum(savedAuthMethod);
+ // 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;
+ } else {
+ authButtons[savedLoginType.getId()].setSelection(true);
+ loginType = savedLoginType;
+ 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;
+ }
+
+
+ // finally check if we had a saved username
+ String savedUsername = Config.getUsername();
+ if (savedUsername != null && !savedUsername.isEmpty()) {
+ usernameText.setText(savedUsername);
+ saveUsernameCheck.setSelection(true);
+ passwordText.setFocus();
+ } else
+ usernameText.setFocus();
+
+ // actions of the login button
+ loginButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ doSaveConfig();
+ doLogin();
+ }
+ });
+
+ // 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;
+ }
+ });
+
+ // add a key listener to the password field to trigger login
+ // when the user presses the ENTER key.
+ passwordText.addKeyListener(new KeyListener() {
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (e.keyCode == SWT.CR) {
+ doSaveConfig();
+ doLogin();
+ }
+ }
+ @Override
+ public void keyPressed(KeyEvent e) {}
+ });
+ }
+
+ /**
+ * Saves various user choices to the config file.
+ * This gets triggered when the login button is activated.
+ */
+ private void doSaveConfig() {
+ // first we need to check if the "Remember me" button is active
+ 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() + "'.");
+ }
+ }
+ // 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 + "'!");
+ }
+ // finalize by actually storing the config file
+ if (!Config.store())
+ LOGGER.error("Could not save '" + Config.getPath() + "'!");
+ }
+ /**
+ * 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() {
+ // sanity check on loginType.
+ if (loginType == null) {
+ LOGGER.error("No login type set, a default should be set! Ignoring...");
+ return;
+ }
+ // 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, SWT.ICON_ERROR);
+ 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, SWT.ICON_ERROR);
+ return;
+ }
+
+ // determine which organization was selected by the user.
+ Organization selectedOrg = getSelectedOrganization();
+
+ // now switch over the login types.
+ switch (loginType) {
+ case BWIDM:
+ BWIDMAuthenticator bwidmAuth = new BWIDMAuthenticator(
+ selectedOrg.getEcpUrl());
+ try {
+ bwidmAuth.login(username, password, new AuthenticatorCallback() {
+ @Override
+ public void postLogin(ReturnCode returnCode, UserInfo user) {
+ // TODO finish this
+ // handle errors first
+ if (returnCode != ReturnCode.NO_ERROR && user == null) {
+ switch(returnCode) {
+ case IDP_ERROR:
+ GuiManager.showMessage("IdP Error", SWT.ICON_ERROR);
+ break;
+ default:
+ GuiManager.showMessage("Internal error!", SWT.ICON_ERROR);
+ break;
+ }
+ } else
+ postSuccessfulLogin();
+ }
+ });
+ } catch (TAuthenticationException e) {
+ //LOGGER.error("Authentication error, see trace: ", e);
+ GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR);
+ return;
+ }
+ break;
+ case BWLP:
+ LOGGER.info("bwlp");
+ BWLPAuthenticator bwlpAuth = new BWLPAuthenticator();
+ try {
+ bwlpAuth.login(username, password, new AuthenticatorCallback() {
+ @Override
+ public void postLogin(ReturnCode returnCode, UserInfo user) {
+ // handle errors first
+ if (returnCode != ReturnCode.NO_ERROR && user == null) {
+ LOGGER.error("BWLP login failed.");
+ GuiManager.showMessage("Login failed!", SWT.ICON_ERROR);
+ }
+ if (returnCode == ReturnCode.NO_ERROR && user != null)
+ postSuccessfulLogin();
+ }
+ });
+ } catch (TAuthenticationException e) {
+ GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR);
+ }
+ break;
+ case SAT:
+ LOGGER.warn("Direct satellite login is not yet supported.");
+ break;
+ default:
+ LOGGER.error("Unknown login type! Ignoring...");
+ break;
+ }
+ return;
+ }
+
+ /**
+ * Functions called by doLogin is the login process succeeded.
+ */
+ private void postSuccessfulLogin() {
+ LOGGER.info(loginType.getTag() + " 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())
+ GuiManager.addContent(new DisclaimerWindow(getShell()));
+ else if (!Config.getVmwareLicenseAgreement())
+ GuiManager.addContent(new VirtualizerNoticeWindow(getShell()));
+ // TODO: See MainWindowLayout comments
+ }
+
+ /**
+ * @return the organization currently selected in the combobox for identity providers
+ */
+ private final Organization getSelectedOrganization() {
+ // get the index of the selected item in the combobox
+ int selectionIndex = idpCombo.getSelectionIndex();
+ if (selectionIndex == -1) {
+ LOGGER.error("No identity provider is selected in the combobox. There should be a default value!");
+ return null;
+ }
+ return (Organization) idpCombo.getData(idpCombo.getItem(selectionIndex));
+ }
+}
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
new file mode 100644
index 00000000..177957bc
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/VirtualizerNoticeWindow.java
@@ -0,0 +1,54 @@
+package org.openslx.dozmod.gui.window;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.openslx.dozmod.Config;
+import org.openslx.dozmod.gui.window.layout.VirtualizerNoticeWindowLayout;
+
+public class VirtualizerNoticeWindow extends VirtualizerNoticeWindowLayout {
+
+ private final static Logger LOGGER = Logger.getLogger(VirtualizerNoticeWindow.class);
+
+ public VirtualizerNoticeWindow(final Shell mainShell) {
+ super(mainShell);
+
+ // function for agreement checkbox
+ continueButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (!Config.setVmwareLicenseAgreement(true))
+ LOGGER.error("Could not set the agreement to the vmware license in '" + Config.getPath() + "'!");
+ Config.store();
+ // TODO GuiManager.addContent(new MainWindowLayout(getShell()));
+ }
+ });
+
+ // actions of the login button
+ linuxDLButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ //clickedLinuxDLButton();
+ }
+ });
+
+ // actions of the login button
+ windowsDLButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ //clickedWindowsDLButton();
+ }
+ });
+
+ // actions of the login button
+ readCheck.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ //clickedReadCheckButton();
+ }
+ });
+
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/DisclaimerWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/DisclaimerWindowLayout.java
new file mode 100644
index 00000000..37b1bdae
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/DisclaimerWindowLayout.java
@@ -0,0 +1,87 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+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 abstract class DisclaimerWindowLayout extends Composite {
+
+ private final String notice = "Bitte lesen und bestätigen Sie folgende rechtliche Hinweise";
+ private final String disclaimer = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \n\n"
+ + "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. \n\n"
+ + "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\n"
+ + "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.\n\n"
+ + "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.\n\n"
+ + "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.\n\n"
+ + "Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus.\n\n"
+ + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n"
+ + "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.\n\n"
+ + "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\n"
+ + "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo";
+
+ private final String checkboxText = "Ja, ich aktzeptiere die Vereinbarung. Benachrichtigung nicht mehr anzeigen.";
+
+ private final String title = "bwLehrpool Suite";
+ private final String noticeLabel = "Hinweis";
+
+ // Buttons
+ protected Button agreeBox;
+ protected Button continueButton;
+
+ public DisclaimerWindowLayout(final Shell mainShell) {
+ super(mainShell, SWT.NONE);
+
+
+ mainShell.setText(title);
+
+ // layout of this composite
+ this.setLayout(new GridLayout(1, true));
+
+
+ // information to read the disclaimer at the beginning of the window.
+ Group noticeGroup = new Group(this, SWT.NONE);
+ noticeGroup.setLayout(new GridLayout());
+ GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
+ noticeGroup.setLayoutData(gridData);
+ noticeGroup.setText(noticeLabel);
+
+ Label noticeLabel = new Label(noticeGroup, SWT.NONE);
+ noticeLabel.setText(notice);
+
+
+ // the disclaimer text box with scrolling functionality
+ Text disclaimerText = new Text(this, SWT.READ_ONLY | SWT.WRAP| SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
+ gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ gridData.widthHint = 900;
+ gridData.heightHint = 600;
+ disclaimerText.setLayoutData(gridData);
+ disclaimerText.setText(disclaimer);
+
+
+ // checkbox for acknowledging the disclaimer
+ Composite checkboxComposite = new Composite(this, SWT.BORDER);
+ checkboxComposite.setLayout(new GridLayout());
+ gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
+
+ checkboxComposite.setLayoutData(gridData);
+
+ agreeBox = new Button(checkboxComposite, SWT.CHECK);
+ agreeBox.setText(checkboxText);
+
+
+ continueButton = new Button(this, SWT.PUSH);
+ continueButton.setText("Weiter");
+ continueButton.setEnabled(false);
+
+ gridData = new GridData(GridData.FILL, GridData.CENTER, true, false);
+ gridData.horizontalAlignment = SWT.RIGHT;
+ continueButton.setLayoutData(gridData);
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
new file mode 100644
index 00000000..99d97eac
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
@@ -0,0 +1,369 @@
+package org.openslx.dozmod.gui.window.layout;
+
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedList;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.openslx.bwlp.thrift.iface.ImagePermissions;
+import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
+import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.helper.TableHelper;
+import org.openslx.dozmod.gui.wizard.ImageWizard;
+
+public abstract class ImageListWindowLayout extends Composite {
+
+ protected String infoTitleString = "Imageauswahl";
+ protected String newButtonLabel = "Neu";
+ protected String editButtonLabel = "Bearbeiten";
+ protected String deleteButtonLabel = "Löschen";
+ protected String downloadButtonLabel = "Download";
+ protected String tableGroupLabel = "Images";
+ protected String vmInfoGroupLabel = "Detailinformationen";
+
+
+ // buttons
+ protected Button newButton;
+ protected Button deleteButton;
+ protected Button editButton;
+ protected Button downloadButton;
+
+ // imageDetail texts
+ protected Text imageSelectedNameLabel;
+ protected Text idInfo;
+ protected Text versionInfo;
+ protected Text lastUpdateInfo;
+ protected Text permissionInfo;
+ protected Text ownerInfo;
+ protected Text templateInfo;
+
+
+ protected String infoTextString = "Hier können Sie images erstellen, bearbeiten und löschen.";
+
+ public ImageListWindowLayout(Composite mainShell) {
+ super(mainShell, SWT.NONE);
+
+ this.setLayout(new GridLayout(2, false));
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ this.setLayoutData(gridData);
+
+
+
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.horizontalSpan = 2;
+ Composite infoComposite = new Composite(this, SWT.BORDER);
+ infoComposite.setLayoutData(gridData);
+ infoComposite.setLayout(new GridLayout(1, false));
+
+
+
+ Label infoTitle = new Label(infoComposite, SWT.NONE);
+ infoTitle.setText(infoTitleString);
+ FontData fontData = infoTitle.getFont().getFontData()[0];
+ Font font = new Font(GuiManager.getDisplay(), new FontData(fontData.getName(), fontData
+ .getHeight(), SWT.BOLD));
+ infoTitle.setFont(font);
+
+ Label infoText = new Label(infoComposite, SWT.NONE);
+ infoText.setText(infoTextString);
+
+
+
+ // group for the table
+ Group tableGroup = new Group(this, SWT.BORDER);
+ tableGroup.setText(tableGroupLabel);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ tableGroup.setLayoutData(gridData);
+ tableGroup.setLayout(new GridLayout(3, true));
+
+ // jface tableviewer on swt table
+ Table vmTable = new Table(tableGroup, SWT.BORDER | SWT.V_SCROLL
+ | SWT.H_SCROLL);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.horizontalSpan = 3;
+ gridData.minimumWidth = 200;
+ vmTable.setLayoutData(gridData);
+ vmTable.setHeaderVisible(true);
+ vmTable.setLinesVisible(true);
+
+ // TableViewer on the table
+ final TableViewer tableViewer = new TableViewer(vmTable);
+ tableViewer.setContentProvider(ArrayContentProvider.getInstance());
+
+
+
+ // For testing
+ ImageSummaryRead imageSummary = new ImageSummaryRead();
+ imageSummary.setImageName("Windoof");
+ imageSummary.setOsId(1);
+ LinkedList<ImageSummaryRead> list = new LinkedList<>();
+ imageSummary.setUserPermissions(new ImagePermissions(true, true, false, false));
+ imageSummary.setUpdateTime(505050550);
+ imageSummary.setOwnerId("2");
+ imageSummary.setImageBaseId("8");
+ imageSummary.setCurrentVersionId("8.12");
+ list.add(imageSummary);
+
+ ImageSummaryRead imageSummary2 = new ImageSummaryRead();
+ imageSummary2.setImageName("Linuksch");
+ imageSummary2.setOsId(2);
+ list.add(imageSummary2);
+
+ // The List to be displayed in the viewer
+ tableViewer.setInput(list);
+
+ TableHelper.createImageTableColumns(tableViewer);
+
+ tableViewer.refresh();
+
+ // create, modify, download and delete buttons
+ Composite buttonComposite = new Composite(tableGroup, SWT.NONE);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.horizontalSpan = 4;
+ gridData.minimumWidth = 200;
+ buttonComposite.setLayoutData(gridData);
+ buttonComposite.setLayout(new RowLayout());
+
+
+
+ newButton = new Button(buttonComposite, SWT.PUSH);
+ newButton.setText(newButtonLabel);
+
+ editButton = new Button(buttonComposite, SWT.PUSH);
+ editButton.setText(editButtonLabel);
+
+ deleteButton = new Button(buttonComposite, SWT.PUSH);
+ deleteButton.setText(deleteButtonLabel);
+
+ downloadButton = new Button(buttonComposite, SWT.PUSH);
+ downloadButton.setText(downloadButtonLabel);
+
+
+ // group for the info of the clicked image in the tableViewer
+ Group vmInfoGroup = new Group(this, SWT.BORDER);
+ vmInfoGroup.setText(vmInfoGroupLabel);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 300;
+ vmInfoGroup.setLayoutData(gridData);
+ vmInfoGroup.setLayout(new GridLayout(2, false));
+
+
+ // image name info
+ Label imageNameCaption = new Label(vmInfoGroup, SWT.NONE);
+ imageSelectedNameLabel = new Text(vmInfoGroup, SWT.READ_ONLY);
+
+ imageNameCaption.setText("Image Name:");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 100;
+ imageSelectedNameLabel.setLayoutData(gridData);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection)
+ tableViewer.getSelection();
+ ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
+ String s = selectedElement.getImageName();
+ if (s == null) {
+ imageSelectedNameLabel.setText("Unknown");
+ } else {
+ imageSelectedNameLabel.setText(s);
+ }
+ }
+ });
+
+
+ // id info
+ Label idInfoCaption = new Label(vmInfoGroup, SWT.NONE);
+ idInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
+ idInfoCaption.setText("ID:");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 100;
+ idInfo.setLayoutData(gridData);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection)
+ tableViewer.getSelection();
+ ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
+ String s = selectedElement.getImageBaseId();
+ if (s == null) {
+ idInfo.setText("Unknown");
+ } else {
+ idInfo.setText(s);
+ }
+ }
+ });
+ // imageSummary.get
+
+
+
+ Label versionInfoCaption = new Label(vmInfoGroup, SWT.NONE);
+ versionInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
+ versionInfoCaption.setText("Version:");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 100;
+ versionInfo.setLayoutData(gridData);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection)
+ tableViewer.getSelection();
+ ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
+ String s = selectedElement.getCurrentVersionId();
+ if (s == null) {
+ versionInfo.setText("Unknown");
+ } else {
+ versionInfo.setText(s);
+ }
+ }
+ });
+
+
+ Label lastUpdateInfoCaption = new Label(vmInfoGroup, SWT.NONE);
+ lastUpdateInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
+ lastUpdateInfoCaption.setText("Letztes Update:");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 100;
+ lastUpdateInfo.setLayoutData(gridData);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection)
+ tableViewer.getSelection();
+ ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
+ long unixTimestamp = selectedElement.getUpdateTime();
+
+
+ if (unixTimestamp == 0) {
+ lastUpdateInfo.setText("Unknown");
+ } else {
+ Date date = new Date(unixTimestamp*1000L);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ String formattedDate = sdf.format(date);
+ lastUpdateInfo.setText(formattedDate);
+ }
+ }
+ });
+
+ Label permissionInfoCaption = new Label(vmInfoGroup, SWT.NONE);
+ permissionInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
+ permissionInfoCaption.setText("Berechtigungen:");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 100;
+ permissionInfo.setLayoutData(gridData);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection)
+ tableViewer.getSelection();
+ ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
+ ImagePermissions p =selectedElement.getUserPermissions();
+ if (p != null){
+ String s = p.toString();
+ if (s == null) {
+ permissionInfo.setText("Unknown");
+ } else {
+ permissionInfo.setText(s);
+ }
+ } else {
+ permissionInfo.setText("Unknown");
+ }
+
+ }
+ });
+
+
+ Label ownerInfoCaption = new Label(vmInfoGroup, SWT.NONE);
+ ownerInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
+ ownerInfoCaption.setText("Besitzer ID:");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 100;
+ ownerInfo.setLayoutData(gridData);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection)
+ tableViewer.getSelection();
+ ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
+
+ String s = selectedElement.getOwnerId();
+
+ if (s != null) {
+ ownerInfo.setText(s);
+ } else {
+ ownerInfo.setText("Unknown");
+ }
+
+ }
+ });
+
+ Label templateCaption = new Label(vmInfoGroup, SWT.NONE);
+ templateInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
+ templateCaption.setText("Vorlage:");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gridData.minimumWidth = 100;
+ templateInfo.setLayoutData(gridData);
+
+ tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection)
+ tableViewer.getSelection();
+ ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
+
+ if (selectedElement.isTemplate) {
+ templateInfo.setText("ja");
+ } else {
+ templateInfo.setText("Nein");
+ }
+ }
+ });
+
+
+ newButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ImageWizard wizard = new ImageWizard(false);
+ WizardDialog wd = new WizardDialog(getShell(), wizard);
+ wd.open();
+ }
+ });
+
+ editButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ImageWizard wizard = new ImageWizard(true);
+ WizardDialog wd = new WizardDialog(getShell(), wizard);
+ wd.open();
+ }
+ });
+
+
+ }
+}
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
new file mode 100644
index 00000000..b527070e
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
@@ -0,0 +1,170 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import org.eclipse.swt.SWT;
+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;
+import org.openslx.dozmod.gui.helper.GuiManager;
+
+public abstract class LoginWindowLayout extends Composite {
+
+ // TODO add ids to use for the authButtons group!
+ protected static enum LOGIN_TYPE {
+ BWIDM(0, "bwidm"),
+ BWLP(1, "bwlp"),
+ SAT(2, "sat");
+
+ private final int id;
+ private final String tag;
+ private LOGIN_TYPE(final int id, final String tag) {
+ 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;
+ }
+ }
+ }
+ // authentication method to use for login attempts
+ protected LOGIN_TYPE loginType = null;
+
+ private Image titleImage;
+
+
+ // textfields for the username/password
+ protected Text usernameText;
+ protected Text passwordText;
+
+ // ComboBox/label for the IDP
+ protected final Combo idpCombo;
+ protected final Label idpText;
+
+ // buttons
+ protected final Button loginButton;
+ protected final Button saveUsernameCheck;
+ protected final Button[] authButtons;
+
+ private static final String title = "bwSuite - Login";
+ private static final String authenticationGroupLabel = "Authentifizierungsart";
+
+ /**
+ * Create a new login composite
+ *
+ * @param mainShell
+ * The shell it should be added to
+ */
+ public LoginWindowLayout(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
+ authButtons = new Button[3];
+ authButtons[LOGIN_TYPE.BWIDM.id] = new Button(authGroup, SWT.RADIO);
+ authButtons[LOGIN_TYPE.BWIDM.id].setText("Authentifizierung über bwIDM");
+ gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ authButtons[LOGIN_TYPE.BWIDM.id].setLayoutData(gridData);
+
+ authButtons[LOGIN_TYPE.BWLP.id] = new Button(authGroup, SWT.RADIO);
+ authButtons[LOGIN_TYPE.BWLP.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.SAT.id] = new Button(authGroup, SWT.RADIO);
+ authButtons[LOGIN_TYPE.SAT.id].setText("Direkte Verbindung zum Satelliten");
+ gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ authButtons[LOGIN_TYPE.SAT.id].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);
+
+ idpText = new Label(loginGroup, SWT.NONE);
+ idpText.setText("IdP:");
+
+ 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));
+
+ 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));
+ // login button
+ loginButton = new Button(loginGroup, SWT.PUSH);
+ loginButton.setText("Login");
+ saveUsernameCheck = new Button(loginGroup, SWT.CHECK);
+ saveUsernameCheck.setText("Benutzername speichern");
+
+ }
+
+ private void loadImage() {
+ try {
+ // 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);
+ titleImage = new Image(GuiManager.getDisplay(), imgData);
+ } catch (Exception e) {
+ System.out.println("Cannot load image");
+ System.out.println(e.getMessage());
+ }
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainWindowLayout.java
new file mode 100644
index 00000000..ef4e2676
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainWindowLayout.java
@@ -0,0 +1,95 @@
+package org.openslx.dozmod.gui.window.layout;
+
+
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+/*
+ * Structure/workflow should be:
+ *
+ * 1) App starts with Login Window for now [1]
+ *
+ * 2) After login, the main window opens.
+ * 2a) If the disclaimer has not been accepted yet, the main window will open it as a modal window
+ * 2b) Maybe do the same with the "you need vmware" window afterwards, or just show a hint in mainwindow
+ * that would open the vmware info window when clicked.
+ * The disclaimer and vmware info should still be reachable via the menu at any time
+ *
+ * - Clicking vm list or lecture list would show the according list in the same window
+ * - adding/editing lecture/image will open a wizard
+ * - doubleclicking a lecture/image will open a detailed info window
+ *
+ *
+ * GuiManager's add/remove content needs refactoring or needs to be moved, as it's
+ * designed like we only have one main window with changing content, but we
+ * actually have lots of independent windows and wizards.
+ *
+ * (TODO: Make sure it doesn't suck on multiscreen setups)
+ *
+ * [1] Later on we might support a "stay logged in" feature that
+ * will skip the login screen
+ */
+
+public abstract class MainWindowLayout extends Composite {
+ // text for info for the vms selection
+ protected String vmInfo = "Infotext VMs.";
+
+ // text for the info for the lecture selection
+ protected String lecturesInfo = "Infotext Veranstaltungen.";
+
+ // buttons
+ protected Button vmButton;
+ protected Button lecturesButton;
+
+ public MainWindowLayout(final Shell mainShell) {
+ super(mainShell, SWT.NONE);
+
+ this.setLayout(new GridLayout(2, true));
+
+ // group for the vm selection
+ Group vmGroup = new Group(this, SWT.NONE);
+ vmGroup.setLayout(new GridLayout());
+ vmGroup.setText("VMs");
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ vmGroup.setLayoutData(gridData);
+
+ vmButton = new Button(vmGroup, SWT.PUSH);
+ vmButton.setText("VM - Übersicht");
+ gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
+ vmButton.setLayoutData(gridData);
+
+
+ Label vmInfoLabel = new Label(vmGroup, SWT.NONE);
+ vmInfoLabel.setText(vmInfo);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ vmInfoLabel.setLayoutData(gridData);
+
+
+ //g group for the lecture selection
+ Group lecturesGroup = new Group(this, SWT.NONE);
+ lecturesGroup.setLayout(new GridLayout());
+ lecturesGroup.setText("Veranstaltungen");
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ lecturesGroup.setLayoutData(gridData);
+
+
+
+ lecturesButton = new Button(lecturesGroup, SWT.PUSH);
+ lecturesButton.setText("Veranstanstaltungen");
+ gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
+ lecturesButton.setLayoutData(gridData);
+
+ Label lecturesInfoLabel = new Label(lecturesGroup, SWT.NONE);
+ lecturesInfoLabel.setText(lecturesInfo);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ lecturesInfoLabel.setLayoutData(gridData);
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
new file mode 100644
index 00000000..bec2dc44
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
@@ -0,0 +1,82 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.openslx.dozmod.gui.helper.GuiManager;
+
+public abstract class VirtualizerNoticeWindowLayout extends Composite {
+ private final String title = "Hinweis VMWare Player";
+ private final String infoText = "Für die Arbeit mit der bwLehrpool Suite wird zwingend ein VMWare Player benötigt. "
+ + "Diesen können Sie sich unter folgendem Link kostenfrei downloaden. "
+ + "Wenn Sie bereits den VMWare Player oder die VMWare Workstation installiert haben, können Sie diesen Hinweis ignorieren.";
+
+ private final String infoTitle = "bwLehrpool Suite";
+
+ protected Button windowsDLButton;
+ protected Button linuxDLButton;
+ protected Button readCheck;
+ protected Button continueButton;
+
+ public VirtualizerNoticeWindowLayout(final Shell mainShell) {
+ super(mainShell, SWT.NONE);
+
+ // set the title of the bar.
+ mainShell.setText(title);
+
+ // layout for this composite
+ this.setLayout(new GridLayout(1, false));
+
+ // bold title at start.
+ Label titleLabel = new Label(this, SWT.NONE);
+ titleLabel.setText(infoTitle);
+ FontData fontData = titleLabel.getFont().getFontData()[0];
+ Font font = new Font(GuiManager.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(),
+ SWT.BOLD));
+ titleLabel.setFont(font);
+ // TODO dispose of font?
+
+ // infotext
+ Label infoLabel = new Label(this, SWT.NONE | SWT.WRAP);
+ infoLabel.setText(infoText);
+ GridData gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
+ infoLabel.setLayoutData(gridData);
+
+ // composite for the windows vmware-download button
+ Composite windowsComposite = new Composite(this, SWT.NONE);
+ windowsComposite.setLayout(new GridLayout());
+ gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
+ windowsComposite.setLayoutData(gridData);
+
+ new Label(windowsComposite, SWT.NONE).setText("Windows:");
+ windowsDLButton = new Button(windowsComposite, SWT.PUSH);
+ windowsDLButton.setText("VMWare Player Herunterladen");
+
+ // composite for the linux vmware-download button
+ Composite linuxComposite = new Composite(this, SWT.NONE);
+ linuxComposite.setLayout(new GridLayout());
+ gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
+ linuxComposite.setLayoutData(gridData);
+
+ new Label(windowsComposite, SWT.NONE).setText("Linux:");
+ linuxDLButton = new Button(windowsComposite, SWT.PUSH);
+ linuxDLButton.setText("VMWare Player Herunterladen");
+
+ readCheck = new Button(this, SWT.CHECK);
+ readCheck.setText("Diese Benachrichtigung nicht mehr anzeigen.");
+ gridData = new GridData(GridData.BEGINNING, GridData.END, false, false);
+ readCheck.setLayoutData(gridData);
+
+ continueButton = new Button(this, SWT.PUSH);
+ continueButton.setText("Weiter");
+ gridData = new GridData(GridData.BEGINNING, GridData.END, false, false);
+ continueButton.setLayoutData(gridData);
+
+ }
+} \ No newline at end of file
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java
new file mode 100644
index 00000000..1cac417e
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/ImageWizard.java
@@ -0,0 +1,48 @@
+package org.openslx.dozmod.gui.wizard;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.openslx.dozmod.gui.wizard.page.ImageMetaDataPage;
+import org.openslx.dozmod.gui.wizard.page.ImageUploadPage;
+
+public class ImageWizard extends Wizard{
+
+ protected ImageUploadPage imageUploadPage;
+ protected ImageMetaDataPage imageMetaDataPage;
+ protected boolean editExistingImage;
+
+
+
+
+ /**
+ * Wizard for creating or editing an image
+ * @param editExistingImage wether to create new or edit existing image
+ */
+ public ImageWizard(boolean editExistingImage) {
+ super();
+ setNeedsProgressMonitor(true);
+ this.editExistingImage = editExistingImage;
+ }
+
+
+ @Override
+ public String getWindowTitle() {
+ return "Neues Image erzeugen";
+ }
+
+ @Override
+ public void addPages() {
+ imageUploadPage = new ImageUploadPage(editExistingImage);
+ imageMetaDataPage = new ImageMetaDataPage();
+ addPage(imageUploadPage);
+ addPage(imageMetaDataPage);
+ }
+
+
+ @Override
+ public boolean performFinish() {
+ // Print the result to the console
+ System.out.println(imageUploadPage.getText1());
+ System.out.println(imageMetaDataPage.getImageDescription());
+ return true;
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
new file mode 100644
index 00000000..3c27407d
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageMetaDataPageLayout.java
@@ -0,0 +1,93 @@
+package org.openslx.dozmod.gui.wizard.layout;
+
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+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.Text;
+
+
+
+public abstract class ImageMetaDataPageLayout extends WizardPage {
+
+ protected Composite container;
+
+ protected Combo osCombo;
+ protected Text descriptionText;
+ protected Button licencedSoftwareCheck;
+
+ // permissions checks
+ protected Button readPermissionsCheck;
+ protected Button writePermissionsCheck;
+ protected Button linkPermissionsCheck;
+ protected Button adminPermissionsCheck;
+
+
+
+ /**
+ * wizard page for entering image data at creating or editing an image
+ */
+ public ImageMetaDataPageLayout() {
+ super("Eingabe Ihrer Daten", "Eingabe Ihrer Daten", null);
+ setDescription("Geben Sie bitte einen aussagekräftigen Namen für das neue Image ein.");
+ }
+
+
+
+ @Override
+ public void createControl(Composite parent) {
+ container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
+
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+
+
+
+ Label osCaption = new Label(container, SWT.NONE);
+ osCaption.setText("Betriebssystem:");
+ osCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
+
+ Label descriptionCation = new Label(container, SWT.NONE);
+ descriptionCation.setText("Beschreibung:");
+ descriptionText = new Text(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.heightHint = 80;
+ descriptionText.setLayoutData(gd);
+
+ Label licencedSoftwareCaption = new Label(container, SWT.NONE);
+ licencedSoftwareCaption.setText("Image enthält lizenzpflichtige Software");
+ licencedSoftwareCheck = new Button(container, SWT.CHECK);
+
+ Group permissionsGroup = new Group(container, SWT.BORDER);
+ gd = new GridData();
+ gd.horizontalSpan = 2;
+ permissionsGroup.setLayoutData(gd);
+
+
+ permissionsGroup.setText("Standardberechtigungen");
+ permissionsGroup.setLayout(new GridLayout(4, true));
+
+ readPermissionsCheck = new Button(permissionsGroup, SWT.CHECK);
+ readPermissionsCheck.setText("Lesen");
+ writePermissionsCheck = new Button(permissionsGroup, SWT.CHECK);
+ writePermissionsCheck.setText("Schreiben");
+ linkPermissionsCheck = new Button(permissionsGroup, SWT.CHECK);
+ linkPermissionsCheck.setText("Verlinken");
+ adminPermissionsCheck = new Button(permissionsGroup, SWT.CHECK);
+ adminPermissionsCheck.setText("Admin");
+ }
+
+
+ public String getImageDescription() {
+ return descriptionText.getText();
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadPageLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadPageLayout.java
new file mode 100644
index 00000000..4282f9dd
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/layout/ImageUploadPageLayout.java
@@ -0,0 +1,87 @@
+package org.openslx.dozmod.gui.wizard.layout;
+
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+
+
+public abstract class ImageUploadPageLayout extends WizardPage {
+
+ protected Text imageName;
+ protected Composite container;
+ protected boolean editExistingImage;
+ protected Button imageFileBrowseButton;
+
+
+
+ /**
+ * Page for uploading an imagefile
+ * @param editExistingImage wether to edit existing image file or create new one
+ */
+ public ImageUploadPageLayout(boolean editExistingImage) {
+ super("Eingabe Ihrer Daten");
+ setTitle("Eingabe Ihrer Daten");
+ setDescription("Geben Sie bitte einen aussagekräftigen Namen für das neue Image ein.");
+ this.editExistingImage = editExistingImage;
+ }
+
+
+
+ @Override
+ public void createControl(Composite parent) {
+ container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 2;
+ Label imageNameCaption= new Label(container, SWT.NONE);
+ imageNameCaption.setText("Name des Images");
+
+
+ imageName = new Text(container, SWT.BORDER | SWT.SINGLE);
+ imageName.setText("");
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ imageName.setLayoutData(gd);
+ imageName.setEnabled(!editExistingImage);
+ System.out.println(editExistingImage);
+
+ imageName.addKeyListener(new KeyListener() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (!imageName.getText().isEmpty()) {
+ setPageComplete(true);
+ } else {
+ setPageComplete(false);
+ }
+ }
+ });
+
+ Label imageFileCaption = new Label(container, SWT.NONE);
+ imageFileCaption.setText("Imagefile:");
+ imageFileBrowseButton = new Button(container, SWT.PUSH);
+ imageFileBrowseButton.setText("Browse");
+
+
+ // required to avoid an error in the system <-- TODO: WTF?
+ setControl(container);
+ setPageComplete(editExistingImage);
+ }
+
+
+ public String getText1() { // TODO: ????????????
+ return imageName.getText();
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
new file mode 100644
index 00000000..969a6c52
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageMetaDataPage.java
@@ -0,0 +1,7 @@
+package org.openslx.dozmod.gui.wizard.page;
+
+import org.openslx.dozmod.gui.wizard.layout.ImageMetaDataPageLayout;
+
+public class ImageMetaDataPage extends ImageMetaDataPageLayout {
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java
new file mode 100644
index 00000000..617e7efc
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadPage.java
@@ -0,0 +1,11 @@
+package org.openslx.dozmod.gui.wizard.page;
+
+import org.openslx.dozmod.gui.wizard.layout.ImageUploadPageLayout;
+
+public class ImageUploadPage extends ImageUploadPageLayout {
+
+ public ImageUploadPage(boolean editExistingImage) {
+ super(editExistingImage);
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/ACache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ACache.java
index 68e8433d..4b859f66 100644
--- a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/ACache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ACache.java
@@ -1,4 +1,4 @@
-package org.openslx.bwlp.dozmod.thrift;
+package org.openslx.dozmod.thrift;
import java.util.concurrent.atomic.AtomicReference;
diff --git a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/ImageCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageCache.java
index 2628807a..a2fac063 100644
--- a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/ImageCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageCache.java
@@ -1,12 +1,12 @@
-package org.openslx.bwlp.dozmod.thrift;
+package org.openslx.dozmod.thrift;
import java.util.List;
import org.apache.thrift.TException;
-import org.openslx.bwlp.dozmod.thrift.ACache.CacheMode;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
import org.openslx.bwlp.thrift.iface.TInternalServerError;
+import org.openslx.dozmod.thrift.ACache.CacheMode;
import org.openslx.thrifthelper.ThriftManager;
public class ImageCache {
diff --git a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/MetaDataCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java
index 726dfd3d..d7dbd972 100644
--- a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/MetaDataCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java
@@ -1,4 +1,4 @@
-package org.openslx.bwlp.dozmod.thrift;
+package org.openslx.dozmod.thrift;
import java.util.List;
diff --git a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/OrganizationCache.java
index 30a0cb3e..dde31d89 100644
--- a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/OrganizationCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/OrganizationCache.java
@@ -1,4 +1,4 @@
-package org.openslx.bwlp.dozmod.thrift;
+package org.openslx.dozmod.thrift;
import java.util.List;
diff --git a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/Session.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java
index 0cdce3fd..33612746 100644
--- a/dozentenmodul/src/main/java/org/openslx/bwlp/dozmod/thrift/Session.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java
@@ -1,8 +1,7 @@
-package org.openslx.bwlp.dozmod.thrift;
+package org.openslx.dozmod.thrift;
import org.openslx.bwlp.thrift.iface.ClientSessionData;
-
-import util.ServiceProviderResponse;
+import org.openslx.dozmod.authentication.ServiceProviderResponse;
public class Session {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/CheckIntegrity.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/CheckIntegrity.java
new file mode 100644
index 00000000..845c1734
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/CheckIntegrity.java
@@ -0,0 +1,121 @@
+package org.openslx.dozmod.util;
+
+public class CheckIntegrity {
+
+ // private static boolean isFine = false;
+
+ // integrity check on permissions put by user for an image
+ public static boolean[] isIntegreForImage(boolean isRead, boolean isWrite,
+ boolean isLink, boolean isAdmin) {
+
+ // boolean array for the correct result values
+ boolean[] rights = new boolean[4];
+ rights[0] = isRead;
+ rights[1] = isWrite;
+ rights[2] = isLink;
+ rights[3] = isAdmin;
+
+ System.out.println("*****************************");
+ System.out.println(isRead + " " + isWrite + " " + isLink + " "
+ + isAdmin);
+
+ if (isRead) // if read is allowed, only read is allowed
+ {
+ rights[0] = true; // read allowed
+ } else // if read is not allowed, nothing is allowed
+ {
+ rights[0] = false;
+ rights[1] = false;
+ rights[2] = false;
+ rights[3] = false;
+ }
+
+ if (isWrite) // if write was selected
+ {
+ rights[0] = true;
+ rights[1] = true;
+ } else // if write was unselected
+ {
+ // rights[0] = false;
+ rights[1] = false;
+ }
+
+ if (isLink) // if link was selected, read and link are allowed
+ {
+ rights[0] = true;
+ rights[2] = true;
+ } else // if link is unselected, link is not allowed
+ {
+ rights[2] = false;
+ }
+
+ if (isAdmin) // if admin is selected, anything is allowed
+ {
+ rights[0] = true;
+ rights[1] = true;
+ rights[2] = true;
+ rights[3] = true;
+ } else // if admin is unselected, admin is not allowed
+ {
+ rights[3] = false;
+ }
+
+ System.out.println(">-------------<");
+ System.out.println(rights[0] + " " + rights[1] + " " + rights[2] + " "
+ + rights[3]);
+
+ return rights;
+
+ }// end isIntegreForImage()
+
+
+ // integrity check on permissions put by user for a lecture
+ public static boolean[] isIntegreForLecture(boolean isRead, boolean isWrite, boolean isAdmin) {
+
+ // boolean array for the correct result values
+ boolean[] rights = new boolean[4];
+ rights[0] = isRead;
+ rights[1] = isWrite;
+ rights[2] = isAdmin;
+
+ System.out.println("*****************************");
+ System.out.println(isRead + " " + isWrite + " " + isAdmin);
+
+ if (isRead) // if read is allowed, only read is allowed
+ {
+ rights[0] = true; // read allowed
+ } else // if read is not allowed, nothing is allowed
+ {
+ rights[0] = false;
+ rights[1] = false;
+ rights[2] = false;
+ }
+
+ if (isWrite) // if write was selected
+ {
+ rights[0] = true;
+ rights[1] = true;
+ } else // if write was unselected
+ {
+ // rights[0] = false;
+ rights[1] = false;
+ }
+
+ if (isAdmin) // if admin is selected, anything is allowed
+ {
+ rights[0] = true;
+ rights[1] = true;
+ rights[2] = true;
+ } else // if admin is unselected, admin is not allowed
+ {
+ rights[2] = false;
+ }
+
+ System.out.println(">-------------<");
+ System.out.println(rights[0] + " " + rights[1] + " " + rights[2]);
+
+ return rights;
+
+ }// end isIntegreForLecture()
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
new file mode 100644
index 00000000..d69b7746
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java
@@ -0,0 +1,35 @@
+package org.openslx.dozmod.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+public class FormatHelper {
+
+ private static final SimpleDateFormat in = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ private static final SimpleDateFormat out = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
+
+ /**
+ * Convert mysql date/time format to human readable (German) format.
+ * If the given date is not parsable, "<invalid>" will be returned.
+ *
+ * @param dateTime yyyy-MM-dd HH:mm:ss
+ * @return dd.MM.yy HH:mm
+ */
+ public static String mysqlDateToGerman(String dateTime) {
+ try {
+ return out.format(in.parse(dateTime));
+ } catch (ParseException e) {
+ return "<invalid>";
+ }
+ }
+
+ public static String byteToGigabyte(long bytes, boolean si) {
+ int unit = si ? 1000 : 1024;
+ if (bytes < unit)
+ return bytes + " B";
+ int exp = (int) (Math.log(bytes) / Math.log(unit));
+ String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
+ return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java
new file mode 100644
index 00000000..acedba09
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/News.java
@@ -0,0 +1,236 @@
+package org.openslx.dozmod.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.sql.Date;
+
+import javax.swing.JOptionPane;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.openslx.bwlp.thrift.iface.SessionData;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Class representing the news given by the satellite
+ * Makes use of the News-API of the webservice slx-admin:
+ * http://satellite.ip/slx-admin/api.php?do=news
+ *
+ * Access the data through the public getters:
+ * String newsHeadline = News.getHeadline();
+ * String newsContent = News.getContent();
+ * Date newsLatestDate = News.getDate();
+ */
+
+public class News {
+
+ // Logger instance for this class
+ private final static Logger LOGGER = Logger.getLogger(News.class);
+
+ // Private members representing the news
+ private static String headline = null;
+ private static String content = null;
+ private static Date date = null;
+
+ /**
+ * Gets the headline as String.
+ *
+ * @return String Contains the headline text.
+ */
+ public static String getHeadline() {
+ if (headline != null)
+ return headline;
+ else {
+ init();
+ // check if it is still null
+ if (headline != null)
+ return headline;
+ else
+ return null;
+ }
+ }
+
+ /**
+ * Gets the content as String.
+ *
+ * @return String Contains the content text.
+ */
+ public static String getContent() {
+ if (content != null)
+ return content;
+ else {
+ init();
+ if (content != null)
+ return content;
+ else
+ return null;
+ }
+ }
+
+ /**
+ * Gets the date of the latest news as Date.
+ *
+ * @return Date Represent last modification date.
+ */
+ public static Date getDate() {
+ if (date != null)
+ return date;
+ else {
+ init();
+ if (date != null)
+ return date;
+ else
+ return null;
+ }
+ }
+
+ /**
+ * Private 'init' function doing the main work.
+ * It is called by getters if their object is null.
+ * Follows these steps:
+ * - Opens URL as stream
+ * - Parse stream as (XML-)Document
+ * - Check validity of the news format:
+ * <news>
+ * <headline>...</headline>
+ * <content>...</content>
+ * <date>...</date>
+ * </news>
+ *
+ * - Sets private members
+ */
+
+ private static void init(){
+ // Document representing the XML
+ Document doc = null;
+ String satIp = SessionData._Fields.SERVER_ADDRESS.toString();
+ // sanity check to see if we have the satellite IP
+ if (satIp == null || satIp.isEmpty()) {
+ LOGGER.error("No satellite IP adress is set in SessionData, aborting news fetching...");
+ return;
+ }
+
+ // URL to news API
+ URL url = null;
+ try {
+ url = new URL("http://" + SessionData._Fields.SERVER_ADDRESS.toString() + "/slx-admin/api.php?do=news");
+ } catch (MalformedURLException e) {
+ LOGGER.error("Malformated URL to News-API, see trace: ", e);
+ }
+
+ // check is the url got created.
+ if (url == null) {
+ // no URL, log it and return
+ LOGGER.error("URL to the News-API not defined!");
+ return;
+ }
+
+ // set timeout for URLConnection
+ URLConnection urlCon = null;
+ try {
+ urlCon = url.openConnection();
+ // 5 seconds timeout for connection
+ urlCon.setConnectTimeout(5000);
+ // 10 seconds timeout for reading the stream
+ urlCon.setReadTimeout(10000);
+ } catch (IOException e) {
+ LOGGER.error("IO error while requesting News URL, see trace: ", e);
+ return;
+ }
+
+ InputStream is = null;
+ try {
+ is = urlCon.getInputStream();
+ } catch (IOException e1) {
+ LOGGER.error("Could not open stream to URL '" + url.toString() + "', see trace: ", e1);
+ return;
+ }
+
+ // use java's DocumentBuilder engine to parse the XML
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = null;
+
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ LOGGER.error("XML parsing configuration error, see trace: ", e);
+ return;
+ }
+
+ // try the parsing
+ try {
+ doc = builder.parse(is);
+ } catch (SAXException e) {
+ LOGGER.error("XML parsing error, see trace: ", e);
+ return;
+ } catch (IOException e) {
+ LOGGER.error("IO-Error, see trace: ", e);
+ return;
+ }
+
+ // now that we have parsed the XML, check if it is valid
+ Element docRoot = doc.getDocumentElement();
+
+ // first element has to be name "news"
+ if (docRoot.getNodeName().equals("news")) {
+ Node headlineNode = null;
+ Node contentNode = null;
+ Node dateNode = null;
+
+ // get list of every child
+ NodeList nList = docRoot.getElementsByTagName("*");
+
+ // fail if the list is empty
+ if (nList == null) return;
+
+ // now we go through the list looking for our elements
+ // TODO: get definition of tags externally/through static api?
+ for (int i = 0; i < nList.getLength(); i++) {
+ Node current = nList.item(i);
+ if (current.getNodeType() == Node.ELEMENT_NODE) {
+ if (current.getNodeName().equals("headline") &&
+ current.getFirstChild().getNodeType() == Node.TEXT_NODE) headlineNode = current.getFirstChild();
+ // FIXME: temporary workaround for possibly different slx-admin versions!
+ if ((current.getNodeName().equals("info") || current.getNodeName().equals("content")) &&
+ current.getFirstChild().getNodeType() == Node.TEXT_NODE) contentNode = current.getFirstChild();
+ if (current.getNodeName().equals("date") &&
+ current.getFirstChild().getNodeType() == Node.TEXT_NODE) dateNode = current.getFirstChild();
+ }
+ }
+
+ // set what the elements we found
+ if (headlineNode != null) headline = headlineNode.getNodeValue().trim();
+ if (contentNode != null) content = contentNode.getNodeValue().trim();
+ if (dateNode != null) {
+ // for the date we need a bit more stuff
+ Date tmpDate = null;
+ try {
+ tmpDate = new Date(Long.parseLong(dateNode.getNodeValue().trim()) * 1000);
+ } catch (NumberFormatException nfe) {
+ LOGGER.error("Date format is invalid, see trace: ", nfe);
+ JOptionPane.showMessageDialog(null,
+ "Zeitstempel aus der XML is invalid!",
+ "Fehler", JOptionPane.ERROR_MESSAGE);
+ // TODO: set current date.
+ }
+ // Date creation worked, save it
+ if (tmpDate != null) date = tmpDate;
+ }
+ } else {
+ JOptionPane.showMessageDialog(null,
+ "Invalides XML! Kein 'news' Wurzelelement. News wird leer gelassen.",
+ "Fehler", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java
new file mode 100644
index 00000000..224ad865
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java
@@ -0,0 +1,82 @@
+package org.openslx.dozmod.util;
+
+import java.awt.Desktop;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.JOptionPane;
+
+import org.apache.log4j.Logger;
+
+public class OpenLinks {
+
+ /**
+ * Logger instance for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(OpenLinks.class);
+
+ /**
+ * Map containing the links
+ */
+ @SuppressWarnings("serial")
+ private static Map<String, String> links = Collections.unmodifiableMap(new HashMap<String, String>(){{
+ put("faq", "http://bwlehrpool.hs-offenburg.de");
+ put("otrs", "http://bwlehrpool.hs-offenburg.de");
+ put("vmware", "https://my.vmware.com/de/web/vmware/free#desktop_end_user_computing/vmware_player/6_0");
+ put("intro", "http://www.hs-offenburg.de/fileadmin/Einrichtungen/hrz/Projekte/bwLehrpool/3_bwLehrpool_-_Image_einbinden_und_starten.pdf");
+ // TODO use enum not map
+ }});
+
+ /**
+ * Static URIs
+ */
+
+ private static Map<String, URI> uris;
+ static {
+ // temp map
+ Map<String, URI> tmpUris = new HashMap<String, URI>();
+ for (String key : links.keySet()) {
+ URI tmp;
+ try {
+ tmp = new URI(links.get(key));
+ } catch (URISyntaxException e) {
+ // should never happen!
+ LOGGER.error("Bad URI syntax of '" + key + "', see trace: ", e);
+ tmp = null;
+ }
+ tmpUris.put(key, tmp);
+ }
+ // check sizes of maps to be equal
+ if (links.size() != tmpUris.size()) {
+ LOGGER.error("Links and URIs have different sizes, this should not happen. Contact a developper.");
+ }
+
+ // all good, save it to the actual 'uris' map
+ uris = Collections.unmodifiableMap(tmpUris);
+ }
+
+
+ public static void openWebpage(String key) {
+ // first check if we have the link for the request key
+ if (!uris.containsKey(key)) {
+ LOGGER.error("OpenLinks has to link to '" + key + "'. Check if the given key actually exists.");
+ return;
+ }
+ Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop()
+ : null;
+ if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
+ try {
+ desktop.browse(uris.get(key));
+ } catch (Exception e) {
+ e.printStackTrace();
+ JOptionPane.showMessageDialog(null,
+ e.getCause() + "\n" + e.getStackTrace(),
+ "Debug-Message", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }// end openWebpage
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java
new file mode 100644
index 00000000..7ece2088
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ProxyConfigurator.java
@@ -0,0 +1,84 @@
+package org.openslx.dozmod.util;
+
+import java.io.IOException;
+import java.net.ProxySelector;
+import java.text.MessageFormat;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+import com.btr.proxy.search.ProxySearch;
+import com.btr.proxy.search.wpad.WpadProxySearchStrategy;
+import com.btr.proxy.util.ProxyException;
+import com.btr.proxy.util.Logger.LogBackEnd;
+import com.btr.proxy.util.Logger.LogLevel;
+
+/**
+ * Configures the proxy
+ *
+ * @author Jonathan Bauer
+ */
+
+public class ProxyConfigurator {
+
+ /**
+ * Logger for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(ProxyConfigurator.class);
+
+ /**
+ * Initialization method.
+ */
+ public static void init() throws IOException {
+ // first setup the logger of proxy_vole
+ com.btr.proxy.util.Logger.setBackend(new LogBackEnd() {
+
+ @SuppressWarnings("deprecation")
+ public void log(Class<?> clazz, LogLevel loglevel, String msg,
+ Object... params) {
+ Priority priority;
+ switch (loglevel) {
+ case ERROR:
+ priority = Level.ERROR;
+ break;
+ case WARNING:
+ priority = Priority.WARN;
+ break;
+ case INFO:
+ priority = Priority.INFO;
+ break;
+ default:
+ priority = Priority.DEBUG;
+ }
+ Logger.getLogger(clazz).log(priority, MessageFormat.format(msg, params));
+ }
+
+ public boolean isLogginEnabled(LogLevel logLevel) {
+ return true;
+ }
+ });
+
+ // try to find local proxy settings
+ ProxySearch proxySearch = ProxySearch.getDefaultProxySearch();
+ ProxySelector myProxySelector = proxySearch.getProxySelector();
+
+ if (myProxySelector == null) {
+ // didn't work, try WPAD detection
+ LOGGER.error("No suitable proxy settings found, trying WPAD...");
+ WpadProxySearchStrategy ss = new WpadProxySearchStrategy();
+ try {
+ myProxySelector = ss.getProxySelector();
+ } catch (ProxyException e) {
+ LOGGER.error("WPAD proxy error, see trace: ", e);
+ }
+ }
+ // final check to see if WPAD actually worked
+ if (myProxySelector != null) {
+ LOGGER.debug("Proxy initialised.");
+ ProxySelector.setDefault(myProxySelector);
+ } else {
+ LOGGER.error("Could not find a suitable proxy!");
+ }
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
new file mode 100644
index 00000000..89b7e6ba
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
@@ -0,0 +1,95 @@
+package org.openslx.dozmod.util;
+
+import java.awt.Graphics2D;
+import java.awt.SystemColor;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Text;
+import org.openslx.dozmod.gui.helper.GuiManager;
+
+/**
+ * Helper class for loading resources. This should be error safe loaders with a
+ * fall back in case the requested resource can't be found, or isn't of the
+ * expected type.
+ */
+public class ResourceLoader {
+
+ /**
+ * Logger for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(ResourceLoader.class);
+
+ public static ImageData getImageData(String path) {
+
+ ImageData _imgData = null;
+ URL _url = ResourceLoader.class.getResource(path);
+ if (_url == null) {
+ LOGGER.error("Resource not found: " + path);
+ return errorIcon("nope").getImageData();
+ } else {
+ try {
+ _imgData = new ImageData(_url.openStream());
+ } catch (Exception e) {
+ LOGGER.error("Resource not loadable: " + path + ". See trace: ", e);
+ return errorIcon("nope").getImageData();
+ }
+ return _imgData;
+ }
+ }
+
+ /**
+ * Helper that will create an icon with given text.
+ * @param errorText Text to render to icon
+ * @return the icon
+ */
+ private static Image errorIcon(String errorText) {
+ GC gc = new GC(GuiManager.getDisplay());
+ Font font = new Font(GuiManager.getDisplay(), "Tahoma", 20, SWT.NORMAL);
+ gc.setFont(font);
+ // get dimensions of text
+ Image image = new Image(GuiManager.getDisplay(), gc.stringExtent(errorText).x, gc.stringExtent(errorText).y);
+ GC gc2 = new GC(image);
+ gc2.setBackground(GuiManager.getDisplay().getSystemColor(SWT.COLOR_CYAN));
+ gc2.drawText(errorText, 0, 0);
+ gc2.dispose();
+ return image;
+ }
+
+ /**
+ * Tries to load the given resource treating it as a text file
+ *
+ * @param path
+ * Resource path to load
+ * @return content of the loaded resource as String
+ */
+ public static String getTextFile(String path) {
+ String fileContent = null;
+ try {
+ fileContent = IOUtils.toString(ResourceLoader.class
+ .getResourceAsStream(path));
+ } catch (Exception e) {
+ LOGGER.error("IO error while trying to load resource '" + path
+ + "'. See trace: ", e);
+ }
+
+ if (fileContent != null) {
+ return fileContent;
+ } else {
+ return "Resource '" + path + "' not found.";
+ }
+ }
+}