1) Added missing strings for italic, underline and strike through.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ImportBookmarksAction.java
1 package net.sourceforge.phpdt.sql.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.DocumentBuilder;
9 import javax.xml.parsers.DocumentBuilderFactory;
10 import javax.xml.parsers.ParserConfigurationException;
11
12 import org.apache.crimson.tree.XmlDocument;
13 import org.eclipse.jface.action.IAction;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.FileDialog;
17 import org.eclipse.ui.IViewActionDelegate;
18 import org.eclipse.ui.IViewPart;
19 import org.w3c.dom.Element;
20 import org.xml.sax.SAXException;
21
22 import net.sourceforge.phpdt.sql.Messages;
23 import net.sourceforge.phpdt.sql.view.BookmarkView;
24 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
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          * @see org.eclipse.ui.IActionDelegate#run(IAction)
49          */
50         public void run(IAction action) {
51                 String filename = dialog.open();
52                 if (filename != null) {
53                         File importFile = new File(filename);
54                         
55                         XmlDocument doc = new XmlDocument();
56                         FileInputStream source = null;
57                         try {
58                                 source = new FileInputStream(importFile);
59                         } catch (FileNotFoundException e1) {
60                                 e1.printStackTrace();
61                                 return;
62                         }
63                         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
64                         DocumentBuilder parser;
65                         try {
66                                 parser = factory.newDocumentBuilder();
67                                 doc = (XmlDocument) parser.parse(source);
68                         } catch (ParserConfigurationException e) {
69                                 e.printStackTrace();
70                                 return;
71                         } catch (SAXException e) {
72                                 e.printStackTrace();
73                                 return;
74                         } catch (IOException e) {
75                                 e.printStackTrace();
76                                 return;
77                         }
78                         Element root = doc.getDocumentElement();
79                 
80                         BookmarkContentProvider.getInstance().importXML(root);
81                 
82                         view.refresh();         
83
84                 }
85         }
86
87         /**
88          * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
89          */
90         public void selectionChanged(IAction action, ISelection selection) {
91         }
92
93 }