Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2008-07-10 10:57:09 +0000
committerTomasz Zarna2008-07-10 10:57:09 +0000
commit8f5fbae662ffbae1ddfd0dd2026741a57426e618 (patch)
tree272fd4a5a3515908ff33c2fe51747ca942c3c8de
parent53e1400e24fbc460dd8f6beed0081fee31459568 (diff)
downloadeclipse.platform.team-8f5fbae662ffbae1ddfd0dd2026741a57426e618.tar.gz
eclipse.platform.team-8f5fbae662ffbae1ddfd0dd2026741a57426e618.tar.xz
eclipse.platform.team-8f5fbae662ffbae1ddfd0dd2026741a57426e618.zip
NEW - bug 239959: Adding content to "Compare with other resource" dialog by drag&dropping
https://bugs.eclipse.org/bugs/show_bug.cgi?id=239959
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java37
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java10
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties11
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java46
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java514
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java36
-rw-r--r--bundles/org.eclipse.compare/plugin.properties3
-rw-r--r--bundles/org.eclipse.compare/plugin.xml8
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java37
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java10
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties11
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java46
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java514
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java36
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.properties3
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/plugin.xml8
16 files changed, 1290 insertions, 40 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java
index 839f003ae..598818fea 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java
@@ -19,6 +19,7 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareUI;
+import org.eclipse.core.resources.IResource;
/*
@@ -26,17 +27,31 @@ import org.eclipse.compare.CompareUI;
*/
public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
- private ResourceCompareInput fInput;
- private IWorkbenchPage fWorkbenchPage;
-
+ private static ResourceCompareInput fInput;
+ private static IWorkbenchPage fWorkbenchPage;
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());
- if (!ok) return;
+ boolean ok = fInput.setSelection(selection, fWorkbenchPage
+ .getWorkbenchWindow().getShell());
+ if (!ok)
+ return;
+ fInput.initializeCompareConfiguration();
+ CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
+ fInput = null; // don't reuse this input!
+ }
+ }
+
+ public static void run(IResource[] resources) {
+ fWorkbenchPage = CompareUIPlugin.getActiveWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ if (fInput != null) {
+ boolean ok = fInput.setSelection(resources, fWorkbenchPage
+ .getWorkbenchWindow().getShell());
+ if (!ok)
+ return;
fInput.initializeCompareConfiguration();
CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
fInput= null; // don't reuse this input!
@@ -58,6 +73,16 @@ public class CompareAction extends BaseCompareAction implements IObjectActionDel
return fInput.isEnabled(selection);
}
+ public static boolean isEnabled(IResource[] resources) {
+ if (fInput == null) {
+ CompareConfiguration cc = new CompareConfiguration();
+ cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(
+ false));
+ fInput = new ResourceCompareInput(cc);
+ }
+ return fInput.isEnabled(resources);
+ }
+
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
fWorkbenchPage= targetPart.getSite().getPage();
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
index 800ea1820..49c15408f 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
@@ -108,6 +108,16 @@ 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_clearAll;
+ public static String CompareWithOther_clear;
static {
NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
index 08a678b6a..b100020b5 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
@@ -119,3 +119,14 @@ 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 panel
+CompareWithOther_leftPanel=Left panel
+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 not be empty.
+CompareWithOther_clearAll=Clear All
+CompareWithOther_clear=Clear
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java
new file mode 100644
index 000000000..f48404afd
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The "Compare with other resource" action
+ * @since 3.4
+ */
+public class CompareWithOtherResourceAction implements IObjectActionDelegate {
+
+ Shell shell;
+ CompareWithOtherResourceDialog dialog;
+ private ISelection fselection;
+
+ public CompareWithOtherResourceAction() {
+ shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ public void run(IAction action) {
+ dialog = new CompareWithOtherResourceDialog(shell, fselection);
+ dialog.open();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ fselection = selection;
+ }
+
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
new file mode 100644
index 000000000..879926d3a
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
@@ -0,0 +1,514 @@
+/*******************************************************************************
+ * 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.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.
+ * <p>
+ * This class can be used as is or can be subclassed.
+ *
+ * @since 3.4
+ */
+public class CompareWithOtherResourceDialog extends TitleAreaDialog {
+
+ public int CLEAR_RETURN_CODE = 150; // any number != 0
+
+ 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();
+ }
+
+ 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])) {
+ event.currentDataType = event.dataTypes[i];
+ if (event.detail != DND.DROP_COPY)
+ event.detail = DND.DROP_NONE;
+ }
+ break;
+ }
+ }
+
+ public void dragLeave(DropTargetEvent event) {
+ }
+
+ 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;
+ }
+ if (resourceTransfer.isSupportedType(event.currentDataType)) {
+ if (event.detail != DND.DROP_COPY)
+ event.detail = DND.DROP_NONE;
+ }
+ }
+
+ public void dragOver(DropTargetEvent event) {
+ }
+
+ public void drop(DropTargetEvent event) {
+ if (textTransfer.isSupportedType(event.currentDataType)) {
+ String txt = (String) event.data;
+ section.fileText.setText(txt);
+ section.setResource(ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(txt));
+ }
+ if (resourceTransfer.isSupportedType(event.currentDataType)) {
+ IResource[] files = (IResource[]) event.data;
+ section.setResource(files[0]);
+ section.fileText.setText(section.getResource().getFullPath()
+ .toString());
+ }
+ }
+
+ public void dropAccept(DropTargetEvent event) {
+ }
+
+ }
+
+ private abstract class InternalSection {
+
+ protected Text fileText;
+ protected IResource resource;
+ protected IResource[] files;
+ protected String fileString = null;
+ protected Group group;
+ protected Button clearButton;
+
+ public InternalSection(Composite parent) {
+ createContents(parent);
+ }
+
+ public InternalSection() {
+ }
+
+ public void createContents(Composite parent) {
+ }
+
+ public IResource getResource() {
+ if (resource == null) {
+ if (fileString != null) { //$NON-NLS-1$
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
+ .getRoot();
+ resource = root.findMember(fileString);
+ if (resource instanceof IWorkspaceRoot)
+ return null;
+ return resource;
+ }
+ }
+ return resource;
+ }
+
+ public void setResource(IResource resource) {
+ this.resource = resource;
+ fileText.setText(resource.getFullPath().toString());
+ }
+
+ protected void clearResource() {
+ resource = null;
+ fileText.setText(""); //$NON-NLS-1$
+ }
+
+ protected void initDrag() {
+ DragSource source = new DragSource(fileText, DND.DROP_MOVE
+ | DND.DROP_COPY);
+ 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);
+ final TextTransfer textTransfer = TextTransfer.getInstance();
+ final ResourceTransfer resourceTransfer = ResourceTransfer
+ .getInstance();
+ Transfer[] types = new Transfer[] { textTransfer, resourceTransfer };
+ target.setTransfer(types);
+ target.addDropListener(new FileTextDropListener(this));
+ }
+
+ protected void createGroup(Composite parent) {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ group = new Group(parent, SWT.NONE);
+ group.setLayout(layout);
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ group.setLayoutData(gridData);
+ }
+
+ protected void createFileText() {
+ fileText = new Text(group, SWT.SINGLE | SWT.BORDER);
+ fileText.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ if (files != null)
+ resource = files[0];
+ fileString = fileText.getText();
+ if (fileString == "") //$NON-NLS-1$
+ resource = null;
+ else
+ resource = getResource();
+ if (okButton != null)
+ okButton.setEnabled(comparePossible());
+ updateErrorInfo();
+ }
+
+ });
+
+ GridData textData = new GridData();
+ textData.grabExcessHorizontalSpace = true;
+ textData.horizontalAlignment = SWT.FILL;
+ fileText.setLayoutData(textData);
+ }
+
+ protected void createFileLabel() {
+ final Label fileLabel = new Label(group, SWT.NONE);
+ fileLabel.setText(CompareMessages.CompareWithOther_fileLabel);
+ }
+
+ 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();
+ }
+
+ });
+ }
+
+ abstract public void setLayoutData(GridData layoutData);
+
+ abstract public void setText(String text);
+
+ }
+
+ private class InternalGroup extends InternalSection {
+
+ public InternalGroup(Composite parent) {
+ super();
+ createContents(parent);
+ }
+
+ public void createContents(Composite parent) {
+ createGroup(parent);
+ createFileLabel();
+ createFileText();
+ createClearButton(group);
+ initDrag();
+ initDrop();
+ }
+
+ public void setText(String text) {
+ group.setText(text);
+ }
+
+ public void setLayoutData(GridData layoutData) {
+ group.setLayoutData(layoutData);
+ }
+ }
+
+ private class InternalExpandable extends InternalSection {
+
+ private ExpandableComposite expandable;
+
+ public InternalExpandable(Composite parent) {
+ super();
+ createContents(parent);
+ }
+
+ public void createContents(Composite parent) {
+
+ final Composite p = parent;
+
+ expandable = new ExpandableComposite(parent, SWT.NONE,
+ ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
+
+ createGroup(expandable);
+ expandable.setClient(group);
+ expandable.addExpansionListener(new ExpansionAdapter() {
+ public void expansionStateChanged(ExpansionEvent e) {
+ p.getShell().pack();
+ }
+ });
+
+ createFileLabel();
+ createFileText();
+ createClearButton(group);
+ initDrag();
+ initDrop();
+ }
+
+ public void setText(String text) {
+ expandable.setText(text);
+ group.setText(text);
+ }
+
+ public void setLayoutData(GridData layoutData) {
+ expandable.setLayoutData(layoutData);
+ }
+
+ }
+
+ private Button okButton, cancelButton, clearAllButton;
+ 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);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.makeColumnsEqualWidth = true;
+ mainPanel.setLayout(layout);
+ 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, true);
+ ancestorGD.horizontalSpan = 2;
+ ancestorPanel.setLayoutData(ancestorGD);
+
+ rightPanel = new InternalGroup(mainPanel);
+ rightPanel.setText(CompareMessages.CompareWithOther_rightPanel);
+ GridData rightGD = new GridData(SWT.FILL, SWT.FILL, true, true);
+ rightPanel.setLayoutData(rightGD);
+
+ leftPanel = new InternalGroup(mainPanel);
+ leftPanel.setText(CompareMessages.CompareWithOther_leftPanel);
+ GridData leftGD = new GridData(SWT.FILL, SWT.FILL, true, true);
+ leftPanel.setLayoutData(leftGD);
+
+ setSelection(fselection);
+ getShell().setText(CompareMessages.CompareWithOther_dialogTitle);
+ setTitle(CompareMessages.CompareWithOther_dialogMessage);
+
+ return mainPanel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
+ * .swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ okButton = createButton(parent, OK, IDialogConstants.OK_LABEL, false);
+ okButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+
+ 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 };
+
+ if (CompareAction.isEnabled(resources))
+ CompareAction.run(resources);
+ }
+
+ });
+ okButton.setEnabled(comparePossible());
+
+ cancelButton = createButton(parent, CANCEL,
+ IDialogConstants.CANCEL_LABEL, true);
+ cancelButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ }
+
+ });
+
+ clearAllButton = createButton(parent, CLEAR_RETURN_CODE,
+ CompareMessages.CompareWithOther_clearAll, false);
+ clearAllButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ leftPanel.clearResource();
+ rightPanel.clearResource();
+ ancestorPanel.clearResource();
+ }
+
+ });
+ }
+
+ private void setSelection(ISelection selection) {
+ IResource[] selectedResources = Utilities.getResources(selection);
+ switch (selectedResources.length) {
+ case 0:
+ break;
+ 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 comparePossible() {
+ IResource[] resources;
+ if (ancestorPanel.resource == null)
+ resources = new IResource[] { leftPanel.resource,
+ rightPanel.resource };
+ else
+ resources = new IResource[] { ancestorPanel.resource,
+ leftPanel.resource, rightPanel.resource };
+
+ ResourceCompareInput r = new ResourceCompareInput(
+ new CompareConfiguration());
+ return r.isEnabled(resources);
+ }
+
+ private void updateErrorInfo() {
+ if (leftPanel.resource == null || rightPanel.resource == null)
+ setMessage(CompareMessages.CompareWithOther_error_empty,
+ IMessageProvider.ERROR);
+ else if (!comparePossible())
+ setMessage(CompareMessages.CompareWithOther_error_not_comparable,
+ IMessageProvider.ERROR);
+ else
+ setMessage(null);
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
index fcacd04f4..e534fa5a0 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
@@ -201,11 +201,14 @@ class ResourceCompareInput extends CompareEditorInput {
// to use as the ancestor. Returns false if the user cancels the prompt,
// true otherwise.
boolean setSelection(ISelection s, Shell shell) {
-
- IResource[] selection= Utilities.getResources(s);
+ IResource[] selection = Utilities.getResources(s);
+ return setSelection(selection, shell);
+ }
+
+ boolean setSelection(IResource[] selection, Shell shell) {
+
+ fThreeWay = selection.length == 3;
- fThreeWay= selection.length == 3;
-
if (fThreeWay) {
SelectAncestorDialog dialog =
new SelectAncestorDialog(shell, selection);
@@ -233,21 +236,26 @@ class ResourceCompareInput extends CompareEditorInput {
* Returns true if compare can be executed for the given selection.
*/
public boolean isEnabled(ISelection s) {
-
- IResource[] selection= Utilities.getResources(s);
- if (selection.length < 2 || selection.length > 3)
+
+ IResource[] selection = Utilities.getResources(s);
+ return isEnabled(selection);
+ }
+
+ public boolean isEnabled(IResource[] resources) {
+ if (resources.length < 2 || resources.length > 3)
return false;
- boolean threeWay= selection.length == 3;
+ boolean threeWay= resources.length == 3;
- if (threeWay)
+ if (threeWay) {
// It only makes sense if they're all mutually comparable.
// If not, the user should compare two of them.
- return comparable(selection[0], selection[1])
- && comparable(selection[0], selection[2])
- && comparable(selection[1], selection[2]);
-
- return comparable(selection[0], selection[1]);
+ return comparable(resources[0], resources[1])
+ && comparable(resources[0], resources[2])
+ && comparable(resources[1], resources[2]);
+ }
+
+ return comparable(resources[0], resources[1]);
}
/**
diff --git a/bundles/org.eclipse.compare/plugin.properties b/bundles/org.eclipse.compare/plugin.properties
index c00338667..be271000e 100644
--- a/bundles/org.eclipse.compare/plugin.properties
+++ b/bundles/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/plugin.xml b/bundles/org.eclipse.compare/plugin.xml
index 0a0ab38ca..c0b472075 100644
--- a/bundles/org.eclipse.compare/plugin.xml
+++ b/bundles/org.eclipse.compare/plugin.xml
@@ -201,6 +201,14 @@
enablesFor="2+"
id="compareWithEachOther">
</action>
+ <action
+ class="org.eclipse.compare.internal.CompareWithOtherResourceAction"
+ enablesFor="1"
+ id="compareWithOtherResource"
+ label="%CompareWithOtherResource.label"
+ menubarPath="compareWithMenu/compareWithGroup"
+ tooltip="%CompareWithOtherResourceAction.tooltip">
+ </action>
</objectContribution>
<objectContribution
objectClass="org.eclipse.core.resources.IFile"
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..598818fea 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
@@ -19,6 +19,7 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareUI;
+import org.eclipse.core.resources.IResource;
/*
@@ -26,17 +27,31 @@ import org.eclipse.compare.CompareUI;
*/
public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
- private ResourceCompareInput fInput;
- private IWorkbenchPage fWorkbenchPage;
-
+ private static ResourceCompareInput fInput;
+ private static IWorkbenchPage fWorkbenchPage;
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());
- if (!ok) return;
+ boolean ok = fInput.setSelection(selection, fWorkbenchPage
+ .getWorkbenchWindow().getShell());
+ if (!ok)
+ return;
+ fInput.initializeCompareConfiguration();
+ CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
+ fInput = null; // don't reuse this input!
+ }
+ }
+
+ public static void run(IResource[] resources) {
+ fWorkbenchPage = CompareUIPlugin.getActiveWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ if (fInput != null) {
+ boolean ok = fInput.setSelection(resources, fWorkbenchPage
+ .getWorkbenchWindow().getShell());
+ if (!ok)
+ return;
fInput.initializeCompareConfiguration();
CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
fInput= null; // don't reuse this input!
@@ -58,6 +73,16 @@ public class CompareAction extends BaseCompareAction implements IObjectActionDel
return fInput.isEnabled(selection);
}
+ public static boolean isEnabled(IResource[] resources) {
+ if (fInput == null) {
+ CompareConfiguration cc = new CompareConfiguration();
+ cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(
+ false));
+ fInput = new ResourceCompareInput(cc);
+ }
+ return fInput.isEnabled(resources);
+ }
+
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
fWorkbenchPage= targetPart.getSite().getPage();
}
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..49c15408f 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
@@ -108,6 +108,16 @@ 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_clearAll;
+ public static String CompareWithOther_clear;
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 08a678b6a..b100020b5 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
@@ -119,3 +119,14 @@ 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 panel
+CompareWithOther_leftPanel=Left panel
+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 not be empty.
+CompareWithOther_clearAll=Clear All
+CompareWithOther_clear=Clear
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..f48404afd
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The "Compare with other resource" action
+ * @since 3.4
+ */
+public class CompareWithOtherResourceAction implements IObjectActionDelegate {
+
+ Shell shell;
+ CompareWithOtherResourceDialog dialog;
+ private ISelection fselection;
+
+ public CompareWithOtherResourceAction() {
+ shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ public void run(IAction action) {
+ dialog = new CompareWithOtherResourceDialog(shell, fselection);
+ dialog.open();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ fselection = selection;
+ }
+
+}
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..879926d3a
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
@@ -0,0 +1,514 @@
+/*******************************************************************************
+ * 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.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.
+ * <p>
+ * This class can be used as is or can be subclassed.
+ *
+ * @since 3.4
+ */
+public class CompareWithOtherResourceDialog extends TitleAreaDialog {
+
+ public int CLEAR_RETURN_CODE = 150; // any number != 0
+
+ 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();
+ }
+
+ 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])) {
+ event.currentDataType = event.dataTypes[i];
+ if (event.detail != DND.DROP_COPY)
+ event.detail = DND.DROP_NONE;
+ }
+ break;
+ }
+ }
+
+ public void dragLeave(DropTargetEvent event) {
+ }
+
+ 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;
+ }
+ if (resourceTransfer.isSupportedType(event.currentDataType)) {
+ if (event.detail != DND.DROP_COPY)
+ event.detail = DND.DROP_NONE;
+ }
+ }
+
+ public void dragOver(DropTargetEvent event) {
+ }
+
+ public void drop(DropTargetEvent event) {
+ if (textTransfer.isSupportedType(event.currentDataType)) {
+ String txt = (String) event.data;
+ section.fileText.setText(txt);
+ section.setResource(ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(txt));
+ }
+ if (resourceTransfer.isSupportedType(event.currentDataType)) {
+ IResource[] files = (IResource[]) event.data;
+ section.setResource(files[0]);
+ section.fileText.setText(section.getResource().getFullPath()
+ .toString());
+ }
+ }
+
+ public void dropAccept(DropTargetEvent event) {
+ }
+
+ }
+
+ private abstract class InternalSection {
+
+ protected Text fileText;
+ protected IResource resource;
+ protected IResource[] files;
+ protected String fileString = null;
+ protected Group group;
+ protected Button clearButton;
+
+ public InternalSection(Composite parent) {
+ createContents(parent);
+ }
+
+ public InternalSection() {
+ }
+
+ public void createContents(Composite parent) {
+ }
+
+ public IResource getResource() {
+ if (resource == null) {
+ if (fileString != null) { //$NON-NLS-1$
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
+ .getRoot();
+ resource = root.findMember(fileString);
+ if (resource instanceof IWorkspaceRoot)
+ return null;
+ return resource;
+ }
+ }
+ return resource;
+ }
+
+ public void setResource(IResource resource) {
+ this.resource = resource;
+ fileText.setText(resource.getFullPath().toString());
+ }
+
+ protected void clearResource() {
+ resource = null;
+ fileText.setText(""); //$NON-NLS-1$
+ }
+
+ protected void initDrag() {
+ DragSource source = new DragSource(fileText, DND.DROP_MOVE
+ | DND.DROP_COPY);
+ 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);
+ final TextTransfer textTransfer = TextTransfer.getInstance();
+ final ResourceTransfer resourceTransfer = ResourceTransfer
+ .getInstance();
+ Transfer[] types = new Transfer[] { textTransfer, resourceTransfer };
+ target.setTransfer(types);
+ target.addDropListener(new FileTextDropListener(this));
+ }
+
+ protected void createGroup(Composite parent) {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ group = new Group(parent, SWT.NONE);
+ group.setLayout(layout);
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ group.setLayoutData(gridData);
+ }
+
+ protected void createFileText() {
+ fileText = new Text(group, SWT.SINGLE | SWT.BORDER);
+ fileText.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ if (files != null)
+ resource = files[0];
+ fileString = fileText.getText();
+ if (fileString == "") //$NON-NLS-1$
+ resource = null;
+ else
+ resource = getResource();
+ if (okButton != null)
+ okButton.setEnabled(comparePossible());
+ updateErrorInfo();
+ }
+
+ });
+
+ GridData textData = new GridData();
+ textData.grabExcessHorizontalSpace = true;
+ textData.horizontalAlignment = SWT.FILL;
+ fileText.setLayoutData(textData);
+ }
+
+ protected void createFileLabel() {
+ final Label fileLabel = new Label(group, SWT.NONE);
+ fileLabel.setText(CompareMessages.CompareWithOther_fileLabel);
+ }
+
+ 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();
+ }
+
+ });
+ }
+
+ abstract public void setLayoutData(GridData layoutData);
+
+ abstract public void setText(String text);
+
+ }
+
+ private class InternalGroup extends InternalSection {
+
+ public InternalGroup(Composite parent) {
+ super();
+ createContents(parent);
+ }
+
+ public void createContents(Composite parent) {
+ createGroup(parent);
+ createFileLabel();
+ createFileText();
+ createClearButton(group);
+ initDrag();
+ initDrop();
+ }
+
+ public void setText(String text) {
+ group.setText(text);
+ }
+
+ public void setLayoutData(GridData layoutData) {
+ group.setLayoutData(layoutData);
+ }
+ }
+
+ private class InternalExpandable extends InternalSection {
+
+ private ExpandableComposite expandable;
+
+ public InternalExpandable(Composite parent) {
+ super();
+ createContents(parent);
+ }
+
+ public void createContents(Composite parent) {
+
+ final Composite p = parent;
+
+ expandable = new ExpandableComposite(parent, SWT.NONE,
+ ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
+
+ createGroup(expandable);
+ expandable.setClient(group);
+ expandable.addExpansionListener(new ExpansionAdapter() {
+ public void expansionStateChanged(ExpansionEvent e) {
+ p.getShell().pack();
+ }
+ });
+
+ createFileLabel();
+ createFileText();
+ createClearButton(group);
+ initDrag();
+ initDrop();
+ }
+
+ public void setText(String text) {
+ expandable.setText(text);
+ group.setText(text);
+ }
+
+ public void setLayoutData(GridData layoutData) {
+ expandable.setLayoutData(layoutData);
+ }
+
+ }
+
+ private Button okButton, cancelButton, clearAllButton;
+ 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);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.makeColumnsEqualWidth = true;
+ mainPanel.setLayout(layout);
+ 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, true);
+ ancestorGD.horizontalSpan = 2;
+ ancestorPanel.setLayoutData(ancestorGD);
+
+ rightPanel = new InternalGroup(mainPanel);
+ rightPanel.setText(CompareMessages.CompareWithOther_rightPanel);
+ GridData rightGD = new GridData(SWT.FILL, SWT.FILL, true, true);
+ rightPanel.setLayoutData(rightGD);
+
+ leftPanel = new InternalGroup(mainPanel);
+ leftPanel.setText(CompareMessages.CompareWithOther_leftPanel);
+ GridData leftGD = new GridData(SWT.FILL, SWT.FILL, true, true);
+ leftPanel.setLayoutData(leftGD);
+
+ setSelection(fselection);
+ getShell().setText(CompareMessages.CompareWithOther_dialogTitle);
+ setTitle(CompareMessages.CompareWithOther_dialogMessage);
+
+ return mainPanel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
+ * .swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar(Composite parent) {
+ okButton = createButton(parent, OK, IDialogConstants.OK_LABEL, false);
+ okButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+
+ 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 };
+
+ if (CompareAction.isEnabled(resources))
+ CompareAction.run(resources);
+ }
+
+ });
+ okButton.setEnabled(comparePossible());
+
+ cancelButton = createButton(parent, CANCEL,
+ IDialogConstants.CANCEL_LABEL, true);
+ cancelButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ }
+
+ });
+
+ clearAllButton = createButton(parent, CLEAR_RETURN_CODE,
+ CompareMessages.CompareWithOther_clearAll, false);
+ clearAllButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ leftPanel.clearResource();
+ rightPanel.clearResource();
+ ancestorPanel.clearResource();
+ }
+
+ });
+ }
+
+ private void setSelection(ISelection selection) {
+ IResource[] selectedResources = Utilities.getResources(selection);
+ switch (selectedResources.length) {
+ case 0:
+ break;
+ 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 comparePossible() {
+ IResource[] resources;
+ if (ancestorPanel.resource == null)
+ resources = new IResource[] { leftPanel.resource,
+ rightPanel.resource };
+ else
+ resources = new IResource[] { ancestorPanel.resource,
+ leftPanel.resource, rightPanel.resource };
+
+ ResourceCompareInput r = new ResourceCompareInput(
+ new CompareConfiguration());
+ return r.isEnabled(resources);
+ }
+
+ private void updateErrorInfo() {
+ if (leftPanel.resource == null || rightPanel.resource == null)
+ setMessage(CompareMessages.CompareWithOther_error_empty,
+ IMessageProvider.ERROR);
+ else if (!comparePossible())
+ setMessage(CompareMessages.CompareWithOther_error_not_comparable,
+ IMessageProvider.ERROR);
+ else
+ setMessage(null);
+ }
+}
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..e534fa5a0 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
@@ -201,11 +201,14 @@ class ResourceCompareInput extends CompareEditorInput {
// to use as the ancestor. Returns false if the user cancels the prompt,
// true otherwise.
boolean setSelection(ISelection s, Shell shell) {
-
- IResource[] selection= Utilities.getResources(s);
+ IResource[] selection = Utilities.getResources(s);
+ return setSelection(selection, shell);
+ }
+
+ boolean setSelection(IResource[] selection, Shell shell) {
+
+ fThreeWay = selection.length == 3;
- fThreeWay= selection.length == 3;
-
if (fThreeWay) {
SelectAncestorDialog dialog =
new SelectAncestorDialog(shell, selection);
@@ -233,21 +236,26 @@ class ResourceCompareInput extends CompareEditorInput {
* Returns true if compare can be executed for the given selection.
*/
public boolean isEnabled(ISelection s) {
-
- IResource[] selection= Utilities.getResources(s);
- if (selection.length < 2 || selection.length > 3)
+
+ IResource[] selection = Utilities.getResources(s);
+ return isEnabled(selection);
+ }
+
+ public boolean isEnabled(IResource[] resources) {
+ if (resources.length < 2 || resources.length > 3)
return false;
- boolean threeWay= selection.length == 3;
+ boolean threeWay= resources.length == 3;
- if (threeWay)
+ if (threeWay) {
// It only makes sense if they're all mutually comparable.
// If not, the user should compare two of them.
- return comparable(selection[0], selection[1])
- && comparable(selection[0], selection[2])
- && comparable(selection[1], selection[2]);
-
- return comparable(selection[0], selection[1]);
+ return comparable(resources[0], resources[1])
+ && comparable(resources[0], resources[2])
+ && comparable(resources[1], resources[2]);
+ }
+
+ return comparable(resources[0], resources[1]);
}
/**
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..be271000e 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..c0b472075 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="1"
+ id="compareWithOtherResource"
+ label="%CompareWithOtherResource.label"
+ menubarPath="compareWithMenu/compareWithGroup"
+ tooltip="%CompareWithOtherResourceAction.tooltip">
+ </action>
</objectContribution>
<objectContribution
objectClass="org.eclipse.core.resources.IFile"

Back to the top