Vaadin 8 wrapper for the medium editor javascript library. https://github.com/yabwe/medium-editor
Important: For Vaadin 7 please use 1.2.2
- MediumEditor component
- MediumEditorField for simple usage in
com.vaadin.data.fieldgroup.BeanFieldGroup<T>
orcom.vaadin.data.fieldgroup.FieldGroup
- Configure the editor's options with a fluent api
- Usage of Vaadin's FontAwesome integration, therefore no addional css file must be included.
- Localization for English and German
- Custom localization by configuration
If you want to run the demo application locally, see the Contribution Section
Get the addon from https://vaadin.com/directory#!addon/medium-editor-wrapper.
Vaadin runs its own Maven repository and you can download the addon there as well, but you will need to create a free vaadin account first.
Repository
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
Dependency
<dependencies>
<dependency>
<groupId>com.byteowls</groupId>
<artifactId>vaadin-medium-editor</artifactId>
<version>replace.with.version</version>
</dependency>
</dependencies>
Repository
repositories {
jcenter()
}
Dependency
dependencies {
compile ("com.byteowls:vaadin-medium-editor:replace.with.version")
}
For more examples please see the demo app
MediumEditor editor = new MediumEditor();
editor.setFocusOutlineEnabled(false);
editor.setJsLoggingEnabled(true);
// using lorem ipsum to get some text. see demo for dependency
editor.setContent(Lorem.getHtmlParagraphs(3, 3));
editor.addBlurListener(value -> {
preview.setValue(value);
});
The MediumEditor is a vaadin component in its most basic form a <div>
. So in contrast to the javascript library under the hood, there is no constructor for setting a selector string or a inserting dom elements.
This is a known limitation because you cannot have a single editor configuration for more than one field.
// inherited vaadin component method
editor.setSizeFull();
Other wrapper specific options.
- focusOutlineEnabled ... If true the outline / border is shown as soon as the components gets the focus.
- jsLoggingEnabled ... If true logging with
console.log
in the connector script is enabled. Setting this to true, let you review - content
- addBlurListener ... On every blur event on client side the current content is sent to the server. Register your listener to do sth with it.
You're able to use the MediumEditor just like that
protected void init(VaadinRequest request) {
MediumEditor editor = new MediumEditor();
setContent(editor);
}
In this case the default medium-editor options are set. See https://github.com/yabwe/medium-editor#mediumeditor-options for the javascript lib options.
You can overwrite the default options with
MediumEditor editor = new MediumEditor();
editor.configure(
editor.options()
// use FontAwesome button labels
.fontawesomeButtonLabels()
// start configuring the toolbar
.toolbar()
// only this buttons should be included
.buttons(Buttons.BOLD, Buttons.ITALIC, Buttons.H1, Buttons.JUSTIFY_CENTER)
// the the german translations for the buttons. be aware of the order
.buttonTranslations("fett", "kursiv", "Ueberschrift1", "zentriert")
// configuring the button is done, we want to go back and continue configuring other options
.done()
// start configuring the placeholder if the component has no content
.placeholder()
// the actual text
.text("Input prompt")
// configuring the placeholder is done, again we go back and continue configuring other options
.done()
// urls added to the content are automatically converted to links
.autoLink(true)
// image dragging
.imageDragging(false)
// we're done :)
.done()
);
The wrappers fluent option api is mostly named after the javascript options documented at https://github.com/yabwe/medium-editor#mediumeditor-options.
I'll probably add more javadoc in the next versions.
The MediumEditorField is great for usage within FieldGroups.
MediumEditorField editorField = new MediumEditorField(this.i18n.get("messaging.email.content"));
// get the field's editor for further configuration
MediumEditor editor = editorField.getEditor();
The editor
field is then bound to a FieldGroup and might be configured the same way seen above.
- JDK 8 or higher
- Vaadin 8.0.0 or higher
- JDK 8 (because of Lambdas)
- Vaadin 8.0.x
The Vaadin-Medium-Editor is only a wrapper. So if you have any feature requests or found any bugs in the javascript lib please use Medium Editor's issue tracker https://github.com/yabwe/medium-editor/issues
In all other cases please create a issue at https://github.com/moberwasserlechner/vaadin-medium-editor/issues or contribute to the project yourself. For contribution see the next section.
- Fork repo
- Open command line
- Clone your fork
git@github.com:USERNAME/vaadin-medium-editor.git
cd vaadin-medium-editor
- Build eclipse meta data
./gradlew cleanEclipse eclipse
- Open Eclipse
- File -> Import... -> General -> Existing Projects into Workspace
- Browse to your git repository
- Check the option "Search for nested projects"
- Check all 3 projects
- Press finish
This should take not more than 1-2 minutes. You does not need to use any gradle eclipse plugins.
Please do not mix more than one issue in a feature branch. Each feature/bugfix should have its own branch and its own Pull Request (PR).
- Create a issue and describe what you want to do at Issue Tracker
- Create your feature branch (
git checkout -b feature/my-feature
orgit checkout -b bugfix/my-bugfix
) - Test your changes to the best of your ability.
- Add a demo view to the demo application
- Commit your changes (
git commit -m 'Describe feature or bug'
) - Push to the branch (
git push origin feature/my-feature
) - Create a Github Pull Request
The demo application is based on Spring Boot. So its possible to run the Demo as Java Application right out of Eclipse, there is not servlet container needed as Spring Boot has a embedded Tomcat 8 included.
- Open "Debug Configurations..." dialog
- Create a new "Java Application"
- Choose the "vaadin-medium-editor-demo" project
- Use "com.byteowls.vaadin.mediumeditor.demo.AddonDemoApplication" as Main class
- Set
-Dprofile=dev
as VM argument. This ensures that source code panel in the demo is correctly filled while developing. - Browse to
http://localhost:8080/
Additional languages are very welcome.
ResourceBundles with properties files for the actual translations are used. They are located at
https://github.com/moberwasserlechner/vaadin-medium-editor/tree/master/addon/src/main/resources/com/byteowls/vaadin/mediumeditor/options
Supported languages are:
- English (fallback)
- German
Please use the sun coding convention. Please do not use tabs at all!
MIT. Please see LICENSE.
Please see CHANGELOG.