summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/util
diff options
context:
space:
mode:
authorSimon Rettberg2015-03-06 18:30:38 +0100
committerSimon Rettberg2015-03-06 18:30:38 +0100
commit3231fee56ce50facd8483e7af4d7f9ff63c5bc38 (patch)
tree9d76b3aeb94ab560e518e3a55b051702761f5118 /dozentenmodul/src/main/java/util
parentMACHETE KILLT CODEZEILEN (diff)
downloadtutor-module-3231fee56ce50facd8483e7af4d7f9ff63c5bc38.tar.gz
tutor-module-3231fee56ce50facd8483e7af4d7f9ff63c5bc38.tar.xz
tutor-module-3231fee56ce50facd8483e7af4d7f9ff63c5bc38.zip
Aua, aua...
Diffstat (limited to 'dozentenmodul/src/main/java/util')
-rw-r--r--dozentenmodul/src/main/java/util/FormatHelper.java35
-rw-r--r--dozentenmodul/src/main/java/util/GuiManager.java19
-rw-r--r--dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java110
3 files changed, 74 insertions, 90 deletions
diff --git a/dozentenmodul/src/main/java/util/FormatHelper.java b/dozentenmodul/src/main/java/util/FormatHelper.java
new file mode 100644
index 00000000..08d8498e
--- /dev/null
+++ b/dozentenmodul/src/main/java/util/FormatHelper.java
@@ -0,0 +1,35 @@
+package 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.yy HH:mm");
+
+ /**
+ * 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/util/GuiManager.java b/dozentenmodul/src/main/java/util/GuiManager.java
index 8710cef9..4b8b610e 100644
--- a/dozentenmodul/src/main/java/util/GuiManager.java
+++ b/dozentenmodul/src/main/java/util/GuiManager.java
@@ -23,7 +23,6 @@ import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
-import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import org.apache.log4j.Logger;
@@ -177,9 +176,9 @@ public abstract class GuiManager {
private static boolean addHelp() {
// let's see if we have a HELP_MESSAGE variable defined in
// the class of the currentFrame, if so we need to show it by pressing "Hilfe"
- String test = "";
+ final String helpMessage;
try {
- test = (String) (currentFrame.getClass().getDeclaredField("HELP_MESSAGE").get(currentFrame));
+ helpMessage = (String) (currentFrame.getClass().getDeclaredField("HELP_MESSAGE").get(currentFrame));
} catch (NoSuchFieldException e) {
// only this case if interesting for us,
// since we now we don't have a help message to show
@@ -187,7 +186,7 @@ public abstract class GuiManager {
} catch (IllegalArgumentException|IllegalAccessException|SecurityException e) {
LOGGER.error("Failed to check for 'HELP_MESSAGE' variable in '"
+ currentFrame.getClass() + "' class, see trace: " + e);
- // just do nothing
+ return false;
}
// print it for debugging purposes
// still here? means we have a HELP_MESSAGE to display
@@ -195,14 +194,6 @@ public abstract class GuiManager {
mnNewMenu_Info.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
- String helpMessage = null;
- try {
- helpMessage = (String) currentFrame.getClass().getField("HELP_MESSAGE").get(currentFrame);
- } catch (IllegalArgumentException | IllegalAccessException
- | NoSuchFieldException | SecurityException e) {
- LOGGER.error("Failed to check for 'HELP_MESSAGE' variable in '"
- + currentFrame.getClass() + "' class, see trace: " + e);
- }
JOptionPane.showMessageDialog(currentFrame, helpMessage != null ? helpMessage : "No help message.",
"Hilfe zu dieser Oberfläche", JOptionPane.INFORMATION_MESSAGE);
}
@@ -265,9 +256,7 @@ public abstract class GuiManager {
newFrame.getWidth(), newFrame.getHeight());
}
}
- /**
- *
- */
+
public static void openPopup(Component popup) {
if (!(popup instanceof JFrame)) {
LOGGER.error("Popup classes need to be JFrame, given a: " + popup.getClass().getName());
diff --git a/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java b/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java
index e03e1106..412fdd5d 100644
--- a/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java
+++ b/dozentenmodul/src/main/java/util/ListAllOtherUsers_GUI.java
@@ -1,6 +1,5 @@
package util;
-import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
@@ -9,7 +8,6 @@ import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import javax.swing.DefaultListSelectionModel;
@@ -21,8 +19,6 @@ import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextPane;
-import javax.swing.UIManager;
-import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
@@ -39,19 +35,13 @@ import org.openslx.thrifthelper.ThriftManager;
@SuppressWarnings("serial")
public class ListAllOtherUsers_GUI extends JFrame {
- private final static Logger LOGGER = Logger
- .getLogger(ListAllOtherUsers_GUI.class);
+ private final static Logger LOGGER = Logger.getLogger(ListAllOtherUsers_GUI.class);
private final JPanel contentPanel = new JPanel();
- String[] result;
- JTable tableUsers;
- boolean activeSearch = false;
+ private JTable tableUsers;
+ private String[] titles = { "userID", "Nachname", "Vorname", "Mail" };
- String[] titles = { "userID", "Nachname", "Vorname", "Mail" };
-
private JButton btnAdd;
- private List<Person> map = null; // List of people
- Component c = null;
private JTable table;
private int userIDPos;
@@ -62,31 +52,24 @@ public class ListAllOtherUsers_GUI extends JFrame {
+ "Sie können die Veranstaltungen hier löschen. Alternativ werden veraltete Einträge irgendwann automatisch gelöscht.<br />"
+ "Veraltet bedeutet, dass Veranstaltungen, die drei Monate lang nicht augerufen wurden, vorerst deaktiviert werden."
+ "</div></html>";
-
-
+
//prevent table cells being clickable
- final DefaultTableModel modelUsers = new DefaultTableModel(titles, 0){
+ final DefaultTableModel modelUsers = new DefaultTableModel(titles, 0) {
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
-
- final TableRowSorter<TableModel> rowSorterAll = new TableRowSorter<TableModel>(modelUsers);
- /**
- *
- * Constructor
- */
+ final TableRowSorter<TableModel> rowSorterAll = new TableRowSorter<TableModel>(modelUsers);
- public ListAllOtherUsers_GUI(final JTable table,
- final int userIDPos) {
+ public ListAllOtherUsers_GUI(final JTable table, final int userIDPos) {
// get table model to work with
final DefaultTableModel model = (DefaultTableModel) table.getModel();
-
+
//set incoming table
- this.table=table;
- this.userIDPos=userIDPos;
+ this.table = table;
+ this.userIDPos = userIDPos;
addWindowListener(new WindowAdapter() {
@@ -104,20 +87,11 @@ public class ListAllOtherUsers_GUI extends JFrame {
// Verhindert das Vergroessern Des Fensters
setResizable(false);
- try {
- // Setzt das Look & Feel auf System
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (ClassNotFoundException | InstantiationException
- | IllegalAccessException | UnsupportedLookAndFeelException e) {
-
- e.printStackTrace();
- }
// Setzt den Fenstertitel
setTitle("bwLehrpool Suite - Benutzer hinzufügen");
// Zentriert das Fenster in die Bildmitte
setBounds(0, 0, 531, 673);
-
getContentPane().setLayout(null);
{
JPanel panel = new JPanel();
@@ -201,19 +175,15 @@ public class ListAllOtherUsers_GUI extends JFrame {
// GUI?
Object[] obj = {
- tableUsers.getValueAt(
- selectedRows[pos], 1)
- + ", "
- + tableUsers.getValueAt(
- selectedRows[pos], 2), // Nachname
- // und
- // Vorname
+ tableUsers.getValueAt(selectedRows[pos], 1) + ", "
+ + tableUsers.getValueAt(selectedRows[pos], 2), // Nachname
+ // und
+ // Vorname
false, // Read image
false, // Write image
false, // Link image
false, // Admin image
- tableUsers.getValueAt(
- selectedRows[pos], 0) // userID
+ tableUsers.getValueAt(selectedRows[pos], 0) // userID
};
model.addRow(obj);
@@ -221,18 +191,14 @@ public class ListAllOtherUsers_GUI extends JFrame {
// lecture
// GUI?
Object[] obj = {
- tableUsers.getValueAt(
- selectedRows[pos], 1)
- + ", "
- + tableUsers.getValueAt(
- selectedRows[pos], 2), // Nachname
- // und
- // Vorname
+ tableUsers.getValueAt(selectedRows[pos], 1) + ", "
+ + tableUsers.getValueAt(selectedRows[pos], 2), // Nachname
+ // und
+ // Vorname
false, // Read image
false, // Write image
false, // Admin image
- tableUsers.getValueAt(
- selectedRows[pos], 0) // userID
+ tableUsers.getValueAt(selectedRows[pos], 0) // userID
};
model.addRow(obj);
}
@@ -255,39 +221,33 @@ public class ListAllOtherUsers_GUI extends JFrame {
getContentPane().add(separator_1);
}
-
// get users from db which are not in listed in the permission yet
public void initTableContent() {
-
- //LOGGER.info("Getting list of all other users from server");
+
try {
-
+
//set users which are NOT to be listed in table
//logged on user
user.add(0, person.verantwortlicher.getUserID());
-
+
//users already in table
- for(int y=0; y<table.getRowCount(); y++){
- user.add(""+table.getValueAt(y, userIDPos));
- }
-
- //get the info
- map = ThriftManager.getSatClient().getAllOtherSatelliteUsers(user,SessionData.authToken);
- Iterator<Person> i = map.iterator();
+ for (int y = 0; y < table.getRowCount(); y++) {
+ user.add("" + table.getValueAt(y, userIDPos));
+ }
- int x = 0;
- while (i.hasNext()) {
+ //get the info
+ List<Person> users = ThriftManager.getSatClient().getAllOtherSatelliteUsers(user,
+ SessionData.authToken);
+ for (Person p : users) {
// erzeuge Objekte fuer die Tabelle
- Object[] obj = { map.get(x).getUserID(), // userID
- map.get(x).getNachname(), // Nachname
- map.get(x).getVorname(),// Vorname
- map.get(x).getMail() // EMail
+ Object[] obj = { p.getUserID(), // userID
+ p.getNachname(), // Nachname
+ p.getVorname(),// Vorname
+ p.getMail() // EMail
};
// Fuege diese Objekte der Tabelle hinzu
modelUsers.addRow(obj);
- i.next();
- x++;
- }// end while
+ }
} catch (TException e2) {
LOGGER.info("Failed to get List of users from server");