summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2015-09-03 14:06:35 +0200
committerJonathan Bauer2015-09-03 14:06:35 +0200
commit4ad94edadb8710fe0e98c5169ea4a23c5f20d75b (patch)
treed2d3f16b527fcb278545b08ce072b08968cddc27
parent[client] removed unused interface implementation (diff)
downloadtutor-module-4ad94edadb8710fe0e98c5169ea4a23c5f20d75b.tar.gz
tutor-module-4ad94edadb8710fe0e98c5169ea4a23c5f20d75b.tar.xz
tutor-module-4ad94edadb8710fe0e98c5169ea4a23c5f20d75b.zip
[client] enumize LectureList Filters stuff
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java170
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java7
2 files changed, 124 insertions, 53 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 c2edc99f..beb2e3f2 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
@@ -11,6 +11,8 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
@@ -25,8 +27,10 @@ import javax.swing.event.ListSelectionListener;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.LectureSummary;
+import org.openslx.bwlp.thrift.iface.UserInfo;
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.window.LectureDetailsWindow.LectureUpdatedCallback;
@@ -37,6 +41,7 @@ import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.ThriftActions;
import org.openslx.dozmod.thrift.ThriftActions.DeleteLectureCallback;
import org.openslx.dozmod.thrift.cache.LectureCache;
+import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
@@ -51,6 +56,75 @@ public class LectureListWindow extends LectureListWindowLayout {
public final LectureListWindow me = this;
+ // Filter types as an enum
+ public static enum FilterType {
+ ALL("Alle anzeigen"),
+ OWN("Nur eigene Anzeigen"),
+ ACTIVE("Nur aktive anzeigen"),
+ EDITABLE("Nur editierbare anzeigen"),
+ EXPIRING("Bald auslaufende");
+
+ private final String name;
+
+ private FilterType(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ private Pattern searchFieldPattern = null;
+
+ private final RowFilter<ListModel<LectureSummary>, Integer> filterSearchTerm = new RowFilter<ListModel<LectureSummary>, Integer>() {
+ public boolean include(Entry<? extends ListModel<LectureSummary>, ? extends Integer> entry) {
+ LectureSummary lecture = lectureTable.getModelRow(entry.getIdentifier());
+ if (searchFieldPattern.matcher(lecture.lectureName).find())
+ return true;
+ UserInfo user = UserCache.find(lecture.ownerId);
+ if (user == null)
+ return false;
+ if (searchFieldPattern.matcher(user.firstName).find())
+ return true;
+ if (searchFieldPattern.matcher(user.lastName).find())
+ return true;
+ if (searchFieldPattern.matcher(user.eMail).find())
+ return true;
+ return false;
+ }
+ };
+ // filter for own lectures
+ private final RowFilter<ListModel<LectureSummary>, Integer> filterOwn = new RowFilter<ListModel<LectureSummary>, Integer>() {
+ public boolean include(Entry<? extends ListModel<LectureSummary>, ? extends Integer> entry) {
+ return lectureTable.getModelRow(entry.getIdentifier()).ownerId.equals(Session.getUserId());
+ }
+ };
+ // filter for active lectures
+ private final RowFilter<ListModel<LectureSummary>, Integer> filterActive = new RowFilter<ListModel<LectureSummary>, Integer>() {
+ public boolean include(Entry<? extends ListModel<LectureSummary>, ? extends Integer> entry) {
+ return lectureTable.getModelRow(entry.getIdentifier()).isEnabled;
+ }
+ };
+ // filter for editable lectures
+ private final RowFilter<ListModel<LectureSummary>, Integer> filterEditable = new RowFilter<ListModel<LectureSummary>, Integer>() {
+ public boolean include(Entry<? extends ListModel<LectureSummary>, ? extends Integer> entry) {
+ return LecturePerms.canEdit(lectureTable.getModelRow(entry.getIdentifier()));
+ }
+ };
+ // filter for expiring lectures
+ private final RowFilter<ListModel<LectureSummary>, Integer> filterExpiring = new RowFilter<ListModel<LectureSummary>, Integer>() {
+ public boolean include(Entry<? extends ListModel<LectureSummary>, ? extends Integer> entry) {
+ LectureSummary selLect = lectureTable.getModelRow(entry.getIdentifier());
+ long end = selLect.getEndTime() * 1000l;
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date());
+ cal.add(Calendar.DATE, 7);
+ return cal.getTimeInMillis() > end ? true: false;
+ }
+ };
+
/**
* Popup menu items
*/
@@ -74,6 +148,17 @@ public class LectureListWindow extends LectureListWindowLayout {
@Override
public void changedUpdate(DocumentEvent e) {
// stuff
+ String str = searchTextField.getText();
+ if (str == null || str.isEmpty()) {
+ searchFieldPattern = null;
+ } else {
+ try {
+ searchFieldPattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE);
+ searchTextField.setForeground(UIManager.getColor("TextField.foreground"));
+ } catch (PatternSyntaxException ex) {
+ searchTextField.setForeground(Color.RED);
+ }
+ }
applyFilterOnTable();
}
});
@@ -240,57 +325,42 @@ public class LectureListWindow extends LectureListWindowLayout {
* Applies the filter entered in the search field to the table
*/
private void applyFilterOnTable() {
- try {
- // List for filters
- List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(3);
-
- // string for text in filter text field
- String filterField = searchTextField.getText();
- filters.add(RowFilter.regexFilter("(?i)" + filterField, 0, 1, 2));
- // filter for user (only show own)
- switch (filterCbo.getSelectedIndex()) {
- case 0:
- // no additional filters
- break;
- case 1:
- // filter for owner
- String userFilter = Session.getUserId();
- filters.add(RowFilter.regexFilter("(?i)" + userFilter, 1));
- break;
- case 2:
- // filter for editable
- RowFilter<Object, Object> editFilter = new RowFilter<Object, Object>() {
- public boolean include(Entry entry) {
- return lectureTable.getModelRow((Integer) entry.getIdentifier()).getDefaultPermissions().edit;
- }
- };
- filters.add(editFilter);
- break;
- case 3:
- // filter for soon ending lectures
- RowFilter<Object, Object> expireFilter = new RowFilter<Object, Object>() {
- public boolean include(Entry entry) {
- long endTime = lectureTable.getModelRow((Integer) entry.getIdentifier()).getEndTime() * 1000l;
- Calendar cal = Calendar.getInstance();
- cal.setTime(new Date());
- cal.add(Calendar.DATE, 7);
- return cal.getTimeInMillis() > endTime ? true: false;
- }
- };
- filters.add(expireFilter);
- break;
- default:
- break;
- }
- // for using multiple filters
- RowFilter<Object, Object> andFilters = RowFilter.andFilter(filters);
- lectureTable.getRowSorter().setRowFilter(andFilters);
-
- searchTextField.setForeground(UIManager.getColor("TextField.foreground"));
- } catch (IllegalArgumentException ex) {
- // TODO set background color of search field to something redish
- searchTextField.setForeground(Color.RED);
+ // Filter list we are about to fill
+ List<RowFilter<ListModel<LectureSummary>, Integer>> filters = new ArrayList<>();
+
+ // string for text in filter text field
+ if (searchFieldPattern != null) {
+ filters.add(filterSearchTerm);
}
+
+ // filters from the combobox
+ FilterType filterType = (FilterType) filterCbo.getSelectedItem();
+ switch (filterType) {
+ case ALL:
+ // no additional filters
+ break;
+ case OWN:
+ // filter for owner
+ filters.add(filterOwn);
+ break;
+ case ACTIVE:
+ // show only active lectures
+ filters.add(filterActive);
+ break;
+ case EDITABLE:
+ // show only editable lectures
+ filters.add(filterEditable);
+ break;
+ case EXPIRING:
+ // show only expiring lectures
+ filters.add(filterExpiring);
+ default:
+ break;
+ }
+
+ // for using multiple filters
+ RowFilter<ListModel<LectureSummary>, Integer> andFilters = RowFilter.andFilter(filters);
+ lectureTable.getRowSorter().setRowFilter(andFilters);
}
private void refreshList(final boolean force) {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java
index 0d9be1c4..ac23d07c 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java
@@ -19,6 +19,7 @@ import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.control.table.LectureTable;
import org.openslx.dozmod.gui.helper.CompositePage;
import org.openslx.dozmod.gui.helper.GridManager;
+import org.openslx.dozmod.gui.window.LectureListWindow.FilterType;
@SuppressWarnings("serial")
public abstract class LectureListWindowLayout extends CompositePage {
@@ -38,7 +39,7 @@ public abstract class LectureListWindowLayout extends CompositePage {
protected JButton deleteButton;
protected JButton editButton;
protected JButton switchViewButton;
- protected JComboBox<String> filterCbo;
+ protected JComboBox<FilterType> filterCbo;
// imageDetail texts
@@ -80,8 +81,8 @@ public abstract class LectureListWindowLayout extends CompositePage {
filterPanel.setBorder(new TitledBorder(filterPanelLabel));
filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.LINE_AXIS));
searchTextField = new JTextField();
- filterCbo = new JComboBox<String>();
- for (String s: showOwnedLabel){
+ filterCbo = new JComboBox<FilterType>();
+ for (FilterType s : FilterType.values()) {
filterCbo.addItem(s);
}
filterPanel.add(searchTextField);