Skip to content

Commit

Permalink
eclipse-archived#190 In progress TqCL - syntax (insert) and library s…
Browse files Browse the repository at this point in the history
…ervices
  • Loading branch information
rtotaro committed Jan 6, 2017
1 parent c4f76c2 commit 95209f0
Show file tree
Hide file tree
Showing 14 changed files with 222 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package org.eclipse.triquetrum.commands.api.services;

import java.util.ArrayList;
import java.util.List;

public class ActorDescriptor extends EntityDescriptor {

public ActorDescriptor(String displayName, String clazz, String icon) {
super(displayName, clazz, icon);
private List<PortDescriptor> ports = new ArrayList<>();

public ActorDescriptor(String sourceLibrary,String displayName, String clazz, String icon) {
super(sourceLibrary,displayName, clazz, icon);
}

@Override
public String getCategory() {
return "Actor";
}

public void addPort(PortDescriptor port)
{
ports.add(port);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class DirectorDescriptor extends EntityDescriptor {

public DirectorDescriptor(String displayName, String clazz, String icon) {
super(displayName, clazz, icon);
public DirectorDescriptor(String sourceLibrary,String displayName, String clazz, String icon) {
super(sourceLibrary,displayName, clazz, icon);
// TODO Auto-generated constructor stub
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package org.eclipse.triquetrum.commands.api.services;

import java.util.ArrayList;
import java.util.List;

public abstract class EntityDescriptor {

private String clazz;

private String displayName;

private String icon;

private String sourceLibrary;

private List<ParameterDescriptor> parameters = new ArrayList<>();

public EntityDescriptor(String displayName, String clazz, String icon) {
public EntityDescriptor(String sourceLibrary,String displayName, String clazz, String icon) {
super();
this.sourceLibrary = sourceLibrary;
this.displayName = displayName;
this.clazz = clazz;
this.icon = icon;
}


public String getSourceLibrary() {
return sourceLibrary;
}

public String getClazz() {
return clazz;
Expand All @@ -28,6 +41,16 @@ public String getIcon() {
}

public abstract String getCategory();


public void addParameter(ParameterDescriptor parameter) {
parameters.add(parameter);
}


public List<ParameterDescriptor> getParameters() {
return parameters;
}



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.eclipse.triquetrum.commands.api.services;

public class ParameterDescriptor extends EntityDescriptor {

private String defaultValue="";

public ParameterDescriptor(String sourceLibrary,String displayName, String clazz, String icon) {
super(sourceLibrary,displayName, clazz, icon);
}

@Override
public String getCategory() {
return "Parameter";
}

public String getDefaultValue() {
return defaultValue;
}

public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.eclipse.triquetrum.commands.api.services;

public class PortDescriptor extends EntityDescriptor {

private boolean input;

private boolean output;


public PortDescriptor(String sourceLibrary,String displayName, String clazz, String icon) {
super(sourceLibrary,displayName, clazz, icon);
}

@Override
public String getCategory() {
return "Port";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface TqCLLibraryProvider {

public List<ActorDescriptor> getActors(String library) throws TqCLLibraryException;

// public ActorDescriptor getActor(String library,String actorName) throws TqCLLibraryException;
public EntityDescriptor getActor(String library,String actorClass) throws TqCLLibraryException;

public List<DirectorDescriptor> getDirectors(String library) throws TqCLLibraryException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.eclipse.triquetrum.commands.api.services.ActorDescriptor;
import org.eclipse.triquetrum.commands.api.services.DirectorDescriptor;
import org.eclipse.triquetrum.commands.api.services.EntityDescriptor;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryException;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryProvider;

Expand Down Expand Up @@ -105,4 +106,9 @@ public void addLibraryProvider(TqCLLibraryProvider tqCLLibraryProvider) {
}
}

@Override
public EntityDescriptor getActor(String library, String actorName) throws TqCLLibraryException {
return this.libraryProviders.get(library).getActor(library, actorName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.eclipse.triquetrum.commands.ui.contentassist;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -24,7 +25,10 @@
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.triquetrum.commands.api.TqCLServices;
import org.eclipse.triquetrum.commands.api.services.ActorDescriptor;
import org.eclipse.triquetrum.commands.api.services.DirectorDescriptor;
import org.eclipse.triquetrum.commands.api.services.EntityDescriptor;
import org.eclipse.triquetrum.commands.api.services.ParameterDescriptor;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryException;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryProvider;
import org.eclipse.triquetrum.commands.tqcl.Category;
Expand All @@ -35,11 +39,16 @@
import org.eclipse.triquetrum.workflow.editor.TriqFeatureProvider;
import org.eclipse.triquetrum.workflow.editor.features.ModelElementCreateFeature;
import org.eclipse.triquetrum.workflow.model.util.PtolemyUtil;
import org.eclipse.ui.internal.handlers.WizardHandler.New;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;

import com.google.common.collect.ArrayTable;
import com.google.common.collect.Multimap;
import com.google.common.collect.Table;

import ptolemy.actor.CompositeActor;
import ptolemy.data.expr.Parameter;
import ptolemy.kernel.Entity;
Expand All @@ -55,6 +64,8 @@ public class TqclProposalProvider extends AbstractTqclProposalProvider {

private Map<String, ModelElementCreateFeature> featuresMap = new HashMap<>();

private Map<String, EntityDescriptor> entityDescriptorsMap = new HashMap<>();

private void initFeatureMap() {
if (featuresMap.isEmpty()) {
TriqFeatureProvider featureProvider = new TriqFeatureProvider(new TriqDiagramTypeProvider());
Expand All @@ -75,40 +86,53 @@ public void completeInsert_EntityClass(EObject model, Assignment assignment, Con
ICompletionProposalAcceptor acceptor) {
super.completeInsert_EntityClass(model, assignment, context, acceptor);

try {
Insert insert = (Insert) model;
TriquetrumScript triquetrumScript = (TriquetrumScript) insert.eContainer();
EList<Library> libraries = triquetrumScript.getLibraries();
TqCLLibraryProvider tcqlLibraryProvider = TqCLServices.getInstance().getTcqlLibraryProvider();
Category category = insert.getCategory();
List<? extends EntityDescriptor> descriptors = new ArrayList<>();
if (libraries == null) {
return;
}
if (insert.getCategory() == null) {
category = Category.ACTOR;
}
for (Library library : libraries) {
switch (category) {
case ACTOR:
descriptors.addAll((List) tcqlLibraryProvider.getActors(library.getName()));
break;

case DIRECTOR:
descriptors.addAll((List) tcqlLibraryProvider.getDirectors(library.getName()));
break;

default:
break;
if (model instanceof Insert) {
try {

Insert insert = (Insert) model;
TriquetrumScript triquetrumScript = (TriquetrumScript) insert.eContainer();
EList<Library> libraries = triquetrumScript.getLibraries();
TqCLLibraryProvider tcqlLibraryProvider = TqCLServices.getInstance().getTcqlLibraryProvider();
Category category = insert.getCategory();
List<? extends EntityDescriptor> descriptors = new ArrayList<>();
if (libraries == null) {
return;
}
if (insert.getCategory() == null) {
category = Category.ACTOR;
}
for (Library library : libraries) {
switch (category) {
case ACTOR:
List<ActorDescriptor> actorDescriptors = tcqlLibraryProvider.getActors(library.getName());
for (EntityDescriptor actorDescriptor : actorDescriptors) {
entityDescriptorsMap.put(actorDescriptor.getClazz(), actorDescriptor);
}
descriptors.addAll((List) actorDescriptors);
break;

case DIRECTOR:
List<DirectorDescriptor> directors = tcqlLibraryProvider.getDirectors(library.getName());
descriptors.addAll((List) directors);
for (DirectorDescriptor directorDescriptor : directors) {
entityDescriptorsMap.put(directorDescriptor.getClazz(), directorDescriptor);
}
descriptors.addAll((List) directors);
break;

default:
break;
}
}
for (EntityDescriptor key : descriptors) {
ICompletionProposal completionProposal = createCompletionProposal('<' + key.getClazz() + "> as ",
key.getClazz(), null, context);
acceptor.accept(completionProposal);
}
} catch (TqCLLibraryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (EntityDescriptor key : descriptors) {
ICompletionProposal completionProposal = createCompletionProposal('<' + key.getClazz() + "> as ",key.getClazz(),null, context);
acceptor.accept(completionProposal);
}
} catch (TqCLLibraryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Expand All @@ -122,7 +146,7 @@ public void completeInsert_Name(EObject model, Assignment assignment, ContentAss
String name = StringUtils.substringAfterLast(qualifiedName, ".");
name = name.replaceAll("<", "");
name = name.replaceAll(">", "");
ICompletionProposal completionProposal = createCompletionProposal('"'+name+'"',name,null , context);
ICompletionProposal completionProposal = createCompletionProposal('"' + name + '"', name, null, context);
acceptor.accept(completionProposal);
}
}
Expand All @@ -132,37 +156,29 @@ public void completeInsert_Parameters(EObject model, Assignment assignment, Cont
ICompletionProposalAcceptor acceptor) {
if (model instanceof Insert) {
Insert insert = (Insert) model;
String qualifiedName = insert.getEntityClass();
ModelElementCreateFeature modelElementCreateFeature = featuresMap.get(qualifiedName.replaceAll("\"", ""));

String wrappedClass = modelElementCreateFeature.getWrappedClass();
try {

CompositeActor ca = new CompositeActor();

// TODO:Find a better way to do that
List<Parameter> parameters = new ArrayList<>();
if ("Directors".equals(modelElementCreateFeature.getGroup())) {
Attribute director = PtolemyUtil._createAttribute(ca, wrappedClass, "autocomplention");
parameters = director.attributeList(Parameter.class);
Category category = ((Insert) insert).getCategory();
if (category == null) {
category = Category.ACTOR;
}
String entityClass = insert.getEntityClass();

EntityDescriptor actor = entityDescriptorsMap.get(entityClass.substring(1, entityClass.lastIndexOf('>')));
if (actor == null) {
return;
}
List<ParameterDescriptor> parameters = actor.getParameters();
for (ParameterDescriptor parameterDescriptor : parameters) {
String displayName = parameterDescriptor.getDisplayName();
String proposal = "";
if (displayName.contains(" ")) {
proposal = "\"" + displayName + "\"";
} else {
Entity<?> entity = PtolemyUtil._createEntity(ca, wrappedClass, null, "autocomplention");
parameters = entity.attributeList(Parameter.class);
proposal = MessageFormat.format("${0}=\"{1}\"", displayName, parameterDescriptor.getDefaultValue());
}
String description = displayName + "(default=" + parameterDescriptor.getDefaultValue() + ")";

for (Parameter parameter : parameters) {
Visibility visibility = parameter.getVisibility();

if (!Parameter.NOT_EDITABLE.equals(visibility)) {
ICompletionProposal completionProposal = createCompletionProposal(parameter.getName(), context);
acceptor.accept(completionProposal);
}
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
ICompletionProposal completionProposal = createCompletionProposal(proposal, description, null, context);
acceptor.accept(completionProposal);
}

}
Expand All @@ -176,6 +192,7 @@ public void complete_Parameter(EObject model, RuleCall ruleCall, ContentAssistCo
initFeatureMap();
org.eclipse.triquetrum.commands.tqcl.Parameter param = (org.eclipse.triquetrum.commands.tqcl.Parameter) model;
EObject eContainer = param.eContainer();

}

}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 95209f0

Please sign in to comment.