/**
  * Add the element to the viewer.
  *
  * @param parent the parent of the element which is already added to the viewer
  * @param element the element to be added to the viewer
  */
 protected void doAdd(ISynchronizeModelElement parent, ISynchronizeModelElement element) {
   if (additionsMap == null) {
     if (Policy.DEBUG_SYNC_MODELS) {
       System.out.println("Added view item " + element.getName()); // $NON-NLS-1$
     }
     AbstractTreeViewer viewer = (AbstractTreeViewer) getViewer();
     viewer.add(parent, element);
   } else {
     // Accumulate the additions
     if (Policy.DEBUG_SYNC_MODELS) {
       System.out.println("Queueing view item for addition " + element.getName()); // $NON-NLS-1$
     }
     Set toAdd = (Set) additionsMap.get(parent);
     if (toAdd == null) {
       toAdd = new HashSet();
       additionsMap.put(parent, toAdd);
     }
     toAdd.add(element);
   }
 }
Ejemplo n.º 2
0
 protected void doRemove(TestModelChange change) {
   if (fViewer instanceof ListViewer) {
     ((ListViewer) fViewer).remove(change.getChildren());
   } else if (fViewer instanceof TableViewer) {
     ((TableViewer) fViewer).remove(change.getChildren());
   } else if (fViewer instanceof AbstractTreeViewer) {
     ((AbstractTreeViewer) fViewer).remove(change.getChildren());
   } else if (fViewer instanceof ComboViewer) {
     ((ComboViewer) fViewer).remove(change.getChildren());
   } else {
     Assert.isTrue(false, "Unknown kind of viewer");
   }
 }
Ejemplo n.º 3
0
  private void remove(Object element, boolean refreshViewer) {
    // precondition here: fResult.getMatchCount(child) <= 0

    if (hasChildren(element)) {
      if (refreshViewer) fTreeViewer.refresh(element);
    } else {
      if (!hasMatches(element)) {
        fChildrenMap.remove(element);
        Object parent = getParent(element);
        if (parent != null) {
          removeFromSiblings(element, parent);
          remove(parent, refreshViewer);
        } else {
          removeFromSiblings(element, fResult);
          if (refreshViewer) fTreeViewer.refresh();
        }
      } else {
        if (refreshViewer) {
          fTreeViewer.refresh(element);
        }
      }
    }
  }
Ejemplo n.º 4
0
 private void insert(Object child, boolean refreshViewer) {
   int searchFor = ((Q7SearchQuery) fResult.getQuery()).getSearchFor();
   boolean isDependencySearch =
       searchFor == Q7SearchQuery.CONTEXTS_BY_ID
           || searchFor == Q7SearchQuery.TESTCASE_BY_ID
           || searchFor == Q7SearchQuery.VERIFICATION_BY_ID;
   if (isDependencySearch) {
     child = getParent(child);
   }
   Object parent = getParent(child);
   while (parent != null) {
     if (insertChild(parent, child)) {
       if (refreshViewer) fTreeViewer.add(parent, child);
     } else {
       if (refreshViewer) fTreeViewer.refresh(parent);
       return;
     }
     child = parent;
     parent = getParent(child);
   }
   if (insertChild(fResult, child)) {
     if (refreshViewer) fTreeViewer.add(fResult, child);
   }
 }
Ejemplo n.º 5
0
 protected void doInsert(TestModelChange change) {
   if (fViewer instanceof ListViewer) {
     if (change.getParent() != null && change.getParent().equals(fViewer.getInput())) {
       ((ListViewer) fViewer).add(change.getChildren());
     }
   } else if (fViewer instanceof TableViewer) {
     if (change.getParent() != null && change.getParent().equals(fViewer.getInput())) {
       ((TableViewer) fViewer).add(change.getChildren());
     }
   } else if (fViewer instanceof AbstractTreeViewer) {
     ((AbstractTreeViewer) fViewer).add(change.getParent(), change.getChildren());
   } else if (fViewer instanceof ComboViewer) {
     ((ComboViewer) fViewer).add(change.getChildren());
   } else {
     Assert.isTrue(false, "Unknown kind of viewer");
   }
 }
  /*
   * Method that can be called from the UI thread to update the view model.
   */
  private void internalRunViewUpdate(final Runnable runnable, boolean preserveExpansion) {
    StructuredViewer viewer = getViewer();
    IResource[] expanded = null;
    IResource[] selected = null;
    try {
      if (Utils.canUpdateViewer(viewer)) {
        viewer.getControl().setRedraw(false);
        if (preserveExpansion) {
          expanded = provider.getExpandedResources();
          selected = provider.getSelectedResources();
        }
        if (viewer instanceof AbstractTreeViewer && additionsMap == null)
          additionsMap = new HashMap();
      }
      runnable.run();
    } finally {
      if (Utils.canUpdateViewer(viewer)) {
        try {
          if (additionsMap != null && !additionsMap.isEmpty() && Utils.canUpdateViewer(viewer)) {
            for (Iterator iter = additionsMap.keySet().iterator(); iter.hasNext(); ) {
              ISynchronizeModelElement parent = (ISynchronizeModelElement) iter.next();
              if (Policy.DEBUG_SYNC_MODELS) {
                System.out.println("Adding child view items of " + parent.getName()); // $NON-NLS-1$
              }
              Set toAdd = (Set) additionsMap.get(parent);
              ((AbstractTreeViewer) viewer).add(parent, toAdd.toArray(new Object[toAdd.size()]));
            }
            additionsMap = null;
          }
          if (expanded != null) {
            provider.expandResources(expanded);
          }
          if (selected != null) {
            provider.selectResources(selected);
          }
        } finally {
          viewer.getControl().setRedraw(true);
        }
      }
    }

    ISynchronizeModelElement root = provider.getModelRoot();
    if (root instanceof SynchronizeModelElement) ((SynchronizeModelElement) root).fireChanges();
  }
Ejemplo n.º 7
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.search.internal.ui.text.IFileSearchContentProvider#
  * elementsChanged(java.lang.Object[])
  */
 public synchronized void elementsChanged(Object[] updatedElements) {
   for (int i = 0; i < updatedElements.length; i++) {
     if (!(updatedElements[i] instanceof LineElement)) {
       // change events to elements are reported in file search
       if (fResult.getMatchCount(updatedElements[i]) > 0) insert(updatedElements[i], true);
       else remove(updatedElements[i], true);
     } else {
       // change events to line elements are reported in text search
       LineElement lineElement = (LineElement) updatedElements[i];
       int nMatches = lineElement.getNumberOfMatches(fResult);
       if (nMatches > 0) {
         if (hasChild(lineElement.getParent(), lineElement)) {
           fTreeViewer.update(new Object[] {lineElement, lineElement.getParent()}, null);
         } else {
           insert(lineElement, true);
         }
       } else {
         remove(lineElement, true);
       }
     }
   }
 }
Ejemplo n.º 8
0
 public void clear() {
   initialize(fResult);
   fTreeViewer.refresh();
 }