1 11 package org.eclipse.update.internal.ui.wizards; 12 13 import java.io.*; 14 import java.util.Vector ; 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 24 public class SitesImportExport { 25 26 static String 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 [] { "*.xml", "*" }); 40 SiteBookmark[] siteBookmarks = null; 41 42 String 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"); 66 String bookmarksFile = dialog.open(); 67 if (bookmarksFile == null) 68 return; 69 70 Vector bookmarks = new Vector (siteBookmarks.length); 71 for (int i=0; i<siteBookmarks.length; i++) 72 bookmarks.add(siteBookmarks[i]); 73 BookmarkUtil.store(bookmarksFile, bookmarks); 74 } 75 76 82 static SiteBookmark[] createImportedBookmarks(File file) { 83 Vector bookmarks = new Vector (); 84 BookmarkUtil.parse(file.getAbsolutePath(), bookmarks); 85 return BookmarkUtil.getBookmarks(bookmarks); 86 } 87 88 } 89 | Popular Tags |