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 | |
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
3 files changed, 95 insertions, 18 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java index 5a7fd9d2..59789c75 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ImageListViewer.java @@ -39,8 +39,8 @@ public class ImageListViewer extends QLabel { private static final Logger LOGGER = Logger.getLogger(ImageListViewer.class); // search/filter components - protected JTextField searchTextField; - protected JComboBox<FilterType> filterCbo; + protected JTextField txtSearch; + protected JComboBox<FilterType> cboFilter; protected JLabel imageCountLabel; // image table @@ -123,13 +123,13 @@ public class ImageListViewer extends QLabel { JPanel filterPanel = new JPanel(); filterPanel.setBorder(new TitledBorder("Suchen")); filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.LINE_AXIS)); - searchTextField = new JTextField(); - filterCbo = new JComboBox<FilterType>(); + txtSearch = new JTextField(); + cboFilter = new JComboBox<FilterType>(); for (FilterType s : FilterType.values()) { - filterCbo.addItem(s); + cboFilter.addItem(s); } - filterPanel.add(searchTextField); - filterPanel.add(filterCbo); + filterPanel.add(txtSearch); + filterPanel.add(cboFilter); // Panel for itemCount JPanel imageCountPanel = new JPanel(); @@ -151,31 +151,31 @@ public class ImageListViewer extends QLabel { * ActionListeners */ // filter the objects in the table depending on the search field - searchTextField.getDocument().addDocumentListener(new TextChangeListener() { + txtSearch.getDocument().addDocumentListener(new TextChangeListener() { @Override public void changed() { - String str = searchTextField.getText(); + String str = txtSearch.getText(); if (str == null || str.isEmpty()) { searchFieldPattern = null; } else { try { searchFieldPattern = Pattern.compile(str, Pattern.CASE_INSENSITIVE); - searchTextField.setForeground(UIManager.getColor("TextField.foreground")); + txtSearch.setForeground(UIManager.getColor("TextField.foreground")); } catch (PatternSyntaxException ex) { - searchTextField.setForeground(Color.RED); + txtSearch.setForeground(Color.RED); } } applyFilterOnTable(); } }); - filterCbo.addActionListener(new ActionListener() { + cboFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applyFilterOnTable(); } }); - filterCbo.setSelectedItem(defaultFilter == null ? FilterType.USABLE : defaultFilter); + cboFilter.setSelectedItem(defaultFilter == null ? FilterType.USABLE : defaultFilter); } /** @@ -190,7 +190,7 @@ public class ImageListViewer extends QLabel { filters.add(filterSearchTerm); } - FilterType filterType = (FilterType) filterCbo.getSelectedItem(); + FilterType filterType = (FilterType) cboFilter.getSelectedItem(); switch (filterType) { case ALL: // all.... 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 * diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImagePublishedWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImagePublishedWindowLayout.java index 256d763f..8f69d1f4 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImagePublishedWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImagePublishedWindowLayout.java @@ -23,10 +23,10 @@ public class ImagePublishedWindowLayout extends JDialog { protected final ImagePublishedTable imagePublishedTable; private static final int ICON_SIZE_Y = 24; + protected final JTextField txtSearch; protected final JButton btnDownload; protected final JButton btnSatDownload; protected final JButton btnClose; - protected final JTextField txtSearch; private static String title = "Öffentliche VMs"; @@ -35,7 +35,6 @@ public class ImagePublishedWindowLayout extends JDialog { : ModalityType.MODELESS); GridManager grid = new GridManager(this, 1); - // --------------- filter field -------------------------------------- JPanel filterPanel = new JPanel(); filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.LINE_AXIS)); @@ -71,8 +70,8 @@ public class ImagePublishedWindowLayout extends JDialog { // --------------- end button panel ---------------------------------- // pack it all -// grid.add(filterPanel).fill(true, false).expand(true, false); -// grid.nextRow(); // TODO working search box + grid.add(filterPanel).fill(true, false).expand(true, false); + grid.nextRow(); grid.add(listPane).fill(true, true).expand(true, true); grid.nextRow(); grid.add(buttonPanel).fill(true, false).expand(true, false); |