/* (non-Javadoc)
  * @see org.eclipse.jface.viewers.IContentProvider#dispose()
  */
 public void dispose() {
   ICommonContentExtensionSite extensionSite = getExtensionSite();
   if (extensionSite != null) {
     extensionSite.getExtensionStateModel().removePropertyChangeListener(this);
   }
   ISynchronizationContext context = getContext();
   if (context != null) context.getDiffTree().removeDiffChangeListener(this);
   ISynchronizePageConfiguration configuration = getConfiguration();
   if (configuration != null) configuration.removePropertyChangeListener(this);
 }
 private Object[] internalGetChildren(Object parent, boolean isElement) {
   Object element = internalGetElement(parent);
   if (element instanceof ISynchronizationScope) {
     // If the root is a scope, we want to include all models in the scope
     ISynchronizationScope rms = (ISynchronizationScope) element;
     if (rms.getMappings(getModelProviderId()).length > 0) {
       empty = false;
       return new Object[] {getModelProvider()};
     }
     empty = true;
     return new Object[0];
   } else if (element instanceof ISynchronizationContext) {
     ISynchronizationContext context = (ISynchronizationContext) element;
     // If the root is a context, we want to filter by the context
     ISynchronizationContext sc = (ISynchronizationContext) element;
     if (sc.getScope().getMappings(getModelProviderId()).length > 0) {
       Object root = getModelRoot();
       boolean initialized = isInitialized(context);
       if (!initialized
           || getChildrenInContext(sc, root, getDelegateChildren(root, isElement)).length > 0) {
         if (!initialized) requestInitialization(context);
         empty = false;
         return new Object[] {getModelProvider()};
       }
     }
     empty = true;
     return new Object[0];
   }
   if (element == getModelProvider()) {
     ISynchronizationContext context = getContext();
     if (context != null && !isInitialized(context)) {
       return new Object[0];
     }
     element = getModelRoot();
     if (parent instanceof TreePath) {
       parent = TreePath.EMPTY.createChildPath(element);
     } else {
       parent = element;
     }
   }
   Object[] delegateChildren = getDelegateChildren(parent, isElement);
   ISynchronizationContext context = getContext();
   if (context == null) {
     ISynchronizationScope scope = getScope();
     if (scope == null) {
       return delegateChildren;
     } else {
       return getChildrenInScope(scope, parent, delegateChildren);
     }
   } else {
     return getChildrenInContext(context, parent, delegateChildren);
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.ui.navigator.ICommonContentProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite)
  */
 public void init(ICommonContentExtensionSite site) {
   // Set the site
   this.site = site;
   // Configure the content provider based on the site and state model
   site.getExtensionStateModel().addPropertyChangeListener(this);
   ISynchronizePageConfiguration configuration = getConfiguration();
   if (configuration != null) configuration.addPropertyChangeListener(this);
   ITreeContentProvider provider = getDelegateContentProvider();
   if (provider instanceof ICommonContentProvider) {
     ((ICommonContentProvider) provider).init(site);
   }
   ISynchronizationContext context = getContext();
   if (context != null) context.getDiffTree().addDiffChangeListener(this);
 }
 /**
  * Return whether the given object is visible in the synchronization page showing this content
  * based on the diffs in the given context. Visibility is determined by obtaining the diffs for
  * the object from the context by calling {@link #getTraversals(ISynchronizationContext, Object)}
  * to get the traversals, then obtaining the diffs from the context's diff tree and then calling
  * {@link #isVisible(IDiff)} for each diff.
  *
  * @param context the synchronization context
  * @param object the object
  * @return whether the given object is visible in the synchronization page showing this content
  */
 protected boolean isVisible(ISynchronizationContext context, Object object) {
   ResourceTraversal[] traversals = getTraversals(context, object);
   IDiff[] deltas = context.getDiffTree().getDiffs(traversals);
   boolean visible = false;
   if (isVisible(deltas)) {
     visible = true;
   }
   return visible;
 }
 /**
  * Return the subset of children that are of interest from the given context. By default, this
  * method returns those children whose traversals contain a diff in the context. However, it does
  * not include those model elements that do not exist locally but are within the context (e.g.
  * locally deleted elements and remotely added elements). Subclasses must override to include
  * these.
  *
  * @param context the context
  * @param parent the parent of the children
  * @param children the children
  * @return the subset of children that are of interest from the given context
  */
 protected Object[] getChildrenInContext(
     ISynchronizationContext context, Object parent, Object[] children) {
   if (children.length != 0) children = getChildrenInScope(context.getScope(), parent, children);
   if (parent instanceof IResource) {
     IResource resource = (IResource) parent;
     children = getChildrenWithPhantoms(context, resource, children);
   }
   if (children.length == 0) return children;
   return internalGetChildren(context, parent, children);
 }
 private Object[] getChildrenWithPhantoms(
     ISynchronizationContext context, IResource resource, Object[] children) {
   IResource[] setChildren = context.getDiffTree().members(resource);
   if (setChildren.length == 0) return children;
   if (children.length == 0) return setChildren;
   Set result = new HashSet(children.length);
   for (int i = 0; i < children.length; i++) {
     result.add(children[i]);
   }
   for (int i = 0; i < setChildren.length; i++) {
     result.add(setChildren[i]);
   }
   return result.toArray();
 }
 /**
  * Return whether the given element has children in the given context. The children may or may not
  * exist locally. By default, this method returns true if the traversals for the element contain
  * any diffs. This could result in false positives. Subclasses can override to provide a more
  * efficient or precise answer.
  *
  * @param element a model element.
  * @return whether the given element has children in the given context
  */
 protected boolean hasChildrenInContext(ISynchronizationContext context, Object element) {
   ResourceTraversal[] traversals = getTraversals(context, element);
   if (traversals == null) return true;
   return context.getDiffTree().getDiffs(traversals).length > 0;
 }
Ejemplo n.º 8
0
 /**
  * If we needed to retrieve additional mappings for the given context's scope, this will return
  * them.
  *
  * @param context The context to check for additional mappings.
  * @return The additional mappings for the given context if any, <code>null</code> otherwise.
  */
 public static ResourceMapping[] getAdditionalMappings(ISynchronizationContext context) {
   return (ResourceMapping[]) context.getCache().get(EMFModelProvider.EMF_ADDITIONAL_MAPPINGS);
 }
Ejemplo n.º 9
0
 /**
  * Caches the given mappings within the given synchronization context.
  *
  * @param context Context in which to cache the given additional mappings.
  * @param additionalMappings Additional mappings discovered for this context.
  */
 public static void cacheAdditionalMappings(
     ISynchronizationContext context, ResourceMapping[] additionalMappings) {
   context.getCache().put(EMFModelProvider.EMF_ADDITIONAL_MAPPINGS, additionalMappings);
 }