Back to Tutorials Index... ## Autocompletion Since the last releases, VSM supports the autocompletion feature within the scene script editor window. This feature is not available for all extensions. To activate it, it is neccesary to indicate that the extension supports autocompletation and it is also mandatory to provide a method with all the available options. ### Specifying that the extension supports autocompletation: To specify that an extension provides autocompletion features, the Executor class must implement the interface `ExportableCompletion`. Ex: ``` public class DecadExecutor extends ActivityExecutor implements ExportableCompletion { ... } ``` It is mandatory to implmement the contract defined by the *ExportableCompletion* interface. This interface only has one method: `public List<String> getExportableActions(){...}` As you can see, this method returns a list of strings. Such a list, should contain all the options available for the extension. The implementation of this method could vary depending on how we obtain the options. For example, **Stickman**, provides a public method which returns a list of all the animations that Stickman can perform. If we don't have such functionality from the agent rendering application, we can hardcoded build such a list. The following snippet is a class part of the **DECAD Executor** that retrieves all the animations from DECAD server, parses it and adds it on the list which it is ultimately returned. ``` package de.dfki.vsm.xtension.decad.properties; import de.dfki.vsm.util.extensions.ExportableCompletion; import de.dfki.vsm.util.log.LOGDefaultLogger; import de.dfki.vsm.xtension.decad.commands.AnimationsListCommand; import de.dfki.vsm.xtension.decad.commands.DecadCommand; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ExportAnimations implements ExportableCompletion { private final LOGDefaultLogger mLogger = LOGDefaultLogger.getInstance(); @Override public List<String> getExportableActions() { try { return getAnimationListFromServer(); } catch (InterruptedException | IOException e) { mLogger.message("Could not load animations from server"); } return new ArrayList<>(); } private ArrayList<String> getAnimationListFromServer() throws InterruptedException, IOException { JSONArray jsonAnimation = fetchAnimationsFromServer(); return convertJsonArrayToArrayList(jsonAnimation); } @NotNull private ArrayList<String> convertJsonArrayToArrayList(JSONArray jsonAnimation) { ArrayList<String> animations = new ArrayList<>(); for (int i = 0; i < jsonAnimation.length(); i++) { animations.add(jsonAnimation.getString(i)); } return animations; } @NotNull private JSONArray fetchAnimationsFromServer() throws IOException, InterruptedException { DecadCommand animationList = new AnimationsListCommand(); animationList.execute(); String animationsResponse = animationList.getResponse(); return new JSONArray(animationsResponse); } } ```
Back to Tutorials Index...