1 package com.quantum.actions;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
8 import javax.xml.parsers.ParserConfigurationException;
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;
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;
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$
49 * @see org.eclipse.ui.IActionDelegate#run(IAction)
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);
58 FileInputStream source = null;
60 source = new FileInputStream(importFile);
61 } catch (FileNotFoundException e1) {
66 Document doc = XMLHelper.createFromInputStream(source);
67 Element root = doc.getDocumentElement();
68 BookmarkCollection.getInstance().importXML(root);
71 } catch (ParserConfigurationException e) {
73 } catch (SAXException e) {
75 } catch (IOException e) {
83 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
85 public void selectionChanged(IAction action, ISelection selection) {