diff options
author | Remi Schnekenburger | 2015-10-27 13:47:25 +0000 |
---|---|---|
committer | Remi Schnekenburger | 2015-10-27 13:47:25 +0000 |
commit | b06cef0b9417f03a4d5a389c314f432f2d9b9e34 (patch) | |
tree | 44b2c70f86e3115d83ca6fe80ff66369cfa8a889 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands | |
parent | 308666baced83ced2447c2cdf7cce54b6b7192e3 (diff) | |
download | org.eclipse.papyrus-b06cef0b9417f03a4d5a389c314f432f2d9b9e34.tar.gz org.eclipse.papyrus-b06cef0b9417f03a4d5a389c314f432f2d9b9e34.tar.xz org.eclipse.papyrus-b06cef0b9417f03a4d5a389c314f432f2d9b9e34.zip |
revert commit affc638f030129e887837f8594f43a5edb540807 (2500+ test
failing)
Change-Id: Id950d8beb6eb60c0f17dc223a2cd9a27e0bd93cd
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands')
-rw-r--r-- | plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java | 134 |
1 files changed, 59 insertions, 75 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java index 12b463c5622..cdd7a64ee2f 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java @@ -1,75 +1,59 @@ -/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
-import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-
-/**
- * A replacement for CreateCommand that avoids that takes into account the incorrect
- * generation of ViewProvider by GMFTooling and modifies SemanticAdapter in call to {@link ViewService#provides(Class, org.eclipse.core.runtime.IAdaptable, View, String, int, boolean, org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint)} .
- */
-public class CreateViewCommand extends CreateCommand {
-
- /** Constructor */
- public CreateViewCommand(TransactionalEditingDomain editingDomain, ViewDescriptor viewDescriptor, View containerView) {
- super(editingDomain, viewDescriptor, containerView);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean canExecute() {
-
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=450921
- // it should be possible to create not only elements with semantic
- // like oval or note
- int hint;
- try {
- hint = Integer.parseInt(viewDescriptor.getSemanticHint());
- } catch(Exception e) {
- hint = -1;
- }
-
- if (hint == -1) {
- return super.canExecute();
- }
-
- // Warning the element adapter can possibly be null (see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=353129)
- if (viewDescriptor.getElementAdapter() == null) {
- return false;
- }
-
- // Try to adapt the descriptor ElementAdapter in EObject
- EObject element = EMFHelper.getEObject(viewDescriptor.getElementAdapter());
- IElementType elementType = (IElementType) viewDescriptor.getElementAdapter().getAdapter(IElementType.class);
-
- SemanticElementAdapter semanticAdapter = new SemanticElementAdapter(element, elementType);
-
- // Use the semanticAdapter instead of view descriptor element adapter to avoid the use of provides(ViewForKind) method
- // from ViewProvider which is incorrectly implemented in GMF Tooling generated editors (other editors may have undesired side-effect on each-other).
-
- return ViewService.getInstance().provides(viewDescriptor.getViewKind(), semanticAdapter, containerView, viewDescriptor.getSemanticHint(), viewDescriptor.getIndex(), viewDescriptor.isPersisted(), viewDescriptor.getPreferencesHint());
- }
-
-
-
-}
+/***************************************************************************** + * Copyright (c) 2011 CEA LIST. + * + * 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: + * + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.gmfdiag.common.commands; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.diagram.core.services.ViewService; +import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.notation.View; + +/** + * A replacement for CreateCommand that avoids that takes into account the incorrect + * generation of ViewProvider by GMFTooling and modifies SemanticAdapter in call to {@link ViewService#provides(Class, org.eclipse.core.runtime.IAdaptable, View, String, int, boolean, org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint)} . + */ +public class CreateViewCommand extends CreateCommand { + + /** Constructor */ + public CreateViewCommand(TransactionalEditingDomain editingDomain, ViewDescriptor viewDescriptor, View containerView) { + super(editingDomain, viewDescriptor, containerView); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean canExecute() { + // Warning the element adapter can possibly be null (see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=353129) + if (viewDescriptor.getElementAdapter() == null) { + return false; + } + + // Try to adapt the descriptor ElementAdapter in EObject + EObject element = EMFHelper.getEObject(viewDescriptor.getElementAdapter()); + IElementType elementType = (IElementType) viewDescriptor.getElementAdapter().getAdapter(IElementType.class); + + SemanticElementAdapter semanticAdapter = new SemanticElementAdapter(element, elementType); + + // Use the semanticAdapter instead of view descriptor element adapter to avoid the use of provides(ViewForKind) method + // from ViewProvider which is incorrectly implemented in GMF Tooling generated editors (other editors may have undesired side-effect on each-other). + + return ViewService.getInstance().provides(viewDescriptor.getViewKind(), semanticAdapter, containerView, viewDescriptor.getSemanticHint(), viewDescriptor.getIndex(), viewDescriptor.isPersisted(), viewDescriptor.getPreferencesHint()); + } + + + +} |