Testing the post-commit script the only way i know how.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / ImportBookmarksAction.java
1 package com.quantum.actions;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7
8 import javax.xml.parsers.ParserConfigurationException;
9
10 import com.quantum.Messages;
11 import com.quantum.QuantumPlugin;
12 import com.quantum.model.BookmarkCollection;
13 import com.quantum.util.xml.XMLHelper;
14 import com.quantum.view.bookmark.BookmarkView;
15
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.FileDialog;
20 import org.eclipse.ui.IViewActionDelegate;
21 import org.eclipse.ui.IViewPart;
22 import org.w3c.dom.Document;
23 import org.w3c.dom.Element;
24 import org.xml.sax.SAXException;
25
26 /**
27  * @author root
28  *
29  * To change this generated comment edit the template variable "typecomment":
30  * Window>Preferences>Java>Templates.
31  * To enable and disable the creation of type comments go to
32  * Window>Preferences>Java>Code Generation.
33  */
34 public class ImportBookmarksAction implements IViewActionDelegate {
35         BookmarkView view;
36         FileDialog dialog;
37         /**
38          * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
39          */
40         public void init(IViewPart view) {
41                 this.view = (BookmarkView) view;
42                 dialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);
43                 dialog.setFilterExtensions(new String[]{"*.xml","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
44                 dialog.setFilterNames(new String[]{Messages.getString("filedialog.xmlFiles"),Messages.getString("filedialog.xmlFiles")}); //$NON-NLS-1$ //$NON-NLS-2$
45                 
46         }
47
48         /**
49          * @see org.eclipse.ui.IActionDelegate#run(IAction)
50          */
51         public void run(IAction action) {
52                 dialog.setFilterPath(QuantumPlugin.getDefault().getPreferenceStore().getString("quantum.dialogs.importbookmark.path"));
53                 String filename = dialog.open();
54                 if (filename != null) {
55                         QuantumPlugin.getDefault().getPreferenceStore().setValue("quantum.dialogs.importbookmark.path", filename);
56                         File importFile = new File(filename);
57                         
58                         FileInputStream source = null;
59                         try {
60                                 source = new FileInputStream(importFile);
61                         } catch (FileNotFoundException e1) {
62                                 e1.printStackTrace();
63                                 return;
64                         }
65                         try {
66                                 Document doc = XMLHelper.createFromInputStream(source);
67                         Element root = doc.getDocumentElement();
68                         BookmarkCollection.getInstance().importXML(root);
69                 
70                         view.refresh();         
71             } catch (ParserConfigurationException e) {
72                 e.printStackTrace();
73             } catch (SAXException e) {
74                 e.printStackTrace();
75             } catch (IOException e) {
76                 e.printStackTrace();
77             }
78
79                 }
80         }
81
82         /**
83          * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
84          */
85         public void selectionChanged(IAction action, ISelection selection) {
86         }
87
88 }