summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-16 12:35:30 +0200
committerSimon Rettberg2015-09-16 12:35:30 +0200
commit30823441525a7137d98a47b18b2aca6e566cd818 (patch)
treeeaf78d6d96b950baad0403d17bbe50177777981d
parent[server] Support querying master->sat transfer status (diff)
downloadtutor-module-30823441525a7137d98a47b18b2aca6e566cd818.tar.gz
tutor-module-30823441525a7137d98a47b18b2aca6e566cd818.tar.xz
tutor-module-30823441525a7137d98a47b18b2aca6e566cd818.zip
[client] Clean up satellite selection window
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java73
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java50
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java18
3 files changed, 65 insertions, 76 deletions
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
index 3980f315..04d618b4 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java
@@ -5,26 +5,22 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map.Entry;
-import javax.swing.JFrame;
import javax.swing.JRadioButton;
-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;
/**
* Window for selecting an available satellite or setting custom ip.
*/
@SuppressWarnings("serial")
-public class SatelliteListWindow extends SatelliteListWindowLayout implements UiFeedback {
+public class SatelliteListWindow extends SatelliteListWindowLayout {
- private final static Logger LOGGER = Logger.getLogger(SatelliteListWindow.class);
-
- private static Satellite satellite;
+ private Satellite satellite = null;
public interface UserAddedCallback {
public void userAdded(UserInfo user, SatelliteListWindow window);
@@ -35,48 +31,42 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui
*/
public SatelliteListWindow(final Window modalParent, List<Satellite> satList) {
super(modalParent, satList);
- setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-
// Check, whether we have any satellites
if (satList != null && !satList.isEmpty()){
- satelliteButtons[0].setSelected(true);
+ radioToSat.keySet().iterator().next().setSelected(true);
customIpField.setEnabled(false);
} else {
radioCustomIp.setSelected(true);
}
// deactivate the custom field when selecting a satellite to make things clearer for user
- for ( int i = 0; i < satCount; i++ ){
- satelliteButtons[i].addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- customIpField.setEnabled(false);
- }
- });
- }
-
- radioCustomIp.addActionListener(new ActionListener() {
+ ActionListener listener = new ActionListener() {
@Override
- public void actionPerformed(ActionEvent arg0) {
- customIpField.setEnabled(true);
+ public void actionPerformed(ActionEvent e) {
+ customIpField.setEnabled(radioCustomIp.isSelected());
}
- });
+ };
+ for ( JRadioButton radio : radioToSat.keySet() ){
+ radio.addActionListener(listener);
+ }
+ radioCustomIp.addActionListener(listener);
- exitButton.addActionListener(new ActionListener() {
+ // Continue button
+ nextButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// satellite is selected
if(!radioCustomIp.isSelected()){
// check, which satellite is selected
- for (JRadioButton button : satelliteButtons) {
- if(button.isSelected()){
- // return it.
- satellite = radioToSat.get(button);
+ for ( Entry<JRadioButton, Satellite> entry : radioToSat.entrySet() ){
+ if(entry.getKey().isSelected()){
+ satellite = entry.getValue();
+ break;
}
}
}
- // custom button selected or something went wrong
- if (satellite == null || radioCustomIp.isSelected()) {
+ // custom button selected
+ if (radioCustomIp.isSelected()) {
satellite = new Satellite();
satellite.addressList = new ArrayList<String>();
satellite.addressList.add(customIpField.getText());
@@ -85,32 +75,25 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui
}
});
- getRootPane().setDefaultButton(exitButton);
+ getRootPane().setDefaultButton(nextButton);
Gui.centerShellOverShell(modalParent, this);
}
+
+ private Satellite runAndReturn() {
+ setVisible(true);
+ return satellite;
+ }
/**
* Open a new SatelliteListWindow
*
* @param modalParent
* @param satList The list of satellites to display.
- * @return satellite with address to use.
+ * @return satellite with address to use, or null on error/cancel
*/
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() {
+ return new SatelliteListWindow( modalParent, satList ).runAndReturn();
}
-
}
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
index cb1dc3a1..33a44e69 100644
--- 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
@@ -1,5 +1,6 @@
package org.openslx.dozmod.gui.window.layout;
+import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Window;
import java.util.HashMap;
@@ -11,6 +12,7 @@ import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
+import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
@@ -21,49 +23,46 @@ import org.openslx.dozmod.gui.helper.GridManager;
@SuppressWarnings("serial")
public class SatelliteListWindowLayout extends JDialog {
- protected final JButton exitButton;
+ protected final JButton nextButton;
protected final JTextField customIpField;
protected final JRadioButton radioCustomIp;
- protected final JRadioButton[] satelliteButtons;
- protected final int satCount;
protected final HashMap<JRadioButton, Satellite> radioToSat = new HashMap<JRadioButton, Satellite>();
- protected final ButtonGroup btnGroup;
- private static String title = "Liste an Satelliten";
+ private static String title = "Satelliten-Server wählen";
protected SatelliteListWindowLayout(Window modalParent, List<Satellite> satList) {
super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
: ModalityType.MODELESS);
-
- GridManager windowGrid = new GridManager(this, 1);
JPanel radioPanel = new JPanel();
- radioPanel.setBorder(BorderFactory.createTitledBorder( "Satelliten Auswahl"));
+ radioPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
GridManager selectionPanelGrid = new GridManager(radioPanel, 2);
- btnGroup = new ButtonGroup();
+ ButtonGroup btnGroup = new ButtonGroup();
// --------------- radio buttons sat selection --------------------------------------
- satCount = satList.size();
- satelliteButtons = new JRadioButton[satCount];
+ selectionPanelGrid.add(new JLabel("Vorgegebene Server"), 2);
+ selectionPanelGrid.nextRow();
// create the radioButtons, add them to the map, button group and the selection grid.
- for (int index = 0; index < satCount; index++ ){
- satelliteButtons[index] = new JRadioButton(satList.get(index).getDisplayName());
- radioToSat.put(satelliteButtons[index], satList.get(index));
- btnGroup.add(satelliteButtons[index]);
- selectionPanelGrid.add(satelliteButtons[index], 2).fill(true, false).expand(true, false);
+ for ( Satellite sat : satList ){
+ JRadioButton radioButton = new JRadioButton(sat.getDisplayName());
+ radioButton.setEnabled(sat.addressList != null && !sat.addressList.isEmpty());
+ radioToSat.put(radioButton, sat);
+ btnGroup.add(radioButton);
+ selectionPanelGrid.add(radioButton, 2).fill(true, false).expand(true, false);
selectionPanelGrid.nextRow();
}
// --------------- end radio buttons for sat selection ------------------------------------
// --------------- custom ip button and field --------------------------------------
- radioCustomIp = new JRadioButton("Benutzerdefiniert");
+ selectionPanelGrid.add(new JLabel("Server-Adresse selbst eingeben"), 2);
+ selectionPanelGrid.nextRow();
+ radioCustomIp = new JRadioButton("");
btnGroup.add(radioCustomIp);
- customIpField = new JTextField();
- customIpField.setPreferredSize(new Dimension(120, 25));
+ customIpField = new JTextField("");
selectionPanelGrid.add(radioCustomIp).fill(true, false).expand(false, false);
selectionPanelGrid.add(customIpField).fill(true, false).expand(true, false);
selectionPanelGrid.nextRow();
- selectionPanelGrid.finish(true);
// --------------- end custom ip field --------------------------------
+ selectionPanelGrid.finish(false);
// --------------- button panel --------------------------------------
JPanel buttonPane = new JPanel();
@@ -71,16 +70,13 @@ public class SatelliteListWindowLayout extends JDialog {
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);
+ nextButton = new JButton("Weiter");
+ buttonPane.add(nextButton);
// --------------- end button panel ----------------------------------
// pack it all
- windowGrid.add(radioPanel).fill(true, true).expand(true, true);
- windowGrid.nextRow();
- windowGrid.add(buttonPane).fill(true, false).expand(true, false);
- windowGrid.nextRow();
- windowGrid.finish(false);
+ getContentPane().add(radioPanel, BorderLayout.CENTER);
+ getContentPane().add(buttonPane, BorderLayout.PAGE_END);
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 931802cb..b67b41b9 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java
@@ -112,15 +112,25 @@ public class ThriftActions {
// TODO: Show list if > 1
// Satellite sat = data.satellites.get(0);
Satellite sat = null;
- if (data.satellites.size() == 1 && !LoginWindow.forceCustomSatellite)
+ if (data.satellites.size() == 1 && !LoginWindow.forceCustomSatellite) {
sat = data.satellites.get(0);
- else
+ } else {
sat = SatelliteListWindow.open(window , data.satellites);
+ }
- if (sat.addressList == null || sat.addressList.isEmpty()) {
+ if (sat.addressList == null) {
+ // TODO: Ask for manual IP address entry
+ Gui.asyncMessageBox(
+ "Login erfolgreich, aber es wurde kein Satelliten-Server ausgewählt.\n"
+ + "Vorgang abgebrochen.",
+ MessageType.ERROR, LOGGER, null);
+ return false;
+ }
+ if (sat.addressList.isEmpty()) {
// TODO: Ask for manual IP address entry
Gui.asyncMessageBox(
- "Login erfolgreich, aber für den Satelliten ist keine IP-Adresse hinterlegt",
+ "Login erfolgreich, aber für den ausgewählten Satelliten-Server ist\n"
+ + "keine Adresse hinterlegt. Kann nicht verbinden.",
MessageType.ERROR, LOGGER, null);
return false;
}