Class SynchronizationScopeManager

  • All Implemented Interfaces:
    IAdaptable, ISynchronizationScopeManager
    Direct Known Subclasses:
    SubscriberScopeManager

    public class SynchronizationScopeManager
    extends PlatformObject
    implements ISynchronizationScopeManager
    Class for translating a set of ResourceMapping objects representing a view selection into the complete set of resources to be operated on.

    Here's a summary of the scope generation algorithm:

    1. Obtain selected mappings
    2. Project mappings onto resources using the appropriate context(s) in order to obtain a set of ResourceTraverals
    3. Determine what model providers are interested in the targeted resources
    4. From those model providers, obtain the set of affected resource mappings
    5. If the original set is the same as the new set, we are done.
    6. If the set differs from the original selection, rerun the mapping process for any new mappings
      • Only need to query model providers for mappings for new resources
      • Keep repeating until no new mappings or resources are added

    This implementation does not involve participants in the scope management process. It is up to subclasses that wish to support a longer life cycle for scopes to provide for participation. For example, the SubscriberScopeManager class includes participates in the scope management process.

    Since:
    3.2
    See Also:
    ResourceMapping, SubscriberScopeManager
    • Constructor Detail

      • SynchronizationScopeManager

        public SynchronizationScopeManager​(String name,
                                           ResourceMapping[] inputMappings,
                                           ResourceMappingContext resourceMappingContext,
                                           boolean consultModels)
        Create a scope manager that uses the given context to determine what resources should be included in the scope. If consultModels is true then the model providers will be queried in order to determine if additional mappings should be included in the scope
        Parameters:
        name - the name of the scope
        inputMappings - the input mappings
        resourceMappingContext - a resource mapping context
        consultModels - whether model providers should be consulted
    • Method Detail

      • getMappingsFromProviders

        public static ResourceMapping[] getMappingsFromProviders​(ResourceTraversal[] traversals,
                                                                 ResourceMappingContext context,
                                                                 IProgressMonitor monitor)
                                                          throws CoreException
        Convenience method for obtaining the set of resource mappings from all model providers that overlap with the given resources.
        Parameters:
        traversals - the resource traversals
        context - the resource mapping context
        monitor - a progress monitor
        Returns:
        the resource mappings
        Throws:
        CoreException - if an error occurs
      • getSchedulingRule

        public ISchedulingRule getSchedulingRule()
        Return the scheduling rule that is used when initializing and refreshing the scope. By default, a rule that covers all projects for the input mappings of the scope is returned. Subclasses may override.
        Returns:
        the scheduling rule that is used when initializing and refreshing the scope
      • initialize

        public void initialize​(IProgressMonitor monitor)
                        throws CoreException
        Description copied from interface: ISynchronizationScopeManager
        Build the scope that is used to determine the complete set of resource mappings, and hence resources, that an operation should be performed on.

        This method obtains a lock on the workspace root to avoid workspace changes while calculating the scope.

        Specified by:
        initialize in interface ISynchronizationScopeManager
        Parameters:
        monitor - a progress monitor when building the scope
        Throws:
        CoreException - if an error occurs
      • refresh

        public ResourceTraversal[] refresh​(ResourceMapping[] mappings,
                                           IProgressMonitor monitor)
                                    throws CoreException
        Description copied from interface: ISynchronizationScopeManager
        Refresh the scope of this manager for the given mappings. Changes in the scope will be reported as a property change event fired from the scope. Clients should call this method when a change in the workspace or a change issued from this manager have resulted in a change in the resources that should be included in the scope.
        Specified by:
        refresh in interface ISynchronizationScopeManager
        Parameters:
        mappings - the mappings to be refreshed
        monitor - a progress monitor
        Returns:
        a set of traversals that cover the given mappings
        Throws:
        CoreException - if an error occurs
      • setHasAdditionalMappings

        protected final void setHasAdditionalMappings​(ISynchronizationScope scope,
                                                      boolean hasAdditionalMappings)
        Set whether the scope has additional mappings. This method is not intended to be overridden.
        Parameters:
        hasAdditionalMappings - a boolean indicating if the scope has additional mappings
      • setHasAdditionalResources

        protected final void setHasAdditionalResources​(boolean hasAdditionalResources)
        Set whether the scope has additional resources. This method is not intended to be overridden.
        Parameters:
        hasAdditionalResources - a boolean indicating if the scope has additional resources
      • createScope

        protected final ISynchronizationScope createScope​(ResourceMapping[] inputMappings)
        Create the scope that will be populated and returned by the builder. This method is not intended to be overridden by clients.
        Parameters:
        inputMappings - the input mappings
        Returns:
        a newly created scope that will be populated and returned by the builder
      • adjustInputTraversals

        protected ResourceTraversal[] adjustInputTraversals​(ResourceTraversal[] traversals)
        Adjust the given set of input resources to include any additional resources required by a particular repository provider for the current operation. By default the original set is returned but subclasses may override. Overriding methods should return a set of resources that include the original resource either explicitly or implicitly as a child of a returned resource.

        Subclasses may override this method to include additional resources.

        Parameters:
        traversals - the input resource traversals
        Returns:
        the input resource traversals adjusted to include any additional resources required for the current operation
      • addMappingToScope

        protected final ResourceTraversal[] addMappingToScope​(ResourceMapping mapping,
                                                              ResourceTraversal[] traversals)
        Add the mapping and its calculated traversals to the scope. Return the resources that were not previously covered by the scope. This method is not intended to be subclassed by clients.
        Parameters:
        mapping - the resource mapping
        traversals - the resource mapping's traversals
        Returns:
        the resource traversals that were not previously covered by the scope
      • dispose

        public void dispose()
        Description copied from interface: ISynchronizationScopeManager
        Method to be invoked when the scope of this manager is no longer needed. It is typically the responsibility of the client that creates a scope manager to dispose it.
        Specified by:
        dispose in interface ISynchronizationScopeManager
      • refresh

        public void refresh​(ResourceMapping[] mappings)
        Refresh the given mappings by recalculating the traversals for the mappings and adjusting the scope accordingly.
        Parameters:
        mappings - the mappings to be refreshed
      • getName

        public String getName()
        Returns the human readable name of this manager. The name is never null.
        Returns:
        the name associated with this scope manager