1 package net.sourceforge.phpdt.sql.actions;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
8 import javax.xml.parsers.DocumentBuilder;
9 import javax.xml.parsers.DocumentBuilderFactory;
10 import javax.xml.parsers.ParserConfigurationException;
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;
22 import net.sourceforge.phpdt.sql.Messages;
23 import net.sourceforge.phpdt.sql.view.BookmarkView;
24 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
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.
34 public class ImportBookmarksAction implements IViewActionDelegate {
38 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
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$
48 * @see org.eclipse.ui.IActionDelegate#run(IAction)
50 public void run(IAction action) {
51 String filename = dialog.open();
52 if (filename != null) {
53 File importFile = new File(filename);
55 XmlDocument doc = new XmlDocument();
56 FileInputStream source = null;
58 source = new FileInputStream(importFile);
59 } catch (FileNotFoundException e1) {
63 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
64 DocumentBuilder parser;
66 parser = factory.newDocumentBuilder();
67 doc = (XmlDocument) parser.parse(source);
68 } catch (ParserConfigurationException e) {
71 } catch (SAXException e) {
74 } catch (IOException e) {
78 Element root = doc.getDocumentElement();
80 BookmarkContentProvider.getInstance().importXML(root);
88 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
90 public void selectionChanged(IAction action, ISelection selection) {