summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Schwaer2015-10-05 17:52:28 +0200
committerStephan Schwaer2015-10-05 17:52:28 +0200
commit8c90c0716a148272d6e5b2216597c0f940825d9b (patch)
tree076e18ab730629c3101f8e8bc4768a36fa48761e
parent[client] Fixed NPE when opening links. (diff)
downloadtutor-module-8c90c0716a148272d6e5b2216597c0f940825d9b.tar.gz
tutor-module-8c90c0716a148272d6e5b2216597c0f940825d9b.tar.xz
tutor-module-8c90c0716a148272d6e5b2216597c0f940825d9b.zip
[client] Now possible to delete multiple images. Needs cleanup
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java12
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java79
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java101
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java2
4 files changed, 159 insertions, 35 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java
index 87f69264..f8808c0d 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java
@@ -3,6 +3,7 @@ package org.openslx.dozmod.gui.control.table;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Comparator;
+import java.util.LinkedList;
import java.util.List;
import javax.swing.JTable;
@@ -88,6 +89,17 @@ public abstract class ListTable<T> extends JTable {
return getModelRow(convertRowIndexToModel(rowIndex));
}
+ public List<T> getSelectedItems() {
+ int[] rows = getSelectedRows();
+ if (rows.length == 0)
+ return null;
+ List<T> itemList = new ArrayList<T>();
+ for (int i : rows) {
+ itemList.add(getViewRow(i));
+ }
+ return itemList;
+ }
+
public T getSelectedItem() {
int rowIndex = getSelectedRow();
if (rowIndex == -1)
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 86f6468b..31d047c9 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
@@ -6,6 +6,7 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
@@ -13,6 +14,7 @@ import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
+import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@@ -81,11 +83,13 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
performImageDownload(imageTable.getSelectedItem());
}
if (e.getSource().equals(popupItemDelete)) {
- deleteBaseImage(imageTable.getSelectedItem());
+ deleteImages(imageTable.getSelectedItems());
}
}
});
+ imageTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+
// add them to the popup menu
pop.addMenuItem(popupItemNewLecture);
pop.addMenuItem(popupItemEdit);
@@ -133,14 +137,31 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
}
private void processClick(MouseEvent e) {
- int r = imageTable.rowAtPoint(e.getPoint());
- if (r >= 0 && r < imageTable.getRowCount()) {
- // highlight the row and popup the menu
- imageTable.setRowSelectionInterval(r, r);
+ // rowIndex at mouse cursor
+ int mouseRowIndex = imageTable.rowAtPoint(e.getPoint());
+
+ // is the click event on an already selected row?
+ boolean alreadySelectedRow = false;
+ for (int i : imageTable.getSelectedRows()) {
+ if (i == mouseRowIndex) {
+ alreadySelectedRow = true;
+ break;
+ }
+ }
+
+ if (mouseRowIndex >= 0 && mouseRowIndex < imageTable.getRowCount()
+ && SwingUtilities.isRightMouseButton(e)) {
+ // select row if it wasn't in selection before
+ if (!alreadySelectedRow) {
+ imageTable.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 > imageTable.getRowCount())) {
imageTable.clearSelection();
}
}
@@ -176,8 +197,8 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
});
deleteButton.addActionListener(new ActionListener() {
@Override
- public void actionPerformed(ActionEvent ae) {
- deleteBaseImage(imageTable.getSelectedItem());
+ public void actionPerformed(ActionEvent e) {
+ deleteImages(imageTable.getSelectedItems());
}
});
switchViewButton.addActionListener(new ActionListener() {
@@ -238,15 +259,18 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
*/
private void updateAvailableOptions(ImageSummaryRead item) {
boolean isValid = item != null && item.getLatestVersionId() != null;
+ boolean singleSelection = !(imageTable.getSelectedRows().length > 1);
boolean download = isValid && ImagePerms.canDownload(item);
boolean link = isValid && ImagePerms.canLink(item);
boolean admin = ImagePerms.canAdmin(item);
- downloadButton.setEnabled(true);
- newLectureButton.setEnabled(link);
- deleteButton.setEnabled(admin);
- popupItemDownload.setEnabled(download);
- popupItemNewLecture.setEnabled(link);
- popupItemDelete.setEnabled(admin);
+ downloadButton.setEnabled(download && singleSelection);
+ newLectureButton.setEnabled(link && singleSelection);
+ deleteButton.setEnabled(admin || !singleSelection);
+ popupItemDownload.setEnabled(download && singleSelection);
+ popupItemNewLecture.setEnabled(link && singleSelection);
+ popupItemDelete.setEnabled(admin || !singleSelection);
+ editButton.setEnabled(singleSelection);
+
}
/********************************************************************************
@@ -318,12 +342,37 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa
*
* @param image image to delete
*/
+ //TODO seems like it's no longer needed.
private void deleteBaseImage(final ImageSummaryRead image) {
ThriftActions.deleteImageBase(JOptionPane.getFrameForComponent(this), image.getImageBaseId(), this);
}
/**
- * Callback when download initialized
+ * Delete a list of images and display the images, which couldn't be
+ * deleted.
+ *
+ * @param imageList the images to be deleted.
+ */
+ private void deleteImages(List<ImageSummaryRead> imageList) {
+ boolean failedToDeleteAll = false;
+ StringBuilder builder = new StringBuilder();
+ for (ImageSummaryRead image : imageList) {
+ if (ImagePerms.canAdmin(image)) {
+ deleteBaseImage(image);
+ } else {
+ failedToDeleteAll = true;
+ builder.append('\n');
+ builder.append(image.imageName);
+ }
+ }
+ if (failedToDeleteAll) {
+ Gui.showMessageBox("Folgende images konnten nicht gelöscht werden: " + builder.toString(),
+ MessageType.INFO, LOGGER, null);
+ }
+ }
+
+ /**
+ * Callback when download initialised
*
* @param success true if downloading, false otherwise
*/
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());
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 54ef67fe..3fdff1c7 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
@@ -27,7 +27,7 @@ public abstract class ImageListWindowLayout extends CompositePage {
protected final static String infoTitleString = "Übersicht Virtuelle Maschinen";
protected final static String newButtonLabel = "Neue VM";
protected final static String newLectureButtonLabel = "Neue Veranstaltung";
- protected final static String editButtonLabel = "Bearbeiten";
+ protected final static String editButtonLabel = "Detailansicht";
protected final static String downloadButtonLabel = "Download";
protected final static String deleteButtonLabel = "Löschen";
protected final static String switchViewButtonLabel = "Zu 'Veranstaltungen' wechseln";