Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Guidelines for having specific icons in proposals
Guidelines for having specific icons in proposals [message #1763372] Sun, 14 May 2017 17:43 Go to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear all.

I would like to have specific icons for my DSL types in the content assist proposals.

public class SARLImportingTypesProposalProvider extends ImportingTypesProposalProvider {

	@Inject
	private InheritanceHelper inheritanceHelper;

	@Inject
	private CommonTypeComputationServices services;

	@Inject
	private SARLImages images;

	private Image image;

	@Override
	protected void createTypeProposal(String typeName, int modifiers, boolean isInnerType,
			ICompletionProposalFactory proposalFactory, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor, IJvmTypeProvider jvmTypeProvider,
			IValueConverter<String> valueConverter) {

		JvmType type = null;
		if (jvmTypeProvider != null) {
			type = jvmTypeProvider.findTypeByName(typeName);
		}
		if (type == null && context != null) {
			type = this.services.getTypeReferences().findDeclaredType(typeName, context.getCurrentModel());
		}

		this.image = null;
		if (type instanceof JvmGenericType) {
			final JvmGenericType gtype = (JvmGenericType) type;
			if (this.inheritanceHelper.isSarlAgent(gtype)) {
				this.image = this.images.forAgent(JvmVisibility.PUBLIC, 0).createImage();
			} else if (this.inheritanceHelper.isSarlBehavior(gtype)) {
				this.image = this.images.forBehavior(JvmVisibility.PUBLIC, 0).createImage();
			}
		}

		super.createTypeProposal(typeName, modifiers, isInnerType, proposalFactory, context, acceptor, jvmTypeProvider,
				valueConverter);
	}

	@Override
	protected Image computeImage(String typeName, boolean isInnerType, int modifiers) {
		if (this.image != null) {
			return this.image;
		}
		return super.computeImage(typeName, isInnerType, modifiers);
	}

}


This code works as expected: a specific icon is shown in the content assist popup for the DSL elements.

Unfortunately, this solution suffers of a big disavantage: when the content assist needs to go through all the class path for building the proposal list, e.g. after typing "var x = new ", then the proposal provider takes a long time (a couple of minutes) for showing the proposals. This is due to the time for loading the classes (call to findTypeByName). The second time the content assist is called on the same context, it is efficient.

My question is: what could be a better way for providing a specific icon in the content assist?

Thank by advance.
Stéphane.
Re: Guidelines for having specific icons in proposals [message #1763373 is a reply to message #1763372] Sun, 14 May 2017 17:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
can you be more specific on what your code does? isSarlAgent / isSarlBehavior

if this is a interface/subclass then have a look at org.eclipse.xtext.common.types.xtext.ui.ITypesProposalProvider.createSubTypeProposals(JvmType, ICompletionProposalFactory, ContentAssistContext, EReference, ICompletionProposalAcceptor)

https://kthoms.wordpress.com/2012/03/14/how-to-limit-proposed-java-types-to-implementors-of-an-interface/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Guidelines for having specific icons in proposals [message #1763375 is a reply to message #1763373] Sun, 14 May 2017 18:28 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Dear Christian.

Currently, there is no problem regarding the types that are proposed (I'm able to restrict the proposals with the createSubTypeProposals function).
Here, my issue is related to the icon that is displayed at the side of the proposals in the popup, when there is no filtering of the proposals, i.e. no subtype contraint, etc.
This may occurs when doing a Ctrl+Space at the position of the | in the following Xtend code:
class X {
    def void fct() {
        var x = new |
    }
}


In this case, all the types on the class path should be proposed, and they are; but they have all a Java icon (class icon, interface icon, etc.).

The code of isSarlAgent is equivalent to "parameter instanceof SarlAgent" and isSarlBehavior to "parameter instanceof SarlBehavior". They are working fine. They are reading a specific annotation attached to the Java type that specifies the DSL type (agent or behavior) of the element (this avoids to do a real instance-of through the Ecore hierarchy).

Without my implementation above, the icons are always the icons for classes because the generated JvmType corresponds to a class.
Indeed, my DSL elements (SarlAgent, SarlBehavior) are both Java classes after being Jvm inferred.

But I would like to display a specific icon for the SarlAgent, and another specific icon for the SarlBehavior, not the JDT icons.
The code that I propose work fine, i.e. the specific icons are displayed at the side of my DSL types.

Unfortunately, the first time I push Ctrl+Space, the proposal provider takes a couple of minutes for building the list of the proposals. And this is the issue.
When I remove the call to findDeclaredType, the computation time is only a couple of seconds (but I cannot have specific icons in the proposals' popup).

Until I use an "instanceof" approach for determining the type of of the DSL elements, I think I need to get the JvmType. So that the call to findDeclaredType is mandatory.

My question is: Am I right with this assumption? Is another approach, faster, exists?

As far as I know, the computeImage() in JDT uses the provided "modifiers" parameter for determining the icons. Unfortunately, we cannot use these modifiers easily because they are computed by JDT from the Java bytecode.

Hoping my explanations make my question more clear.

Stéphane.

[Updated on: Sun, 14 May 2017 18:30]

Report message to a moderator

Re: Guidelines for having specific icons in proposals [message #1763376 is a reply to message #1763375] Sun, 14 May 2017 18:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Well my intention was you to Lok into the code

If i am right this code uses jdt search API.
And yoi could do that too

Search subtypes of type a and gives icon a
Search subtypes oft type b and give icon b
Maybe not subtypes of and and not Subtyps of b for Rest (do t kbiw if that will work)



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Guidelines for having specific icons in proposals [message #1763377 is a reply to message #1763376] Sun, 14 May 2017 18:48 Go to previous message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Thank you.
I will try your approach: when no filtering is initial ask, I will force the filtering on the different types and set the icons accordingly.
I will try that and evaluate the computation time of this approach.
Stéphane.
Previous Topic:GeneratedClass is already defined
Next Topic:URI has an authority component
Goto Forum:
  


Current Time: Tue Apr 16 12:44:24 GMT 2024

Powered by FUDForum. Page generated in 0.30837 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top