KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > wizards > SitesImportExport


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.ui.wizards;
12
13 import java.io.*;
14 import java.util.Vector JavaDoc;
15
16 import org.eclipse.jface.dialogs.*;
17 import org.eclipse.swt.*;
18 import org.eclipse.swt.widgets.*;
19 import org.eclipse.update.internal.ui.*;
20 import org.eclipse.update.internal.ui.model.*;
21
22 /**
23  */

24 public class SitesImportExport {
25
26     static String JavaDoc lastLocation = null;
27     
28     public SitesImportExport() {
29         super();
30     }
31     
32
33     public static SiteBookmark[] getImportedBookmarks(Shell parent) {
34         FileDialog dialog = new FileDialog(parent);
35         dialog.setText(
36             UpdateUIMessages.LocalSiteSelector_dialogMessageImport);
37
38         dialog.setFilterExtensions(new String JavaDoc[] { "*.xml", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
39

40         SiteBookmark[] siteBookmarks = null;
41
42         String JavaDoc bookmarksFile = dialog.open();
43         while (bookmarksFile != null && siteBookmarks == null) {
44             File file = new File(bookmarksFile);
45             siteBookmarks = createImportedBookmarks(file);
46             if (siteBookmarks == null || siteBookmarks.length == 0) {
47                 MessageDialog.openInformation(
48                     parent,
49                     UpdateUIMessages.LocalSiteSelector_importInfoTitle,
50                     UpdateUIMessages.LocalSiteSelector_importInfoMessage);
51                 bookmarksFile = dialog.open();
52             } else {
53                 break;
54             }
55         }
56         return siteBookmarks;
57     }
58
59     public static void exportBookmarks(Shell parent, SiteBookmark[] siteBookmarks) {
60         FileDialog dialog = new FileDialog(parent, SWT.SAVE);
61         dialog.setText(
62             UpdateUIMessages.LocalSiteSelector_dialogMessageExport);
63
64         dialog.setFileName("bookmarks.xml"); //$NON-NLS-1$
65

66         String JavaDoc bookmarksFile = dialog.open();
67         if (bookmarksFile == null)
68             return;
69         
70         Vector JavaDoc bookmarks = new Vector JavaDoc(siteBookmarks.length);
71         for (int i=0; i<siteBookmarks.length; i++)
72             bookmarks.add(siteBookmarks[i]);
73         BookmarkUtil.store(bookmarksFile, bookmarks);
74     }
75     
76     /**
77      * Creates bookmarks out from the given file
78      *
79      * @param file
80      * @return
81      */

82     static SiteBookmark[] createImportedBookmarks(File file) {
83         Vector JavaDoc bookmarks = new Vector JavaDoc();
84         BookmarkUtil.parse(file.getAbsolutePath(), bookmarks);
85         return BookmarkUtil.getBookmarks(bookmarks);
86     }
87
88 }
89
Popular Tags