Package com.alkacon.acacia.client.example

Source Code of com.alkacon.acacia.client.example.Example

* This library is part of the Acacia Editor -
* an open source inline and form based content editor for GWT.
* Copyright (c) Alkacon Software GmbH (
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* Lesser General Public License for more details.
* For further information about Alkacon Software, please see the
* company website:
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

package com.alkacon.acacia.client.example;

import com.alkacon.acacia.client.FormParent;
import com.alkacon.acacia.client.I_EntityRenderer;
import com.alkacon.acacia.client.I_WidgetFactory;
import com.alkacon.acacia.client.Renderer;
import com.alkacon.acacia.client.WidgetService;
import com.alkacon.acacia.client.css.I_LayoutBundle;
import com.alkacon.acacia.client.widgets.FormWidgetWrapper;
import com.alkacon.acacia.client.widgets.I_EditWidget;
import com.alkacon.acacia.client.widgets.I_FormEditWidget;
import com.alkacon.acacia.client.widgets.StringWidget;
import com.alkacon.acacia.client.widgets.TinyMCEWidget;
import com.alkacon.acacia.shared.AttributeConfiguration;
import com.alkacon.acacia.shared.ContentDefinition;
import com.alkacon.acacia.shared.Type;
import com.alkacon.vie.client.Entity;
import com.alkacon.vie.client.I_Vie;
import com.alkacon.vie.client.Vie;
import com.alkacon.vie.shared.I_Entity;
import com.alkacon.vie.shared.I_Type;

import java.util.HashMap;
import java.util.Map;


* Show case for the form renderer.<p>
public class Example implements EntryPoint {

    /** Address attribute name. */
    private static String addressAttribute = "person:address";

    /** Address type name. */
    private static String addressTypeName = "type:address";

    /** City attribute name. */
    private static String cityAttribute = "address:city";

    /** Country attribute type name. */
    private static String countryAttribute = "address:country";

    /** First name attribute name. */
    private static String firstnameAttribute = "person:firstname";

    /** Last name attribute name. */
    private static String lastNameAttribute = "person:lastname";

    /** Person type name. */
    private static String personTypeName = "type:person";

    /** String type name. */
    private static String stringTypeName = "type:string";

     * @see
    public void onModuleLoad() {


        I_Vie vie = Vie.getInstance();
        ContentDefinition definition = generateContentDefinition();
        I_Entity person = register(vie, definition);

        WidgetService service = new WidgetService();
        service.addWidgetFactory("string", new I_WidgetFactory() {

            public I_FormEditWidget createFormWidget(String configuration) {

                return new FormWidgetWrapper(new StringWidget());

            public I_EditWidget createInlineWidget(String configuration, Element element) {

                return new StringWidget(element);
        service.addWidgetFactory("html", new I_WidgetFactory() {

            public I_FormEditWidget createFormWidget(String configuration) {

                return new FormWidgetWrapper(new TinyMCEWidget(null));

            public I_EditWidget createInlineWidget(String configuration, Element element) {

                return new TinyMCEWidget(element, null);
        I_EntityRenderer defaultRenderer = new Renderer(vie, service);
        FormParent formParent = new FormParent(RootPanel.get("inline_form"));
        I_EntityRenderer renderer = service.getRendererForType(vie.getType(personTypeName));
        renderer.renderInline(person, formParent, null);

        ((Entity)person).addValueChangeHandler(new ValueChangeHandler<Entity>() {

            public void onValueChange(ValueChangeEvent<Entity> event) {

                RootPanel.get().add(new Label(event.getValue().toJSON()));

     * Generates a content definition.<p>
     * @return the content definition
    private ContentDefinition generateContentDefinition() {

        Type string = new Type(stringTypeName);
        Type address = new Type(addressTypeName);
        address.addAttribute(cityAttribute, stringTypeName, 1, 1);
        address.addAttribute(countryAttribute, stringTypeName, 1, 1);
        Type person = new Type(personTypeName);
        person.addAttribute(firstnameAttribute, stringTypeName, 1, 1);
        person.addAttribute(lastNameAttribute, stringTypeName, 1, 1);
        person.addAttribute(addressAttribute, addressTypeName, 1, 1);
        Map<String, I_Type> types = new HashMap<String, I_Type>();
        types.put(stringTypeName, string);
        types.put(addressTypeName, address);
        types.put(personTypeName, person);
        Map<String, AttributeConfiguration> attributes = new HashMap<String, AttributeConfiguration>();
        attributes.put(firstnameAttribute, new AttributeConfiguration(
            "The firtname",
        attributes.put(lastNameAttribute, new AttributeConfiguration(
            "The lastname",

        attributes.put(cityAttribute, new AttributeConfiguration("City", "The city", "string", null, "", "wide"));
        attributes.put(countryAttribute, new AttributeConfiguration(
            "The country",

        com.alkacon.acacia.shared.Entity addressEntity = new com.alkacon.acacia.shared.Entity(

        addressEntity.setAttributeValue(cityAttribute, "Hamburg");
        addressEntity.setAttributeValue(countryAttribute, "fr");

        com.alkacon.acacia.shared.Entity personEntity = new com.alkacon.acacia.shared.Entity("myPerson", personTypeName);
        personEntity.setAttributeValue(firstnameAttribute, "Hans");
        personEntity.setAttributeValue(lastNameAttribute, "Albers");
        personEntity.setAttributeValue(addressAttribute, addressEntity);
        return new ContentDefinition(personEntity, attributes, types, null, false, "de");

     * Registers the types within the content definition.<p>
     * @param vie the VIE instance
     * @param definition the content definition
     * @return the registered content entity
    private I_Entity register(I_Vie vie, ContentDefinition definition) {

        Map<String, I_Type> types = definition.getTypes();
        I_Type base = types.get(definition.getEntity().getTypeName());
        vie.registerTypes(base, types);
        return vie.registerEntity(definition.getEntity());

Related Classes of com.alkacon.acacia.client.example.Example

Copyright © 2018 All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact