diff options
author | Tomasz Zarna | 2009-02-27 12:44:07 +0000 |
---|---|---|
committer | Tomasz Zarna | 2009-02-27 12:44:07 +0000 |
commit | 2e4b8b148821815e4b69494b8291ba3ff706ac24 (patch) | |
tree | 94cb8d2cd19147b6fc4366e92b6b816352eba58e | |
parent | b4bda40a7d75926c5094e4c6c115dd55162cbed6 (diff) | |
download | eclipse.platform.team-2e4b8b148821815e4b69494b8291ba3ff706ac24.tar.gz eclipse.platform.team-2e4b8b148821815e4b69494b8291ba3ff706ac24.tar.xz eclipse.platform.team-2e4b8b148821815e4b69494b8291ba3ff706ac24.zip |
bug 201116: [Viewers] Compare will silently discard additional contentMergeViewers associated with the same file extension
11 files changed, 505 insertions, 168 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java index c47fb93c6..cdda37d51 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java @@ -19,6 +19,7 @@ import java.util.Set; 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.ICompareAsText; 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,7 +146,7 @@ import org.eclipse.ui.services.IServiceLocator; public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress, ICompareContainer { private static final boolean DEBUG= false; - + /** * The name of the "dirty" property (value <code>"DIRTY_STATE"</code>). */ @@ -203,6 +205,7 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang private String fHelpContextId; private InternalOutlineViewerCreator fOutlineView; private ICompareAsText fCompareAsText; + private ViewerDescriptor vd; private class InternalOutlineViewerCreator extends OutlineViewerCreator { private OutlineViewerCreator getWrappedCreator() { @@ -552,13 +555,8 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang 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) @@ -926,8 +924,10 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang */ public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) { - Viewer newViewer= CompareUI.findContentViewer(oldViewer, input, parent, fCompareConfiguration); - + Viewer newViewer = vd != null ? vd.createViewer(oldViewer, parent, + fCompareConfiguration) : CompareUI.findContentViewer(oldViewer, + input, parent, fCompareConfiguration); + boolean isNewViewer= newViewer != oldViewer; if (DEBUG) System.out.println("CompareEditorInput.findContentViewer: " + isNewViewer); //$NON-NLS-1$ @@ -949,6 +949,27 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang } /** + * @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 <code>true</code> if there are unsaved changes. * The value returned is the value of the <code>DIRTY_STATE</code> property of this input object. diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java index b49cf0410..cab95e2d0 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java @@ -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 <code>CompareViewerPane</code> is a convenience class which installs a @@ -63,12 +80,8 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider, 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 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider, }; addMouseListener(ml); - label.addMouseListener(ml); + getTopLeft().addMouseListener(ml); addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { @@ -98,6 +111,24 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider, } /** + * @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 <code>null</code> clears it. * diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java index bc2892da8..31a89a157 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java @@ -216,6 +216,17 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane { 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 abstract class CompareViewerSwitchingPane extends CompareViewerPane { */ public void setInput(Object input) { - if (getInput() == input) + if (!inputChanged(input)) return; - - boolean hadFocus= hasFocus2(); + + boolean hadFocus = hasFocus2(); super.setInput(input); diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java new file mode 100644 index 000000000..8e8497a4e --- /dev/null +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.compare.internal; + +import java.util.Set; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareEditorInput; +import org.eclipse.compare.CompareViewerSwitchingPane; +import org.eclipse.compare.Splitter; +import org.eclipse.compare.structuremergeviewer.ICompareInput; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.ui.PlatformUI; + +public class CompareContentViewerSwitchingPane extends + CompareViewerSwitchingPane { + + private CompareEditorInput fCompareEditorInput; + + private ViewerDescriptor fSelectedViewerDescriptor; + + private ToolBar toolBar; + + private Menu menu; + + public CompareContentViewerSwitchingPane(Splitter parent, int style, + CompareEditorInput cei) { + super(parent, style); + fCompareEditorInput = cei; + } + + private CompareConfiguration getCompareConfiguration() { + return fCompareEditorInput.getCompareConfiguration(); + } + + protected Viewer getViewer(Viewer oldViewer, Object input) { + if (fSelectedViewerDescriptor != null) { + Set viewers = CompareUIPlugin.getDefault().findContentViewerDescriptor( + oldViewer, input, getCompareConfiguration()); + if (viewers.contains(fSelectedViewerDescriptor)) { + // use selected viewer only when appropriate for the new input + fCompareEditorInput + .setViewerDescriptor(fSelectedViewerDescriptor); + Viewer viewer = fCompareEditorInput.findContentViewer( + oldViewer, (ICompareInput) input, this); + return viewer; + } + } + if (input instanceof ICompareInput) { + fCompareEditorInput.setViewerDescriptor(null); + Viewer viewer = fCompareEditorInput.findContentViewer(oldViewer, + (ICompareInput) input, this); + fCompareEditorInput.setViewerDescriptor(fSelectedViewerDescriptor); + return viewer; + } + return null; + } + + protected Control createTopLeft(Composite p) { + final Composite composite = new Composite(p, SWT.NONE) { + public Point computeSize(int wHint, int hHint, boolean changed) { + return super.computeSize(wHint, Math.max(24, hHint), changed); + } + }; + + RowLayout layout = new RowLayout(); + layout.marginTop = 0; + composite.setLayout(layout); + + CLabel cl = new CLabel(composite, SWT.NONE); + cl.setText(null); + + toolBar = new ToolBar(composite, SWT.FLAT); + toolBar.setVisible(false); // hide by default + final ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH, 0); + toolItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage( + /* IWorkbenchGraphicConstants */"IMG_LCL_VIEW_MENU")); //$NON-NLS-1$ + toolItem + .setToolTipText(CompareMessages.CompareContentViewerSwitchingPane_switchButtonTooltip); + toolItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + Rectangle bounds = toolItem.getBounds(); + Point topLeft = new Point(bounds.x, bounds.y + bounds.height); + topLeft = toolBar.toDisplay(topLeft); + menu.setLocation(topLeft.x, topLeft.y); + menu.setVisible(true); + } + }); + return composite; + } + + protected boolean inputChanged(Object input) { + return getInput() != input + || fCompareEditorInput.getViewerDescriptor() != fSelectedViewerDescriptor; + } + + public void setInput(Object input) { + super.setInput(input); + Set/* <ViewerDescriptor> */data = CompareUIPlugin.getDefault() + .findContentViewerDescriptor(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); + } + } + } +} diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java index bd3f98fd8..e935247ab 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java @@ -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 final class CompareMessages extends NLS { 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); diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties index 4a7bb5b3e..142f5b53c 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties @@ -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_externalFolderMainButton=Browse... CompareWithOtherResourceDialog_externalFolderRadioButton=External folder CompareWithOtherResourceDialog_workspaceMainButton=Browse... CompareWithOtherResourceDialog_workspaceRadioButton=Workspace + +CompareContentViewerSwitchingPane_defaultViewer=Default +CompareContentViewerSwitchingPane_switchButtonTooltip=Switch diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java index a9695a338..49c5a9072 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java @@ -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.HashMap; 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 @@ public final class CompareUIPlugin extends AbstractUIPlugin { 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); - } - } - } + 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); + } - 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$ - } - } - } + 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); + } + } + } - 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; - } + 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 @@ public final class CompareUIPlugin extends AbstractUIPlugin { 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 @@ public final class CompareUIPlugin extends AbstractUIPlugin { private Map fStructureViewerAliases; private CompareFilter fFilter; private IPropertyChangeListener fPropertyChangeListener; - + /** * Creates the <code>CompareUIPlugin</code> object and registers all * structure creators, content merge viewers, and structure merge viewers @@ -807,21 +824,8 @@ public final class CompareUIPlugin extends AbstractUIPlugin { 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 - * is returned. Otherwise the input's type is used to find a viewer descriptor in the registry - * which in turn is used to create a content compare viewer under the given parent composite. - * If no viewer descriptor can be found <code>null</code> is returned. - * - * @param oldViewer a new viewer is only created if this old viewer cannot show the given input - * @param in the input object for which to find a content viewer - * @param parent the SWT parent composite under which the new viewer is created - * @param cc a configuration which is passed to a newly created viewer - * @return the compare viewer which is suitable for the given input object or <code>null</code> - */ - public Viewer findContentViewer(Viewer oldViewer, Object in, Composite parent, CompareConfiguration cc) { - + public Set/*<ViewerDescriptor>*/ findContentViewerDescriptor(Viewer oldViewer, Object in, CompareConfiguration cc) { + Set result = new LinkedHashSet(); if (in instanceof IStreamContentAccessor) { String type= ITypedElement.TEXT_TYPE; @@ -831,9 +835,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin { IContentType ct= getContentType(tin); if (ct != null) { initializeRegistries(); - Viewer viewer= getViewer(fContentViewers.search(ct), oldViewer, parent, cc); - if (viewer != null) - return viewer; + List list = fContentViewers.searchAll(ct); + if (list != null) + result.addAll(list); } String ty= tin.getType(); @@ -842,18 +846,18 @@ public final class CompareUIPlugin extends AbstractUIPlugin { } initializeRegistries(); - Viewer viewer= getViewer(fContentViewers.search(type), oldViewer, parent, cc); - if (viewer != null) - return viewer; + List list = fContentViewers.searchAll(type); + if (list != null) + result.addAll(list); // fallback - return new SimpleTextViewer(parent); + result.add(fContentViewers.search(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT))); + return result; } if (!(in instanceof ICompareInput)) return null; - - ICompareInput input= (ICompareInput) in; + ICompareInput input= (ICompareInput) in; IContentType ctype= getCommonType(input); if (isCompareAsText(input, cc)) { @@ -861,9 +865,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin { } if (ctype != null) { initializeRegistries(); - Viewer viewer= getViewer(fContentMergeViewers.search(ctype), oldViewer, parent, cc); - if (viewer != null) - return viewer; + List list = fContentMergeViewers.searchAll(ctype); + if (list != null) + result.addAll(list); } String[] types= getTypes(input); @@ -888,9 +892,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin { if (type != null) { initializeRegistries(); - Viewer viewer= getViewer(fContentMergeViewers.search(type), oldViewer, parent, cc); - if (viewer != null) - return viewer; + List list = fContentMergeViewers.searchAll(type); + if (list != null) + result.addAll(list); } // fallback @@ -906,13 +910,31 @@ public final class CompareUIPlugin extends AbstractUIPlugin { type= BINARY_TYPE; initializeRegistries(); - IViewerDescriptor vd= (IViewerDescriptor) fContentMergeViewers.search(type); - if (vd != null) - return vd.createViewer(oldViewer, parent, cc); + 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 + * is returned. Otherwise the input's type is used to find a viewer descriptor in the registry + * which in turn is used to create a content compare viewer under the given parent composite. + * If no viewer descriptor can be found <code>null</code> is returned. + * + * @param oldViewer a new viewer is only created if this old viewer cannot show the given input + * @param in the input object for which to find a content viewer + * @param parent the SWT parent composite under which the new viewer is created + * @param cc a configuration which is passed to a newly created viewer + * @return the compare viewer which is suitable for the given input object or <code>null</code> + */ + public Viewer findContentViewer(Viewer oldViewer, Object in, Composite parent, CompareConfiguration cc) { + return getViewer(findContentViewerDescriptor(oldViewer, in, cc).toArray()[0], oldViewer, parent, cc); + } + private boolean isCompareAsText(ICompareInput input, CompareConfiguration cc) { Set set = (Set)cc.getProperty(ICompareAsText.PROP_TEXT_INPUTS); if (set == null) diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java index 86fff3282..1636d6046 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java @@ -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 <code>Viewer</code>s from an <code>IConfigurationElement</code>. @@ -25,6 +24,7 @@ public class ViewerDescriptor implements IViewerDescriptor { 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 class ViewerDescriptor implements IViewerDescriptor { public String getExtension() { return fConfiguration.getAttribute(EXTENSIONS_ATTRIBUTE); } + + String getLabel() { + return fConfiguration.getAttribute(LABEL_ATTRIBUTE); + } } diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties index b52898939..6fb2a5e3a 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties @@ -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 @@ ValidateEdit.error.stillReadonly= File ''{0}'' is read-only. context.description = Comparing in an Editor context.name = Comparing in an Editor + +BinaryCompare.label=Binary Compare +TextCompare.label=Text Compare +ImageCompare.label=Image Compare diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml index 844a64108..0cf7b3573 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml @@ -307,19 +307,22 @@ <extension point="org.eclipse.compare.contentMergeViewers"> <viewer - extensions="class,exe,dll,binary,zip,jar" class="org.eclipse.compare.internal.BinaryCompareViewerCreator" - id="org.eclipse.compare.BinaryCompareViewerCreator"> + extensions="class,exe,dll,binary,zip,jar" + id="org.eclipse.compare.BinaryCompareViewerCreator" + label="%BinaryCompare.label"> </viewer> <viewer - extensions="txt" class="org.eclipse.compare.internal.TextMergeViewerCreator" - id="org.eclipse.compare.TextMergeViewerCreator"> + extensions="txt" + id="org.eclipse.compare.TextMergeViewerCreator" + label="%TextCompare.label"> </viewer> <viewer - extensions="gif,jpg,jpeg,png,bmp,ico,tif,tiff" class="org.eclipse.compare.internal.ImageMergeViewerCreator" - id="org.eclipse.compare.ImageMergeViewerCreator"> + extensions="gif,jpg,jpeg,png,bmp,ico,tif,tiff" + id="org.eclipse.compare.ImageMergeViewerCreator" + label="%ImageCompare.label"> </viewer> <contentTypeBinding contentTypeId="org.eclipse.core.runtime.text" diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/schema/contentMergeViewers.exsd b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/schema/contentMergeViewers.exsd index 244662a10..ee34a6dc5 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/schema/contentMergeViewers.exsd +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/schema/contentMergeViewers.exsd @@ -2,9 +2,9 @@ <!-- Schema file written by PDE --> <schema targetNamespace="org.eclipse.compare" xmlns="http://www.w3.org/2001/XMLSchema"> <annotation> - <appinfo> + <appInfo> <meta.schema plugin="org.eclipse.compare" id="contentMergeViewers" name="ContentMerge Viewers"/> - </appinfo> + </appInfo> <documentation> 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 @@ for viewers <samp>org.eclipse.compare.IViewerCreator</samp>. <element name="extension"> <annotation> - <appinfo> + <appInfo> <meta.element /> - </appinfo> + </appInfo> </annotation> <complexType> <sequence> @@ -45,9 +45,9 @@ for viewers <samp>org.eclipse.compare.IViewerCreator</samp>. <documentation> an optional name of the extension instance </documentation> - <appinfo> + <appInfo> <meta.attribute translatable="true"/> - </appinfo> + </appInfo> </annotation> </attribute> </complexType> @@ -68,9 +68,9 @@ for viewers <samp>org.eclipse.compare.IViewerCreator</samp>. a fully qualified name of a class that implements a factory for the content merge viewer and implements <samp>org.eclipse.compare.IViewerCreator</samp> </documentation> - <appinfo> + <appInfo> <meta.attribute kind="java" basedOn=":org.eclipse.compare.IViewerCreator"/> - </appinfo> + </appInfo> </annotation> </attribute> <attribute name="extensions" type="string"> @@ -80,6 +80,16 @@ content merge viewer and implements <samp>org.eclipse.compare.IViewerCreat </documentation> </annotation> </attribute> + <attribute name="label" type="string"> + <annotation> + <documentation> + a translatable label that will be used in the UI for this viewer + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> </complexType> </element> @@ -95,9 +105,9 @@ content merge viewer and implements <samp>org.eclipse.compare.IViewerCreat <documentation> The id of a content type defined using the <code>org.eclipse.core.contenttype.contentTypes</code> extension point. </documentation> - <appinfo> + <appInfo> <meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/> - </appinfo> + </appInfo> </annotation> </attribute> <attribute name="contentMergeViewerId" type="string" use="required"> @@ -105,18 +115,18 @@ content merge viewer and implements <samp>org.eclipse.compare.IViewerCreat <documentation> 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>) </documentation> - <appinfo> + <appInfo> <meta.attribute kind="identifier" basedOn="org.eclipse.compare.contentMergeViewers/viewer/@id"/> - </appinfo> + </appInfo> </annotation> </attribute> </complexType> </element> <annotation> - <appinfo> + <appInfo> <meta.section type="examples"/> - </appinfo> + </appInfo> <documentation> The following is an example of a compare/merge viewer for text files (extension "txt"): @@ -135,9 +145,9 @@ for text files (extension "txt"): </annotation> <annotation> - <appinfo> + <appInfo> <meta.section type="apiInfo"/> - </appinfo> + </appInfo> <documentation> The contributed class must implement <code>org.eclipse.compare.IViewerCreator</code> </documentation> @@ -145,20 +155,20 @@ for text files (extension "txt"): <annotation> - <appinfo> + <appInfo> <meta.section type="implementation"/> - </appinfo> + </appInfo> <documentation> The Compare UI plugin defines content viewers for text, binary contents, and images. </documentation> </annotation> <annotation> - <appinfo> + <appInfo> <meta.section type="copyright"/> - </appinfo> + </appInfo> <documentation> - 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> </documentation> </annotation> |