1 11 package org.eclipse.update.internal.ui.model; 12 13 import java.io.*; 14 import java.net.*; 15 import java.util.Iterator ; 16 import java.util.Vector ; 17 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.update.configurator.*; 20 import org.eclipse.update.internal.ui.*; 21 import org.eclipse.update.operations.*; 22 23 public class UpdateModel implements IAdaptable { 24 private Vector bookmarks = new Vector (); 25 private Vector listeners = new Vector (); 26 private static final String BOOKMARK_FILE = "bookmarks.xml"; 28 public UpdateModel() { 29 reset(); 30 } 31 32 public void reset() { 33 bookmarks.clear(); 35 BookmarkUtil.parse(getBookmarksFileName(), bookmarks); 36 } 37 38 private String getBookmarksFileName() { 39 URL platformXML = ConfiguratorUtils.getCurrentPlatformConfiguration().getConfigurationLocation(); 40 if (!"file".equals(platformXML.getProtocol())) { IPath path = UpdateUI.getDefault().getStateLocation(); 42 path = path.append(BOOKMARK_FILE); 43 return path.toOSString(); 44 } else { 45 File f = new File(platformXML.getFile()); 46 f = new File(f.getParentFile(), BOOKMARK_FILE); 47 return f.getAbsolutePath(); 48 } 49 } 50 51 public void shutdown() { 52 saveBookmarks(); 53 } 54 55 public void saveBookmarks() { 56 BookmarkUtil.store(getBookmarksFileName(), bookmarks); 57 } 58 59 60 public void addBookmark(NamedModelObject bookmark) { 61 bookmarks.add(bookmark); 62 bookmark.setModel(this); 63 fireObjectsAdded(null, new Object []{bookmark}); 64 } 65 66 public void removeBookmark(NamedModelObject bookmark) { 67 bookmarks.remove(bookmark); 68 bookmark.setModel(null); 69 fireObjectsRemoved(null, new Object []{bookmark}); 70 } 71 72 public NamedModelObject [] getBookmarks() { 73 return (NamedModelObject[])bookmarks.toArray(new NamedModelObject[bookmarks.size()]); 74 } 75 76 public SiteBookmark [] getBookmarkLeafs() { 77 return BookmarkUtil.getBookmarks(bookmarks); 78 } 79 80 public BookmarkFolder getFolder(IPath path) { 81 return BookmarkUtil.getFolder(bookmarks, path); 82 } 83 84 public void addUpdateModelChangedListener(IUpdateModelChangedListener listener) { 85 if (!listeners.contains(listener)) 86 listeners.add(listener); 87 } 88 89 90 public void removeUpdateModelChangedListener(IUpdateModelChangedListener listener) { 91 if (listeners.contains(listener)) 92 listeners.remove(listener); 93 } 94 95 public void fireObjectsAdded(Object parent, Object [] children) { 96 for (Iterator iter=listeners.iterator(); 97 iter.hasNext();) { 98 IUpdateModelChangedListener listener = (IUpdateModelChangedListener)iter.next(); 99 listener.objectsAdded(parent, children); 100 } 101 } 102 103 104 public void fireObjectsRemoved(Object parent, Object [] children) { 105 for (Iterator iter=listeners.iterator(); 106 iter.hasNext();) { 107 IUpdateModelChangedListener listener = (IUpdateModelChangedListener)iter.next(); 108 listener.objectsRemoved(parent, children); 109 } 110 } 111 112 public void fireObjectChanged(Object object, String property) { 113 for (Iterator iter=listeners.iterator(); 114 iter.hasNext();) { 115 IUpdateModelChangedListener listener = (IUpdateModelChangedListener)iter.next(); 116 listener.objectChanged(object, property); 117 } 118 } 119 public Object getAdapter(Class key) { 120 return null; 121 } 122 } 123 | Popular Tags |