diff options
author | Stephan Schwaer | 2015-10-05 17:52:28 +0200 |
---|---|---|
committer | Stephan Schwaer | 2015-10-05 17:52:28 +0200 |
commit | 8c90c0716a148272d6e5b2216597c0f940825d9b (patch) | |
tree | 076e18ab730629c3101f8e8bc4768a36fa48761e /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java | |
parent | [client] Fixed NPE when opening links. (diff) | |
download | tutor-module-8c90c0716a148272d6e5b2216597c0f940825d9b.tar.gz tutor-module-8c90c0716a148272d6e5b2216597c0f940825d9b.tar.xz tutor-module-8c90c0716a148272d6e5b2216597c0f940825d9b.zip |
[client] Now possible to delete multiple images. Needs cleanup
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java | 101 |
1 files changed, 82 insertions, 19 deletions
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 b2ac8991..970e12fb 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 @@ -8,7 +8,6 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -21,6 +20,7 @@ import javax.swing.JFrame; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; import javax.swing.RowFilter; import javax.swing.SwingUtilities; import javax.swing.UIManager; @@ -144,6 +144,8 @@ public class LectureListWindow extends LectureListWindowLayout { public LectureListWindow() { super(); + lectureTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + // filter the objects in the table depending on the search field searchTextField.getDocument().addDocumentListener(new DocumentListener() { @Override @@ -200,7 +202,7 @@ public class LectureListWindow extends LectureListWindowLayout { deleteButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - deleteLecture(lectureTable.getSelectedItem()); + deleteLectures(lectureTable.getSelectedItems()); } }); @@ -255,7 +257,7 @@ public class LectureListWindow extends LectureListWindowLayout { ImageDetailsWindow.open(JOptionPane.getFrameForComponent(me), lecture.imageBaseId, null); } if (e.getSource().equals(popupItemDelete)) { - deleteLecture(lecture); + deleteLectures(lectureTable.getSelectedItems()); } } }); @@ -270,7 +272,10 @@ public class LectureListWindow extends LectureListWindowLayout { lectureTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - + if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { + openLectureDetails(lectureTable.getSelectedItem()); + } + processClick(e); } @Override @@ -284,20 +289,48 @@ public class LectureListWindow extends LectureListWindowLayout { } private void processClick(MouseEvent e) { - // left double click => open details - if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2 && Session.canListImages()) { - openLectureDetails(lectureTable.getSelectedItem()); - return; + // // left double click => open details + // if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2 && Session.canListImages()) { + // openLectureDetails(lectureTable.getSelectedItem()); + // return; + // } + // // else, check if we are a popup trigger + // int r = lectureTable.rowAtPoint(e.getPoint()); + // if (r >= 0 && r < lectureTable.getRowCount()) { + // // highlight the row and popup the menu + // lectureTable.setRowSelectionInterval(r, r); + // if (e.isPopupTrigger()) { + // pop.show(e.getComponent(), e.getX(), e.getY()); + // } + // } else { + // lectureTable.clearSelection(); + // } + + // rowIndex at mouse cursor + int mouseRowIndex = lectureTable.rowAtPoint(e.getPoint()); + + // is the click event on an already selected row? + boolean alreadySelectedRow = false; + for (int i : lectureTable.getSelectedRows()) { + if (i == mouseRowIndex) { + alreadySelectedRow = true; + break; + } } - // else, check if we are a popup trigger - int r = lectureTable.rowAtPoint(e.getPoint()); - if (r >= 0 && r < lectureTable.getRowCount()) { - // highlight the row and popup the menu - lectureTable.setRowSelectionInterval(r, r); + + if (mouseRowIndex >= 0 && mouseRowIndex < lectureTable.getRowCount() + && SwingUtilities.isRightMouseButton(e)) { + // select row if it wasn't in selection before + if (!alreadySelectedRow) { + lectureTable.setRowSelectionInterval(mouseRowIndex, mouseRowIndex); + } if (e.isPopupTrigger()) { pop.show(e.getComponent(), e.getX(), e.getY()); } - } else { + } + // TODO This doesn't work, make deselection possible by clicking on empty table space + else if (SwingUtilities.isLeftMouseButton(e) + && (mouseRowIndex < 0 || mouseRowIndex > lectureTable.getRowCount())) { lectureTable.clearSelection(); } } @@ -346,15 +379,22 @@ public class LectureListWindow extends LectureListWindowLayout { } /** - * Updates the buttons/popup menu items according to the user's permissions + * Updates the buttons/popup menu items according to the user's permissions, + * status and number of selections * * @param item the image to check the user's permissions for */ + //TODO rework the visibility of buttons? private void updateAvailableOptions(LectureSummary lecture) { - boolean edit = LecturePerms.canEdit(lecture); boolean admin = LecturePerms.canAdmin(lecture); - deleteButton.setEnabled(admin); + boolean singleSelection = !(lectureTable.getSelectedRows().length > 1); + + deleteButton.setEnabled(admin || !singleSelection); popupItemDelete.setEnabled(admin); + popupItemLinked.setEnabled(Session.canListImages() && singleSelection); + popupItemDownload.setEnabled(Session.canListImages() && singleSelection); + popupItemNew.setEnabled(Session.canListImages() && singleSelection); + popupItemEdit.setEnabled(Session.canListImages() && singleSelection); } /** @@ -388,6 +428,30 @@ public class LectureListWindow extends LectureListWindowLayout { } /** + * Delete a list of lectures and display the lectures, which couldn't be + * deleted. + * + * @param lectureList the images to be deleted. + */ + private void deleteLectures(List<LectureSummary> lectureList) { + boolean failedToDeleteAll = false; + StringBuilder builder = new StringBuilder(); + for (LectureSummary lecture : lectureList) { + if (LecturePerms.canAdmin(lecture)) { + deleteLecture(lecture); + } else { + failedToDeleteAll = true; + builder.append('\n'); + builder.append(lecture.lectureName); + } + } + if (failedToDeleteAll) { + Gui.showMessageBox("Folgende images konnten nicht gelöscht werden: " + builder.toString(), + MessageType.INFO, LOGGER, null); + } + } + + /** * Applies the filter entered in the search field to the table */ private void applyFilterOnTable() { @@ -457,8 +521,7 @@ public class LectureListWindow extends LectureListWindowLayout { @Override public void requestShow() { - // en-/disable buttons when student - switchViewButton.setEnabled(Session.canListImages()); + // en-/disable buttons when studentswitchViewButton.setEnabled(Session.canListImages()); newButton.setEnabled(Session.canListImages()); popupItemNew.setEnabled(Session.canListImages()); popupItemLinked.setEnabled(Session.canListImages()); |