diff options
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java')
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java | 285 |
1 files changed, 0 insertions, 285 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java deleted file mode 100644 index 1c53e5e09..000000000 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.internal.ui.history; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.compare.*; -import org.eclipse.compare.structuremergeviewer.Differencer; -import org.eclipse.compare.structuremergeviewer.ICompareInput; -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.core.history.LocalFileRevision; -import org.eclipse.team.internal.ui.*; -import org.eclipse.team.internal.ui.mapping.AbstractCompareInput; -import org.eclipse.team.internal.ui.mapping.CompareInputChangeNotifier; -import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement; -import org.eclipse.team.ui.synchronize.SaveableCompareEditorInput; -import org.eclipse.ui.IWorkbenchPage; - -public class CompareFileRevisionEditorInput extends SaveableCompareEditorInput { - - private ITypedElement left; - private ITypedElement right; - - CompareInputChangeNotifier notifier = new CompareInputChangeNotifier() { - protected IResource[] getResources(ICompareInput input) { - IResource resource = getResource(input); - if (resource == null) - return new IResource[0]; - return new IResource[] { resource }; - } - }; - - public class MyDiffNode extends AbstractCompareInput { - public MyDiffNode(ITypedElement left, ITypedElement right) { - super(Differencer.CHANGE, null, left, right); - } - public void fireChange() { - super.fireChange(); - } - protected CompareInputChangeNotifier getChangeNotifier() { - return notifier; - } - public boolean needsUpdate() { - // The remote never changes - return false; - } - public void update() { - fireChange(); - } - } - - /** - * Creates a new CompareFileRevisionEditorInput. - * @param left - * @param right - * @param page - */ - public CompareFileRevisionEditorInput(ITypedElement left, ITypedElement right, IWorkbenchPage page) { - super(new CompareConfiguration(), page); - this.left = left; - this.right = right; - setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, new String[] { left.getName() })); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.LocalResourceCompareEditorInput#internalPrepareInput(org.eclipse.core.runtime.IProgressMonitor) - */ - protected ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - ICompareInput input = createCompareInput(); - getCompareConfiguration().setLeftEditable(isLeftEditable(input)); - getCompareConfiguration().setRightEditable(false); - ensureContentsCached(getLeftRevision(), getRightRevision(), monitor); - initLabels(input); - return input; - } - - protected FileRevisionTypedElement getRightRevision() { - if (right instanceof FileRevisionTypedElement) { - return (FileRevisionTypedElement) right; - } - return null; - } - - protected FileRevisionTypedElement getLeftRevision() { - if (left instanceof FileRevisionTypedElement) { - return (FileRevisionTypedElement) left; - } - return null; - } - - private static void ensureContentsCached(FileRevisionTypedElement left, FileRevisionTypedElement right, - IProgressMonitor monitor) { - if (left != null) { - try { - left.cacheContents(monitor); - } catch (CoreException e) { - TeamUIPlugin.log(e); - } - } - if (right != null) { - try { - right.cacheContents(monitor); - } catch (CoreException e) { - TeamUIPlugin.log(e); - } - } - } - - private boolean isLeftEditable(ICompareInput input) { - Object left = input.getLeft(); - if (left instanceof IEditableContent) { - return ((IEditableContent) left).isEditable(); - } - return false; - } - - private IResource getResource(ICompareInput input) { - if (getLocalElement() instanceof IResourceProvider) { - return ((IResourceProvider) getLocalElement()).getResource(); - } - return null; - } - - private ICompareInput createCompareInput() { - MyDiffNode input = new MyDiffNode(left,right); - return input; - } - - private void initLabels(ICompareInput input) { - CompareConfiguration cc = getCompareConfiguration(); - if (getLeftRevision() != null) { - String leftLabel = getFileRevisionLabel(getLeftRevision()); - cc.setLeftLabel(leftLabel); - } else if (getResource(input) != null) { - String label = NLS.bind(TeamUIMessages.CompareFileRevisionEditorInput_workspace, new Object[]{ input.getLeft().getName() }); - cc.setLeftLabel(label); - } - if (getRightRevision() != null) { - String rightLabel = getFileRevisionLabel(getRightRevision()); - cc.setRightLabel(rightLabel); - } - } - - private String getFileRevisionLabel(FileRevisionTypedElement element) { - Object fileObject = element.getFileRevision(); - if (fileObject instanceof LocalFileRevision){ - IFileState state = ((LocalFileRevision) fileObject).getState(); - if (state != null) { - return NLS.bind(TeamUIMessages.CompareFileRevisionEditorInput_localRevision, new Object[]{element.getName(), element.getTimestamp()}); - } - } else { - return NLS.bind(TeamUIMessages.CompareFileRevisionEditorInput_repository, new Object[]{ element.getName(), element.getContentIdentifier(), element.getAuthor()}); - } - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.compare.CompareEditorInput#getToolTipText() - */ - public String getToolTipText() { - Object[] titleObject = new Object[3]; - titleObject[0] = getLongName(left); - titleObject[1] = getContentIdentifier(getLeftRevision()); - titleObject[2] = getContentIdentifier(getRightRevision()); - return NLS.bind(TeamUIMessages.CompareFileRevisionEditorInput_compareResourceAndVersions, titleObject); - } - - /* (non-Javadoc) - * @see org.eclipse.compare.CompareEditorInput#getTitle() - */ - public String getTitle() { - Object[] titleObject = new Object[3]; - titleObject[0] = getShortName(left); - titleObject[1] = getContentIdentifier(getLeftRevision()); - titleObject[2] = getContentIdentifier(getRightRevision()); - return NLS.bind(TeamUIMessages.CompareFileRevisionEditorInput_compareResourceAndVersions, titleObject); - } - - /* (non-Javadoc) - * @see org.eclipse.compare.CompareEditorInput#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - if (adapter == IFile.class || adapter == IResource.class) { - if (getLocalElement() != null) { - return getLocalElement().getResource(); - } - return null; - } - return super.getAdapter(adapter); - } - - private String getShortName(ITypedElement element) { - if (element instanceof FileRevisionTypedElement){ - FileRevisionTypedElement fileRevisionElement = (FileRevisionTypedElement) element; - return fileRevisionElement.getName(); - } - else if (element instanceof LocalResourceTypedElement){ - LocalResourceTypedElement typedContent = (LocalResourceTypedElement) element; - return typedContent.getResource().getName(); - } - return element.getName(); - } - - private String getLongName(ITypedElement element) { - if (element instanceof FileRevisionTypedElement){ - FileRevisionTypedElement fileRevisionElement = (FileRevisionTypedElement) element; - return fileRevisionElement.getPath(); - } - else if (element instanceof LocalResourceTypedElement){ - LocalResourceTypedElement typedContent = (LocalResourceTypedElement) element; - return typedContent.getResource().getFullPath().toString(); - } - return element.getName(); - } - - private String getContentIdentifier(ITypedElement element){ - if (element instanceof FileRevisionTypedElement){ - FileRevisionTypedElement fileRevisionElement = (FileRevisionTypedElement) element; - Object fileObject = fileRevisionElement.getFileRevision(); - if (fileObject instanceof LocalFileRevision){ - try { - IStorage storage = ((LocalFileRevision) fileObject).getStorage(new NullProgressMonitor()); - if (Utils.getAdapter(storage, IFileState.class) != null){ - //local revision - return TeamUIMessages.CompareFileRevisionEditorInput_0; - } else if (Utils.getAdapter(storage, IFile.class) != null) { - //current revision - return TeamUIMessages.CompareFileRevisionEditorInput_1; - } - } catch (CoreException e) { - } - } else { - return fileRevisionElement.getContentIdentifier(); - } - } - return TeamUIMessages.CompareFileRevisionEditorInput_2; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.LocalResourceCompareEditorInput#fireInputChange() - */ - protected void fireInputChange() { - ((MyDiffNode)getCompareResult()).fireChange(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#contentsCreated() - */ - protected void contentsCreated() { - super.contentsCreated(); - notifier.initialize(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#handleDispose() - */ - protected void handleDispose() { - super.handleDispose(); - notifier.dispose(); - if (getLocalElement() != null) { - getLocalElement().discardBuffer(); - } - } - - public LocalResourceTypedElement getLocalElement() { - if (left instanceof LocalResourceTypedElement) { - return (LocalResourceTypedElement) left; - } - return null; - } - - public ITypedElement getLeft() { - return left; - } -} |