### Eclipse Workspace Patch 1.0 #P org.eclipse.compare Index: compare/org/eclipse/compare/internal/CompareMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java,v retrieving revision 1.20 diff -u -r1.20 CompareMessages.java --- compare/org/eclipse/compare/internal/CompareMessages.java 10 Oct 2008 14:55:31 -0000 1.20 +++ compare/org/eclipse/compare/internal/CompareMessages.java 27 Feb 2009 11:20:19 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 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 @@ -129,6 +129,8 @@ public static String CompareWithOtherResourceDialog_externalFolderRadioButton; public static String CompareWithOtherResourceDialog_workspaceMainButton; public static String CompareWithOtherResourceDialog_workspaceRadioButton; + public static String CompareContentViewerSwitchingPane_defaultViewer; + public static String CompareContentViewerSwitchingPane_switchButtonTooltip; static { NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class); Index: compare/org/eclipse/compare/internal/CompareMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties,v retrieving revision 1.31 diff -u -r1.31 CompareMessages.properties --- compare/org/eclipse/compare/internal/CompareMessages.properties 10 Oct 2008 14:55:31 -0000 1.31 +++ compare/org/eclipse/compare/internal/CompareMessages.properties 27 Feb 2009 11:20:19 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. +# Copyright (c) 2000, 2009 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 @@ -141,3 +141,6 @@ CompareWithOtherResourceDialog_externalFolderRadioButton=External folder CompareWithOtherResourceDialog_workspaceMainButton=Browse... CompareWithOtherResourceDialog_workspaceRadioButton=Workspace + +CompareContentViewerSwitchingPane_defaultViewer=Default +CompareContentViewerSwitchingPane_switchButtonTooltip=Switch Index: compare/org/eclipse/compare/internal/ViewerDescriptor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java,v retrieving revision 1.14 diff -u -r1.14 ViewerDescriptor.java --- compare/org/eclipse/compare/internal/ViewerDescriptor.java 22 May 2007 20:19:52 -0000 1.14 +++ compare/org/eclipse/compare/internal/ViewerDescriptor.java 27 Feb 2009 11:20:19 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2009 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 @@ -10,13 +10,12 @@ *******************************************************************************/ package org.eclipse.compare.internal; -import org.eclipse.swt.widgets.Composite; - +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.IViewerCreator; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.compare.*; - import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Composite; /** * Creates Viewers from an IConfigurationElement. @@ -25,6 +24,7 @@ private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$ private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$ + private final static String LABEL_ATTRIBUTE = "label"; //$NON-NLS-1$ private IConfigurationElement fConfiguration; private IViewerCreator fViewerCreator; @@ -69,4 +69,8 @@ public String getExtension() { return fConfiguration.getAttribute(EXTENSIONS_ATTRIBUTE); } + + String getLabel() { + return fConfiguration.getAttribute(LABEL_ATTRIBUTE); + } } Index: compare/org/eclipse/compare/internal/CompareUIPlugin.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java,v retrieving revision 1.73 diff -u -r1.73 CompareUIPlugin.java --- compare/org/eclipse/compare/internal/CompareUIPlugin.java 10 Oct 2008 09:44:04 -0000 1.73 +++ compare/org/eclipse/compare/internal/CompareUIPlugin.java 27 Feb 2009 11:20:19 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 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 @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.ResourceBundle; @@ -92,73 +93,89 @@ static class CompareRegistry { - private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ - private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$ - private final static String CONTENT_TYPE_ID_ATTRIBUTE= "contentTypeId"; //$NON-NLS-1$ - - private HashMap fIdMap; // maps ids to data - private HashMap fExtensionMap; // maps extensions to data - private HashMap fContentTypeBindings; // maps content type bindings to data - - - void register(IConfigurationElement element, Object data) { - String id= element.getAttribute(ID_ATTRIBUTE); - if (id != null) { - if (fIdMap == null) - fIdMap= new HashMap(); - fIdMap.put(id, data); - } - - String types= element.getAttribute(EXTENSIONS_ATTRIBUTE); - if (types != null) { - if (fExtensionMap == null) - fExtensionMap= new HashMap(); - StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreElements()) { - String extension= tokenizer.nextToken().trim(); - fExtensionMap.put(normalizeCase(extension), data); - } - } - } - - void createBinding(IConfigurationElement element, String idAttributeName) { - String type= element.getAttribute(CONTENT_TYPE_ID_ATTRIBUTE); - String id= element.getAttribute(idAttributeName); - if (id == null) - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetIdAttributeMissing", idAttributeName)); //$NON-NLS-1$ - if (type != null && id != null && fIdMap != null) { - Object o= fIdMap.get(id); - if (o != null) { - IContentType ct= fgContentTypeManager.getContentType(type); - if (ct != null) { - if (fContentTypeBindings == null) - fContentTypeBindings= new HashMap(); - fContentTypeBindings.put(ct, o); - } else { - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.contentTypeNotFound", type)); //$NON-NLS-1$ - } - } else { - logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetNotFound", id)); //$NON-NLS-1$ - } - } - } - - Object search(IContentType type) { - if (fContentTypeBindings != null) { - for (; type != null; type= type.getBaseType()) { - Object data= fContentTypeBindings.get(type); - if (data != null) - return data; - } - } - return null; - } + private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ + private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$ + private final static String CONTENT_TYPE_ID_ATTRIBUTE= "contentTypeId"; //$NON-NLS-1$ + + private HashMap fIdMap; // maps ids to data + private HashMap fExtensionMap; // multimap: maps extensions to list of data + private HashMap fContentTypeBindings; // multimap: maps content type bindings to list of data + + + void register(IConfigurationElement element, Object data) { + String id= element.getAttribute(ID_ATTRIBUTE); + if (id != null) { + if (fIdMap == null) + fIdMap= new HashMap(); + fIdMap.put(id, data); + } + + String types= element.getAttribute(EXTENSIONS_ATTRIBUTE); + if (types != null) { + if (fExtensionMap == null) + fExtensionMap= new HashMap(); + StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$ + while (tokenizer.hasMoreElements()) { + String extension= tokenizer.nextToken().trim(); + List l = (List) fExtensionMap.get(normalizeCase(extension)); + if (l == null) + fExtensionMap.put(normalizeCase(extension), l=new ArrayList()); + l.add(data); + } + } + } + + void createBinding(IConfigurationElement element, String idAttributeName) { + String type= element.getAttribute(CONTENT_TYPE_ID_ATTRIBUTE); + String id= element.getAttribute(idAttributeName); + if (id == null) + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetIdAttributeMissing", idAttributeName)); //$NON-NLS-1$ + if (type != null && id != null && fIdMap != null) { + Object o= fIdMap.get(id); + if (o != null) { + IContentType ct= fgContentTypeManager.getContentType(type); + if (ct != null) { + if (fContentTypeBindings == null) + fContentTypeBindings= new HashMap(); + List l = (List) fContentTypeBindings.get(ct); + if (l == null) + fContentTypeBindings.put(ct, l=new ArrayList()); + l.add(o); + } else { + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.contentTypeNotFound", type)); //$NON-NLS-1$ + } + } else { + logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetNotFound", id)); //$NON-NLS-1$ + } + } + } + + Object search(IContentType type) { + List list = searchAll(type); + return list != null ? list.get(0) : null; + } - Object search(String extension) { - if (fExtensionMap != null) - return fExtensionMap.get(normalizeCase(extension)); - return null; - } + List searchAll(IContentType type) { + if (fContentTypeBindings != null) { + for (; type != null; type= type.getBaseType()) { + List data= (List) fContentTypeBindings.get(type); + if (data != null) + return data; + } + } + return null; + } + + Object search(String extension) { + List list = searchAll(extension); + return list != null ? list.get(0) : null; + } + + List searchAll(String extension) { + if (fExtensionMap != null) + return (List) fExtensionMap.get(normalizeCase(extension)); + return null; + } } /** Status code describing an internal error */ @@ -171,19 +188,19 @@ private static final String BINARY_TYPE= "binary"; //$NON-NLS-1$ private static final String STREAM_MERGER_EXTENSION_POINT= "streamMergers"; //$NON-NLS-1$ - private static final String STREAM_MERGER= "streamMerger"; //$NON-NLS-1$ - private static final String STREAM_MERGER_ID_ATTRIBUTE= "streamMergerId"; //$NON-NLS-1$ + private static final String STREAM_MERGER= "streamMerger"; //$NON-NLS-1$ + private static final String STREAM_MERGER_ID_ATTRIBUTE= "streamMergerId"; //$NON-NLS-1$ private static final String STRUCTURE_CREATOR_EXTENSION_POINT= "structureCreators"; //$NON-NLS-1$ - private static final String STRUCTURE_CREATOR= "structureCreator"; //$NON-NLS-1$ - private static final String STRUCTURE_CREATOR_ID_ATTRIBUTE= "structureCreatorId"; //$NON-NLS-1$ - + private static final String STRUCTURE_CREATOR= "structureCreator"; //$NON-NLS-1$ + private static final String STRUCTURE_CREATOR_ID_ATTRIBUTE= "structureCreatorId"; //$NON-NLS-1$ + private static final String VIEWER_TAG= "viewer"; //$NON-NLS-1$ private static final String STRUCTURE_MERGE_VIEWER_EXTENSION_POINT= "structureMergeViewers"; //$NON-NLS-1$ - private static final String STRUCTURE_MERGE_VIEWER_ID_ATTRIBUTE= "structureMergeViewerId"; //$NON-NLS-1$ + private static final String STRUCTURE_MERGE_VIEWER_ID_ATTRIBUTE= "structureMergeViewerId"; //$NON-NLS-1$ private static final String CONTENT_MERGE_VIEWER_EXTENSION_POINT= "contentMergeViewers"; //$NON-NLS-1$ - private static final String CONTENT_MERGE_VIEWER_ID_ATTRIBUTE= "contentMergeViewerId"; //$NON-NLS-1$ + private static final String CONTENT_MERGE_VIEWER_ID_ATTRIBUTE= "contentMergeViewerId"; //$NON-NLS-1$ private static final String CONTENT_VIEWER_EXTENSION_POINT= "contentViewers"; //$NON-NLS-1$ - private static final String CONTENT_VIEWER_ID_ATTRIBUTE= "contentViewerId"; //$NON-NLS-1$ + private static final String CONTENT_VIEWER_ID_ATTRIBUTE= "contentViewerId"; //$NON-NLS-1$ private static final String CONTENT_TYPE_BINDING= "contentTypeBinding"; //$NON-NLS-1$ @@ -223,7 +240,7 @@ private Map fStructureViewerAliases; private CompareFilter fFilter; private IPropertyChangeListener fPropertyChangeListener; - + /** * Creates the CompareUIPlugin object and registers all * structure creators, content merge viewers, and structure merge viewers @@ -807,6 +824,102 @@ return null; } + public Set/**/ getContentViewersData(Viewer oldViewer, Object in, CompareConfiguration cc) { + Set result = new LinkedHashSet(); + if (in instanceof IStreamContentAccessor) { + String type= ITypedElement.TEXT_TYPE; + + if (in instanceof ITypedElement) { + ITypedElement tin= (ITypedElement) in; + + IContentType ct= getContentType(tin); + if (ct != null) { + initializeRegistries(); + List list = fContentViewers.searchAll(ct); + if (list != null) + result.addAll(list); + } + + String ty= tin.getType(); + if (ty != null) + type= ty; + } + + initializeRegistries(); + List list = fContentViewers.searchAll(type); + if (list != null) + result.addAll(list); + + // fallback + result.add(fContentViewers.search(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT))); + return result; + } + + if (!(in instanceof ICompareInput)) + return null; + + ICompareInput input= (ICompareInput) in; + + IContentType ctype= getCommonType(input); + if (isCompareAsText(input, cc)) { + ctype = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT); + } + if (ctype != null) { + initializeRegistries(); + List list = fContentMergeViewers.searchAll(ctype); + if (list != null) + result.addAll(list); + } + + String[] types= getTypes(input); + String type= null; + if (isHomogenous(types)) + type= types[0]; + + if (ITypedElement.FOLDER_TYPE.equals(type)) + return null; + + if (type == null) { + int n= 0; + for (int i= 0; i < types.length; i++) + if (!ITypedElement.UNKNOWN_TYPE.equals(types[i])) { + n++; + if (type == null) + type= types[i]; // remember the first known type + } + if (n > 1) // don't use the type if there were more than one + type= null; + } + + if (type != null) { + initializeRegistries(); + List list = fContentMergeViewers.searchAll(type); + if (list != null) + result.addAll(list); + } + + // fallback + String leftType= guessType(input.getLeft()); + String rightType= guessType(input.getRight()); + + if (leftType != null || rightType != null) { + boolean right_text= rightType != null && ITypedElement.TEXT_TYPE.equals(rightType); + boolean left_text= leftType != null && ITypedElement.TEXT_TYPE.equals(leftType); + if ((leftType == null && right_text) || (left_text && rightType == null) || (left_text && right_text)) + type= ITypedElement.TEXT_TYPE; + else + type= BINARY_TYPE; + + initializeRegistries(); + List list = fContentMergeViewers.searchAll(type); + if (list != null) + result.addAll(list); + + return result; + } + return null; + } + /** * Returns a content compare viewer based on an old viewer and an input object. * If the old viewer is suitable for showing the input the old viewer @@ -920,7 +1033,7 @@ return set.contains(input); } - private static Viewer getViewer(Object descriptor, Viewer oldViewer, Composite parent, CompareConfiguration cc) { + static Viewer getViewer(Object descriptor, Viewer oldViewer, Composite parent, CompareConfiguration cc) { if (descriptor instanceof IViewerDescriptor) return ((IViewerDescriptor)descriptor).createViewer(oldViewer, parent, cc); return null; Index: compare/org/eclipse/compare/CompareViewerSwitchingPane.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java,v retrieving revision 1.32 diff -u -r1.32 CompareViewerSwitchingPane.java --- compare/org/eclipse/compare/CompareViewerSwitchingPane.java 4 Feb 2009 10:47:50 -0000 1.32 +++ compare/org/eclipse/compare/CompareViewerSwitchingPane.java 27 Feb 2009 11:20:19 -0000 @@ -216,6 +216,17 @@ return true; return false; } + + /** + * @param input the input + * @return true, if the input is considered as changed + * @noreference This method is not intended to be referenced by clients. + * @nooverride This method is not intended to be re-implemented or extended + * by clients. + */ + protected boolean inputChanged(Object input) { + return getInput() != input; + } /** * Sets the input object of this pane. @@ -233,10 +244,10 @@ */ public void setInput(Object input) { - if (getInput() == input) + if (!inputChanged(input)) return; - - boolean hadFocus= hasFocus2(); + + boolean hadFocus = hasFocus2(); super.setInput(input); Index: compare/org/eclipse/compare/CompareEditorInput.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java,v retrieving revision 1.105 diff -u -r1.105 CompareEditorInput.java --- compare/org/eclipse/compare/CompareEditorInput.java 23 Jan 2009 15:58:06 -0000 1.105 +++ compare/org/eclipse/compare/CompareEditorInput.java 27 Feb 2009 11:20:19 -0000 @@ -19,6 +19,7 @@ import org.eclipse.compare.contentmergeviewer.IFlushable; import org.eclipse.compare.internal.BinaryCompareViewer; import org.eclipse.compare.internal.ChangePropertyAction; +import org.eclipse.compare.internal.CompareContentViewerSwitchingPane; import org.eclipse.compare.internal.CompareEditorInputNavigator; import org.eclipse.compare.internal.CompareMessages; import org.eclipse.compare.internal.ComparePreferencePage; @@ -27,6 +28,7 @@ import org.eclipse.compare.internal.ICompareUIConstants; import org.eclipse.compare.internal.OutlineViewerCreator; import org.eclipse.compare.internal.Utilities; +import org.eclipse.compare.internal.ViewerDescriptor; import org.eclipse.compare.structuremergeviewer.DiffTreeViewer; import org.eclipse.compare.structuremergeviewer.ICompareInput; import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener; @@ -144,6 +146,8 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress, ICompareContainer { private static final boolean DEBUG= false; + + private ViewerDescriptor vd; /** * The name of the "dirty" property (value "DIRTY_STATE"). @@ -552,13 +556,8 @@ Control outline= createOutlineContents(fComposite, SWT.HORIZONTAL); - fContentInputPane= new CompareViewerSwitchingPane(fComposite, SWT.BORDER | SWT.FLAT) { - protected Viewer getViewer(Viewer oldViewer, Object input) { - if (input instanceof ICompareInput) - return findContentViewer(oldViewer, (ICompareInput)input, this); - return null; - } - }; + fContentInputPane= new CompareContentViewerSwitchingPane(fComposite, SWT.BORDER | SWT.FLAT, this); + if (fFocusPane == null) fFocusPane= fContentInputPane; if (outline != null) @@ -924,10 +923,17 @@ * @param parent the SWT parent composite under which the new viewer is created * @return a compare viewer which is suitable for the given input object or null */ - public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) { - - Viewer newViewer= CompareUI.findContentViewer(oldViewer, input, parent, fCompareConfiguration); - + public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, + Composite parent) { + Viewer newViewer = null; + if (vd != null) { + newViewer = vd.createViewer(oldViewer, parent, + fCompareConfiguration); + } else { + newViewer = CompareUI.findContentViewer(oldViewer, input, parent, + fCompareConfiguration); + } + boolean isNewViewer= newViewer != oldViewer; if (DEBUG) System.out.println("CompareEditorInput.findContentViewer: " + isNewViewer); //$NON-NLS-1$ @@ -949,6 +955,27 @@ } /** + * @param vd + * the viewer descriptor + * @noreference This method is not intended to be referenced by clients. + * @nooverride This method is not intended to be re-implemented or extended + * by clients. + */ + public void setViewerDescriptor(ViewerDescriptor vd) { + this.vd = vd; + } + + /** + * @return the viewer descriptor set for the input + * @noreference This method is not intended to be referenced by clients. + * @nooverride This method is not intended to be re-implemented or extended + * by clients. + */ + public ViewerDescriptor getViewerDescriptor() { + return this.vd; + } + + /** * Returns true if there are unsaved changes. * The value returned is the value of the DIRTY_STATE property of this input object. Index: compare/org/eclipse/compare/CompareViewerPane.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java,v retrieving revision 1.25 diff -u -r1.25 CompareViewerPane.java --- compare/org/eclipse/compare/CompareViewerPane.java 5 Apr 2007 14:48:38 -0000 1.25 +++ compare/org/eclipse/compare/CompareViewerPane.java 27 Feb 2009 11:20:19 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2009 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 @@ -10,17 +10,34 @@ *******************************************************************************/ package org.eclipse.compare; -import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.ToolBarManager; -import org.eclipse.jface.viewers.*; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.*; +import org.eclipse.swt.accessibility.ACC; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.custom.ViewForm; -import org.eclipse.swt.events.*; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.*; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; /** * A CompareViewerPane is a convenience class which installs a @@ -63,12 +80,8 @@ marginWidth= 0; marginHeight= 0; - CLabel label= new CLabel(this, SWT.NONE) { - public Point computeSize(int wHint, int hHint, boolean changed) { - return super.computeSize(wHint, Math.max(24, hHint), changed); - } - }; - setTopLeft(label); + Control topLeft = createTopLeft(this); + setTopLeft(topLeft); MouseAdapter ml= new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { @@ -82,7 +95,7 @@ }; addMouseListener(ml); - label.addMouseListener(ml); + getTopLeft().addMouseListener(ml); addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { @@ -98,6 +111,24 @@ } /** + * @param parent + * a widget which will be the parent of the control (cannot be + * null) + * @return the control to be placed in the top left corner of the pane + * @noreference This method is not intended to be referenced by clients. + * @nooverride This method is not intended to be re-implemented or extended + * by clients. + */ + protected Control createTopLeft(Composite parent) { + CLabel label = new CLabel(this, SWT.NONE) { + public Point computeSize(int wHint, int hHint, boolean changed) { + return super.computeSize(wHint, Math.max(24, hHint), changed); + } + }; + return label; + } + + /** * Set the pane's title text. * The value null clears it. * Index: schema/contentMergeViewers.exsd =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/schema/contentMergeViewers.exsd,v retrieving revision 1.18 diff -u -r1.18 contentMergeViewers.exsd --- schema/contentMergeViewers.exsd 24 Sep 2008 17:14:44 -0000 1.18 +++ schema/contentMergeViewers.exsd 27 Feb 2009 11:20:19 -0000 @@ -2,9 +2,9 @@ - + - + This extension point allows a plug-in to register compare/merge viewers for specific content types. The viewer is expected to @@ -17,9 +17,9 @@ - + - + @@ -45,9 +45,9 @@ an optional name of the extension instance - + - + @@ -68,9 +68,9 @@ a fully qualified name of a class that implements a factory for the content merge viewer and implements <samp>org.eclipse.compare.IViewerCreator</samp> - + - + @@ -80,6 +80,16 @@ + + + + a translatable label that will be used in the UI for this viewer + + + + + + @@ -95,9 +105,9 @@ The id of a content type defined using the <code>org.eclipse.core.contenttype.contentTypes</code> extension point. - + - + @@ -105,18 +115,18 @@ The id of a merge viewer defined using the <code>viewer</code> element of this extension point (i.e. <code>org.eclipse.compare.contentMergeViewers</code>) - + - + - + - + The following is an example of a compare/merge viewer for text files (extension "txt"): @@ -135,9 +145,9 @@ - + - + The contributed class must implement <code>org.eclipse.compare.IViewerCreator</code> @@ -145,20 +155,20 @@ - + - + The Compare UI plugin defines content viewers for text, binary contents, and images. - + - + - Copyright (c) 2000, 2008 IBM Corporation and others.<br> + Copyright (c) 2000, 2009 IBM Corporation and others.<br> 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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> Index: plugin.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties,v retrieving revision 1.93 diff -u -r1.93 plugin.properties --- plugin.properties 19 Aug 2008 14:45:06 -0000 1.93 +++ plugin.properties 27 Feb 2009 11:20:18 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. +# Copyright (c) 2000, 2009 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 @@ -224,3 +224,7 @@ context.description = Comparing in an Editor context.name = Comparing in an Editor + +BinaryCompare.label=Binary Compare +TextCompare.label=Text Compare +ImageCompare.label=Image Compare Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml,v retrieving revision 1.68 diff -u -r1.68 plugin.xml --- plugin.xml 25 Aug 2008 12:35:11 -0000 1.68 +++ plugin.xml 27 Feb 2009 11:20:18 -0000 @@ -307,19 +307,22 @@ + extensions="class,exe,dll,binary,zip,jar" + id="org.eclipse.compare.BinaryCompareViewerCreator" + label="%BinaryCompare.label"> + extensions="txt" + id="org.eclipse.compare.TextMergeViewerCreator" + label="%TextCompare.label"> + extensions="gif,jpg,jpeg,png,bmp,ico,tif,tiff" + id="org.eclipse.compare.ImageMergeViewerCreator" + label="%ImageCompare.label"> */data = CompareUIPlugin.getDefault() + .getContentViewersData(getViewer(), input, + getCompareConfiguration()); + updateMenu(data); + } + + private void updateMenu(Set data) { + if (data != null && data.size() > 1) { + ViewerDescriptor[] fViewerDescriptors = (ViewerDescriptor[]) data + .toArray(new ViewerDescriptor[0]); + + // dispose the old menu, if exists + if (menu != null) + menu.dispose(); + + menu = new Menu(getShell(), SWT.POP_UP); + + // add default + String label = fViewerDescriptors[0].getLabel(); + if (label == null || label.equals("")) { //$NON-NLS-1$ + label = CompareMessages.CompareContentViewerSwitchingPane_defaultViewer; + } + MenuItem defaultItem = new MenuItem(menu, SWT.RADIO); + defaultItem.setText(label); + defaultItem + .addSelectionListener(createSelectionListener(fViewerDescriptors[0])); + menu.setDefaultItem(defaultItem); + defaultItem.setSelection(fViewerDescriptors[0] == fSelectedViewerDescriptor); + + // add others + for (int j = 1; j < fViewerDescriptors.length; j++) { + final ViewerDescriptor vdi = fViewerDescriptors[j]; + label = vdi.getLabel(); + if (label != null && !label.equals("")) { //$NON-NLS-1$ + MenuItem item = new MenuItem(menu, SWT.RADIO); + item.setText(label); + item.addSelectionListener(createSelectionListener(vdi)); + item + .setSelection(fViewerDescriptors[j] == fSelectedViewerDescriptor); + } + } + toolBar.setVisible(true); + } else { + toolBar.setVisible(false); + } + } + + private SelectionListener createSelectionListener(final ViewerDescriptor vd) { + return new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + MenuItem mi = (MenuItem) e.widget; + if (mi.getSelection()) { + Viewer oldViewer = getViewer(); + fSelectedViewerDescriptor = vd; + CompareContentViewerSwitchingPane.this.setInput(oldViewer + .getInput()); + } + } + + public void widgetDefaultSelected(SelectionEvent e) { + // nothing to do + } + }; + } + + public void setText(String label) { + Composite c = (Composite) getTopLeft(); + Control[] children = c.getChildren(); + for (int i = 0; i < children.length; i++) { + if (children[i] instanceof CLabel) { + CLabel cl = (CLabel) children[i]; + if (cl != null && !cl.isDisposed()) { + cl.setText(label); + c.layout(); + } + return; + } + } + } + + public void setImage(Image image) { + Composite c = (Composite) getTopLeft(); + Control[] children = c.getChildren(); + for (int i = 0; i < children.length; i++) { + if (children[i] instanceof CLabel) { + CLabel cl = (CLabel) children[i]; + if (cl != null && !cl.isDisposed()) + cl.setImage(image); + return; + } + } + } + + public void addMouseListener(MouseListener listener) { + Composite c = (Composite) getTopLeft(); + Control[] children = c.getChildren(); + for (int i = 0; i < children.length; i++) { + if (children[i] instanceof CLabel) { + CLabel cl = (CLabel) children[i]; + cl.addMouseListener(listener); + } + } + } +}