aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-04-15 09:04:40 (EDT)
committersefftinge2009-04-15 09:04:40 (EDT)
commitf48d5d57501be591bdd3afa48cf519306db59bd4 (patch)
tree5023811d9641293a7f0b3feb1ff82a372f771754
parent598a399e884a4d9aebbd2c797a95f8ca0fdd3434 (diff)
downloadorg.eclipse.xtext-f48d5d57501be591bdd3afa48cf519306db59bd4.zip
org.eclipse.xtext-f48d5d57501be591bdd3afa48cf519306db59bd4.tar.gz
org.eclipse.xtext-f48d5d57501be591bdd3afa48cf519306db59bd4.tar.bz2
DefaultLabelProvider uses AdapterFactoryLabelProvider as fallback
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java58
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/service/DefaultUIModule.java17
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/DefaultLabelProvider.java18
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactory.java25
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactoryLabelProvider.java25
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/PluginImageHelper.java21
-rw-r--r--tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/DefaultLabelProviderTest.java5
7 files changed, 113 insertions, 56 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java
index 4fb17b5..07a5e5e 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/AbstractJavaProposalProvider.java
@@ -13,16 +13,13 @@ import java.util.Collections;
import java.util.List;
import org.apache.log4j.Logger;
-import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
-import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.AbstractElement;
import org.eclipse.xtext.AbstractRule;
@@ -53,12 +50,13 @@ public abstract class AbstractJavaProposalProvider implements IProposalProvider
protected static final String LEXER_RULE_STRING = "STRING";
// logger available to subclasses
protected final static Logger logger = Logger.getLogger(IProposalProvider.class);
+
@Inject
protected IScopeProvider scopeProvider;
- @Inject(optional=true)
- protected AdapterFactory adapterFactory;
- // @Inject(optional=true) does not work due to some plugin visibility quirks
- protected AdapterFactoryLabelProvider adapterFactoryLabelProvider;
+
+ @Inject
+ protected ILabelProvider labelProvider;
+
protected JavaReflectiveMethodInvoker methodInvoker;
protected List<IProposalProvider> proposalProviders;
@@ -93,7 +91,7 @@ public abstract class AbstractJavaProposalProvider implements IProposalProvider
TypeRef typeRef = calledRule.getType();
return invokeMethod("complete"+ ( null!=typeRef.getMetamodel().getAlias() ? Strings.toFirstUpper(typeRef.getMetamodel().getAlias()) + "_" : "" )
+ Strings.toFirstUpper(typeRef.getClassifier().getName()),
- Arrays.<Class<?>> asList(EObject.class, RuleCall.class,contentAssistContext.getModel() == null ?
+ Arrays.<Class<?>> asList(EObject.class, RuleCall.class,contentAssistContext.getModel() == null ?
EObject.class : contentAssistContext.getModel().getClass(),
IContentAssistContext.class), Arrays.asList(
contentAssistContext.getModel(),ruleCall,contentAssistContext));
@@ -109,7 +107,7 @@ public abstract class AbstractJavaProposalProvider implements IProposalProvider
Assignment assignment, IContentAssistContext contentAssistContext) {
ParserRule parserRule = GrammarUtil.containingParserRule(assignment);
// TODO : Better call completeRuleCall ?
- return invokeMethod("complete"+ Strings.toFirstUpper(parserRule.getName()) + "_"+
+ return invokeMethod("complete"+ Strings.toFirstUpper(parserRule.getName()) + "_"+
Strings.toFirstUpper(assignment.getFeature()), Arrays.<Class<?>> asList(EObject.class, Assignment.class,
IContentAssistContext.class), Arrays.asList(contentAssistContext.getModel(), assignment,contentAssistContext));
}
@@ -120,7 +118,8 @@ public abstract class AbstractJavaProposalProvider implements IProposalProvider
*/
protected ICompletionProposal createCompletionProposal(AbstractElement abstractElement, String displayString,
IContentAssistContext contentAssistContext) {
- return createCompletionProposal(abstractElement, displayString,contentAssistContext,getImage(abstractElement));
+ return createCompletionProposal(abstractElement, displayString, contentAssistContext,
+ getImage(abstractElement));
}
/**
@@ -220,51 +219,22 @@ public abstract class AbstractJavaProposalProvider implements IProposalProvider
if (null != candidate.name() && isCandidateMatchingPrefix(contentAssistContext
.getModel(), ref, candidate, trimmedPrefix)) {
completionProposalList.add(createCompletionProposal(crossReference, candidate.name(),
- contentAssistContext,getImage(candidate.element())));
+ contentAssistContext, getImage(candidate.element())));
}
}
}
}
-
return completionProposalList;
}
-
+
/**
- * Returns the image for the label of the given element.
+ * Returns the image for the label of the given element.
*
* @param element the element for which to provide the label image
* @return the image used to label the element, or <code>null</code> if there is no image for the given object
*/
protected Image getImage(EObject eObject) {
- return getAdapterFactoryLabelProvider().getImage(eObject);
- }
-
- /**
- * @return an instance that wraps the given {@link #getAdapterFactory()} to delegates its JFace provider
- * interfaces to corresponding adapter-implemented item provider interfaces
- * @see AdapterFactoryLabelProvider
- */
- protected AdapterFactoryLabelProvider getAdapterFactoryLabelProvider() {
- if (null == this.adapterFactoryLabelProvider) {
- this.adapterFactoryLabelProvider = new AdapterFactoryLabelProvider(
- getAdapterFactory());
- }
- return this.adapterFactoryLabelProvider;
- }
-
- /**
- * @return an adapter factory that yield adapters that implement the various item label provider interfaces.
- * @see AdapterFactory
- */
- protected AdapterFactory getAdapterFactory() {
- if (null == this.adapterFactory) {
- ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory(
- ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
- composedAdapterFactory
- .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
- this.adapterFactory = composedAdapterFactory;
- }
- return this.adapterFactory;
+ return labelProvider.getImage(eObject);
}
@SuppressWarnings("unchecked")
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/service/DefaultUIModule.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/service/DefaultUIModule.java
index 9bdf27a..023c033 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/service/DefaultUIModule.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/service/DefaultUIModule.java
@@ -7,6 +7,9 @@
*******************************************************************************/
package org.eclipse.xtext.ui.common.service;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.reconciler.IReconciler;
@@ -25,6 +28,8 @@ import org.eclipse.xtext.ui.common.editor.syntaxcoloring.antlr.NullTokenColorer;
import org.eclipse.xtext.ui.core.DefaultLabelProvider;
import org.eclipse.xtext.ui.core.DefaultLocationInFileProvider;
import org.eclipse.xtext.ui.core.ILocationInFileProvider;
+import org.eclipse.xtext.ui.core.InjectableAdapterFactory;
+import org.eclipse.xtext.ui.core.InjectableAdapterFactoryLabelProvider;
import org.eclipse.xtext.ui.core.editor.IDamagerRepairer;
import org.eclipse.xtext.ui.core.editor.XtextDamagerRepairer;
import org.eclipse.xtext.ui.core.editor.reconciler.XtextReconciler;
@@ -82,4 +87,16 @@ public abstract class DefaultUIModule extends AbstractGenericModule {
return XtextDamagerRepairer.class;
}
+ public Class<? extends AdapterFactory> bindAdapterFactory() {
+ return InjectableAdapterFactory.class;
+ }
+
+ public Class<? extends AdapterFactoryLabelProvider> bindAdapterFactoryLabelProvider() {
+ return InjectableAdapterFactoryLabelProvider.class;
+ }
+
+ public ComposedAdapterFactory.Descriptor.Registry bindComposedAdapterFactoryDescriptorRegistry() {
+ return ComposedAdapterFactory.Descriptor.Registry.INSTANCE;
+ }
+
}
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/DefaultLabelProvider.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/DefaultLabelProvider.java
index 6c4ba21..c4f56fe 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/DefaultLabelProvider.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/DefaultLabelProvider.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.util.PolymorphicDispatcher;
@@ -51,14 +52,19 @@ public class DefaultLabelProvider extends LabelProvider {
@Inject
private IImageHelper imageHelper;
+ @Inject
+ private AdapterFactoryLabelProvider adapterFactoryLabelProvider;
+
@Override
- public final String getText(Object element) {
+ public String getText(Object element) {
return getText.invoke(element);
}
@Override
- public final Image getImage(Object element) {
+ public Image getImage(Object element) {
String imageName = getImage.invoke(element);
+ if (imageName == null && adapterFactoryLabelProvider != null)
+ return adapterFactoryLabelProvider.getImage(element);
return getImageHelper().getImage(imageName);
}
@@ -124,5 +130,13 @@ public class DefaultLabelProvider extends LabelProvider {
public IImageHelper getImageHelper() {
return imageHelper;
}
+
+ public AdapterFactoryLabelProvider getAdapterFactoryLabelProvider() {
+ return adapterFactoryLabelProvider;
+ }
+
+ public void setAdapterFactoryLabelProvider(AdapterFactoryLabelProvider adapterFactoryLabelProvider) {
+ this.adapterFactoryLabelProvider = adapterFactoryLabelProvider;
+ }
}
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactory.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactory.java
new file mode 100644
index 0000000..99df87e
--- /dev/null
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactory.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.xtext.ui.core;
+
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory.Descriptor.Registry;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class InjectableAdapterFactory extends ComposedAdapterFactory {
+
+ @Inject
+ public InjectableAdapterFactory(Registry adapterFactoryDescriptorRegistry) {
+ super(adapterFactoryDescriptorRegistry);
+ }
+
+}
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactoryLabelProvider.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactoryLabelProvider.java
new file mode 100644
index 0000000..ebff39d
--- /dev/null
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/InjectableAdapterFactoryLabelProvider.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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
+ *******************************************************************************/
+package org.eclipse.xtext.ui.core;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class InjectableAdapterFactoryLabelProvider extends AdapterFactoryLabelProvider {
+
+ @Inject
+ public InjectableAdapterFactoryLabelProvider(AdapterFactory adapterFactory) {
+ super(adapterFactory);
+ }
+
+}
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/PluginImageHelper.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/PluginImageHelper.java
index e0942df..0e11837 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/PluginImageHelper.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/PluginImageHelper.java
@@ -36,9 +36,8 @@ public class PluginImageHelper implements IImageHelper {
@Named("org.eclipse.xtext.ui.core.PluginImageHelper.notFound")
private String notFound = "notFound.gif";
- public Image getImage(String imgname) {
- if (imgname == null)
- imgname = defaultImage;
+ public Image getImage(String imageName) {
+ String imgname = imageName == null ? defaultImage : imageName;
if (imgname != null) {
Image result = null;
URL imgUrl = getPlugin().getBundle().getEntry(getPathSuffix() + imgname);
@@ -53,10 +52,9 @@ public class PluginImageHelper implements IImageHelper {
}
}
return result;
- } else {
- if (!imgname.equals(notFound)) {
- return getImage(notFound);
- }
+ }
+ if (!imgname.equals(notFound)) {
+ return getImage(notFound);
}
}
return null;
@@ -85,4 +83,13 @@ public class PluginImageHelper implements IImageHelper {
public String getNotFound() {
return notFound;
}
+
+ public String getDefaultImage() {
+ return defaultImage;
+ }
+
+ public void setDefaultImage(String defaultImage) {
+ this.defaultImage = defaultImage;
+ }
+
}
diff --git a/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/DefaultLabelProviderTest.java b/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/DefaultLabelProviderTest.java
index 3768163..19d9de4 100644
--- a/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/DefaultLabelProviderTest.java
+++ b/tests/org.eclipse.xtext.ui.core.tests/src/org/eclipse/xtext/ui/core/DefaultLabelProviderTest.java
@@ -11,13 +11,12 @@ package org.eclipse.xtext.ui.core;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.emf.common.util.WrappedException;
-
import junit.framework.TestCase;
+import org.eclipse.emf.common.util.WrappedException;
+
/**
* @author Sven Efftinge - Initial contribution and API
- *
*/
public class DefaultLabelProviderTest extends TestCase {