Update of /cvsroot/jcommander/plugins/org.jcommander.eclipsepatch.compare/compare/org/eclipse/compare/internal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5127/compare/org/eclipse/compare/internal Added Files: ReplaceWithEditionAction.properties BufferedCanvas.java CompareFilter.java ImageCanvas.java CompareMessages.java AddFromHistoryDialog.java StructureCreatorDescriptor.java CompareWithEditionAction.java ImageMergeViewerResources.properties AddFromHistoryAction.java DiffImage.java ExceptionHandler.java TextViewerCreator.java ViewerSwitchingCancelled.java IViewerDescriptor.java MergeSourceViewer.java TextMergeViewerCreator.java MergeViewerAction.java TokenComparator.java CompareOutlinePage.java EditionAction.java ReplaceWithPreviousEditionAction.java ResourceCompareInput.java ReplaceWithEditionAction.java IgnoreWhiteSpaceAction.java CompareUIPlugin.java MergeViewerContentProvider.java TabFolderLayout.java DocLineComparator.java ViewerDescriptor.java ComparePreferencePage.java ICompareContextIds.java OverlayPreferenceStore.java BinaryCompareViewerResources.properties INavigatable.java AbstractViewer.java CompareEditor.java BinaryCompareViewer.java CompareDialog.java ImageMergeViewer.java CompareNavigator.java DocumentManager.java ListDialog.java AddFromHistoryAction.properties CompareMessages.properties BaseCompareAction.java IOpenable.java NullViewer.java CompareAction.java SimpleTextViewer.java ShowPseudoConflicts.java ResizableDialog.java StreamMergerDescriptor.java ChangePropertyAction.java CompareWithEditionAction.properties ISavable.java ImageMergeViewerCreator.java ListContentProvider.java Utilities.java BinaryCompareViewerCreator.java Messages.java CompareEditorContributor.java BufferedResourceNode.java Log Message: org.eclipse.compare, extracted from the Eclipse CVS. Now independent of org.eclipse.ui.ide etc. --- NEW FILE: ICompareContextIds.java --- /******************************************************************************* * Copyright (c) 2000, 2003 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.internal; import org.eclipse.compare.CompareUI; /** * Help context ids for the Compare UI. * <p> * This interface contains constants only; it is not intended to be implemented * or extended. * </p> * */ public interface ICompareContextIds { public static final String PREFIX= CompareUI.PLUGIN_ID + '.'; // Dialogs public static final String EDITION_DIALOG= PREFIX + "edition_dialog_context"; //$NON-NLS-1$ public static final String COMPARE_EDITOR= PREFIX + "compare_editor_context"; //$NON-NLS-1$ public static final String PATCH_INPUT_WIZARD_PAGE= PREFIX + "patch_input_wizard_page_context"; //$NON-NLS-1$ public static final String PATCH_PREVIEW_WIZARD_PAGE= PREFIX + "patch_preview_wizard_page_context"; //$NON-NLS-1$ public static final String ADD_FROM_HISTORY_DIALOG= PREFIX + "add_from_history_dialog_context"; //$NON-NLS-1$ public static final String COMPARE_DIALOG= PREFIX + "compare_dialog_context"; //$NON-NLS-1$ public static final String COMPARE_WITH_EDITION_DIALOG= PREFIX + "compare_with_edition_dialog_context"; //$NON-NLS-1$ public static final String REPLACE_WITH_EDITION_DIALOG= PREFIX + "replace_with_edition_dialog_context"; //$NON-NLS-1$ // Viewer public static final String TEXT_MERGE_VIEW= PREFIX + "text_merge_view_context"; //$NON-NLS-1$ public static final String IMAGE_COMPARE_VIEW= PREFIX + "image_compare_view_context"; //$NON-NLS-1$ public static final String BINARY_COMPARE_VIEW= PREFIX + "binary_compare_view_context"; //$NON-NLS-1$ public static final String DIFF_VIEW= PREFIX + "diff_view_context"; //$NON-NLS-1$ // Actions public static final String GLOBAL_NEXT_DIFF_ACTION= PREFIX + "global_next_diff_action_context"; //$NON-NLS-1$ public static final String GLOBAL_PREVIOUS_DIFF_ACTION= PREFIX + "global_previous_diff_action_context"; //$NON-NLS-1$ public static final String NEXT_DIFF_ACTION= PREFIX + "next_diff_action_context"; //$NON-NLS-1$ public static final String PREVIOUS_DIFF_ACTION= PREFIX + "previous_diff_action_context"; //$NON-NLS-1$ public static final String IGNORE_WHITESPACE_ACTION= PREFIX + "ignore_whitespace_action_context"; //$NON-NLS-1$ // Preference page public static final String COMPARE_PREFERENCE_PAGE= PREFIX + "compare_preference_page_context"; //$NON-NLS-1$ } --- NEW FILE: CompareNavigator.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.internal; import org.eclipse.swt.widgets.Control; import org.eclipse.jface.viewers.Viewer; import org.eclipse.compare.CompareEditorInput; import org.eclipse.compare.*; /** * Supports cross-pane navigation through differences. * XXX: Design is as it is because the feature had to be added without touching API. */ public class CompareNavigator implements ICompareNavigator { private boolean fLastDirection= true; private CompareViewerSwitchingPane[] fPanes; // Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106 private boolean fNextFirstTime= true; public CompareNavigator(CompareViewerSwitchingPane[] panes) { fPanes= panes; } public CompareViewerSwitchingPane[] getPanes() { return fPanes; } public boolean selectChange(boolean next) { fLastDirection= next; // Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106 if (next && fNextFirstTime && mustOpen()) { fNextFirstTime= false; openElement(); } // find most down stream CompareViewerPane int n= 0; INavigatable[] navigators= new INavigatable[4]; for (int i= 0; i < fPanes.length; i++) { navigators[n]= getNavigator(fPanes[i]); if (navigators[n] != null) n++; } while (n > 0) { n--; if (navigators[n].gotoDifference(next)) { // at end of this navigator continue; } // not at end return false; } return true; } private static INavigatable getNavigator(CompareViewerSwitchingPane pane) { if (pane == null) return null; if (pane.isEmpty()) return null; Viewer viewer= pane.getViewer(); if (viewer == null) return null; Control control= viewer.getControl(); if (control == null) return null; Object data= control.getData(INavigatable.NAVIGATOR_PROPERTY); if (data instanceof INavigatable) return (INavigatable) data; return null; } private static CompareNavigator findNavigator(Control c) { while (c != null && !c.isDisposed()) { // PR 1GEUVV2 Object data= c.getData(); if (data instanceof CompareEditorInput) { CompareEditorInput cei= (CompareEditorInput) data; Object adapter= cei.getAdapter(CompareNavigator.class); if (adapter instanceof CompareNavigator) return (CompareNavigator)adapter; } c= c.getParent(); } return null; } private boolean resetDirection() { boolean last= fLastDirection; fLastDirection= true; return last; } public static boolean getDirection(Control c) { CompareNavigator nav= findNavigator(c); if (nav != null) return nav.resetDirection(); return true; } /* * Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106 */ private boolean mustOpen() { if (fPanes == null || fPanes.length == 0) return false; for (int i= 1; i < fPanes.length; i++) { CompareViewerSwitchingPane pane= fPanes[i]; if (pane != null && pane.getInput() != null) return false; } return true; } /* * Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106 */ private void openElement() { if (fPanes == null || fPanes.length == 0) return; IOpenable openable= getOpenable(fPanes[0]); if (openable != null) { openable.openSelected(); } } /* * Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106 */ private static IOpenable getOpenable(CompareViewerSwitchingPane pane) { if (pane == null) return null; if (pane.isEmpty()) return null; Viewer viewer= pane.getViewer(); if (viewer == null) return null; Control control= viewer.getControl(); if (control == null) return null; Object data= control.getData(IOpenable.OPENABLE_PROPERTY); if (data instanceof IOpenable) return (IOpenable) data; return null; } } --- NEW FILE: DiffImage.java --- /******************************************************************************* * Copyright (c) 2000, 2003 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.internal; import org.eclipse.swt.graphics.*; import org.eclipse.jface.resource.CompositeImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor; /** * Combines an image with an overlay. */ public class DiffImage extends CompositeImageDescriptor { static final int HEIGHT= 16; private Image fBaseImage; private ImageDescriptor fOverlayImage; private int fWidth; private boolean fLeft= true; public DiffImage(Image base, ImageDescriptor overlay, int w) { fBaseImage= base; fOverlayImage= overlay; fWidth= w; } public DiffImage(Image base, ImageDescriptor overlay, int w, boolean onLeft) { fBaseImage= base; fOverlayImage= overlay; fWidth= w; fLeft= onLeft; } protected Point getSize() { return new Point(fWidth, HEIGHT); } protected void drawCompositeImage(int width, int height) { if (fLeft) { if (fBaseImage != null) { ImageData base= fBaseImage.getImageData(); if (base == null) base= DEFAULT_IMAGE_DATA; drawImage(base, fWidth - base.width, 0); } if (fOverlayImage != null) { ImageData overlay= fOverlayImage.getImageData(); if (overlay == null) overlay= DEFAULT_IMAGE_DATA; drawImage(overlay, 0, (HEIGHT - overlay.height) / 2); } } else { if (fBaseImage != null) { ImageData base= fBaseImage.getImageData(); if (base == null) base= DEFAULT_IMAGE_DATA; drawImage(base, 0, 0); } if (fOverlayImage != null) { ImageData overlay= fOverlayImage.getImageData(); if (overlay == null) overlay= DEFAULT_IMAGE_DATA; drawImage(overlay, fWidth - overlay.width, (HEIGHT - overlay.height) / 2); } } } } --- NEW FILE: ResourceCompareInput.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.internal; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.HashSet; import java.util.Set; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.swt.widgets.Composite; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import org.eclipse.compare.*; import org.eclipse.compare.structuremergeviewer.*; /** * A two-way or three-way compare for arbitrary IResources. */ class ResourceCompareInput extends CompareEditorInput { private static final boolean NORMALIZE_CASE= true; private boolean fThreeWay= false; private Object fRoot; private IStructureComparator fAncestor; private IStructureComparator fLeft; private IStructureComparator fRight; private IResource fAncestorResource; private IResource fLeftResource; private IResource fRightResource; private DiffTreeViewer fDiffViewer; private IAction fOpenAction; class MyDiffNode extends DiffNode { private boolean fDirty= false; private ITypedElement fLastId; private String fLastName; public MyDiffNode(IDiffContainer parent, int description, ITypedElement ancestor, ITypedElement left, ITypedElement right) { super(parent, description, ancestor, left, right); } public void fireChange() { super.fireChange(); setDirty(true); fDirty= true; if (fDiffViewer != null) fDiffViewer.refresh(this); } void clearDirty() { fDirty= false; } public String getName() { if (fLastName == null) fLastName= super.getName(); if (fDirty) return '<' + fLastName + '>'; return fLastName; } public ITypedElement getId() { ITypedElement id= super.getId(); if (id == null) return fLastId; fLastId= id; return id; } } static class FilteredBufferedResourceNode extends BufferedResourceNode { FilteredBufferedResourceNode(IResource resource) { super(resource); } protected IStructureComparator createChild(IResource child) { String name= child.getName(); if (CompareUIPlugin.getDefault().filter(name, child instanceof IContainer, false)) return null; return new FilteredBufferedResourceNode(child); } } /* * Creates an compare editor input for the given selection. */ ResourceCompareInput(CompareConfiguration config) { super(config); } public Viewer createDiffViewer(Composite parent) { fDiffViewer= new DiffTreeViewer(parent, getCompareConfiguration()) { protected void fillContextMenu(IMenuManager manager) { if (fOpenAction == null) { fOpenAction= new Action() { public void run() { handleOpen(null); } }; Utilities.initAction(fOpenAction, getBundle(), "action.CompareContents."); //$NON-NLS-1$ } boolean enable= false; ISelection selection= getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss= (IStructuredSelection)selection; if (ss.size() == 1) { Object element= ss.getFirstElement(); if (element instanceof MyDiffNode) { ITypedElement te= ((MyDiffNode) element).getId(); if (te != null) enable= !ITypedElement.FOLDER_TYPE.equals(te.getType()); } else enable= true; } } fOpenAction.setEnabled(enable); manager.add(fOpenAction); super.fillContextMenu(manager); } }; return fDiffViewer; } void setSelection(ISelection s) { IResource[] selection= Utilities.getResources(s); fThreeWay= selection.length == 3; fAncestorResource= null; fLeftResource= selection[0]; fRightResource= selection[1]; if (fThreeWay) { fLeftResource= selection[1]; fRightResource= selection[2]; } fAncestor= null; fLeft= getStructure(fLeftResource); fRight= getStructure(fRightResource); if (fThreeWay) { fAncestorResource= selection[0]; fAncestor= getStructure(fAncestorResource); } } /* * Returns true if compare can be executed for the given selection. */ public boolean isEnabled(ISelection s) { IResource[] selection= Utilities.getResources(s); if (selection.length < 2 || selection.length > 3) return false; fThreeWay= selection.length == 3; fLeftResource= selection[0]; fRightResource= selection[1]; if (fThreeWay) { fLeftResource= selection[1]; fRightResource= selection[2]; } if (!comparable(fLeftResource, fRightResource)) return false; if (fThreeWay) { fAncestorResource= selection[0]; if (!comparable(fLeftResource, fRightResource)) return false; } return true; } /** * Initializes the images in the compare configuration. */ void initializeCompareConfiguration() { CompareConfiguration cc= getCompareConfiguration(); if (fLeftResource != null) { cc.setLeftLabel(buildLabel(fLeftResource)); cc.setLeftImage(CompareUIPlugin.getImage(fLeftResource)); } if (fRightResource != null) { cc.setRightLabel(buildLabel(fRightResource)); cc.setRightImage(CompareUIPlugin.getImage(fRightResource)); } if (fThreeWay && fAncestorResource != null) { cc.setAncestorLabel(buildLabel(fAncestorResource)); cc.setAncestorImage(CompareUIPlugin.getImage(fAncestorResource)); } } /* * Returns true if both resources are either structured or unstructured. */ private boolean comparable(IResource c1, IResource c2) { return hasStructure(c1) == hasStructure(c2); } /* * Returns true if the given argument has a structure. */ private boolean hasStructure(IResource input) { if (input instanceof IContainer) return true; if (input instanceof IFile) { IFile file= (IFile) input; String type= file.getFileExtension(); if (type != null) { type= normalizeCase(type); return "JAR".equals(type) || "ZIP".equals(type); //$NON-NLS-2$ //$NON-NLS-1$ } } return false; } /* * Creates a <code>IStructureComparator</code> for the given input. * Returns <code>null</code> if no <code>IStructureComparator</code> * can be found for the <code>IResource</code>. */ private IStructureComparator getStructure(IResource input) { if (input instanceof IContainer) return new FilteredBufferedResourceNode(input); if (input instanceof IFile) { IStructureComparator rn= new FilteredBufferedResourceNode(input); IFile file= (IFile) input; String type= normalizeCase(file.getFileExtension()); if ("JAR".equals(type) || "ZIP".equals(type)) //$NON-NLS-2$ //$NON-NLS-1$ return new ZipFileStructureCreator().getStructure(rn); return rn; } return null; } /* * Performs a two-way or three-way diff on the current selection. */ public Object prepareInput(IProgressMonitor pm) throws InvocationTargetException { try { // fix for PR 1GFMLFB: ITPUI:WIN2000 - files that are out of sync with the file system appear as empty fLeftResource.refreshLocal(IResource.DEPTH_INFINITE, pm); fRightResource.refreshLocal(IResource.DEPTH_INFINITE, pm); if (fThreeWay && fAncestorResource != null) fAncestorResource.refreshLocal(IResource.DEPTH_INFINITE, pm); // end fix pm.beginTask(Utilities.getString("ResourceCompare.taskName"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$ String leftLabel= fLeftResource.getName(); String rightLabel= fRightResource.getName(); String title; if (fThreeWay) { String format= Utilities.getString("ResourceCompare.threeWay.title"); //$NON-NLS-1$ String ancestorLabel= fAncestorResource.getName(); title= MessageFormat.format(format, new String[] {ancestorLabel, leftLabel, rightLabel}); } else { String format= Utilities.getString("ResourceCompare.twoWay.title"); //$NON-NLS-1$ title= MessageFormat.format(format, new String[] {leftLabel, rightLabel}); } setTitle(title); Differencer d= new Differencer() { protected Object visit(Object parent, int description, Object ancestor, Object left, Object right) { return new MyDiffNode((IDiffContainer) parent, description, (ITypedElement)ancestor, (ITypedElement)left, (ITypedElement)right); } }; fRoot= d.findDifferences(fThreeWay, pm, null, fAncestor, fLeft, fRight); return fRoot; } catch (CoreException ex) { throw new InvocationTargetException(ex); } finally { pm.done(); } } public String getToolTipText() { if (fLeftResource != null && fRightResource != null) { String leftLabel= fLeftResource.getFullPath().makeRelative().toString(); String rightLabel= fRightResource.getFullPath().makeRelative().toString(); if (fThreeWay) { String format= Utilities.getString("ResourceCompare.threeWay.tooltip"); //$NON-NLS-1$ String ancestorLabel= fAncestorResource.getFullPath().makeRelative().toString(); return MessageFormat.format(format, new String[] {ancestorLabel, leftLabel, rightLabel}); } String format= Utilities.getString("ResourceCompare.twoWay.tooltip"); //$NON-NLS-1$ return MessageFormat.format(format, new String[] {leftLabel, rightLabel}); } // fall back return super.getToolTipText(); } private String buildLabel(IResource r) { String n= r.getFullPath().toString(); if (n.charAt(0) == IPath.SEPARATOR) return n.substring(1); return n; } public void saveChanges(IProgressMonitor pm) throws CoreException { super.saveChanges(pm); if (fRoot instanceof DiffNode) { try { commit(pm, (DiffNode) fRoot); } finally { if (fDiffViewer != null) fDiffViewer.refresh(); setDirty(false); } } } /* * Recursively walks the diff tree and commits all changes. */ private static void commit(IProgressMonitor pm, DiffNode node) throws CoreException { if (node instanceof MyDiffNode) ((MyDiffNode)node).clearDirty(); ITypedElement left= node.getLeft(); if (left instanceof BufferedResourceNode) ((BufferedResourceNode) left).commit(pm); ITypedElement right= node.getRight(); if (right instanceof BufferedResourceNode) ((BufferedResourceNode) right).commit(pm); IDiffElement[] children= node.getChildren(); if (children != null) { for (int i= 0; i < children.length; i++) { IDiffElement element= children[i]; if (element instanceof DiffNode) commit(pm, (DiffNode) element); } } } /* (non Javadoc) * see IAdaptable.getAdapter */ public Object getAdapter(Class adapter) { if (IFile[].class.equals(adapter)) { HashSet collector= new HashSet(); collectDirtyResources(fRoot, collector); return collector.toArray(new IFile[collector.size()]); } return super.getAdapter(adapter); } private void collectDirtyResources(Object o, Set collector) { if (o instanceof DiffNode) { DiffNode node= (DiffNode) o; ITypedElement left= node.getLeft(); if (left instanceof BufferedResourceNode) { BufferedResourceNode bn= (BufferedResourceNode) left; if (bn.isDirty()) { IResource resource= bn.getResource(); if (resource instanceof IFile) collector.add(resource); } } ITypedElement right= node.getRight(); if (right instanceof BufferedResourceNode) { BufferedResourceNode bn= (BufferedResourceNode) right; if (bn.isDirty()) { IResource resource= bn.getResource(); if (resource instanceof IFile) collector.add(resource); } } IDiffElement[] children= node.getChildren(); if (children != null) { for (int i= 0; i < children.length; i++) { IDiffElement element= children[i]; if (element instanceof DiffNode) collectDirtyResources(element, collector); } } } } private static String normalizeCase(String s) { if (NORMALIZE_CASE && s != null) return s.toUpperCase(); return s; } } --- NEW FILE: TextViewerCreator.java --- /******************************************************************************* * Copyright (c) 2000, 2003 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.internal; import org.eclipse.swt.widgets.Composite; import org.eclipse.jface.viewers.Viewer; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.IViewerCreator; /** * A factory object for the <code>TextMergeViewer</code>. * This indirection is necessary because only objects with a default * constructor can be created via an extension point * (this precludes Viewers). */ public class TextViewerCreator implements IViewerCreator { public Viewer createViewer(Composite parent, CompareConfiguration mp) { return new SimpleTextViewer(parent); } } --- NEW FILE: CompareUIPlugin.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.internal; import java.io.*; import java.lang.reflect.InvocationTargetException; import java.net.*; import java.util.*; import java.util.List; import org.eclipse.ui.*; [...1123 lines suppressed...] } } } return (IEditorPart[])result.toArray(new IEditorPart[result.size()]); } public static void logErrorMessage(String message) { if (message == null) message= ""; //$NON-NLS-1$ log(new Status(IStatus.ERROR, getPluginId(), INTERNAL_ERROR, message, null)); } public static void log(Throwable e) { log(new Status(IStatus.ERROR, getPluginId(), INTERNAL_ERROR, CompareMessages.ComparePlugin_internal_error, e)); } public static void log(IStatus status) { getDefault().getLog().log(status); } } --- NEW FILE: MergeViewerAction.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.internal; import org.eclipse.ui.texteditor.IUpdate; import org.eclipse.jface.action.Action; public abstract class MergeViewerAction extends Action implements IUpdate { private boolean fMutable; private boolean fSelection; private boolean fContent; public MergeViewerAction(boolean mutable, boolean selection, boolean content) { fMutable= mutable; fSelection= selection; fContent= content; } public boolean isSelectionDependent() { return fSelection; } public boolean isContentDependent() { return fContent; } public boolean isEditableDependent() { return fMutable; } public void update() { // empty default implementation } } --- NEW FILE: ReplaceWithEditionAction.properties --- ############################################################################### # 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 ############################################################################### # @(#)ReplaceWithEditionAction.properties # # Resources for ReplaceWithEditionAction.java title= Replace from Local History treeTitleFormat= Local History of ''{0}'' dateIcon= obj16/day_obj.gif timeIcon= obj16/resource_obj.gif treeFormat= {0} workspaceTreeFormat= {0} (Workspace File) parseErrorFormat= {0} (Parse Error) editionLabel= Local History ({0}) workspaceEditionLabel= Workspace File targetLabel= {0} todayFormat= Today ({0}) yesterdayFormat= Yesterday ({0}) dayFormat= {0} buttonLabel= Replace noLocalHistoryError= No local history available for selected resource. replaceError=Cannot replace resource (reason: {0}). taskName=Replacing --- NEW FILE: ComparePreferencePage.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.internal; import java.io.*; import java.util.*; import org.eclipse.ui.*; import org.eclipse.ui.dialogs.PreferenceLinkArea; import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.preference.*; import org.eclipse.jface.util.*; import org.eclipse.compare.*; import org.eclipse.compare.contentmergeviewer.TextMergeViewer; import org.eclipse.compare.structuremergeviewer.*; public class ComparePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { class FakeInput implements ITypedElement, IEncodedStreamContentAccessor { static final String UTF_16= "UTF-16"; //$NON-NLS-1$ String fContent; FakeInput(String name) { fContent= loadPreviewContentFromFile(name); } public Image getImage() { return null; } public String getName() { return "no name"; //$NON-NLS-1$ } public String getType() { return "no type"; //$NON-NLS-1$ } public InputStream getContents() { return new ByteArrayInputStream(Utilities.getBytes(fContent, UTF_16)); } public String getCharset() { return UTF_16; } } private static final String PREFIX= CompareUIPlugin.PLUGIN_ID + "."; //$NON-NLS-1$ public static final String OPEN_STRUCTURE_COMPARE= PREFIX + "OpenStructureCompare"; //$NON-NLS-1$ public static final String SYNCHRONIZE_SCROLLING= PREFIX + "SynchronizeScrolling"; //$NON-NLS-1$ public static final String SHOW_PSEUDO_CONFLICTS= PREFIX + "ShowPseudoConflicts"; //$NON-NLS-1$ public static final String INITIALLY_SHOW_ANCESTOR_PANE= PREFIX + "InitiallyShowAncestorPane"; //$NON-NLS-1$ public static final String PREF_SAVE_ALL_EDITORS= PREFIX + "SaveAllEditors"; //$NON-NLS-1$ public static final String SHOW_MORE_INFO= PREFIX + "ShowMoreInfo"; //$NON-NLS-1$ public static final String IGNORE_WHITESPACE= PREFIX + "IgnoreWhitespace"; //$NON-NLS-1$ //public static final String USE_SPLINES= PREFIX + "UseSplines"; //$NON-NLS-1$ public static final String USE_SINGLE_LINE= PREFIX + "UseSingleLine"; //$NON-NLS-1$ //public static final String USE_RESOLVE_UI= PREFIX + "UseResolveUI"; //$NON-NLS-1$ public static final String PATH_FILTER= PREFIX + "PathFilter"; //$NON-NLS-1$ private TextMergeViewer fPreviewViewer; private IPropertyChangeListener fPreferenceChangeListener; private CompareConfiguration fCompareConfiguration; private OverlayPreferenceStore fOverlayStore; private Map fCheckBoxes= new HashMap(); private Text fFilters; private SelectionListener fCheckBoxListener; public final OverlayPreferenceStore.OverlayKey[] fKeys= new OverlayPreferenceStore.OverlayKey[] { new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, OPEN_STRUCTURE_COMPARE), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SYNCHRONIZE_SCROLLING), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SHOW_PSEUDO_CONFLICTS), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, INITIALLY_SHOW_ANCESTOR_PANE), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, SHOW_MORE_INFO), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, IGNORE_WHITESPACE), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PREF_SAVE_ALL_EDITORS), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT), //new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, USE_SPLINES), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, USE_SINGLE_LINE), //new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, USE_RESOLVE_UI), new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PATH_FILTER), }; public static void initDefaults(IPreferenceStore store) { store.setDefault(OPEN_STRUCTURE_COMPARE, true); store.setDefault(SYNCHRONIZE_SCROLLING, true); store.setDefault(SHOW_PSEUDO_CONFLICTS, false); store.setDefault(INITIALLY_SHOW_ANCESTOR_PANE, false); store.setDefault(SHOW_MORE_INFO, false); store.setDefault(IGNORE_WHITESPACE, false); store.setDefault(PREF_SAVE_ALL_EDITORS, false); //store.setDefault(USE_SPLINES, false); store.setDefault(USE_SINGLE_LINE, true); //store.setDefault(USE_RESOLVE_UI, false); store.setDefault(PATH_FILTER, ""); //$NON-NLS-1$ store.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true); } public ComparePreferencePage() { //setDescription(Utilities.getString("ComparePreferencePage.description")); //$NON-NLS-1$ setPreferenceStore(CompareUIPlugin.getDefault().getPreferenceStore()); fOverlayStore= new OverlayPreferenceStore(getPreferenceStore(), fKeys); fPreferenceChangeListener= new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { String key= event.getProperty(); if (key.equals(INITIALLY_SHOW_ANCESTOR_PANE)) { boolean b= fOverlayStore.getBoolean(INITIALLY_SHOW_ANCESTOR_PANE); if (fCompareConfiguration != null) { fCompareConfiguration.setProperty(INITIALLY_SHOW_ANCESTOR_PANE, new Boolean(b)); } } } }; fOverlayStore.addPropertyChangeListener(fPreferenceChangeListener); } /* * @see IWorkbenchPreferencePage#init() */ public void init(IWorkbench workbench) { // empty } /* * @see PreferencePage#performOk() */ public boolean performOk() { fOverlayStore.propagate(); return true; } /* * @see PreferencePage#performDefaults() */ protected void performDefaults() { fOverlayStore.loadDefaults(); initializeFields(); super.performDefaults(); } /* * @see DialogPage#dispose() */ public void dispose() { if (fOverlayStore != null) { if (fPreferenceChangeListener != null) { fOverlayStore.removePropertyChangeListener(fPreferenceChangeListener); fPreferenceChangeListener= null; } fOverlayStore.stop(); fOverlayStore= null; } super.dispose(); } static public boolean getSaveAllEditors() { IPreferenceStore store= CompareUIPlugin.getDefault().getPreferenceStore(); return store.getBoolean(PREF_SAVE_ALL_EDITORS); } static public void setSaveAllEditors(boolean value) { IPreferenceStore store= CompareUIPlugin.getDefault().getPreferenceStore(); store.setValue(PREF_SAVE_ALL_EDITORS, value); } /* * @see PreferencePage#createContents(Composite) */ protected Control createContents(Composite parent) { PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ICompareContextIds.COMPARE_PREFERENCE_PAGE); fOverlayStore.load(); fOverlayStore.start(); TabFolder folder= new TabFolder(parent, SWT.NONE); folder.setLayout(new TabFolderLayout()); folder.setLayoutData(new GridData(GridData.FILL_BOTH)); TabItem item= new TabItem(folder, SWT.NONE); item.setText(Utilities.getString("ComparePreferencePage.generalTab.label")); //$NON-NLS-1$ //item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CFILE)); item.setControl(createGeneralPage(folder)); item= new TabItem(folder, SWT.NONE); item.setText(Utilities.getString("ComparePreferencePage.textCompareTab.label")); //$NON-NLS-1$ //item.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CFILE)); item.setControl(createTextComparePage(folder)); initializeFields(); Dialog.applyDialogFont(folder); return folder; } private Control createGeneralPage(Composite parent) { Composite composite= new Composite(parent, SWT.NULL); GridLayout layout= new GridLayout(); layout.numColumns= 1; composite.setLayout(layout); addCheckBox(composite, "ComparePreferencePage.structureCompare.label", OPEN_STRUCTURE_COMPARE, 0); //$NON-NLS-1$ addCheckBox(composite, "ComparePreferencePage.showMoreInfo.label", SHOW_MORE_INFO, 0); //$NON-NLS-1$ addCheckBox(composite, "ComparePreferencePage.ignoreWhitespace.label", IGNORE_WHITESPACE, 0); //$NON-NLS-1$ // a spacer new Label(composite, SWT.NONE); addCheckBox(composite, "ComparePreferencePage.saveBeforePatching.label", PREF_SAVE_ALL_EDITORS, 0); //$NON-NLS-1$ // a spacer new Label(composite, SWT.NONE); Label l= new Label(composite, SWT.WRAP); l.setText(Utilities.getString("ComparePreferencePage.filter.description")); //$NON-NLS-1$ Composite c2= new Composite(composite, SWT.NONE); c2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); layout= new GridLayout(2, false); layout.marginWidth= 0; c2.setLayout(layout); l= new Label(c2, SWT.NONE); l.setText(Utilities.getString("ComparePreferencePage.filter.label")); //$NON-NLS-1$ fFilters= new Text(c2, SWT.BORDER); fFilters.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fFilters.setText(fOverlayStore.getString(PATH_FILTER)); fFilters.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { String filters= fFilters.getText(); String message= CompareFilter.validateResourceFilters(filters); setValid(message == null); setMessage(null); setErrorMessage(message); fOverlayStore.setValue(PATH_FILTER, filters); } } ); return composite; } private Control createTextComparePage(Composite parent) { Composite composite= new Composite(parent, SWT.NULL); GridLayout layout= new GridLayout(); layout.numColumns= 1; composite.setLayout(layout); addCheckBox(composite, "ComparePreferencePage.synchronizeScrolling.label", SYNCHRONIZE_SCROLLING, 0); //$NON-NLS-1$ addCheckBox(composite, "ComparePreferencePage.initiallyShowAncestorPane.label", INITIALLY_SHOW_ANCESTOR_PANE, 0); //$NON-NLS-1$ addCheckBox(composite, "ComparePreferencePage.showPseudoConflicts.label", SHOW_PSEUDO_CONFLICTS, 0); //$NON-NLS-1$ //addCheckBox(composite, "ComparePreferencePage.useSplines.label", USE_SPLINES, 0); //$NON-NLS-1$ addCheckBox(composite, "ComparePreferencePage.useSingleLine.label", USE_SINGLE_LINE, 0); //$NON-NLS-1$ //addCheckBox(composite, "ComparePreferencePage.useResolveUI.label", USE_RESOLVE_UI, 0); //$NON-NLS-1$ // a spacer Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); separator.setVisible(false); Label previewLabel= new Label(composite, SWT.NULL); previewLabel.setText(Utilities.getString("ComparePreferencePage.preview.label")); //$NON-NLS-1$ Control previewer= createPreviewer(composite); GridData gd= new GridData(GridData.FILL_BOTH); gd.widthHint= convertWidthInCharsToPixels(60); gd.heightHint= convertHeightInCharsToPixels(13); previewer.setLayoutData(gd); PreferenceLinkArea area = new PreferenceLinkArea(composite, SWT.NONE, "org.eclipse.ui.preferencePages.ColorsAndFonts", Utilities.getString("ComparePreferencePage.colorAndFontLink"), //$NON-NLS-1$ //$NON-NLS-2$ (IWorkbenchPreferenceContainer) getContainer(), null); GridData data= new GridData(SWT.FILL, SWT.CENTER, false, false); area.getControl().setLayoutData(data); return composite; } private Control createPreviewer(Composite parent) { fCompareConfiguration= new CompareConfiguration(fOverlayStore); fCompareConfiguration.setAncestorLabel(Utilities.getString("ComparePreferencePage.ancestor.label")); //$NON-NLS-1$ fCompareConfiguration.setLeftLabel(Utilities.getString("ComparePreferencePage.left.label")); //$NON-NLS-1$ fCompareConfiguration.setLeftEditable(false); fCompareConfiguration.setRightLabel(Utilities.getString("ComparePreferencePage.right.label")); //$NON-NLS-1$ fCompareConfiguration.setRightEditable(false); fPreviewViewer= new TextMergeViewer(parent, SWT.BORDER, fCompareConfiguration); fPreviewViewer.setInput( new DiffNode(Differencer.CONFLICTING, new FakeInput("ComparePreferencePage.previewAncestor"), //$NON-NLS-1$ new FakeInput("ComparePreferencePage.previewLeft"), //$NON-NLS-1$ new FakeInput("ComparePreferencePage.previewRight") //$NON-NLS-1$ ) ); Control c= fPreviewViewer.getControl(); c.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (fCompareConfiguration != null) fCompareConfiguration.dispose(); } }); return c; } private void initializeFields() { Iterator e= fCheckBoxes.keySet().iterator(); while (e.hasNext()) { Button b= (Button) e.next(); String key= (String) fCheckBoxes.get(b); b.setSelection(fOverlayStore.getBoolean(key)); } if (fFilters != null) fFilters.setText(fOverlayStore.getString(PATH_FILTER)); } // overlay stuff private Button addCheckBox(Composite parent, String labelKey, String key, int indentation) { String label= Utilities.getString(labelKey); Button checkBox= new Button(parent, SWT.CHECK); checkBox.setText(label); GridData gd= new GridData(GridData.FILL_HORIZONTAL); gd.horizontalIndent= indentation; gd.horizontalSpan= 2; checkBox.setLayoutData(gd); if (fCheckBoxListener == null) { fCheckBoxListener= new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button button= (Button) e.widget; fOverlayStore.setValue((String) fCheckBoxes.get(button), button.getSelection()); } }; } checkBox.addSelectionListener(fCheckBoxListener); fCheckBoxes.put(checkBox, key); return checkBox; } private String loadPreviewContentFromFile(String key) { String preview= Utilities.getString(key); String separator= System.getProperty("line.separator"); //$NON-NLS-1$ StringBuffer buffer= new StringBuffer(); for (int i= 0; i < preview.length(); i++) { char c= preview.charAt(i); if (c == '\n') buffer.append(separator); else buffer.append(c); } return buffer.toString(); } } --- NEW FILE: IOpenable.java --- /******************************************************************************* * Copyright (c) 2000, 2003 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.internal; /* * Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20106 */ public interface IOpenable { static final String OPENABLE_PROPERTY= "org.eclipse.compare.internal.Openable"; //$NON-NLS-1$ /** * Opens the selected element */ void openSelected(); } --- NEW FILE: ImageCanvas.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.internal; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; /** * A <code>Canvas</code> showing a single centered SWT <code>Image</code>. * If the <code>Image</code> is larger than the <code>Canvas<code>, * <code>Scrollbars</code> will appear. */ class ImageCanvas extends Canvas { private Image fImage; /* * Create a new ImageCanvas with the given SWT stylebits. * (SWT.H_SCROLL and SWT.V_SCROLL are automtically added). */ public ImageCanvas(Composite parent, int style) { super(parent, style | SWT.H_SCROLL | SWT.V_SCROLL); ScrollBar sb= getHorizontalBar(); sb.setIncrement(20); sb.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { repaint(); } }); sb= getVerticalBar(); sb.setIncrement(20); sb.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { repaint(); } }); addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { updateScrollbars(); } }); addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { paint(event.gc); } }); } /* * Set the SWT Image to use as the ImageCanvas contents. */ public void setImage(Image img) { fImage= img; if (!isDisposed()) { getHorizontalBar().setSelection(0); getVerticalBar().setSelection(0); updateScrollbars(); getParent().layout(); redraw(); } } public void repaint() { if (!isDisposed()) { GC gc= new GC(this); paint(gc); gc.dispose(); } } void paint(GC gc) { if (fImage != null) { Rectangle bounds= fImage.getBounds(); Rectangle clientArea= getClientArea(); int x; if (bounds.width < clientArea.width) x= (clientArea.width - bounds.width) / 2; else x= -getHorizontalBar().getSelection(); int y; if (bounds.height < clientArea.height) y= (clientArea.height - bounds.height) / 2; else y= -getVerticalBar().getSelection(); gc.drawImage(fImage, x, y); } } /** * @private */ void updateScrollbars() { Rectangle bounds= fImage != null ? fImage.getBounds() : new Rectangle(0, 0, 0, 0); Point size= getSize(); Rectangle clientArea= getClientArea(); ScrollBar horizontal= getHorizontalBar(); if (bounds.width <= clientArea.width) { horizontal.setVisible(false); horizontal.setSelection(0); } else { horizontal.setPageIncrement(clientArea.width - horizontal.getIncrement()); int max= bounds.width + (size.x - clientArea.width); horizontal.setMaximum(max); horizontal.setThumb(size.x > max ? max : size.x); horizontal.setVisible(true); } ScrollBar vertical= getVerticalBar(); if (bounds.height <= clientArea.height) { vertical.setVisible(false); vertical.setSelection(0); } else { vertical.setPageIncrement(clientArea.height - vertical.getIncrement()); int max= bounds.height + (size.y - clientArea.height); vertical.setMaximum(max); vertical.setThumb(size.y > max ? max : size.y); vertical.setVisible(true); } } } --- NEW FILE: BufferedResourceNode.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.internal; import java.io.*; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.compare.*; import org.eclipse.compare.structuremergeviewer.IStructureComparator; /** * A buffer for a workspace resource. */ public class BufferedResourceNode extends ResourceNode { private boolean fDirty= false; private IFile fDeleteFile; /** * Creates a <code>ResourceNode</code> for the given resource. * * @param resource the resource */ public BufferedResourceNode(IResource resource) { super(resource); } /* * Returns <code>true</code> if buffer contains uncommitted changes. */ public boolean isDirty() { return fDirty; } protected IStructureComparator createChild(IResource child) { return new BufferedResourceNode(child); } public void setContent(byte[] contents) { fDirty= true; super.setContent(contents); } /* * Commits buffered contents to resource. */ public void commit(IProgressMonitor pm) throws CoreException { if (fDirty) { if (fDeleteFile != null) { fDeleteFile.delete(true, true, pm); return; } IResource resource= getResource(); if (resource instanceof IFile) { byte[] bytes= getContent(); ByteArrayInputStream is= new ByteArrayInputStream(bytes); try { IFile file= (IFile) resource; if (file.exists()) file.setContents(is, false, true, pm); else file.create(is, false, pm); fDirty= false; } finally { if (is != null) try { is.close(); } catch(IOException ex) { // Silently ignored } } } } } public ITypedElement replace(ITypedElement child, ITypedElement other) { if (child == null) { // add resource // create a node without a resource behind it! IResource resource= getResource(); if (resource instanceof IFolder) { IFolder folder= (IFolder) resource; IFile file= folder.getFile(other.getName()); child= new BufferedResourceNode(file); } } if (other == null) { // delete resource IResource resource= getResource(); if (resource instanceof IFolder) { IFolder folder= (IFolder) resource; IFile file= folder.getFile(child.getName()); if (file != null && file.exists()) { fDeleteFile= file; fDirty= true; } } return null; } if (other instanceof IStreamContentAccessor && child instanceof IEditableContent) { IEditableContent dst= (IEditableContent) child; try { InputStream is= ((IStreamContentAccessor)other).getContents(); byte[] bytes= Utilities.readBytes(is); if (bytes != null) dst.setContent(bytes); } catch (CoreException ex) { // NeedWork } } return child; } } --- NEW FILE: ViewerSwitchingCancelled.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.internal; public class ViewerSwitchingCancelled extends RuntimeException { private static final long serialVersionUID = 1L; } --- NEW FILE: ResizableDialog.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.internal; import java.util.ResourceBundle; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.DialogSettings; /** * Base class for resizable Dialogs with persistent window bounds. */ public abstract class ResizableDialog extends Dialog { // dialog store id constants private final static String DIALOG_BOUNDS_KEY= "ResizableDialogBounds"; //$NON-NLS-1$ private static final String X= "x"; //$NON-NLS-1$ private static final String Y= "y"; //$NON-NLS-1$ private static final String WIDTH= "width"; //$NON-NLS-1$ private static final String HEIGHT= "height"; //$NON-NLS-1$ protected ResourceBundle fBundle; private Rectangle fNewBounds; private IDialogSettings fSettings; private String fContextId; public ResizableDialog(Shell parent, ResourceBundle bundle) { super(parent); setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX); fBundle= bundle; fSettings= CompareUIPlugin.getDefault().getDialogSettings(); } public void setHelpContextId(String contextId) { fContextId= contextId; } /* * @see org.eclipse.jface.window.Window#configureShell(Shell) */ protected void configureShell(Shell newShell) { super.configureShell(newShell); if (fContextId != null) PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, fContextId); } protected Point getInitialSize() { int width= 0; int height= 0; final Shell s= getShell(); if (s != null) { s.addControlListener( new ControlListener() { public void controlMoved(ControlEvent arg0) { fNewBounds= s.getBounds(); } public void controlResized(ControlEvent arg0) { fNewBounds= s.getBounds(); } } ); } IDialogSettings bounds= fSettings.getSection(DIALOG_BOUNDS_KEY); if (bounds == null) { if (fBundle != null) { width= Utilities.getInteger(fBundle, WIDTH, 0); height= Utilities.getInteger(fBundle, HEIGHT, 0); Shell shell= getParentShell(); if (shell != null) { Point parentSize= shell.getSize(); if (width <= 0) width= parentSize.x-300; if (height <= 0) height= parentSize.y-200; } } else { Shell shell= getParentShell(); if (shell != null) { Point parentSize= shell.getSize(); width= parentSize.x-100; height= parentSize.y-100; } } if (width < 700) width= 700; if (height < 500) height= 500; } else { try { width= bounds.getInt(WIDTH); } catch (NumberFormatException e) { width= 700; } try { height= bounds.getInt(HEIGHT); } catch (NumberFormatException e) { height= 500; } } return new Point(width, height); } protected Point getInitialLocation(Point initialSize) { Point loc= super.getInitialLocation(initialSize); IDialogSettings bounds= fSettings.getSection(DIALOG_BOUNDS_KEY); if (bounds != null) { try { loc.x= bounds.getInt(X); } catch (NumberFormatException e) { // silently ignored } try { loc.y= bounds.getInt(Y); } catch (NumberFormatException e) { // silently ignored } } return loc; } public boolean close() { boolean closed= super.close(); if (closed && fNewBounds != null) saveBounds(fNewBounds); return closed; } private void saveBounds(Rectangle bounds) { IDialogSettings dialogBounds= fSettings.getSection(DIALOG_BOUNDS_KEY); if (dialogBounds == null) { dialogBounds= new DialogSettings(DIALOG_BOUNDS_KEY); fSettings.addSection(dialogBounds); } dialogBounds.put(X, bounds.x); dialogBounds.put(Y, bounds.y); dialogBounds.put(WIDTH, bounds.width); dialogBounds.put(HEIGHT, bounds.height); } } --- NEW FILE: CompareEditorContributor.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.internal; import java.util.ResourceBundle; import org.eclipse.jface.action.*; import org.eclipse.ui.*; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.help.IWorkbenchHelpSystem; import org.eclipse.ui.part.EditorActionBarContributor; import org.eclipse.compare.*; public class CompareEditorContributor extends EditorActionBarContributor { private IEditorPart fActiveEditorPart= null; private IgnoreWhiteSpaceAction fIgnoreWhitespace; private NavigationAction fNext; private NavigationAction fPrevious; private NavigationAction fToolbarNext; private NavigationAction fToolbarPrevious; public CompareEditorContributor() { ResourceBundle bundle= CompareUI.getResourceBundle(); IWorkbenchHelpSystem helpSystem= PlatformUI.getWorkbench().getHelpSystem(); fIgnoreWhitespace= new IgnoreWhiteSpaceAction(bundle, null); helpSystem.setHelp(fIgnoreWhitespace, ICompareContextIds.IGNORE_WHITESPACE_ACTION); fNext= new NavigationAction(bundle, true); helpSystem.setHelp(fNext, ICompareContextIds.GLOBAL_NEXT_DIFF_ACTION); fPrevious= new NavigationAction(bundle, false); helpSystem.setHelp(fPrevious, ICompareContextIds.GLOBAL_PREVIOUS_DIFF_ACTION); fToolbarNext= new NavigationAction(bundle, true); helpSystem.setHelp(fToolbarNext, ICompareContextIds.NEXT_DIFF_ACTION); fToolbarPrevious= new NavigationAction(bundle, false); helpSystem.setHelp(fToolbarPrevious, ICompareContextIds.PREVIOUS_DIFF_ACTION); } /* * @see EditorActionBarContributor#contributeToToolBar(IToolBarManager) */ public void contributeToToolBar(IToolBarManager tbm) { tbm.add(new Separator()); tbm.add(fIgnoreWhitespace); tbm.add(fToolbarNext); tbm.add(fToolbarPrevious); } /* * @see EditorActionBarContributor#contributeToMenu(IMenuManager) */ public void contributeToMenu(IMenuManager menuManager) { // empty implementation } public void setActiveEditor(IEditorPart targetEditor) { if (fActiveEditorPart == targetEditor) return; fActiveEditorPart= targetEditor; if (fActiveEditorPart != null) { IEditorInput input= fActiveEditorPart.getEditorInput(); if (input instanceof CompareEditorInput) { CompareEditorInput compareInput= (CompareEditorInput) input; fNext.setCompareEditorInput(compareInput); fPrevious.setCompareEditorInput(compareInput); // Begin fix http://bugs.eclipse.org/bugs/show_bug.cgi?id=20105 fToolbarNext.setCompareEditorInput(compareInput); fToolbarPrevious.setCompareEditorInput(compareInput); // End fix http://bugs.eclipse.org/bugs/show_bug.cgi?id=20105 } } if (targetEditor instanceof CompareEditor) { IActionBars actionBars= getActionBars(); CompareEditor editor= (CompareEditor) targetEditor; editor.setActionBars(actionBars); actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNext); actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPrevious); CompareConfiguration cc= editor.getCompareConfiguration(); fIgnoreWhitespace.setCompareConfiguration(cc); } } } --- NEW FILE: OverlayPreferenceStore.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 Corp... [truncated message content] |