Author: jflesch
Date: 2007-08-03 19:35:37 +0000 (Fri, 03 Aug 2007)
New Revision: 14477

Added:
   trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
Modified:
   trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
Log:
Cleanup the code relative to the index settings dialog

Modified: trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java  2007-08-03 17:56:44 UTC 
(rev 14476)
+++ trunk/apps/Thaw/src/thaw/fcp/FreenetURIHelper.java  2007-08-03 19:35:37 UTC 
(rev 14477)
@@ -20,10 +20,13 @@
                if (key == null)
                    return false;

-               return (key.startsWith("CHK@")
-                       || key.startsWith("SSK@")
-                       || key.startsWith("USK@")
-                       || key.startsWith("KSK@"));
+               if (key.startsWith("CHK@")
+                   || key.startsWith("SSK@")
+                   || key.startsWith("USK@")) {
+                       return (key.length() > 20);
+               }
+
+               return key.startsWith("KSK@");
        }

        public static String cleanURI(String uri) {

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-03 
17:56:44 UTC (rev 14476)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-03 
19:35:37 UTC (rev 14477)
@@ -297,6 +297,8 @@

 thaw.plugin.index.addAlreadyExistingIndex=Ajouter un index d?j? existant

+thaw.plugin.index.indexSettings=R?glages de l'index
+
 thaw.plugin.index.indexKey=Clef publique de l'index:
 thaw.plugin.index.indexPrivateKey=Clef priv?e de l'index:


Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-03 17:56:44 UTC 
(rev 14476)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-03 19:35:37 UTC 
(rev 14477)
@@ -305,6 +305,7 @@

 thaw.plugin.index.addAlreadyExistingIndex=Add an already existing index

+thaw.plugin.index.indexSettings=Index settings
 thaw.plugin.index.indexKey=Index key:
 thaw.plugin.index.indexPrivateKey=Private key:


Modified: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-08-03 
17:56:44 UTC (rev 14476)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-08-03 
19:35:37 UTC (rev 14477)
@@ -166,6 +166,11 @@
                //        "SET IGNORECASE TRUE");

                sendQuery(db,
+                         "CREATE CACHED TABLE categories ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "name VARCHAR(255) NOT NULL)");
+
+               sendQuery(db,
                          "CREATE CACHED TABLE indexFolders ("
                          + "id INTEGER IDENTITY NOT NULL,"
                          + "name VARCHAR(255) NOT NULL,"
@@ -210,14 +215,7 @@
                //+ "FOREIGN KEY (folderId) REFERENCES indexFolders (id)"
                //+ "FOREIGN KEY (parentId) REFERENCES indexFolders (id))");

-
-               /* not used at the moment */
                sendQuery(db,
-                         "CREATE CACHED TABLE categories ("
-                         + "id INTEGER IDENTITY NOT NULL,"
-                         + "name VARCHAR(255) NOT NULL)");
-
-               sendQuery(db,
                          "CREATE CACHED TABLE files ("
                          + "id INTEGER IDENTITY NOT NULL,"
                          + "filename VARCHAR(255) NOT NULL,"
@@ -225,7 +223,7 @@
                          + "localPath VARCHAR(500) NULL,"
                          + "mime VARCHAR(50) NULL,"
                          + "size BIGINT NOT NULL,"
-                         + "category INTEGER NULL,"
+                         + "category INTEGER NULL," // This field is a mistake.
                          + "indexParent INTEGER NOT NULL,"
                          + "toDelete BOOLEAN DEFAULT FALSE NOT NULL,"
                          + "dontDelete BOOLEAN DEFAULT FALSE NOT NULL,"

Added: trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java               
                (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java       
2007-08-03 19:35:37 UTC (rev 14477)
@@ -0,0 +1,304 @@
+package thaw.plugins.index;
+
+
+import javax.swing.JButton;
+import javax.swing.JTextField;
+import javax.swing.JCheckBox;
+import javax.swing.JPopupMenu;
+import javax.swing.JDialog;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+
+import java.awt.GridLayout;
+import java.awt.BorderLayout;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseEvent;
+
+import thaw.fcp.FCPQueueManager;
+import thaw.fcp.FreenetURIHelper;
+import thaw.core.I18n;
+import thaw.core.Logger;
+
+
+public class IndexConfigDialog implements ActionListener, MouseListener {
+       private JDialog frame;
+
+       private IndexBrowserPanel indexBrowser;
+       private FCPQueueManager queueManager;
+       private Index index;
+
+
+       private JButton okButton;
+       private JButton cancelButton;
+       private int formState;
+
+       private JButton resetCommentsButton;
+
+       private JTextField publicKeyField       = null;
+       private JTextField privateKeyField      = null;
+       private JCheckBox  publishPrivateKeyBox = null;
+       private JCheckBox  allowCommentsBox     = null;
+
+       private JPopupMenu popupMenuA;
+       private JPopupMenu popupMenuB;
+
+
+       /**
+        * Use it to add an already existing index (won't add it ; just get the 
basic values)
+        * Various fields will be disabled (publish private key, etc).
+        */
+       public IndexConfigDialog(IndexBrowserPanel indexBrowser,
+                                FCPQueueManager queueManager) {
+               this(indexBrowser, queueManager, null);
+       }
+
+       /**
+        * Use it to modify an existing index (will modify automagically)
+        * @param index if index is provided, changes will be automagically set
+        */
+       public IndexConfigDialog(IndexBrowserPanel indexBrowser,
+                                FCPQueueManager queueManager,
+                                Index index) {
+               this.indexBrowser = indexBrowser;
+               this.queueManager = queueManager;
+               this.index = index;
+       }
+
+
+       public String getPublicKey() {
+               String key = publicKeyField.getText();
+
+               if (!FreenetURIHelper.isAKey(key))
+                       return null;
+
+               return key;
+       }
+
+       public String getPrivateKey() {
+               String key = privateKeyField.getText();
+
+               if (!FreenetURIHelper.isAKey(key))
+                       return null;
+
+               return key;
+       }
+
+       public boolean getPublishPrivateKey() {
+               return publishPrivateKeyBox.isSelected();
+       }
+
+       public boolean getAllowComments() {
+               return allowCommentsBox.isSelected();
+       }
+
+
+
+       /**
+        * If this function return true, you can use the get[...]() function
+        * to get the user input.
+        * (Note: What a mess !)
+        * @return false if the user cancelled
+        */
+       public boolean promptUser() {
+               prepareDialog();
+               return (showDialog());
+       }
+
+
+
+       private void prepareDialog() {
+               frame = new JDialog(indexBrowser.getMainWindow().getMainFrame(),
+                                   
I18n.getMessage("thaw.plugin.index.indexSettings"));
+
+               frame.getContentPane().setLayout(new BorderLayout());
+
+
+               /* main elements (fields, checkboxes, etc) */
+
+               publicKeyField       = new JTextField((index == null) ?
+                                                     "USK@" :
+                                                     index.getPublicKey());
+
+               privateKeyField      = new JTextField((index == null) ?
+                                                     "SSK@" :
+                                                     index.getPrivateKey());
+
+               publishPrivateKeyBox = new 
JCheckBox(I18n.getMessage("thaw.plugin.index.publishPrivateKey"),
+                                                    ((index == null) ?
+                                                     false :
+                                                     
index.publishPrivateKey()));
+
+               publishPrivateKeyBox.setEnabled(index != null && 
index.getPrivateKey() != null);
+
+               allowCommentsBox     = new 
JCheckBox(I18n.getMessage("thaw.plugin.index.allowComments"),
+                                                    (index == null) ?
+                                                    false :
+                                                    
(index.getCommentPublicKey() != null));
+
+               allowCommentsBox.setEnabled((index == null) ?
+                                           false :
+                                           (index.getPrivateKey() != null));
+
+
+               resetCommentsButton = new 
JButton(I18n.getMessage("thaw.plugin.index.comment.reset"));
+               resetCommentsButton.addActionListener(this);
+
+
+               /* public & private keys */
+
+               final JPanel labelPanel = new JPanel();
+               final JPanel textFieldPanel = new JPanel();
+
+               labelPanel.setLayout(new GridLayout(2, 1));
+               textFieldPanel.setLayout(new GridLayout(2, 1));
+
+               labelPanel.add(new 
JLabel(I18n.getMessage("thaw.plugin.index.indexKey")+ " "), BorderLayout.WEST);
+               textFieldPanel.add(publicKeyField, BorderLayout.CENTER);
+
+               popupMenuA = new JPopupMenu();
+               JMenuItem item = new 
JMenuItem(I18n.getMessage("thaw.common.paste"));
+               popupMenuA.add(item);
+               new thaw.gui.GUIHelper.PasteHelper(item, publicKeyField);
+               publicKeyField.addMouseListener(this);
+
+
+               labelPanel.add(new 
JLabel(I18n.getMessage("thaw.plugin.index.indexPrivateKey")+" "), 
BorderLayout.WEST);
+               textFieldPanel.add(privateKeyField, BorderLayout.CENTER);
+
+               popupMenuB = new JPopupMenu();
+               item = new JMenuItem(I18n.getMessage("thaw.common.paste"));
+               popupMenuB.add(item);
+               new thaw.gui.GUIHelper.PasteHelper(item, privateKeyField);
+               privateKeyField.addMouseListener(this);
+
+
+               frame.getContentPane().add(labelPanel, BorderLayout.WEST);
+               frame.getContentPane().add(textFieldPanel, BorderLayout.CENTER);
+
+
+               /** various other settings **/
+
+
+               final JPanel indexSettingsPanel = new JPanel();
+               indexSettingsPanel.setLayout(new GridLayout(3, 1));
+
+               final JPanel mainButtonPanel = new JPanel();
+               mainButtonPanel.setLayout(new GridLayout(1, 2));
+
+               cancelButton = new 
JButton(I18n.getMessage("thaw.common.cancel"));
+               okButton = new JButton(I18n.getMessage("thaw.common.ok"));
+
+               cancelButton.addActionListener(this);
+               okButton.addActionListener(this);
+
+               mainButtonPanel.add(okButton);
+               mainButtonPanel.add(cancelButton);
+
+               JPanel commentPanel = new JPanel(new BorderLayout());
+               commentPanel.add(allowCommentsBox, BorderLayout.CENTER);
+
+               if (index != null && index.getPrivateKey() != null)
+                       commentPanel.add(resetCommentsButton, 
BorderLayout.EAST);
+
+
+               indexSettingsPanel.add(publishPrivateKeyBox);
+               indexSettingsPanel.add(commentPanel);
+               indexSettingsPanel.add(mainButtonPanel);
+
+               frame.getContentPane().add(indexSettingsPanel, 
BorderLayout.SOUTH);
+       }
+
+
+       private boolean showDialog() {
+
+               /* let's rock'n'rool :p */
+
+               frame.setSize(700, 140);
+               frame.setVisible(true);
+
+               try {
+                       synchronized(this) {
+                               wait();
+                       }
+               } catch(final InterruptedException e) {
+                       /* \_o< */
+               }
+
+               frame.setVisible(false);
+               frame.dispose();
+
+               if (formState == 2) /* cancelled */
+                       return false;
+
+               if (index != null) {
+                       updateValues(index);
+               }
+
+               return true;
+       }
+
+
+       public void updateValues(Index index) {
+               index.setPublicKey(getPublicKey());
+               index.setPrivateKey(getPrivateKey());
+
+               if (getPrivateKey() != null)
+                       index.setPublishPrivateKey(getPublishPrivateKey());
+
+               if (index.canHaveComments() && !getAllowComments()) {
+                       Logger.notice(this, "Purging comments ...");
+                       index.purgeCommentKeys();
+               } else if (!index.canHaveComments() && getAllowComments()) {
+                       Logger.notice(this, "Purging comments & regenerating 
keys ...");
+                       index.regenerateCommentKeys(queueManager);
+               }
+       }
+
+
+       public synchronized void actionPerformed(final ActionEvent e) {
+               if (e.getSource() == okButton) {
+                       formState = 1;
+                       synchronized(this) {
+                               notifyAll();
+                       }
+                       return;
+               }
+
+               if (e.getSource() == cancelButton) {
+                       formState = 2;
+                       synchronized(this) {
+                               notifyAll();
+                       }
+                       return;
+               }
+
+               if (e.getSource() == resetCommentsButton) {
+                       index.regenerateCommentKeys(queueManager);
+               }
+       }
+
+       public void mouseClicked(final MouseEvent e) { }
+       public void mouseEntered(final MouseEvent e) { }
+       public void mouseExited(final MouseEvent e) { }
+
+       public void mousePressed(final MouseEvent e) {
+               showPopupMenu(e);
+       }
+
+       public void mouseReleased(final MouseEvent e) {
+               showPopupMenu(e);
+       }
+
+       protected void showPopupMenu(final MouseEvent e) {
+               if(e.isPopupTrigger()) {
+                       if (e.getComponent() == publicKeyField)
+                               popupMenuA.show(e.getComponent(), e.getX(), 
e.getY());
+                       if (e.getComponent() == privateKeyField)
+                               popupMenuB.show(e.getComponent(), e.getX(), 
e.getY());
+               }
+       }
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-08-03 17:56:44 UTC (rev 14476)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-08-03 19:35:37 UTC (rev 14477)
@@ -262,7 +262,9 @@
        }


-       public static void createIndex(final FCPQueueManager queueManager, 
final IndexBrowserPanel indexBrowser, IndexFolder target, final String name) {
+       public static void createIndex(final FCPQueueManager queueManager,
+                                      final IndexBrowserPanel indexBrowser,
+                                      IndexFolder target, final String name) {

                IndexCreator creator = new IndexCreator(queueManager, 
indexBrowser, null);
                creator.setTarget(target);
@@ -272,252 +274,6 @@



-       /**
-        * In fact, this dialog allows to change various settings related to 
the index
-        * THIS DIALOG BECOMES REALLY DIRTY ! TO REWRITE !
-        */
-       public static class KeyAsker implements ActionListener, MouseListener {
-               private Index index;
-               private FCPQueueManager queueManager;
-
-               private JButton okButton;
-               private JButton cancelButton;
-               private int formState;
-
-               private JButton resetCommentsButton;
-
-               private JTextField publicKeyField       = null;
-               private JTextField privateKeyField      = null;
-               private JCheckBox  publishPrivateKeyBox = null;
-               private JCheckBox  allowCommentsBox     = null;
-
-               private JPopupMenu popupMenuA;
-               private JPopupMenu popupMenuB;
-
-               public KeyAsker() {
-
-               }
-
-               /**
-                * @param index can be null
-                * @param queueManager can be null if index is null
-                */
-               public static KeyAsker askKeys(final Index index,
-                                              final FCPQueueManager 
queueManager,
-                                              final boolean askPrivateKey,
-                                              final String defaultPublicKey,
-                                              final String defaultPrivateKey,
-                                              final boolean 
defaultPublishPrivateKey,
-                                              final boolean 
defaultAllowComments,
-                                              final boolean 
enablePublishPrivateKeyChoice,
-                                              final IndexBrowserPanel 
indexBrowser) {
-                       KeyAsker asker = new KeyAsker();
-                       asker.askKeysBis(index, queueManager,
-                                        askPrivateKey, defaultPublicKey,
-                                        defaultPrivateKey, 
defaultPublishPrivateKey,
-                                        defaultAllowComments,
-                                        enablePublishPrivateKeyChoice,
-                                        indexBrowser);
-                       if (asker.getPublicKey() != null)
-                               return asker;
-                       else
-                               return null;
-               }
-
-
-               private String publicKeyResult = null;
-               private String privateKeyResult = null;
-               private boolean publishPrivateKey = false;
-               private boolean allowComments = false;
-
-
-               public String getPublicKey() {
-                       return publicKeyResult;
-               }
-
-               public String getPrivateKey() {
-                       return privateKeyResult;
-               }
-
-               public boolean getPublishPrivateKey() {
-                       return publishPrivateKey;
-               }
-
-               public boolean getAllowComments() {
-                       return allowComments;
-               }
-
-               public synchronized void askKeysBis(Index index, 
FCPQueueManager queueManager,
-                                                   final boolean askPrivateKey,
-                                                   String defaultPublicKey,
-                                                   String defaultPrivateKey,
-                                                   boolean 
defaultPublishPrivateKey,
-                                                   boolean 
defaultAllowComments,
-                                                   final boolean 
enablePublishPrivateKeyChoice,
-                                                   final IndexBrowserPanel 
indexBrowser) {
-                       this.index = index;
-                       this.queueManager = queueManager;
-
-                       formState = 0;
-
-                       if (defaultPublicKey == null)
-                               defaultPublicKey = "USK@";
-
-                       if (defaultPrivateKey == null)
-                               defaultPrivateKey = "SSK@";
-
-                       final JDialog frame = new 
JDialog(indexBrowser.getMainWindow().getMainFrame(), 
I18n.getMessage("thaw.plugin.index.indexKey"));
-
-                       frame.getContentPane().setLayout(new BorderLayout());
-
-                       publicKeyField       = new JTextField(defaultPublicKey);
-                       privateKeyField      = new 
JTextField(defaultPrivateKey);
-                       publishPrivateKeyBox = new 
JCheckBox(I18n.getMessage("thaw.plugin.index.publishPrivateKey"),
-                                                            
defaultPublishPrivateKey);
-                       
publishPrivateKeyBox.setEnabled(enablePublishPrivateKeyChoice);
-                       allowCommentsBox     = new 
JCheckBox(I18n.getMessage("thaw.plugin.index.allowComments"),
-                                                            
defaultAllowComments);
-                       
allowCommentsBox.setEnabled(enablePublishPrivateKeyChoice); /* if we can't 
publish the private key, we can't change comment setting */
-
-                       resetCommentsButton = new 
JButton(I18n.getMessage("thaw.plugin.index.comment.reset"));
-                       resetCommentsButton.addActionListener(this);
-
-                       final JPanel subPanelA = new JPanel(); /* left  => 
labels */
-                       final JPanel subPanelB = new JPanel(); /* right => 
textfield */
-
-                       subPanelA.setLayout(new GridLayout(askPrivateKey ? 2 : 
1, 1));
-                       subPanelB.setLayout(new GridLayout(askPrivateKey ? 2 : 
1, 1));
-
-                       subPanelA.add(new 
JLabel(I18n.getMessage("thaw.plugin.index.indexKey")+ " "), BorderLayout.WEST);
-                       subPanelB.add(publicKeyField, BorderLayout.CENTER);
-
-                       popupMenuA = new JPopupMenu();
-                       JMenuItem item = new 
JMenuItem(I18n.getMessage("thaw.common.paste"));
-                       popupMenuA.add(item);
-                       new thaw.gui.GUIHelper.PasteHelper(item, 
publicKeyField);
-                       publicKeyField.addMouseListener(this);
-
-                       if (askPrivateKey) {
-                               subPanelA.add(new 
JLabel(I18n.getMessage("thaw.plugin.index.indexPrivateKey")+" "), 
BorderLayout.WEST);
-                               subPanelB.add(privateKeyField, 
BorderLayout.CENTER);
-
-                               popupMenuB = new JPopupMenu();
-                               item = new 
JMenuItem(I18n.getMessage("thaw.common.paste"));
-                               popupMenuB.add(item);
-                               new thaw.gui.GUIHelper.PasteHelper(item, 
privateKeyField);
-                               privateKeyField.addMouseListener(this);
-                       }
-
-                       frame.getContentPane().add(subPanelA, 
BorderLayout.WEST);
-                       frame.getContentPane().add(subPanelB, 
BorderLayout.CENTER);
-
-                       final JPanel subPanelC = new JPanel();
-                       subPanelC.setLayout(new GridLayout(3, 1));
-
-                       final JPanel subSubPanelC = new JPanel();
-                       subSubPanelC.setLayout(new GridLayout(1, 2));
-
-                       cancelButton = new 
JButton(I18n.getMessage("thaw.common.cancel"));
-                       okButton = new 
JButton(I18n.getMessage("thaw.common.ok"));
-
-                       cancelButton.addActionListener(this);
-                       okButton.addActionListener(this);
-
-                       subSubPanelC.add(okButton);
-                       subSubPanelC.add(cancelButton);
-
-                       JPanel commentPanel = new JPanel(new BorderLayout());
-                       commentPanel.add(allowCommentsBox, BorderLayout.CENTER);
-
-                       if (index != null && index.getPrivateKey() != null)
-                               commentPanel.add(resetCommentsButton, 
BorderLayout.EAST);
-
-
-                       subPanelC.add(publishPrivateKeyBox);
-                       subPanelC.add(commentPanel);
-                       subPanelC.add(subSubPanelC);
-
-                       frame.getContentPane().add(subPanelC, 
BorderLayout.SOUTH);
-
-                       frame.setSize(700, 140);
-                       frame.setVisible(true);
-
-                       try {
-                               wait();
-                       } catch(final java.lang.InterruptedException e) {
-                               /* \_o< */
-                       }
-
-                       frame.setVisible(false);
-
-                       if (formState == 2)
-                               return;
-
-                       publicKeyResult = publicKeyField.getText();
-
-                       if (askPrivateKey)
-                               privateKeyResult = privateKeyField.getText();
-
-                       frame.dispose();
-
-                       if ((publicKeyResult == null) || 
(publicKeyResult.length() < 20))
-                               {
-                                       publicKeyResult = null;
-                                       privateKeyResult = null;
-                               }
-
-                       if ((privateKeyResult == null) || 
(privateKeyResult.length() < 20))
-                               privateKeyResult = null;
-                       else
-                               publishPrivateKey = 
publishPrivateKeyBox.isSelected();
-
-                       allowComments = allowCommentsBox.isSelected();
-
-                       Logger.info(this, "public : "+publicKeyResult + " ; 
Private : "+privateKeyResult);
-               }
-
-               public synchronized void actionPerformed(final ActionEvent e) {
-                       if (e.getSource() == okButton) {
-                               formState = 1;
-                               notifyAll();
-                               return;
-                       }
-
-                       if (e.getSource() == cancelButton) {
-                               formState = 2;
-                               notifyAll();
-                               return;
-                       }
-
-                       if (e.getSource() == resetCommentsButton) {
-                               index.regenerateCommentKeys(queueManager);
-                       }
-               }
-
-               public void mouseClicked(final MouseEvent e) { }
-               public void mouseEntered(final MouseEvent e) { }
-               public void mouseExited(final MouseEvent e) { }
-
-               public void mousePressed(final MouseEvent e) {
-                       showPopupMenu(e);
-               }
-
-               public void mouseReleased(final MouseEvent e) {
-                       showPopupMenu(e);
-               }
-
-               protected void showPopupMenu(final MouseEvent e) {
-                       if(e.isPopupTrigger()) {
-                               if (e.getComponent() == publicKeyField)
-                                       popupMenuA.show(e.getComponent(), 
e.getX(), e.getY());
-                               if (e.getComponent() == privateKeyField)
-                                       popupMenuB.show(e.getComponent(), 
e.getX(), e.getY());
-                       }
-               }
-
-       }
-
-
        public static class IndexModifier extends BasicIndexAction implements 
Runnable {

                public IndexModifier(final FCPQueueManager queueManager, final 
IndexBrowserPanel indexBrowser, final AbstractButton actionSource) {
@@ -534,33 +290,20 @@
                public void apply() {
                        final Index index = ((Index)getTarget());

-                       final KeyAsker asker = KeyAsker.askKeys(index, 
getQueueManager(),
-                                                               true, 
index.getPublicKey(),
-                                                               
index.getPrivateKey(), index.publishPrivateKey(),
-                                                               
index.canHaveComments(), true, getIndexBrowserPanel());
+                       IndexConfigDialog dialog = new 
IndexConfigDialog(getIndexBrowserPanel(),
+                                                                        
getQueueManager(),
+                                                                        index);

-                       if (asker == null) {
+                       if (!dialog.promptUser()) {
                                Logger.info(this, "Change cancelled");
                                return;
                        }

-                       /* Could be done in one shot ... but this way is so 
easier .... :) */
-                       index.setPrivateKey(asker.getPrivateKey());
-                       
index.setPublishPrivateKey(asker.getPublishPrivateKey());
-                       index.setPublicKey(asker.getPublicKey());
-
-                       if (index.canHaveComments() && 
!asker.getAllowComments()) {
-                               Logger.notice(this, "Purging comments ...");
-                               index.purgeCommentKeys();
-                       } else if (!index.canHaveComments() && 
asker.getAllowComments()) {
-                               Logger.notice(this, "Purging comments & 
regenerating keys ...");
-                               index.regenerateCommentKeys(getQueueManager());
-                       }
-
                        getIndexBrowserPanel().getIndexTree().refresh(index);

-                       new 
WarningWindow(getIndexBrowserPanel().getMainWindow(),
-                                         
I18n.getMessage("thaw.plugin.index.mustReinsert"));
+                       if (index.getPrivateKey() != null)
+                               new 
WarningWindow(getIndexBrowserPanel().getMainWindow(),
+                                                 
I18n.getMessage("thaw.plugin.index.mustReinsert"));
                }
        }

@@ -578,21 +321,18 @@
                }

                public void apply() {
-                       KeyAsker asker;
                        String publicKey = null;
                        String privateKey = null;
                        boolean publishPrivate = false;

-                       asker = KeyAsker.askKeys(null, null,
-                                                true, "USK@", "SSK@",
-                                                false, false, false, 
getIndexBrowserPanel());
+                       IndexConfigDialog dialog = new 
IndexConfigDialog(getIndexBrowserPanel(),
+                                                                        
getQueueManager());

-                       if (asker == null)
+                       if (!dialog.promptUser()) /* cancelled */
                                return;

-                       publicKey = asker.getPublicKey();
-                       privateKey = asker.getPrivateKey();
-                       //publishPrivate = asker.getPublishPrivateKey(); /* 
useless ; will be reset when downloading */
+                       publicKey = dialog.getPublicKey();
+                       privateKey = dialog.getPrivateKey();

                        IndexManagementHelper.reuseIndex(getQueueManager(), 
getIndexBrowserPanel(), (IndexFolder)getTarget(), publicKey, privateKey);
                }


Reply via email to