Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

44
Introducing AutoComplete for Velocity and FreeMarker languages in Liferay Portal 6.2 Liferay UI Engineer Iliyan Peychev Thursday, October 10, 13

Transcript of Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Page 1: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Introducing AutoComplete for Velocity and FreeMarker languages in Liferay Portal 6.2

Liferay UI Engineer

Iliyan Peychev

Thursday, October 10, 13

Page 2: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

A few words about meStarted as C developer ~12 years ago.

Lately turned to Java developer.

Currently working as Front-End engineer at Liferay.

Twitter: ipeychevGitHub: ipeychev

Thursday, October 10, 13

Page 3: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• What we had in Liferay 6.1• Making the AutoComplete• Making the Palette• Applying both to Web Content, DDM and ADT• Extending the AutoComplete• Future

Agenda

Thursday, October 10, 13

Page 4: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• Relatively complicated user interface

What we had in Liferay 6.1

Thursday, October 10, 13

Page 5: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Step #1:Click on Add Template Button

What we had in Liferay 6.1

Thursday, October 10, 13

Page 6: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Step #2:Click on Launch EditorButton

What we had in Liferay 6.1

Thursday, October 10, 13

Page 7: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Result:Plain Text Editor

What we had in Liferay 6.1

Thursday, October 10, 13

Page 8: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Or basicRich Text Editor

What we had in Liferay 6.1

Thursday, October 10, 13

Page 9: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Click Save orSave and Continue

If you want to edit again,click again on Launch Editor

What we had in Liferay 6.1

Thursday, October 10, 13

Page 10: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• Relatively complicated user interface (true, right?)

What we had in Liferay 6.1

Thursday, October 10, 13

Page 11: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• Relatively complicated user interface (true, right?)• ACE Editor without any kind of AutoComplete

What we had in Liferay 6.1

Thursday, October 10, 13

Page 12: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• Relatively complicated user interface (true, right?)• ACE Editor without any kind of AutoComplete• No Palette

What we had in Liferay 6.1

Thursday, October 10, 13

Page 13: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• Relatively complicated user interface (true, right?)• ACE Editor without any kind of AutoComplete• No Palette• No context help, no link to external resources

What we had in Liferay 6.1

Thursday, October 10, 13

Page 14: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• Relatively complicated user interface (true, right?)• ACE Editor without any kind of AutoComplete• No Palette• No context help, no link to external resources

As result, developers very often used external editors to create their Templates.

What we had in Liferay 6.1

Thursday, October 10, 13

Page 15: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Making the AutoComplete

Thursday, October 10, 13

Page 16: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

ACE Editor does not provide AutoComplete.

We had to build it from scratch.

Fortunately, it turned its API is powerful enough to achieve this goal without many efforts.

Making the AutoComplete

Thursday, October 10, 13

Page 17: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

AutoComplete architecture

ACE Editor Language processor Result list

FiltersSortersFormatters

Thursday, October 10, 13

Page 18: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

• Fill mode• Overwrite mode

Overwrite mode is by default, it replaces the input string entirely.

Fill mode adds the suggestion after the input string.

AutoComplete modes

Thursday, October 10, 13

Page 19: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

We built a new module for the AlloyUI Framework.

This module consists of Base, UI and Language processors.

Currently we support parts of Freemarker and Velocity languages.

ACE AutoComplete is an AlloyUI module

Thursday, October 10, 13

Page 20: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

The Base module intercepts ACE Editor commands, like:

- onTextInput- golinedown- golineup- gotoend- gotolineend- gotolinestart

(and a few others)

The Base

Thursday, October 10, 13

Page 21: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

The UI is a standard AlloyUI Overlay.

It is used to draw the suggestions in a list.

Supports keyboard navigation.

The developer can specify custom sorters or filters.

The UI

Thursday, October 10, 13

Page 22: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Since Freemarker and Velocity are similar and we support part of them, they have a common ancestor.

For both languages we support Directives and Variables.

The Language Processors

Thursday, October 10, 13

Page 23: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

An instance of the Template editor can be modified on the fly.

This means we can always plug and unplug the AutoComplete functionality.

We can even replace one language with another.

Plugin Infrastructure

Thursday, October 10, 13

Page 24: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

AutoComplete Variables example

Variable

AutoComplete UI

Thursday, October 10, 13

Page 25: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

AutoComplete Directives example

Thursday, October 10, 13

Page 26: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Learning from the mistakesInitially we implemented the AutoComplete using Ternary Search Tree.

c / | \ a u h | | | \ t t e u / / | / | s p e i s

Source: Wikipedia

Thursday, October 10, 13

Page 27: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Learning from the mistakesSearching was fast.

Constructing the Tree turned to be slow, so we discarded it from the Editor.

However, it is now AlloyUI module and all developers can use it.

Hint - use it when you construct the tree rarely (or once), but search often.

Thursday, October 10, 13

Page 28: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Making the Palette

Thursday, October 10, 13

Page 29: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Making the PaletteRepresents the most often used:• General variables• Utilities• Web Content Services• Portal Services• Data List Variables• Data List Record Fields

Thursday, October 10, 13

Page 30: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Making the PaletteRepresents the most often used:• General variables• Utilities• Web Content Services• Portal Services• Data List Variables• Data List Record Fields

Dynamically adds the fields in Structures and Data Definitions

Thursday, October 10, 13

Page 31: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

The Palette – general view

Thursday, October 10, 13

Page 32: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

The Palette – general view

Click with the mouse (or tap) to insert the item in the editor

Thursday, October 10, 13

Page 33: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

The Palette – general viewThe result goes where the cursor was

Thursday, October 10, 13

Page 34: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

From Structure to TemplateLet's suppose we have an example structure with

three fields:

• Name• Image• URL

Thursday, October 10, 13

Page 35: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

From Structure to Template

Thursday, October 10, 13

Page 36: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

From Structure to Template

The Palette automatically includes the structure fields on creating Template.

Thursday, October 10, 13

Page 37: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Context help and searching

Context help with link to the Javadoc page

Search box, use it to filter the results

Thursday, October 10, 13

Page 38: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Applying the Palette and AutoComplete• Applying to Web Content• Applying to Data Definitions• Applying to ADT (Application Display Template)

Thursday, October 10, 13

Page 39: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Applying to Data Definitions

Displays the previously created fields into the Data Definition

Thursday, October 10, 13

Page 40: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Extending AutoComplete

The AutoComplete is built with the idea of being easily extendable.

One day I read this Tweet:

“Primeros pasos en el desarrollo de un editor sql online utilizando @AlloyUI , #keepworking ”

Victor Miranda, Support Engineer, Liferay Spain

He created AutoComplete for SQL.

Thursday, October 10, 13

Page 41: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Extending AutoComplete

Web Based SQL Editor with AutoComplete

Thursday, October 10, 13

Page 42: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

The future• Adding more language processors.• Adding visual formatters.• Applying the AutoComplete to other Editors.• Show nested fields in Palette

Thursday, October 10, 13

Page 43: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

You can contribute too!

Sometimes the chains that prevent us to be creative and free are more mental than physical.

Thursday, October 10, 13

Page 44: Implementing AutoComplete for Freemarker and Velocity languages in ACE Editor

Thanks!

Questions?

Twitter: ipeychevGitHub: ipeychev

Thursday, October 10, 13