Author: jflesch
Date: 2007-07-23 16:50:29 +0000 (Mon, 23 Jul 2007)
New Revision: 14281
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
Log:
Implement search in the messages
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
2007-07-23 15:57:05 UTC (rev 14280)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MessageTreeTable.java
2007-07-23 16:50:29 UTC (rev 14281)
@@ -50,6 +50,7 @@
import thaw.core.Logger;
import thaw.plugins.miniFrost.interfaces.Board;
+import thaw.plugins.miniFrost.interfaces.BoardFactory;
import thaw.plugins.miniFrost.interfaces.Message;
@@ -98,10 +99,16 @@
private JComboBox actions;
+ private int orderBy;
+ private boolean desc;
+
public MessageTreeTable(MiniFrostPanel mainPanel) {
this.mainPanel = mainPanel;
+ orderBy = Board.ORDER_DATE;
+ desc = true;
+
panel = new JPanel(new BorderLayout(5, 5));
@@ -114,6 +121,10 @@
searchButton = new
JButton(I18n.getMessage("thaw.common.search"),
IconBox.minSearch);
+ searchButton.addActionListener(this);
+ searchField.addActionListener(this);
+
+
nextUnread = new JButton("", IconBox.minNextUnread);
nextUnread.setToolTipText(I18n.getMessage("thaw.plugin.miniFrost.nextUnread"));
nextUnread.addActionListener(this);
@@ -325,6 +336,9 @@
public void setBoard(Board board) {
this.targetBoard = board;
+
+ searchField.setText("");
+ everywhereBox.setSelected(false);
}
public Board getBoard() {
@@ -332,8 +346,30 @@
}
public void refresh() {
- if (targetBoard != null)
- model.setMessages(targetBoard.getMessages());
+ refresh(null, Board.ORDER_DATE, true, false);
+ }
+
+ public void refresh(String[] keywords, int orderBy, boolean desc,
boolean allBoards) {
+ Vector msgs = null;
+
+ if ((!allBoards) && targetBoard != null) {
+ msgs = targetBoard.getMessages(keywords, orderBy, desc);
+ }
+
+ if (allBoards) {
+ msgs = new Vector();
+
+ BoardFactory[] factories =
mainPanel.getPluginCore().getFactories();
+
+ for (int i = 0 ; i < factories.length ; i++) {
+ Vector boardMsgs =
factories[i].getAllMessages(keywords, orderBy, desc);
+ msgs.addAll(boardMsgs);
+ }
+ }
+
+ if (msgs != null)
+ model.setMessages(msgs);
+
model.refresh();
}
@@ -356,8 +392,17 @@
public void actionPerformed(ActionEvent e) {
- if (e.getSource() == nextUnread) {
+ if (e.getSource() == searchButton
+ || e.getSource() == searchField) {
+ String[] keywords = searchField.getText().split(" ");
+
+ Logger.info(this, "Searching ...");
+
+ refresh(keywords, orderBy, desc,
everywhereBox.isSelected());
+
+ } else if (e.getSource() == nextUnread) {
+
if (targetBoard == null) {
Logger.warning(this, "No message selected atm ;
can't get the next unread message");
return;
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-07-23 15:57:05 UTC (rev 14280)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2007-07-23 16:50:29 UTC (rev 14281)
@@ -13,9 +13,10 @@
import thaw.core.Logger;
import thaw.plugins.Hsqldb;
+import thaw.plugins.miniFrost.interfaces.Board;
public class KSKBoard
- implements thaw.plugins.miniFrost.interfaces.Board, Runnable, Observer {
+ implements Board, Runnable, Observer {
public final static int MAX_DOWNLOADS_AT_THE_SAME_TIME = 5;
public final static int MAX_FAILURES_IN_A_ROW = 5;
@@ -42,7 +43,11 @@
private int newMsgs;
+ private KSKBoard() {
+ }
+
+
public KSKBoard(KSKBoardFactory factory,
int id, String name,
Date lastUpdate,
@@ -58,7 +63,49 @@
}
- public Vector getMessages() {
+ public Vector getMessages(String[] keywords,
+ int orderBy,
+ boolean desc) {
+ return getMessages(id, factory, this, keywords, orderBy, desc,
false);
+ }
+
+
+ protected static Vector getMessages(int id,
+ KSKBoardFactory factory,
+ KSKBoard board,
+ String[] keywords,
+ int orderBy,
+ boolean desc,
+ boolean allBoards) {
+
+ String orderColumn;
+
+ if (orderBy == Board.ORDER_SUBJECT)
+ orderColumn = "LOWER(subject)";
+ else if (orderBy == Board.ORDER_SENDER)
+ orderColumn = "LOWER(nick)";
+ else
+ orderColumn = "date";
+
+ if (desc)
+ orderColumn += " DESC";
+
+ String whereBase = "WHERE true AND ";
+
+ if (!allBoards) {
+ whereBase = "WHERE boardId = ? AND ";
+ }
+
+ String keywordsStr = "";
+
+ if (keywords != null) {
+ for (int i = 0 ; i < keywords.length ; i++) {
+ keywordsStr += " AND (LOWER(subject) LIKE ? "+
+ " OR LOWER(content) LIKE ? "+
+ " OR LOWER(nick) LIKE ?)";
+ }
+ }
+
Vector v = new Vector();
try {
@@ -67,18 +114,41 @@
synchronized(db.dbLock) {
PreparedStatement st;
- st =
db.getConnection().prepareStatement("SELECT id, subject, nick, "+
- "
sigId, date, rev, "+
- "
read "+
+ st =
db.getConnection().prepareStatement("SELECT id, "+
+ "
subject, "+
+ "
nick, "+
+ "
sigId, "+
+ "
date, "+
+ "
rev, "+
+ "
read, "+
+ "
boardId "+
"FROM
frostKSKMessages "+
- "WHERE
boardId = ? AND "+
+
whereBase+
"archived = FALSE "+
- "ORDER
BY date DESC");
- st.setInt(1, id);
+
keywordsStr+
+ "ORDER
BY "+orderColumn);
+ int i = 1;
+ if (!allBoards)
+ st.setInt(i++, id);
+
+ if (keywords != null) {
+ for (int j = 0 ; j < keywords.length ;
j++) {
+ String word =
keywords[j].toLowerCase();
+
+ st.setString(i++, "%"+word+"%");
+ st.setString(i++, "%"+word+"%");
+ st.setString(i++, "%"+word+"%");
+ }
+ }
+
ResultSet set = st.executeQuery();
while(set.next()) {
+ KSKBoard daBoard = ((board != null) ?
+ board :
+
factory.getBoard(set.getInt("boardId")));
+
v.add(new KSKMessage(set.getInt("id"),
set.getString("subject"),
set.getString("nick"),
@@ -87,12 +157,12 @@
set.getInt("rev"),
set.getBoolean("read"),
false,
- this));
+ daBoard));
}
}
} catch(SQLException e) {
- Logger.error(this, "Can't get message list because :
"+e.toString());
+ Logger.error(new KSKBoard(), "Can't get message list
because : "+e.toString());
}
return v;
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-23 15:57:05 UTC (rev 14280)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-23 16:50:29 UTC (rev 14281)
@@ -6,6 +6,7 @@
import java.sql.*;
import java.util.HashMap;
+import java.util.Iterator;
import thaw.core.Core;
import thaw.core.Logger;
@@ -14,6 +15,8 @@
import thaw.plugins.Hsqldb;
import thaw.plugins.MiniFrost;
+
+
public class KSKBoardFactory
implements thaw.plugins.miniFrost.interfaces.BoardFactory {
@@ -149,6 +152,30 @@
}
+ protected KSKBoard getBoard(String name) {
+ return (KSKBoard)boards.get(name);
+ }
+
+
+ protected KSKBoard getBoard(int id) {
+ for (Iterator it = boards.values().iterator();
+ it.hasNext();) {
+ KSKBoard board = (KSKBoard)it.next();
+
+ if (board.getId() == id)
+ return board;
+ }
+
+ return null;
+ }
+
+
+ public Vector getAllMessages(String[] keywords, int orderBy, boolean
desc) {
+ return KSKBoard.getMessages(-1, this, null, keywords, orderBy,
desc, true);
+ }
+
+
+
public void createBoard(thaw.core.MainWindow mainWindow) {
String name =
JOptionPane.showInputDialog(mainWindow.getMainFrame(),
I18n.getMessage("thaw.plugin.miniFrost.boardName"),
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
2007-07-23 15:57:05 UTC (rev 14280)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/Board.java
2007-07-23 16:50:29 UTC (rev 14281)
@@ -29,11 +29,20 @@
//public BoardFolder getParentFolder();
+ public final static int ORDER_SUBJECT = 0;
+ public final static int ORDER_SENDER = 1;
+ public final static int ORDER_DATE = 2;
+
/**
* don't store/cache the messages,
* just give them.
+ * @param keywords can be null
+ * @param orderBy specify an order
+ * @param desc
*/
- public Vector getMessages();
+ public Vector getMessages(String[] keywords,
+ int orderBy,
+ boolean desc);
/**
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
2007-07-23 15:57:05 UTC (rev 14280)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
2007-07-23 16:50:29 UTC (rev 14281)
@@ -16,6 +16,7 @@
public boolean init(Hsqldb db, thaw.core.Core core,
MiniFrost miniFrost);
+
/**
* @return all the boards managed by this factory
*/
@@ -23,6 +24,12 @@
/**
+ * similar to Board.getMessages()
+ * @param orderBy see Board
+ */
+ public Vector getAllMessages(String[] keywords, int orderBy, boolean
desc);
+
+ /**
* display the dialog asking for a name, etc.
* the tree will be reloaded after that
*/