/**
  * Return whether the given saveable contains any resources that are descendants of the root
  * resources.
  *
  * @param saveable the saveable
  * @return whether the given saveable contains any resources that are descendants of the root
  *     resources
  */
 private boolean isDescendantOfRoots(Saveable saveable) {
   // First, try and adapt the saveable to a resource mapping.
   ResourceMapping mapping = ResourceUtil.getResourceMapping(saveable);
   if (mapping != null) {
     try {
       ResourceTraversal[] traversals =
           mapping.getTraversals(ResourceMappingContext.LOCAL_CONTEXT, null);
       for (int i = 0; i < traversals.length; i++) {
         ResourceTraversal traversal = traversals[i];
         IResource[] resources = traversal.getResources();
         for (int j = 0; j < resources.length; j++) {
           IResource resource = resources[j];
           if (isDescendantOfRoots(resource)) {
             return true;
           }
         }
       }
     } catch (CoreException e) {
       IDEWorkbenchPlugin.log(
           NLS.bind(
               "An internal error occurred while determining the resources for {0}",
               saveable.getName()),
           e); //$NON-NLS-1$
     }
   } else {
     // If there is no mapping, try to adapt to a resource or file directly
     IFile file = ResourceUtil.getFile(saveable);
     if (file != null) {
       return isDescendantOfRoots(file);
     }
   }
   return false;
 }
Example #2
0
 /* (non-Javadoc)
  * @see org.eclipse.team.core.mapping.IResourceMappingScope#getMapping(java.lang.Object)
  */
 public ResourceMapping getMapping(Object modelObject) {
   ResourceMapping[] mappings = getMappings();
   for (int i = 0; i < mappings.length; i++) {
     ResourceMapping mapping = mappings[i];
     if (mapping.getModelObject().equals(modelObject)) return mapping;
   }
   return null;
 }
Example #3
0
 /* (non-Javadoc)
  * @see org.eclipse.team.core.mapping.IResourceMappingScope#getModelProviders()
  */
 public ModelProvider[] getModelProviders() {
   Set result = new HashSet();
   ResourceMapping[] mappings = getMappings();
   for (int i = 0; i < mappings.length; i++) {
     ResourceMapping mapping = mappings[i];
     ModelProvider modelProvider = mapping.getModelProvider();
     if (modelProvider != null) result.add(modelProvider);
   }
   return (ModelProvider[]) result.toArray(new ModelProvider[result.size()]);
 }
Example #4
0
 /* (non-Javadoc)
  * @see org.eclipse.team.core.mapping.IResourceMappingScope#getMappings(java.lang.String)
  */
 public ResourceMapping[] getMappings(String id) {
   Set result = new HashSet();
   ResourceMapping[] mappings = getMappings();
   for (int i = 0; i < mappings.length; i++) {
     ResourceMapping mapping = mappings[i];
     if (mapping.getModelProviderId().equals(id)) {
       result.add(mapping);
     }
   }
   return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]);
 }
 @Override
 protected ResourceTraversal[] getTraversals(ISynchronizationContext context, Object object) {
   if (object instanceof IAdaptable) {
     ResourceMapping rm = getResourceMapping(object);
     GitSubscriberMergeContext ctx = (GitSubscriberMergeContext) getContext();
     ResourceMappingContext rmCtx = new GitSubscriberResourceMappingContext(ctx.getSyncData());
     try {
       return rm.getTraversals(rmCtx, new NullProgressMonitor());
     } catch (CoreException e) {
       Activator.logError(e.getMessage(), e);
     }
   }
   return null;
 }
 /**
  * Return whether the given element has children in the given scope. By default, true is returned
  * if the given element contains any elements in the scope or if any of the elements in the scope
  * contain the given element and the delegate provider returns children for the element. The
  * {@link ResourceMapping#contains(ResourceMapping)} is used to test for containment. Subclasses
  * may override to provide a more efficient implementation.
  *
  * @param scope the scope
  * @param element the element
  * @return whether the given element has children in the given scope
  */
 protected boolean hasChildrenInScope(ISynchronizationScope scope, Object element) {
   ResourceMapping mapping = Utils.getResourceMapping(internalGetElement(element));
   if (mapping != null) {
     ResourceMapping[] mappings = scope.getMappings(mapping.getModelProviderId());
     for (int i = 0; i < mappings.length; i++) {
       ResourceMapping sm = mappings[i];
       if (mapping.contains(sm)) {
         return true;
       }
       if (sm.contains(mapping)) {
         return getDelegateChildren(element).length > 0;
       }
     }
   }
   return false;
 }