Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Richard2013-07-25 11:59:36 +0000
committerMikaƫl Barbero2013-08-19 12:28:55 +0000
commitc648e68f9b8d2877f83ee4ac1f45b2b4ba48eb9f (patch)
tree24488b022b45c0a31860e350b79a1c4c8e8a9589
parentb7b0e9e562817b02fed04d37657a744f2797ceed (diff)
downloadorg.eclipse.emf.compare-c648e68f9b8d2877f83ee4ac1f45b2b4ba48eb9f.tar.gz
org.eclipse.emf.compare-c648e68f9b8d2877f83ee4ac1f45b2b4ba48eb9f.tar.xz
org.eclipse.emf.compare-c648e68f9b8d2877f83ee4ac1f45b2b4ba48eb9f.zip
[411663] Prevent comparison between an object and one of its container.
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInDialog.java171
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInNewEditor.java172
2 files changed, 182 insertions, 161 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInDialog.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInDialog.java
index 839b20eb4..15fb344d5 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInDialog.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInDialog.java
@@ -1,80 +1,91 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.handler;
-
-import java.util.Iterator;
-
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.CompareUI;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class CompareInDialog extends AbstractCompareHandler {
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- AdapterFactory adapterFactory = new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
-
- final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
- final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
-
- if (currentSelection instanceof IStructuredSelection) {
- Iterator<?> iterator = ((IStructuredSelection)currentSelection).iterator();
- Notifier left = null;
- Notifier right = null;
- Notifier origin = null;
-
- left = (Notifier)iterator.next();
- if (iterator.hasNext()) {
- right = (Notifier)iterator.next();
- }
- if (iterator.hasNext()) {
- origin = (Notifier)iterator.next();
- }
-
- if (origin != null) {
- Shell shell = HandlerUtil.getActiveShell(event);
- SelectAncestorDialog dialog = new SelectAncestorDialog(shell, adapterFactory, new Notifier[] {
- left, right, origin });
- if (dialog.open() == Window.CANCEL) {
- return null;
- } else {
- left = dialog.leftNotifier;
- right = dialog.rightNotifier;
- origin = dialog.originNotifier;
- }
- }
-
- final CompareEditorInput input = createCompareEditorInput(activePart, adapterFactory, left,
- right, origin);
- CompareUI.openCompareDialog(input);
- }
-
- return null; // Reserved for future use, MUST be null.
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.internal.handler;
+
+import java.util.Iterator;
+
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.CompareUI;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class CompareInDialog extends AbstractCompareHandler {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ AdapterFactory adapterFactory = new ComposedAdapterFactory(
+ ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+
+ final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+
+ if (currentSelection instanceof IStructuredSelection) {
+ Iterator<?> iterator = ((IStructuredSelection)currentSelection).iterator();
+ Notifier left = null;
+ Notifier right = null;
+ Notifier origin = null;
+
+ left = (Notifier)iterator.next();
+ if (iterator.hasNext()) {
+ right = (Notifier)iterator.next();
+ }
+ if (iterator.hasNext()) {
+ origin = (Notifier)iterator.next();
+ }
+
+ if (origin != null) {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ SelectAncestorDialog dialog = new SelectAncestorDialog(shell, adapterFactory, new Notifier[] {
+ left, right, origin });
+ if (dialog.open() == Window.CANCEL) {
+ return null;
+ } else {
+ left = dialog.leftNotifier;
+ right = dialog.rightNotifier;
+ origin = dialog.originNotifier;
+ }
+ }
+
+ if (left instanceof EObject
+ && right instanceof EObject
+ && (EcoreUtil.isAncestor((EObject)left, (EObject)right) || EcoreUtil.isAncestor(
+ (EObject)right, (EObject)left))) {
+ MessageDialog.openInformation(activePart.getSite().getShell(), "EMF Compare",
+ "Can't run a comparison between an object and one of its ancestor.");
+ } else {
+ final CompareEditorInput input = createCompareEditorInput(activePart, adapterFactory, left,
+ right, origin);
+ CompareUI.openCompareDialog(input);
+ }
+ }
+
+ return null; // Reserved for future use, MUST be null.
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInNewEditor.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInNewEditor.java
index fdcd6d8e2..8a493aead 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInNewEditor.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/CompareInNewEditor.java
@@ -1,81 +1,91 @@
-/*******************************************************************************
- * Copyright (c) 2012 Obeo.
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.handler;
-
-import java.util.Iterator;
-
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.CompareUI;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
- */
-public class CompareInNewEditor extends AbstractCompareHandler {
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- AdapterFactory adapterFactory = new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
-
- final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
- final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
-
- if (currentSelection instanceof IStructuredSelection) {
- Iterator<?> iterator = ((IStructuredSelection)currentSelection).iterator();
- Notifier left = null;
- Notifier right = null;
- Notifier origin = null;
-
- left = (Notifier)iterator.next();
- if (iterator.hasNext()) {
- right = (Notifier)iterator.next();
- }
- if (iterator.hasNext()) {
- origin = (Notifier)iterator.next();
- }
-
- if (origin != null) {
- Shell shell = HandlerUtil.getActiveShell(event);
- SelectAncestorDialog dialog = new SelectAncestorDialog(shell, adapterFactory, new Notifier[] {
- left, right, origin });
- if (dialog.open() == Window.CANCEL) {
- return null;
- } else {
- left = dialog.leftNotifier;
- right = dialog.rightNotifier;
- origin = dialog.originNotifier;
- }
- }
-
- final CompareEditorInput input = createCompareEditorInput(activePart, adapterFactory, left,
- right, origin);
- CompareUI.openCompareEditor(input);
- }
-
- return null; // Reserved for future use, MUST be null.
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.internal.handler;
+
+import java.util.Iterator;
+
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.CompareUI;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class CompareInNewEditor extends AbstractCompareHandler {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ AdapterFactory adapterFactory = new ComposedAdapterFactory(
+ ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+
+ final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ final ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+
+ if (currentSelection instanceof IStructuredSelection) {
+ Iterator<?> iterator = ((IStructuredSelection)currentSelection).iterator();
+ Notifier left = null;
+ Notifier right = null;
+ Notifier origin = null;
+
+ left = (Notifier)iterator.next();
+ if (iterator.hasNext()) {
+ right = (Notifier)iterator.next();
+ }
+ if (iterator.hasNext()) {
+ origin = (Notifier)iterator.next();
+ }
+
+ if (origin != null) {
+ Shell shell = HandlerUtil.getActiveShell(event);
+ SelectAncestorDialog dialog = new SelectAncestorDialog(shell, adapterFactory, new Notifier[] {
+ left, right, origin });
+ if (dialog.open() == Window.CANCEL) {
+ return null;
+ } else {
+ left = dialog.leftNotifier;
+ right = dialog.rightNotifier;
+ origin = dialog.originNotifier;
+ }
+ }
+
+ if (left instanceof EObject
+ && right instanceof EObject
+ && (EcoreUtil.isAncestor((EObject)left, (EObject)right) || EcoreUtil.isAncestor(
+ (EObject)right, (EObject)left))) {
+ MessageDialog.openInformation(activePart.getSite().getShell(), "EMF Compare",
+ "Can't run a comparison between an object and one of its ancestor.");
+ } else {
+ final CompareEditorInput input = createCompareEditorInput(activePart, adapterFactory, left,
+ right, origin);
+ CompareUI.openCompareEditor(input);
+ }
+ }
+
+ return null; // Reserved for future use, MUST be null.
+ }
+}

Back to the top