Author: jflesch
Date: 2006-10-08 20:21:05 +0000 (Sun, 08 Oct 2006)
New Revision: 10650

Added:
   trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java
Modified:
   trunk/apps/Thaw/src/thaw/core/Logger.java
   trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
   trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
   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/IndexBrowserPanel.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.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/LinkTable.java
   trunk/apps/Thaw/src/thaw/plugins/index/Tables.java
Log:
It is now possible to make links to other file indexes

Modified: trunk/apps/Thaw/src/thaw/core/Logger.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Logger.java   2006-10-08 17:20:46 UTC (rev 
10649)
+++ trunk/apps/Thaw/src/thaw/core/Logger.java   2006-10-08 20:21:05 UTC (rev 
10650)
@@ -94,10 +94,10 @@
         * As it. Similar to verbose()
         */
        public static void asIt(Object o, String msg) {
-               //if(LOG_LEVEL >= 5) {
+               if(LOG_LEVEL >= 5) {
                        System.out.println(msg);
                        notifyLogListeners(msg);
-                       //}
+               }
        }



Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2006-10-08 17:20:46 UTC 
(rev 10649)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2006-10-08 20:21:05 UTC 
(rev 10650)
@@ -217,17 +217,20 @@
                                        status = "Available";
                                        fileSize = (new 
Long(message.getValue("DataLength"))).longValue();

-                                       progress = 100;
-                                       running = false;
-                                       successful = true;
-                                       
                                        if(isPersistent()) {
                                                if(destinationDir != null) {

                                                        
if(!fileExists(destinationDir)) {
+                                                               progress = 99;
+                                                               running = true;
+                                                               successful = 
false;
                                                                
saveFileTo(destinationDir);
-                                                       } else
+                                                       } else {
+                                                               progress = 100;
+                                                               running = false;
+                                                               successful = 
true;
                                                                
Logger.info(this, "File already existing. Not rewrited");
+                                                       }

                                                } else {
                                                        Logger.info(this, 
"Don't know where to put file, so file not asked to the node");

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java      2006-10-08 17:20:46 UTC 
(rev 10649)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java      2006-10-08 20:21:05 UTC 
(rev 10650)
@@ -577,6 +577,15 @@
                                running = false;

                                publicKey = msg.getValue("URI");
+
+                               if (publicKey == null) {
+                                       status = "[Warning]";
+                                       Logger.warning(this, "PutSuccessful 
message without URI field ?!");
+                                       setChanged();
+                                       notifyObservers();
+                                       return;
+                               }
+
                                publicKey = publicKey.replaceAll("freenet:", 
"");

                                if(keyType == 1)

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-10-08 17:20:46 UTC 
(rev 10649)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-10-08 20:21:05 UTC 
(rev 10650)
@@ -201,6 +201,7 @@
 thaw.plugin.index.indexes=Indexes

 thaw.plugin.index.addIndex=Add a file index
+thaw.plugin.index.addIndexFromLink=Add this index to your list
 thaw.plugin.index.createIndex=Create a file index
 thaw.plugin.index.addCategory=Add a folder
 thaw.plugin.index.rename=Rename

Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-10-08 17:20:46 UTC 
(rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java    2006-10-08 20:21:05 UTC 
(rev 10650)
@@ -73,7 +73,7 @@
        public File(Hsqldb db, Element fileElement, Index parent) {
                this.db = db;

-               id = Integer.parseInt(fileElement.getAttribute("id"));
+               id = Integer.parseInt(fileElement.getAttribute("id")); /* will 
be changed when inserted in the database */
                publicKey = fileElement.getAttribute("key");

                localPath = null;
@@ -290,8 +290,10 @@


        public Element getXML(Document xmlDoc) {
-               if(getPublicKey() == null)
+               if(getPublicKey() == null) {
+                       Logger.notice(this, "No public key for file 
'"+fileName+"' => not added to the index");
                        return null;
+               }

                Element file = xmlDoc.createElement("file");


Added: trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java 2006-10-08 
17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java 2006-10-08 
20:21:05 UTC (rev 10650)
@@ -0,0 +1,5 @@
+package thaw.plugins.index;
+
+public interface FileAndLinkList extends FileList, LinkList {
+
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-10-08 
17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2006-10-08 
20:21:05 UTC (rev 10650)
@@ -358,7 +358,6 @@
                }

                public void refresh(TableModelEvent e) {
-
                        fireTableChanged(e);
                }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-10-08 17:20:46 UTC 
(rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2006-10-08 20:21:05 UTC 
(rev 10650)
@@ -33,7 +33,7 @@
 import thaw.plugins.Hsqldb;
 import thaw.core.*;

-public class Index extends java.util.Observable implements FileList, LinkList, 
IndexTreeNode, java.util.Observer {
+public class Index extends java.util.Observable implements FileAndLinkList, 
IndexTreeNode, java.util.Observer {

        private Hsqldb db;
        private IndexTree tree;
@@ -94,6 +94,10 @@
                treeNode.setUserObject(this);
        }

+       public void setParent(IndexCategory parent) {
+               this.parent = parent;
+       }
+
        public DefaultMutableTreeNode getTreeNode() {
                return treeNode;
        }
@@ -137,7 +141,7 @@

                        st.setInt(8, revision);

-                       if(parent.getId() >= 0)
+                       if(parent != null && parent.getId() >= 0)
                                st.setInt(9, parent.getId());
                        else
                                st.setNull(9, Types.INTEGER);
@@ -183,8 +187,8 @@

        public void delete() {
                try {
-                       loadFiles(null, false);
-                       loadLinks(null, false);
+                       loadFiles(null, true);
+                       loadLinks(null, true);

                        for(Iterator fileIt = fileList.iterator(); 
fileIt.hasNext(); ) {
                                thaw.plugins.index.File file = 
(thaw.plugins.index.File)fileIt.next();
@@ -205,6 +209,23 @@
                }
        }

+
+       protected String changeRevision(String key, int move) {
+               try {
+                       String newKey;
+                       String[] split = key.split("/");
+                       newKey = split[0] + "/" + split[1] + "/"
+                               + 
Integer.toString(Integer.parseInt(split[2])+move) + "/"
+                               + split[3];
+                       
+               } catch (Exception e) {
+                       Logger.warning(this, "Unable to add a revision to the 
key '"+key+"' because : "+e.toString());
+               }
+
+               return key;
+       }
+
+
        public void update() {
                targetFile = new java.io.File(toString()+".xml");

@@ -235,7 +256,7 @@

                        Logger.info(this, "Getting last version");

-                       clientGet = new FCPClientGet(publicKey, 4, 2, false, 
System.getProperty("java.io.tmpdir"));
+                       clientGet = new FCPClientGet(changeRevision(publicKey, 
1), 4, 2, false, System.getProperty("java.io.tmpdir"));
                        transfer = clientGet;
                        clientGet.addObserver(this);

@@ -257,6 +278,7 @@
                        PreparedStatement st = c.prepareStatement("DELETE FROM 
links WHERE indexParent = ?");
                        st.setInt(1, getId());
                        st.execute();
+                       linkList = new Vector();
                } catch(SQLException e) {
                        Logger.warning(this, "Unable to purge da list ! 
Exception: "+e.toString());
                }
@@ -268,6 +290,7 @@
                        PreparedStatement st = c.prepareStatement("DELETE FROM 
files WHERE indexParent = ?");
                        st.setInt(1, getId());
                        st.execute();
+                       fileList = new Vector();
                } catch(SQLException e) {
                        Logger.warning(this, "Unable to purge da list ! 
Exception: "+e.toString());
                }
@@ -383,8 +406,10 @@
        ////// FILE LIST ////////

        public void loadFiles(String columnToSort, boolean asc) {
-               if(fileList != null)
+               if(fileList != null) {
+                       Logger.notice(this, "Files already loaded, won't reload 
them");
                        return;
+               }

                fileList = new Vector();

@@ -520,8 +545,10 @@

        public void loadLinks(String columnToSort, boolean asc)
        {
-               if(linkList != null)
+               if(linkList != null) {
+                       Logger.notice(this, "Links aleady loaded, won't reload 
...");
                        return;
+               }

                linkList = new Vector();

@@ -543,10 +570,8 @@
                                ResultSet results = st.getResultSet();

                                while(results.next()) {
-                                       String[] split = publicKey.split("/");
                                        try {
-                                               String indexName = 
split[split.length-2];
-                                               Link link = new Link(db, 
indexName, publicKey, this);
+                                               Link link = new Link(db, 
results, this);
                                                linkList.add(link);
                                        } catch(Exception e) {
                                                Logger.warning(this, "Unable to 
add index '"+publicKey+"' to the list because: "+e.toString());
@@ -683,6 +708,22 @@
        public Element getXMLLinks(Document xmlDoc) {
                Element links = xmlDoc.createElement("indexes");

+               if (linkList == null) {
+                       loadLinks(null, true);
+               }
+
+               for (Iterator it = getLinkList().iterator();
+                    it.hasNext();) {
+                       Link link = (Link)it.next();
+
+                       Element xmlLink = link.getXML(xmlDoc);
+
+                       if (xmlLink != null)
+                               links.appendChild(xmlLink);
+                       else
+                               Logger.warning(this, "Unable to get XML for the 
link '"+link.getIndexName()+"' => Gruick da link");
+               }
+
                return links;
        }

@@ -769,14 +810,14 @@
                        if(list.item(i).getNodeType() == Node.ELEMENT_NODE) {
                                Element e = (Element)list.item(i);

-                               /* TODO : Links */
+                               Link link = new Link(db, e, this);
+                               addLink(link);
                        }
                }

        }

        public void loadFileList(Element rootEl) {
-               fileList = new Vector();
                purgeFileList();

                Element filesEl = 
(Element)rootEl.getElementsByTagName("files").item(0);
@@ -792,4 +833,18 @@
                }
        }

+
+       static String getNameFromKey(String key) {
+               String name = null;
+               try {
+                       String[] cutcut = key.split("/");
+                       name = cutcut[cutcut.length-1];
+                       name = name.replaceAll(".xml", "");
+               } catch (Exception e) {
+                       Logger.warning(e, "thaw.plugins.index.Index: Error 
while parsing index key: "+key+" because: "+e.toString() );
+                       name = key;
+               }
+               return name;
+       }
+
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java       
2006-10-08 17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java       
2006-10-08 20:21:05 UTC (rev 10650)
@@ -1,4 +1,4 @@
-package thaw.plugins;
+package thaw.plugins.index;

 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
@@ -17,7 +17,7 @@
 import thaw.core.*;
 import thaw.fcp.*;

-import thaw.plugins.index.*;
+import thaw.plugins.Hsqldb;


 public class IndexBrowserPanel implements 
javax.swing.event.TreeSelectionListener, ActionListener {
@@ -44,7 +44,7 @@
                listAndDetails = new JPanel();
                listAndDetails.setLayout(new BorderLayout(10, 10));

-               tables = new Tables(false, queueManager);
+               tables = new Tables(false, db, queueManager, indexTree);
                fileDetails = new FileDetailsEditor(false);

                listAndDetails.add(tables.getPanel(), BorderLayout.CENTER);
@@ -65,18 +65,29 @@
        public void save() {
                indexTree.save();
        }
+
+
+       protected void setList(FileAndLinkList l) {
+               setFileList(l);
+               setLinkList(l);
+       }

        protected void setFileList(FileList l) {
                tables.getFileTable().setFileList(l);           
        }
+
+       protected void setLinkList(LinkList l) {
+               tables.getLinkTable().setLinkList(l);
+       }


        public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                javax.swing.tree.TreePath path = e.getPath();
-               
+
+               setList(null);
+
                if(path == null) {
                        Logger.notice(this, "Path null ?");
-                       setFileList(null);
                        return;
                }

@@ -84,17 +95,19 @@

                if(node == null) {
                        Logger.notice(this, "Node null ?");
-                       setFileList(null);
                        return;
                }

-               if(node instanceof FileList) {
+               if (node instanceof FileList) {
                        Logger.info(this, "FileList !");
                        setFileList((FileList)node);
-                       return;
                }
-               
-               setFileList(null);
+
+               if (node instanceof LinkList) {
+                       Logger.info(this, "LinkList !");
+                       setLinkList((LinkList)node);
+               }
+
        }



Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java   2006-10-08 
17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java   2006-10-08 
20:21:05 UTC (rev 10650)
@@ -48,6 +48,10 @@

        }

+       public void setParent(IndexCategory parent) {
+               this.parent = parent;
+       }
+
        public DefaultMutableTreeNode getTreeNode() {
                return this;
        }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java        
2006-10-08 17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java        
2006-10-08 20:21:05 UTC (rev 10650)
@@ -1,4 +1,4 @@
-package thaw.plugins;
+package thaw.plugins.index;

 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
@@ -19,7 +19,9 @@

 import thaw.plugins.index.*;

+import thaw.plugins.Hsqldb;

+
 public class IndexEditorPanel implements java.util.Observer, 
javax.swing.event.TreeSelectionListener, ActionListener {
        public final static int DEFAULT_INSERTION_PRIORITY = 4;

@@ -36,7 +38,8 @@
        private JButton insertAndAddButton;
        private JButton linkButton;

-       private FileList fileList = null;
+       private FileList fileList = null; /* Index or SearchResult object */
+       private LinkList linkList = null;

        private Hsqldb db;
        private FCPQueueManager queueManager;
@@ -48,12 +51,6 @@

                indexTree = new 
IndexTree(I18n.getMessage("thaw.plugin.index.yourIndexes"), true, false, 
queueManager, db);

-               listAndDetails = new JPanel();
-               listAndDetails.setLayout(new BorderLayout(0, 0));
-
-               tables = new Tables(true, queueManager);
-               fileDetails = new FileDetailsEditor(true);
-
                toolBar = new JToolBar();
                toolBar.setFloatable(false);

@@ -75,6 +72,12 @@
                toolBar.addSeparator();
                toolBar.add(linkButton);

+               tables = new Tables(true, db, queueManager, indexTree);
+               fileDetails = new FileDetailsEditor(true);
+
+               listAndDetails = new JPanel();
+               listAndDetails.setLayout(new BorderLayout(0, 0));
+
                listAndDetails.add(toolBar, BorderLayout.NORTH);
                listAndDetails.add(tables.getPanel(), BorderLayout.CENTER);
                listAndDetails.add(fileDetails.getPanel(), BorderLayout.SOUTH);
@@ -101,6 +104,17 @@
                linkButton.setEnabled(a);
        }

+       protected void setList(FileAndLinkList l) {
+               setLinkList(l);
+               setFileList(l);
+       }
+
+       protected void setLinkList(LinkList l) {
+               buttonsEnabled(l != null && l instanceof Index);
+               this.linkList = l;
+               tables.getLinkTable().setLinkList(l);
+       }
+
        protected void setFileList(FileList l) {
                buttonsEnabled(l != null && l instanceof Index);

@@ -111,9 +125,10 @@
        public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                javax.swing.tree.TreePath path = e.getPath();

+               setList(null);
+
                if(path == null) {
                        Logger.notice(this, "Path null ?");
-                       setFileList(null);
                        return;
                }

@@ -121,16 +136,19 @@

                if(node == null) {
                        Logger.notice(this, "Node null ?");
-                       setFileList(null);
                        return;
                }

-               if(node instanceof FileList) {                  
+               if(node instanceof FileList) {
+                       Logger.info(this, "FileList !");
                        setFileList((FileList)node);
-                       return;
                }
-               
-               setFileList(null);
+
+               if(node instanceof LinkList) {
+                       Logger.info(this, "LinkList !");
+                       setLinkList((LinkList)node);
+               }
+
        }


@@ -189,14 +207,15 @@


        public class LinkMaker implements Runnable {
-               public LinkMaker() {
+               public LinkMaker() { }

-               }
-
                public void run() {
                        IndexSelecter indexSelecter = new IndexSelecter();
                        String indexKey = indexSelecter.askForAnIndexURI(db);
-                       
+                       if (indexKey != null) {
+                               Link newLink = new Link(db, indexKey, 
(Index)linkList);
+                               ((Index)linkList).addLink(newLink);
+                       }
                }
        }

@@ -204,8 +223,7 @@
                if(o instanceof FCPClientPut) {
                        FCPClientPut clientPut = (FCPClientPut)o;
                        if(clientPut.isFinished()) {
-                               queueManager.remove(clientPut);
-                               
+                               queueManager.remove(clientPut);                 
        
                        }
                }
        }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2006-10-08 
17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2006-10-08 
20:21:05 UTC (rev 10650)
@@ -3,6 +3,7 @@
 import javax.swing.JPanel;
 import java.awt.BorderLayout;
 import javax.swing.JTree;
+import javax.swing.tree.TreeSelectionModel;
 import javax.swing.tree.TreeNode;
 import javax.swing.tree.MutableTreeNode;
 import javax.swing.tree.DefaultMutableTreeNode;
@@ -170,6 +171,9 @@

                tree.setCellRenderer(treeRenderer);

+               if (selectionOnly)
+                       
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+
                panel.add(new JScrollPane(tree));
        }

@@ -255,14 +259,8 @@
                                        Logger.warning(this, 
"UnsupportedEncodingException (UTF-8): "+exc.toString());
                                }

-                               try {
-                                       String[] cutcut = publicKey.split("/");
-                                       name = cutcut[cutcut.length-1];
-                                       name = name.replaceAll(".xml", "");
-                               } catch(Exception exc) {
-                                       Logger.warning(this, "Error while 
parsing index key: "+publicKey+" because: "+exc.toString() );
-                                       name = publicKey;
-                               }
+                               name = Index.getNameFromKey(publicKey);
+
                        } else
                                name = 
askAName(I18n.getMessage("thaw.plugin.index.indexName"),
                                               
I18n.getMessage("thaw.plugin.index.newIndex"));
@@ -413,4 +411,18 @@
                }
        }

+
+       void addToRoot(IndexTreeNode node) {
+               node.setParent(root);
+               root.insert(node.getTreeNode(), root.getChildCount());
+               reloadModel(root);
+       }
+
+       /**
+        * @param node can be null
+        */
+       void reloadModel(DefaultMutableTreeNode node) {
+               treeModel.reload(node);
+       }
+
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java   2006-10-08 
17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java   2006-10-08 
20:21:05 UTC (rev 10650)
@@ -7,6 +7,8 @@
 public interface IndexTreeNode {

        public DefaultMutableTreeNode getTreeNode();
+       
+       public void setParent(IndexCategory parent);

        /**
         * get Id of this node in the database.

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Link.java    2006-10-08 17:20:46 UTC 
(rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java    2006-10-08 20:21:05 UTC 
(rev 10650)
@@ -2,6 +2,11 @@

 import java.sql.*;

+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
 import thaw.core.Logger;
 import thaw.plugins.Hsqldb;

@@ -20,8 +25,32 @@
                this.indexName = indexName;
                this.key = key;
                this.parent = parent;
+               this.db = hsqldb;
        }

+       public Link(Hsqldb hsqldb, String key, Index parent) {
+               this(hsqldb, Index.getNameFromKey(key), key, parent);
+       }
+
+       public Link(Hsqldb hsqldb, ResultSet resultSet, Index parent) throws 
SQLException {
+               this.db = hsqldb;
+               this.id = resultSet.getInt("id");
+               this.key = resultSet.getString("publicKey");
+
+               this.indexName = Index.getNameFromKey(this.key);
+
+               this.parent = parent;
+       }
+
+       public Link(Hsqldb hsqldb, Element linkElement, Index parent) {
+               this.db = hsqldb;
+               this.key = linkElement.getAttribute("key");
+
+               this.indexName = Index.getNameFromKey(this.key);
+
+               this.parent = parent;
+       }
+
        public String getKey() {
                return key;
        }
@@ -124,4 +153,13 @@
                        Logger.error(this, "Unable to update link to 
'"+indexName+"' because: "+e.toString());
                }
        }
+
+
+       public Element getXML(Document xmlDoc) {
+               Element link = xmlDoc.createElement("index");
+
+               link.setAttribute("key", key);
+
+               return link;
+       }
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java       2006-10-08 
17:20:46 UTC (rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java       2006-10-08 
20:21:05 UTC (rev 10650)
@@ -41,6 +41,9 @@
 import thaw.core.*;
 import thaw.fcp.*;

+import thaw.plugins.Hsqldb;
+
+
 public class LinkTable implements MouseListener, KeyListener, ActionListener {

        private JPanel panel;
@@ -52,11 +55,20 @@
        private FCPQueueManager queueManager;
        private boolean modifiables;

+       private JPopupMenu rightClickMenu;
+       private JMenuItem removeLinks;
+       private JMenuItem addThisIndex;
+       private JMenuItem copyKey;
+       private IndexTree indexTree;
+
+       private Hsqldb db;
+
        private int[] selectedRows;

-       public LinkTable (boolean modifiables, FCPQueueManager queueManager) {
+       public LinkTable (boolean modifiables, Hsqldb db, FCPQueueManager 
queueManager, IndexTree tree) {
                this.modifiables = modifiables;
                this.queueManager = queueManager;
+               this.db = db;

                linkListModel = new LinkListModel();
                table = new JTable(linkListModel);
@@ -68,6 +80,23 @@
                panel.add(new 
JLabel(I18n.getMessage("thaw.plugin.index.linkList")), BorderLayout.NORTH);
                panel.add(new JScrollPane(table));

+               rightClickMenu = new JPopupMenu();
+               removeLinks = new 
JMenuItem(I18n.getMessage("thaw.common.remove"));
+               addThisIndex = new 
JMenuItem(I18n.getMessage("thaw.plugin.index.addIndexFromLink"));
+               copyKey = new 
JMenuItem(I18n.getMessage("thaw.plugin.index.copyKey"));
+
+               removeLinks.addActionListener(this);
+               addThisIndex.addActionListener(this);
+               copyKey.addActionListener(this);
+
+               if (modifiables)
+                       rightClickMenu.add(removeLinks);
+               rightClickMenu.add(addThisIndex);
+               rightClickMenu.add(copyKey);
+
+               table.addMouseListener(this);
+
+               indexTree = tree;
        }

        public JPanel getPanel() {
@@ -89,7 +118,12 @@
        }

        public void mouseClicked(MouseEvent e) {
-
+               if(e.getButton() == MouseEvent.BUTTON3
+                  && linkList != null) {
+                       removeLinks.setEnabled(linkList instanceof Index);
+                       selectedRows = table.getSelectedRows();
+                       rightClickMenu.show(e.getComponent(), e.getX(), 
e.getY());
+               }
        }

        public void mouseEntered(MouseEvent e) { }
@@ -107,7 +141,44 @@
        public void keyTyped(KeyEvent e) { }

        public void actionPerformed(ActionEvent e) {
+               Vector links;
+               String keyList = "";

+               if (linkList == null)
+                       return;
+
+               links = linkList.getLinkList();
+
+               for (int i = 0 ; i < selectedRows.length;  i++) {
+                       
+                       if (e.getSource() == removeLinks) {
+                               Link link = (Link)links.get(selectedRows[i]);
+                               ((Index)linkList).removeLink(link);
+                       }
+
+                       if (e.getSource() == addThisIndex) {
+                               Link link = (Link)links.get(selectedRows[i]);
+                               Index index = new Index(db, queueManager, -2, 
null, Index.getNameFromKey(link.getKey()),
+                                                       
Index.getNameFromKey(link.getKey()), link.getKey(), null,
+                                                       0, null, false);
+                               index.create();
+                               indexTree.addToRoot(index);
+                       }
+
+                       if (e.getSource() == copyKey) {
+                               Link link = (Link)links.get(selectedRows[i]);
+                               if (link.getKey() != null)
+                                       keyList = keyList + link.getKey() + 
"\n";
+                       }
+               }
+
+               if(e.getSource() == copyKey) {
+                       Toolkit tk = Toolkit.getDefaultToolkit();
+                       StringSelection st = new StringSelection(keyList);
+                       Clipboard cp = tk.getSystemClipboard();
+                       cp.setContents(st, null);
+               }
+
        }


@@ -134,7 +205,7 @@
                        }

                        if (newLinkList != null && (newLinkList instanceof 
Observable)) {
-                               ((Observable)newLinkList).deleteObserver(this);
+                               ((Observable)newLinkList).addObserver(this);
                        }

                        linkList = newLinkList;
@@ -162,6 +233,8 @@
                                }
                        }

+                       refresh();
+
                }

                public int getRowCount() {
@@ -199,13 +272,12 @@
                        refresh(event);
                }

-                       public void refresh(int row) {
+               public void refresh(int row) {
                        TableModelEvent event = new TableModelEvent(this, row);
                        refresh(event);
                }

                public void refresh(TableModelEvent e) {
-
                        fireTableChanged(e);
                }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/Tables.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Tables.java  2006-10-08 17:20:46 UTC 
(rev 10649)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Tables.java  2006-10-08 20:21:05 UTC 
(rev 10650)
@@ -6,6 +6,8 @@

 import thaw.fcp.FCPQueueManager;

+import thaw.plugins.Hsqldb;
+
 /**
  * Contains a FileTable, a LinkTable, and a SearchBar
  */
@@ -16,12 +18,12 @@
        private FileTable fileTable;
        private LinkTable linkTable;

-       public Tables(boolean modifiables, FCPQueueManager queueManager) {
+       public Tables(boolean modifiables, Hsqldb db, FCPQueueManager 
queueManager, IndexTree tree) {
                panel = new JPanel();
                panel.setLayout(new BorderLayout(10, 10));

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

                searchBar = new SearchBar(fileTable, linkTable);



Reply via email to