diff options
author | Tomasz Zarna | 2008-08-19 07:58:04 +0000 |
---|---|---|
committer | Tomasz Zarna | 2008-08-19 07:58:04 +0000 |
commit | aead4a2851364ccb48d5ad51f1c0d2254cc7ec0d (patch) | |
tree | 615e780f37fdd5f539e17665d095ad12bac6e1a0 /bundles | |
parent | 0f051757866633f186cf3787ebb8c4529f9a59b7 (diff) | |
download | eclipse.platform.team-aead4a2851364ccb48d5ad51f1c0d2254cc7ec0d.tar.gz eclipse.platform.team-aead4a2851364ccb48d5ad51f1c0d2254cc7ec0d.tar.xz eclipse.platform.team-aead4a2851364ccb48d5ad51f1c0d2254cc7ec0d.zip |
bug 239959: Adding content to "Compare with other resource" dialog by drag&dropping
Diffstat (limited to 'bundles')
8 files changed, 604 insertions, 16 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java index 839f003ae..0ff9e5444 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 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 @@ -8,17 +8,17 @@ * Contributors: * IBM Corporation - initial API and implementation * Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource + * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959 *******************************************************************************/ package org.eclipse.compare.internal; +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareUI; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; - import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.compare.CompareUI; /* @@ -26,16 +26,16 @@ import org.eclipse.compare.CompareUI; */ public class CompareAction extends BaseCompareAction implements IObjectActionDelegate { - private ResourceCompareInput fInput; - private IWorkbenchPage fWorkbenchPage; - + protected ResourceCompareInput fInput; + protected IWorkbenchPage fWorkbenchPage; + protected boolean showSelectAncestorDialog = true; public void run(ISelection selection) { if (fInput != null) { // Pass the shell so setSelection can prompt the user for which // resource should be the ancestor - boolean ok = fInput.setSelection(selection, - fWorkbenchPage.getWorkbenchWindow().getShell()); + boolean ok = fInput.setSelection(selection, fWorkbenchPage + .getWorkbenchWindow().getShell(), showSelectAncestorDialog); if (!ok) return; fInput.initializeCompareConfiguration(); CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage); 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 800ea1820..1a8ea13ec 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, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource + * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959 *******************************************************************************/ package org.eclipse.compare.internal; @@ -108,6 +109,17 @@ public final class CompareMessages extends NLS { public static String SelectAncestorDialog_title; public static String SelectAncestorDialog_message; public static String SelectAncestorDialog_option; + public static String CompareWithOther_fileLabel; + public static String CompareWithOther_ancestor; + public static String CompareWithOther_rightPanel; + public static String CompareWithOther_leftPanel; + public static String CompareWithOther_dialogTitle; + public static String CompareWithOther_dialogMessage; + public static String CompareWithOther_error_not_comparable; + public static String CompareWithOther_error_empty; + public static String CompareWithOther_clear; + public static String CompareWithOther_warning_two_way; + public static String CompareWithOther_info; 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 5025827f9..060dc661d 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 @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource +# Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959 ############################################################################### ComparePlugin_internal_error= Internal Error @@ -119,3 +120,15 @@ SelectAncestorDialog_title=Select Common Ancestor SelectAncestorDialog_message=Which resource would you like to use as the common ancestor in the three-way compare? SelectAncestorDialog_option=''{0}'' ShowWhitespaceAction_0=Show &Whitespace Characters + +CompareWithOther_fileLabel=File: +CompareWithOther_ancestor=Ancestor +CompareWithOther_rightPanel=Right +CompareWithOther_leftPanel=Left +CompareWithOther_dialogTitle=Compare with Other Resource +CompareWithOther_dialogMessage=Select resources to compare +CompareWithOther_error_not_comparable=Selected resources are not comparable. +CompareWithOther_error_empty=Both left and right panel must contain a valid path. +CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed. +CompareWithOther_clear=Clear +CompareWithOther_info=Drag files from a view or between dialog's fields. diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java new file mode 100644 index 000000000..e0c74cf8f --- /dev/null +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008 Aleksandra Wozniak 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: + * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial API and implementation + *******************************************************************************/ +package org.eclipse.compare.internal; + +import org.eclipse.jface.viewers.ISelection; + +/** + * The "Compare with other resource" action + * + * @since 3.4 + */ +public class CompareWithOtherResourceAction extends CompareAction { + + public void run(ISelection selection) { + // Show CompareWithOtherResourceDialog which return resources to compare + // and ancestor if specified. Don't need to display the other dialog + showSelectAncestorDialog = false; + super.run(selection); + } + + protected boolean isEnabled(ISelection selection) { + // ignore returned value + super.isEnabled(selection); + return true; + } + +} diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java new file mode 100644 index 000000000..cdfea56c3 --- /dev/null +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java @@ -0,0 +1,481 @@ +/******************************************************************************* + * Copyright (c) 2008 Aleksandra Wozniak 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: + * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial API and implementation + *******************************************************************************/ +package org.eclipse.compare.internal; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.DropTargetListener; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.part.ResourceTransfer; + +/** + * This is a dialog that can invoke the compare editor on chosen files. + * + * @since 3.4 + */ +public class CompareWithOtherResourceDialog extends TitleAreaDialog { + + private int CLEAR_RETURN_CODE = 150; // any number != 0 + private int MIN_WIDTH = 300; + private int MIN_HEIGHT = 175; + + private class FileTextDragListener implements DragSourceListener { + + private InternalSection section; + + public FileTextDragListener(InternalSection section) { + this.section = section; + } + + public void dragFinished(DragSourceEvent event) { + section.fileText.setText(""); //$NON-NLS-1$ + } + + public void dragSetData(DragSourceEvent event) { + if (TextTransfer.getInstance().isSupportedType(event.dataType)) { + event.data = section.fileText.getText(); + } else + event.data = section.fileText.getText(); + } + + public void dragStart(DragSourceEvent event) { + if (section.fileText.getText() == null) + event.doit = false; + } + } + + private class FileTextDropListener implements DropTargetListener { + + private InternalSection section; + private ResourceTransfer resourceTransfer; + private TextTransfer textTransfer; + + public FileTextDropListener(InternalSection section) { + this.section = section; + resourceTransfer = ResourceTransfer.getInstance(); + textTransfer = TextTransfer.getInstance(); + } + + public void dragEnter(DropTargetEvent event) { + + if (event.detail == DND.DROP_DEFAULT) { + if ((event.operations & DND.DROP_COPY) != 0) + event.detail = DND.DROP_COPY; + else + event.detail = DND.DROP_NONE; + } + + for (int i = 0; i < event.dataTypes.length; i++) { + if (resourceTransfer.isSupportedType(event.dataTypes[i]) + || textTransfer.isSupportedType(event.dataTypes[i])) { + event.currentDataType = event.dataTypes[i]; + if (event.detail != DND.DROP_COPY) + event.detail = DND.DROP_NONE; + break; + } + } + } + + public void dragLeave(DropTargetEvent event) { + // intentionally empty + } + + public void dragOperationChanged(DropTargetEvent event) { + + if (event.detail == DND.DROP_DEFAULT) { + if ((event.operations & DND.DROP_COPY) != 0) + event.detail = DND.DROP_COPY; + else + event.detail = DND.DROP_NONE; + } else if (resourceTransfer.isSupportedType(event.currentDataType)) { + if (event.detail != DND.DROP_COPY) + event.detail = DND.DROP_NONE; + } + } + + public void dragOver(DropTargetEvent event) { + // intentionally empty + } + + public void drop(DropTargetEvent event) { + + if (textTransfer.isSupportedType(event.currentDataType)) { + String txt = (String) event.data; + section.setResource(ResourcesPlugin.getWorkspace().getRoot() + .findMember(txt)); + } else if (resourceTransfer.isSupportedType(event.currentDataType)) { + IResource[] files = (IResource[]) event.data; + section.setResource(files[0]); + } + + updateErrorInfo(); + } + + public void dropAccept(DropTargetEvent event) { + // intentionally empty + } + + } + + private abstract class InternalSection { + + protected Group group; + protected Text fileText; + private IResource resource; + + public InternalSection(Composite parent) { + createContents(parent); + } + + private InternalSection() { + // not to instantiate + } + + public void createContents(Composite parent) { + createGroup(parent); + createFileLabel(); + createFileCombo(); + initDrag(); + initDrop(); + } + + public IResource getResource() { + return resource; + } + + public void setResource(IResource resource) { + this.resource = resource; + String txt = resource.getFullPath().toString(); + fileText.setText(txt); + } + + public void setResource(String s) { + IResource tmp = ResourcesPlugin.getWorkspace().getRoot() + .findMember(s); + if (tmp instanceof IWorkspaceRoot) + resource = null; + else + resource = tmp; + + } + + protected void clearResource() { + resource = null; + fileText.setText(""); //$NON-NLS-1$ + updateErrorInfo(); + } + + protected void initDrag() { + DragSource source = new DragSource(fileText, DND.DROP_MOVE + | DND.DROP_COPY | DND.DROP_DEFAULT); + Transfer[] types = new Transfer[] { TextTransfer.getInstance(), + ResourceTransfer.getInstance() }; + source.setTransfer(types); + source.addDragListener(new FileTextDragListener(this)); + } + + protected void initDrop() { + DropTarget target = new DropTarget(fileText, DND.DROP_MOVE + | DND.DROP_COPY | DND.DROP_DEFAULT); + Transfer[] types = new Transfer[] { TextTransfer.getInstance(), + ResourceTransfer.getInstance() }; + target.setTransfer(types); + target.addDropListener(new FileTextDropListener(this)); + } + + protected void createGroup(Composite parent) { + group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout(3, false)); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + } + + protected void createFileCombo() { + fileText = new Text(group, SWT.BORDER); + fileText + .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + fileText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + setResource(fileText.getText()); + updateErrorInfo(); + } + }); + + fileText.addSelectionListener(new SelectionListener() { + + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) { + setResource(fileText.getText()); + updateErrorInfo(); + } + + }); + } + + protected void createFileLabel() { + final Label fileLabel = new Label(group, SWT.NONE); + fileLabel.setText(CompareMessages.CompareWithOther_fileLabel); + } + } + + private class InternalGroup extends InternalSection { + + public InternalGroup(Composite parent) { + createContents(parent); + } + + public void setText(String text) { + group.setText(text); + } + + public void setLayoutData(GridData layoutData) { + group.setLayoutData(layoutData); + } + } + + private class InternalExpandable extends InternalSection { + + private ExpandableComposite expandable; + private Button clearButton; + + public InternalExpandable(Composite parent) { + createContents(parent); + } + + public void createContents(Composite parent) { + createGroup(parent); + createFileLabel(); + createFileCombo(); + createClearButton(group); + initDrag(); + initDrop(); + } + + public void createGroup(Composite parent) { + final Composite p = parent; + expandable = new ExpandableComposite(parent, SWT.NONE, + ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE); + super.createGroup(expandable); + expandable.setClient(group); + expandable.addExpansionListener(new ExpansionAdapter() { + public void expansionStateChanged(ExpansionEvent e) { + p.layout(); + } + }); + } + + protected void createClearButton(Composite parent) { + clearButton = createButton(parent, CLEAR_RETURN_CODE, + CompareMessages.CompareWithOther_clear, false); + clearButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) { + clearResource(); + } + }); + } + + public void setText(String text) { + expandable.setText(text); + group.setText(text); + } + + public void setLayoutData(GridData layoutData) { + expandable.setLayoutData(layoutData); + } + } + + private Button okButton; + private InternalGroup rightPanel, leftPanel; + private InternalExpandable ancestorPanel; + private ISelection fselection; + + /** + * Creates the dialog. + * + * @param shell + * a shell + * @param selection + * if the selection is not null, it will be set as initial files + * for comparison + * @since 3.4 + */ + protected CompareWithOtherResourceDialog(Shell shell, ISelection selection) { + super(shell); + setShellStyle(SWT.MODELESS | SWT.RESIZE | SWT.MAX); + fselection = selection; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets + * .Composite) + */ + protected Control createDialogArea(Composite parent) { + + Composite mainPanel = new Composite(parent, SWT.NULL); + mainPanel.setLayout(new GridLayout(2, true)); + mainPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + ancestorPanel = new InternalExpandable(mainPanel); + ancestorPanel.setText(CompareMessages.CompareWithOther_ancestor); + GridData ancestorGD = new GridData(SWT.FILL, SWT.FILL, true, false); + ancestorGD.horizontalSpan = 2; + ancestorPanel.setLayoutData(ancestorGD); + + leftPanel = new InternalGroup(mainPanel); + leftPanel.setText(CompareMessages.CompareWithOther_leftPanel); + leftPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + rightPanel = new InternalGroup(mainPanel); + rightPanel.setText(CompareMessages.CompareWithOther_rightPanel); + rightPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + setSelection(fselection); + getShell().setText(CompareMessages.CompareWithOther_dialogTitle); + setTitle(CompareMessages.CompareWithOther_dialogMessage); + getShell().setMinimumSize(convertHorizontalDLUsToPixels(MIN_WIDTH), + convertVerticalDLUsToPixels(MIN_HEIGHT)); + + return mainPanel; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse + * .swt.widgets.Composite) + */ + protected void createButtonsForButtonBar(Composite parent) { + super.createButtonsForButtonBar(parent); + okButton = getButton(IDialogConstants.OK_ID); + updateErrorInfo(); + setMessage(CompareMessages.CompareWithOther_info); + } + + private void setSelection(ISelection selection) { + IResource[] selectedResources = Utilities.getResources(selection); + switch (selectedResources.length) { + case 1: + leftPanel.setResource(selectedResources[0]); + break; + case 2: + leftPanel.setResource(selectedResources[0]); + rightPanel.setResource(selectedResources[1]); + break; + case 3: + ancestorPanel.setResource(selectedResources[0]); + ancestorPanel.expandable.setExpanded(true); + leftPanel.setResource(selectedResources[1]); + rightPanel.setResource(selectedResources[2]); + break; + } + } + + private boolean isComparePossible() { + IResource[] resources; + if (ancestorPanel.getResource() == null) { + resources = new IResource[] { leftPanel.getResource(), + rightPanel.getResource() }; + } else { + resources = new IResource[] { ancestorPanel.getResource(), + leftPanel.getResource(), rightPanel.getResource() }; + } + + ResourceCompareInput r = new ResourceCompareInput( + new CompareConfiguration()); + return r.isEnabled(new StructuredSelection(resources)); + } + + private void updateErrorInfo() { + if (okButton != null) { + if (leftPanel.getResource() == null + || rightPanel.getResource() == null) { + setMessage(CompareMessages.CompareWithOther_error_empty, + IMessageProvider.ERROR); + okButton.setEnabled(false); + } else if (ancestorPanel.getResource() == null + && ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$ + setMessage(CompareMessages.CompareWithOther_warning_two_way, + IMessageProvider.WARNING); + } else if (!isComparePossible()) { + setMessage( + CompareMessages.CompareWithOther_error_not_comparable, + IMessageProvider.ERROR); + okButton.setEnabled(false); + } else { + setMessage(CompareMessages.CompareWithOther_info); + okButton.setEnabled(true); + } + } + } + + /** + * Returns table with selected resources. If any resource wasn't chosen in + * the ancestor panel, table has only two elements -- resources chosen in + * left and right panel. In the other case table contains all three + * resources. + * + * @return table with selected resources + */ + public IResource[] getResult() { + IResource[] resources; + IResource rightResource = rightPanel.getResource(); + IResource leftResource = leftPanel.getResource(); + IResource ancestorResource = ancestorPanel.getResource(); + if (ancestorResource == null) + resources = new IResource[] { leftResource, rightResource }; + else + resources = new IResource[] { ancestorResource, leftResource, + rightResource }; + return resources; + } +} diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java index fcacd04f4..1ab061f11 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource + * Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959 *******************************************************************************/ package org.eclipse.compare.internal; @@ -196,12 +197,16 @@ class ResourceCompareInput extends CompareEditorInput { } }; } - // If the compare is three-way, this method asks the user which resource - // to use as the ancestor. Returns false if the user cancels the prompt, + // to use as the ancestor. Depending on the value of + // showSelectAncestorDialog flag it uses different dialogs to get the + // feedback from the user. Returns false if the user cancels the prompt, // true otherwise. - boolean setSelection(ISelection s, Shell shell) { - + boolean setSelection(ISelection s, Shell shell, boolean showSelectAncestorDialog) { + + if (!showSelectAncestorDialog) + return showCompareWithOtherResourceDialog(shell, s); + IResource[] selection= Utilities.getResources(s); fThreeWay= selection.length == 3; @@ -223,12 +228,43 @@ class ResourceCompareInput extends CompareEditorInput { fLeftResource= selection[0]; fRightResource= selection[1]; } + fLeft= getStructure(fLeftResource); + fRight= getStructure(fRightResource); + return true; + } + + private boolean showCompareWithOtherResourceDialog(Shell shell, ISelection s) { + CompareWithOtherResourceDialog dialog = new CompareWithOtherResourceDialog(shell, s); + if (dialog.open() != IDialogConstants.OK_ID) + return false; + IResource[] selection = dialog.getResult(); + if (!checkSelection(selection)) + return false; + fThreeWay = selection.length == 3; + if (fThreeWay) { + fAncestorResource = selection[0]; + fAncestor = getStructure(fAncestorResource); + fLeftResource = selection[1]; + fRightResource = selection[2]; + } else { + fAncestorResource = null; + fAncestor = null; + fLeftResource = selection[0]; + fRightResource = selection[1]; + } fLeft= getStructure(fLeftResource); fRight= getStructure(fRightResource); return true; } - + + private boolean checkSelection(IResource[] resources) { + for (int i = 0; i < resources.length; i++) + if (resources[i] == null) + return false; + return true; + } + /* * Returns true if compare can be executed for the given selection. */ 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 c00338667..9cb5a37cd 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties @@ -83,6 +83,9 @@ CompareWithMenu.label= Comp&are With CompareWithEachOtherAction.label= &Each Other CompareWithEachOtherAction.tooltip= Compare the Selected Resources +CompareWithOtherResource.label= &Other Resource... +CompareWithOtherResource.tooltip= Open the 'Compare With' Dialog + CompareWithHistoryAction.label= &Local History... CompareWithHistoryAction.tooltip= Compare the Selected Resource with Local History 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 0a0ab38ca..91c8be4d0 100644 --- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml +++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml @@ -201,6 +201,14 @@ enablesFor="2+" id="compareWithEachOther"> </action> + <action + class="org.eclipse.compare.internal.CompareWithOtherResourceAction" + enablesFor="+" + id="compareWithOtherResource" + label="%CompareWithOtherResource.label" + menubarPath="compareWithMenu/compareWithGroup" + tooltip="%CompareWithOtherResourceAction.tooltip"> + </action> </objectContribution> <objectContribution objectClass="org.eclipse.core.resources.IFile" |