/*******************************************************************************
* 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.compare;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.MessageFormat;
import com.ibm.icu.util.Calendar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.*;
import java.util.*;
import org.eclipse.compare.internal.CompareContainer;
import org.eclipse.compare.internal.CompareUIPlugin;
import org.eclipse.compare.internal.ResizableDialog;
import org.eclipse.compare.internal.StructureCreatorDescriptor;
import org.eclipse.compare.internal.Utilities;
import org.eclipse.compare.structuremergeviewer.DiffNode;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
import org.eclipse.compare.structuremergeviewer.IStructureCreator;
/**
* A dialog where one input element can be compared against
* a list of historic variants (editions) of the same input element.
* The dialog can be used to implement functions like "Compare/Replace with Version" or
* "Compare/Replace from Local History" on workspace resources.
*
* In addition it is possible to specify a subsection of the input element
* (e.g. a method in a Java source file) by means of a "path".
* In this case the dialog compares only the subsection (as specified by the path)
* with the corresponding subsection in the list of editions.
* Only those editions are shown where the subsection differs from the same subsection in
* another edition thereby minimizing the number of presented variants.
* This functionality can be used to implement "Replace from Local History"
* for the Java language.
*
* Subsections of an input element are determined by first finding an
* IStructureCreator for the input's type.
* Then the method locate is used to extract the subsection.
*
* Each edition (variant in the list of variants) must implement the IModificationDate interface
* so that the dialog can sort the editions and present them in a tree structure where every
* node corresponds one day.
*
* The functionality is surfaced in a single function selectEdition.
*
* Clients may instantiate this class; it is not intended to be subclassed.
*
*
* @see IModificationDate
* @see ITypedElement
*
* @deprecated Use an org.eclipse.team.ui.history.IHistoryPageSource in conjunction with
* the org.eclipse.team.ui.history.IHistoryView or a HistoryPageCompareEditorInput.
* For sub-file elements, a org.eclipse.team.ui.history.ElementLocalHistoryPageSource can be used.
* @noextend This class is not intended to be subclassed by clients.
*/
@Deprecated
public class EditionSelectionDialog extends ResizableDialog {
/**
* An item in an underlying edition.
*/
private static class Pair {
private ITypedElement fEdition;
private ITypedElement fItem;
private String fContent;
private IStructureCreator fStructureCreator;
private boolean fHasError= false;
Pair(IStructureCreator structureCreator, ITypedElement edition, ITypedElement item) {
fStructureCreator= structureCreator;
fEdition= edition;
fItem= item;
}
Pair(IStructureCreator structureCreator, ITypedElement edition) {
this(structureCreator, edition, edition);
}
ITypedElement getEdition() {
return fEdition;
}
ITypedElement getItem() {
return fItem;
}
/*
* The content is lazily loaded
*/
private String getContent() {
if (fContent == null) {
if (fStructureCreator != null)
fContent= fStructureCreator.getContents(fItem, false);
else {
if (fItem instanceof IStreamContentAccessor) {
IStreamContentAccessor sca= (IStreamContentAccessor) fItem;
try {
fContent= Utilities.readString(sca);
} catch (CoreException ex) {
// NeedWork
CompareUIPlugin.log(ex);
}
}
}
if (fContent == null)
fContent= ""; //$NON-NLS-1$
}
return fContent;
}
@Override
public boolean equals(Object other) {
if (other != null && other.getClass() == getClass()) {
if (getContent().equals(((Pair)other).getContent()))
return true;
}
return super.equals(other);
}
@Override
public int hashCode() {
return getContent().hashCode();
}
}
// Configuration options
private CompareConfiguration fCompareConfiguration;
private ArrayList