diff options
| author | pguilet | 2017-02-09 13:45:37 +0000 |
|---|---|---|
| committer | Pierre Guilet | 2017-02-13 15:09:30 +0000 |
| commit | af595e47adb7716eec0217bd76fb1ac806c01728 (patch) | |
| tree | 710c8e45cc6438aa2b56d6eca3029f0c2efc738a | |
| parent | ad7959b30bbf91621e9ab7a42c5b59f86e43a83f (diff) | |
| download | org.eclipse.sirius-af595e47adb7716eec0217bd76fb1ac806c01728.tar.gz org.eclipse.sirius-af595e47adb7716eec0217bd76fb1ac806c01728.tar.xz org.eclipse.sirius-af595e47adb7716eec0217bd76fb1ac806c01728.zip | |
[485671] Authorize only EClass in domain class zone's completion
- Fix completion of "Type name" and "Domain class" field by showing only
EClass.
- Add corresponding test.
- Update tests according to fix.
Bug: 485671
Change-Id: I758c156cedf0d5bb4ecc918f02d37043fa50b987
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
3 files changed, 56 insertions, 13 deletions
diff --git a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java index cc78b03451..427c01ce1f 100644 --- a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java +++ b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/api/assist/TypeContentProposalProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2017 THALES GLOBAL SERVICES. * 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 @@ -35,7 +35,7 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; /** - * Content Proposal Provider for Type names. + * Content Proposal Provider for Type names (domain classes). * * @author cbrun * @@ -57,6 +57,7 @@ public class TypeContentProposalProvider implements IContentProposalProvider { /** * {@inheritDoc} */ + @Override public IContentProposal[] getProposals(final String contents, final int position) { final String incompleteText = contents.substring(0, position); final List<EClassifier> proposals = assistant.proposal(incompleteText); @@ -91,12 +92,14 @@ public class TypeContentProposalProvider implements IContentProposalProvider { adapter.addContentProposalListener(new IContentProposalListener2() { + @Override public void proposalPopupClosed(final ContentProposalAdapter arg0) { if (section instanceof ModelViewBinding) { ((ModelViewBinding) section).enableModelUpdating(); } } + @Override public void proposalPopupOpened(final ContentProposalAdapter arg0) { if (section instanceof ModelViewBinding) { ((ModelViewBinding) section).disableModelUpdating(); @@ -122,11 +125,11 @@ public class TypeContentProposalProvider implements IContentProposalProvider { IAssistContentProvider contentProposalAdapter = extension.get(0); contentProposalAdapter.setView(section); IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class); // gives - // the - // user - // content - // assist - // binding + // the + // user + // content + // assist + // binding TriggerSequence[] activeBindinds = bindingService.getActiveBindingsFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); if (activeBindinds != null && activeBindinds.length > 0) { TriggerSequence sequence = activeBindinds[0]; diff --git a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/assist/TypeAssistant.java b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/assist/TypeAssistant.java index 55116b245b..13b24cce60 100644 --- a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/assist/TypeAssistant.java +++ b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/assist/TypeAssistant.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2017 THALES GLOBAL SERVICES. * 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 @@ -16,6 +16,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; @@ -29,7 +30,7 @@ import org.eclipse.sirius.viewpoint.description.RepresentationDescription; import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; /** - * A Type Assistant provides type names from incomplete names. + * A Type Assistant provides type names (domain classes) from incomplete names. * * @author cbrun * @@ -126,8 +127,11 @@ public class TypeAssistant { private void addProposals(final Collection<EClassifier> proposals, final EPackage ePackage, final String incompleteName) { for (final EClassifier clazz : ePackage.getEClassifiers()) { - // CHECKSTYLE:OFF - if ((clazz.getName() != null && clazz.getName().startsWith(incompleteName)) || ((ePackage.getName() != null && (ePackage.getName() + "." + clazz.getName()).startsWith(incompleteName))) || ((ePackage.getName() != null && (ePackage.getName() + "::" + clazz.getName()).startsWith(incompleteName)))) { + boolean addProposal = clazz.getName() != null && clazz.getName().startsWith(incompleteName); + addProposal = addProposal || ((ePackage.getName() != null && (ePackage.getName() + "." + clazz.getName()).startsWith(incompleteName))); + addProposal = addProposal || ((ePackage.getName() != null && (ePackage.getName() + "::" + clazz.getName()).startsWith(incompleteName))); + addProposal = addProposal && clazz instanceof EClass; + if (addProposal) { proposals.add(clazz); } } diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/editor/TypeAssistantTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/editor/TypeAssistantTests.java index 5759e96d2a..f8817e6c17 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/editor/TypeAssistantTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/vsm/editor/TypeAssistantTests.java @@ -14,6 +14,8 @@ import java.util.List; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EEnum; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EPackage.Registry; import org.eclipse.emf.ecore.EcoreFactory; @@ -79,7 +81,7 @@ public class TypeAssistantTests extends TestCase { public void testAddProposalsWithAQLSyntaxSeparator() { registryStub.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); List<EClassifier> proposals = typeAssistant.proposal("ecore:"); - assertEquals("with ':' as beginning we should have 53 proposals", 53, proposals.size()); + assertEquals("with ':' as beginning we should have 20 proposals", 20, proposals.size()); } /** @@ -89,7 +91,7 @@ public class TypeAssistantTests extends TestCase { public void testAddProposalsWithAQLSyntaxSeparator2() { registryStub.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); List<EClassifier> proposals = typeAssistant.proposal("ecore::"); - assertEquals("with ':' as beginning we should have 53 proposals", 53, proposals.size()); + assertEquals("with ':' as beginning we should have 20 proposals", 20, proposals.size()); } /** @@ -109,6 +111,40 @@ public class TypeAssistantTests extends TestCase { assertEquals("with OneT as beginning we should have OneType proposal", eClass, proposals.get(0)); } + /** + * Test that {@link EEnum} are not proposed from {@link TypeAssistant} + * because Sirius does not handle it. + */ + public void testProposalsWithEEnum() { + EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); + ePackage.setName("EPackage"); + ePackage.setNsURI("http://www.example.com/dsl/viewpoint/tests/TypeAssistantTests/0.1.0"); + EEnum eEnum = EcoreFactory.eINSTANCE.createEEnum(); + eEnum.setName("OneType"); + ePackage.getEClassifiers().add(eEnum); + registryStub.put(ePackage.getNsURI(), ePackage); + + List<EClassifier> proposals = typeAssistant.proposal("OneT"); + assertEquals("EEnum should not be proposed.", 0, proposals.size()); + } + + /** + * Test that {@link EDatatype} are not proposed from {@link TypeAssistant} + * because Sirius does not handle it. + */ + public void testProposalsWithEDatatype() { + EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); + ePackage.setName("EPackage"); + ePackage.setNsURI("http://www.example.com/dsl/viewpoint/tests/TypeAssistantTests/0.1.0"); + EDataType eDatatype = EcoreFactory.eINSTANCE.createEDataType(); + eDatatype.setName("OneType"); + ePackage.getEClassifiers().add(eDatatype); + registryStub.put(ePackage.getNsURI(), ePackage); + + List<EClassifier> proposals = typeAssistant.proposal("OneT"); + assertEquals("EEnum should not be proposed.", 0, proposals.size()); + } + @Override protected void tearDown() throws Exception { registryStub = null; |
