Author: jflesch
Date: 2006-12-05 20:24:15 +0000 (Tue, 05 Dec 2006)
New Revision: 11247
Modified:
trunk/apps/Thaw/src/thaw/core/FileChooser.java
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
Log:
add index import/export function
Modified: trunk/apps/Thaw/src/thaw/core/FileChooser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/FileChooser.java 2006-12-05 19:56:19 UTC
(rev 11246)
+++ trunk/apps/Thaw/src/thaw/core/FileChooser.java 2006-12-05 20:24:15 UTC
(rev 11247)
@@ -24,6 +24,7 @@
this.fileChooser.setDialogTitle(title);
}
+
public void setDirectoryOnly(boolean v) {
if(v)
this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-12-05 19:56:19 UTC
(rev 11246)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-12-05 20:24:15 UTC
(rev 11247)
@@ -255,3 +255,5 @@
thaw.plugin.index.changeIndexKeys=Change the index keys
thaw.plugin.index.unknownIndexes=Unknown indexes:
+thaw.plugin.index.importIndex=Import index content from a file
+thaw.plugin.index.exportIndex=Export index content to a file
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2006-12-05 19:56:19 UTC (rev 11246)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2006-12-05 20:24:15 UTC (rev 11247)
@@ -21,7 +21,10 @@
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import javax.swing.JMenuItem;
+import javax.swing.JFileChooser;
+import java.io.FileOutputStream;
+
import java.util.Vector;
import java.util.Iterator;
@@ -32,7 +35,6 @@
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
-import thaw.core.FileChooser;
import thaw.core.Config;
import thaw.core.I18n;
import thaw.core.FreenetURIHelper;
@@ -41,6 +43,7 @@
import thaw.fcp.*;
import thaw.core.Logger;
import thaw.core.MainWindow;
+import thaw.core.FileChooser;
/**
* Index.java, IndexCategory.java and IndexTree.java must NEVER use this
helper (to avoid loops).
@@ -595,6 +598,70 @@
+ public static class IndexExporter extends BasicIndexAction {
+ public IndexExporter(AbstractButton actionSource) {
+ super(null, null, null, null, actionSource);
+ }
+
+ public void setTarget(IndexTreeNode node) {
+ super.setTarget(node);
+ getActionSource().setEnabled(node != null && node
instanceof Index);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ java.io.File newFile;
+
+ FileChooser fileChooser = new FileChooser();
+
fileChooser.setTitle(I18n.getMessage("thaw.plugin.index.exportIndex"));
+ fileChooser.setDirectoryOnly(false);
+ fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
+ newFile = fileChooser.askOneFile();
+
+ if (newFile == null)
+ return;
+
+ FileOutputStream out;
+
+ try {
+ out = new FileOutputStream(newFile);
+ } catch(java.io.FileNotFoundException excep) {
+ Logger.warning(this, "Unable to create file
'"+newFile.toString()+"' ! not generated because : "+excep.toString());
+ return;
+ }
+
+ ((Index)getTarget()).generateXML(out);
+ }
+ }
+
+
+ public static class IndexImporter extends BasicIndexAction {
+ public IndexImporter(AbstractButton actionSource) {
+ super(null, null, null, null, actionSource);
+ }
+
+ public void setTarget(IndexTreeNode node) {
+ super.setTarget(node);
+ getActionSource().setEnabled(node != null && node
instanceof Index);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ java.io.File newFile;
+
+ FileChooser fileChooser = new FileChooser();
+
fileChooser.setTitle(I18n.getMessage("thaw.plugin.index.importIndex"));
+ fileChooser.setDirectoryOnly(false);
+ fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
+ newFile = fileChooser.askOneFile();
+
+ if (newFile == null)
+ return;
+
+ ((Index)getTarget()).loadXML(newFile.getPath());
+ }
+ }
+
+
+
/**
* Can be used on indexes or index categories.
*/
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-12-05
19:56:19 UTC (rev 11246)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-12-05
20:24:15 UTC (rev 11247)
@@ -207,6 +207,14 @@
indexMenu.add(item);
indexAndFileActions.add(new
IndexManagementHelper.IndexRenamer(this, item));
+ item = new
JMenuItem(I18n.getMessage("thaw.plugin.index.exportIndex"));
+ indexMenu.add(item);
+ indexAndFileActions.add(new
IndexManagementHelper.IndexExporter(item));
+
+ item = new
JMenuItem(I18n.getMessage("thaw.plugin.index.importIndex"));
+ indexMenu.add(item);
+ indexAndFileActions.add(new
IndexManagementHelper.IndexImporter(item));
+
item = new
JMenuItem(I18n.getMessage("thaw.plugin.index.delete"));
indexMenu.add(item);
indexAndFileActions.add(new
IndexManagementHelper.IndexDeleter(this, item));