Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2021-10-06 12:44:49 +0000
committerPatrick Tessier2021-10-07 13:29:45 +0000
commitf459c7898d10153d13c8eeafe081ce5ed8268a48 (patch)
tree0861cbc5e3eda34884af7afad4044c9c2beac5b0
parent85523ac029fc73ae6df7e6285f05a61eafacde46 (diff)
downloadorg.eclipse.papyrus-f459c7898d10153d13c8eeafe081ce5ed8268a48.tar.gz
org.eclipse.papyrus-f459c7898d10153d13c8eeafe081ce5ed8268a48.tar.xz
org.eclipse.papyrus-f459c7898d10153d13c8eeafe081ce5ed8268a48.zip
Bug 576474: [Xtext] The completion proposal will generate NPE with the new nested XText Editor
Change-Id: I2b88fef3e2b03f1c554f3453f8feedab3a6592a7 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF6
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/pom.xml2
-rw-r--r--plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/CompletionProposalUtils.java66
3 files changed, 60 insertions, 14 deletions
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF
index e4c02b6fb2a..15b8f149578 100644
--- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/META-INF/MANIFEST.MF
@@ -14,9 +14,11 @@ Require-Bundle: org.eclipse.emf.databinding;bundle-version="[1.5.0,2.0.0)",
org.eclipse.papyrus.uml.xtext.integration.core;bundle-version="[3.0.0,4.0.0)",
org.eclipse.ui.ide;bundle-version="[3.17.0,4.0.0)",
org.eclipse.uml2.uml;bundle-version="[5.5.0,6.0.0)",
- org.eclipse.xtext.ui;bundle-version="[2.22.0,3.0.0)"
+ org.eclipse.xtext.ui;bundle-version="[2.22.0,3.0.0)",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.papyrus.infra.core;bundle-version="[4.2.0,5.0.0)"
Bundle-Vendor: Eclipse Modeling Project
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Name: Papyrus GMF Xtext Integration
Bundle-Activator: org.eclipse.papyrus.uml.xtext.integration.ui.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/pom.xml b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/pom.xml
index 41112bc253d..4e4dadb461e 100644
--- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/pom.xml
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/pom.xml
@@ -9,6 +9,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.xtext.integration.ui</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/CompletionProposalUtils.java b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/CompletionProposalUtils.java
index bfd2531f1f8..6de58bfc77e 100644
--- a/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/CompletionProposalUtils.java
+++ b/plugins/uml/xtext/org.eclipse.papyrus.uml.xtext.integration.ui/src/org/eclipse/papyrus/uml/xtext/integration/CompletionProposalUtils.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 2021 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -12,7 +12,7 @@
* Contributors:
* CEA LIST - Initial API and implementation
* Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - bug 479041
- *
+ * Vincent LORENZO (CEA LIST) vincent.lorenzo@cea.fr - bug576474
*****************************************************************************/
package org.eclipse.papyrus.uml.xtext.integration;
@@ -21,8 +21,15 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
import org.eclipse.papyrus.infra.ui.util.DisplayUtils;
+import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForSelection;
+import org.eclipse.papyrus.uml.xtext.integration.ui.Activator;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Namespace;
@@ -32,12 +39,37 @@ import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
/**
* @author CEA LIST - Initial contribution and API
*/
-@SuppressWarnings("nls")
public class CompletionProposalUtils {
+ /**
+ * @deprecated
+ * use the method getLabelProvider instead
+ */
+ @Deprecated(since = "3.1.0", forRemoval = true)
protected final static ILabelProvider labelProvider = DisplayUtils.getLabelProvider();
/**
+ *
+ * @param eobject
+ * an eobject
+ * @return
+ * the label provider to use for the given eobject
+ * @since 3.1
+ */
+ protected final static ILabelProvider getLabelProvider(final EObject eobject) {
+ try {
+ LabelProviderService service = ServiceUtilsForSelection.getInstance().getService(LabelProviderService.class, new StructuredSelection(eobject));
+ if (service != null) {
+ return service.getLabelProvider(eobject);
+ }
+ } catch (ServiceException e) {
+ Activator.log.error("Label provider service not found", e); //$NON-NLS-1$
+ }
+
+ return null;
+ }
+
+ /**
* Public Utility method for creating a completion proposal
*
* @param namedElement
@@ -54,13 +86,19 @@ public class CompletionProposalUtils {
String completionString,
String displayString,
ContentAssistContext context) {
- String additionalProposalInfo = "" + namedElement.getQualifiedName() + "\n" + '(' + namedElement.eClass().getName() + ')'; //$NON-NLS-1$ //$NON-NLS-2$
-
+ final StringBuilder builder = new StringBuilder(namedElement.getQualifiedName());
+ builder.append("\n").append('(').append(namedElement.eClass().getName()).append(')'); //$NON-NLS-1$
+ final String additionalProposalInfo = builder.toString();
+ Image image = null;
+ final ILabelProvider provider = getLabelProvider(namedElement);
+ if (provider != null) {
+ image = provider.getImage(namedElement);
+ }
CustomCompletionProposal completionProposal = new CustomCompletionProposal(completionString, // String to be inserted
context.getOffset(), // Offset
context.getSelectedText().length(), // Replacement length
completionString.length(), // cursorPosition
- labelProvider.getImage(namedElement), // image
+ image, // image
" " + displayString, // displayString //$NON-NLS-1$
null, // contextInformation
additionalProposalInfo, // additionalProposalInfo
@@ -85,13 +123,19 @@ public class CompletionProposalUtils {
String completionString,
String displayString,
ContentAssistContext context) {
- String additionalProposalInfo = "" + namedElement.getQualifiedName() + "\n" + '(' + namedElement.eClass().getName() + ')'; //$NON-NLS-1$ //$NON-NLS-2$
-
+ final StringBuilder builder = new StringBuilder(namedElement.getQualifiedName());
+ builder.append("\n").append('(').append(namedElement.eClass().getName()).append(')'); //$NON-NLS-1$
+ final String additionalProposalInfo = builder.toString();
+ Image image = null;
+ final ILabelProvider provider = getLabelProvider(namedElement);
+ if (provider != null) {
+ image = provider.getImage(namedElement);
+ }
CustomCompletionProposal completionProposal = new CustomCompletionProposal(completionString, // String to be inserted
context.getOffset() - context.getPrefix().length(), // Offset
context.getPrefix().length(), // Replacement length
completionString.length(), // cursorPosition
- labelProvider.getImage(namedElement), // image
+ image, // image
" " + displayString, // displayString //$NON-NLS-1$
null, // contextInformation
additionalProposalInfo, // additionalProposalInfo
@@ -140,10 +184,10 @@ public class CompletionProposalUtils {
List<Package> importedPackages = null;
if (null != model) {
- importedPackages = new ArrayList<Package>(model.getImportedPackages());
+ importedPackages = new ArrayList<>(model.getImportedPackages());
}
- List<Namespace> visitedNamespaces = new ArrayList<Namespace>();
+ List<Namespace> visitedNamespaces = new ArrayList<>();
Namespace currentNamespace = namedElement.getNamespace();
boolean rootFound = false;

Back to the top