/******************************************************************************* * Copyright (c) 2000, 2017 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.team.ui.synchronize; import java.lang.reflect.InvocationTargetException; import org.eclipse.compare.*; import org.eclipse.compare.structuremergeviewer.ICompareInput; import org.eclipse.compare.structuremergeviewer.IDiffContainer; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.osgi.util.NLS; import org.eclipse.team.core.TeamException; import org.eclipse.team.core.synchronize.SyncInfo; import org.eclipse.team.internal.ui.*; import org.eclipse.team.internal.ui.synchronize.SyncInfoModelElement; import org.eclipse.team.internal.ui.synchronize.SynchronizePageConfiguration; import org.eclipse.ui.progress.UIJob; /** * A {@link SyncInfo} editor input used as input to a two-way or three-way * compare viewer. It defines methods for accessing the three sides for the * compare, and a name and image which is used when displaying the three way input * in an editor. This input can alternately be used to show compare results in * a dialog by calling {@link CompareUI#openCompareDialog(org.eclipse.compare.CompareEditorInput)}. *
* The editor will not update when the elements in the sync info are changed. *
** Supports saving the local resource that is changed in the editor and will be updated * when the local resources is changed. *
* @see SyncInfo * @since 3.0 */ public final class SyncInfoCompareInput extends SaveableCompareEditorInput implements IResourceChangeListener { private MyDiffNode node; private String description; private IResource resource; private ISynchronizeParticipant participant; private ISynchronizePageConfiguration synchronizeConfiguration; /* * This class exists so that we can force the text merge viewers to update by * calling #fireChange when we save the compare input to disk. The side * effect is that the compare viewers will be updated to reflect the new changes * that have been made. Compare doesn't do this by default. */ private static class MyDiffNode extends SyncInfoModelElement { public MyDiffNode(IDiffContainer parent, SyncInfo info) { super(parent, info); } @Override public void fireChange() { super.fireChange(); } } /** * Creates a compare editor input based on an existingSyncInfo
.
*
* @param description a description of the context of this sync info. This
* is displayed to the user.
* @param sync the SyncInfo
used as the base for the compare input.
*/
public SyncInfoCompareInput(String description, SyncInfo sync) {
super(getDefaultCompareConfiguration(), null);
Assert.isNotNull(sync);
Assert.isNotNull(description);
this.description = description;
this.resource = sync.getLocal();
this.node = new MyDiffNode(null, sync);
setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, new String[] { sync.getLocal().getName() }));
}
/**
* Creates a compare editor input based on an existing SyncInfo
* from the given participant.
*
* @param participant the participant from which the sync info was obtained. The
* name of the participant is used as the description which is displayed to the user.
* @param sync the SyncInfo
used as the base for the compare input.
*
* @since 3.1
*/
public SyncInfoCompareInput(ISynchronizeParticipant participant, SyncInfo sync) {
this(participant.getName(), sync);
this.participant = participant;
}
public SyncInfoCompareInput(ISynchronizePageConfiguration configuration,
SyncInfo info) {
this(configuration.getParticipant(), info);
this.synchronizeConfiguration = configuration;
}
@Override
protected void handleDispose() {
super.handleDispose();
if (synchronizeConfiguration != null) {
ICompareNavigator navigator = (ICompareNavigator)synchronizeConfiguration.getProperty(SynchronizePageConfiguration.P_INPUT_NAVIGATOR);
if (navigator != null && navigator == super.getNavigator()) {
synchronizeConfiguration.setProperty(SynchronizePageConfiguration.P_INPUT_NAVIGATOR, new CompareNavigator() {
@Override
protected INavigatable[] getNavigatables() {
return new INavigatable[0];
}
});
}
}
}
@SuppressWarnings("unchecked")
@Override
public