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

mport org.eclipse.team.core.history.IFileRevision;
import org.eclipse.team.core.mapping.IResourceDiff;
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.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
import org.eclipse.team.ui.mapping.ISynchronizationCompareInput;
import org.eclipse.team.ui.mapping.SaveableComparison;

public class ResourceDiffCompareInput
  extends AbstractCompareInput
  implements ISynchronizationCompareInput, IAdaptable, IResourceProvider
{
  private IDiff node;
  private final ISynchronizationContext context;
  
  public static int getCompareKind(IDiff node)
  {
    int compareKind = 0;
    if (node != null)
    {
      switch (node.getKind())
      {
      case 1: 
        compareKind = 1;
        break;
      case 2: 
        compareKind = 2;
        break;
      case 4: 
        compareKind = 3;
      }
      if ((node instanceof IThreeWayDiff))
      {
        IThreeWayDiff twd = (IThreeWayDiff)node;
        switch (twd.getDirection())
        {
        case 256: 
          compareKind |= 0x8;
          break;
        case 512: 
          compareKind |= 0x4;
          break;
        case 768: 
          compareKind |= 0x4;
          compareKind |= 0x8;
        }
      }
    }
    return compareKind;
  }
  
  private static FileRevisionTypedElement getRightContributor(IDiff node)
  {
    if ((node instanceof IResourceDiff))
    {
      IResourceDiff rd = (IResourceDiff)node;
      return asTypedElement(rd.getAfterState(), getLocalEncoding(node));
    }
    if ((node instanceof IThreeWayDiff))
    {
      IThreeWayDiff twd = (IThreeWayDiff)node;
      IResourceDiff diff = (IResourceDiff)twd.getRemoteChange();
      if (diff != null) {
        return getRightContributor(diff);
      }
      diff = (IResourceDiff)twd.getLocalChange();
      return asTypedElement(diff.getBeforeState(), getLocalEncoding(node));
    }
    return null;
  }
  
  private static LocalResourceTypedElement getLeftContributor(IDiff node)
  {
    return new LocalResourceTypedElement(ResourceDiffTree.getResourceFor(node));
  }
  
  private static FileRevisionTypedElement getAncestor(IDiff node)
  {
    if ((node instanceof IThreeWayDiff))
    {
      IThreeWayDiff twd = (IThreeWayDiff)node;
      IResourceDiff diff = (IResourceDiff)twd.getLocalChange();
      if (diff == null) {
        diff = (IResourceDiff)twd.getRemoteChange();
      }
      return asTypedElement(diff.getBeforeState(), getLocalEncoding(node));
    }
    return null;
  }
  
  private static String getLocalEncoding(IDiff node)
  {
    IResource resource = ResourceDiffTree.getResourceFor(node);
    if ((resource instanceof IEncodedStorage))
    {
      IEncodedStorage es = (IEncodedStorage)resource;
      try
      {
        return es.getCharset();
      }
      catch (CoreException e)
      {
        TeamUIPlugin.log(e);
      }
    }
    return null;
  }
  
  private static FileRevisionTypedElement asTypedElement(IFileRevision state, String localEncoding)
  {
    if (state == null) {
      return null;
    }
    return new FileRevisionTypedElement(state, localEncoding);
  }
  
  public static void ensureContentsCached(IDiff diff, IProgressMonitor monitor)
    throws CoreException
  {
    if (diff != null) {
      ensureContentsCached(getAncestor(diff), getRightContributor(diff), monitor);
    }
  }
  
  private static void ensureContentsCached(Object ancestor, Object right, IProgressMonitor monitor)
    throws CoreException
  {
    SubMonitor sm = SubMonitor.convert(monitor, 100);
    if ((ancestor instanceof FileRevisionTypedElement))
    {
      FileRevisionTypedElement fste = (FileRevisionTypedElement)ancestor;
      fste.cacheContents(sm.newChild(50));
    }
    else
    {
      sm.setWorkRemaining(50);
    }
    if ((right instanceof FileRevisionTypedElement))
    {
      FileRevisionTypedElement fste = (FileRevisionTypedElement)right;
      fste.cacheContents(sm.newChild(50));
    }
    if (monitor != null) {
      monitor.done();
    }
  }
  
  public ResourceDiffCompareInput(IDiff diff, ISynchronizationContext context)
  {
    super(getCompareKind(diff), getAncestor(diff), getLeftContributor(diff), getRightContributor(diff));
    node = diff;
    this.context = context;
  }
  
  public void fireChange()
  {
    super.fireChange();
  }
  
  public void prepareInput(CompareConfiguration configuration, IProgressMonitor monitor)
    throws CoreException
  {
    configuration.setLabelProvider(this, ((ResourceCompareInputChangeNotifier)getChangeNotifier()).getLabelProvider());
    ensureContentsCached(getAncestor(), getRight(), monitor);
  }
  
  public SaveableComparison getSaveable()
  {
    return null;
  }
  
  public Object getAdapter(Class adapter)
  {
    if ((adapter == IFile.class) || (adapter == IResource.class)) {
      return ResourceDiffTree.getResourceFor(node);
    }
    if (adapter == ResourceMapping.class)
    {
      IResource resource = ResourceDiffTree.getResourceFor(node);
      return resource.getAdapter(adapter);
    }
    return null;
  }
  
  public String getFullPath()
  {
    IResource resource = ResourceDiffTree.getResourceFor(node);
    if (resource != null) {
      return resource.getFullPath().toString();
    }
    return getName();
  }
  
  public boolean isCompareInputFor(Object object)
  {
    IResource resource = ResourceDiffTree.getResourceFor(node);
    IResource other = Utils.getResource(object);
    if ((resource != null) && (other != null)) {
      return resource.equals(other);
    }
    return false;
  }
  
  public IResource getResource()
  {
    return ResourceDiffTree.getResourceFor(node);
  }
  
  public CompareInputChangeNotifier getChangeNotifier()
  {
    return ResourceCompareInputChangeNotifier.getChangeNotifier(context);
  }
  
  public boolean equals(Object other)
  {
    if (other == this) {
      return true;
    }
    if ((other instanceof ResourceDiffCompareInput))
    {
      ResourceDiffCompareInput otherInput = (ResourceDiffCompareInput)other;
      
      return (isEqual(getLeft(), otherInput.getLeft())) && (isEqual(getRight(), otherInput.getRight())) && (isEqual(getAncestor(), otherInput.getAncestor()));
    }
    return false;
  }
  
  private boolean isEqual(ITypedElement e1, ITypedElement e2)
  {
    if (e1 == null) {
      return e2 == null;
    }
    if (e2 == null) {
      return false;
    }
    return e1.equals(e2);
  }
  
  public int hashCode()
  {
    return getResource().hashCode();
  }
  
  public void update()
  {
    IDiff newNode = context.getDiffTree().getDiff(getResource());
    if (newNode == null)
    {
      setKind(0);
      fireChange();
    }
    else
    {
      LocalResourceTypedElement left = (LocalResourceTypedElement)getLeft();
      if ((!node.equals(newNode)) || (!left.isSynchronized()))
      {
        node = newNode;
        setKind(getCompareKind(node));
        left.update();
        FileRevisionTypedElement newRight = getRightContributor(node);
        propogateAuthorIfSameRevision((FileRevisionTypedElement)getRight(), newRight);
        setRight(newRight);
        FileRevisionTypedElement newAncestor = getAncestor(node);
        propogateAuthorIfSameRevision((FileRevisionTypedElement)getAncestor(), newAncestor);
        setAncestor(newAncestor);
        propogateAuthorIfSameRevision((FileRevisionTypedElement)getAncestor(), (FileRevisionTypedElement)getRight());
      }
      fireChange();
    }
  }
  
  private boolean propogateAuthorIfSameRevision(FileRevisionTypedElement oldContributor, FileRevisionTypedElement newContributor)
  {
    if ((oldContributor == null) || (newContributor == null)) {
      return false;
    }
    String author = oldContributor.getAuthor();
    if ((newContributor.getAuthor() == null) && (author != null) && (oldContributor.getContentIdentifier().equals(newContributor.getContentIdentifier())))
    {
      newContributor.setAuthor(author);
      return true;
    }
    return false;
  }
  
  private boolean propogateAuthorIfSameRevision(FileRevisionTypedElement oldContributor, LocalResourceTypedElement newContributor)
  {
    if ((oldContributor == null) || (newContributor == null)) {
      return false;
    }
    String author = oldContributor.getAuthor();
    if ((newContributor.getAuthor() == null) && (author != null) && (oldContributor.getContentIdentifier().equals(getLocalContentId())))
    {
      newContributor.setAuthor(author);
      return true;
    }
    return false;
  }
  
  public boolean needsUpdate()
  {
    IDiff newNode = context.getDiffTree().getDiff(getResource());
    return (newNode == null) || (!newNode.equals(node));
  }
  
  public String getLocalContentId()
  {
    return Utils.getLocalContentId(node);
  }
  
  public boolean updateAuthorInfo(IProgressMonitor monitor)
    throws CoreException
  {
    boolean fireEvent = false;
    FileRevisionTypedElement ancestor = (FileRevisionTypedElement)getAncestor();
    FileRevisionTypedElement right = (FileRevisionTypedElement)getRight();
    LocalResourceTypedElement left = (LocalResourceTypedElement)getLeft();
    if ((ancestor != null) && (ancestor.getAuthor() == null))
    {
      ancestor.fetchAuthor(monitor);
      fireEvent |= ancestor.getAuthor() != null;
    }
    fireEvent |= propogateAuthorIfSameRevision(ancestor, right);
    fireEvent |= propogateAuthorIfSameRevision(ancestor, left);
    if ((right != null) && (right.getAuthor() == null))
    {
      right.fetchAuthor(monitor);
      fireEvent |= right.getAuthor() != null;
    }
    fireEvent |= propogateAuthorIfSameRevision(right, left);
    if ((left != null) && (left.getAuthor() == null))
    {
      left.fetchAuthor(monitor);
      fireEvent |= (fireEvent = left.getAuthor() != null ? 1 : 0);
    }
    return fireEvent;
  }
}

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

import java.io.PrintStream;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
import org.eclipse.ui.part.ResourceTransfer;

public class ResourceDragAdapterAssistant
  extends CommonDragAdapterAssistant
{
  private static final Transfer[] SUPPORTED_TRANSFERS = {
    ResourceTransfer.getInstance(), 
    FileTransfer.getInstance() };
  private static final Class IRESOURCE_TYPE = IResource.class;
  
  public Transfer[] getSupportedTransferTypes()
  {
    return SUPPORTED_TRANSFERS;
  }
  
  public boolean setDragData(DragSourceEvent anEvent, IStructuredSelection aSelection)
  {
    IResource[] resources = getSelectedResources(aSelection);
    if (resources.length > 0)
    {
      if (ResourceTransfer.getInstance().isSupportedType(dataType))
      {
        data = resources;
        if (Policy.DEBUG_DND) {
          System.out.println("ResourceDragAdapterAssistant.dragSetData set ResourceTransfer");
        }
        return true;
      }
      if (FileTransfer.getInstance().isSupportedType(dataType))
      {
        int length = resources.length;
        int actualLength = 0;
        String[] fileNames = new String[length];
        for (int i = 0; i < length; i++)
        {
          IPath location = resources[i].getLocation();
          if (location != null) {
            fileNames[(actualLength++)] = location.toOSString();
          }
        }
        if (actualLength > 0)
        {
          if (actualLength < length)
          {
            String[] tempFileNames = fileNames;
            fileNames = new String[actualLength];
            for (int i = 0; i < actualLength; i++) {
              fileNames[i] = tempFileNames[i];
            }
          }
          data = fileNames;
          if (Policy.DEBUG_DND) {
            System.out.println("ResourceDragAdapterAssistant.dragSetData set FileTransfer");
          }
          return true;
        }
      }
    }
    return false;
  }
  
  private IResource[] getSelectedResources(IStructuredSelection aSelection)
  {
    Set resources = new LinkedHashSet();
    IResource resource = null;
    for (Iterator iter = aSelection.iterator(); iter.hasNext();)
    {
      Object selected = iter.next();
      resource = adaptToResource(selected);
      if (resource != null) {
        resources.add(resource);
      }
    }
    return (IResource[])resources.toArray(new IResource[resources.size()]);
  }
  
  private IResource adaptToResource(Object selected)
  {
    IResource resource;
    IResource resource;
    if ((selected instanceof IResource))
    {
      resource = (IResource)selected;
    }
    else
    {
      IResource resource;
      if ((selected instanceof IAdaptable)) {
        resource = (IResource)((IAdaptable)selected)
          .getAdapter(IRESOURCE_TYPE);
      } else {
        resource = (IResource)Platform.getAdapterManager().getAdapter(
          selected, IRESOURCE_TYPE);
      }
    }
    return resource;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceDragAdapterAssistant
 * 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.IModelProviderDescriptor;
import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.WorkbenchLabelProvider;

public class ResourceMappingLabelProvider
  extends LabelProvider
{
  WorkbenchLabelProvider provider = new WorkbenchLabelProvider();
  
  public String getText(Object element)
  {
    if ((element instanceof ResourceMapping))
    {
      ResourceMapping mapping = (ResourceMapping)element;
      String text = this.provider.getText(mapping.getModelObject());
      if ((text != null) && (text.length() > 0)) {
        return text;
      }
      return super.getText(mapping.getModelObject());
    }
    if ((element instanceof ModelProvider))
    {
      ModelProvider provider = (ModelProvider)element;
      return provider.getDescriptor().getLabel();
    }
    String text = this.provider.getText(element);
    if ((text != null) && (text.length() > 0)) {
      return text;
    }
    return super.getText(element);
  }
  
  public Image getImage(Object element)
  {
    Image image = provider.getImage(element);
    if (image != null) {
      return image;
    }
    if ((element instanceof ResourceMapping))
    {
      ResourceMapping mapping = (ResourceMapping)element;
      image = provider.getImage(mapping.getModelObject());
      if (image != null) {
        return image;
      }
    }
    return super.getImage(element);
  }
  
  public void dispose()
  {
    provider.dispose();
    super.dispose();
  }
}

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

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.diff.FastDiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;

class ResourceMarkAsMergedHandler$1
  extends ResourceModelProviderOperation
{
  final ResourceMarkAsMergedHandler this$0;
  
  ResourceMarkAsMergedHandler$1(ResourceMarkAsMergedHandler paramResourceMarkAsMergedHandler, ISynchronizePageConfiguration $anonymous0, IStructuredSelection $anonymous1)
  {
    super($anonymous0, $anonymous1);this$0 = paramResourceMarkAsMergedHandler;
  }
  
  public void execute(IProgressMonitor monitor)
    throws InvocationTargetException, InterruptedException
  {
    try
    {
      IMergeContext context = (IMergeContext)getContext();
      IDiff[] deltas = getTargetDiffs();
      ISchedulingRule rule = getMergeRule(context, deltas);
      context.run(new ResourceMarkAsMergedHandler.2(this, deltas, context), 
      
        rule, 0, monitor);
    }
    catch (CoreException e)
    {
      throw new InvocationTargetException(e);
    }
  }
  
  private ISchedulingRule getMergeRule(IMergeContext context, IDiff[] deltas)
  {
    ISchedulingRule result = null;
    for (int i = 0; i < deltas.length; i++)
    {
      IDiff node = deltas[i];
      ISchedulingRule rule = context.getMergeRule(node);
      if (result == null) {
        result = rule;
      } else {
        result = MultiRule.combine(result, rule);
      }
    }
    return result;
  }
  
  private void markAsMerged(IDiff[] deltas, IMergeContext context, IProgressMonitor monitor)
    throws CoreException
  {
    context.markAsMerged(deltas, false, monitor);
  }
  
  protected FastDiffFilter getDiffFilter()
  {
    return new ResourceMarkAsMergedHandler.3(this);
  }
  
  protected String getJobName()
  {
    IDiff[] diffs = getTargetDiffs();
    if (diffs.length == 1) {
      return TeamUIMessages.ResourceMarkAsMergedHandler_0;
    }
    return NLS.bind(TeamUIMessages.ResourceMarkAsMergedHandler_1, new Integer(diffs.length).toString());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceMarkAsMergedHandler.1
 * 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.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IMergeContext;

class ResourceMarkAsMergedHandler$2
  implements IWorkspaceRunnable
{
  final ResourceMarkAsMergedHandler.1 this$1;
  private final IDiff[] val$deltas;
  private final IMergeContext val$context;
  
  ResourceMarkAsMergedHandler$2(ResourceMarkAsMergedHandler.1 param1, IDiff[] paramArrayOfIDiff, IMergeContext paramIMergeContext)
  {
    this$1 = param1;val$deltas = paramArrayOfIDiff;val$context = paramIMergeContext;
  }
  
  public void run(IProgressMonitor monitor)
    throws CoreException
  {
    ResourceMarkAsMergedHandler.1.access$0(this$1, val$deltas, val$context, monitor);
  }
}

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

import org.eclipse.team.core.diff.FastDiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.diff.IThreeWayDiff;

class ResourceMarkAsMergedHandler$3
  extends FastDiffFilter
{
  final ResourceMarkAsMergedHandler.1 this$1;
  
  ResourceMarkAsMergedHandler$3(ResourceMarkAsMergedHandler.1 param1)
  {
    this$1 = param1;
  }
  
  public boolean select(IDiff node)
  {
    if ((node instanceof IThreeWayDiff))
    {
      IThreeWayDiff twd = (IThreeWayDiff)node;
      if ((twd.getDirection() == 768) || 
        (twd.getDirection() == 512)) {
        return true;
      }
    }
    return false;
  }
}

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

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.diff.FastDiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.core.mapping.IResourceDiffTree;
import org.eclipse.team.core.mapping.ISynchronizationContext;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.ui.mapping.SynchronizationOperation;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;

public class ResourceMarkAsMergedHandler
  extends ResourceMergeActionHandler
{
  private ResourceModelProviderOperation operation;
  
  public ResourceMarkAsMergedHandler(ISynchronizePageConfiguration configuration)
  {
    super(configuration);
  }
  
  protected synchronized SynchronizationOperation getOperation()
  {
    if (operation == null) {
      operation = new ResourceModelProviderOperation(getConfiguration(), 
        getStructuredSelection())
        {
          public void execute(IProgressMonitor monitor)
            throws InvocationTargetException, InterruptedException
          {
            try
            {
              IMergeContext context = (IMergeContext)getContext();
              IDiff[] deltas = getTargetDiffs();
              ISchedulingRule rule = getMergeRule(context, deltas);
              context.run(new ResourceMarkAsMergedHandler.2(this, deltas, context), 
              
                rule, 0, monitor);
            }
            catch (CoreException e)
            {
              throw new InvocationTargetException(e);
            }
          }
          
          private ISchedulingRule getMergeRule(IMergeContext context, IDiff[] deltas)
          {
            ISchedulingRule result = null;
            for (int i = 0; i < deltas.length; i++)
            {
              IDiff node = deltas[i];
              ISchedulingRule rule = context.getMergeRule(node);
              if (result == null) {
                result = rule;
              } else {
                result = MultiRule.combine(result, rule);
              }
            }
            return result;
          }
          
          private void markAsMerged(IDiff[] deltas, IMergeContext context, IProgressMonitor monitor)
            throws CoreException
          {
            context.markAsMerged(deltas, false, monitor);
          }
          
          protected FastDiffFilter getDiffFilter()
          {
            return new ResourceMarkAsMergedHandler.3(this);
          }
          
          protected String getJobName()
          {
            IDiff[] diffs = getTargetDiffs();
            if (diffs.length == 1) {
              return TeamUIMessages.ResourceMarkAsMergedHandler_0;
            }
            return NLS.bind(TeamUIMessages.ResourceMarkAsMergedHandler_1, new Integer(diffs.length).toString());
          }
        };
      }
      return operation;
    }
    
    public void updateEnablement(IStructuredSelection selection)
    {
      synchronized (this)
      {
        operation = null;
      }
      super.updateEnablement(selection);
      int mode = getConfiguration().getMode();
      if (((mode == 2) && 
        (getSynchronizationContext().getDiffTree().countFor(768, 768) == 0L)) || (
        (getSynchronizationContext().getDiffTree().countFor(768, 768) == 0L) && 
        (getSynchronizationContext().getDiffTree().countFor(512, 768) == 0L)))
      {
        setEnabled(false);
        return;
      }
    }
    
    public Object execute(ExecutionEvent event)
      throws ExecutionException
    {
      if (saveDirtyEditors()) {
        return super.execute(event);
      }
      return null;
    }
  }

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

class ResourceMergeActionHandler$1
  implements Runnable
{
  final ResourceMergeActionHandler this$0;
  
  ResourceMergeActionHandler$1(ResourceMergeActionHandler paramResourceMergeActionHandler)
  {
    this$0 = paramResourceMergeActionHandler;
  }
  
  public void run()
  {
    ResourceMergeActionHandler.access$1(this$0, ResourceMergeActionHandler.access$0(this$0));
  }
}

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

class ResourceMergeActionHandler$2
  implements Runnable
{
  final ResourceMergeActionHandler this$0;
  
  ResourceMergeActionHandler$2(ResourceMergeActionHandler paramResourceMergeActionHandler)
  {
    this$0 = paramResourceMergeActionHandler;
  }
  
  public void run()
  {
    ResourceMergeActionHandler.access$1(this$0, ResourceMergeActionHandler.access$0(this$0));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ui.mapping.ResourceMergeActionHandler.2
 * 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.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.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.team.core.diff.IDiffChangeEvent;
import org.eclipse.team.core.diff.IDiffChangeListener;
import org.eclipse.team.core.diff.IDiffTree;
import org.eclipse.team.core.mapping.IResourceDiffTree;
import org.eclipse.team.core.mapping.ISynchronizationContext;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.mapping.MergeActionHandler;
import org.eclipse.team.ui.synchronize.ISynchronizePage;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.ui.ide.IDE;

public abstract class ResourceMergeActionHandler
  extends MergeActionHandler
  implements IDiffChangeListener, IPropertyChangeListener
{
  public ResourceMergeActionHandler(ISynchronizePageConfiguration configuration)
  {
    super(configuration);
    getSynchronizationContext().getDiffTree().addDiffChangeListener(this);
    configuration.addPropertyChangeListener(this);
  }
  
  public final boolean saveDirtyEditors()
  {
    if ((needsToSaveDirtyEditors()) && 
      (!saveAllEditors(getTargetResources(), confirmSaveOfDirtyEditor()))) {
      return false;
    }
    return true;
  }
  
  private IResource[] getTargetResources()
  {
    IStructuredSelection selection = getStructuredSelection();
    Object[] objects = selection.toArray();
    Set roots = new HashSet();
    for (int i = 0; i < objects.length; i++)
    {
      Object object = objects[i];
      ResourceMapping mapping = Utils.getResourceMapping(object);
      if (mapping != null) {
        try
        {
          ResourceTraversal[] traversals = mapping.getTraversals(ResourceMappingContext.LOCAL_CONTEXT, null);
          for (int j = 0; j < traversals.length; j++)
          {
            ResourceTraversal traversal = traversals[j];
            IResource[] resources = traversal.getResources();
            for (int k = 0; k < resources.length; k++)
            {
              IResource resource = resources[k];
              roots.add(resource);
            }
          }
        }
        catch (CoreException e)
        {
          TeamUIPlugin.log(e);
        }
      }
    }
    return (IResource[])roots.toArray(new IResource[roots.size()]);
  }
  
  public final boolean saveAllEditors(IResource[] resources, boolean confirm)
  {
    return IDE.saveAllEditors(resources, confirm);
  }
  
  protected boolean needsToSaveDirtyEditors()
  {
    return true;
  }
  
  protected boolean confirmSaveOfDirtyEditor()
  {
    return true;
  }
  
  protected ISynchronizationContext getSynchronizationContext()
  {
    return (ISynchronizationContext)getConfiguration().getProperty("org.eclipse.team.ui.synchronizationContext");
  }
  
  public void propertyChanged(IDiffTree tree, int property, IPath[] paths) {}
  
  public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor)
  {
    Utils.syncExec(new Runnable()
    {
      public void run()
      {
        updateEnablement(ResourceMergeActionHandler.access$0(ResourceMergeActionHandler.this));
      }
    }, (StructuredViewer)getConfiguration().getPage().getViewer());
  }
  
  public void propertyChange(PropertyChangeEvent event)
  {
    if (event.getProperty() == "org.eclipse.team.ui.P_SYNCVIEWPAGE_MODE") {
      Utils.syncExec(new Runnable()
      {
        public void run()
        {
          updateEnablement(ResourceMergeActionHandler.access$0(ResourceMergeActionHandler.this));
        }
      }, (StructuredViewer)getConfiguration().getPage().getViewer());
    }
  }
}

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

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.diff.FastDiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;

class ResourceMergeHandler$1
  extends ResourceModelProviderOperation
{
  final ResourceMergeHandler this$0;
  
  ResourceMergeHandler$1(ResourceMergeHandler paramResourceMergeHandler, ISynchronizePageConfiguration $anonymous0, IStructuredSelection $anonymous1)
  {
    super($anonymous0, $anonymous1);this$0 = paramResourceMergeHandler;
  }
  
  public void execute(IProgressMonitor monitor)
    throws InvocationTargetException, InterruptedException
  {
    try
    {
      IMergeContext context = (IMergeContext)getContext();
      IDiff[] diffs = getTargetDiffs();
      if (diffs.length == 0) {
        this$0.promptForNoChanges();
      }
      IStatus status = context.merge(diffs, ResourceMergeHandler.access$0(this$0), monitor);
      if (!status.isOK()) {
        throw new CoreException(status);
      }
    }
    catch (CoreException e)
    {
      throw new InvocationTargetException(e);
    }
  }
  
  protected FastDiffFilter getDiffFilter()
  {
    return new ResourceMergeHandler.2(this);
  }
  
  protected String getJobName()
  {
    IDiff[] diffs = getTargetDiffs();
    if (ResourceMergeHandler.access$0(this$0))
    {
      if (diffs.length == 1) {
        return TeamUIMessages.ResourceMergeHandler_0;
      }
      return NLS.bind(TeamUIMessages.ResourceMergeHandler_1, new Integer(diffs.length).toString());
    }
    if (diffs.length == 1) {
      return TeamUIMessages.ResourceMergeHandler_2;
    }
    return NLS.bind(TeamUIMessages.ResourceMergeHandler_3, new Integer(diffs.length).toString());
  }
}

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

import org.eclipse.team.core.diff.FastDiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.diff.IThreeWayDiff;

class ResourceMergeHandler$2
  extends FastDiffFilter
{
  final ResourceMergeHandler.1 this$1;
  
  ResourceMergeHandler$2(ResourceMergeHandler.1 param1)
  {
    this$1 = param1;
  }
  
  public boolean select(IDiff node)
  {
    if ((node instanceof IThreeWayDiff))
    {
      IThreeWayDiff twd = (IThreeWayDiff)node;
      if (((twd.getDirection() == 256) && (ResourceMergeHandler.access$0(ResourceMergeHandler.1.access$0(this$1)))) || (twd.getDirection() == 768) || (twd.getDirection() == 512)) {
        return true;
      }
      return false;
    }
    return ResourceMergeHandler.access$0(ResourceMergeHandler.1.access$0(this$1));
  }
}

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

class ResourceMergeHandler$3
  implements Runnable
{
  final ResourceMergeHandler this$0;
  private final boolean[] val$confirmed;
  
  ResourceMergeHandler$3(ResourceMergeHandler paramResourceMergeHandler, boolean[] paramArrayOfBoolean)
  {
    this$0 = paramResourceMergeHandler;val$confirmed = paramArrayOfBoolean;
  }
  
  public void run()
  {
    val$confirmed[0] = this$0.promptToConfirm();
  }
}

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

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.team.ui.synchronize.ISynchronizePageSite;

class ResourceMergeHandler$4
  implements Runnable
{
  final ResourceMergeHandler this$0;
  
  ResourceMergeHandler$4(ResourceMergeHandler paramResourceMergeHandler)
  {
    this$0 = paramResourceMergeHandler;
  }
  
  public void run()
  {
    MessageDialog.openInformation(ResourceMergeHandler.access$1(this$0).getSite().getShell(), TeamUIMessages.ResourceMergeHandler_6, TeamUIMessages.ResourceMergeHandler_7);
  }
}

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

import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.diff.FastDiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.mapping.SynchronizationOperation;
import org.eclipse.team.ui.synchronize.ISynchronizePage;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.team.ui.synchronize.ISynchronizePageSite;

public class ResourceMergeHandler
  extends ResourceMergeActionHandler
{
  private final boolean overwrite;
  private ResourceModelProviderOperation operation;
  
  public ResourceMergeHandler(ISynchronizePageConfiguration configuration, boolean overwrite)
  {
    super(configuration);
    this.overwrite = overwrite;
  }
  
  protected synchronized SynchronizationOperation getOperation()
  {
    if (operation == null) {
      operation = new ResourceModelProviderOperation(getConfiguration(), getStructuredSelection())
      {
        public void execute(IProgressMonitor monitor)
          throws InvocationTargetException, InterruptedException
        {
          try
          {
            IMergeContext context = (IMergeContext)getContext();
            IDiff[] diffs = getTargetDiffs();
            if (diffs.length == 0) {
              promptForNoChanges();
            }
            IStatus status = context.merge(diffs, overwrite, monitor);
            if (!status.isOK()) {
              throw new CoreException(status);
            }
          }
          catch (CoreException e)
          {
            throw new InvocationTargetException(e);
          }
        }
        
        protected FastDiffFilter getDiffFilter()
        {
          return new ResourceMergeHandler.2(this);
        }
        
        protected String getJobName()
        {
          IDiff[] diffs = getTargetDiffs();
          if (overwrite)
          {
            if (diffs.length == 1) {
              return TeamUIMessages.ResourceMergeHandler_0;
            }
            return NLS.bind(TeamUIMessages.ResourceMergeHandler_1, new Integer(diffs.length).toString());
          }
          if (diffs.length == 1) {
            return TeamUIMessages.ResourceMergeHandler_2;
          }
          return NLS.bind(TeamUIMessages.ResourceMergeHandler_3, new Integer(diffs.length).toString());
        }
      };
    }
    return operation;
  }
  
  public void updateEnablement(IStructuredSelection selection)
  {
    synchronized (this)
    {
      operation = null;
    }
    super.updateEnablement(selection);
    int mode = getConfiguration().getMode();
    if ((mode == 2) && (!overwrite))
    {
      setEnabled(false);
      return;
    }
  }
  
  public Object execute(ExecutionEvent event)
    throws ExecutionException
  {
    if ((saveDirtyEditors()) && ((!overwrite) || (promptToConfirm()))) {
      return super.execute(event);
    }
    return null;
  }
  
  protected boolean promptToConfirm()
  {
    if (Display.getCurrent() != null) {
      return internalPromptToConfirm();
    }
    boolean[] confirmed = new boolean[1];
    Shell shell = getConfiguration().getSite().getShell();
    if (!shell.isDisposed()) {
      Utils.syncExec(new Runnable()
      {
        private final boolean[] val$confirmed;
        
        public void run()
        {
          val$confirmed[0] = promptToConfirm();
        }
      }, shell);
    }
    return confirmed[0];
  }
  
  private boolean internalPromptToConfirm()
  {
    return MessageDialog.openQuestion(getConfiguration().getSite().getShell(), TeamUIMessages.ResourceMergeHandler_4, TeamUIMessages.ResourceMergeHandler_5);
  }
  
  protected void promptForNoChanges()
  {
    Utils.syncExec(new Runnable()
    {
      public void run()
      {
        MessageDialog.openInformation(getConfiguration().getSite().getShell(), TeamUIMessages.ResourceMergeHandler_6, TeamUIMessages.ResourceMergeHandler_7);
      }
    }, (StructuredViewer)getConfiguration().getPage().getViewer());
  }
}

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

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.team.internal.ui.synchronize.actions.RefactorActionGroup;
import org.eclipse.
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