Author: jflesch
Date: 2006-10-20 21:47:59 +0000 (Fri, 20 Oct 2006)
New Revision: 10684

Modified:
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/plugins/index/File.java
   trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java
   trunk/apps/Thaw/src/thaw/plugins/index/Link.java
   trunk/apps/Thaw/src/thaw/plugins/index/Tables.java
Log:
Add an option to find quickly the index corresponding to a file

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-10-20 20:43:03 UTC 
(rev 10683)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-10-20 21:47:59 UTC 
(rev 10684)
@@ -235,3 +235,5 @@
 thaw.plugin.index.linkList=Link list

 thaw.plugin.index.selectIndex=Select an index or specify the key
+
+thaw.plugin.index.gotoIndex=Go to the corresponding index

Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-10-20 20:43:03 UTC 
(rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-10-20 21:47:59 UTC 
(rev 10684)
@@ -29,6 +29,7 @@
        private FCPTransferQuery transfer = null; /* can be null */

        private Index parent;
+       private int parentId;

        private Hsqldb db;

@@ -49,7 +50,7 @@
                size = (new java.io.File(path)).length();

                this.category = category;
-               this.parent = parent;
+               setParent(parent);

                if(transfer != null)
                        ((java.util.Observable)transfer).addObserver(this);
@@ -63,6 +64,7 @@
                publicKey = resultSet.getString("publicKey");
                localPath = resultSet.getString("localPath");
                size = resultSet.getLong("size");
+               parentId = resultSet.getInt("indexParent");
                //category = resultSet.getString("category");

                deduceFilenameFromKey();
@@ -114,12 +116,20 @@

        public void setParent(Index parent) {
                this.parent = parent;
+               if (parent != null)
+                       this.parentId = parent.getId();
+               else
+                       this.parentId = -1;
        }

        public Index getParent() {
                return parent;
        }

+       public int getParentId() {
+               return parentId;
+       }
+
        public String getFilename() {
                return fileName;
        }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-10-20 
20:43:03 UTC (rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-10-20 
21:47:59 UTC (rev 10684)
@@ -71,6 +71,8 @@

        private JMenuItem copyFileKeys;

+       private JMenuItem gotoIndex;
+
        private FCPQueueManager queueManager;

        private String sortColumn = null;
@@ -78,10 +80,16 @@

        private int[] selectedRows;

-       public FileTable(boolean modifiables, FCPQueueManager queueManager) {
+       private Config config;
+       private Tables tables;
+       private IndexTree tree;
+
+       public FileTable(boolean modifiables, FCPQueueManager queueManager, 
IndexTree tree, Config config, Tables tables) {
                this.queueManager = queueManager;
-
+               this.config = config;
                this.modifiables = modifiables;
+               this.tables = tables;
+               this.tree = tree;


                rightClickMenu = new JPopupMenu();
@@ -106,6 +114,11 @@
                copyFileKeys.addActionListener(this);
                rightClickMenu.add(copyFileKeys);

+               gotoIndex = new 
JMenuItem(I18n.getMessage("thaw.plugin.index.gotoIndex"));
+               gotoIndex.addActionListener(this);
+               gotoIndex.setEnabled(false);
+               rightClickMenu.add(gotoIndex);
+
                fileListModel = new FileListModel();
                table = new JTable(fileListModel);
                table.setShowGrid(true);
@@ -149,6 +162,8 @@
        public void mouseClicked(MouseEvent e) {
                if(e.getButton() == MouseEvent.BUTTON3
                   && fileList != null) {
+                       gotoIndex.setEnabled(!(fileList instanceof Index));
+
                        selectedRows = table.getSelectedRows();
                        rightClickMenu.show(e.getComponent(), e.getX(), 
e.getY());
                }
@@ -178,8 +193,44 @@

                java.io.File destination = null;

+               if (e.getSource() == gotoIndex) {
+                       if (selectedRows.length <= 0)
+                               return;
+
+                       thaw.plugins.index.File file = 
(thaw.plugins.index.File)fileList.getFileList().get(selectedRows[0]);
+
+                       if (file.getParentId() == -1) {
+                               Logger.notice(this, "No parent ? abnormal");
+                               return;
+                       }
+
+                       Index parent = 
tree.getRoot().getIndex(file.getParentId());
+
+                       if (parent == null) {
+                               Logger.notice(this, "Cannot find again the 
parent ?! Id: "+Integer.toString(file.getParentId()));
+                               return;
+                       }
+                       
+                       tables.setList(parent);
+
+                       int row;
+                       
+                       row = parent.getFilePosition(file);
+
+                       if (row < 0)
+                               Logger.notice(this, "File not found in the 
index ?! Index : "+parent.getKey()+" ; File: " +file.getPublicKey());
+                       else
+                               setSelectedRows(row, row);
+
+                       return;
+               }
+
                if(e.getSource() == downloadFiles) {
-                       FileChooser fileChooser = new FileChooser();
+                       FileChooser fileChooser ;
+                       if (config.getValue("lastDestinationDirectory") == null)
+                               fileChooser = new FileChooser();
+                       else
+                               fileChooser = new 
FileChooser(config.getValue("lastDestinationDirectory"));
                        
fileChooser.setTitle(I18n.getMessage("thaw.plugin.fetch.destinationDirectory"));
                        fileChooser.setDirectoryOnly(true);
                        fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
@@ -188,6 +239,8 @@

                        if(destination == null)
                                return;
+
+                       config.setValue("lastDestinationDirectory", 
destination.getPath());
                }

                if(e.getSource() == removeFiles) {
@@ -260,6 +313,11 @@
                        cp.setContents(st, null);
                }
        }
+
+
+       public void setSelectedRows(int min, int max) {
+               table.setRowSelectionInterval(min, max);
+       }


        public class FileListModel extends javax.swing.table.AbstractTableModel 
implements java.util.Observer {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-10-20 20:43:03 UTC 
(rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-10-20 21:47:59 UTC 
(rev 10684)
@@ -101,10 +101,18 @@
                this.parent = parent;
        }

+       public IndexCategory getParent() {
+               return parent;
+       }
+
        public DefaultMutableTreeNode getTreeNode() {
                return treeNode;
        }

+       public Index getIndex(int id) {
+               return (id == getId()) ? this : null;
+       }
+
        public void generateKeys(FCPQueueManager queueManager) {
                publicKey = "N/A";
                privateKey = "N/A";
@@ -469,7 +477,7 @@
                fileList = new Vector();

                try {
-                       String query = "SELECT id, publicKey, mime, size, 
localPath, category FROM files WHERE indexParent = ?";
+                       String query = "SELECT id, publicKey, mime, size, 
localPath, category, indexParent FROM files WHERE indexParent = ?";

                        if(columnToSort != null) {
                                query = query + "ORDER BY " + columnToSort;
@@ -519,7 +527,31 @@
                return (thaw.plugins.index.File)fileList.get(index);
        }

+       public int getFilePosition(thaw.plugins.index.File fileA) {
+               int pos = fileList.indexOf(fileA);

+               if (fileA.getPublicKey() == null)
+                       return -1;
+
+               if (pos < 0) {
+                       /* Manual research */
+                       pos = 0;
+                       for(Iterator it = fileList.iterator();
+                           it.hasNext();) {
+                               thaw.plugins.index.File fileB = 
(thaw.plugins.index.File)it.next();
+
+                               if (fileB.getPublicKey() != null
+                                   && 
fileB.getPublicKey().equals(fileA.getPublicKey()))
+                                       return pos;
+                               pos++;
+
+                       }
+               }
+
+               return -1;
+       }
+
+
        public void unloadFiles() {
                /*
                for(Iterator it = fileList.iterator();
@@ -891,7 +923,12 @@

        public String getHeaderElement(Element header, String name) {
                try {
-                       Element sub = 
(Element)header.getElementsByTagName(name).item(0);
+                       NodeList nl = header.getElementsByTagName(name);
+
+                       if (nl == null)
+                               return null;
+
+                       Element sub = (Element)nl.item(0);
                        return ((Text)sub.getFirstChild()).getData();
                } catch(Exception e) {
                        Logger.notice(this, "Unable to get header element 
'"+name+"', because: "+e.toString());

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java   2006-10-20 
20:43:03 UTC (rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java   2006-10-20 
21:47:59 UTC (rev 10684)
@@ -372,6 +372,9 @@

        public Vector getIndexIds()
        {
+               if(children == null)
+                       children = loadChildren();
+
                Vector result = new Vector();

                for(Iterator it = children.iterator();
@@ -383,6 +386,24 @@
                return result;
        }

+
+       public Index getIndex(int id)
+       {
+               if(children == null)
+                       children = loadChildren();
+
+               for(Iterator it = children.iterator();
+                   it.hasNext();) {
+                       IndexTreeNode node = 
(IndexTreeNode)((DefaultMutableTreeNode)it.next()).getUserObject();
+                       Index result = node.getIndex(id);
+                       if (result != null)
+                               return result;
+               }
+               
+               return null;
+       }
+
+
        public boolean isLeaf() {
                return false;
        }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2006-10-20 
20:43:03 UTC (rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2006-10-20 
21:47:59 UTC (rev 10684)
@@ -225,6 +225,9 @@
                return tree;
        }

+       public IndexCategory getRoot() {
+               return root;
+       }

        public void mouseClicked(MouseEvent e) {
                notifySelection(e);

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java   2006-10-20 
20:43:03 UTC (rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java   2006-10-20 
21:47:59 UTC (rev 10684)
@@ -52,5 +52,7 @@

        public Vector getIndexIds();

+       public Index getIndex(int id);
+
        public void addObserver(java.util.Observer o);
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Link.java    2006-10-20 20:43:03 UTC 
(rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java    2006-10-20 21:47:59 UTC 
(rev 10684)
@@ -23,7 +23,10 @@

        public Link(Hsqldb hsqldb, String indexName, String key, Index parent) {
                this.indexName = indexName;
-               this.key = key;
+               if (key != null)
+                       this.key = key.trim();
+               else
+                       this.key = null;
                this.parent = parent;
                this.db = hsqldb;
        }
@@ -46,6 +49,9 @@
                this.db = hsqldb;
                this.key = linkElement.getAttribute("key");

+               if (this.key != null)
+                       this.key = this.key.trim();
+
                this.indexName = Index.getNameFromKey(this.key);

                this.parent = parent;
@@ -70,6 +76,9 @@
        public void setIndexKey(String key) {
                this.key = key;

+               if (this.key != null)
+                       this.key = this.key.trim();
+
                setChanged();
                notifyObservers();
        }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Tables.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Tables.java  2006-10-20 20:43:03 UTC 
(rev 10683)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Tables.java  2006-10-20 21:47:59 UTC 
(rev 10684)
@@ -28,15 +28,15 @@
                panel = new JPanel();
                panel.setLayout(new BorderLayout(10, 10));

-               fileTable = new FileTable(modifiables, queueManager);
+               fileTable = new FileTable(modifiables, queueManager, tree, 
config, this);
                linkTable = new LinkTable(modifiables, db, queueManager, tree);

                searchBar = new SearchBar(db, tree, queueManager, this);

                split = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
-                                        linkTable.getPanel(),
+                                      linkTable.getPanel(),
                                       fileTable.getPanel());
-
+               
                panel.add(searchBar.getPanel(), BorderLayout.NORTH);
                panel.add(split, BorderLayout.CENTER);
        }


Reply via email to