diff options
| author | Jonathan Bauer | 2015-08-03 18:22:22 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2015-08-03 18:22:22 +0200 |
| commit | d1d1278f2c788627fd690e8785a39834e14f9e54 (patch) | |
| tree | b5aa530b664330c077b4011319f47848433a7c17 /dozentenmodul/src/main/java | |
| parent | [client] add column classes to generic ListTable (diff) | |
| parent | [client] Added lecture details layout and window. (not working yet) (diff) | |
| download | tutor-module-d1d1278f2c788627fd690e8785a39834e14f9e54.tar.gz tutor-module-d1d1278f2c788627fd690e8785a39834e14f9e54.tar.xz tutor-module-d1d1278f2c788627fd690e8785a39834e14f9e54.zip | |
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
Diffstat (limited to 'dozentenmodul/src/main/java')
15 files changed, 612 insertions, 128 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index fb789811..6fb45d35 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -31,7 +31,7 @@ public class App { private static void setupLogger() { // path to the log file - final String logFilePath = Config.getPath() + System.getProperty("file.separator") + "bwSuite.log"; + final String logFilePath = Config.getPath() + File.separator + "bwSuite.log"; // check if we had an old log file final File logFile = new File(logFilePath); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java index c9471174..d2781cb9 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferTask.java @@ -195,8 +195,10 @@ public abstract class TransferTask implements Runnable { // We had a transfer that reported success before, so we assume there are no more pending blocks // not being actively transfered already. Only trigger a new upload if this was the last active // transfer and it failed. This also resets endgame mode. + LOGGER.debug("Disabled endgame mode"); endgame = false; } else if (!endgame && success) { + LOGGER.debug("Enabled endgame mode"); endgame = true; } } 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 2279d3c1..efef7a0c 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -10,6 +10,9 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -24,7 +27,10 @@ import org.apache.log4j.Logger; import org.openslx.dozmod.App; import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.Gui.GuiCallable; +import org.openslx.dozmod.gui.activity.ActivityPanel; +import org.openslx.dozmod.gui.activity.UploadPanel; import org.openslx.dozmod.gui.helper.CompositePage; +import org.openslx.dozmod.gui.helper.DebugWindow; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.DisclaimerWindow; import org.openslx.dozmod.gui.window.ImageListWindow; @@ -32,6 +38,7 @@ import org.openslx.dozmod.gui.window.LectureListWindow; import org.openslx.dozmod.gui.window.LoginWindow; import org.openslx.dozmod.gui.window.MainMenuWindow; import org.openslx.dozmod.gui.window.VirtualizerNoticeWindow; +import org.openslx.dozmod.state.UploadWizardState; import org.openslx.dozmod.thrift.Session; import org.openslx.thrifthelper.ThriftManager; import org.openslx.thrifthelper.ThriftManager.ErrorCallback; @@ -41,7 +48,8 @@ public abstract class MainWindow { private final static Logger LOGGER = Logger.getLogger(MainWindow.class); private static final JFrame mainWindow; - private static final JPanel mainContainer = new JPanel(); + private static final JPanel mainContainer; + private static final JPanel activityPanel; private static CompositePage currentPage; @@ -49,6 +57,8 @@ public abstract class MainWindow { private static final Map<Class<? extends CompositePage>, CompositePage> pages = new ConcurrentHashMap<>(); + private static final List<ActivityPanel> activities = new ArrayList<>(); + private static final String THRIFT_CONNECTION_ERROR = "Lost connection to the masterserver. Do you want to retry?"; /** @@ -83,13 +93,24 @@ public abstract class MainWindow { } static { - JFrame ret = Gui.syncExec(new GuiCallable<JFrame>() { + mainWindow = Gui.syncExec(new GuiCallable<JFrame>() { @Override public JFrame run() { return new JFrame("bwLehrstuhl"); } }); - mainWindow = ret; + mainContainer = Gui.syncExec(new GuiCallable<JPanel>() { + @Override + public JPanel run() { + return new JPanel(); + } + }); + activityPanel = Gui.syncExec(new GuiCallable<JPanel>() { + @Override + public JPanel run() { + return new JPanel(); + } + }); } /** @@ -169,6 +190,16 @@ public abstract class MainWindow { registerPage(new ImageListWindow()); registerPage(new LectureListWindow()); + // Debug? + if (System.getProperty("log") != null) { + DebugWindow win = new DebugWindow(); + win.setMinimumSize(new Dimension(0, 250)); + win.setPreferredSize(win.getMinimumSize()); + mainWindow.getContentPane().add(win, BorderLayout.PAGE_START); + } + activityPanel.setLayout(new BoxLayout(activityPanel, BoxLayout.PAGE_AXIS)); + mainWindow.getContentPane().add(activityPanel, BorderLayout.PAGE_END); + // center the window on the primary monitor mainWindow.getContentPane().add(mainContainer, BorderLayout.CENTER); mainWindow.setVisible(true); @@ -188,6 +219,11 @@ public abstract class MainWindow { // Show main menu by default showPage(MainMenuWindow.class); + + UploadWizardState test = new UploadWizardState(); + test.name = "TEST TEST"; + test.diskFile = new File("/bla/blu/blubb.blsdfg.vmdk"); + addUpload(test); } /** @@ -195,9 +231,16 @@ public abstract class MainWindow { * confirmation. */ protected static void askApplicationQuit() { - // TODO: Only ask if an upload or download is running,, wizard is open etc.. - if (Gui.showMessageBox(mainWindow, "Are you sure you want to quit?", MessageType.QUESTION_YESNO, - null, null)) { + boolean open = false; + for (ActivityPanel activity : activities) { + if (activity.wantConfirmQuit()) { + open = true; + break; + } + } + if (!open + || Gui.showMessageBox(mainWindow, "Are you sure you want to quit?", + MessageType.QUESTION_YESNO, null, null)) { Gui.exit(0); } isQuitQuestionOpen = false; @@ -217,15 +260,20 @@ public abstract class MainWindow { window.setVisible(false); } + public static void addUpload(UploadWizardState state) { + activities.add(new UploadPanel(activityPanel, state)); + activityPanel.validate(); + } + private static void createMenu() { // the File menu button JMenuBar menuBar = new JMenuBar(); mainWindow.setJMenuBar(menuBar); - JMenu cascadeFileMenu = new JMenu("&File"); + JMenu cascadeFileMenu = new JMenu("File"); menuBar.add(cascadeFileMenu); - JMenuItem exitItem = new JMenuItem("&Exit"); + JMenuItem exitItem = new JMenuItem("Exit"); cascadeFileMenu.add(exitItem); exitItem.addActionListener(new ActionListener() { @@ -236,11 +284,11 @@ public abstract class MainWindow { }); // the About menu button - JMenu cascadeAboutMenu = new JMenu("&About"); + JMenu cascadeAboutMenu = new JMenu("About"); menuBar.add(cascadeAboutMenu); - JMenuItem disclaimerItem = new JMenuItem("&Disclaimer"); - JMenuItem virtualizerNoticeItem = new JMenuItem("&Virtualizer"); + JMenuItem disclaimerItem = new JMenuItem("Disclaimer"); + JMenuItem virtualizerNoticeItem = new JMenuItem("Virtualizer"); cascadeAboutMenu.add(disclaimerItem); cascadeAboutMenu.add(virtualizerNoticeItem); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/ActivityPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/ActivityPanel.java new file mode 100644 index 00000000..eb651fef --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/ActivityPanel.java @@ -0,0 +1,23 @@ +package org.openslx.dozmod.gui.activity; + +import javax.swing.JPanel; + +public abstract class ActivityPanel extends JPanel { + + private final JPanel container; + + public ActivityPanel(JPanel container) { + this.container = container; + container.add(this); + } + + /** + * If this activity wants to prevent the user from closing the application, + * it should return true. This makes the application ask the user to confirm + * quitting. + * + * @return true to ask the user for confirmation + */ + public abstract boolean wantConfirmQuit(); + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java new file mode 100644 index 00000000..430f6ae6 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UploadPanel.java @@ -0,0 +1,70 @@ +package org.openslx.dozmod.gui.activity; + +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.openslx.dozmod.gui.control.BlockProgressBar; +import org.openslx.dozmod.state.UploadWizardState; + +@SuppressWarnings("serial") +public class UploadPanel extends ActivityPanel { + + private final JLabel lblStatus; + + private final BlockProgressBar progress; + + private final UploadWizardState state; + + public UploadPanel(JPanel container, UploadWizardState state) { + super(container); + this.state = state; + setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + // Header: [status] VM-Name ---- fileName [Button] + JPanel header = new JPanel(); + header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS)); + lblStatus = new JLabel("[init]"); + header.add(lblStatus); + header.add(Box.createHorizontalStrut(10)); + JLabel vmName = new JLabel(state.name); + vmName.setFont(vmName.getFont().deriveFont(Font.BOLD)); + header.add(vmName); + header.add(Box.createHorizontalGlue()); + header.add(new JLabel(state.diskFile.getName())); + header.add(Box.createHorizontalStrut(10)); + JButton button = new JButton("Knopf"); + button.addActionListener(new ButtonAction()); + header.add(button); + add(header); + // ProgressBar + JPanel progressWrapper = new JPanel(); + progressWrapper.setLayout(new GridLayout(1, 1)); + progressWrapper.setMinimumSize(new Dimension(0, 50)); + progressWrapper.setPreferredSize(progressWrapper.getMinimumSize()); + progress = new BlockProgressBar(null); + progressWrapper.add(progress); + add(progressWrapper); + } + + @Override + public boolean wantConfirmQuit() { + return false; + } + + private class ButtonAction implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + } + } + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java index dfe0858a..3f1361a4 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java @@ -9,7 +9,7 @@ import org.openslx.dozmod.util.FormatHelper; public class ImageTable extends ListTable<ImageSummaryRead> { private static String[] columnNames = - { "Name", "OS", "Verantwortlicher", "Letztes Update", "Größe" }; + { "Name", "OS", "Verantwortlicher", "Letztes Update", "Größe", "Version", "Vorlage" }; private static Class<?>[] columnClasses = { String.class, String.class, String.class, String.class, String.class }; @@ -31,6 +31,10 @@ public class ImageTable extends ListTable<ImageSummaryRead> { return FormatHelper.longDate(row.getUpdateTime()); if (columnIndex == 4) return row.getCurrentVersionId() == null ? "-" : FormatHelper.bytes(row.getFileSize(), false); + if (columnIndex == 5) + return row.getCurrentVersionId() == null ? "-" : row.getCurrentVersionId(); + if (columnIndex == 6) + return row.isTemplate ? "Ja" : "Nein"; throw new IndexOutOfBoundsException(); } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DebugWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DebugWindow.java new file mode 100644 index 00000000..14d96738 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/DebugWindow.java @@ -0,0 +1,95 @@ +package org.openslx.dozmod.gui.helper; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Insets; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextPane; +import javax.swing.border.BevelBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.text.BadLocationException; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; + +import org.apache.log4j.Appender; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Priority; +import org.apache.log4j.spi.LoggingEvent; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +@SuppressWarnings("serial") +public class DebugWindow extends JPanel { + + private static final DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss"); + + private final JTextPane txtLog; + + public DebugWindow() { + setLayout(new BorderLayout()); + txtLog = new JTextPane(); + txtLog.setEditable(false); + txtLog.setBackground(Color.WHITE); + txtLog.setForeground(Color.BLACK); + txtLog.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5))); + JScrollPane sp = new JScrollPane(txtLog, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + sp.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); + add(sp, BorderLayout.CENTER); + registerLogger(); + validate(); + } + + private void registerLogger() { + Appender appender = new AppenderSkeleton() { + + @Override + public boolean requiresLayout() { + return false; + } + + @Override + public void close() { + // Nothing to do + } + + @Override + protected void append(LoggingEvent event) { + Level l = event.getLevel(); + Color c; + if (l.isGreaterOrEqual(Priority.ERROR)) { + c = Color.RED; + } else if (l.isGreaterOrEqual(Priority.WARN)) { + c = Color.ORANGE; + } else if (l.isGreaterOrEqual(Priority.INFO)) { + c = Color.BLACK; + } else { + c = Color.GRAY; + } + log("[" + formatter.print(event.getTimeStamp()) + "] ", Color.BLACK); + log(event.getThreadName() + "@" + event.getLoggerName().replaceAll("^.*\\.", ""), Color.GRAY); + log(" " + event.getMessage() + "\n", c); + } + }; + BasicConfigurator.configure(appender); + } + + private void log(String msg, Color c) { + StyledDocument doc = txtLog.getStyledDocument(); + SimpleAttributeSet keyWord = new SimpleAttributeSet(); + StyleConstants.setForeground(keyWord, c); + try { + doc.insertString(doc.getLength(), msg, keyWord); + } catch (BadLocationException e) { + e.printStackTrace(); // Do not use LOGGER here to prevent infinite loop + } + txtLog.setCaretPosition(doc.getLength()); + } + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index 9d72f25a..05e1df76 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -109,7 +109,10 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout { lblUpdater.setUser(UserCache.find(image.getUpdaterId())); lblCreateTime.setText(FormatHelper.longDate(image.getCreateTime())); lblUpdateTime.setText(FormatHelper.longDate(image.getUpdateTime())); - + txtId.setText(image.getImageBaseId()); + txtVersion.setText(image.getCurrentVersionId()); + + List<OperatingSystem> osList = MetaDataCache.getOperatingSystems(); // all fine, lets sort it Collections.sort(osList, new Comparator<OperatingSystem>() { @@ -149,8 +152,11 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout { txtTitle.setEnabled(editable); txtDescription.setEnabled(editable); txtTags.setEnabled(editable); + txtVersion.setEnabled(editable); + txtId.setEnabled(editable); btnIsTemplate.setEnabled(editable); cboOperatingSystem.setEnabled(editable); + cboShareMode.setEnabled(editable); } /** 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 af70b22b..e8a8b2e4 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 @@ -9,24 +9,18 @@ import java.util.List; import java.util.regex.PatternSyntaxException; import javax.swing.JFrame; -import javax.swing.JTextField; import javax.swing.RowFilter; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import org.apache.log4j.Logger; -import org.openslx.bwlp.thrift.iface.ImagePermissions; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.window.layout.ImageListWindowLayout; import org.openslx.dozmod.gui.wizard.ImageWizard; import org.openslx.dozmod.thrift.ImageCache; -import org.openslx.dozmod.thrift.UserCache; -import org.openslx.dozmod.util.FormatHelper; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; @@ -65,47 +59,7 @@ public class ImageListWindow extends ImageListWindowLayout { } }); - // Selection listener for the table to update the details panel when an image is clicked - imageTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { - ImageSummaryRead image = imageTable.getSelectedItem(); - if (image == null) - return; - // Fill detail information fields - // Image name - setFieldText(imageSelectedNameLabel, image.getImageName()); - // id of the lecture - setFieldText(idInfo, image.getImageBaseId()); - // version of the image TODO last? current? - setFieldText(versionInfo, image.getCurrentVersionId()); - // last update of image - setFieldText(lastUpdateInfo, FormatHelper.longDate(image.getUpdateTime())); - // permissions of this image - ImagePermissions perms = image.getUserPermissions(); - if (perms == null) - perms = image.getDefaultPermissions(); - if (perms != null) - setFieldText(permissionInfo, perms.toString()); - // the owner of the selected lecture - setFieldText(ownerInfo, FormatHelper.userName(UserCache.find(image.getOwnerId()))); - // is it a template? - if (image.isTemplate) - templateInfo.setText("Ja"); - else - templateInfo.setText("Nein"); - - me.invalidate(); - me.validate(); - } - private void setFieldText(JTextField control, String content) { - if (content == null) { - control.setText("<null>"); - } else { - control.setText(content); - } - } - }); + imageTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java new file mode 100644 index 00000000..ee7f5db8 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java @@ -0,0 +1,147 @@ +package org.openslx.dozmod.gui.window; + +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.ImageDetailsRead; +import org.openslx.bwlp.thrift.iface.LectureRead; +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.MainWindow; +import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.window.layout.LectureDetailsWindowLayout; +import org.openslx.dozmod.permissions.ImagePerms; +import org.openslx.dozmod.thrift.MetaDataCache; +import org.openslx.dozmod.thrift.Session; +import org.openslx.dozmod.thrift.UserCache; +import org.openslx.dozmod.util.FormatHelper; +import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; + +@SuppressWarnings("serial") +public class LectureDetailsWindow extends LectureDetailsWindowLayout { + + private static final Logger LOGGER = Logger.getLogger(LectureDetailsWindow.class); + + private final LectureDetailsWindow me = this; + + private LectureRead lecture = null; + + public LectureDetailsWindow(Frame modalParent) { + super(modalParent); + + // Close button closes window + btnClose.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + // ESC closes this window + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + LOGGER.debug("he"); + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + dispose(); + } + } + }); + setFocusable(true); + } + + /** + * @param lectureId the id of the image to be displayed + */ + public void setLecture(final String lectureId) { + + QuickTimer.scheduleOnce(new Task() { + @Override + public void fire() { + Exception error = null; + try { + synchronized (me) { + if (lecture != null) + return; + lecture = ThriftManager.getSatClient().getLectureDetails(Session.getSatelliteToken(), lectureId); + } + } catch (Exception e) { + error = e; + } + final Exception e = error; + Gui.asyncExec(new Runnable() { + @Override + public void run() { + if (e != null || lecture == null) { + Gui.showMessageBox(null, "Konnte Daten der Vorlesung nicht abrufen", + MessageType.ERROR, LOGGER, e); + dispose(); + } else { + fill(); + } + } + }); + } + }); + } + + /** + * callback function when we received the image's details from the server + */ + private void fill() { + if (lecture == null) + return; + txtTitle.setText(lecture.getLectureName()); + txtDescription.setText(lecture.getDescription()); + if (lecture.image != null) + txtImageName.setText(lecture.image.getImageName()); + lblOwner.setUser(UserCache.find(lecture.getOwnerId())); + lblUpdater.setUser(UserCache.find(lecture.getUpdaterId())); + lblCreateTime.setText(FormatHelper.longDate(lecture.getCreateTime())); + lblUpdateTime.setText(FormatHelper.longDate(lecture.getUpdateTime())); + lblStartTime.setText(FormatHelper.longDate(lecture.getStartTime())); + lblEndTime.setText(FormatHelper.longDate(lecture.getEndTime())); + + txtId.setText(lecture.getLectureId()); + + btnIsEnabled.setSelected(lecture.isEnabled); + btnIsExam.setSelected(lecture.isExam); + // TODO grey out non editable components + //makeEditable(ImagePerms.canEdit(lecture)); + pack(); + MainWindow.centerShell(this); + setVisible(true); + } + + /** + * Enables/disables the editable fields based on 'editable' + * + * @param editable true to make fields editable, false otherwise. + */ + private void makeEditable(boolean editable) { + txtTitle.setEnabled(editable); + txtDescription.setEnabled(editable); + txtId.setEnabled(editable); + } + + /** + * Opens a new LectureDetailsWindow showing the details of the + * lecture with ID = lectureId + * + * @param modalParent parent of this window + * @param lectureId id of the lecture to set the details of + */ + public static void open(Frame modalParent, String lectureId) { + LectureDetailsWindow win = new LectureDetailsWindow(modalParent); + win.setLecture(lectureId); + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java index 4b24ce5e..eb4dc1ee 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java @@ -6,6 +6,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.List; +import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; @@ -51,6 +52,18 @@ public class LectureListWindow extends LectureListWindowLayout { // TODO: Set filter } }); + + lectureTable.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + LectureSummary lecture = lectureTable.getSelectedItem(); + if (lecture == null) + return; + LectureDetailsWindow.open((JFrame)SwingUtilities.getWindowAncestor(me), lecture.getLectureId()); + } + } + }); lectureTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override 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 0df9cb04..594eba07 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 @@ -81,11 +81,11 @@ public class LoginWindow extends LoginWindowLayout { idpLabel.setVisible(type == LOGIN_TYPE.ECP); idpCombo.setVisible(type == LOGIN_TYPE.ECP); loginType = type; - } + } } }); } - + // check if we had saved an authentication method String savedAuthMethod = Config.getAuthenticationMethod(); LOGIN_TYPE savedLoginType; @@ -95,7 +95,7 @@ public class LoginWindow extends LoginWindowLayout { // if no valid LOGIN_TYPE was saved, just enable the BWIDM button savedLoginType = LOGIN_TYPE.ECP; } - + if (savedLoginType == LOGIN_TYPE.ECP) { // disable login button til the idp list is here loginButton.setEnabled(false); @@ -114,7 +114,7 @@ public class LoginWindow extends LoginWindowLayout { App.waitForInit(); orgs = OrganizationCache.getAll(); } catch (Exception e) { - LoginWindow.LOGGER.error("Error during execution: ", e); + LOGGER.error("Error during execution: ", e); } // filter out every organisation without ecp Iterator<Organization> iterator = orgs.iterator(); @@ -140,7 +140,7 @@ public class LoginWindow extends LoginWindowLayout { }); } }); - + loginButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -156,7 +156,7 @@ public class LoginWindow extends LoginWindowLayout { if (e.getKeyCode() == KeyEvent.VK_ENTER) { doLogin(); } - + } }); @@ -174,25 +174,22 @@ public class LoginWindow extends LoginWindowLayout { /** * Called by the thread fetching the organization list from the cache * - * @param orgs list of organization to show in the combo box + * @param orgs list of organization to show in the combo box */ public void populateIdpCombo(List<Organization> orgs) { - + // sanity checks on orgs if (orgs == null) { LOGGER.error("No organizations received from the cache."); return; } - for (Organization org : orgs) { LOGGER.debug(org); } idpCombo.setModel(new DefaultComboBoxModel<Organization>(orgs.toArray(new Organization[orgs.size()]))); idpCombo.setRenderer(new DefaultListCellRenderer() { @Override - public Component getListCellRendererComponent(JList<?> list, - Object value, int index, boolean isSelected, - boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, - isSelected, cellHasFocus); + public Component getListCellRendererComponent(JList<?> list, Object value, int index, + boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Organization) { Organization org = (Organization) value; setText(org.getDisplayName()); @@ -276,8 +273,8 @@ public class LoginWindow extends LoginWindowLayout { case SERVICE_PROVIDER_ERROR: // here if we have t != null then we have not received a token // if we have t, then the token is invalid. - Gui.showMessageBox(me, "Invalid token from the service provider!", - MessageType.ERROR, LOGGER, t); + Gui.showMessageBox(me, "Invalid token from the service provider!", MessageType.ERROR, + LOGGER, t); break; case UNREGISTERED_ERROR: Gui.showMessageBox(me, "You are not registered to bwLehrpool. Please visit " @@ -285,8 +282,8 @@ public class LoginWindow extends LoginWindowLayout { LOGGER, t); break; case INVALID_URL_ERROR: - Gui.showMessageBox(me, "ECP Authenticator says: Invalid URL.", - MessageType.ERROR, LOGGER, t); + Gui.showMessageBox(me, "ECP Authenticator says: Invalid URL.", MessageType.ERROR, LOGGER, + t); break; case GENERIC_ERROR: default: @@ -317,8 +314,7 @@ public class LoginWindow extends LoginWindowLayout { try { authenticator.login(username, password, authenticatorCallback); } catch (Exception e) { - Gui.showMessageBox(this, "Authentication failed: " + e.getMessage(), MessageType.ERROR, - LOGGER, e); + Gui.showMessageBox(this, "Authentication failed: " + e.getMessage(), MessageType.ERROR, LOGGER, e); return; } } @@ -337,8 +333,8 @@ public class LoginWindow extends LoginWindowLayout { try { ThriftManager.getSatClient().isAuthenticated(Session.getSatelliteToken()); // now read the config to see if the user already agreed to the disclaimer -// if (DisclaimerWindow.shouldBeShown()) -// VirtualizerNoticeWindow.open(); + // if (DisclaimerWindow.shouldBeShown()) + // VirtualizerNoticeWindow.open(); LOGGER.debug("Closing..."); dispose(); return; @@ -353,7 +349,7 @@ public class LoginWindow extends LoginWindowLayout { * Opens the login window */ public static void open(Frame modalParent) { - + LoginWindow win = new LoginWindow(modalParent); MainWindow.centerShell(win); win.setVisible(true); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java index 498c44f8..c0c32f71 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java @@ -43,6 +43,10 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JTextField txtTags; protected final JCheckBox btnIsTemplate; protected final JComboBox<ShareMode> cboShareMode; + + protected final JTextField txtId; + protected final JTextField txtVersion; + protected final JButton btnSaveChanges; protected final JButton btnClose; @@ -67,7 +71,6 @@ public abstract class ImageDetailsWindowLayout extends JDialog { // description txtDescription = new JTextArea(); infoPanel.add(new JLabel("Beschreibung"), GridPos.get(0, 1, false, false)); - infoPanel.add(new JScrollPane(txtDescription), GridPos.get(1, 1, true, false)); // owner @@ -119,6 +122,14 @@ public abstract class ImageDetailsWindowLayout extends JDialog { infoPanel.add(new JLabel("Vorlage"), GridPos.get(0, 10, false, false)); infoPanel.add(btnIsTemplate, GridPos.get(1, 10, true, false)); + txtVersion = new JTextField(); + infoPanel.add(new JLabel("Version"), GridPos.get(0, 11, false, false)); + infoPanel.add(txtVersion, GridPos.get(1, 11, true, false)); + + txtId = new JTextField(); + infoPanel.add(new JLabel("ID"), GridPos.get(0, 12, false, false)); + infoPanel.add(txtId, GridPos.get(1, 12, true, false)); + // finally add the infoPanel itself to the main view add(infoPanel, BorderLayout.CENTER); // button panel on the bottom 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 index 438e9795..1c21dbe2 100644 --- 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 @@ -1,19 +1,14 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.BorderLayout; -import java.awt.Dimension; import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JSplitPane; import javax.swing.JTextField; -import javax.swing.border.TitledBorder; import org.apache.log4j.Logger; import org.openslx.dozmod.gui.control.table.ImageTable; @@ -33,11 +28,10 @@ public abstract class ImageListWindowLayout extends CompositePage { protected final static String downloadButtonLabel = "Download"; protected final static String backButtonLabel = "Zurück"; protected final static String tableGroupLabel = "Images"; - protected final static String vmInfoGroupLabel = "Detailinformationen"; protected final static String filterGroupLabel = "Filter"; // -------------------------------------- - // Left panel: search field, table and buttons + // search field, table and buttons protected JTextField searchTextField; protected ImageTable imageTable; protected JButton newButton; @@ -45,15 +39,7 @@ public abstract class ImageListWindowLayout extends CompositePage { protected JButton downloadButton; protected JButton backButton; - // -------------------------------------- - // Right panel: image details information - protected JTextField imageSelectedNameLabel; - protected JTextField idInfo; - protected JTextField versionInfo; - protected JTextField lastUpdateInfo; - protected JTextField permissionInfo; - protected JTextField ownerInfo; - protected JTextField templateInfo; + public ImageListWindowLayout() { super(new BorderLayout()); @@ -69,7 +55,7 @@ public abstract class ImageListWindowLayout extends CompositePage { add(infoPanel, BorderLayout.NORTH); // -------------------------------------- - // LEFT: List panel with the list of the images + // the panel for the table and search field JPanel listPanel = new JPanel(new BorderLayout()); // the search field searchTextField = new JTextField(); @@ -77,6 +63,9 @@ public abstract class ImageListWindowLayout extends CompositePage { // the actual table imageTable = new ImageTable(); listPanel.add(new JScrollPane(imageTable), BorderLayout.CENTER); + add(listPanel, BorderLayout.CENTER); + + // -------------------------------------- // the buttons at the bottom JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); @@ -90,32 +79,7 @@ public abstract class ImageListWindowLayout extends CompositePage { buttonPanel.add(backButton); listPanel.add(buttonPanel, BorderLayout.PAGE_END); - // -------------------------------------- - // RIGHT: Details panel for the selected image - final JPanel detailsPane = new JPanel(); - detailsPane.setLayout(new GridBagLayout()); - detailsPane.setBorder(new TitledBorder(vmInfoGroupLabel)); - detailsPane.setMaximumSize(new Dimension(400, Integer.MAX_VALUE)); - detailsPane.setMinimumSize(new Dimension(350, 0)); - detailsPane.setPreferredSize(detailsPane.getMinimumSize()); - // image name info - int row = 0; - imageSelectedNameLabel = createCaptionAndTextfield("Name", detailsPane, row++); - idInfo = createCaptionAndTextfield("ID", detailsPane, row++); - versionInfo = createCaptionAndTextfield("Version", detailsPane, row++); - lastUpdateInfo = createCaptionAndTextfield("Letztes Update", detailsPane, row++); - permissionInfo = createCaptionAndTextfield("Berechtigungen", detailsPane, row++); - ownerInfo = createCaptionAndTextfield("Besitzer", detailsPane, row++); - templateInfo = createCaptionAndTextfield("Vorlage", detailsPane, row++); - // For some reason without this the controls above are centered vertically - detailsPane.add(new JPanel(), GridPos.get(0, row++, 2, 1, true, true)); - // the actual layout of the whole window - JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); - splitPane.setLeftComponent(listPanel); - splitPane.setRightComponent(detailsPane); - // make the left panel grab the excess space - splitPane.setResizeWeight(1); - add(splitPane); + } public JTextField createCaptionAndTextfield(String captionString, JPanel group, int row) { JLabel caption = new JLabel(captionString); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java new file mode 100644 index 00000000..18231147 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java @@ -0,0 +1,151 @@ +package org.openslx.dozmod.gui.window.layout; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Font; +import java.awt.Frame; +import java.awt.GridBagLayout; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.ShareMode; +import org.openslx.dozmod.gui.control.PersonLabel; +import org.openslx.dozmod.gui.helper.GridPos; + +@SuppressWarnings("serial") +public abstract class LectureDetailsWindowLayout extends JDialog { + + protected final JLabel txtTitle; + protected final JTextArea txtDescription; + + protected final JTextField txtImageName; + + protected final PersonLabel lblOwner; + protected final JLabel lblCreateTime; + protected final PersonLabel lblUpdater; + protected final JLabel lblUpdateTime; + + protected final JLabel lblStartTime; + protected final JLabel lblEndTime; + + protected final JCheckBox btnIsEnabled; + protected final JCheckBox btnAutoUpdate; + protected final JCheckBox btnIsExam; + + + protected final JTextField txtId; + + protected final JLabel lblUseCount; + + protected final JButton btnSaveChanges; + protected final JButton btnClose; + + // TODO: Permissions, ... + + public LectureDetailsWindowLayout(Frame modalParent) { + super(modalParent, "der mit dem blub", ModalityType.APPLICATION_MODAL); + setResizable(true); + setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + setLayout(new BorderLayout()); + + // use panel to put every info related widget in it + // then we will set the panel in BorderLayout.CENTER + JPanel infoPanel = new JPanel(); + infoPanel.setLayout(new GridBagLayout()); + infoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + // helper for row index + int row = 0; + + // -- name -- + txtTitle = new JLabel(); + txtTitle.setFont(txtTitle.getFont().deriveFont(Font.BOLD, txtTitle.getFont().getSize2D() * 2)); + infoPanel.add(txtTitle, GridPos.get(0, row++, 2, 1, true, false)); + + // description + txtDescription = new JTextArea(); + infoPanel.add(new JLabel("Beschreibung"), GridPos.get(0, row++, false, false)); + infoPanel.add(new JScrollPane(txtDescription), GridPos.get(1, row++, true, false)); + + // linked image name + txtImageName = new JTextField(); + infoPanel.add(new JLabel("Imagename"), GridPos.get(0, row++, false, false)); + infoPanel.add(txtImageName, GridPos.get(1, row++, true, false)); + + // start time of the lecture + lblStartTime = new JLabel(); + infoPanel.add(new JLabel("Startzeit"), GridPos.get(0, row++, false, false)); + infoPanel.add(lblStartTime, GridPos.get(1, row++, true, false)); + + // end time of the lecture + lblEndTime = new JLabel(); + infoPanel.add(new JLabel("Endzeit"), GridPos.get(0, row++, false, false)); + infoPanel.add(lblEndTime, GridPos.get(1, row++, true, false)); + + // owner + lblOwner = new PersonLabel(); + infoPanel.add(new JLabel("Besitzer"), GridPos.get(0, row++, false, false)); + infoPanel.add(lblOwner, GridPos.get(1, row++, true, false)); + // creation time + lblCreateTime = new JLabel(); + infoPanel.add(new JLabel("Erstellt"), GridPos.get(0, row++, false, false)); + infoPanel.add(lblCreateTime, GridPos.get(1, row++, true, false)); + // last updater + lblUpdater = new PersonLabel(); + infoPanel.add(new JLabel("Geändert durch"), GridPos.get(0, row++, false, false)); + infoPanel.add(lblUpdater, GridPos.get(1, row++, true, false)); + // last updated + lblUpdateTime = new JLabel(); + infoPanel.add(new JLabel("Änderungszeitpunkt"), GridPos.get(0, row++, false, false)); + infoPanel.add(lblUpdateTime, GridPos.get(1, row++, true, false)); + // enabled + btnIsEnabled = new JCheckBox(); + infoPanel.add(new JLabel("Vorlage"), GridPos.get(0, row++, false, false)); + infoPanel.add(btnIsEnabled, GridPos.get(1, row++, true, false)); + // is exam + btnIsExam = new JCheckBox(); + infoPanel.add(new JLabel("Vorlage"), GridPos.get(0, row++, false, false)); + infoPanel.add(btnIsExam, GridPos.get(1, row++, true, false)); + + // auto update + btnAutoUpdate = new JCheckBox(); + infoPanel.add(new JLabel("Vorlage"), GridPos.get(0, row++, false, false)); + infoPanel.add(btnAutoUpdate, GridPos.get(1, row++, true, false)); + // id + txtId = new JTextField(); + infoPanel.add(new JLabel("ID"), GridPos.get(0, row++, false, false)); + infoPanel.add(txtId, GridPos.get(1, row++, true, false)); + // use count + lblUseCount = new JLabel(); + infoPanel.add(new JLabel("ID"), GridPos.get(0, row++, false, false)); + infoPanel.add(lblUseCount, GridPos.get(1, row++, true, false)); + + + // finally add the infoPanel itself to the main view + add(infoPanel, BorderLayout.CENTER); + // button panel on the bottom + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + btnSaveChanges = new JButton("Speichern"); + btnClose = new JButton("Schließen"); + buttonPanel.add(btnSaveChanges); + buttonPanel.add(Box.createGlue()); + buttonPanel.add(btnClose); + add(buttonPanel, BorderLayout.SOUTH); + } +} |
