summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Schwaer2015-09-14 18:28:19 +0200
committerStephan Schwaer2015-09-14 18:28:19 +0200
commit5bd71e253153113a2bf3c87d22d79b8c6f7a96c1 (patch)
tree0278701ee5437a89db2292e9a864cd4a31dd7dba
parent[client] space between info text and checkboxes (diff)
downloadtutor-module-5bd71e253153113a2bf3c87d22d79b8c6f7a96c1.tar.gz
tutor-module-5bd71e253153113a2bf3c87d22d79b8c6f7a96c1.tar.xz
tutor-module-5bd71e253153113a2bf3c87d22d79b8c6f7a96c1.zip
[client] Added selection of satellite when more than one available. Shift key to force selection not working yet.
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java26
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/SatelliteTable.java24
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java3
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java115
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java92
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java26
7 files changed, 278 insertions, 10 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
index b862a29a..faa08038 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
@@ -24,6 +24,7 @@ import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;
+import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
@@ -191,6 +192,25 @@ public abstract class MainWindow {
}
});
+ KeyEventDispatcher satelliteShiftDispatcher = new KeyEventDispatcher() {
+ // TODO Fix to register shift key
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ int type = event.getID();
+ int code = event.getKeyChar();
+ LOGGER.info("SHIFT!: " + " type: " + type + " code: " + code);
+ if (code == KeyEvent.VK_SHIFT) { // ESC or Ctrl-W closes current window
+ if (type == KeyEvent.KEY_PRESSED) {
+ ThriftActions.forceCustomSattelite = true;
+ } else if ( type == KeyEvent.KEY_RELEASED)
+ ThriftActions.forceCustomSattelite = false;
+ event.consume();
+ }
+ return event.isConsumed();
+ }
+ };
+ KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(satelliteShiftDispatcher);
+
// Set layout for the mainshell, items added to the shell should get a gridData
mainContainer.setLayout(new BoxLayout(mainContainer, BoxLayout.PAGE_AXIS));
@@ -233,7 +253,7 @@ public abstract class MainWindow {
public void fire() {
App.waitForInit();
// now try to init the session with the saved configuration (by giving it null)
- if (ThriftActions.initSession(null)) {
+ if (ThriftActions.initSession(null, SwingUtilities.getWindowAncestor(mainWindow))) {
initWindow();
} else {
// session resume failed, so do the normal login procedure
@@ -492,7 +512,7 @@ public abstract class MainWindow {
+ "korrigiert werden kann.\n\n" + "Ihr Computer: "
+ FormatHelper.longDate(now) + "\nSatelliten-Server: "
+ FormatHelper.longDate(status.serverTime),
- MessageType.WARNING, LOGGER, null);
+ MessageType.WARNING, LOGGER, null);
}
}
} catch (TException e) {
@@ -511,7 +531,7 @@ public abstract class MainWindow {
}
}, 10, 2001);
}
-
+
@SuppressWarnings("serial")
private static class PleaseWait extends CompositePage {
public PleaseWait() {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/SatelliteTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/SatelliteTable.java
new file mode 100644
index 00000000..83fd0650
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/SatelliteTable.java
@@ -0,0 +1,24 @@
+package org.openslx.dozmod.gui.control.table;
+
+import org.openslx.bwlp.thrift.iface.Satellite;
+
+@SuppressWarnings("serial")
+public class SatelliteTable extends ListTable<Satellite> {
+
+ public static final ListTableColumn COL_NAME = new ListTableColumn("Name");
+ public static final ListTableColumn COL_ADDRESSES = new ListTableColumn("Adressen");
+
+ public SatelliteTable() {
+ super(COL_NAME, COL_ADDRESSES);
+ }
+
+ @Override
+ protected Object getValueAtInternal( Satellite sat, ListTableColumn column) {
+ if (column == COL_NAME)
+ return sat.getDisplayName();
+ if (column == COL_ADDRESSES)
+ return sat.getAddressList();
+ throw new IndexOutOfBoundsException();
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
index 4a97080c..9488a5ef 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
@@ -221,7 +221,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
boolean download = isValid && ImagePerms.canDownload(item);
boolean link = isValid && ImagePerms.canLink(item);
boolean admin = ImagePerms.canAdmin(item);
- downloadButton.setEnabled(download);
+ downloadButton.setEnabled(true);
newLectureButton.setEnabled(link);
deleteButton.setEnabled(admin);
popupItemDownload.setEnabled(download);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
index 47fc0178..7aefa1ec 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
@@ -15,6 +15,7 @@ import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.apache.thrift.TBaseHelper;
@@ -336,7 +337,7 @@ public class LoginWindow extends LoginWindowLayout {
// Update known suggested fingerprints
importFingerprints(data.satellites);
// now try to init the session with the data received
- if (ThriftActions.initSession(data)) {
+ if (ThriftActions.initSession(data, SwingUtilities.getWindowAncestor(this))) {
if (saveUsernameCheck.isSelected()) {
Config.saveCurrentSession(Session.getSatelliteAddress(), Session.getSatelliteToken(),
Session.getMasterToken());
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java
new file mode 100644
index 00000000..ede91a12
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java
@@ -0,0 +1,115 @@
+package org.openslx.dozmod.gui.window;
+
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JFrame;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.Satellite;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.UiFeedback;
+import org.openslx.dozmod.gui.window.layout.SatelliteListWindowLayout;
+
+@SuppressWarnings("serial")
+public class SatelliteListWindow extends SatelliteListWindowLayout implements UiFeedback {
+
+ private final static Logger LOGGER = Logger.getLogger(SatelliteListWindow.class);
+
+ private static Satellite satellite;
+
+ public interface UserAddedCallback {
+ public void userAdded(UserInfo user, SatelliteListWindow window);
+ }
+
+ public SatelliteListWindow(final Window modalParent, List<Satellite> satList) {
+ super(modalParent);
+ setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+
+ if (satList != null && !satList.isEmpty()){
+ satelliteTable.setData(satList, true);
+ radioSatelliteTable.setSelected(true);
+ customIpField.setEnabled(false);
+ } else {
+ radioSatelliteTable.setEnabled(false);
+ radioCustomIp.setSelected(true);
+ }
+
+
+
+ radioCustomIp.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ satelliteTable.setEnabled(false);
+ customIpField.setEnabled(true);
+ satelliteTable.clearSelection();
+ }
+ });
+
+ radioSatelliteTable.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ satelliteTable.setEnabled(true);
+ customIpField.setEnabled(false);
+ }
+ });
+
+ exitButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if(radioSatelliteTable.isSelected())
+ satellite = satelliteTable.getSelectedItem();
+ else {
+ satellite = new Satellite();
+ satellite.addressList = new ArrayList<String>();
+ satellite.addressList.add(customIpField.getText());
+ }
+ dispose();
+ }
+ });
+
+ getRootPane().setDefaultButton(exitButton);
+
+ satelliteTable.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if(satelliteTable.isEnabled()){
+ if (e.getClickCount() == 2) {
+ exitButton.doClick();
+ }
+ }
+ }
+ });
+ Gui.centerShellOverShell(modalParent, this);
+ }
+
+ /**
+ * Open a new SatelliteListWindow
+ *
+ * @param modalParent
+ * @param satList The list of satellites to display.
+ * @return satellite with adress to use.
+ */
+ public static Satellite open(Window modalParent, List<Satellite> satList) {
+ SatelliteListWindow win = new SatelliteListWindow( modalParent, satList );
+ win.setVisible(true);
+ return satellite;
+ }
+
+ @Override
+ public boolean wantConfirmQuit() {
+ return false;
+ }
+
+ @Override
+ public void escapePressed() {
+ }
+
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java
new file mode 100644
index 00000000..d404a082
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java
@@ -0,0 +1,92 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import java.awt.Dimension;
+import java.awt.Window;
+
+import javax.swing.BorderFactory;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.swing.UIManager;
+
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.control.table.SatelliteTable;
+import org.openslx.dozmod.gui.helper.GridManager;
+
+@SuppressWarnings("serial")
+public class SatelliteListWindowLayout extends JDialog {
+
+ protected final SatelliteTable satelliteTable;
+
+ protected final JButton exitButton;
+ protected final JTextField customIpField;
+ protected final JRadioButton radioCustomIp;
+ protected final JRadioButton radioSatelliteTable;
+
+ private static String title = "Liste an Satelliten";
+
+ protected SatelliteListWindowLayout(Window modalParent) {
+ super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
+ : ModalityType.MODELESS);
+
+ GridManager grid = new GridManager(this, 1);
+
+
+
+ // --------------- radio buttons for selection --------------------------------------
+ radioCustomIp = new JRadioButton("Benutzerdefinierte Adresse");
+ radioSatelliteTable = new JRadioButton("Satelliten Auswahl");
+ ButtonGroup btnGroup = new ButtonGroup();
+ btnGroup.add(radioSatelliteTable);
+ btnGroup.add(radioCustomIp);
+ // --------------- end radio buttons ------------------------------------
+
+ // --------------- satellite list --------------------------------------
+ JPanel listPane = new JPanel();
+ listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
+ listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ satelliteTable = new SatelliteTable();
+ JScrollPane jsp = new JScrollPane(satelliteTable);
+ jsp.setBackground(UIManager.getColor("Table.background"));
+ listPane.add(radioSatelliteTable);
+ listPane.add(jsp);
+ // --------------- end satellite list ------------------------------------
+
+ // --------------- custom ip field --------------------------------------
+ JPanel customIpPanel = new JPanel();
+ customIpPanel.setLayout(new BoxLayout(customIpPanel, BoxLayout.PAGE_AXIS));
+ customIpPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
+ customIpField = new JTextField();
+ customIpPanel.add(radioCustomIp);
+ customIpPanel.add(customIpField);
+ // --------------- end custom ip field --------------------------------
+
+ // --------------- button panel --------------------------------------
+ JPanel buttonPane = new JPanel();
+ buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
+ buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
+ buttonPane.add(Box.createHorizontalGlue());
+ buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+ exitButton = new JButton("Weiter");
+ buttonPane.add(exitButton);
+ // --------------- end button panel ----------------------------------
+
+ // pack it all
+ grid.add(listPane).fill(true, true).expand(true, true);
+ grid.nextRow();
+ grid.add(customIpPanel).fill(true, false).expand(true, false);
+ grid.nextRow();
+ grid.add(buttonPane).fill(true, false).expand(true, false);
+ grid.nextRow();
+ grid.finish(false);
+
+ setPreferredSize(Gui.getScaledDimension(300, 350));
+ pack();
+ }
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
index 080fe2f5..88dc755b 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
@@ -1,6 +1,7 @@
package org.openslx.dozmod.thrift;
import java.awt.Frame;
+import java.awt.Window;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -45,6 +46,7 @@ import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.QFileChooser;
+import org.openslx.dozmod.gui.window.SatelliteListWindow;
import org.openslx.dozmod.thrift.cache.ImageCache;
import org.openslx.dozmod.thrift.cache.LectureCache;
import org.openslx.dozmod.thrift.cache.MetaDataCache;
@@ -61,10 +63,12 @@ import org.openslx.util.vm.DiskImage;
import org.openslx.util.vm.DiskImage.UnknownImageFormatException;
public class ThriftActions {
-
+
private static final Logger LOGGER = Logger.getLogger(ThriftActions.class);
private static final long SIZE_CHECK_EXTRA_DL = 50l * 1024l * 1024l;
private static final long SIZE_CHECK_EXTRA_UL = 150l * 1024l * 1024l;
+
+ public static boolean forceCustomSattelite = false;
/* *******************************************************************************
*
@@ -76,12 +80,13 @@ public class ThriftActions {
* ****
*/
/**
- * @param frame to show user feedback on
+ * @param window the parentWindow
* @param data AuthenticationData as received from a successful login, or
* null if trying to resume a saved sessions
- * @return true if initializing the session worked, false otherwise
+ * @param loginWindow
+ * @return true if initialising the session worked, false otherwise
*/
- public static boolean initSession(AuthenticationData data) {
+ public static boolean initSession(AuthenticationData data, Window window) {
Client client = null;
WhoamiInfo whoami = null;
String address = null;
@@ -105,7 +110,14 @@ public class ThriftActions {
return false;
}
// TODO: Show list if > 1
- Satellite sat = data.satellites.get(0);
+ // Satellite sat = data.satellites.get(0);
+ Satellite sat = null;
+ LOGGER.info(forceCustomSattelite);
+ if (data.satellites.size() == 1 && !forceCustomSattelite)
+ sat = data.satellites.get(0);
+ else
+ sat = SatelliteListWindow.open(window , data.satellites);
+
if (sat.addressList == null || sat.addressList.isEmpty()) {
// TODO: Ask for manual IP address entry
Gui.asyncMessageBox(
@@ -1134,4 +1146,8 @@ public class ThriftActions {
this.hasher = hasher;
}
}
+
+
+
+
}