diff options
author | atischenko | 2015-10-27 18:43:26 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-11-18 16:07:27 +0000 |
commit | e94966c15cb3959b8770c7800fad129ad8a8dab5 (patch) | |
tree | f90b0ee47de3b86862457f17e55ac72ce45d47f7 | |
parent | dba579d7d98e8549daf2cb2b8d7b889c09a6c679 (diff) | |
download | org.eclipse.papyrus-e94966c15cb3959b8770c7800fad129ad8a8dab5.tar.gz org.eclipse.papyrus-e94966c15cb3959b8770c7800fad129ad8a8dab5.tar.xz org.eclipse.papyrus-e94966c15cb3959b8770c7800fad129ad8a8dab5.zip |
Bug 450921 - Additional graphics no longer available
- fix abstract sysml view provider
- add test
Change-Id: Ic0117dc53a821b0d147891d74a2fd0e54cd4d173
Signed-off-by: atischenko <tischenko@montages.com>
5 files changed, 103 insertions, 14 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 c2c060482d0..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 @@ -13,6 +13,7 @@ *****************************************************************************/ 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; @@ -38,20 +39,20 @@ public class CreateViewCommand extends CreateCommand { */ @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; + 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). } - // Try to adapt the descriptor ElementAdapter in EObject - EObject element = EMFHelper.getEObject(viewDescriptor.getElementAdapter()); - IElementType elementType = 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). - + // 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 851baad77e1..15322eced0d 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 {
|