Esempio n. 1
0
  boolean needsRefresh(
      Class<? extends IEntity> entityClass,
      Set<? extends ModelEvent> events,
      boolean searchResultsChanged) {

    /* In case the Filter is not active at all */
    if (fMatcher == null && fType == Type.SHOW_ALL) return false;

    /* News Event */
    if (entityClass.equals(INews.class)) {
      if (fType == Type.SHOW_NEW) return CoreUtils.isNewStateChange(events);
      else if (fType == Type.SHOW_UNREAD) return CoreUtils.isReadStateChange(events);
      else if (fType == Type.SHOW_STICKY) return CoreUtils.isStickyStateChange(events);
    }

    /* Bookmark Event */
    else if (IBookMark.class.isAssignableFrom(entityClass)) {
      if (fMatcher != null) return true;

      if (fType == Type.SHOW_NEVER_VISITED || fType == Type.SHOW_ERRONEOUS) return true;
    }

    /* Searchmark / News Bin Event */
    else if (ISearchMark.class.isAssignableFrom(entityClass)
        || INewsBin.class.isAssignableFrom(entityClass)) {
      if (fMatcher != null && !searchResultsChanged) return true;

      if (fType == Type.SHOW_NEW || fType == Type.SHOW_UNREAD) return true;
    }

    return false;
  }
  void onGenerateName() {
    List<ISearchCondition> conditions = fSearchConditionList.createConditions();
    ISearchCondition locationCondition = fLocationControl.toScopeCondition();
    if (locationCondition != null) conditions.add(locationCondition);

    String name = CoreUtils.getName(conditions, fMatchAllRadio.getSelection());
    if (name.length() > 0) {
      fNameInput.setText(name);
      fNameInput.selectAll();
    }
  }
  /*
   * @see org.rssowl.ui.dialogs.properties.IEntityPropertyPage#finish()
   */
  public void finish() {

    /* Reparent if necessary */
    for (IEntity entity : fEntities) {
      ISearchMark mark = (ISearchMark) entity;
      if (mark.getParent() != fFolderChooser.getFolder()) {
        ReparentInfo<IFolderChild, IFolder> reparent =
            new ReparentInfo<IFolderChild, IFolder>(mark, fFolderChooser.getFolder(), null, null);
        CoreUtils.reparentWithProperties(Collections.singletonList(reparent));
      }
    }
  }
  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, 16));

    /* 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));
    ((GridLayout) scopeContainer.getLayout()).marginLeft = 2;

    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;
  }