Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.ISearchMark


    ISearchField locationField = fFactory.createSearchField(INews.LOCATION, INews.class.getName());
    ISearchCondition condition1 = fFactory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList(bookmark)));
    ISearchCondition condition2 = fFactory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList(bin)));

    ISearchMark sm = fFactory.createSearchMark(null, root, "Search");
    sm.addSearchCondition(condition1);
    sm.addSearchCondition(condition2);

    DynamicDAO.save(root);

    Long bmId = bookmark.getId();
    Long binId = bin.getId();

    root = null;
    locationField = null;
    condition1 = null;
    condition2 = null;
    sm = null;
    bookmark = null;
    bin = null;

    Runtime.getRuntime().gc();

    Owl.getPersistenceService().shutdown(false);
    Owl.getPersistenceService().startup(new NullProgressLongOperationMonitor());

    Collection<ISearchMark> sms = DynamicDAO.loadAll(ISearchMark.class);
    assertEquals(1, sms.size());

    sm = sms.iterator().next();
    assertEquals(2, sm.getSearchConditions().size());

    List<ISearchCondition> conditions = sm.getSearchConditions();
    boolean foundBm = false;
    boolean foundBin = false;

    for (ISearchCondition condition : conditions) {
      assertNotNull(condition.getValue());
View Full Code Here


    childs.add(bookmark1);
    childs.add(bookmark2);

    ISearchCondition condition = fFactory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(childs));

    ISearchMark sm = fFactory.createSearchMark(null, root, "Search");
    sm.addSearchCondition(condition);

    DynamicDAO.save(root);

    Long bmId1 = bookmark1.getId();
    Long bmId2 = bookmark2.getId();

    root = null;
    locationField = null;
    condition = null;
    sm = null;
    bookmark1 = null;
    bookmark2 = null;

    Runtime.getRuntime().gc();

    Owl.getPersistenceService().shutdown(false);
    Owl.getPersistenceService().startup(new NullProgressLongOperationMonitor());

    Collection<ISearchMark> sms = DynamicDAO.loadAll(ISearchMark.class);
    assertEquals(1, sms.size());

    sm = sms.iterator().next();
    assertEquals(1, sm.getSearchConditions().size());

    boolean foundBm1 = false;
    boolean foundBm2 = false;

    condition = sm.getSearchConditions().get(0);
    assertNotNull(condition.getValue());
    assertEquals(true, condition.getValue() instanceof Long[][]);

    Long[][] value = (Long[][]) condition.getValue();
    assertEquals(2, value[1].length);
View Full Code Here

    ISearchField locationField = fFactory.createSearchField(INews.LOCATION, INews.class.getName());
    ISearchCondition condition1 = fFactory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList(subRoot)));
    ISearchCondition condition2 = fFactory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList(bin)));

    ISearchMark sm = fFactory.createSearchMark(null, root, "Search");
    sm.addSearchCondition(condition1);
    sm.addSearchCondition(condition2);

    DynamicDAO.save(root);

    Long folderId = subRoot.getId();
    Long binId = bin.getId();

    root = null;
    locationField = null;
    condition1 = null;
    condition2 = null;
    sm = null;
    subRoot = null;
    bin = null;

    Runtime.getRuntime().gc();

    Owl.getPersistenceService().shutdown(false);
    Owl.getPersistenceService().startup(new NullProgressLongOperationMonitor());

    Collection<ISearchMark> sms = DynamicDAO.loadAll(ISearchMark.class);
    assertEquals(1, sms.size());

    sm = sms.iterator().next();
    assertEquals(2, sm.getSearchConditions().size());

    List<ISearchCondition> conditions = sm.getSearchConditions();
    boolean foundFolder = false;
    boolean foundBin = false;

    for (ISearchCondition condition : conditions) {
      assertNotNull(condition.getValue());
View Full Code Here

          iterator.remove();
      }

      /* Search (exclude if another Search with same name Exists at same Location and same Conditions) */
      else if (child instanceof ISearchMark) {
        ISearchMark search = (ISearchMark) child;
        if (CoreUtils.existsSearchMark(search))
          iterator.remove();
      }

      /* Folder */
 
View Full Code Here

          folder.removeChild(bin);
      }

      /* Search (exclude if another Search with same name Exists at same Location and same Conditions) */
      else if (child instanceof ISearchMark) {
        ISearchMark search = (ISearchMark) child;
        if (CoreUtils.existsSearchMark(search))
          folder.removeChild(search);
      }

      /* Folder */
 
View Full Code Here

    IModelFactory factory = Owl.getModelFactory();
    String newsEntityName = INews.class.getName();

    /* SearchCondition: New and Updated News */
    {
      ISearchMark mark = factory.createSearchMark(null, root, Messages.ImportWizard_NEW_UPDATED_NEWS);
      mark.setMatchAllConditions(true);

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, INews.State.UPDATED));
    }

    /* SearchCondition: Recent News */
    {
      ISearchMark mark = factory.createSearchMark(null, root, Messages.ImportWizard_RECENT_NEWS);
      mark.setMatchAllConditions(true);

      ISearchField field1 = factory.createSearchField(INews.AGE_IN_DAYS, newsEntityName);
      factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS_LESS_THAN, 2);
    }

    /* SearchCondition: News with Attachments */
    {
      ISearchMark mark = factory.createSearchMark(null, root, Messages.ImportWizard_NEWS_WITH_ATTACHMENTS);
      mark.setMatchAllConditions(true);

      ISearchField field = factory.createSearchField(INews.HAS_ATTACHMENTS, newsEntityName);
      factory.createSearchCondition(null, mark, field, SearchSpecifier.IS, true);
    }

    /* SearchCondition: Sticky News */
    {
      ISearchMark mark = factory.createSearchMark(null, root, Messages.ImportWizard_STICKY_NEWS);
      mark.setMatchAllConditions(true);

      ISearchField field = factory.createSearchField(INews.IS_FLAGGED, newsEntityName);
      factory.createSearchCondition(null, mark, field, SearchSpecifier.IS, true);
    }

    /* SearchCondition: News is Labeld */
    {
      ISearchMark mark = factory.createSearchMark(null, root, Messages.ImportWizard_LABELED_NEWS);
      IPreferenceScope preferences = Owl.getPreferenceService().getEntityScope(mark);
      preferences.putInteger(DefaultPreferences.BM_NEWS_GROUPING, NewsGrouping.Type.GROUP_BY_LABEL.ordinal());

      ISearchField field = factory.createSearchField(INews.LABEL, newsEntityName);
      factory.createSearchCondition(null, mark, field, SearchSpecifier.IS, "*"); //$NON-NLS-1$
View Full Code Here

    IFolder root = fFactory.createFolder(null, null, "Root");

    ISearchField field = fFactory.createSearchField(INews.IS_FLAGGED, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, true);

    ISearchMark search = fFactory.createSearchMark(null, root, "Search");
    search.addSearchCondition(condition);

    DynamicDAO.save(root);

    IFeed feed = fFactory.createFeed(null, new URI("feed"));
    INews news1 = fFactory.createNews(null, feed, new Date());
    news1.setFlagged(true);
    INews news2 = fFactory.createNews(null, feed, new Date());
    news2.setFlagged(true);
    INews news3 = fFactory.createNews(null, feed, new Date());
    news3.setFlagged(true);

    DynamicDAO.save(feed);

    waitForIndexer();
    Controller.getDefault().getSavedSearchService().updateSavedSearches(true);

    assertTrue(search.containsNews(news1));
    assertTrue(search.containsNews(news2));
    assertTrue(search.containsNews(news3));

    List<INews> news = search.getNews();
    assertEquals(3, news.size());

    news = search.getNews(INews.State.getVisible());
    assertEquals(3, news.size());

    List<NewsReference> newsRefs = search.getNewsRefs();
    assertEquals(3, newsRefs.size());

    newsRefs = search.getNewsRefs(INews.State.getVisible());
    assertEquals(3, newsRefs.size());
  }
View Full Code Here

    IFolder root = fFactory.createFolder(null, null, "Root");

    ISearchField field = fFactory.createSearchField(INews.IS_FLAGGED, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, true);

    ISearchMark search = fFactory.createSearchMark(null, root, "Search");
    search.addSearchCondition(condition);

    DynamicDAO.save(root);

    ISearchMark searchmark = DynamicDAO.getDAO(ISearchMarkDAO.class).load(condition);
    assertNotNull(searchmark);
    assertEquals("Search", searchmark.getName());
    assertEquals(root, searchmark.getParent());
  }
View Full Code Here

  public ImageDescriptor getImage() {
    return null;
  }

  private Control createContentsSingleSearch(Composite parent) {
    ISearchMark mark = (ISearchMark) fEntities.get(0);
    Pair<ISearchCondition, List<ISearchCondition>> conditions = CoreUtils.splitScope(mark.getSearchConditions());

    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(LayoutUtils.createGridLayout(2, 10, 10));

    /* Name */
    Label nameLabel = new Label(container, SWT.None);
    nameLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    nameLabel.setText(Messages.SearchMarkPropertyPage_NAME);

    Composite nameContainer = new Composite(container, Application.IS_MAC ? SWT.NONE : SWT.BORDER);
    nameContainer.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    nameContainer.setLayout(LayoutUtils.createGridLayout(2, 0, 0));
    if (!Application.IS_MAC)
      nameContainer.setBackground(container.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));

    fNameInput = new Text(nameContainer, Application.IS_MAC ? SWT.BORDER : SWT.NONE);
    OwlUI.makeAccessible(fNameInput, nameLabel);
    fNameInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
    fNameInput.setText(mark.getName());

    ToolBar generateTitleBar = new ToolBar(nameContainer, SWT.FLAT);
    OwlUI.makeAccessible(generateTitleBar, Messages.SearchMarkPropertyPage_NAME_FROM_CONDITION);
    if (!Application.IS_MAC)
      generateTitleBar.setBackground(container.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));

    ToolItem generateTitleItem = new ToolItem(generateTitleBar, SWT.PUSH);
    generateTitleItem.setImage(OwlUI.getImage(fSite.getResourceManager(), "icons/etool16/info.gif")); //$NON-NLS-1$
    generateTitleItem.setToolTipText(Messages.SearchMarkPropertyPage_NAME_FROM_CONDITION);
    generateTitleItem.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        onGenerateName();
      }
    });

    /* Location */
    Label locationLabel = new Label(container, SWT.None);
    locationLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    locationLabel.setText(Messages.SearchMarkPropertyPage_LOCATION);

    fFolderChooser = new FolderChooser(container, mark.getParent(), SWT.BORDER, true);
    fFolderChooser.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    fFolderChooser.setLayout(LayoutUtils.createGridLayout(1, 0, 0, 2, 5, false));
    fFolderChooser.setBackground(container.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));

    Composite topControlsContainer = new Composite(container, SWT.None);
    topControlsContainer.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    topControlsContainer.setLayout(LayoutUtils.createGridLayout(4, 5, 0));
    ((GridLayout) topControlsContainer.getLayout()).marginTop = 10;

    fMatchAllRadio = new Button(topControlsContainer, SWT.RADIO);
    fMatchAllRadio.setText(Messages.SearchMarkPropertyPage_MATCH_ALL);
    fMatchAllRadio.setSelection(mark.matchAllConditions());

    fMatchAnyRadio = new Button(topControlsContainer, SWT.RADIO);
    fMatchAnyRadio.setText(Messages.SearchMarkPropertyPage_MATCH_ANY);
    fMatchAnyRadio.setSelection(!mark.matchAllConditions());

    /* Separator */
    Label sep = new Label(topControlsContainer, SWT.SEPARATOR | SWT.VERTICAL);
    sep.setLayoutData(new GridData(SWT.DEFAULT, 20));

    /* Scope */
    Composite scopeContainer = new Composite(topControlsContainer, SWT.None);
    scopeContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
    scopeContainer.setLayout(LayoutUtils.createGridLayout(2, 0, 0, 0, 5, false));

    Label scopeLabel = new Label(scopeContainer, SWT.NONE);
    scopeLabel.setText(Messages.SearchMarkPropertyPage_SEARCH_IN);

    fLocationControl = new LocationControl(scopeContainer, SWT.WRAP) {
      @Override
      protected String getDefaultLabel() {
        return Messages.SearchMarkPropertyPage_ALL_NEWS;
      }
    };
    fLocationControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
    ((GridData) fLocationControl.getLayoutData()).widthHint = 100;
    fLocationControl.setLayout(LayoutUtils.createGridLayout(1, 0, 0, 0, 0, false));

    if (conditions.getFirst() != null && conditions.getFirst().getValue() instanceof Long[][])
      fLocationControl.select((Long[][]) conditions.getFirst().getValue());

    Composite conditionsContainer = new Composite(container, SWT.BORDER);
    conditionsContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    conditionsContainer.setLayout(LayoutUtils.createGridLayout(1));
    conditionsContainer.setBackground(container.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    conditionsContainer.setBackgroundMode(SWT.INHERIT_FORCE);

    /* Search Conditions List */
    fSearchConditionList = new SearchConditionList(conditionsContainer, SWT.None, conditions.getSecond());
    fSearchConditionList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    if (conditions.getSecond().size() <= 3)
      fSearchConditionList.setVisibleItemCount(3);
    else //Workaround for Bug 1544: State Condition not enough width in propertes when scrollbar showing
      fSearchConditionList.setVisibleItemCount(Math.min(7, conditions.getSecond().size()));

    if (CoreUtils.isLocationConflict(mark.getSearchConditions()))
      fSite.setMessage(Messages.SearchMarkPropertyPage_LOCATION_WARNING, IPropertyDialogSite.MessageType.WARNING);

    return container;
  }
View Full Code Here

    /* Perform OK for multi selection */
    return performOkMultiSearch(entitiesToSave);
  }

  private boolean performOkSingleSearch(Set<IEntity> entitiesToSave) {
    ISearchMark mark = (ISearchMark) fEntities.get(0);

    /* Require a Name */
    if (fNameInput.getText().length() == 0) {
      fSite.select(this);
      fNameInput.setFocus();
      fSite.setMessage(Messages.SearchMarkPropertyPage_SEARCH_NAME, IPropertyDialogSite.MessageType.ERROR);

      return false;
    }

    /* Require a Condition */
    if (fSearchConditionList.isEmpty()) {
      fSite.select(this);
      fNameInput.setFocus();
      fSite.setMessage(Messages.SearchMarkPropertyPage_DEFINE_SEARCH, IPropertyDialogSite.MessageType.ERROR);

      return false;
    }

    /* Check for changed Name */
    if (!mark.getName().equals(fNameInput.getText())) {
      mark.setName(fNameInput.getText());
      entitiesToSave.add(mark);
    }

    /* Update match-all-condition */
    if (mark.matchAllConditions() != fMatchAllRadio.getSelection()) {
      mark.setMatchAllConditions(fMatchAllRadio.getSelection());
      entitiesToSave.add(mark);
      fSearchChanged = true;
    }

    /* Update Conditions (TODO Could be optimized to not replace all conditions) */
    if (fSearchConditionList.isModified() || fLocationControl.isModified()) {
      entitiesToSave.add(mark);
      fSearchChanged = true;

      /* Remove Old Conditions */
      List<ISearchCondition> oldConditions = mark.getSearchConditions();
      for (ISearchCondition oldCondition : oldConditions) {
        mark.removeSearchCondition(oldCondition);
      }

      /* Delete from DB */
      DynamicDAO.deleteAll(oldConditions);

      /* Add New Conditions */
      fSearchConditionList.createConditions(mark);
      ISearchCondition locationCondition = fLocationControl.toScopeCondition();
      if (locationCondition != null)
        mark.addSearchCondition(locationCondition);
    }

    /* Re-Run search if conditions changed */
    if (fSearchChanged)
      Controller.getDefault().getSavedSearchService().updateSavedSearches(Collections.singleton(mark), true);
View Full Code Here

TOP

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

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.