Jain I18N
I18N (Internationalization) support or common use cases default implementation for Vaadin
JainI18N is a pure server-side extension to a great Vaadin framework, providing extra collection of common use cases usually used in almost any vaadin-based web application. There are couple of libraries available to support these features, but either they are missing some of the use cases or they need component registration logic to be written by the developer. This library aims to help you save development time by reusing pre-defined components :
-- I18N (Internationalization) support : I18N support makes your application international compliant by using pure Java messaging API (i. e. resource bundle). This library almost support all the Vaadin components.
This library require few configuration to provide I18N support in your application
- Use I18NUI instead of the UI.
- Use I18NWindow instead of Window.
This library also allows you to defining your own I18NComponentHandler for a specific component.
- Register/De-register your component handler by calling register/deRegister static method of I18NComponentHandlerFactory in initialize method of ApplicationUI class.
-- I18N (Internationalization) change listener : Allows you to customize component data and other attributes on local change.
- You can achieve this functionality in the application by implementing I18NChangeListener interface on your component.
-- Component Initialization : Allows you to initialize component after creation similar to post construct call back in EJB. This initialization happens during I18N component registration API.
- You can achieve this functionality by annotating your initialization method by @JNIComponentInit annotation.
-- Image Component : Allows you to upload image with instant view in the form.
- You can achieve this by adding JImage component in your application.
-- Login event listener : Allows you to call a method in your component after login event accures.
- You can achieve this functionality by implementing JNILoginListenr on your component.
- This requires you to call onLogin static method of the JLoginHandler by passing UI object.
-- Observer Design Pattern : Allows you to add observers and fire an event to call these observable methods.
- Observers defined in each component will be called after firing an event in from the application.
- You can define observable method by annotating @JNIObserver annotation.
-- Action / Menu bar : Allows you to create action/menu bar with or without grouping by annotations.
- You can achieve this functionality by annotating your action method with @JNAction annotation.
- Also, you can group your actions by annotating action provider component or class by annotating them with @JNGroups or @JNGroup annotations.
- This also allows you to add security to all these action methods to control visibility. You can achieve security by providing a security provider which should implemnet JNISecured.
- Also allows you to add confirmation dialog for any action.
Sample code
public class ApplicationUI extends I18NUI { @Inject AuthenticatedUser user; protected void initialize (WrappedRequest request) { initialize (Locale.getDefault()); } public void initialize (Locale locale) { user.setLocale(locale); addApplicationTitle(); VerticalLayout view = new VerticalLayout(); setContent(view); view.setStyleName(ApplicationTheme.VIEW); view.setWidth("100%"); view.setHeight("100%"); view.setSpacing(false); view.setMargin(false); createWelcomebar(view); Header header = CDIComponent.getInstance(Header.class); view.addComponent(header); header.addDefaultTab(); } private void addApplicationTitle() { I18NProvider provider = I18NResourceProvider.instance(); getPage().setTitle(provider.getText(getLocale(), "application.title.name")); } private void createWelcomebar(VerticalLayout view) { WelcomeBar welcomebar = CDIComponent.getInstance(WelcomeBar.class); view.addComponent(welcomebar); } }
public class PersonAnnotationForm extends I18NWindow implements JNIEditLocal, JNIComponent { private Person person; private FieldGroup fieldGroup; private boolean viewOnly; public PersonAnnotationForm() { this.viewOnly = false; } public void init () { setModal(true); setWidth("70%"); VerticalLayout layout = new VerticalLayout(); layout.setWidth("100%"); layout.setMargin(new MarginInfo(false, false, true, false)); layout.setStyleName(ApplicationTheme.ALTERNATE_VIEW); setContent(layout); createFieldGroup(layout); createActions(layout); } private void createActions(VerticalLayout layout) { if(!viewOnly) { JainEditClickListener clickListner = new JainEditClickListener(this); HorizontalLayout hLayout = VaadinHelper.createButtonSegment (clickListner, JAction.SAVE, JAction.CANCEL); VerticalLayout vLayout = new VerticalLayout(); vLayout.setSizeUndefined(); vLayout.setStyleName(ApplicationTheme.VIEW); vLayout.addComponent(hLayout); layout.addComponent(vLayout); layout.setComponentAlignment(vLayout, Alignment.MIDDLE_CENTER); layout.setExpandRatio(vLayout, 1); } } private void createFieldGroup(VerticalLayout layout) { JainBeanItem<Person> item = new JainBeanItem<Person>(getPerson ()); JFieldGroup<Person> jainFieldGroup = new JFieldGroup<Person>(Person.class, 2); jainFieldGroup.setViewOnly (viewOnly); jainFieldGroup.setStyleName(ApplicationTheme.VIEW); jainFieldGroup.setAlternateStyleName(ApplicationTheme.ALTERNATE_VIEW); layout.addComponent(jainFieldGroup); fieldGroup = jainFieldGroup.createFieldGroup(Person.class, item); } public void save() { try { fieldGroup.commit(); Events.instance().raiseEvent(PersonAnnotationGrid.PERSON_CREATED_OR_UPDATED, person); getUI().removeWindow(this); } catch (CommitException e) { e.printStackTrace(); } } public void cancel() { fieldGroup.discard(); getUI().removeWindow(this); } private Person getPerson() { if (person == null) { person = new Person(); person.setAddress(new Address(new ZIP())); } return person; } public void setPerson(Person person) { this.person = person; } public boolean isViewOnly() { return viewOnly; } public void setViewOnly(boolean viewOnly) { this.viewOnly = viewOnly; } }
package com.jain.i18N.component; import com.jain.addon.JNIComponentInit; import com.jain.addon.action.ActionBar; import com.jain.addon.action.ActionMenuBar; import com.jain.addon.action.JNAction; import com.jain.addon.action.JNActionGroup; import com.jain.addon.action.JNActionGroups; import com.jain.addon.component.upload.JImage; import com.jain.common.VaadinHelper; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; import com.vaadin.ui.VerticalLayout; @SuppressWarnings("serial") @JNActionGroups (actionGroups = {@JNActionGroup (name = "file.action.group.name"), @JNActionGroup (name = "new.action.group.name", parent = "file.action.group.name"), @JNActionGroup (name = "edit.action.group.name", icon = "edit.action.icon")}) public class ActionNMenuBar extends VerticalLayout { @JNIComponentInit public void init () { setMargin(true); setSpacing(true); setWidth("100%"); setHeight("100%"); Label label = new Label("menu.bar.component.name"); addComponent(label); ActionMenuBar<ComponentTabContent> menuBar = new ActionMenuBar<ComponentTabContent>(null, this); addComponent(menuBar); setExpandRatio(menuBar, 2); label = new Label("action.bar.component.name"); addComponent(label); ActionBar<ComponentTabContent> actionBar = new ActionBar<ComponentTabContent>(null, this); addComponent(actionBar); setExpandRatio(actionBar, 2); } @JNAction (name = "open.file.action.name", actionGroup = "file.action.group.name", tabIndex = 10) public void openFile() { callActionMessage("open.file.action.name", "file.action.group.name"); } @JNAction (name = "close.action.name", actionGroup = "file.action.group.name", tabIndex = 11) public void newFile() { callActionMessage("close.action.name", "file.action.group.name"); } @JNAction (name = "close.all.action.name", actionGroup = "file.action.group.name", tabIndex = 12, separator = true) public void close() { callActionMessage("close.all.action.name", "file.action.group.name"); } @JNAction (name = "save.action.name", actionGroup = "file.action.group.name", tabIndex = 13, icon="save.action.icon") public void save() { callActionMessage("save.action.name", "file.action.group.name"); } @JNAction (name = "save.as.action.name", actionGroup = "file.action.group.name", tabIndex = 14) public void saveAs() { callActionMessage("save.as.action.name", "file.action.group.name"); } @JNAction (name = "save.all.action.name", actionGroup = "file.action.group.name", tabIndex = 15) public void saveAll() { callActionMessage("save.all.action.name", "file.action.group.name"); } @JNAction (name = "file.action.name", actionGroup = "new.action.group.name", tabIndex = 1) public void file() { callActionMessage("file.action.name", "new.action.group.name"); } @JNAction (name = "folder.action.name", actionGroup = "new.action.group.name", tabIndex = 2) public void folder() { callActionMessage("folder.action.name", "new.action.group.name"); } @JNAction (name = "project.action.name", actionGroup = "new.action.group.name", tabIndex = 3) public void project() { callActionMessage("project.action.name", "new.action.group.name"); } @JNAction (name = "undo.action.name", actionGroup = "edit.action.group.name", tabIndex = 20) public void undo() { callActionMessage("undo.action.name", "edit.action.group.name"); } @JNAction (name = "redo.action.name", actionGroup = "edit.action.group.name", tabIndex = 21, separator = true) public void redo() { callActionMessage("redo.action.name", "edit.action.group.name"); } @JNAction (name = "cut.action.name", actionGroup = "edit.action.group.name", tabIndex = 22) public void cut() { callActionMessage("cut.action.name", "edit.action.group.name"); } @JNAction (name = "copy.action.name", actionGroup = "edit.action.group.name", tabIndex = 23) public void copy() { callActionMessage("copy.action.name", "edit.action.group.name"); } @JNAction (name = "paste.action.name", actionGroup = "edit.action.group.name", tabIndex = 24) public void paste() { callActionMessage("paste.action.name", "edit.action.group.name"); } private void callActionMessage(String actionName, String groupName) { Notification notification = VaadinHelper.createNotificationMessage("action.invoked.from", "action.invoked.from", actionName, groupName); notification.show(getUI().getPage()); } }
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
Upgraded to support 7.5
- Released
- 2015-09-07
- Maturity
- STABLE
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.0+
- Vaadin 7.0 in 1.0.1
- Browser
- Browser Independent
Jain I18N - Vaadin Add-on Directory
I18N (Internationalization) support or common use cases default implementation for VaadinOnline Demo
Source Code
Issue Tracker
Demo/Example Source Code
FAQ
Jain I18N version 1.0.1
Updated API to support Vaadin-7 beta3 API changes
Jain I18N version 1.0.2
Fixed Memory leak problem, available in Event handler.
Moved HAS-A relation ship logic from JainI18N to JainAssoc.
Jain I18N version 1.1.0
1). Added Annotation based Action Bar component
2). Added Annotation based Menu bar component
3). Added mising Menu bar I18N handling
Jain I18N version 1.1.1
Updated to version beta-11
Jain I18N version 1.1.2
Added Annotation based Confirmation dialog for action
Jain I18N version 1.1.3
Moved to Rc2
Jain I18N version 1.1.4
Moved to 7.0.1
Jain I18N version 1.1.6
Upgraded Vaadin Version to 7.2.1
Jain I18N version 1.1.7
Fixed An issue and Upgraded Vaadin version to 7.3.7
Jain I18N version 1.1.9
Upgraded to support 7.5