diff options
author | Jonathan Bauer | 2016-05-12 11:37:49 +0200 |
---|---|---|
committer | Jonathan Bauer | 2016-05-12 11:37:49 +0200 |
commit | 7c284dca69f4c42ca3e188479034db107d982f77 (patch) | |
tree | 95eb7e808ebff9449b6537cc3b269066277eca7b /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java | |
parent | [client] add confirmation message before uploading an image to the masterserver (diff) | |
download | tutor-module-7c284dca69f4c42ca3e188479034db107d982f77.tar.gz tutor-module-7c284dca69f4c42ca3e188479034db107d982f77.tar.xz tutor-module-7c284dca69f4c42ca3e188479034db107d982f77.zip |
[client] add search field to the ImagePublishedWindow
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java index 0d4ea2e9..b682b081 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImagePublishedWindow.java @@ -1,5 +1,6 @@ package org.openslx.dozmod.gui.window; +import java.awt.Color; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -7,17 +8,26 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import javax.swing.JFrame; import javax.swing.JOptionPane; +import javax.swing.RowFilter; import javax.swing.SwingUtilities; +import javax.swing.UIManager; import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.bwlp.thrift.iface.Organization; +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.TextChangeListener; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.layout.ImagePublishedWindowLayout; import org.openslx.dozmod.thrift.ImagePublishedDetailsActions; @@ -26,10 +36,13 @@ import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.ThriftActions.DownloadCallback; import org.openslx.dozmod.thrift.ThriftError; import org.openslx.dozmod.thrift.cache.ImagePublishedCache; +import org.openslx.dozmod.thrift.cache.OrganizationCache; +import org.openslx.dozmod.thrift.cache.UserCache; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; +@SuppressWarnings("serial") public class ImagePublishedWindow extends ImagePublishedWindowLayout implements UiFeedback, DownloadCallback { @@ -37,8 +50,37 @@ public class ImagePublishedWindow extends ImagePublishedWindowLayout implements .getLogger(ImagePublishedWindow.class); private final ImagePublishedWindow me = this; + // Filtering: matches against image's name, user's first/last name or email and organisation name of the owner + private Pattern searchFieldPattern = null; + private final RowFilter<ListModel<ImageSummaryRead>, Integer> filterSearchTerm = new RowFilter<ListModel<ImageSummaryRead>, Integer>() { + public boolean include(Entry<? extends ListModel<ImageSummaryRead>, ? extends Integer> entry) { + // match against image names first + ImageSummaryRead image = imagePublishedTable.getModelRow(entry.getIdentifier()); + if (searchFieldPattern.matcher(image.imageName).find()) + return true; + // match against users + UserInfo user = UserCache.find(image.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; + // match against organizations + Organization org = OrganizationCache.find(user); + if (org == null) + return false; + if (searchFieldPattern.matcher(org.displayName).find()) + return true; + return false; + } + }; + public ImagePublishedWindow(Frame modalParent) { super(modalParent); + // Hook when user presses X (top right) setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @@ -47,12 +89,14 @@ public class ImagePublishedWindow extends ImagePublishedWindowLayout implements dispose(); } }); + btnClose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); + btnSatDownload.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -73,6 +117,7 @@ public class ImagePublishedWindow extends ImagePublishedWindowLayout implements false); } }); + btnDownload.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -88,6 +133,24 @@ public class ImagePublishedWindow extends ImagePublishedWindowLayout implements } }); + txtSearch.getDocument().addDocumentListener(new TextChangeListener() { + @Override + public void changed() { + String str = txtSearch.getText(); + if (str == null || str.isEmpty()) { + searchFieldPattern = null; + } else { + try { + searchFieldPattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE); + txtSearch.setForeground(UIManager.getColor("TextField.foreground")); + } catch (PatternSyntaxException ex) { + txtSearch.setForeground(Color.RED); + } + } + applyFilterOnTable(); + } + }); + imagePublishedTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -127,7 +190,22 @@ public class ImagePublishedWindow extends ImagePublishedWindowLayout implements // init data refreshList(true, 0); } + /** + * Called when a change occurs in the filter search field + */ + private void applyFilterOnTable() { + // List for filters + List<RowFilter<ListModel<ImageSummaryRead>, Integer>> filters = new ArrayList<>(); + + // string for text in filter text field + if (searchFieldPattern != null) { + filters.add(filterSearchTerm); + } + // for using multiple filters if we need it one day + RowFilter<ListModel<ImageSummaryRead>, Integer> andFilters = RowFilter.andFilter(filters); + imagePublishedTable.getRowSorter().setRowFilter(andFilters); + } /** * Callback when download initialized * |