org.eclipse.team.ui_3.6.101.R37x_v20111109-0800

Tree(Object elementOrPath)
  {
    ISynchronizationContext context = getContext();
    if (context != null) {
      return context.getDiffTree();
    }
    return null;
  }
  
  public void resourceChanged(IResourceChangeEvent event)
  {
    String[] markerTypes = { "org.eclipse.core.resources.problemmarker" };
    Set handledResources = new HashSet();
    for (int idx = 0; idx < markerTypes.length; idx++)
    {
      IMarkerDelta[] markerDeltas = event.findMarkerDeltas(markerTypes[idx], true);
      for (int i = 0; i < markerDeltas.length; i++)
      {
        IMarkerDelta delta = markerDeltas[i];
        IResource resource = delta.getResource();
        while ((resource != null) && (resource.getType() != 8) && (!handledResources.contains(resource)))
        {
          handledResources.add(resource);
          resource = resource.getParent();
        }
      }
    }
    if (!handledResources.isEmpty())
    {
      IResource[] resources = (IResource[])handledResources.toArray(new IResource[handledResources.size()]);
      updateLabels(resources);
    }
  }
  
  protected void updateLabels(Object[] resources)
  {
    Utils.asyncExec(new Runnable()
    {
      private final Object[] val$resources;
      
      public void run()
      {
        contentProvider.getStructuredViewer().update(
          val$resources, null);
      }
    }, contentProvider.getStructuredViewer());
  }
  
  protected String getDelegateText(Object elementOrPath)
  {
    if (getConfiguration() != null)
    {
      String label = getTraversalCalculator().getLabel(elementOrPath);
      if (label != null) {
        return label;
      }
    }
    return super.getDelegateText(internalGetElement(elementOrPath));
  }
  
  protected Image getDelegateImage(Object elementOrPath)
  {
    if ((getConfiguration() != null) && (getTraversalCalculator().isCompressedFolder(elementOrPath))) {
      return getImageManager().getImage(TeamUIPlugin.getImageDescriptor("obj/compressed_folder_obj.gif"));
    }
    return super.getDelegateImage(internalGetElement(elementOrPath));
  }
  
  private Object internalGetElement(Object elementOrPath)
  {
    if ((elementOrPath instanceof TreePath))
    {
      TreePath tp = (TreePath)elementOrPath;
      return tp.getLastSegment();
    }
    return elementOrPath;
  }
  
  protected ResourceModelTraversalCalculator getTraversalCalculator()
  {
    return ResourceModelTraversalCalculator.getTraversalCalculator(getConfiguration());
  }
  
  private ISynchronizePageConfiguration getConfiguration()
  {
    return (ISynchronizePageConfiguration)getExtensionSite().getExtensionStateModel().getProperty("org.eclipse.team.ui.synchronizationPageConfiguration");
  }
  
  public void updateLabel(ViewerLabel label, TreePath elementPath)
  {
    label.setImage(getImage(elementPath));
    label.setText(getText(elementPath));
    Font f = getFont(elementPath);
    if (f != null) {
      label.setFont(f);
    }
  }
  
  protected ImageManager getImageManager()
  {
    ISynchronizationContext context = getContext();
    if (context != null) {
      return ImageManager.getImageManager(context, getConfiguration());
    }
    if (localImageManager == null) {
      localImageManager = new ImageManager();
    }
    return localImageManager;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceModelLabelProvider
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ui.mapping;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IResourceDiffTree;
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
import org.eclipse.team.internal.core.mapping.CompoundResourceTraversal;
import org.eclipse.team.internal.core.subscribers.DiffChangeSet;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.team.ui.synchronize.ModelParticipantAction;

public abstract class ResourceModelParticipantAction
  extends ModelParticipantAction
{
  public ResourceModelParticipantAction(String text, ISynchronizePageConfiguration configuration)
  {
    super(text, configuration);
  }
  
  protected ResourceTraversal[] getResourceTraversals(IStructuredSelection selection, IProgressMonitor monitor)
    throws CoreException
  {
    try
    {
      monitor.beginTask(null, selection.size() * 100);
      CompoundResourceTraversal traversal = new CompoundResourceTraversal();
      if ((selection instanceof ITreeSelection))
      {
        ITreeSelection ts = (ITreeSelection)selection;
        TreePath[] paths = ts.getPaths();
        for (int i = 0; i < paths.length; i++)
        {
          TreePath path = paths[i];
          ResourceTraversal[] traversals = getTraversals(path, Policy.subMonitorFor(monitor, 100));
          traversal.addTraversals(traversals);
        }
      }
      else
      {
        for (Iterator iter = selection.iterator(); iter.hasNext();)
        {
          Object element = iter.next();
          ResourceTraversal[] traversals = getTraversals(element, Policy.subMonitorFor(monitor, 100));
          traversal.addTraversals(traversals);
        }
      }
      return traversal.asTraversals();
    }
    finally
    {
      monitor.done();
    }
  }
  
  private ResourceTraversal[] getTraversals(Object element, IProgressMonitor monitor)
    throws CoreException
  {
    ResourceMapping mapping = Utils.getResourceMapping(element);
    if (mapping != null) {
      return mapping.getTraversals(getResourceMappingContext(), monitor);
    }
    return null;
  }
  
  protected ResourceMappingContext getResourceMappingContext()
  {
    return new SynchronizationResourceMappingContext(getSynchronizationContext());
  }
  
  protected ResourceModelTraversalCalculator getTraversalCalculator()
  {
    return ResourceModelTraversalCalculator.getTraversalCalculator(getConfiguration());
  }
  
  private ResourceTraversal[] getTraversals(TreePath path, IProgressMonitor monitor)
    throws CoreException
  {
    if (path.getSegmentCount() > 0)
    {
      DiffChangeSet set = getChangeSet(path);
      Object o = path.getLastSegment();
      if (set != null)
      {
        if (path.getSegmentCount() == 1) {
          return new ResourceTraversal[] { new ResourceTraversal(set.getResources(), 0, 0) };
        }
        if ((o instanceof IResource))
        {
          IResource resource = (IResource)o;
          int depth = getTraversalCalculator().getLayoutDepth(resource, path);
          IDiff[] diffs = set.getDiffTree().getDiffs(resource, depth);
          Set resources = new HashSet();
          for (int i = 0; i < diffs.length; i++)
          {
            IDiff diff = diffs[i];
            IResource r = ResourceDiffTree.getResourceFor(diff);
            if (r != null) {
              resources.add(r);
            }
          }
          return new ResourceTraversal[] { new ResourceTraversal((IResource[])resources.toArray(new IResource[resources.size()]), 0, 0) };
        }
      }
      if (getTraversalCalculator().isResourcePath(path))
      {
        IResource resource = (IResource)o;
        return getTraversalCalculator().getTraversals(resource, path);
      }
      return getTraversals(o, monitor);
    }
    return null;
  }
  
  private DiffChangeSet getChangeSet(TreePath path)
  {
    Object o = path.getFirstSegment();
    if ((o instanceof DiffChangeSet)) {
      return (DiffChangeSet)o;
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceModelParticipantAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ui.mapping;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IModelProviderDescriptor;
import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.mapping.SynchronizationCompareAdapter;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;

public class ResourceModelPersistenceAdapter
  extends SynchronizationCompareAdapter
{
  private static final String RESOURCES = "resources";
  private static final String RESOURCE_PATH = "resourcePath";
  private static final String RESOURCE_TYPE = "resourceType";
  private static final String WORKING_SETS = "workingSets";
  private static final String WORKING_SET_NAME = "workingSetName";
  private static final String MODEL_PROVIDERS = "modelProviders";
  private static final String MODEL_PROVIDER_ID = "modelProviderId";
  
  public void save(ResourceMapping[] mappings, IMemento memento)
  {
    for (int i = 0; i < mappings.length; i++)
    {
      ResourceMapping mapping = mappings[i];
      Object object = mapping.getModelObject();
      if ((object instanceof IResource))
      {
        IResource resource = (IResource)object;
        IMemento child = memento.createChild("resources");
        child.putInteger("resourceType", resource.getType());
        child.putString("resourcePath", resource.getFullPath().toString());
      }
      else if ((object instanceof IWorkingSet))
      {
        IWorkingSet ws = (IWorkingSet)object;
        IMemento child = memento.createChild("workingSets");
        child.putString("workingSetName", ws.getName());
      }
      else if ((object instanceof ModelProvider))
      {
        ModelProvider provider = (ModelProvider)object;
        IMemento child = memento.createChild("modelProviders");
        child.putString("modelProviderId", provider.getId());
      }
    }
  }
  
  public ResourceMapping[] restore(IMemento memento)
  {
    IMemento[] children = memento.getChildren("resources");
    List result = new ArrayList();
    for (int i = 0; i < children.length; i++)
    {
      IMemento child = children[i];
      Integer typeInt = child.getInteger("resourceType");
      if (typeInt != null)
      {
        int type = typeInt.intValue();
        String pathString = child.getString("resourcePath");
        if (pathString != null)
        {
          IPath path = new Path(pathString);
          IResource resource;
          IResource resource;
          IResource resource;
          IResource resource;
          IResource resource;
          switch (type)
          {
          case 8: 
            resource = ResourcesPlugin.getWorkspace().getRoot();
            break;
          case 4: 
            resource = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment());
            break;
          case 1: 
            resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            break;
          case 2: 
            resource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
            break;
          case 3: 
          case 5: 
          case 6: 
          case 7: 
          default: 
            resource = null;
          }
          if (resource != null)
          {
            ResourceMapping mapping = Utils.getResourceMapping(resource);
            if (mapping != null) {
              result.add(mapping);
            }
          }
        }
      }
    }
    children = memento.getChildren("workingSets");
    for (int i = 0; i < children.length; i++)
    {
      IMemento child = children[i];
      String name = child.getString("workingSetName");
      if (name != null)
      {
        IWorkingSet set = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(name);
        if (set != null)
        {
          ResourceMapping mapping = Utils.getResourceMapping(set);
          if (mapping != null) {
            result.add(mapping);
          }
        }
      }
    }
    children = memento.getChildren("modelProviders");
    for (int i = 0; i < children.length; i++)
    {
      IMemento child = children[i];
      String id = child.getString("modelProviderId");
      if (id != null)
      {
        IModelProviderDescriptor desc = ModelProvider.getModelProviderDescriptor(id);
        if (desc != null) {
          try
          {
            ModelProvider provider = desc.getModelProvider();
            if (provider != null)
            {
              ResourceMapping mapping = Utils.getResourceMapping(provider);
              if (mapping != null) {
                result.add(mapping);
              }
            }
          }
          catch (CoreException e)
          {
            TeamUIPlugin.log(e);
          }
        }
      }
    }
    return (ResourceMapping[])result.toArray(new ResourceMapping[result.size()]);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceModelPersistenceAdapter
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ui.mapping;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.team.core.diff.FastDiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IResourceDiffTree;
import org.eclipse.team.core.mapping.ISynchronizationContext;
import org.eclipse.team.core.mapping.ISynchronizationScope;
import org.eclipse.team.internal.core.subscribers.DiffChangeSet;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.internal.ui.synchronize.SynchronizePageConfiguration;
import org.eclipse.team.ui.mapping.SynchronizationOperation;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;

public abstract class ResourceModelProviderOperation
  extends SynchronizationOperation
{
  private final IStructuredSelection selection;
  
  protected ResourceModelProviderOperation(ISynchronizePageConfiguration configuration, IStructuredSelection selection)
  {
    super(configuration, getElements(selection));
    this.selection = selection;
  }
  
  private static Object[] getElements(IStructuredSelection selection)
  {
    return selection.toArray();
  }
  
  private IDiff[] getFileDeltas(Object[] pathOrElements)
  {
    Set result = new HashSet();
    for (int i = 0; i < pathOrElements.length; i++)
    {
      Object pathOrElement = pathOrElements[i];
      IDiff[] diffs = getFileDeltas(pathOrElement);
      for (int j = 0; j < diffs.length; j++)
      {
        IDiff node = diffs[j];
        result.add(node);
      }
    }
    return (IDiff[])result.toArray(new IDiff[result.size()]);
  }
  
  private IDiff[] getFileDeltas(Object pathOrElement)
  {
    List result = new ArrayList();
    ResourceTraversal[] traversals = getTraversals(pathOrElement);
    if (traversals.length > 0)
    {
      ISynchronizationContext context = getContext();
      IResourceDiffTree diffTree = context.getDiffTree();
      IDiff[] diffs = diffTree.getDiffs(traversals);
      for (int i = 0; i < diffs.length; i++)
      {
        IDiff node = diffs[i];
        if ((isVisible(node)) && (getDiffFilter().select(node))) {
          result.add(node);
        }
      }
    }
    return (IDiff[])result.toArray(new IDiff[result.size()]);
  }
  
  protected boolean isVisible(IDiff node)
  {
    return ((SynchronizePageConfiguration)getConfiguration()).isVisible(node);
  }
  
  private ResourceTraversal[] getTraversals(Object pathOrElement)
  {
    Object element;
    Object element;
    if ((pathOrElement instanceof TreePath))
    {
      TreePath tp = (TreePath)pathOrElement;
      Object o = tp.getFirstSegment();
      if ((o instanceof DiffChangeSet))
      {
        DiffChangeSet dcs = (DiffChangeSet)o;
        return getTraversalCalculator().getTraversals(dcs, tp);
      }
      element = tp.getLastSegment();
    }
    else
    {
      element = pathOrElement;
    }
    if (isResourcePath(pathOrElement))
    {
      IResource resource = (IResource)element;
      return getTraversalCalculator().getTraversals(resource, (TreePath)pathOrElement);
    }
    ResourceMapping mapping = Utils.getResourceMapping(element);
    if (mapping != null)
    {
      ResourceTraversal[] traversals = getContext().getScope().getTraversals(mapping);
      if (traversals != null) {
        return traversals;
      }
      try
      {
        return mapping.getTraversals(ResourceMappingContext.LOCAL_CONTEXT, null);
      }
      catch (CoreException e)
      {
        TeamUIPlugin.log(e);
      }
    }
    return new ResourceTraversal[0];
  }
  
  private boolean isResourcePath(Object pathOrElement)
  {
    if ((pathOrElement instanceof TreePath))
    {
      TreePath tp = (TreePath)pathOrElement;
      return getTraversalCalculator().isResourcePath(tp);
    }
    return false;
  }
  
  protected abstract FastDiffFilter getDiffFilter();
  
  public boolean shouldRun()
  {
    Object[] elements = getElements();
    for (int i = 0; i < elements.length; i++)
    {
      Object object = elements[i];
      if (Utils.getResourceMapping(internalGetElement(object)) != null) {
        return true;
      }
    }
    return false;
  }
  
  protected IDiff[] getTargetDiffs()
  {
    return getFileDeltas(getTreePathsOrElements());
  }
  
  private Object[] getTreePathsOrElements()
  {
    if ((selection instanceof ITreeSelection))
    {
      ITreeSelection ts = (ITreeSelection)selection;
      return ts.getPaths();
    }
    return getElements();
  }
  
  protected boolean canRunAsJob()
  {
    return true;
  }
  
  protected ResourceModelTraversalCalculator getTraversalCalculator()
  {
    return ResourceModelTraversalCalculator.getTraversalCalculator(getConfiguration());
  }
  
  private Object internalGetElement(Object elementOrPath)
  {
    if ((elementOrPath instanceof TreePath))
    {
      TreePath tp = (TreePath)elementOrPath;
      return tp.getLastSegment();
    }
    return elementOrPath;
  }
  
  public boolean belongsTo(Object family)
  {
    if (family == getContext()) {
      return true;
    }
    return super.belongsTo(family);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceModelProviderOperation
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ui.mapping;

import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.IModelProviderDescriptor;
import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.team.core.mapping.ISynchronizationScope;
import org.eclipse.team.core.mapping.ISynchronizationScopeParticipant;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;

public class ResourceModelScopeParticipant
  implements ISynchronizationScopeParticipant, IResourceChangeListener, IPropertyChangeListener
{
  private final ModelProvider provider;
  private final ISynchronizationScope scope;
  
  public ResourceModelScopeParticipant(ModelProvider provider, ISynchronizationScope scope)
  {
    this.provider = provider;
    this.scope = scope;
    if (hasWorkspaceMapping()) {
      ResourcesPlugin.getWorkspace().addResourceChangeListener(this, 1);
    }
    if (hasWorkingSetMappings()) {
      PlatformUI.getWorkbench().getWorkingSetManager().addPropertyChangeListener(this);
    }
  }
  
  private boolean hasWorkingSetMappings()
  {
    ResourceMapping[] mappings = scope.getMappings(provider.getDescriptor().getId());
    for (int i = 0; i < mappings.length; i++)
    {
      ResourceMapping mapping = mappings[i];
      Object modelObject = mapping.getModelObject();
      if ((modelObject instanceof IWorkingSet)) {
        return true;
      }
    }
    return false;
  }
  
  private boolean hasWorkspaceMapping()
  {
    ResourceMapping[] mappings = scope.getMappings(this.provider.getDescriptor().getId());
    for (int i = 0; i < mappings.length; i++)
    {
      ResourceMapping mapping = mappings[i];
      Object modelObject = mapping.getModelObject();
      if ((modelObject instanceof IResource))
      {
        IResource resource = (IResource)modelObject;
        if (resource.getType() == 8) {
          return true;
        }
      }
      else if ((modelObject instanceof ModelProvider))
      {
        ModelProvider provider = (ModelProvider)modelObject;
        if (provider.getId().equals("org.eclipse.core.resources.modelProvider")) {
          return true;
        }
      }
    }
    return false;
  }
  
  public ResourceMapping[] handleContextChange(ISynchronizationScope scope, IResource[] resources, IProject[] projects)
  {
    Set result = new HashSet();
    for (int i = 0; i < projects.length; i++)
    {
      IProject project = projects[i];
      collectMappings(project, result);
    }
    return (ResourceMapping[])result.toArray(new ResourceMapping[result.size()]);
  }
  
  private void collectMappings(IProject project, Set result)
  {
    ResourceMapping[] mappings = scope.getMappings(provider.getDescriptor().getId());
    for (int i = 0; i < mappings.length; i++)
    {
      ResourceMapping mapping = mappings[i];
      boolean refresh = false;
      Object modelObject = mapping.getModelObject();
      if ((modelObject instanceof IWorkingSet))
      {
        IWorkingSet set = (IWorkingSet)modelObject;
        IAdaptable[] elements = set.getElements();
        for (int j = 0; j < elements.length; j++)
        {
          IAdaptable adaptable = elements[j];
          ResourceMapping m = (ResourceMapping)Utils.getAdapter(adaptable, ResourceMapping.class);
          if (m != null)
          {
            IProject[] p = m.getProjects();
            for (int k = 0; k < p.length; k++)
            {
              IProject mp = p[k];
              if (mp.equals(project))
              {
                refresh = true;
                break;
              }
            }
          }
          if (refresh) {
            break;
          }
        }
      }
      else if ((modelObject instanceof IResource))
      {
        IResource resource = (IResource)modelObject;
        if (resource.getType() == 8) {
          refresh = true;
        }
      }
      else if ((modelObject instanceof ModelProvider))
      {
        ModelProvider mp = (ModelProvider)modelObject;
        try
        {
          ResourceMapping[] list = mp.getMappings(project, ResourceMappingContext.LOCAL_CONTEXT, null);
          if (list.length > 0) {
            refresh = true;
          }
        }
        catch (CoreException e)
        {
          TeamUIPlugin.log(e);
        }
      }
      if (refresh) {
        result.add(mapping);
      }
    }
  }
  
  public void dispose()
  {
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
    if (PlatformUI.isWorkbenchRunning()) {
      PlatformUI.getWorkbench().getWorkingSetManager().removePropertyChangeListener(this);
    }
  }
  
  public void resourceChanged(IResourceChangeEvent event)
  {
    Set result = new HashSet();
    IResourceDelta[] children = event.getDelta().getAffectedChildren();
    for (int i = 0; i < children.length; i++)
    {
      IResourceDelta delta = children[i];
      IResource resource = delta.getResource();
      if ((resource.getType() == 4) && 
        (((delta.getKind() & 0x3) != 0) || 
        ((delta.getFlags() & 0x4000) != 0)) && 
        (isInContext(resource))) {
        collectMappings((IProject)resource, result);
      }
    }
    if (!result.isEmpty()) {
      fireChange((ResourceMapping[])result.toArray(new ResourceMapping[result.size()]));
    }
  }
  
  private boolean isInContext(IResource resource)
  {
    IProject[] projects = scope.getProjects();
    for (int i = 0; i < projects.length; i++)
    {
      IProject project = projects[i];
      if (project.equals(resource.getProject())) {
        return true;
      }
    }
    return false;
  }
  
  private void fireChange(ResourceMapping[] mappings)
  {
    scope.refresh(mappings);
  }
  
  public void propertyChange(PropertyChangeEvent event)
  {
    if (event.getProperty() == "workingSetContentChange")
    {
      IWorkingSet newSet = (IWorkingSet)event.getNewValue();
      ResourceMapping[] mappings = scope.getMappings(provider.getDescriptor().getId());
      for (int i = 0; i < mappings.length; i++)
      {
        ResourceMapping mapping = mappings[i];
        if (newSet == mapping.getModelObject()) {
          fireChange(new ResourceMapping[] { mapping });
        }
      }
    }
    else
    {
      event.getProperty();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceModelScopeParticipant
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ui.mapping;

import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.team.core.mapping.ISynchronizationScope;
import org.eclipse.team.core.mapping.ISynchronizationScopeParticipant;
import org.eclipse.team.core.mapping.ISynchronizationScopeParticipantFactory;

public class ResourceModelScopeParticipantFactory
  implements ISynchronizationScopeParticipantFactory
{
  private final ModelProvider provider;
  
  public ResourceModelScopeParticipantFactory(ModelProvider provider)
  {
    this.provider = provider;
  }
  
  public ISynchronizationScopeParticipant createParticipant(ModelProvider provider, ISynchronizationScope scope)
  {
    return new ResourceModelScopeParticipant(this.provider, scope);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceModelScopeParticipantFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ui.mapping;

import java.text.Collator;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.ui.views.navigator.ResourceSorter;

public class ResourceModelSorter
  extends ResourceSorter
{
  public ResourceModelSorter()
  {
    super(1);
  }
  
  protected int compareNames(IResource r1, IResource r2)
  {
    if ((getLayout().equals("org.eclipse.team.ui.compressed_layout")) && 
      ((r1 instanceof IFolder)) && 
      ((r2 instanceof IFolder))) {
      return collator.compare(r1.getProjectRelativePath().toString(), r2.getProjectRelativePath().toString());
    }
    return super.compareNames(r1, r2);
  }
  
  protected String getLayout()
  {
    return TeamUIPlugin.getPlugin().getPreferenceStore().getString("org.eclipse.team.ui.default_layout");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceModelSorter
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ui.mapping;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IResourceDiffTree;
import org.eclipse.team.core.mapping.ISynchronizationContext;
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
import org.eclipse.team.internal.core.subscribers.ChangeSet;
import org.eclipse.team.internal.core.subscribers.DiffChangeSet;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;

public class ResourceModelTraversalCalculator
{
  public static final String PROP_TRAVERSAL_CALCULATOR = "org.eclipse.team.ui.resourceModelTraversalCalculator";
  private static ResourceModelTraversalCalculator instance;
  private final ISynchronizePageConfiguration configuration;
  
  public ResourceModelTraversalCalculator(ISynchronizePageConfiguration configuration)
  {
    this.configuration = configuration;
  }
  
  public ResourceModelTraversalCalculator()
  {
    configuration = null;
  }
  
  public int getLayoutDepth(IResource resource, TreePath path)
  {
    if (isFlatPageLayout()) {
      return (resource instanceof IWorkspaceRoot) ? 2 : 0;
    }
    if (resource.getType() == 4) {
      return 2;
    }
    if (resource.getType() == 1) {
      return 0;
    }
    if ((path != null) && (hasNonResource(path))) {
      return 2;
    }
    if (getLayout().equals("org.eclipse.team.ui.flay_layout")) {
      return 0;
    }
    if (getLayout().equals("org.eclipse.team.ui.compressed_layout")) {
      return 1;
    }
    return 2;
  }
  
  public String getLayout()
  {
    return TeamUIPlugin.getPlugin().getPreferenceStore().getString("org.eclipse.team.ui.default_layout");
  }
  
  public Object[] filterChildren(IResourceDiffTree diffTree, IResource resource, Object parentOrPath, Object[] children)
  {
    if ((parentOrPath instanceof TreePath))
    {
      TreePath tp = (TreePath)parentOrPath;
      if (hasNonResource(tp)) {
        return getTreeChildren(diffTree, resource, children);
      }
    }
    if (isFlatPageLayout())
    {
      if ((resource instanceof IWorkspaceRoot)) {
        return diffTree.getAffectedResources();
      }
      return new Object[0];
    }
    if ((getLayout().equals("org.eclipse.team.ui.flay_layout")) && (resource.getType() == 4)) {
      return getFlatChildren(diffTree, resource);
    }
    if ((getLayout().equals("org.eclipse.team.ui.compressed_layout")) && (resource.getType() == 4)) {
      return getCompressedChildren(diffTree, (IProject)resource, children);
    }
    if ((getLayout().equals("org.eclipse.team.ui.compressed_layout")) && (resource.getType() == 2)) {
      return getCompressedChildren(diffTree, (IFolder)resource, children);
    }
    return getTreeChildren(diffTree, resource, children);
  }
  
  private boolean hasNonResource(TreePath parentPath)
  {
    for (int i = 0; i < parentPath.getSegmentCount(); i++)
    {
      Object o = parentPath.getSegment(i);
      if ((!(o instanceof IResource)) && (!(o instanceof ModelProvider)) && (!(o instanceof ChangeSet))) {
        return true;
      }
    }
    return false;
  }
  
  private Object[] getCompressedChildren(IResourceDiffTree diffTree, IProject project, Object[] children)
  {
    Set result = new HashSet();
    IDiff[] diffs = diffTree.getDiffs(project, 2);
    for (int i = 0; i < diffs.length; i++)
    {
      IDiff diff = diffs[i];
      IResource resource = diffTree.getResource(diff);
      if (resource.getType() == 1)
      {
        IContainer parent = resource.getParent();
        if (parent.getType() == 2) {
          result.add(parent);
        } else {
          result.add(resource);
        }
      }
      else if (resource.getType() == 2)
      {
        result.add(resource);
      }
    }
    return result.toArray();
  }
  
  private Object[] getCompressedChildren(IResourceDiffTree diffTree, IFolder folder, Object[] children)
  {
    Set result = new HashSet();
    for (int i = 0; i < children.length; i++)
    {
      Object object = children[i];
      if ((object instanceof IResource))
      {
        IResource resource = (IResource)object;
        if (resource.getType() == 1) {
          result.add(resource);
        }
      }
    }
    IDiff[] diffs = diffTree.getDiffs(folder, 1);
    for (int i = 0; i < diffs.length; i++)
    {
      IDiff diff = diffs[i];
      IResource resource = diffTree.getResource(diff);
      if (resource.getType() == 1) {
        result.add(resource);
      }
    }
    return result.toArray();
  }
  
  private Object[] getFlatChildren(IResourceDiffTree diffTree, IResource resource)
  {
    IDiff[] diffs = diffTree.getDiffs(resource, 2);
    ArrayList result = new ArrayList();
    for (int i = 0; i < diffs.length; i++)
    {
      IDiff diff = diffs[i];
      result.add(diffTree.getResource(diff));
    }
    Object[] allChildren = result.toArray();
    return allChildren;
  }
  
  private Object[] getTreeChildren(IResourceDiffTree diffTree, IResource resource, Object[] children)
  {
    Set result = new HashSet();
    for (int i = 0; i < children.length; i++)
    {
      Object object = children[i];
      result.add(object);
    }
    IResource[] setChildren = getChildren(diffTree, resource);
    for (int i = 0; i < setChildren.length; i++)
    {
      IResource child = setChildren[i];
      result.add(child);
    }
    Object[] allChildren = result.toArray(new Object[result.size()]);
    return allChildren;
  }
  
  public static IResource[] getChildren(IResourceDiffTree diffTree, IResource resource)
  {
    Set result = new HashSet();
    IPath[] childPaths = diffTree.getChildren(resource.getFullPath());
    for (int i = 0; i < childPaths.length; i++)
    {
      IPath path = childPaths[i];
      IDiff delta = diffTree.getDiff(path);
      IResource child;
      IResource child;
      if (delta == null)
      {
        IResource child;
        if (path.segmentCount() == 1) {
          child = ((IWorkspaceRoot)resource).getProject(path.lastSegment());
        } else {
          child = ((IContainer)resource).getFolder(new Path(path.lastSegment()));
        }
      }
      else
      {
        child = diffTree.getResource(delta);
      }
      result.add(child);
    }
    return (IResource[])result.toArray(new IResource[result.size()]);
  }
  
  public ResourceTraversal[] getTraversals(DiffChangeSet dcs, TreePath tp)
  {
    IResource[] resources = getResource(dcs, tp);
    return new ResourceTraversal[] { new ResourceTraversal(resources, 0, 0) };
  }
  
  private IResource[] getResource(DiffChangeSet dcs, TreePath tp)
  {
    if ((tp.getSegmentCount() == 1) && (tp.getFirstSegment() == dcs)) {
      return dcs.getResources();
    }
    Set result = new HashSet();
    Object o = tp.getLastSegment();
    if ((o instanceof IResource))
    {
      IResource resource = (IResource)o;
      int depth = getLayoutDepth(resource, tp);
      IDiff[] diffs = dcs.getDiffTree().getDiffs(resource, depth);
      for (int i = 0; i < diffs.length; i++)
      {
        IDiff diff = diffs[i];
        IResource r = ResourceDiffTree.getResourceFor(diff);
        if (r != null) {
          result.add(r);
        }
      }
    }
    return (IResource[])result.toArray(new IResource[result.size()]);
  }
  
  public ResourceTraversal[] getTraversals(IResource resource, TreePath tp)
  {
    return new ResourceTraversal[] { new ResourceTraversal(new IResource[] { resource }, getLayoutDepth(resource, tp), 0) };
  }
  
  public boolean isResourcePath(TreePath path)
  {
    for (int i = 0; i < path.getSegmentCount(); i++)
    {
      Object o = path.getSegment(i);
      if (!(o instanceof IResource)) {
        return false;
      }
    }
    return true;
  }
  
  public String getLabel(Object elementOrPath)
  {
    if (((elementOrPath instanceof TreePath)) && (hasNonResource((TreePath)elementOrPath))) {
      return null;
    }
    Object element = internalGetElement(elementOrPath);
    Object parent = internalGetElementParent(elementOrPath);
    if ((element instanceof IResource))
    {
      IResource resource = (IResource)element;
      if (isFlatPageLayout())
      {
        IPath path = resource.getFullPath();
        if (!path.isEmpty()) {
          return NLS.bind(TeamUIMessages.ResourceModelLabelProvider_0, resource.getName(), path.toString());
        }
      }
      if ((getLayout().equals("org.eclipse.team.ui.compressed_layout")) && 
        (resource.getType() == 2) && (
        (parent == null) || ((parent instanceof IProject)))) {
        return resource.getProjectRelativePath().toString();
      }
      if ((getLayout().equals("org.eclipse.team.ui.flay_layout")) && 
        (resource.getType() == 1) && (
        (parent == null) || ((parent instanceof IProject))))
      {
        IPath parentPath = resource.getProjectRelativePath().removeLastSegments(1);
        if (!parentPath.isEmpty()) {
          return NLS.bind(TeamUIMessages.ResourceModelLabelProvider_0, resource.getName(), parentPath.toString());
        }
      }
    }
    return null;
  }
  
  public boolean isCompressedFolder(Object elementOrPath)
  {
    if (((elementOrPath instanceof TreePath)) && (hasNonResource((TreePath)elementOrPath))) {
      return false;
    }
    Object element = internalGetElement(elementOrPath);
    Object parent = internalGetElementParent(elementOrPath);
    if ((element instanceof IResource))
    {
      IResource resource = (IResource)element;
      
      return (getLayout().equals("org.eclipse.team.ui.compressed_layout")) && (resource.getType() == 2) && ((parent == null) || ((parent instanceof IProject)));
    }
    return false;
  }
  
  private TreePath internalGetPath(Object elementOrPath)
  {
    if ((elementOrPath instanceof TreePath)) {
      return (TreePath)elementOrPath;
    }
    return null;
  }
  
  private Object internalGetElement(Object elementOrPath)
  {
    if ((elementOrPath instanceof TreePath))
    {
      TreePath tp = (TreePath)elementOrPath;
      return tp.getLastSegment();
    }
    return elementOrPath;
  }
  
  private Object internalGetElementParent(Object elementOrPath)
  {
    if ((elementOrPath instanceof TreePath))
    {
      TreePath tp = (TreePath)elementOrPath;
      if (tp.getSegmentCount() > 1) {
        return tp.getSegment(tp.getSegmentCount() - 2);
      }
    }
    return null;
  }
  
  public boolea
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd