From 1b7dfd683bc059ddbc46a6964234f1a453e0a0cc Mon Sep 17 00:00:00 2001 From: Stephan Schwaer Date: Tue, 29 Sep 2015 18:00:13 +0200 Subject: [client] Added "Show linking lectures" button im imageDetailsW. --- .../java/org/openslx/dozmod/gui/MainWindow.java | 15 ++-- .../dozmod/gui/window/ImageDetailsWindow.java | 94 +++++++++++++--------- .../dozmod/gui/window/LectureListWindow.java | 74 +++++++++++------ .../window/layout/ImageDetailsWindowLayout.java | 12 ++- 4 files changed, 123 insertions(+), 72 deletions(-) (limited to 'dozentenmodul') 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 57c825f5..824a3404 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -82,10 +82,10 @@ public abstract class MainWindow { * * @param clazz */ - public static void showPage(Class clazz) { + public static T showPage(Class clazz) { if (currentPage != null) { if (!currentPage.requestHide()) { - return; // Canceled by currently shown page + return null; // Canceled by currently shown page } currentPage.setVisible(false); } @@ -95,13 +95,14 @@ public abstract class MainWindow { Gui.showMessageBox(mainWindow, "Tried to show unknown page " + clazz.getSimpleName(), MessageType.ERROR, LOGGER, null); Gui.exit(1); - return; + return null; } // sets the starting preferred size. currentPage.requestShow(); currentPage.setVisible(true); mainWindow.validate(); + return (T) currentPage; } public static void centerShell(Window shell) { @@ -192,8 +193,6 @@ public abstract class MainWindow { } }); - - // Set layout for the mainshell, items added to the shell should get a gridData mainContainer.setLayout(new BoxLayout(mainContainer, BoxLayout.PAGE_AXIS)); @@ -495,7 +494,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) { @@ -520,7 +519,9 @@ public abstract class MainWindow { public PleaseWait() { GridManager grid = new GridManager(this, 3); grid.add(Box.createHorizontalGlue()).expand(true, true); - grid.add(new JLabel("Bitte warten, suche Proxy-Konfiguration...")).expand(false, true).fill(true, true); + grid.add(new JLabel("Bitte warten, suche Proxy-Konfiguration...")) + .expand(false, true) + .fill(true, true); grid.add(Box.createHorizontalGlue()).expand(true, true); grid.finish(false); } 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 fbd0f934..0fac31ac 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 @@ -19,6 +19,7 @@ import java.util.Map.Entry; import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JOptionPane; +import javax.swing.RowFilter; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -28,12 +29,14 @@ import org.openslx.bwlp.thrift.iface.ImageDetailsRead; import org.openslx.bwlp.thrift.iface.ImagePermissions; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.ImageVersionDetails; +import org.openslx.bwlp.thrift.iface.LectureSummary; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.ShareMode; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.bwlp.thrift.iface.Virtualizer; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; +import org.openslx.dozmod.gui.control.table.ListTable.ListModel; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.helper.PopupMenu; import org.openslx.dozmod.gui.helper.UiFeedback; @@ -145,6 +148,18 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe refresh(true); } }); + + btnShowLinkingLectures.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (safeClose()) { + LectureListWindow page = MainWindow.showPage(LectureListWindow.class); + page.filterByImageBaseId(image.imageBaseId); + } + } + }); + btnChangeOwner.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -152,10 +167,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe @Override public void userAdded(UserInfo user, UserListWindow window) { window.dispose(); - if (Gui.showMessageBox(me, - "Sind Sie sicher, dass sie die Besitzerrechte an " - + "einen anderen Account übertragen wollen?", - MessageType.QUESTION_YESNO, LOGGER, null)) + if (Gui.showMessageBox(me, "Sind Sie sicher, dass sie die Besitzerrechte an " + + "einen anderen Account übertragen wollen?", MessageType.QUESTION_YESNO, + LOGGER, null)) setImageOwner(user); } @@ -224,12 +238,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe // highlight the row and popup the menu versionTable.setRowSelectionInterval(r, r); if (e.isPopupTrigger()) { - popupItemNew.setEnabled( - versionTable.getSelectedItem().isValid && ImagePerms.canLink(image)); - popupItemDownload.setEnabled( - versionTable.getSelectedItem().isValid && ImagePerms.canDownload(image)); - popupItemDelete.setEnabled( - versionTable.getSelectedItem().isValid && ImagePerms.canAdmin(image)); + popupItemNew.setEnabled(versionTable.getSelectedItem().isValid + && ImagePerms.canLink(image)); + popupItemDownload.setEnabled(versionTable.getSelectedItem().isValid + && ImagePerms.canDownload(image)); + popupItemDelete.setEnabled(versionTable.getSelectedItem().isValid + && ImagePerms.canAdmin(image)); pop.show(e.getComponent(), e.getX(), e.getY()); } } else { @@ -240,8 +254,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe versionTableScrollPane.addMouseListener(ma); versionTable.addMouseListener(ma); - - // listen to changes final DocumentListener docListener = new DocumentListener() { @Override @@ -279,7 +291,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe cboOperatingSystem.addItemListener(comboItemListener); cboShareMode.addItemListener(comboItemListener); chkIsTemplate.addActionListener(checkBoxListener); - + /** * Initial state of GUI elements */ @@ -300,10 +312,9 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe ********************************************************************************/ /** * Sets the image to the given imageBaseId. This will also trigger fill() - * which - * will set the image details fields to the values represented by this + * which will set the image details fields to the values represented by this * image. - * + * * @param imageBaseId the id of the image to be displayed */ public void setImage(final String imageBaseId) { @@ -338,8 +349,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * @param user UserInfo to set the owner to */ private void setImageOwner(final UserInfo user) { - if (!ThriftActions.setImageOwner(JOptionPane.getFrameForComponent(me), image.getImageBaseId(), - user)) { + if (!ThriftActions.setImageOwner(JOptionPane.getFrameForComponent(me), image.getImageBaseId(), user)) { return; } Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user), MessageType.INFO, @@ -350,7 +360,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Called by the "Save" button, tries to save the changes internally and - * then react based depending on the outcome of the save + * then react based depending on the outcome of the save */ private void saveChanges() { boolean saved = saveChangesInternal(); @@ -367,17 +377,18 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } /** - * Helper to only save the changes, nothing else. Updating GUI elements is done by saveChanges() - * + * Helper to only save the changes, nothing else. Updating GUI elements is + * done by saveChanges() + * * @return false if any try to save changes failed, true otherwise */ private boolean saveChangesInternal() { // first build the ImageBaseWrite from the GUI fields final ImageBaseWrite ibw = new ImageBaseWrite(txtTitle.getText(), txtDescription.getText(), cboOperatingSystem.getItemAt(cboOperatingSystem.getSelectedIndex()).osId, image.virtId, - chkIsTemplate.isSelected(), - new ImagePermissions(image.defaultPermissions.link, image.defaultPermissions.download, - image.defaultPermissions.edit, image.defaultPermissions.admin), + chkIsTemplate.isSelected(), new ImagePermissions(image.defaultPermissions.link, + image.defaultPermissions.download, image.defaultPermissions.edit, + image.defaultPermissions.admin), cboShareMode.getItemAt(cboShareMode.getSelectedIndex())); // now trigger the actual action if (metadataChanged) { @@ -460,7 +471,8 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe } // remember custom permissions if (customPermissions != null) { - // need a deep copy of the permission map to be able to check for changes after ImageCustomPermissionWindow + // need a deep copy of the permission map to be able to check for + // changes after ImageCustomPermissionWindow if (originalCustomPermissions == null) originalCustomPermissions = new HashMap(); else @@ -480,7 +492,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe txtId.setText(image.getImageBaseId()); chkIsTemplate.setSelected(image.isTemplate); setTitle(image.getImageName()); - + // fill os combo, but only once :) if (cboOperatingSystem.getItemCount() == 0) { List osList = MetaDataCache.getOperatingSystems(); @@ -524,8 +536,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Checks whether the user changed any fields of the image details and - * enables the save button if so - * TODO TAGS + * enables the save button if so TODO TAGS */ private void reactToChange() { metadataChanged = reactToChangeInternal(); @@ -586,7 +597,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe txtDescription.setEditable(editable); txtTags.setEditable(editable); cboOperatingSystem.setEnabled(editable); - // cboShareMode.setEnabled(editable); + // cboShareMode.setEnabled(editable); btnPermissions.setEnabled(editable && ImagePerms.canAdmin(image)); btnChangeOwner.setEnabled(editable && ImagePerms.canAdmin(image)); btnUpdateImage.setEnabled(editable); @@ -605,11 +616,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe win.setVisible(true); } - /* ******************************************************************************* + /* ******************************************************************************* * - * Dialog class overrides - * - ********************************************************************************/ + * Dialog class overrides + * + * ******************************************************************************* + */ @SuppressWarnings("deprecation") @Override public void show() { @@ -620,14 +632,15 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe super.show(); } - /* ******************************************************************************* + /* ******************************************************************************* * - * UIFeedback implementation - * - ********************************************************************************/ + * UIFeedback implementation + * + * ******************************************************************************* + */ @Override public boolean wantConfirmQuit() { - return metadataChanged || permissionsChanged ; + return metadataChanged || permissionsChanged; } @Override @@ -639,11 +652,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe * Safe close helper: checks if we have unsaved work and prompt the user for * confirmation if so */ - private void safeClose() { + private boolean safeClose() { if ((metadataChanged || permissionsChanged) && !Gui.showMessageBox(me, "Änderungen werden verworfen, wollen Sie wirklich abbrechen?", MessageType.QUESTION_YESNO, null, null)) - return; + return false; dispose(); + return true; } } 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 4758a0c2..91693a09 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 @@ -124,7 +124,7 @@ public class LectureListWindow extends LectureListWindowLayout { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DATE, 7); - return cal.getTimeInMillis() > end ? true: false; + return cal.getTimeInMillis() > end ? true : false; } }; @@ -140,17 +140,18 @@ public class LectureListWindow extends LectureListWindowLayout { public LectureListWindow() { super(); - // filter the objects in the table depending on the search field searchTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { changedUpdate(e); } + @Override public void insertUpdate(DocumentEvent e) { changedUpdate(e); } + @Override public void changedUpdate(DocumentEvent e) { // stuff @@ -172,6 +173,7 @@ public class LectureListWindow extends LectureListWindowLayout { filterCbo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + searchTextField.setEnabled(true); applyFilterOnTable(); } }); @@ -215,7 +217,8 @@ public class LectureListWindow extends LectureListWindowLayout { if (lecture == null) return; if (e.getSource().equals(popupItemNew)) { - if (Gui.showMessageBox(me, "Um eine Veranstaltung zu erstellen, müssen Sie ein Image auswählen. Zur Imageauswahl wechseln?", + if (Gui.showMessageBox(me, "Um eine Veranstaltung zu erstellen, " + + "müssen Sie ein Image auswählen. Zur Imageauswahl wechseln?", MessageType.QUESTION_YESNO, LOGGER, null)) { MainWindow.showPage(ImageListWindow.class); } @@ -224,23 +227,25 @@ public class LectureListWindow extends LectureListWindowLayout { openLectureDetails(lecture); } if (e.getSource().equals(popupItemDownload)) { - + //TODO fix for students, who cannot see imageDetails somehow get filesize from server. - ImageDetailsRead image = ThriftActions.getImageDetails(JOptionPane.getFrameForComponent(me) , lecture.imageBaseId); - if(image != null) { + ImageDetailsRead image = ThriftActions.getImageDetails( + JOptionPane.getFrameForComponent(me), lecture.imageBaseId); + if (image != null) { long versionSize = -1; for (ImageVersionDetails version : image.getVersions()) { - if(version.versionId.equals(lecture.imageVersionId)){ + if (version.versionId.equals(lecture.imageVersionId)) { versionSize = version.fileSize; break; } } if (versionSize != -1) { - ThriftActions.initDownload(JOptionPane.getFrameForComponent(me), lecture.imageVersionId, - lecture.imageBaseId, image.virtId, image.osId, versionSize, null); + ThriftActions.initDownload(JOptionPane.getFrameForComponent(me), + lecture.imageVersionId, lecture.imageBaseId, image.virtId, image.osId, + versionSize, null); } } - + } if (e.getSource().equals(popupItemLinked)) { ImageDetailsWindow.open(JOptionPane.getFrameForComponent(me), lecture.imageBaseId, null); @@ -263,14 +268,17 @@ public class LectureListWindow extends LectureListWindowLayout { public void mouseClicked(MouseEvent e) { } + @Override public void mousePressed(MouseEvent e) { processClick(e); } + @Override public void mouseReleased(MouseEvent e) { processClick(e); } + private void processClick(MouseEvent e) { // left double click => open details if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2 && Session.canListImages()) { @@ -314,6 +322,7 @@ public class LectureListWindow extends LectureListWindowLayout { } updateAvailableOptions(null); } + /** * Updates the buttons/popup menu items according to the user's permissions * @@ -327,18 +336,20 @@ public class LectureListWindow extends LectureListWindowLayout { popupItemEdit.setEnabled(edit); popupItemDelete.setEnabled(admin); } + /** * Opens the given lecture's details as a popup window */ private void openLectureDetails(final LectureSummary lecture) { if (lecture == null) return; - LectureDetailsWindow.open((JFrame)SwingUtilities.getWindowAncestor(me), lecture.getLectureId(), new LectureUpdatedCallback() { - @Override - public void updated(boolean success) { - refreshList(success); - } - }); + LectureDetailsWindow.open((JFrame) SwingUtilities.getWindowAncestor(me), lecture.getLectureId(), + new LectureUpdatedCallback() { + @Override + public void updated(boolean success) { + refreshList(success); + } + }); } /** @@ -347,18 +358,22 @@ public class LectureListWindow extends LectureListWindowLayout { private void deleteLecture(final LectureSummary lecture) { if (lecture == null) return; - ThriftActions.deleteLecture(JOptionPane.getFrameForComponent(me), - lecture.getLectureId(), new DeleteLectureCallback() { - @Override - public void deleted(boolean success) { - refreshList(success); - } - }); + ThriftActions.deleteLecture(JOptionPane.getFrameForComponent(me), lecture.getLectureId(), + new DeleteLectureCallback() { + @Override + public void deleted(boolean success) { + refreshList(success); + } + }); } + /** * Applies the filter entered in the search field to the table */ private void applyFilterOnTable() { + if (filterCbo.getSelectedIndex() == -1) + return; + // Filter list we are about to fill List, Integer>> filters = new ArrayList<>(); @@ -430,4 +445,17 @@ public class LectureListWindow extends LectureListWindowLayout { refreshList(false); } + public void filterByImageBaseId(final String imageBaseId) { + RowFilter, Integer> imageFilter = new RowFilter, Integer>() { + public boolean include(Entry, ? extends Integer> entry) { + LectureSummary lecture = lectureTable.getModelRow(entry.getIdentifier()); + return lecture.imageBaseId.equals(imageBaseId); + } + }; + filterCbo.setSelectedIndex(-1); + searchTextField.setText(""); + searchTextField.setEnabled(false); + lectureTable.getRowSorter().setRowFilter(imageFilter); + setLectureCountLabel(lectureTable.getRowCount()); + } } 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 34b4db4b..ba33d964 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 @@ -59,6 +59,8 @@ public abstract class ImageDetailsWindowLayout extends JDialog { protected final JButton btnUpdateImage; protected final JButton btnClose; + protected final JButton btnShowLinkingLectures; + protected final ImageVersionTable versionTable; protected JScrollPane versionTableScrollPane; @@ -87,8 +89,11 @@ public abstract class ImageDetailsWindowLayout extends JDialog { txtDescription.setWrapStyleWord(true); txtDescription.setMinimumSize(Gui.getScaledDimension(0, 100)); grid.add(new QLabel("Beschreibung")).anchor = GridBagConstraints.FIRST_LINE_START; - grid.add(new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), 2).expand(true, true).fill(true, true); + grid.add( + new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), 2) + .expand(true, true) + .fill(true, true); grid.nextRow(); // owner @@ -176,6 +181,9 @@ public abstract class ImageDetailsWindowLayout extends JDialog { grid.skip(); grid.add(btnPermissions, 2); grid.nextRow(); + btnShowLinkingLectures = new JButton("Verlinkende Veranstatlungen Zeigen"); + grid.add(btnShowLinkingLectures, 3); + grid.nextRow(); grid.add(Box.createVerticalStrut(10), 3); grid.nextRow(); grid.finish(true); -- cgit v1.2.3-55-g7522