|
From: Matthias K <mat...@us...> - 2006-03-21 22:19:35
|
Update of /cvsroot/jcommander/incubator/matthias_kue/org.jcommander.eclipsepatch.compare/compare/org/eclipse/compare/contentmergeviewer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8063/compare/org/eclipse/compare/contentmergeviewer Added Files: package.html TextMergeViewerResources.properties IDocumentRange.java ITokenComparator.java IMergeViewerContentProvider.java TextMergeViewer.java ContentMergeViewer.java Log Message: Patched version of org.eclipse.compare --- NEW FILE: IDocumentRange.java --- /******************************************************************************* * Copyright (c) 2000, 2004 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.contentmergeviewer; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.IDocument; /** * Defines a subrange in a document. * <p> * It is used by text viewers that can work on a subrange of a document. For example, * a text viewer for Java compilation units might use this to restrict the view * to a single method. * </p> * <p> * Clients may implement this interface. * </p> * * @see TextMergeViewer * @see org.eclipse.compare.structuremergeviewer.DocumentRangeNode */ public interface IDocumentRange { /** * The position category typically used for an <code>IDocumentRange</code> position * (value <code>"DocumentRangeCategory"</code>). * @since 2.0 */ public static final String RANGE_CATEGORY= "DocumentRangeCategory"; //$NON-NLS-1$ /** * Returns the underlying document. * * @return the underlying document */ IDocument getDocument(); /** * Returns a position that specifies a subrange in the underlying document, * or <code>null</code> if this document range spans the whole underlying document. * * @return a position that specifies a subrange in the underlying document, or <code>null</code> */ Position getRange(); } --- NEW FILE: TextMergeViewerResources.properties --- ############################################################################### # Copyright (c) 2000, 2005 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 ############################################################################### # NLS_MESSAGEFORMAT_VAR # @(#)TextMergeViewerResources.properties # # Resource strings for TextMergeViewer.java title= Text Compare saveDialog.title= Save Resource saveDialog.message= Resource has been modified. Save changes? compareProgressTask.title= Computing Differences... tooComplexError.title= Error # NLS_MESSAGEFORMAT_ALL tooComplexError.format= Too many differences. Turn on the ''Ignore White Space'' option or do a structure compare first. # NLS_MESSAGEFORMAT_VAR ##################################################### # Toolbar actions ##################################################### action.CopyLeftToRight.label=Copy Left to Right action.CopyLeftToRight.tooltip=Copy All from Left to Right action.CopyLeftToRight.image=copy_r_co.gif action.CopyRightToLeft.label=Copy Right to Left action.CopyRightToLeft.tooltip=Copy All Non-Conflicting Changes from Right to Left action.CopyRightToLeft.image=copy_l_co.gif action.CopyDiffLeftToRight.label=Copy Current Change to Right action.CopyDiffLeftToRight.tooltip=Copy Current Change from Left to Right action.CopyDiffLeftToRight.image=copycont_r_co.gif action.CopyDiffRightToLeft.label=Copy Current Change to Left action.CopyDiffRightToLeft.tooltip=Copy Current Change from Right to Left action.CopyDiffRightToLeft.image=copycont_l_co.gif action.NextDiff.label=Next action.NextDiff.tooltip=Select Next Change action.NextDiff.image=next_nav.gif action.PrevDiff.label=Previous action.PrevDiff.tooltip=Select Previous Change action.PrevDiff.image=prev_nav.gif action.EnableAncestor.label=Enable Ancestor Pane action.EnableAncestor.tooltip.unchecked=Show Ancestor Pane action.EnableAncestor.tooltip.checked=Hide Ancestor Pane action.EnableAncestor.description.unchecked=Show Ancestor Pane action.EnableAncestor.description.checked=Hide Ancestor Pane action.EnableAncestor.image=ancestorpane_co.gif action.IgnoreAncestor.label=Ignore Ancestor action.IgnoreAncestor.tooltip.unchecked=Two-Way Compare (Ignore Ancestor) action.IgnoreAncestor.tooltip.checked=Three-Way Compare action.IgnoreAncestor.description.unchecked=Two-Way Compare (Ignore Ancestor) action.IgnoreAncestor.description.checked=Three-Way Compare action.IgnoreAncestor.image=twowaycompare_co.gif ##################################################### # Context menu actions ##################################################### action.undo.label=Undo@Ctrl+Z action.undo.tooltip=Undo Last Operation action.redo.label=Redo@Ctrl+Y action.redo.tooltip=Redo Last Operation action.cut.label=Cut@Ctrl+X action.cut.tooltip=Cut Text Selection to Clipboard action.copy.label=Copy@Ctrl+C action.copy.tooltip=Copy Text Selection to Clipboard action.paste.label=Paste@Ctrl+V action.paste.tooltip=Replace Text Selection with Clipboard Contents action.delete.label=Delete action.delete.tooltip=Delete Current Text Selection action.find.label=Find...@Ctrl+F action.find.tooltip=Find Occurrence action.selectAll.label=Select All@Ctrl+A action.selectAll.tooltip=Select All Changes action.save.label=Save@Ctrl+S action.save.tooltip=Save Changes --- NEW FILE: IMergeViewerContentProvider.java --- /******************************************************************************* * Copyright (c) 2000, 2004 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.contentmergeviewer; import org.eclipse.swt.graphics.Image; import org.eclipse.jface.viewers.IContentProvider; /** * A content provider that mediates between a <code>ContentMergeViewer</code>'s model * and the viewer itself. * <p> * Clients may implement this interface. * </p> * * @see ContentMergeViewer */ public interface IMergeViewerContentProvider extends IContentProvider { //---- ancestor side /** * Returns the label for the ancestor side of a <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the label for the ancestor side of a <code>ContentMergeViewer</code> */ String getAncestorLabel(Object input); /** * Returns an optional image for the ancestor side of a <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the image for the ancestor side of a <code>ContentMergeViewer</code>, * or <code>null</code> if none */ Image getAncestorImage(Object input); /** * Returns the contents for the ancestor side of a <code>ContentMergeViewer</code>. * The interpretation of the returned object depends on the concrete <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the content for the ancestor side of a <code>ContentMergeViewer</code>, * or <code>null</code> if none */ Object getAncestorContent(Object input); /** * Returns whether the ancestor side of the given input element should be shown. * @param input the merge viewer's input * @return <code>true</code> if the ancestor side of the given input element should be shown */ boolean showAncestor(Object input); //---- left side /** * Returns the label for the left side of a <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the label for the left side of a <code>ContentMergeViewer</code> */ String getLeftLabel(Object input); /** * Returns an optional image for the left side of a <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the image for the left side of a <code>ContentMergeViewer</code>, * or <code>null</code> if none */ Image getLeftImage(Object input); /** * Returns the contents for the left side of a <code>ContentMergeViewer</code>. * The interpretation of the returned object depends on the concrete <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the content for the left side of a <code>ContentMergeViewer</code>, * or <code>null</code> if none */ Object getLeftContent(Object input); /** * Returns whether the left side is editable. * * @param input the input object of the <code>ContentMergeViewer</code> * @return <code>true</code> if the left side of a <code>ContentMergeViewer</code> is editable */ boolean isLeftEditable(Object input); /** * Saves new contents for the left side of the <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @param bytes the new contents to save for the left side */ void saveLeftContent(Object input, byte[] bytes); //---- right side /** * Returns the label for the right side of a <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the label for the right side of a <code>ContentMergeViewer</code> */ String getRightLabel(Object input); /** * Returns an optional image for the right side of a <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the image for the right side of a <code>ContentMergeViewer</code>, * or <code>null</code> if none */ Image getRightImage(Object input); /** * Returns the contents for the right side of a <code>ContentMergeViewer</code>. * The interpretation of the returned object depends on the concrete <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @return the content for the right side of a <code>ContentMergeViewer</code>, * or <code>null</code> if none */ Object getRightContent(Object input); /** * Returns whether the right side is editable. * * @param input the input object of the <code>ContentMergeViewer</code> * @return <code>true</code> if the right side of a <code>ContentMergeViewer</code> is editable */ boolean isRightEditable(Object input); /** * Saves new contents for the right side of the <code>ContentMergeViewer</code>. * * @param input the input object of the <code>ContentMergeViewer</code> * @param bytes the new contents to save for the right side */ void saveRightContent(Object input, byte[] bytes); } --- NEW FILE: package.html --- <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="IBM"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]"> <title>Package-level Javadoc</title> </head> <body> Support for compare and merge viewers which show the content side-by-side. <h2> Package Specification</h2> The <b>ContentMergeViewer</b> is an abstract compare and merge viewer with two side-by-side content areas and an optional content area for a common ancestor (for three-way compare). Because the implementation makes no assumptions about the content type it is a subclass responsibility to deal with a specific type. Its subclass <b>ImageMergeViewer</b> in package org.eclipse.compare.internal shows how to base a simple mergeviewer for images on <b>ContentMergeViewer</b>. <p> A <b>ContentMergeViewer</b> accesses its model by means of a content provider which must implement the <b>IMergeViewerContentProvider</b> interface. <p> The <b>TextMergeViewer</b> is the standard concrete subclass of <b>ContentMergeViewer</b> for comparing and merging text content. <br> A text merge viewer uses the <b>org.eclipse.compare.rangedifferencer.RangeDifferencer</b> to perform a textual, line-by-line comparison of two (or three) input documents. For text lines that differ the <b>TextMergeViewer</b> uses an <b>ITokenComparator</b> to find longest sequences of matching and non-matching tokens. The <b>TextMergeViewer</b>'s default token compare works on characters separated by whitespace. If a different strategy is needed (for example, Java tokens in a Java-aware merge viewer), clients can create their own token comparators by implementing the <b>ITokenComparator</b> interface. <p>The <b>TextMergeViewer</b> not only works on whole documents but on subranges of documents too. In this case the viewer's input must be an <b>IDocumentRange</b> instead of an <b>IDocument</b>. </body> </html> --- NEW FILE: ContentMergeViewer.java --- /******************************************************************************* * Copyright (c) 2000, 2005 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.contentmergeviewer; import java.util.ResourceBundle; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; [...1005 lines suppressed...] boolean leftEmpty= content.getLeftContent(oldInput) == null; boolean rightEmpty= content.getRightContent(oldInput) == null; if (fCompareConfiguration.isLeftEditable() && fLeftSaveAction.isEnabled()) { byte[] bytes= getContents(true); if (leftEmpty && bytes != null && bytes.length == 0) bytes= null; setLeftDirty(false); content.saveLeftContent(oldInput, bytes); } if (fCompareConfiguration.isRightEditable() && fRightSaveAction.isEnabled()) { byte[] bytes= getContents(false); if (rightEmpty && bytes != null && bytes.length == 0) bytes= null; setRightDirty(false); content.saveRightContent(oldInput, bytes); } } } --- NEW FILE: TextMergeViewer.java --- /******************************************************************************* * Copyright (c) 2000, 2005 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 * cha...@ma... - curved line code *******************************************************************************/ package org.eclipse.compare.contentmergeviewer; import java.util.List; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import java.util.HashMap; import java.util.ResourceBundle; [...4266 lines suppressed...] while (e.hasNext()) { Diff diff= (Diff) e.next(); Position pos= diff.getPosition(part); int viewHeight= part.getLineRange(pos, region).y; int virtualHeight= diff.getMaxDiffHeight(fShowAncestor); if (v < (virtualPos + virtualHeight)) { v-= virtualPos; // make relative to this slot if (viewHeight <= 0) { v= 0; } else { v= (v*viewHeight)/virtualHeight; } return viewPos+v; } virtualPos+= virtualHeight; viewPos+= viewHeight; } return viewPos; } } --- NEW FILE: ITokenComparator.java --- /******************************************************************************* * Copyright (c) 2000, 2004 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.contentmergeviewer; import org.eclipse.compare.rangedifferencer.IRangeComparator; /** * For performing a so-called "token compare" on a line of text. * This interface extends the <code>IRangeComparator</code> interface * so that it can be used by the <code>TextMergeViewer</code>. * <p> * <code>TextMergeViewer</code> activates the token compare when navigating into * a range of differing lines. At first the lines are selected as a block. * When navigating into this block the token compare shows for every line * the differing token by selecting them. * <p> * <code>TextMergeViewer</code>'s default token comparator works on characters separated * by whitespace. If a different strategy is needed (for example, to use Java tokens in * a Java-aware merge viewer), clients may create their own token * comparators by implementing this interface (and overriding the * <code>TextMergeViewer.createTokenComparator</code> factory method). * </p> * * @see TextMergeViewer */ public interface ITokenComparator extends IRangeComparator { /** * Returns the start character position of the token with the given index. * If the index is out of range (but not negative) the character position * behind the last character (the length of the input string) is returned. * * @param index index of the token for which to return the start position * @return the start position of the token with the given index * @throws java.lang.IndexOutOfBoundsException if index is negative */ int getTokenStart(int index); /** * Returns the character length of the token with the given index. * If the index is out of range (but not negative) the value 0 is returned. * * @param index index of the token for which to return the start position * @return the character length of the token with the given index * @throws java.lang.IndexOutOfBoundsException if index is negative */ int getTokenLength(int index); } |