Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.IFolder


  private List<ITask> getReloadFeedsTasks(boolean withRetention) {
    List<ITask> tasks = new ArrayList<ITask>();
    Random rand = new Random();

    /* Create Folder with all Bookmarks */
    IFolder rootFolder = new Folder(null, null, "Root");
    for (int i = 1; i < FEEDS + 1; i++) {
      try {
        URI feedLink = fPluginLocation.resolve("data/performance/" + i + ".xml").toURL().toURI();

        IFeed feed = new Feed(feedLink);

        if (withRetention) {
          for (int j = 0; j < 10; j++) {
            INews news = new News(feed);
            news.setTitle("Random Title " + j);
            news.setDescription(getLongDecription());
            news.setLink(new URI("http://www." + System.currentTimeMillis() + ".com/" + rand.nextInt(10000) + j));
            news.setComments("Comments");
            news.setState(INews.State.READ);
            feed.addNews(news);
          }
        }

        feed = DynamicDAO.save(feed);

        IBookMark bookmark = new BookMark(null, rootFolder, new FeedLinkReference(feed.getLink()), "Bookmark");

        if (withRetention)
          Owl.getPreferenceService().getEntityScope(bookmark).putBoolean(DefaultPreferences.DEL_READ_NEWS_STATE, true);

        rootFolder.addMark(bookmark, null, false);
        DynamicDAO.save(rootFolder);
      } catch (Exception e) {
        Activator.getDefault().logError(e.getMessage(), e);
      }
    }

    /* Create Tasks */
    List<IMark> marks = rootFolder.getMarks();
    for (IMark mark : marks) {
      if (mark instanceof IBookMark) {
        final IBookMark bookmark = (IBookMark) mark;

        tasks.add(new TaskAdapter() {
View Full Code Here


  private void importDefaults(List<ILabel> labels) throws PersistenceException, InterpreterException, ParserException {

    /* Import Default Feeds */
    InputStream inS = getClass().getResourceAsStream("/default_feeds.xml"); //$NON-NLS-1$;
    List<? extends IEntity> types = Owl.getInterpreter().importFrom(inS);
    IFolder imported = (IFolder) types.get(0);
    imported.setName("Default"); //$NON-NLS-1$

    /* Create Default SearchMarks */
    String newsEntityName = INews.class.getName();

    /* SearchCondition: New and Updated News */
 
View Full Code Here

    /* Import from File */
    File file = new File(fileName);
    InputStream inS = new FileInputStream(file);
    List<? extends IEntity> types = Owl.getInterpreter().importFrom(inS);
    IFolder defaultContainer = (IFolder) types.get(0);

    /* Map Old Id to IFolderChild */
    Map<Long, IFolderChild> mapOldIdToFolderChild = ImportUtils.createOldIdToEntityMap(types);

    /* Load SearchMarks containing location condition */
    List<ISearchMark> locationConditionSearches = ImportUtils.getLocationConditionSearches(types);

    /* Load the current selected Set */
    IFolder selectedRootFolder;
    if (!InternalOwl.TESTING) {
      String selectedBookMarkSetPref = BookMarkExplorer.getSelectedBookMarkSetPref(OwlUI.getWindow());
      Long selectedFolderID = fPrefsDAO.load(selectedBookMarkSetPref).getLong();
      selectedRootFolder = fFolderDAO.load(selectedFolderID);
    } else {
      Collection<IFolder> rootFolders = DynamicDAO.getDAO(IFolderDAO.class).loadRoots();
      selectedRootFolder = rootFolders.iterator().next();
    }

    /* Load all Root Folders */
    Set<IFolder> rootFolders;
    if (!InternalOwl.TESTING)
      rootFolders = fCacheService.getRootFolders();
    else
      rootFolders = new HashSet<IFolder>(DynamicDAO.getDAO(IFolderDAO.class).loadRoots());

    /* 1.) Handle Folders and Marks from default Container */
    {

      /* Also update Map of Old ID */
      if (defaultContainer.getProperty(ITypeImporter.ID_KEY) != null)
        mapOldIdToFolderChild.put((Long) defaultContainer.getProperty(ITypeImporter.ID_KEY), selectedRootFolder);

      /* Reparent and Save */
      reparentAndSaveChildren(defaultContainer, selectedRootFolder);
      entitiesToReload.addAll(defaultContainer.getChildren());
    }

    /* 2.) Handle other Sets */
    for (int i = 1; i < types.size(); i++) {
      IFolder setFolder = (IFolder) types.get(i);
      IFolder existingSetFolder = null;

      /* Check if set already exists */
      for (IFolder rootFolder : rootFolders) {
        if (rootFolder.getName().equals(setFolder.getName())) {
          existingSetFolder = rootFolder;
          break;
        }
      }

      /* Reparent into Existing Set */
      if (existingSetFolder != null) {

        /* Also update Map of Old ID */
        if (setFolder.getProperty(ITypeImporter.ID_KEY) != null)
          mapOldIdToFolderChild.put((Long) setFolder.getProperty(ITypeImporter.ID_KEY), existingSetFolder);

        /* Reparent and Save */
        reparentAndSaveChildren(setFolder, existingSetFolder);
        entitiesToReload.addAll(existingSetFolder.getChildren());
      }

      /* Otherwise save as new Set */
      else {

View Full Code Here

  /*
   * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
   */
  public Object[] getElements(Object inputElement) {
    if (inputElement instanceof IFolder) {
      IFolder rootFolder = (IFolder) inputElement;

      /* No Grouping */
      if (!fBookmarkGrouping.isActive()) {
        Collection<IFolderChild> elements = rootFolder.getChildren();

        /* Return Children */
        return elements.toArray();
      }

View Full Code Here

   */
  public Object[] getChildren(Object parentElement) {

    /* Return Children of Folder */
    if (parentElement instanceof IFolder) {
      IFolder parent = (IFolder) parentElement;
      Collection<IFolderChild> children = parent.getChildren();

      return children.toArray();
    }

    /* Return Children of Group */
 
View Full Code Here

    /* Grouping not enabled */
    else {

      /* Parent Folder of Folder */
      if (element instanceof IFolder) {
        IFolder folder = (IFolder) element;
        return folder.getParent();
      }

      /* Parent Folder of Mark */
      else if (element instanceof IMark) {
        IMark mark = (IMark) element;
View Full Code Here

  /*
   * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
   */
  public boolean hasChildren(Object element) {
    if (element instanceof IFolder) {
      IFolder folder = (IFolder) element;
      return folder.getChildren().size() > 0;
    }

    else if (element instanceof EntityGroup)
      return ((EntityGroup) element).size() > 0;

View Full Code Here

              Set<IFolder> parentsToUpdate = new HashSet<IFolder>();
              List<Object> expandedElements = new ArrayList<Object>(Arrays.asList(fViewer.getExpandedElements()));
              try {
                fViewer.getControl().getParent().setRedraw(false);
                for (Entry<IFolder, IFolder> entry : entries) {
                  IFolder reparentedFolder = entry.getKey();
                  IFolder oldParent = entry.getValue();

                  /* Reparent while keeping the Selection / Expansion */
                  ISelection selection = fViewer.getSelection();
                  boolean expand = expandedElements.contains(reparentedFolder);
                  fViewer.remove(oldParent, new Object[] { reparentedFolder });
                  fViewer.refresh(reparentedFolder.getParent(), false);
                  fViewer.setSelection(selection);

                  if (expand)
                    fViewer.setExpandedState(reparentedFolder, expand);

                  /* Remember to update parents */
                  parentsToUpdate.add(oldParent);
                  parentsToUpdate.add(reparentedFolder.getParent());
                }
              } finally {
                fViewer.getControl().getParent().setRedraw(true);
              }

              /* Update old Parents of Reparented Bookmarks */
              for (IFolder folder : parentsToUpdate)
                updateFolderAndParents(folder);
            }

            /* Handle Updated Folders */
            if (updatedFolders != null) {
              for (IFolder folder : updatedFolders) {
                if (fInput.equals(folder))
                  fViewer.refresh(fInput);
                else
                  fViewer.refresh(folder);
              }
            }
          }
        });
      }

      /* Folders got deleted */
      public void entitiesDeleted(final Set<FolderEvent> events) {
        JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
          public void run() {

            /* Retrieve Removed Folders */
            Set<IFolder> removedFolders = null;
            for (FolderEvent event : events) {
              if (event.isRoot() && event.getEntity().getParent() != null) {
                if (removedFolders == null)
                  removedFolders = new HashSet<IFolder>();
                removedFolders.add(event.getEntity());
              }
            }

            /* Event not interesting for us or we are disposed */
            if (removedFolders == null || removedFolders.size() == 0)
              return;

            /* Ask Filter */
            if (fBookmarkFilter.needsRefresh(IFolder.class, events))
              fViewer.refresh(false);

            /* Ask Group */
            else if (fBookmarkGrouping.needsRefresh(IFolder.class))
              fViewer.refresh(false);

            /* React normally then */
            else
              fViewer.remove(removedFolders.toArray());

            /* Update Read-State counters on Parents */
            if (!fBookmarkGrouping.isActive()) {
              for (FolderEvent event : events) {
                IFolder eventParent = event.getEntity().getParent();
                if (eventParent != null && eventParent.getParent() != null)
                  updateFolderAndParents(eventParent);
              }
            }
          }
        });
      }

      /* Folders got added */
      public void entitiesAdded(final Set<FolderEvent> events) {
        JobRunner.runInUIThread(SELECTION_DELAY, fViewer.getControl(), new Runnable() {
          public void run() {

            /* Reveal and Select added Folders */
            final List<IFolder> addedFolders = new ArrayList<IFolder>();
            for (FolderEvent folderEvent : events) {
              IFolder addedFolder = folderEvent.getEntity();
              if (addedFolder.getParent() != null)
                addedFolders.add(addedFolder);
            }

            if (!addedFolders.isEmpty())
              fViewer.setSelection(new StructuredSelection(addedFolders), true);
          }
        });
      }
    };

    /* BookMark Listener */
    fBookMarkListener = new BookMarkListener() {

      /* BookMarks got Updated */
      public void entitiesUpdated(final Set<BookMarkEvent> events) {
        JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
          public void run() {
            Set<IBookMark> updatedBookMarks = null;
            Map<IBookMark, IFolder> reparentedBookMarks = null;

            /* Retrieve Updated BookMarks */
            for (BookMarkEvent event : events) {
              if (event.isRoot()) {

                /* BookMark got reparented */
                if (event.getOldParent() != null) {
                  if (reparentedBookMarks == null)
                    reparentedBookMarks = new HashMap<IBookMark, IFolder>();
                  reparentedBookMarks.put(event.getEntity(), event.getOldParent());
                }

                /* Normal Update */
                else {
                  if (updatedBookMarks == null)
                    updatedBookMarks = new HashSet<IBookMark>();
                  updatedBookMarks.add(event.getEntity());
                }
              }
            }

            /* Event not interesting for us or we are disposed */
            if (updatedBookMarks == null && reparentedBookMarks == null)
              return;

            /* Ask Filter */
            if (fBookmarkFilter.needsRefresh(IBookMark.class, events))
              fViewer.refresh(false);

            /* Ask Group */
            else if (fBookmarkGrouping.needsRefresh(IBookMark.class))
              fViewer.refresh(false);

            /* Handle reparented Folders */
            else if (reparentedBookMarks != null) {
              Set<Entry<IBookMark, IFolder>> entries = reparentedBookMarks.entrySet();
              Set<IFolder> parentsToUpdate = new HashSet<IFolder>();
              try {
                fViewer.getControl().getParent().setRedraw(false);
                for (Entry<IBookMark, IFolder> entry : entries) {
                  IBookMark reparentedBookMark = entry.getKey();
                  IFolder oldParent = entry.getValue();

                  /* Reparent while keeping the Selection */
                  ISelection selection = fViewer.getSelection();
                  fViewer.remove(oldParent, new Object[] { reparentedBookMark });
                  fViewer.refresh(reparentedBookMark.getParent(), false);
                  fViewer.setSelection(selection);

                  /* Remember to update parents */
                  parentsToUpdate.add(oldParent);
                  parentsToUpdate.add(reparentedBookMark.getParent());
                }
              } finally {
                fViewer.getControl().getParent().setRedraw(true);
              }

              /* Update old Parents of Reparented Bookmarks */
              for (IFolder folder : parentsToUpdate)
                updateFolderAndParents(folder);
            }

            /* Handle Updated Folders */
            if (updatedBookMarks != null)
              fViewer.update(updatedBookMarks.toArray(), null);
          }
        });
      }

      /* BookMarks got Deleted */
      public void entitiesDeleted(final Set<BookMarkEvent> events) {
        JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
          public void run() {

            /* Retrieve Removed BookMarks */
            Set<IBookMark> removedBookMarks = null;
            for (BookMarkEvent event : events) {
              if (event.isRoot()) {
                if (removedBookMarks == null)
                  removedBookMarks = new HashSet<IBookMark>();
                removedBookMarks.add(event.getEntity());
              }
            }

            /* Event not interesting for us or we are disposed */
            if (removedBookMarks == null || removedBookMarks.size() == 0)
              return;

            /* Ask Filter */
            if (fBookmarkFilter.needsRefresh(IBookMark.class, events))
              fViewer.refresh(false);

            /* Ask Group */
            else if (fBookmarkGrouping.needsRefresh(IBookMark.class))
              fViewer.refresh(false);

            /* React normally then */
            else
              fViewer.remove(removedBookMarks.toArray());

            /* Update Read-State counters on Parents */
            if (!fBookmarkGrouping.isActive()) {
              for (BookMarkEvent event : events) {
                IFolder eventParent = event.getEntity().getParent();
                if (eventParent != null && eventParent.getParent() != null)
                  updateFolderAndParents(eventParent);
              }
            }
          }
        });
      }

      /* BookMarks got Added */
      public void entitiesAdded(Set<BookMarkEvent> events) {

        /* Reveal and Select if single Entity added */
        if (events.size() == 1) {
          final BookMarkEvent event = events.iterator().next();
          JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
            public void run() {
              expand(event.getEntity().getParent());
            }
          });
        }
      }
    };

    {
      /* SearchMark Listener */
      fSearchMarkListener = new SearchMarkListener() {

        /* SearchMarks got Updated */
        public void entitiesUpdated(final Set<SearchMarkEvent> events) {
          JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
            public void run() {
              Set<ISearchMark> updatedSearchMarks = null;
              Map<ISearchMark, IFolder> reparentedSearchMarks = null;

              /* Retrieve Updated SearchMarks */
              for (SearchMarkEvent event : events) {
                if (event.isRoot()) {

                  /* SearchMark got reparented */
                  if (event.getOldParent() != null) {
                    if (reparentedSearchMarks == null)
                      reparentedSearchMarks = new HashMap<ISearchMark, IFolder>();
                    reparentedSearchMarks.put(event.getEntity(), event.getOldParent());
                  }

                  /* Normal Update */
                  else {
                    if (updatedSearchMarks == null)
                      updatedSearchMarks = new HashSet<ISearchMark>();
                    updatedSearchMarks.add(event.getEntity());
                  }
                }
              }

              /* Event not interesting for us or we are disposed */
              if (updatedSearchMarks == null && reparentedSearchMarks == null)
                return;

              /* Ask Filter */
              if (fBookmarkFilter.needsRefresh(ISearchMark.class, events))
                fViewer.refresh(false);

              /* Ask Group */
              else if (fBookmarkGrouping.needsRefresh(ISearchMark.class))
                fViewer.refresh(false);

              /* Handle reparented SearchMarks */
              else if (reparentedSearchMarks != null) {
                Set<Entry<ISearchMark, IFolder>> entries = reparentedSearchMarks.entrySet();
                Set<IFolder> parentsToUpdate = new HashSet<IFolder>();
                try {
                  fViewer.getControl().getParent().setRedraw(false);
                  for (Entry<ISearchMark, IFolder> entry : entries) {
                    ISearchMark reparentedSearchMark = entry.getKey();
                    IFolder oldParent = entry.getValue();

                    /* Reparent while keeping the Selection */
                    ISelection selection = fViewer.getSelection();
                    fViewer.remove(oldParent, new Object[] { reparentedSearchMark });
                    fViewer.refresh(reparentedSearchMark.getParent(), false);
View Full Code Here

  }

  private void collectParents(List<IFolder> parents, IEntity entity) {

    /* Determine Parent Folder */
    IFolder parent = null;
    if (entity instanceof IMark)
      parent = ((IMark) entity).getParent();
    else if (entity instanceof IFolder)
      parent = ((IFolder) entity).getParent();

View Full Code Here

    return false;
  }

  private void expand(IFolder folder) {
    IFolder parent = folder.getParent();
    if (parent != null)
      expand(parent);

    fViewer.setExpandedState(folder, true);
  }
View Full Code Here

TOP

Related Classes of org.rssowl.core.persist.IFolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.