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  |
|
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 #1763375 is a reply to message #1763373] |
Sun, 14 May 2017 18:28   |
|
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
|
|
| | |
Goto Forum:
Current Time: Wed Jun 07 10:00:01 GMT 2023
Powered by FUDForum. Page generated in 0.02704 seconds
|