diff --git a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/TqCLLibraryProvider.java b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/TqCLLibraryProvider.java index 407fa2cb..cfae556d 100644 --- a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/TqCLLibraryProvider.java +++ b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/TqCLLibraryProvider.java @@ -36,5 +36,7 @@ public interface TqCLLibraryProvider { public boolean hasElement(String element); public boolean hasElementInLibrary(String element, String library, String category); + + public EntityDescriptor getDirector(String directorClass) throws TqCLLibraryException; } diff --git a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/impl/TcQLLibraryProviderProxy.java b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/impl/TcQLLibraryProviderProxy.java index 81c31a30..6c18f716 100644 --- a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/impl/TcQLLibraryProviderProxy.java +++ b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/impl/TcQLLibraryProviderProxy.java @@ -122,6 +122,18 @@ public EntityDescriptor getActor(String actorClass) throws TqCLLibraryException } return null; } + + @Override + public EntityDescriptor getDirector(String directorClass) throws TqCLLibraryException { + for (TqCLLibraryProvider provider : libraryProviders.values()) { + EntityDescriptor actor = provider.getDirector(directorClass); + if(actor!=null) + { + return actor; + } + } + return null; + } @Override public boolean hasElementInLibrary(String element, String library,String category) { @@ -133,4 +145,5 @@ public boolean hasElementInLibrary(String element, String library,String categor return false; } + } diff --git a/org.eclipse.triquetrum.commands.xtext.ui/src/main/java/org/eclipse/triquetrum/commands/ui/contentassist/TqclProposalProvider.java b/org.eclipse.triquetrum.commands.xtext.ui/src/main/java/org/eclipse/triquetrum/commands/ui/contentassist/TqclProposalProvider.java index 1061106c..709c6db2 100644 --- a/org.eclipse.triquetrum.commands.xtext.ui/src/main/java/org/eclipse/triquetrum/commands/ui/contentassist/TqclProposalProvider.java +++ b/org.eclipse.triquetrum.commands.xtext.ui/src/main/java/org/eclipse/triquetrum/commands/ui/contentassist/TqclProposalProvider.java @@ -35,6 +35,7 @@ import org.eclipse.triquetrum.commands.tqcl.Insert; import org.eclipse.triquetrum.commands.tqcl.Library; import org.eclipse.triquetrum.commands.tqcl.TriquetrumScript; +import org.eclipse.triquetrum.commands.validation.TqCLUtils; import org.eclipse.xtext.Assignment; import org.eclipse.xtext.RuleCall; import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext; @@ -46,7 +47,7 @@ * on how to customize the content assistant. */ public class TqclProposalProvider extends AbstractTqclProposalProvider { - + @Override public void completeLibrary_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { @@ -54,8 +55,7 @@ public void completeLibrary_Name(EObject model, Assignment assignment, ContentAs TqCLLibraryProvider tqclLibraryProvider = TqCLServices.getInstance().getTqclLibraryProvider(); Set libraryNames = tqclLibraryProvider.getLibraryNames(); for (String string : libraryNames) { - ICompletionProposal completionProposal = createCompletionProposal(string, - string, null, context); + ICompletionProposal completionProposal = createCompletionProposal(string, string, null, context); acceptor.accept(completionProposal); } } @@ -136,20 +136,28 @@ public void completeInsert_Parameters(EObject model, Assignment assignment, Cont ICompletionProposalAcceptor acceptor) { if (model instanceof Insert) { Insert insert = (Insert) model; - Category category = ((Insert) insert).getCategory(); - if (category == null) { - category = Category.ACTOR; - } + Category category = TqCLUtils.getCategory((Insert) insert); String entityClass = insert.getEntityClass(); - EntityDescriptor actor; try { - actor = TqCLServices.getInstance().getTqclLibraryProvider().getActor(cleanEntityName(entityClass)); + TqCLLibraryProvider tqclLibraryProvider = TqCLServices.getInstance().getTqclLibraryProvider(); + EntityDescriptor entityDescriptor = null; + switch (category) { + case ACTOR: + entityDescriptor = tqclLibraryProvider.getActor(TqCLUtils.cleanEntityName(entityClass)); + break; + case DIRECTOR: + entityDescriptor = tqclLibraryProvider.getDirector(TqCLUtils.cleanEntityName(entityClass)); + break; + + default: + break; + } - if (actor == null) { + if (entityDescriptor == null) { return; } - List parameters = actor.getParameters(); + List parameters = entityDescriptor.getParameters(); for (ParameterDescriptor parameterDescriptor : parameters) { String displayName = parameterDescriptor.getDisplayName(); String proposal = ""; @@ -173,8 +181,4 @@ public void completeInsert_Parameters(EObject model, Assignment assignment, Cont } } - public String cleanEntityName(String entityClass) { - return entityClass.substring(1, entityClass.lastIndexOf('>')); - } - } diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/Tqcl.xtext b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/Tqcl.xtext index 6df98985..6968254b 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/Tqcl.xtext +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/Tqcl.xtext @@ -31,6 +31,9 @@ Set: Connect: "connect" from+=ConnectionPort(',' from+=ConnectionPort)* "to" to+=ConnectionPort(',' to+=ConnectionPort)*; +ConnectionPort: + actor=[Insert] '.' port=NamedObj; + GoInto returns Go: "go" direction="into" obj = NamedObj ; @@ -73,8 +76,7 @@ terminal ENTITY_CLASS: //terminal ENTITY_INSTANCE_NAME: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|ESCAPED_CHAR)*; -ConnectionPort: - actor=[Insert] '.' port=NamedObj; + diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/scoping/TqclScopeProvider.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/scoping/TqclScopeProvider.java index e31a38e4..85afc0cb 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/scoping/TqclScopeProvider.java +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/scoping/TqclScopeProvider.java @@ -16,6 +16,8 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.triquetrum.commands.tqcl.Connect; +import org.eclipse.triquetrum.commands.tqcl.Insert; +import org.eclipse.triquetrum.commands.tqcl.TqclPackage; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.scoping.IScope; import org.eclipse.xtext.scoping.Scopes; @@ -30,9 +32,15 @@ public class TqclScopeProvider extends AbstractTqclScopeProvider { @Override public IScope getScope(EObject context, EReference reference) { - if (context instanceof Connect) { + if (context instanceof Connect && reference == TqclPackage.Literals.CONNECTION_PORT__ACTOR) { Connect connect = (Connect) context; - + // Collect a list of candidates by going through the model + // EcoreUtil2 provides useful functionality to do that + // For example searching for all elements within the root Object's tree + EObject rootElement = EcoreUtil2.getRootContainer(context); + Iterable candidates = EcoreUtil2.getAllContentsOfType(rootElement, Insert.class); + // Create IEObjectDescriptions and puts them into an IScope instance + return Scopes.scopeFor(candidates); } return super.getScope(context, reference); diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqCLUtils.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqCLUtils.java new file mode 100644 index 00000000..5603a8e1 --- /dev/null +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqCLUtils.java @@ -0,0 +1,31 @@ +package org.eclipse.triquetrum.commands.validation; + +import org.eclipse.triquetrum.commands.tqcl.Category; +import org.eclipse.triquetrum.commands.tqcl.Insert; + +public class TqCLUtils { + + public static String cleanEntityName(String entityClass) { + return entityClass.substring(1, entityClass.lastIndexOf('>')); + } + + public static Category getCategory(Insert insert) { + Category category = insert.getCategory(); + if (category == null) { + category = Category.ACTOR; + } + return category; + } + + public static String cleanParameterName(String id) { + if (id.startsWith("$")) { + return id.substring(1); + } else if (id.startsWith("\"")) { + return id.substring(1, id.lastIndexOf('"')); + } + + // TODO : throw exception??? + return null; + } + +} diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java index eb4282ae..732646b0 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/validation/TqclValidator.java @@ -24,6 +24,7 @@ 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; import org.eclipse.triquetrum.commands.tqcl.Insert; import org.eclipse.triquetrum.commands.tqcl.Library; import org.eclipse.triquetrum.commands.tqcl.Parameter; @@ -83,25 +84,37 @@ public void checkEntityParameters(Insert insert) { for (EObject eObject : eContents) { if (eObject instanceof Library) { Library library = (Library) eObject; - String libraryName = library.getName(); try { - EntityDescriptor actor = tqclLibraryProvider.getActor(libraryName, - cleanEntityClassName(insert.getEntityClass())); - if (actor != null) { - List parameters = actor.getParameters(); + Category category = TqCLUtils.getCategory(insert); + String entityClass = insert.getEntityClass(); + EntityDescriptor entityDescriptor = null; + switch (category) { + case ACTOR: + entityDescriptor = tqclLibraryProvider.getActor(TqCLUtils.cleanEntityName(entityClass)); + break; + case DIRECTOR: + entityDescriptor = tqclLibraryProvider.getDirector(TqCLUtils.cleanEntityName(entityClass)); + break; + + default: + break; + } + + if (entityDescriptor != null) { + List parameters = entityDescriptor.getParameters(); EList tqclParameters = insert.getParameters(); for (Parameter tqclParameter : tqclParameters) { boolean found = false; for (ParameterDescriptor parameterDescriptor : parameters) { if (parameterDescriptor.getDisplayName() - .equals(cleanParameterName(tqclParameter.getId()))) { + .equals(TqCLUtils.cleanParameterName(tqclParameter.getId()))) { found = true; break; } } if (!found) { - String message = MessageFormat.format("Invalid paramete name {0} for actor {1}", - tqclParameter.getId(), actor.getClazz()); + String message = MessageFormat.format("Invalid parameter name {0} for actor {1}", + tqclParameter.getId(), entityDescriptor.getClazz()); error(message, tqclParameter, TqclPackage.Literals.PARAMETER__ID, INVALID_PARAMETER); } } @@ -114,15 +127,4 @@ public void checkEntityParameters(Insert insert) { } } - private Object cleanParameterName(String id) { - if (id.startsWith("$")) { - return id.substring(1); - } else if (id.startsWith("\"")) { - return id.substring(1, id.lastIndexOf('"')); - } - - // TODO : throw exception??? - return null; - } - } diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumLibraryProvider.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumLibraryProvider.java index 2cb9c4c2..d48d53ae 100644 --- a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumLibraryProvider.java +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumLibraryProvider.java @@ -176,6 +176,11 @@ public EntityDescriptor getActor(String library, String actorClass) throws TqCLL public EntityDescriptor getActor(String actorClass) throws TqCLLibraryException { return actors.get(actorClass); } + + @Override + public EntityDescriptor getDirector(String directorClass) throws TqCLLibraryException { + return directors.get(directorClass); + } @Override public boolean hasElementInLibrary(String element, String library, String category) {