diff options
author | atischenko | 2015-10-27 18:43:26 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-11-18 16:05:50 +0000 |
commit | b58b6686a9c25fbe5c267edf0288023939cbaf21 (patch) | |
tree | 8e27f85db1dc8d7064752fd2eb911030e9c479e6 | |
parent | 4a9d209a3001bd1e5cb4ee981bfcbf5d4df97940 (diff) | |
download | org.eclipse.papyrus-b58b6686a9c25fbe5c267edf0288023939cbaf21.tar.gz org.eclipse.papyrus-b58b6686a9c25fbe5c267edf0288023939cbaf21.tar.xz org.eclipse.papyrus-b58b6686a9c25fbe5c267edf0288023939cbaf21.zip |
Bug 450921 - Additional graphics no longer available
- fix abstract sysml view provider
- add test
Conflicts:
plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateViewCommand.java
Change-Id: I00b16dc621f59db4c4980ffc90df32272a60b5a7
Signed-off-by: atischenko <tischenko@montages.com>
5 files changed, 151 insertions, 63 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 23621256dd4..42ad02653d6 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,61 +1,61 @@ -/*****************************************************************************
- * 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() {
-
- // 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.core.runtime.IAdaptable; +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() { + IAdaptable semanticAdapter = null; + + if (viewDescriptor.getElementAdapter() != null) { + // Try to adapt the descriptor ElementAdapter in EObject + EObject element = EMFHelper.getEObject(viewDescriptor.getElementAdapter()); + IElementType elementType = (IElementType) viewDescriptor.getElementAdapter().getAdapter(IElementType.class); + 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). + } + + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=450921 + // it should be still possible to create elements without semantic if they have a view provider + // (like oval or note) + return ViewService.getInstance().provides(viewDescriptor.getViewKind(), semanticAdapter, containerView, viewDescriptor.getSemanticHint(), viewDescriptor.getIndex(), viewDescriptor.isPersisted(), viewDescriptor.getPreferencesHint()); + } + + + +} diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/provider/CustomAbstractViewProvider.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/provider/CustomAbstractViewProvider.java index 79374db59fa..8958a363c7e 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/provider/CustomAbstractViewProvider.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/provider/CustomAbstractViewProvider.java @@ -114,7 +114,7 @@ public abstract class CustomAbstractViewProvider extends AbstractViewProvider { if ((semanticHint != null) && (!"".equals(semanticHint))) { graphicalType = registry.getNodeGraphicalType(semanticHint, containerView.getType()); - } else { + } else if (semanticAdapter != null) { EObject domainElement = (EObject) semanticAdapter.getAdapter(EObject.class); if (domainElement != null) { diff --git a/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/providers/TestViewProvider_450921.java b/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/providers/TestViewProvider_450921.java new file mode 100644 index 00000000000..0576be45daa --- /dev/null +++ b/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/providers/TestViewProvider_450921.java @@ -0,0 +1,62 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.sysml.diagram.blockdefinition.tests.providers; + +import org.junit.Assert; + +import org.eclipse.gmf.runtime.common.core.service.IOperation; +import org.eclipse.gmf.runtime.diagram.core.services.view.CreateNodeViewOperation; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.CustomViewProvider; +import org.eclipse.papyrus.sysml.diagram.blockdefinition.tests.AbstractTest; +import org.eclipse.papyrus.sysml.diagram.blockdefinition.tests.utils.EditorUtils; +import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes; +import org.junit.Before; +import org.junit.Test; + +/** + * Proposed fix for #450921 allows null semantic adapters to be passed to papyrus ViewProvider's. + * (Before the patch, all null semantic adapters were filtered by the CreateViewCommand). + * This test verifies that the sysml view providers do not fail facing now allowed null adapters. + */ +public class TestViewProvider_450921 extends AbstractTest { + + protected CustomViewProvider provider; + + protected View diagram; + + @Before + public void setUp() throws Exception { + provider = new CustomViewProvider(); + diagram = EditorUtils.getDiagramView(); + } + + @Test + public void testNullSemanticAdapter() throws Exception { + IOperation o = new CreateNodeViewOperation(null, diagram, SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_CLASSIFIER_ID, -1, false, EditorUtils.getDiagramEditPart().getDiagramPreferencesHint()); + Assert.assertTrue("Provider should provide node while semantic adapter null", provider.provides(o)); + } + + @Test + public void testNullSemanticAdapterAndEmptyHint() throws Exception { + IOperation o = new CreateNodeViewOperation(null, diagram, "", -1, false, EditorUtils.getDiagramEditPart().getDiagramPreferencesHint()); + Assert.assertFalse("Provider should not provide undefined element", provider.provides(o)); + } + + @Test + public void testNullSemanticAdapterAndDabHint() throws Exception { + IOperation o = new CreateNodeViewOperation(null, diagram, "Bad hint", -1, false, EditorUtils.getDiagramEditPart().getDiagramPreferencesHint()); + Assert.assertFalse("Provider should not provide undefined element", provider.provides(o)); + } +} diff --git a/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/suites/AllProviderTests.java b/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/suites/AllProviderTests.java new file mode 100644 index 00000000000..8876e13eb64 --- /dev/null +++ b/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/suites/AllProviderTests.java @@ -0,0 +1,25 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.sysml.diagram.blockdefinition.tests.suites; + +import org.eclipse.papyrus.sysml.diagram.blockdefinition.tests.providers.TestViewProvider_450921; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ TestViewProvider_450921.class }) +public class AllProviderTests { + +} diff --git a/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/suites/AllTests.java b/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/suites/AllTests.java index 9bea47a9eca..5ff175507e4 100644 --- a/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/suites/AllTests.java +++ b/tests/junit/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition.tests/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/tests/suites/AllTests.java @@ -33,7 +33,8 @@ import org.junit.runners.Suite.SuiteClasses; AllDnDLinkTests.class,
AllDeletionTests.class,
AllUtilsTests.class,
- AllCanonicalTests.class
+ AllCanonicalTests.class,
+ AllProviderTests.class
})
public class AllTests {
|