Author: jflesch
Date: 2007-03-24 21:41:40 +0000 (Sat, 24 Mar 2007)
New Revision: 12347

Modified:
   trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
Log:
Reimplement the option 'go to the corresponding index' in the file list from a 
search

Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2007-03-24 
21:33:19 UTC (rev 12346)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2007-03-24 
21:41:40 UTC (rev 12347)
@@ -75,7 +75,9 @@
        private boolean sortAsc = false;


+       private thaw.plugins.index.File firstSelectedFile; /* used for the 
'goto corresponding index' option */

+
        public FileTable(final FCPQueueManager queueManager,
                         IndexBrowserPanel indexBrowser,
                         final Config config) {
@@ -178,6 +180,8 @@
        protected void updateRightClickMenu(final Vector selectedFiles) {
                FileManagementHelper.FileAction action;

+               firstSelectedFile = selectedFiles != null ? 
((thaw.plugins.index.File)selectedFiles.get(0)) : null;
+
                for(final Iterator it = rightClickActions.iterator();
                    it.hasNext();) {
                        action = (FileManagementHelper.FileAction)it.next();
@@ -264,7 +268,8 @@
                        if (selectedRows.length <= 0)
                                return;

-                       /* TODO : Re-do it :p */
+                       if (firstSelectedFile != null)
+                               
indexBrowser.selectIndex(firstSelectedFile.getParentId());

                        return;
                }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java       
2007-03-24 21:33:19 UTC (rev 12346)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java       
2007-03-24 21:41:40 UTC (rev 12347)
@@ -200,4 +200,18 @@
        }


+       /**
+        * will call IndexTree.selectIndex(id) and next tell to filetable and 
linktable
+        * to display the content of the specified index
+        */
+       public boolean selectIndex(int id) {
+               Index index = indexTree.selectIndex(id);
+
+               if (index != null) {
+                       setList(index);
+                       return true;
+               } else
+                       return false;
+       }
+
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java     2007-03-24 
21:33:19 UTC (rev 12346)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java     2007-03-24 
21:41:40 UTC (rev 12347)
@@ -1227,4 +1227,52 @@
                return e;
        }

+
+       public IndexFolder getChildFolder(int id) {
+               if (id < 0) {
+                       Logger.notice(this, "getChildFolder() : Asked me to 
have the root ?!");
+                       return null;
+               }
+
+               if (children == null)
+                       loadChildren();
+
+               for (Iterator it = children.iterator() ;
+                    it.hasNext(); ) {
+                       Object child = it.next();
+
+                       if (child instanceof IndexFolder) {
+                               if (((IndexFolder)child).getId() == id) {
+                                       return ((IndexFolder)child);
+                               }
+                       }
+               }
+
+               return null;
+       }
+
+
+       public Index getChildIndex(int id) {
+               if (id < 0) {
+                       Logger.error(this, "getChildIndex() : Invalid parameter 
!");
+                       return null;
+               }
+
+               if (children == null)
+                       loadChildren();
+
+               for (Iterator it = children.iterator() ;
+                    it.hasNext(); ) {
+                       Object child = it.next();
+
+                       if (child instanceof Index) {
+                               if (((Index)child).getId() == id) {
+                                       return ((Index)child);
+                               }
+                       }
+               }
+
+               return null;
+       }
+
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2007-03-24 
21:33:19 UTC (rev 12346)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2007-03-24 
21:41:40 UTC (rev 12347)
@@ -10,6 +10,7 @@
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.Iterator;
 import java.util.Vector;

@@ -104,6 +105,8 @@
                         final FCPQueueManager queueManager,
                         final IndexBrowserPanel indexBrowser,
                         final Config config) {
+               this.indexBrowser = indexBrowser;
+
                updatingIndexes = new Vector();

                this.queueManager = queueManager;
@@ -544,6 +547,96 @@
                }
        }

+
+
+       /**
+        * Will find the corresponding index and all its parents, then
+        * will unfold the tree according to the path to reach the index
+        * and then select the index. (won't touch filetable / linktable)
+        */
+       public Index selectIndex(int id) {
+               int nmbFolders;
+               int[] parentFolders = new int[64];
+
+               if (indexBrowser == null
+                   || indexBrowser.getDb() == null) {
+                       Logger.error(this, "selectIndex() : No access to the db 
?!");
+                       return null;
+               }
+
+               try {
+                       synchronized(indexBrowser.getDb().dbLock) {
+                               PreparedStatement st =
+                                       
indexBrowser.getDb().getConnection().prepareStatement("SELECT folderId FROM 
indexParents WHERE indexId = ?");
+
+                               st.setInt(1, id);
+
+                               ResultSet set = st.executeQuery();
+
+                               for(nmbFolders = 0 ; set.next() ; nmbFolders++) 
{
+                                       if (set.getObject("folderId") != null)
+                                               parentFolders[nmbFolders] = 
set.getInt("folderId");
+                                       else
+                                               parentFolders[nmbFolders] = -1;
+                               }
+
+                               if (nmbFolders == 0) {
+                                       Logger.error(this, "Unable to select 
specified index : Not found.");
+                                       return null;
+                               }
+                       }
+
+               } catch(SQLException e) {
+                       Logger.error(this, "Unable to select specified index 
because : "+e.toString());
+                       return null;
+               }
+
+               IndexTreeNode[] nodes = new IndexTreeNode[nmbFolders+1 /* +1 
for the index */];
+
+               nodes[0] = getRoot();
+
+               for (int i = 1 ; i < nmbFolders; i++) {
+                       IndexFolder folder= null;
+
+                       for (int j= 0 ; j < nmbFolders && folder == null; j++) {
+                               if (parentFolders[j] < 0)
+                                       continue;
+
+                               folder = 
((IndexFolder)nodes[i-1]).getChildFolder(parentFolders[j]);
+
+                       }
+
+                       nodes[i] = folder;
+
+                       if (folder == null) {
+                               Logger.error(this, "SelectIndex : Woops, 
something is missing.");
+
+                               Logger.error(this, "Path found :");
+
+                               for (int j = 0 ; j < nodes.length && nodes[j] 
!= null ; j++) {
+                                       Logger.error(this,
+                                                    " -> "
+                                                    
+Integer.toString(((IndexTreeNode)nodes[j]).getId())
+                                                    + " - "
+                                                    +nodes[j].toString());
+                               }
+
+                               return null;
+                       }
+               }
+
+               nodes[nmbFolders] = 
((IndexFolder)nodes[nmbFolders-1]).getChildIndex(id);
+
+
+               TreePath path = new TreePath(((Object[])nodes));
+
+               tree.setSelectionPath(path);
+
+               return ((Index)nodes[nmbFolders]);
+       }
+
+
+
        public class IndexTreeRenderer extends DefaultTreeCellRenderer {

                private static final long serialVersionUID = 1L;


Reply via email to