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

jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
import org.eclipse.team.internal.ui.mapping.AbstractCompareInput;
import org.eclipse.team.internal.ui.mapping.CompareInputChangeNotifier;
import org.eclipse.team.ui.mapping.SaveableComparison;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.ISaveablesLifecycleListener;
import org.eclipse.ui.ISaveablesSource;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.Saveable;
import org.eclipse.ui.SaveablesLifecycleEvent;
import org.eclipse.ui.actions.ContributionItemFactory;
import org.eclipse.ui.actions.OpenFileAction;
import org.eclipse.ui.actions.OpenWithMenu;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.ui.ide.IGotoMarker;
import org.eclipse.ui.keys.IBindingService;
import org.eclipse.ui.services.IDisposable;
import org.eclipse.ui.texteditor.ITextEditor;

public class SaveablesCompareEditorInput
  extends CompareEditorInput
  implements ISaveablesSource
{
  private IPropertyListener fLeftPropertyListener;
  private IPropertyListener fRightPropertyListener;
  private Saveable fLeftSaveable;
  private Saveable fRightSaveable;
  private ITypedElement fAncestorElement;
  private ITypedElement fLeftElement;
  private ITypedElement fRightElement;
  private final IWorkbenchPage page;
  private final ListenerList inputChangeListeners = new ListenerList(
    1);
  private ICompareInputChangeListener compareInputChangeListener;
  
  public SaveablesCompareEditorInput(ITypedElement ancestor, ITypedElement left, ITypedElement right, IWorkbenchPage page)
  {
    super(new CompareConfiguration());
    this.page = page;
    fAncestorElement = ancestor;
    fLeftElement = left;
    fRightElement = right;
  }
  
  private static ITypedElement getFileElement(ITypedElement element, CompareEditorInput editorInput)
  {
    if ((element instanceof LocalResourceTypedElement)) {
      return element;
    }
    if ((editorInput instanceof CompareFileRevisionEditorInput)) {
      return 
        ((CompareFileRevisionEditorInput)editorInput).getLocalElement();
    }
    return null;
  }
  
  public static ITypedElement createFileElement(IFile file)
  {
    return new LocalResourceTypedElement(file);
  }
  
  private ISaveablesLifecycleListener getSaveablesLifecycleListener(IWorkbenchPart part)
  {
    ISaveablesLifecycleListener listener = (ISaveablesLifecycleListener)
      Utils.getAdapter(part, ISaveablesLifecycleListener.class);
    if (listener == null) {
      listener = (ISaveablesLifecycleListener)part.getSite().getService(
        ISaveablesLifecycleListener.class);
    }
    return listener;
  }
  
  protected void contentsCreated()
  {
    super.contentsCreated();
    compareInputChangeListener = new ICompareInputChangeListener()
    {
      public void compareInputChanged(ICompareInput source)
      {
        if (source == getCompareResult())
        {
          boolean closed = false;
          if (source.getKind() == 0) {
            closed = closeEditor(true);
          }
          if (!closed) {
            SaveablesCompareEditorInput.this.propogateInputChange();
          }
        }
      }
    };
    getCompareInput().addCompareInputChangeListener(
      compareInputChangeListener);
    if ((getLeftSaveable() instanceof SaveableComparison))
    {
      SaveableComparison lscm = (SaveableComparison)fLeftSaveable;
      fLeftPropertyListener = new IPropertyListener()
      {
        public void propertyChanged(Object source, int propId)
        {
          if (propId == 257) {
            setLeftDirty(fLeftSaveable.isDirty());
          }
        }
      };
      lscm.addPropertyListener(fLeftPropertyListener);
    }
    if ((getRightSaveable() instanceof SaveableComparison))
    {
      SaveableComparison rscm = (SaveableComparison)fRightSaveable;
      fRightPropertyListener = new IPropertyListener()
      {
        public void propertyChanged(Object source, int propId)
        {
          if (propId == 257) {
            setRightDirty(fRightSaveable.isDirty());
          }
        }
      };
      rscm.addPropertyListener(fRightPropertyListener);
    }
    setLeftDirty(fLeftSaveable.isDirty());
    setRightDirty(fRightSaveable.isDirty());
  }
  
  protected void handleDispose()
  {
    super.handleDispose();
    ICompareInput compareInput = getCompareInput();
    if (compareInput != null) {
      compareInput.removeCompareInputChangeListener(compareInputChangeListener);
    }
    compareInputChangeListener = null;
    if ((fLeftSaveable instanceof SaveableComparison))
    {
      SaveableComparison scm = (SaveableComparison)fLeftSaveable;
      scm.removePropertyListener(fLeftPropertyListener);
    }
    if ((fLeftSaveable instanceof LocalResourceSaveableComparison))
    {
      LocalResourceSaveableComparison rsc = (LocalResourceSaveableComparison)fLeftSaveable;
      rsc.dispose();
    }
    if ((fRightSaveable instanceof SaveableComparison))
    {
      SaveableComparison scm = (SaveableComparison)fRightSaveable;
      scm.removePropertyListener(fRightPropertyListener);
    }
    if ((fRightSaveable instanceof LocalResourceSaveableComparison))
    {
      LocalResourceSaveableComparison rsc = (LocalResourceSaveableComparison)fRightSaveable;
      rsc.dispose();
    }
    if ((getCompareResult() instanceof IDisposable)) {
      ((IDisposable)getCompareResult()).dispose();
    }
  }
  
  private String[] getLabels()
  {
    IResource leftResource = getResource(fLeftElement);
    IResource rightResource = getResource(fRightElement);
    if ((leftResource != null) && (rightResource != null))
    {
      String leftLabel = leftResource.getFullPath().makeRelative().toString();
      String rightLabel = rightResource.getFullPath().makeRelative().toString();
      if (fAncestorElement != null)
      {
        IResource ancestorResource = getResource(fAncestorElement);
        if (ancestorResource != null)
        {
          String ancestorLabel = rightResource.getFullPath().makeRelative().toString();
          return new String[] { ancestorLabel, leftLabel, rightLabel };
        }
      }
      return new String[] { leftLabel, rightLabel };
    }
    if (fAncestorElement != null) {
      return new String[] { fAncestorElement.getName(), fLeftElement.getName(), fRightElement.getName() };
    }
    return new String[] { fLeftElement.getName(), fRightElement.getName() };
  }
  
  public String getToolTipText()
  {
    String[] labels = getLabels();
    if (labels.length == 3) {
      return NLS.bind(TeamUIMessages.SaveablesCompareEditorInput_threeWayTooltip, labels);
    }
    return NLS.bind(TeamUIMessages.SaveablesCompareEditorInput_twoWayTooltip, labels);
  }
  
  public String getTitle()
  {
    String[] labels = getLabels();
    if (labels.length == 3) {
      return NLS.bind(TeamUIMessages.SaveablesCompareEditorInput_threeWayTitle, labels);
    }
    return NLS.bind(TeamUIMessages.SaveablesCompareEditorInput_twoWayTitle, labels);
  }
  
  private IWorkbenchPage getPage()
  {
    if (page == null) {
      return 
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    }
    return page;
  }
  
  protected final ICompareInput getCompareInput()
  {
    return (ICompareInput)getCompareResult();
  }
  
  protected void fireInputChange()
  {
    ((MyDiffNode)getCompareResult()).fireChange();
  }
  
  protected Saveable getLeftSaveable()
  {
    if (fLeftSaveable == null) {
      fLeftSaveable = createLeftSaveable();
    }
    return fLeftSaveable;
  }
  
  protected Saveable getRightSaveable()
  {
    if (fRightSaveable == null) {
      fRightSaveable = createRightSaveable();
    }
    return fRightSaveable;
  }
  
  protected Saveable createLeftSaveable()
  {
    Object compareResult = getCompareResult();
    
    Assert.isNotNull(compareResult, 
      "This method cannot be called until after prepareInput is called");
    ITypedElement leftFileElement = getFileElement(getCompareInput()
      .getLeft(), this);
    return new InternalResourceSaveableComparison(
      (ICompareInput)compareResult, this, leftFileElement);
  }
  
  protected Saveable createRightSaveable()
  {
    Object compareResult = getCompareResult();
    
    Assert.isNotNull(compareResult, 
      "This method cannot be called until after prepareInput is called");
    ITypedElement rightFileElement = getFileElement(getCompareInput()
      .getRight(), this);
    return new InternalResourceSaveableComparison(
      (ICompareInput)compareResult, this, rightFileElement);
  }
  
  public Saveable[] getActiveSaveables()
  {
    if (getCompareResult() == null) {
      return new Saveable[0];
    }
    return new Saveable[] { getLeftSaveable(), getRightSaveable() };
  }
  
  public Saveable[] getSaveables()
  {
    return getActiveSaveables();
  }
  
  public Viewer findContentViewer(Viewer pOldViewer, ICompareInput pInput, Composite pParent)
  {
    Viewer newViewer = super.findContentViewer(pOldViewer, pInput, pParent);
    boolean isNewViewer = newViewer != pOldViewer;
    if ((isNewViewer) && ((newViewer instanceof IPropertyChangeNotifier)) && 
      ((fLeftSaveable instanceof IPropertyChangeListener)) && 
      ((fRightSaveable instanceof IPropertyChangeListener)))
    {
      IPropertyChangeNotifier dsp = (IPropertyChangeNotifier)newViewer;
      IPropertyChangeListener lpcl = (IPropertyChangeListener)fLeftSaveable;
      IPropertyChangeListener rpcl = (IPropertyChangeListener)fRightSaveable;
      dsp.addPropertyChangeListener(lpcl);
      dsp.addPropertyChangeListener(rpcl);
      Control c = newViewer.getControl();
      c.addDisposeListener(new DisposeListener()
      {
        private final IPropertyChangeNotifier val$dsp;
        private final IPropertyChangeListener val$lpcl;
        private final IPropertyChangeListener val$rpcl;
        
        public void widgetDisposed(DisposeEvent e)
        {
          val$dsp.removePropertyChangeListener(val$lpcl);
          val$dsp.removePropertyChangeListener(val$rpcl);
        }
      });
    }
    return newViewer;
  }
  
  public boolean isDirty()
  {
    if ((fLeftSaveable != null) && (fLeftSaveable.isDirty())) {
      return true;
    }
    if ((fRightSaveable != null) && (fRightSaveable.isDirty())) {
      return true;
    }
    return super.isDirty();
  }
  
  boolean isSaveNeeded(Saveable saveable)
  {
    if (saveable == null) {
      return isSaveNeeded();
    }
    if (saveable.equals(fLeftSaveable)) {
      return isLeftSaveNeeded();
    }
    if (saveable.equals(fRightSaveable)) {
      return isRightSaveNeeded();
    }
    return isSaveNeeded();
  }
  
  void setDirty(boolean dirty, Saveable saveable)
  {
    if (saveable.equals(fLeftSaveable)) {
      setLeftDirty(dirty);
    }
    if (saveable.equals(fRightSaveable)) {
      setRightDirty(dirty);
    }
  }
  
  void saveChanges(IProgressMonitor monitor, Saveable saveable)
    throws CoreException
  {
    if (saveable.equals(fLeftSaveable))
    {
      flushLeftViewers(monitor);
      return;
    }
    if (saveable.equals(fRightSaveable))
    {
      flushRightViewers(monitor);
      return;
    }
    Assert.isTrue(false, "invalid saveable parameter");
  }
  
  protected boolean closeEditor(boolean checkForUnsavedChanges)
  {
    if ((isSaveNeeded()) && (checkForUnsavedChanges)) {
      return false;
    }
    Runnable runnable = new Runnable()
    {
      public void run()
      {
        IEditorPart part = SaveablesCompareEditorInput.this.getPage().findEditor(
          SaveablesCompareEditorInput.this);
        SaveablesCompareEditorInput.this.getPage().closeEditor(part, false);
      }
    };
    if (Display.getCurrent() != null)
    {
      runnable.run();
    }
    else
    {
      Display display = getPage().getWorkbenchWindow().getShell()
        .getDisplay();
      display.asyncExec(runnable);
    }
    return true;
  }
  
  protected Object prepareInput(IProgressMonitor monitor)
    throws InvocationTargetException, InterruptedException
  {
    ICompareInput input = prepareCompareInput(monitor);
    if (input != null) {
      setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, 
        new String[] { input.getName() }));
    }
    return input;
  }
  
  protected ICompareInput prepareCompareInput(IProgressMonitor monitor)
    throws InvocationTargetException, InterruptedException
  {
    ICompareInput input = createCompareInput();
    getCompareConfiguration().setLeftEditable(isEditable(input.getLeft()));
    getCompareConfiguration()
      .setRightEditable(isEditable(input.getRight()));
    initLabels();
    return input;
  }
  
  private boolean isEditable(Object obj)
  {
    if ((obj instanceof IEditableContent)) {
      return ((IEditableContent)obj).isEditable();
    }
    return false;
  }
  
  private void initLabels()
  {
    CompareConfiguration cc = getCompareConfiguration();
    
    IResource ancestorResource = getResource(fAncestorElement);
    IResource leftResource = getResource(fLeftElement);
    IResource rightResource = getResource(fRightElement);
    if (ancestorResource != null)
    {
      String ancestorLabel = ancestorResource.getFullPath()
        .makeRelative().toString();
      
      cc.setAncestorLabel(ancestorLabel);
    }
    if ((leftResource != null) && (rightResource != null))
    {
      String leftLabel = leftResource.getFullPath().makeRelative()
        .toString();
      String rightLabel = rightResource.getFullPath().makeRelative()
        .toString();
      
      cc.setLeftLabel(leftLabel);
      cc.setRightLabel(rightLabel);
    }
  }
  
  private ICompareInput createCompareInput()
  {
    return fAncestorElement == null ? new MyDiffNode(fLeftElement, 
      fRightElement) : new MyDiffNode(fAncestorElement, fLeftElement, 
      fRightElement);
  }
  
  private CompareInputChangeNotifier notifier = new CompareInputChangeNotifier()
  {
    protected IResource[] getResources(ICompareInput input)
    {
      IResource leftResource = SaveablesCompareEditorInput.this.getResource(fLeftElement);
      IResource rightResource = SaveablesCompareEditorInput.this.getResource(fRightElement);
      if ((leftResource == null) && (rightResource == null)) {
        return new IResource[0];
      }
      if ((leftResource == null) && (rightResource != null)) {
        return new IResource[] { rightResource };
      }
      if ((leftResource != null) && (rightResource == null)) {
        return new IResource[] { leftResource };
      }
      return new IResource[] { leftResource, rightResource };
    }
  };
  
  private class MyDiffNode
    extends AbstractCompareInput
  {
    public MyDiffNode(ITypedElement left, ITypedElement right)
    {
      super(null, left, right);
    }
    
    public MyDiffNode(ITypedElement ancestor, ITypedElement left, ITypedElement right)
    {
      super(ancestor, left, right);
    }
    
    public void fireChange()
    {
      super.fireChange();
    }
    
    protected CompareInputChangeNotifier getChangeNotifier()
    {
      return notifier;
    }
    
    public boolean needsUpdate()
    {
      return true;
    }
    
    public void update()
    {
      fireChange();
    }
  }
  
  private IResource getResource(ITypedElement pElement)
  {
    if (((pElement instanceof LocalResourceTypedElement)) && 
      ((pElement instanceof IResourceProvider))) {
      return ((IResourceProvider)pElement).getResource();
    }
    return null;
  }
  
  public void registerContextMenu(MenuManager pMenuManager, ISelectionProvider pSelectionProvider)
  {
    super.registerContextMenu(pMenuManager, pSelectionProvider);
    Saveable lLeftSaveable = getLeftSaveable();
    ITypedElement lLeftElement = getFileElement(getCompareInput()
      .getLeft(), this);
    if ((lLeftSaveable instanceof LocalResourceSaveableComparison)) {
      pMenuManager.addMenuListener(new IMenuListener()
      {
        private final Saveable val$lLeftSaveable;
        private final ITypedElement val$lLeftElement;
        private final ISelectionProvider val$pSelectionProvider;
        
        public void menuAboutToShow(IMenuManager manager)
        {
          SaveablesCompareEditorInput.handleMenuAboutToShow(manager, getContainer(), val$lLeftSaveable, val$lLeftElement, val$pSelectionProvider);
        }
      });
    }
    Saveable lRightSaveable = getRightSaveable();
    ITypedElement lRightElement = getFileElement(getCompareInput()
      .getRight(), this);
    if ((lRightSaveable instanceof LocalResourceSaveableComparison)) {
      pMenuManager.addMenuListener(new IMenuListener()
      {
        private final Saveable val$lRightSaveable;
        private final ITypedElement val$lRightElement;
        private final ISelectionProvider val$pSelectionProvider;
        
        public void menuAboutToShow(IMenuManager manager)
        {
          SaveablesCompareEditorInput.handleMenuAboutToShow(manager, getContainer(), val$lRightSaveable, val$lRightElement, val$pSelectionProvider);
        }
      });
    }
  }
  
  public void addCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener)
  {
    if (input == getCompareResult()) {
      inputChangeListeners.add(listener);
    } else {
      super.addCompareInputChangeListener(input, listener);
    }
  }
  
  public void removeCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener)
  {
    if (input == getCompareResult()) {
      inputChangeListeners.remove(listener);
    } else {
      super.removeCompareInputChangeListener(input, listener);
    }
  }
  
  private void propogateInputChange()
  {
    if (!inputChangeListeners.isEmpty())
    {
      Object[] allListeners = inputChangeListeners.getListeners();
      ICompareInput compareResult = (ICompareInput)getCompareResult();
      for (int i = 0; i < allListeners.length; i++)
      {
        ICompareInputChangeListener listener = (ICompareInputChangeListener)allListeners[i];
        SafeRunner.run(new ISafeRunnable()
        {
          private final ICompareInputChangeListener val$listener;
          private final ICompareInput val$compareResult;
          
          public void run()
            throws Exception
          {
            val$listener.compareInputChanged(val$compareResult);
          }
          
          public void handleException(Throwable exception) {}
        });
      }
    }
  }
  
  public Image getTitleImage()
  {
    ImageRegistry reg = TeamUIPlugin.getPlugin().getImageRegistry();
    Image image = reg.get("eview16/synch_synch.gif");
    if (image == null)
    {
      image = getImageDescriptor().createImage();
      reg.put("eview16/synch_synch.gif", image);
    }
    return image;
  }
  
  public ImageDescriptor getImageDescriptor()
  {
    return TeamUIPlugin.getImageDescriptor("eview16/synch_synch.gif");
  }
  
  public boolean canRunAsJob()
  {
    return true;
  }
  
  private static String getShowInMenuLabel()
  {
    String keyBinding = null;
    
    IBindingService bindingService = (IBindingService)
      PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    if (bindingService != null) {
      keyBinding = 
        bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu");
    }
    if (keyBinding == null) {
      keyBinding = "";
    }
    return 
      NLS.bind(TeamUIMessages.SaveableCompareEditorInput_0, keyBinding);
  }
  
  private class InternalResourceSaveableComparison
    extends LocalResourceSaveableComparison
    implements EditableSharedDocumentAdapter.ISharedDocumentAdapterListener
  {
    private LocalResourceTypedElement lrte;
    private boolean connected = false;
    
    public InternalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput, ITypedElement element)
    {
      super(editorInput, element);
      if ((element instanceof LocalResourceTypedElement))
      {
        lrte = ((LocalResourceTypedElement)element);
        if (lrte.isConnected()) {
          registerSaveable(true);
        } else {
          lrte.setSharedDocumentListener(this);
        }
      }
    }
    
    protected void fireInputChange()
    {
      SaveablesCompareEditorInput.this.fireInputChange();
    }
    
    public void dispose()
    {
      super.dispose();
      if (lrte != null) {
        lrte.setSharedDocumentListener(null);
      }
    }
    
    public void handleDocumentConnected()
    {
      if (connected) {
        return;
      }
      connected = true;
      registerSaveable(false);
      if (lrte != null) {
        lrte.setSharedDocumentListener(null);
      }
    }
    
    private void registerSaveable(boolean init)
    {
      ICompareContainer container = getContainer();
      IWorkbenchPart part = container.getWorkbenchPart();
      if (part != null)
      {
        ISaveablesLifecycleListener lifecycleListener = SaveablesCompareEditorInput.this.getSaveablesLifecycleListener(part);
        if (!init) {
          lifecycleListener.handleLifecycleEvent(new SaveablesLifecycleEvent(
            part, 3, 
            new Saveable[] { this }, false));
        }
        initializeHashing();
        
        lifecycleListener
          .handleLifecycleEvent(new SaveablesLifecycleEvent(part, 
          1, 
          new Saveable[] { this }, false));
      }
    }
    
    public void handleDocumentDeleted() {}
    
    public void handleDocumentDisconnected() {}
    
    public void handleDocumentFlushed() {}
    
    public void handleDocumentSaved() {}
    
    public boolean equals(Object obj)
    {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof Saveable)) {
        return false;
      }
      Class tmp20_17 = SaveablesCompareEditorInput.class$0;
      if (tmp20_17 == null)
      {
        tmp20_17;
        try
        {
          tmpTernaryOp = (SaveablesCompareEditorInput.class$0 = Class.forName("org.eclipse.jface.text.IDocument"));
        }
        catch (ClassNotFoundException localClassNotFoundException1)
        {
          throw new NoClassDefFoundError(localClassNotFoundException1.getMessage());
        }
      }
      Object document = getAdapter(tmp20_17);
      if (document != null)
      {
        Class tmp64_61 = SaveablesCompareEditorInput.class$0;
        if (tmp64_61 == null)
        {
          tmp64_61;
          try
          {
            tmpTernaryOp = (SaveablesCompareEditorInput.class$0 = Class.forName("org.eclipse.jface.text.IDocument"));
          }
          catch (ClassNotFoundException localClassNotFoundException2)
          {
            throw new NoClassDefFoundError(localClassNotFoundException2.getMessage());
          }
        }
        Object otherDocument = ((Saveable)obj)
          .getAdapter(tmp64_61);
        return document.equals(otherDocument);
      }
      if ((obj instanceof InternalResourceSaveableComparison))
      {
        InternalResourceSaveableComparison rscm = (InternalResourceSaveableComparison)obj;
        return (rscm.getInput().equals(getInput())) && (lrte.equals(lrte));
      }
      return false;
    }
  }
  
  public static void handleMenuAboutToShow(IMenuManager manager, ICompareContainer container, Saveable saveable, ITypedElement element, ISelectionProvider provider)
  {
    if ((provider instanceof ITextViewer))
    {
      ITextViewer v = (ITextViewer)provider;
      IDocument d = v.getDocument();
      IDocument other = (IDocument)Utils.getAdapter(saveable, IDocument.class);
      if ((d == other) && 
        ((element instanceof IResourceProvider)))
      {
        IResourceProvider rp = (IResourceProvider)element;
        IResource resource = rp.getResource();
        StructuredSelection selection = new StructuredSelection(resource);
        IWorkbenchPart workbenchPart = container.getWorkbenchPart();
        if (workbenchPart != null)
        {
          IWorkbenchSite ws = workbenchPart.getSite();
          
          MenuManager submenu1 = new MenuManager(getShowInMenuLabel());
          IContributionItem showInMenu = ContributionItemFactory.VIEWS_SHOW_IN.create(ws.getWorkbenchWindow());
          submenu1.add(showInMenu);
          manager.insertAfter("file", submenu1);
          MenuManager submenu2 = new MenuManager(TeamUIMessages.OpenWithActionGroup_0);
          
          submenu2.add(new OpenWithMenu(ws.getPage(), resource)
          {
            private final IWorkbenchSite val$ws;
            private final ITextViewer val$v;
            
            protected void openEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor)
            {
              super.openEditor(editorDescriptor, openUsingDescriptor);
              IEditorPart editor = val$ws.getPage().getActiveEditor();
              Point selectedRange = val$v.getSelectedRange();
              SaveablesCompareEditorInput.revealInEditor(editor, x, y);
            }
          });
          manager.insertAfter("file", submenu2);
          
          OpenFileAction openFileAction = new OpenFileAction(ws.getPage())
          {
            private final IWorkbenchSite val$ws;
            private final ITextViewer val$v;
            
            public void run()
            {
              super.run();
              IEditorPart editor = val$ws.getPage().getActiveEditor();
              Point selectedRange = val$v.getSelectedRange();
              SaveablesCompareEditorInput.revealInEditor(editor, x, y);
            }
          };
          openFileAction.selectionChanged(selection);
          manager.insertAfter("file", openFileAction);
        }
      }
    }
  }
  
  private static void revealInEditor(IEditorPart editor, int offset, int length)
  {
    if ((editor instanceof ITextEditor))
    {
      ((ITextEditor)editor).selectAndReveal(offset, length); return;
    }
    IGotoMarker gotoMarkerTarget;
    IGotoMarker gotoMarkerTarget;
    if ((editor instanceof IGotoMarker)) {
      gotoMarkerTarget = (IGotoMarker)editor;
    } else {
      gotoMarkerTarget = editor != null ? (IGotoMarker)editor.getAdapter(IGotoMarker.class) : null;
    }
    if (gotoMarkerTarget != null)
    {
      IEditorInput input = editor.getEditorInput();
      if ((input instanceof IFileEditorInput))
      {
        WorkspaceModifyOperation op = new WorkspaceModifyOperation()
        {
          private final int val$offset;
          private final int val$length;
          private final IGotoMarker val$gotoMarkerTarget;
          
          /* Error */
          protected void execute(IProgressMonitor monitor)
            throws CoreException
          {
            // Byte code:
            //   0: aconst_null
            //   1: astore_2
            //   2: aload_0
            //   3: getfield 61	org/eclipse/team/internal/ui/synchronize/SaveablesCompareEditorInput$12:val$input	Lorg/eclipse/ui/IEditorInput;
            //   6: checkcast 35	org/eclipse/ui/IFileEditorInput
            //   9: invokeinterface 67 1 0
            //   14: ldc 3
            //   16: invokeinterface 64 2 0
            //   21: astore_2
            //   22: aload_2
            //   23: ldc 2
            //   25: aload_0
            //   26: getfield 60	org/eclipse/team/internal/ui/synchronize/SaveablesCompareEditorInput$12:val$offset	I
            //   29: invokeinterface 66 3 0
            //   34: aload_2
            //   35: ldc 1
            //   37: aload_0
            //   38: getfield 60	org/eclipse/team/internal/ui/synchronize/SaveablesCompareEditorInput$12:val$offset	I
            //   41: aload_0
            //   42: getfield 59	org/eclipse/team/internal/ui/synchronize/SaveablesCompareEditorInput$12:val$length	I
            //   45: iadd
            //   46: invokeinterface 66 3 0
            //   51: aload_0
            //   52: getfield 62	org/eclipse/team/internal/ui/synchronize/SaveablesCompareEditorInput$12:val$gotoMarkerTarget	Lorg/eclipse/ui/ide/IGotoMarker;
            //   55: aload_2
            //   56: invokeinterface 68 2 0
            //   61: goto +16 -> 77
            //   64: astore_3
            //   65: aload_2
            //   66: ifnull +9 -> 75
            //   69: aload_2
            //   70: invokeinterface 65 1 0
            //   75: aload_3
            //   76: athrow
            //   77: aload_2
            //   78: ifnull +9 -> 87
            //   81: aload_2
            //   82: invokeinterface 65 1 0
            //   87: return
            // Line number table:
            //   Java source line #880	-> byte code offset #0
            //   Java source line #882	-> byte code offset #2
            //   Java source line #883	-> byte code offset #22
            //   Java source line #884	-> byte code offset #34
            //   Java source line #886	-> byte code offset #51
            //   Java source line #888	-> byte code offset #64
            //   Java source line #889	-> byte code offset #65
            //   Java source line #890	-> byte code offset #69
            //   Java source line #891	-> byte code offset #75
            //   Java source line #889	-> byte code offset #77
            //   Java source line #890	-> byte code offset #81
            //   Java source line #892	-> byte code offset #87
            // Local variable table:
            //   start	length	slot	name	signature
            //   0	88	0	this	12
            //   0	88	1	monitor	IProgressMonitor
            //   1	81	2	marker	org.eclipse.core.resources.IMarker
            //   64	12	3	localObject	Object
            // Exception table:
            //   from	to	target	type
            //   2	64	64	finally
          }
        };
        try
        {
          op.run(null);
        }
        catch (InvocationTargetException localInvocationTargetException) {}catch (InterruptedException localInterruptedException)
        {
          Assert.isTrue(false, "this operation can not be canceled");
        }
      }
      return;
    }
  }
}

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

import org.eclipse.core.runtime.CoreException;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipantDescriptor;
import org.eclipse.team.ui.synchronize.ISynchronizeScope;
import org.eclipse.team.ui.synchronize.SubscriberParticipant;

public abstract class ScopableSubscriberParticipant
  extends SubscriberParticipant
{
  public ScopableSubscriberParticipant() {}
  
  public ScopableSubscriberParticipant(ISynchronizeScope scope)
  {
    super(scope);
  }
  
  protected void setSubscriber(Subscriber subscriber)
  {
    super.setSubscriber(subscriber);
    try
    {
      ISynchronizeParticipantDescriptor descriptor = getDescriptor();
      setInitializationData(descriptor);
    }
    catch (CoreException e)
    {
      TeamUIPlugin.log(e);
    }
    if (getSecondaryId() == null) {
      setSecondaryId(Long.toString(System.currentTimeMillis()));
    }
  }
  
  protected abstract ISynchronizeParticipantDescriptor getDescriptor();
}

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

import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.help.IWorkbenchHelpSystem;

public class StartupPreferencePage
  extends FieldEditorPreferencePage
  implements IWorkbenchPreferencePage
{
  public static final String PROP_STARTUP_ACTION = "startupAction";
  public static final String STARTUP_ACTION_NONE = "none";
  public static final String STARTUP_ACTION_POPULATE = "populate";
  public static final String STARTUP_ACTION_SYNCHRONIZE = "synchronize";
  public static final String STARTUP_PREFERENCES = "org.eclipse.team.ui.startupPreferences";
  
  public StartupPreferencePage(IPreferenceStore store)
  {
    super(1);
    setTitle(TeamUIMessages.StartupPreferencePage_0);
    setDescription(TeamUIMessages.StartupPreferencePage_1);
    setPreferenceStore(store);
  }
  
  public void init(IWorkbench workbench) {}
  
  public void createControl(Composite parent)
  {
    super.createControl(parent);
    
    PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), "org.eclipse.team.ui.sync_startup_preference_page_context");
  }
  
  protected void createFieldEditors()
  {
    addField(new RadioGroupFieldEditor("startupAction", 
      TeamUIMessages.StartupPreferencePage_2, 1, 
      new String[][] {
      { TeamUIMessages.StartupPreferencePage_3, "populate" }, 
      { TeamUIMessages.StartupPreferencePage_4, "synchronize" }, 
      { TeamUIMessages.StartupPreferencePage_5, "none" } }, 
      
      getFieldEditorParent(), true));
  }
}

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

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.widgets.Control;

class StructuredViewerAdvisor$1
  implements IPropertyChangeListener
{
  final StructuredViewerAdvisor this$0;
  
  StructuredViewerAdvisor$1(StructuredViewerAdvisor paramStructuredViewerAdvisor)
  {
    this$0 = paramStructuredViewerAdvisor;
  }
  
  public void propertyChange(PropertyChangeEvent event)
  {
    if (event.getProperty().equals("org.eclipse.team.ui.view_syncinfo_in_label"))
    {
      StructuredViewer viewer = this$0.getViewer();
      if ((viewer != null) && (!viewer.getControl().isDisposed())) {
        viewer.refresh(true);
      }
    }
  }
}

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

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;

class StructuredViewerAdvisor$2
  implements DisposeListener
{
  final StructuredViewerAdvisor this$0;
  
  StructuredViewerAdvisor$2(StructuredViewerAdvisor paramStructuredViewerAdvisor)
  {
    this$0 = paramStructuredViewerAdvisor;
  }
  
  public void widgetDisposed(DisposeEvent e)
  {
    this$0.dispose();
  }
}

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

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.ui.OpenAndLinkWithEditorHelper;

class StructuredViewerAdvisor$3
  extends OpenAndLinkWithEditorHelper
{
  final StructuredViewerAdvisor this$0;
  
  StructuredViewerAdvisor$3(StructuredViewerAdvisor paramStructuredViewerAdvisor, StructuredViewer $anonymous0)
  {
    super($anonymous0);this$0 = paramStructuredViewerAdvisor;
  }
  
  /* Error */
  protected void activate(ISelection selection)
  {
    // Byte code:
    //   0: invokestatic 41	org/eclipse/jface/util/OpenStrategy:getOpenMethod	()I
    //   3: istore_2
    //   4: iconst_0
    //   5: invokestatic 42	org/eclipse/jface/util/OpenStrategy:setOpenMethod	(I)V
    //   8: aload_0
    //   9: getfield 40	org/eclipse/team/internal/ui/synchronize/StructuredViewerAdvisor$3:this$0	Lorg/eclipse/team/internal/ui/synchronize/StructuredViewerAdvisor;
    //   12: invokestatic 43	org/eclipse/team/internal/ui/synchronize/StructuredViewerAdvisor:access$0	(Lorg/eclipse/team/internal/ui/synchronize/StructuredViewerAdvisor;)V
    //   15: goto +10 -> 25
    //   18: astore_3
    //   19: iload_2
    //   20: invokestatic 42	org/eclipse/jface/util/OpenStrategy:setOpenMethod	(I)V
    //   23: aload_3
    //   24: athrow
    //   25: iload_2
    //   26: invokestatic 42	org/eclipse/jface/util/OpenStrategy:setOpenMethod	(I)V
    //   29: return
    // Line number table:
    //   Java source line #132	-> byte code offset #0
    //   Java source line #134	-> byte code offset #4
    //   Java source line #135	-> byte code offset #8
    //   Java source line #136	-> byte code offset #18
    //   Java source line #137	-> byte code offset #19
    //   Java source line #138	-> byte code offset #23
    //   Java source line #137	-> byte code offset #25
    //   Java source line #139	-> byte code offset #29
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	30	0	this	3
    //   0	30	1	selection	ISelection
    //   3	23	2	currentMode	int
    //   18	6	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   4	18	18	finally
  }
  
  protected void linkToEditor(ISelection selection) {}
  
  protected void open(ISelection selection, boolean activate)
  {
    StructuredViewerAdvisor.access$0(this$0);
  }
}

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

import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.StructuredViewer;

class StructuredViewerAdvisor$4
  implements IDoubleClickListener
{
  final StructuredViewerAdvisor this$0;
  private final StructuredViewer val$viewer;
  
  StructuredViewerAdvisor$4(StructuredViewerAdvisor paramStructuredViewerAdvisor, StructuredViewer paramStructuredViewer)
  {
    this$0 = paramStructuredViewerAdvisor;val$viewer = paramStructuredViewer;
  }
  
  public void doubleClick(DoubleClickEvent event)
  {
    this$0.handleDoubleClick(val$viewer, event);
  }
}

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

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredViewer;

cla
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